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 @@ ...@@ -9,11 +9,14 @@
#include "ash/login/ui/lock_window.h" #include "ash/login/ui/lock_window.h"
#include "ash/login/ui/login_data_dispatcher.h" #include "ash/login/ui/login_data_dispatcher.h"
#include "ash/public/interfaces/session_controller.mojom.h" #include "ash/public/interfaces/session_controller.mojom.h"
#include "ash/root_window_controller.h"
#include "ash/session/session_controller.h" #include "ash/session/session_controller.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wallpaper/wallpaper_widget_controller.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "ui/compositor/layer.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -28,6 +31,13 @@ views::View* BuildContentsView(LoginDataDispatcher* data_dispatcher) { ...@@ -28,6 +31,13 @@ views::View* BuildContentsView(LoginDataDispatcher* data_dispatcher) {
return new LockContentsView(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 // Global lock screen instance. There can only ever be on lock screen at a
// time. // time.
LockScreen* instance_ = nullptr; LockScreen* instance_ = nullptr;
...@@ -67,22 +77,38 @@ void LockScreen::Show() { ...@@ -67,22 +77,38 @@ void LockScreen::Show() {
window->set_data_dispatcher(std::move(data_dispatcher)); window->set_data_dispatcher(std::move(data_dispatcher));
window->Show(); window->Show();
for (aura::Window* window : Shell::GetAllRootWindows()) {
ui::Layer* layer = GetWallpaperLayerForWindow(window);
instance_->initial_blur_[layer] = layer->layer_blur();
}
instance_->ToggleBlur(); instance_->ToggleBlur();
} }
void LockScreen::Destroy() { void LockScreen::Destroy() {
CHECK_EQ(instance_, this); 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(); window_->Close();
delete instance_; delete instance_;
instance_ = nullptr; instance_ = nullptr;
} }
void LockScreen::ToggleBlur() { void LockScreen::ToggleBlur() {
if (instance_->window_->GetLayer()->background_blur() == 0) {
// TODO(jdufault): Use correct blur amount. // TODO(jdufault): Use correct blur amount.
instance_->window_->GetLayer()->SetBackgroundBlur(20); 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 { } else {
instance_->window_->GetLayer()->SetBackgroundBlur(0); layer->SetLayerBlur(target_blur);
}
} }
} }
......
...@@ -5,11 +5,17 @@ ...@@ -5,11 +5,17 @@
#ifndef ASH_LOGIN_UI_LOCK_SCREEN_H_ #ifndef ASH_LOGIN_UI_LOCK_SCREEN_H_
#define ASH_LOGIN_UI_LOCK_SCREEN_H_ #define ASH_LOGIN_UI_LOCK_SCREEN_H_
#include <unordered_map>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "base/macros.h" #include "base/macros.h"
class AccountId; class AccountId;
namespace ui {
class Layer;
}
namespace ash { namespace ash {
class LockWindow; class LockWindow;
...@@ -40,6 +46,9 @@ class LockScreen { ...@@ -40,6 +46,9 @@ class LockScreen {
// Unowned pointer to the window which hosts the lock screen. // Unowned pointer to the window which hosts the lock screen.
LockWindow* window_ = nullptr; LockWindow* window_ = nullptr;
// The wallpaper bluriness before entering lock_screen.
std::unordered_map<ui::Layer*, float> initial_blur_;
DISALLOW_COPY_AND_ASSIGN(LockScreen); DISALLOW_COPY_AND_ASSIGN(LockScreen);
}; };
......
...@@ -97,6 +97,7 @@ Layer::Layer() ...@@ -97,6 +97,7 @@ Layer::Layer()
layer_brightness_(0.0f), layer_brightness_(0.0f),
layer_grayscale_(0.0f), layer_grayscale_(0.0f),
layer_inverted_(false), layer_inverted_(false),
layer_blur_sigma_(0.0f),
layer_temperature_(0.0f), layer_temperature_(0.0f),
layer_blue_scale_(1.0f), layer_blue_scale_(1.0f),
layer_green_scale_(1.0f), layer_green_scale_(1.0f),
...@@ -123,6 +124,7 @@ Layer::Layer(LayerType type) ...@@ -123,6 +124,7 @@ Layer::Layer(LayerType type)
layer_brightness_(0.0f), layer_brightness_(0.0f),
layer_grayscale_(0.0f), layer_grayscale_(0.0f),
layer_inverted_(false), layer_inverted_(false),
layer_blur_sigma_(0.0f),
layer_temperature_(0.0f), layer_temperature_(0.0f),
layer_blue_scale_(1.0f), layer_blue_scale_(1.0f),
layer_green_scale_(1.0f), layer_green_scale_(1.0f),
...@@ -174,6 +176,7 @@ std::unique_ptr<Layer> Layer::Clone() const { ...@@ -174,6 +176,7 @@ std::unique_ptr<Layer> Layer::Clone() const {
clone->SetLayerBrightness(GetTargetBrightness()); clone->SetLayerBrightness(GetTargetBrightness());
clone->SetLayerGrayscale(GetTargetGrayscale()); clone->SetLayerGrayscale(GetTargetGrayscale());
clone->SetLayerInverted(layer_inverted_); clone->SetLayerInverted(layer_inverted_);
clone->SetLayerBlur(layer_blur_sigma_);
if (alpha_shape_) if (alpha_shape_)
clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_)); clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_));
...@@ -401,6 +404,12 @@ void Layer::SetBackgroundBlur(float blur_sigma) { ...@@ -401,6 +404,12 @@ void Layer::SetBackgroundBlur(float blur_sigma) {
SetLayerBackgroundFilters(); SetLayerBackgroundFilters();
} }
void Layer::SetLayerBlur(float blur_sigma) {
layer_blur_sigma_ = blur_sigma;
SetLayerFilters();
}
void Layer::SetLayerSaturation(float saturation) { void Layer::SetLayerSaturation(float saturation) {
layer_saturation_ = saturation; layer_saturation_ = saturation;
SetLayerFilters(); SetLayerFilters();
...@@ -492,6 +501,10 @@ void Layer::SetLayerFilters() { ...@@ -492,6 +501,10 @@ void Layer::SetLayerFilters() {
} }
if (layer_inverted_) if (layer_inverted_)
filters.Append(cc::FilterOperation::CreateInvertFilter(1.0)); 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 // Brightness goes last, because the resulting colors neeed clamping, which
// cause further color matrix filters to be applied separately. In this order, // cause further color matrix filters to be applied separately. In this order,
// they all can be combined in a single pass. // they all can be combined in a single pass.
......
...@@ -198,6 +198,10 @@ class COMPOSITOR_EXPORT Layer ...@@ -198,6 +198,10 @@ class COMPOSITOR_EXPORT Layer
float background_blur() const { return background_blur_sigma_; } float background_blur() const { return background_blur_sigma_; }
void SetBackgroundBlur(float 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. // Saturate all pixels of this layer by this amount.
// This effect will get "combined" with the inverted, // This effect will get "combined" with the inverted,
// brightness and grayscale setting. // brightness and grayscale setting.
...@@ -511,6 +515,7 @@ class COMPOSITOR_EXPORT Layer ...@@ -511,6 +515,7 @@ class COMPOSITOR_EXPORT Layer
float layer_brightness_; float layer_brightness_;
float layer_grayscale_; float layer_grayscale_;
bool layer_inverted_; bool layer_inverted_;
float layer_blur_sigma_;
// The global color temperature value (0.0f ~ 1.0f). Used to calculate the // 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 // 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