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