Commit 11c9d1dc authored by wutao's avatar wutao Committed by Commit Bot

CrOS: Use foreground blur for lock screen.

Using foreground blur make it possible to cache the render surface and
provide good performance.

Bug: 738185
Test: tested locally.
Change-Id: I838c072ecd4deeb9e181e08644d215877616f0ef
Reviewed-on: https://chromium-review.googlesource.com/578713
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488618}
parent 7f80af5b
......@@ -9,11 +9,14 @@
#include "ash/login/ui/lock_window.h"
#include "ash/login/ui/login_data_dispatcher.h"
#include "ash/public/interfaces/session_controller.mojom.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
#include "chromeos/chromeos_switches.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
......@@ -28,6 +31,13 @@ views::View* BuildContentsView(LoginDataDispatcher* data_dispatcher) {
return new LockContentsView(data_dispatcher);
}
ui::Layer* GetWallpaperLayerForWindow(aura::Window* window) {
return RootWindowController::ForWindow(window)
->wallpaper_widget_controller()
->widget()
->GetLayer();
}
// Global lock screen instance. There can only ever be on lock screen at a
// time.
LockScreen* instance_ = nullptr;
......@@ -67,22 +77,38 @@ void LockScreen::Show() {
window->set_data_dispatcher(std::move(data_dispatcher));
window->Show();
for (aura::Window* window : Shell::GetAllRootWindows()) {
ui::Layer* layer = GetWallpaperLayerForWindow(window);
instance_->initial_blur_[layer] = layer->layer_blur();
}
instance_->ToggleBlur();
}
void LockScreen::Destroy() {
CHECK_EQ(instance_, this);
for (aura::Window* window : Shell::GetAllRootWindows()) {
ui::Layer* layer = GetWallpaperLayerForWindow(window);
auto it = initial_blur_.find(layer);
if (it != initial_blur_.end())
layer->SetLayerBlur(it->second);
}
window_->Close();
delete instance_;
instance_ = nullptr;
}
void LockScreen::ToggleBlur() {
if (instance_->window_->GetLayer()->background_blur() == 0) {
// TODO(jdufault): Use correct blur amount.
instance_->window_->GetLayer()->SetBackgroundBlur(20);
} else {
instance_->window_->GetLayer()->SetBackgroundBlur(0);
// TODO(jdufault): Use correct blur amount.
float target_blur = 20.0f;
for (aura::Window* window : Shell::GetAllRootWindows()) {
ui::Layer* layer = GetWallpaperLayerForWindow(window);
if (layer->layer_blur() == target_blur) {
layer->SetLayerBlur(0.0f);
} else {
layer->SetLayerBlur(target_blur);
}
}
}
......
......@@ -5,11 +5,17 @@
#ifndef ASH_LOGIN_UI_LOCK_SCREEN_H_
#define ASH_LOGIN_UI_LOCK_SCREEN_H_
#include <unordered_map>
#include "ash/ash_export.h"
#include "base/macros.h"
class AccountId;
namespace ui {
class Layer;
}
namespace ash {
class LockWindow;
......@@ -40,6 +46,9 @@ class LockScreen {
// Unowned pointer to the window which hosts the lock screen.
LockWindow* window_ = nullptr;
// The wallpaper bluriness before entering lock_screen.
std::unordered_map<ui::Layer*, float> initial_blur_;
DISALLOW_COPY_AND_ASSIGN(LockScreen);
};
......
......@@ -97,6 +97,7 @@ Layer::Layer()
layer_brightness_(0.0f),
layer_grayscale_(0.0f),
layer_inverted_(false),
layer_blur_sigma_(0.0f),
layer_temperature_(0.0f),
layer_blue_scale_(1.0f),
layer_green_scale_(1.0f),
......@@ -123,6 +124,7 @@ Layer::Layer(LayerType type)
layer_brightness_(0.0f),
layer_grayscale_(0.0f),
layer_inverted_(false),
layer_blur_sigma_(0.0f),
layer_temperature_(0.0f),
layer_blue_scale_(1.0f),
layer_green_scale_(1.0f),
......@@ -174,6 +176,7 @@ std::unique_ptr<Layer> Layer::Clone() const {
clone->SetLayerBrightness(GetTargetBrightness());
clone->SetLayerGrayscale(GetTargetGrayscale());
clone->SetLayerInverted(layer_inverted_);
clone->SetLayerBlur(layer_blur_sigma_);
if (alpha_shape_)
clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_));
......@@ -401,6 +404,12 @@ void Layer::SetBackgroundBlur(float blur_sigma) {
SetLayerBackgroundFilters();
}
void Layer::SetLayerBlur(float blur_sigma) {
layer_blur_sigma_ = blur_sigma;
SetLayerFilters();
}
void Layer::SetLayerSaturation(float saturation) {
layer_saturation_ = saturation;
SetLayerFilters();
......@@ -492,6 +501,10 @@ void Layer::SetLayerFilters() {
}
if (layer_inverted_)
filters.Append(cc::FilterOperation::CreateInvertFilter(1.0));
if (layer_blur_sigma_) {
filters.Append(cc::FilterOperation::CreateBlurFilter(
layer_blur_sigma_, SkBlurImageFilter::kClamp_TileMode));
}
// Brightness goes last, because the resulting colors neeed clamping, which
// cause further color matrix filters to be applied separately. In this order,
// they all can be combined in a single pass.
......
......@@ -198,6 +198,10 @@ class COMPOSITOR_EXPORT Layer
float background_blur() const { return background_blur_sigma_; }
void SetBackgroundBlur(float blur_sigma);
// Blur pixels of this layer by 3 * this amount.
float layer_blur() const { return layer_blur_sigma_; }
void SetLayerBlur(float blur_sigma);
// Saturate all pixels of this layer by this amount.
// This effect will get "combined" with the inverted,
// brightness and grayscale setting.
......@@ -511,6 +515,7 @@ class COMPOSITOR_EXPORT Layer
float layer_brightness_;
float layer_grayscale_;
bool layer_inverted_;
float layer_blur_sigma_;
// The global color temperature value (0.0f ~ 1.0f). Used to calculate the
// layer blue and green colors scales. 0.0f is least warm (default), and 1.0f
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment