diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 03:19:12 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 03:19:12 +0000 |
commit | da7584c4ac68c5828fafdedf055ae86e90bf4a3a (patch) | |
tree | 7131e828da36341a8cb86c0d984e923f4117b976 /ui | |
parent | 44f3e79b95fd6225ab760a0442d4fb23a9bc41b5 (diff) | |
download | chromium_src-da7584c4ac68c5828fafdedf055ae86e90bf4a3a.zip chromium_src-da7584c4ac68c5828fafdedf055ae86e90bf4a3a.tar.gz chromium_src-da7584c4ac68c5828fafdedf055ae86e90bf4a3a.tar.bz2 |
aura: Add Layer::LAYER_SOLID_COLOR to compositor.
This adds a new layer type backed by
WebKit::WebSolidColorLayer. I'm using it for the power
button animation's background (which previously had a
fullscreen texture that it just painted black).
I'm also renaming LAYER_HAS_TEXTURE to LAYER_TEXTURED and
LAYER_HAS_NO_TEXTURE to LAYER_NOT_DRAWN.
BUG=109083
TEST=manual: checked that the power button animation looks the same as before
TBR=sky
Review URL: http://codereview.chromium.org/9289036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119580 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/demo/demo_main.cc | 6 | ||||
-rw-r--r-- | ui/aura/event_filter_unittest.cc | 2 | ||||
-rw-r--r-- | ui/aura/root_window.cc | 2 | ||||
-rw-r--r-- | ui/aura/test/test_windows.cc | 4 | ||||
-rw-r--r-- | ui/aura/window_unittest.cc | 22 | ||||
-rw-r--r-- | ui/gfx/compositor/layer.cc | 31 | ||||
-rw-r--r-- | ui/gfx/compositor/layer.h | 17 | ||||
-rw-r--r-- | ui/gfx/compositor/layer_unittest.cc | 24 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 4 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura_unittest.cc | 4 |
10 files changed, 72 insertions, 44 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index 4b0f0eb..2882032 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -94,7 +94,7 @@ int main(int argc, char** argv) { DemoWindowDelegate window_delegate1(SK_ColorBLUE); aura::Window window1(&window_delegate1); window1.set_id(1); - window1.Init(ui::Layer::LAYER_HAS_TEXTURE); + window1.Init(ui::Layer::LAYER_TEXTURED); window1.SetBounds(gfx::Rect(100, 100, 400, 400)); window1.Show(); window1.SetParent(NULL); @@ -102,7 +102,7 @@ int main(int argc, char** argv) { DemoWindowDelegate window_delegate2(SK_ColorRED); aura::Window window2(&window_delegate2); window2.set_id(2); - window2.Init(ui::Layer::LAYER_HAS_TEXTURE); + window2.Init(ui::Layer::LAYER_TEXTURED); window2.SetBounds(gfx::Rect(200, 200, 350, 350)); window2.Show(); window2.SetParent(NULL); @@ -110,7 +110,7 @@ int main(int argc, char** argv) { DemoWindowDelegate window_delegate3(SK_ColorGREEN); aura::Window window3(&window_delegate3); window3.set_id(3); - window3.Init(ui::Layer::LAYER_HAS_TEXTURE); + window3.Init(ui::Layer::LAYER_TEXTURED); window3.SetBounds(gfx::Rect(10, 10, 50, 50)); window3.Show(); window3.SetParent(&window2); diff --git a/ui/aura/event_filter_unittest.cc b/ui/aura/event_filter_unittest.cc index e0ea127..bd58faa 100644 --- a/ui/aura/event_filter_unittest.cc +++ b/ui/aura/event_filter_unittest.cc @@ -71,7 +71,7 @@ class TestEventFilterWindowDelegate : public TestWindowDelegate { Window* CreateWindow(int id, Window* parent, WindowDelegate* delegate) { Window* window = new Window(delegate ? delegate : new TestWindowDelegate); window->set_id(id); - window->Init(ui::Layer::LAYER_HAS_TEXTURE); + window->Init(ui::Layer::LAYER_TEXTURED); window->SetParent(parent); window->SetBounds(gfx::Rect(0, 0, 100, 100)); window->Show(); diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index 7720699..a7f36a5 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -699,7 +699,7 @@ bool RootWindow::IsFocusedWindow(const Window* window) const { } void RootWindow::Init() { - Window::Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + Window::Init(ui::Layer::LAYER_NOT_DRAWN); SetBounds(gfx::Rect(host_->GetSize())); Show(); compositor()->SetRootLayer(layer()); diff --git a/ui/aura/test/test_windows.cc b/ui/aura/test/test_windows.cc index 10aa994..1c8a540 100644 --- a/ui/aura/test/test_windows.cc +++ b/ui/aura/test/test_windows.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// 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. @@ -47,7 +47,7 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate, Window* window = new Window(delegate); window->set_id(id); window->SetType(type); - window->Init(ui::Layer::LAYER_HAS_TEXTURE); + window->Init(ui::Layer::LAYER_TEXTURED); window->SetBounds(bounds); window->Show(); window->SetParent(parent); diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 2230c26..5bb0bbd 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -227,11 +227,11 @@ TEST_F(WindowTest, GetChildById) { // and not containing NULL or parents. TEST_F(WindowTest, Contains) { Window parent(NULL); - parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + parent.Init(ui::Layer::LAYER_NOT_DRAWN); Window child1(NULL); - child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child1.Init(ui::Layer::LAYER_NOT_DRAWN); Window child2(NULL); - child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child2.Init(ui::Layer::LAYER_NOT_DRAWN); child1.SetParent(&parent); child2.SetParent(&child1); @@ -259,7 +259,7 @@ TEST_F(WindowTest, ConvertPointToWindow) { TEST_F(WindowTest, HitTest) { Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); w1.set_id(1); - w1.Init(ui::Layer::LAYER_HAS_TEXTURE); + w1.Init(ui::Layer::LAYER_TEXTURED); w1.SetBounds(gfx::Rect(10, 10, 50, 50)); w1.Show(); w1.SetParent(NULL); @@ -387,11 +387,11 @@ TEST_F(WindowTest, OrphanedBeforeOnDestroyed) { // Make sure StackChildAtTop moves both the window and layer to the front. TEST_F(WindowTest, StackChildAtTop) { Window parent(NULL); - parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + parent.Init(ui::Layer::LAYER_NOT_DRAWN); Window child1(NULL); - child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child1.Init(ui::Layer::LAYER_NOT_DRAWN); Window child2(NULL); - child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child2.Init(ui::Layer::LAYER_NOT_DRAWN); child1.SetParent(&parent); child2.SetParent(&parent); @@ -414,13 +414,13 @@ TEST_F(WindowTest, StackChildAtTop) { // Various assertions for StackChildAbove. TEST_F(WindowTest, StackChildAbove) { Window parent(NULL); - parent.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + parent.Init(ui::Layer::LAYER_NOT_DRAWN); Window child1(NULL); - child1.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child1.Init(ui::Layer::LAYER_NOT_DRAWN); Window child2(NULL); - child2.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child2.Init(ui::Layer::LAYER_NOT_DRAWN); Window child3(NULL); - child3.Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + child3.Init(ui::Layer::LAYER_NOT_DRAWN); child1.SetParent(&parent); child2.SetParent(&parent); diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc index 2220f82..6d1d6d5 100644 --- a/ui/gfx/compositor/layer.cc +++ b/ui/gfx/compositor/layer.cc @@ -15,6 +15,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatPoint.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFloatRect.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSolidColorLayer.h" #include "ui/base/animation/animation.h" #include "ui/gfx/canvas_skia.h" #include "ui/gfx/compositor/compositor_switches.h" @@ -28,7 +29,7 @@ namespace { const float EPSILON = 1e-3f; -bool IsApproximateMultilpleOf(float value, float base) { +bool IsApproximateMultipleOf(float value, float base) { float remainder = fmod(fabs(value), base); return remainder < EPSILON || base - remainder < EPSILON; } @@ -42,7 +43,7 @@ const ui::Layer* GetRoot(const ui::Layer* layer) { namespace ui { Layer::Layer() - : type_(LAYER_HAS_TEXTURE), + : type_(LAYER_TEXTURED), compositor_(NULL), parent_(NULL), visible_(true), @@ -193,7 +194,7 @@ bool Layer::IsDrawn() const { } bool Layer::ShouldDraw() const { - return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f; + return type_ != LAYER_NOT_DRAWN && GetCombinedOpacity() > 0.0f; } // static @@ -223,6 +224,7 @@ void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) { } void Layer::SetExternalTexture(ui::Texture* texture) { + DCHECK_EQ(type_, LAYER_TEXTURED); layer_updated_externally_ = !!texture; texture_ = texture; if (web_layer_is_accelerated_ != layer_updated_externally_) { @@ -264,7 +266,18 @@ void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { NOTREACHED(); } +void Layer::SetColor(SkColor color) { + DCHECK_EQ(type_, LAYER_SOLID_COLOR); + // WebColor is equivalent to SkColor, per WebColor.h. + web_layer_.to<WebKit::WebSolidColorLayer>().setBackgroundColor( + static_cast<WebKit::WebColor>(color)); + SetFillsBoundsOpaquely(SkColorGetA(color) == 0xFF); +} + void Layer::SchedulePaint(const gfx::Rect& invalid_rect) { + if (type_ == LAYER_SOLID_COLOR) + return; + WebKit::WebFloatRect web_rect( invalid_rect.x(), invalid_rect.y(), @@ -336,7 +349,7 @@ void Layer::GetLayerProperties(const ui::Transform& parent_transform, static_cast<float>(bounds().y())); current_transform.ConcatTransform(parent_transform); - if (fills_bounds_opaquely_ && type_ == LAYER_HAS_TEXTURE) { + if (fills_bounds_opaquely_ && type_ != LAYER_NOT_DRAWN) { LayerProperties properties; properties.layer = this; properties.transform_relative_to_root = current_transform; @@ -442,7 +455,10 @@ float Layer::GetOpacityForAnimation() const { } void Layer::CreateWebLayer() { - web_layer_ = WebKit::WebContentLayer::create(this); + if (type_ == LAYER_SOLID_COLOR) + web_layer_ = WebKit::WebSolidColorLayer::create(); + else + web_layer_ = WebKit::WebContentLayer::create(this); web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f)); web_layer_.setOpaque(true); web_layer_is_accelerated_ = false; @@ -461,9 +477,10 @@ void Layer::RecomputeTransform() { void Layer::RecomputeDrawsContentAndUVRect() { DCHECK(!web_layer_.isNull()); - bool should_draw = type_ == LAYER_HAS_TEXTURE; + bool should_draw = type_ != LAYER_NOT_DRAWN; if (!web_layer_is_accelerated_) { - web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); + if (type_ != LAYER_SOLID_COLOR) + web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw); web_layer_.setBounds(bounds_.size()); } else { DCHECK(texture_); diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h index b1477cb..ab6599e 100644 --- a/ui/gfx/compositor/layer.h +++ b/ui/gfx/compositor/layer.h @@ -13,6 +13,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" +#include "third_party/skia/include/core/SkColor.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebContentLayerClient.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebLayer.h" #include "ui/gfx/rect.h" @@ -42,8 +43,15 @@ class COMPOSITOR_EXPORT Layer : NON_EXPORTED_BASE(public WebKit::WebContentLayerClient) { public: enum LayerType { - LAYER_HAS_NO_TEXTURE = 0, - LAYER_HAS_TEXTURE = 1 + // A layer that has no onscreen representation (note that its children will + // still be drawn, though). + LAYER_NOT_DRAWN = 0, + + // A layer that has a texture. + LAYER_TEXTURED = 1, + + // A layer that's drawn as a single color. + LAYER_SOLID_COLOR = 2, }; Layer(); @@ -163,9 +171,12 @@ class COMPOSITOR_EXPORT Layer : // single-compositor world. void SetExternalTexture(ui::Texture* texture); - // Resets the canvas of the texture. + // Resets the canvas of the texture. May only be called for LAYER_TEXTURED. void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin); + // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. + void SetColor(SkColor color); + // Adds |invalid_rect| to the Layer's pending invalid rect and calls // ScheduleDraw(). void SchedulePaint(const gfx::Rect& invalid_rect); diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc index f5d3ac7..4f4cfe4 100644 --- a/ui/gfx/compositor/layer_unittest.cc +++ b/ui/gfx/compositor/layer_unittest.cc @@ -118,7 +118,7 @@ std::string GetLayerChildrenNames(const Layer& layer) { class ColoredLayer : public Layer, public LayerDelegate { public: explicit ColoredLayer(SkColor color) - : Layer(Layer::LAYER_HAS_TEXTURE), + : Layer(Layer::LAYER_TEXTURED), color_(color) { set_delegate(this); } @@ -171,7 +171,7 @@ class LayerWithRealCompositorTest : public testing::Test { } Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { - Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); + Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN); layer->SetBounds(bounds); return layer; } @@ -381,7 +381,7 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate { } virtual Layer* CreateNoTextureLayer(const gfx::Rect& bounds) { - Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); + Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN); layer->SetBounds(bounds); return layer; } @@ -587,13 +587,13 @@ class LayerWithNullDelegateTest : public LayerWithDelegateTest { } Layer* CreateTextureLayer(const gfx::Rect& bounds) { - Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE); + Layer* layer = CreateLayer(Layer::LAYER_TEXTURED); layer->SetBounds(bounds); return layer; } Layer* CreateNoTextureLayer(const gfx::Rect& bounds) OVERRIDE { - Layer* layer = CreateLayer(Layer::LAYER_HAS_NO_TEXTURE); + Layer* layer = CreateLayer(Layer::LAYER_NOT_DRAWN); layer->SetBounds(bounds); return layer; } @@ -610,9 +610,9 @@ class LayerWithNullDelegateTest : public LayerWithDelegateTest { // Various visibile/drawn assertions. TEST_F(LayerWithNullDelegateTest, Visibility) { - scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); - scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); - scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); + scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED)); + scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED)); + scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED)); l1->Add(l2.get()); l2->Add(l3.get()); @@ -654,10 +654,10 @@ TEST_F(LayerWithNullDelegateTest, Visibility) { // Checks that stacking-related methods behave as advertised. TEST_F(LayerWithNullDelegateTest, Stacking) { - scoped_ptr<Layer> root(new Layer(Layer::LAYER_HAS_NO_TEXTURE)); - scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE)); - scoped_ptr<Layer> l2(new Layer(Layer::LAYER_HAS_TEXTURE)); - scoped_ptr<Layer> l3(new Layer(Layer::LAYER_HAS_TEXTURE)); + scoped_ptr<Layer> root(new Layer(Layer::LAYER_NOT_DRAWN)); + scoped_ptr<Layer> l1(new Layer(Layer::LAYER_TEXTURED)); + scoped_ptr<Layer> l2(new Layer(Layer::LAYER_TEXTURED)); + scoped_ptr<Layer> l3(new Layer(Layer::LAYER_TEXTURED)); l1->set_name("1"); l2->set_name("2"); l3->set_name("3"); diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 08e50cd..b9ff0a2 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -175,8 +175,8 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { window_->SetIntProperty(aura::client::kShowStateKey, params.show_state); window_->SetTransparent(params.transparent); window_->Init(params.create_texture_for_layer ? - ui::Layer::LAYER_HAS_TEXTURE : - ui::Layer::LAYER_HAS_NO_TEXTURE); + ui::Layer::LAYER_TEXTURED : + ui::Layer::LAYER_NOT_DRAWN); if (params.type == Widget::InitParams::TYPE_CONTROL) window_->Show(); diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index 91e02a3..e7ddf31 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -48,7 +48,7 @@ class NativeWidgetAuraTest : public testing::Test { TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { // Make a parent window larger than the host represented by rootwindow. scoped_ptr<aura::Window> parent(new aura::Window(NULL)); - parent->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + parent->Init(ui::Layer::LAYER_NOT_DRAWN); parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); scoped_ptr<Widget> widget(new Widget()); NativeWidgetAura* window = Init(parent.get(), widget.get()); @@ -64,7 +64,7 @@ TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) { // Make a parent window smaller than the host represented by rootwindow. scoped_ptr<aura::Window> parent(new aura::Window(NULL)); - parent->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); + parent->Init(ui::Layer::LAYER_NOT_DRAWN); parent->SetBounds(gfx::Rect(0, 0, 480, 320)); scoped_ptr<Widget> widget(new Widget()); NativeWidgetAura* window = Init(parent.get(), widget.get()); |