Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: ash/wm/system_background_controller.cc

Issue 11273059: ash: Clean up system background layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/system_background_controller.h ('k') | ash/wm/workspace/colored_window_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/system_background_controller.h"
6 #include "third_party/skia/include/core/SkBitmap.h"
7 #include "third_party/skia/include/core/SkColor.h"
8 #include "ui/aura/root_window.h"
9 #include "ui/base/layout.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/layer_type.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/image/image_skia.h"
14 #include "ui/gfx/image/image_skia_rep.h"
15
16 namespace ash {
17 namespace internal {
18
19 namespace {
20
21 #if defined(OS_CHROMEOS)
22 // Background color used for the Chrome OS boot splash screen.
23 const SkColor kChromeOsBootColor = SkColorSetARGB(0xff, 0xfe, 0xfe, 0xfe);
24 #endif
25
26 } // namespace
27
28 // ui::LayerDelegate that copies the aura host window's content to a ui::Layer.
29 class SystemBackgroundController::HostContentLayerDelegate
30 : public ui::LayerDelegate {
31 public:
32 explicit HostContentLayerDelegate(aura::RootWindow* root_window)
33 : root_window_(root_window) {
34 }
35
36 virtual ~HostContentLayerDelegate() {}
37
38 // ui::LayerDelegate overrides:
39 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
40 // It'd be safer to copy the area to a canvas in the constructor and then
41 // copy from that canvas to this one here, but this appears to work (i.e. we
42 // only call this before we draw our first frame) and it saves us an extra
43 // copy.
44 root_window_->CopyAreaToSkCanvas(
45 gfx::Rect(root_window_->GetHostOrigin(), root_window_->GetHostSize()),
46 gfx::Point(), canvas->sk_canvas());
47 }
48
49 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {}
50
51 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE {
52 return base::Closure();
53 }
54
55 private:
56 aura::RootWindow* root_window_; // not owned
57
58 DISALLOW_COPY_AND_ASSIGN(HostContentLayerDelegate);
59 };
60
61 SystemBackgroundController::SystemBackgroundController(
62 aura::RootWindow* root_window,
63 Content initial_content)
64 : root_window_(root_window),
65 content_(CONTENT_INVALID) {
66 root_window_->AddRootWindowObserver(this);
67 SetContent(initial_content);
68 }
69
70 SystemBackgroundController::~SystemBackgroundController() {
71 root_window_->RemoveRootWindowObserver(this);
72 }
73
74 void SystemBackgroundController::SetContent(Content new_content) {
75 if (new_content == content_)
76 return;
77
78 content_ = new_content;
79 switch (new_content) {
80 case CONTENT_COPY_FROM_HOST:
81 CreateTexturedLayerWithHostContent();
82 break;
83 case CONTENT_BLACK:
84 CreateColoredLayer(SK_ColorBLACK);
85 break;
86 #if defined(OS_CHROMEOS)
87 case CONTENT_CHROME_OS_BOOT_COLOR:
88 CreateColoredLayer(kChromeOsBootColor);
89 break;
90 #endif
91 case CONTENT_INVALID:
92 DCHECK(false) << "Invalid background layer content";
93 }
94 }
95
96 void SystemBackgroundController::OnRootWindowResized(
97 const aura::RootWindow* root,
98 const gfx::Size& old_size) {
99 DCHECK_EQ(root_window_, root);
100 if (layer_.get())
101 UpdateLayerBounds(layer_.get());
102 }
103
104 void SystemBackgroundController::CreateTexturedLayerWithHostContent() {
105 layer_.reset();
106 layer_delegate_.reset(new HostContentLayerDelegate(root_window_));
107 layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
108 layer_->set_delegate(layer_delegate_.get());
109 UpdateLayerBounds(layer_.get());
110 AddLayerToRootLayer(layer_.get());
111 }
112
113 void SystemBackgroundController::CreateColoredLayer(SkColor color) {
114 layer_.reset();
115 layer_delegate_.reset();
116 layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
117 layer_->SetColor(color);
118 UpdateLayerBounds(layer_.get());
119 AddLayerToRootLayer(layer_.get());
120 }
121
122 void SystemBackgroundController::UpdateLayerBounds(ui::Layer* layer) {
123 layer->SetBounds(gfx::Rect(root_window_->layer()->bounds().size()));
124 }
125
126 void SystemBackgroundController::AddLayerToRootLayer(ui::Layer* layer) {
127 ui::Layer* root_layer = root_window_->layer();
128 root_layer->Add(layer);
129 root_layer->StackAtBottom(layer);
130 }
131
132 } // namespace internal
133 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/system_background_controller.h ('k') | ash/wm/workspace/colored_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698