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

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: fix compile errors, hopefully 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 ~HostContentLayerDelegate() {}
sky 2012/10/26 19:51:33 virtual
Daniel Erat 2012/10/29 15:50:32 Done.
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 DCHECK_NE(new_content, CONTENT_INVALID);
76 if (new_content == content_)
77 return;
78
79 content_ = new_content;
80 switch (new_content) {
81 case CONTENT_COPY_FROM_HOST:
82 CreateTexturedLayerWithHostContent();
83 break;
84 case CONTENT_BLACK:
85 CreateColoredLayer(SK_ColorBLACK);
86 break;
87 #if defined(OS_CHROMEOS)
88 case CONTENT_CHROME_OS_BOOT_COLOR:
89 CreateColoredLayer(kChromeOsBootColor);
90 break;
91 #endif
92 default:
sky 2012/10/26 19:51:33 nit: add CONTENT_INVALID and remove the default so
Daniel Erat 2012/10/29 15:50:32 Done.
93 NOTREACHED() << "Unhandled content type " << new_content;
94 }
95 }
96
97 void SystemBackgroundController::OnRootWindowResized(
98 const aura::RootWindow* root,
99 const gfx::Size& old_size) {
100 DCHECK_EQ(root_window_, root);
101 if (layer_.get())
102 UpdateLayerBounds(layer_.get());
103 }
104
105 void SystemBackgroundController::CreateTexturedLayerWithHostContent() {
106 layer_delegate_.reset(new HostContentLayerDelegate(root_window_));
sky 2012/10/26 19:51:33 Since layer_ references layer_delegate_ can you de
Daniel Erat 2012/10/29 15:50:32 Done (heh, did this at first but figured I was bei
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_delegate_.reset();
115 layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
116 layer_->SetColor(color);
117 UpdateLayerBounds(layer_.get());
118 AddLayerToRootLayer(layer_.get());
119 }
120
121 void SystemBackgroundController::UpdateLayerBounds(ui::Layer* layer) {
122 layer->SetBounds(root_window_->layer()->bounds());
sky 2012/10/26 19:51:33 SetBounds(gfx::Rect(root_window_->layer()->bounds(
Daniel Erat 2012/10/29 15:50:32 Whoops, thanks. Done.
123 }
124
125 void SystemBackgroundController::AddLayerToRootLayer(ui::Layer* layer) {
126 ui::Layer* root_layer = root_window_->layer();
127 root_layer->Add(layer);
128 root_layer->StackAtBottom(layer);
129 }
130
131 } // namespace internal
132 } // 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