summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 22:39:45 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-20 22:39:45 +0000
commitfe9d23f2c945bd2cfa39f5893b5e2f000dd6baf3 (patch)
treeaf22261fc6fab81379e571eb9fa42237f2ab0e2f /ui
parenta13da216e3642f8b35e1a95e09974bf144ff3f17 (diff)
downloadchromium_src-fe9d23f2c945bd2cfa39f5893b5e2f000dd6baf3.zip
chromium_src-fe9d23f2c945bd2cfa39f5893b5e2f000dd6baf3.tar.gz
chromium_src-fe9d23f2c945bd2cfa39f5893b5e2f000dd6baf3.tar.bz2
Use WebKit compositor in ui::Layer
BUG=99524 TEST=compositor_unittests Review URL: http://codereview.chromium.org/8222028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106606 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/test/test_suite.cc3
-rw-r--r--ui/aura_shell/aura_shell.gyp2
-rw-r--r--ui/aura_shell/examples/aura_shell_main.cc4
-rw-r--r--ui/aura_shell/test_suite.cc3
-rw-r--r--ui/gfx/compositor/DEPS7
-rw-r--r--ui/gfx/compositor/compositor.cc15
-rw-r--r--ui/gfx/compositor/compositor.gyp37
-rw-r--r--ui/gfx/compositor/compositor.h6
-rw-r--r--ui/gfx/compositor/compositor_cc.cc125
-rw-r--r--ui/gfx/compositor/compositor_cc.h82
-rw-r--r--ui/gfx/compositor/compositor_test_support.cc35
-rw-r--r--ui/gfx/compositor/compositor_test_support.h19
-rw-r--r--ui/gfx/compositor/layer.cc114
-rw-r--r--ui/gfx/compositor/layer.h29
-rw-r--r--ui/gfx/compositor/layer_unittest.cc104
-rw-r--r--ui/gfx/compositor/test_compositor.cc6
-rw-r--r--ui/gfx/compositor/test_compositor.h1
-rw-r--r--ui/gfx/compositor/test_compositor_host_linux.cc3
-rw-r--r--ui/gfx/compositor/test_suite.cc15
-rw-r--r--ui/gfx/compositor/test_suite.h11
21 files changed, 571 insertions, 51 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 828227b..e5053f3 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -83,6 +83,7 @@
'../../skia/skia.gyp:skia',
'../../testing/gtest.gyp:gtest',
'../gfx/compositor/compositor.gyp:compositor',
+ '../gfx/compositor/compositor.gyp:compositor_test_support',
'../gfx/gl/gl.gyp:gl',
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
diff --git a/ui/aura/test/test_suite.cc b/ui/aura/test/test_suite.cc
index b1b371b..11e0f3b 100644
--- a/ui/aura/test/test_suite.cc
+++ b/ui/aura/test/test_suite.cc
@@ -9,6 +9,7 @@
#include "build/build_config.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_test_support.h"
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/gl/gl_implementation.h"
@@ -27,9 +28,11 @@ void AuraTestSuite::Initialize() {
// Force unittests to run using en-US so if we test against string
// output, it'll pass regardless of the system language.
ui::ResourceBundle::InitSharedInstance("en-US");
+ ui::CompositorTestSupport::Initialize();
}
void AuraTestSuite::Shutdown() {
+ ui::CompositorTestSupport::Terminate();
ui::ResourceBundle::CleanupSharedInstance();
base::TestSuite::Shutdown();
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp
index 637534b..8fef1ec 100644
--- a/ui/aura_shell/aura_shell.gyp
+++ b/ui/aura_shell/aura_shell.gyp
@@ -73,6 +73,7 @@
'../../third_party/icu/icu.gyp:icuuc',
'../../views/views.gyp:views',
'../gfx/compositor/compositor.gyp:compositor',
+ '../gfx/compositor/compositor.gyp:compositor_test_support',
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
'../ui.gyp:ui_resources',
@@ -110,6 +111,7 @@
'../../views/views.gyp:views',
'../aura/aura.gyp:aura',
'../gfx/compositor/compositor.gyp:compositor',
+ '../gfx/compositor/compositor.gyp:compositor_test_support',
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
'../ui.gyp:ui_resources',
diff --git a/ui/aura_shell/examples/aura_shell_main.cc b/ui/aura_shell/examples/aura_shell_main.cc
index 486554b..414bcdd 100644
--- a/ui/aura_shell/examples/aura_shell_main.cc
+++ b/ui/aura_shell/examples/aura_shell_main.cc
@@ -15,6 +15,7 @@
#include "ui/aura_shell/shell_factory.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_test_support.h"
namespace {
@@ -69,6 +70,7 @@ int main(int argc, char** argv) {
// Create the message-loop here before creating the desktop.
MessageLoop message_loop(MessageLoop::TYPE_UI);
+ ui::CompositorTestSupport::Initialize();
aura_shell::Shell::GetInstance()->SetDelegate(new ShellDelegateImpl);;
@@ -78,6 +80,8 @@ int main(int argc, char** argv) {
delete aura::Desktop::GetInstance();
+ ui::CompositorTestSupport::Terminate();
+
return 0;
}
diff --git a/ui/aura_shell/test_suite.cc b/ui/aura_shell/test_suite.cc
index 2652a24..5ccb18f 100644
--- a/ui/aura_shell/test_suite.cc
+++ b/ui/aura_shell/test_suite.cc
@@ -9,6 +9,7 @@
#include "build/build_config.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_test_support.h"
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/gl/gl_implementation.h"
@@ -27,9 +28,11 @@ void AuraShellTestSuite::Initialize() {
// Force unittests to run using en-US so if we test against string
// output, it'll pass regardless of the system language.
ui::ResourceBundle::InitSharedInstance("en-US");
+ ui::CompositorTestSupport::Initialize();
}
void AuraShellTestSuite::Shutdown() {
+ ui::CompositorTestSupport::Terminate();
ui::ResourceBundle::CleanupSharedInstance();
base::TestSuite::Shutdown();
diff --git a/ui/gfx/compositor/DEPS b/ui/gfx/compositor/DEPS
new file mode 100644
index 0000000..956b453
--- /dev/null
+++ b/ui/gfx/compositor/DEPS
@@ -0,0 +1,7 @@
+# NOTE(piman): This is not an invitation to add WebKit stuff in general into
+# the compositor/ui. These lines will disappear once we can extract the Chromium
+# Compositor out of WebKit.
+include_rules = [
+ "+webkit/glue",
+ "+webkit/gpu",
+]
diff --git a/ui/gfx/compositor/compositor.cc b/ui/gfx/compositor/compositor.cc
index 6f7e5db..87aa06e 100644
--- a/ui/gfx/compositor/compositor.cc
+++ b/ui/gfx/compositor/compositor.cc
@@ -25,10 +25,15 @@ Compositor::Compositor(CompositorDelegate* delegate, const gfx::Size& size)
Compositor::~Compositor() {
}
+void Compositor::ScheduleDraw() {
+ delegate_->ScheduleDraw();
+}
+
void Compositor::SetRootLayer(Layer* root_layer) {
root_layer_ = root_layer;
if (!root_layer_->GetCompositor())
root_layer_->SetCompositor(this);
+ OnRootLayerChanged();
}
void Compositor::Draw(bool force_clear) {
@@ -36,7 +41,7 @@ void Compositor::Draw(bool force_clear) {
return;
NotifyStart(force_clear);
- root_layer_->DrawTree();
+ DrawTree();
NotifyEnd();
}
@@ -52,6 +57,14 @@ bool Compositor::HasObserver(CompositorObserver* observer) {
return observer_list_.HasObserver(observer);
}
+void Compositor::OnRootLayerChanged() {
+ ScheduleDraw();
+}
+
+void Compositor::DrawTree() {
+ root_layer_->DrawTree();
+}
+
void Compositor::NotifyStart(bool clear) {
OnNotifyStart(clear);
}
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index d5e38b7..0e94f3e 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -29,6 +29,7 @@
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/ui/gfx/gl/gl.gyp:gl',
'<(DEPTH)/ui/ui.gyp:ui',
+ '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
],
'defines': [
'COMPOSITOR_IMPLEMENTATION',
@@ -39,6 +40,8 @@
'compositor_export.h',
'compositor_gl.cc',
'compositor_gl.h',
+ 'compositor_cc.cc',
+ 'compositor_cc.h',
'compositor_observer.h',
'compositor_stub.cc',
'compositor_win.cc',
@@ -77,6 +80,39 @@
['exclude', '^compositor_win.cc'],
],
}],
+ ['use_webkit_compositor == 1', {
+ 'sources/': [
+ ['exclude', '^compositor_(gl|win|stub).(h|cc)$'],
+ ],
+ 'dependencies': [
+ '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_gpu',
+ ],
+ }, {
+ 'sources!': [
+ 'compositor_cc.cc',
+ 'compositor_cc.h',
+ ],
+ }
+ ],
+ ],
+ },
+ {
+ 'target_name': 'compositor_test_support',
+ 'type': '<(component)',
+ 'dependencies': [
+ '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_support',
+ '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
+ ],
+ 'sources': [
+ 'compositor_test_support.cc',
+ 'compositor_test_support.h',
+ ],
+ 'conditions': [
+ ['use_webkit_compositor == 1', {
+ 'dependencies': [
+ '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_support',
+ ],
+ }],
],
},
{
@@ -92,6 +128,7 @@
'<(DEPTH)/ui/ui.gyp:ui',
'<(DEPTH)/ui/ui.gyp:ui_resources',
'compositor',
+ 'compositor_test_support',
],
'sources': [
'layer_unittest.cc',
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 1251b6a..574fed8 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -107,9 +107,7 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
virtual void Blur(const gfx::Rect& bounds) = 0;
// Schedules a redraw of the layer tree associated with this compositor.
- void ScheduleDraw() {
- delegate_->ScheduleDraw();
- }
+ virtual void ScheduleDraw();
// Sets the root of the layer tree drawn by this Compositor.
// The Compositor does not own the root layer.
@@ -150,6 +148,8 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
virtual void OnNotifyEnd() = 0;
virtual void OnWidgetSizeChanged() = 0;
+ virtual void OnRootLayerChanged();
+ virtual void DrawTree();
CompositorDelegate* delegate() { return delegate_; }
diff --git a/ui/gfx/compositor/compositor_cc.cc b/ui/gfx/compositor/compositor_cc.cc
new file mode 100644
index 0000000..1aaddab
--- /dev/null
+++ b/ui/gfx/compositor/compositor_cc.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2011 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 "ui/gfx/compositor/compositor_cc.h"
+
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
+#include "ui/gfx/compositor/layer.h"
+#include "webkit/glue/webthread_impl.h"
+#include "webkit/gpu/webgraphicscontext3d_in_process_impl.h"
+
+namespace {
+webkit_glue::WebThreadImpl* g_compositor_thread = NULL;
+} // anonymous namespace
+
+namespace ui {
+
+TextureCC::TextureCC() {
+}
+
+void TextureCC::SetCanvas(const SkCanvas& canvas,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) {
+}
+
+void TextureCC::Draw(const ui::TextureDrawParams& params,
+ const gfx::Rect& clip_bounds_in_texture) {
+}
+
+CompositorCC::CompositorCC(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
+ const gfx::Size& size)
+ : Compositor(delegate, size),
+ widget_(widget),
+ root_web_layer_(WebKit::WebLayer::create(this)) {
+ WebKit::WebLayerTreeView::Settings settings;
+ settings.enableCompositorThread = !!g_compositor_thread;
+ host_ = WebKit::WebLayerTreeView::create(this, root_web_layer_, settings);
+ root_web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
+ OnWidgetSizeChanged();
+}
+
+CompositorCC::~CompositorCC() {
+}
+
+void CompositorCC::InitializeThread() {
+ g_compositor_thread = new webkit_glue::WebThreadImpl("Browser Compositor");
+ WebKit::WebCompositor::setThread(g_compositor_thread);
+}
+
+void CompositorCC::TerminateThread() {
+ DCHECK(g_compositor_thread);
+ delete g_compositor_thread;
+ g_compositor_thread = NULL;
+}
+
+Texture* CompositorCC::CreateTexture() {
+ return new TextureCC();
+}
+
+void CompositorCC::Blur(const gfx::Rect& bounds) {
+ NOTIMPLEMENTED();
+}
+
+void CompositorCC::ScheduleDraw() {
+ if (g_compositor_thread)
+ host_.composite();
+ else
+ Compositor::ScheduleDraw();
+}
+
+void CompositorCC::OnNotifyStart(bool clear) {
+}
+
+void CompositorCC::OnNotifyEnd() {
+}
+
+void CompositorCC::OnWidgetSizeChanged() {
+ host_.setViewportSize(size());
+ root_web_layer_.setBounds(size());
+}
+
+void CompositorCC::OnRootLayerChanged() {
+ root_web_layer_.removeAllChildren();
+ root_web_layer_.addChild(root_layer()->web_layer());
+}
+
+void CompositorCC::DrawTree() {
+ host_.composite();
+}
+
+void CompositorCC::animateAndLayout(double frameBeginTime) {
+}
+
+void CompositorCC::applyScrollDelta(const WebKit::WebSize&) {
+}
+
+WebKit::WebGraphicsContext3D* CompositorCC::createContext3D() {
+ WebKit::WebGraphicsContext3D* context =
+ new webkit::gpu::WebGraphicsContext3DInProcessImpl(widget_, NULL);
+ WebKit::WebGraphicsContext3D::Attributes attrs;
+ context->initialize(attrs, 0, true);
+ return context;
+}
+
+void CompositorCC::didRebindGraphicsContext(bool success) {
+}
+
+void CompositorCC::scheduleComposite() {
+ ScheduleDraw();
+}
+
+void CompositorCC::notifyNeedsComposite() {
+ ScheduleDraw();
+}
+
+Compositor* Compositor::Create(CompositorDelegate* owner,
+ gfx::AcceleratedWidget widget,
+ const gfx::Size& size) {
+ return new CompositorCC(owner, widget, size);
+}
+
+} // namespace ui
diff --git a/ui/gfx/compositor/compositor_cc.h b/ui/gfx/compositor/compositor_cc.h
new file mode 100644
index 0000000..72ea136
--- /dev/null
+++ b/ui/gfx/compositor/compositor_cc.h
@@ -0,0 +1,82 @@
+// Copyright (c) 2011 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.
+
+#ifndef UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_
+#define UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "ui/gfx/compositor/compositor.h"
+#include "ui/gfx/size.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerTreeView.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerTreeViewClient.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace ui {
+
+class COMPOSITOR_EXPORT TextureCC : public Texture {
+ public:
+ TextureCC();
+
+ // Texture implementation.
+ virtual void SetCanvas(const SkCanvas& canvas,
+ const gfx::Point& origin,
+ const gfx::Size& overall_size) OVERRIDE;
+
+ virtual void Draw(const ui::TextureDrawParams& params,
+ const gfx::Rect& clip_bounds_in_texture) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TextureCC);
+};
+
+class COMPOSITOR_EXPORT CompositorCC : public Compositor,
+ public WebKit::WebLayerTreeViewClient,
+ public WebKit::WebLayerClient {
+ public:
+ CompositorCC(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
+ const gfx::Size& size);
+ virtual ~CompositorCC();
+
+ static void InitializeThread();
+ static void TerminateThread();
+
+ protected:
+ // Compositor implementation.
+ virtual Texture* CreateTexture() OVERRIDE;
+ virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
+ virtual void ScheduleDraw() OVERRIDE;
+ virtual void OnNotifyStart(bool clear) OVERRIDE;
+ virtual void OnNotifyEnd() OVERRIDE;
+ virtual void OnWidgetSizeChanged() OVERRIDE;
+ virtual void OnRootLayerChanged() OVERRIDE;
+ virtual void DrawTree() OVERRIDE;
+
+ // WebLayerTreeViewClient implementation.
+ virtual void animateAndLayout(double frameBeginTime) OVERRIDE;
+ virtual void applyScrollDelta(const WebKit::WebSize&) OVERRIDE;
+ virtual WebKit::WebGraphicsContext3D* createContext3D() OVERRIDE;
+ virtual void didRebindGraphicsContext(bool success) OVERRIDE;
+ virtual void scheduleComposite() OVERRIDE;
+
+ // WebLayerClient implementation.
+ virtual void notifyNeedsComposite() OVERRIDE;
+
+ private:
+ gfx::AcceleratedWidget widget_;
+ WebKit::WebLayer root_web_layer_;
+ WebKit::WebLayerTreeView host_;
+
+ DISALLOW_COPY_AND_ASSIGN(CompositorCC);
+};
+
+} // namespace ui
+
+#endif // UI_GFX_COMPOSITOR_COMPOSITOR_CC_H_
diff --git a/ui/gfx/compositor/compositor_test_support.cc b/ui/gfx/compositor/compositor_test_support.cc
new file mode 100644
index 0000000..e72bd0c
--- /dev/null
+++ b/ui/gfx/compositor/compositor_test_support.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2011 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 "ui/gfx/compositor/compositor_test_support.h"
+
+#if defined(USE_WEBKIT_COMPOSITOR)
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
+#include "webkit/glue/webkitplatformsupport_impl.h"
+#endif
+
+namespace ui {
+
+#if defined(USE_WEBKIT_COMPOSITOR)
+static webkit_glue::WebKitPlatformSupportImpl* g_webkit_support;
+#endif
+
+void CompositorTestSupport::Initialize() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ DCHECK(!g_webkit_support);
+ g_webkit_support = new webkit_glue::WebKitPlatformSupportImpl;
+ WebKit::initialize(g_webkit_support);
+#endif
+}
+
+void CompositorTestSupport::Terminate() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ DCHECK(g_webkit_support);
+ WebKit::shutdown();
+ delete g_webkit_support;
+ g_webkit_support = NULL;
+#endif
+}
+
+} // namespace ui
diff --git a/ui/gfx/compositor/compositor_test_support.h b/ui/gfx/compositor/compositor_test_support.h
new file mode 100644
index 0000000..de520a0
--- /dev/null
+++ b/ui/gfx/compositor/compositor_test_support.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2011 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.
+
+#ifndef UI_GFX_COMPOSITOR_TEST_SUPPORT_H_
+#define UI_GFX_COMPOSITOR_TEST_SUPPORT_H_
+#pragma once
+
+namespace ui {
+
+class CompositorTestSupport {
+ public:
+ static void Initialize();
+ static void Terminate();
+};
+
+} // namespace ui
+
+#endif // UI_GFX_COMPOSITOR_TEST_SUPPORT_H_
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index c094b1e..1a42754 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -8,6 +8,9 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatPoint.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebFloatRect.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
#include "ui/base/animation/animation.h"
#include "ui/gfx/compositor/layer_animator.h"
#include "ui/gfx/canvas_skia.h"
@@ -36,6 +39,9 @@ Layer::Layer(Compositor* compositor)
layer_updated_externally_(false),
opacity_(1.0f),
delegate_(NULL) {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ CreateWebLayer();
+#endif
}
Layer::Layer(Compositor* compositor, LayerType type)
@@ -47,6 +53,9 @@ Layer::Layer(Compositor* compositor, LayerType type)
layer_updated_externally_(false),
opacity_(1.0f),
delegate_(NULL) {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ CreateWebLayer();
+#endif
}
Layer::~Layer() {
@@ -54,6 +63,9 @@ Layer::~Layer() {
parent_->Remove(this);
for (size_t i = 0; i < children_.size(); ++i)
children_[i]->parent_ = NULL;
+#if defined(USE_WEBKIT_COMPOSITOR)
+ web_layer_.removeFromParent();
+#endif
}
Compositor* Layer::GetCompositor() {
@@ -74,6 +86,9 @@ void Layer::Add(Layer* child) {
child->parent_->Remove(child);
child->parent_ = this;
children_.push_back(child);
+#if defined(USE_WEBKIT_COMPOSITOR)
+ web_layer_.addChild(child->web_layer_);
+#endif
RecomputeHole();
}
@@ -84,6 +99,9 @@ void Layer::Remove(Layer* child) {
DCHECK(i != children_.end());
children_.erase(i);
child->parent_ = NULL;
+#if defined(USE_WEBKIT_COMPOSITOR)
+ child->web_layer_.removeFromParent();
+#endif
RecomputeHole();
@@ -96,6 +114,10 @@ void Layer::MoveToFront(Layer* child) {
DCHECK(i != children_.end());
children_.erase(i);
children_.push_back(child);
+#if defined(USE_WEBKIT_COMPOSITOR)
+ child->web_layer_.removeFromParent();
+ web_layer_.addChild(child->web_layer_);
+#endif
}
bool Layer::Contains(const Layer* other) const {
@@ -165,6 +187,10 @@ void Layer::SetVisible(bool visible) {
DropTextures();
if (parent_)
parent_->RecomputeHole();
+#if defined(USE_WEBKIT_COMPOSITOR)
+ // TODO(piman): Expose a visibility flag on WebLayer.
+ web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
+#endif
}
bool Layer::IsDrawn() const {
@@ -174,7 +200,7 @@ bool Layer::IsDrawn() const {
return layer == NULL;
}
-bool Layer::ShouldDraw() {
+bool Layer::ShouldDraw() const {
return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f &&
!hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size()));
}
@@ -206,6 +232,9 @@ void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
if (parent())
parent()->RecomputeHole();
+#if defined(USE_WEBKIT_COMPOSITOR)
+ web_layer_.setOpaque(fills_bounds_opaquely);
+#endif
}
void Layer::SetExternalTexture(ui::Texture* texture) {
@@ -215,6 +244,9 @@ void Layer::SetExternalTexture(ui::Texture* texture) {
}
void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ NOTREACHED();
+#else
DCHECK_EQ(type_, LAYER_HAS_TEXTURE);
if (!texture_.get())
@@ -222,19 +254,32 @@ void Layer::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
texture_->SetCanvas(canvas, origin, bounds_.size());
invalid_rect_ = gfx::Rect();
+#endif
}
void Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ WebKit::WebFloatRect web_rect(invalid_rect.x(),
+ invalid_rect.y(),
+ invalid_rect.width(),
+ invalid_rect.height());
+ web_layer_.invalidateRect(web_rect);
+#else
invalid_rect_ = invalid_rect_.Union(invalid_rect);
ScheduleDraw();
+#endif
}
void Layer::ScheduleDraw() {
- if (GetCompositor())
- GetCompositor()->ScheduleDraw();
+ Compositor* compositor = GetCompositor();
+ if (compositor)
+ compositor->ScheduleDraw();
}
void Layer::Draw() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ NOTREACHED();
+#else
DCHECK(GetCompositor());
if (!ShouldDraw())
return;
@@ -274,15 +319,38 @@ void Layer::Draw() {
if (!regions_to_draw[i].IsEmpty())
texture_->Draw(texture_draw_params, regions_to_draw[i]);
}
+#endif
}
void Layer::DrawTree() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ NOTREACHED();
+#else
if (!visible_)
return;
Draw();
for (size_t i = 0; i < children_.size(); ++i)
children_.at(i)->DrawTree();
+#endif
+}
+
+void Layer::notifyNeedsComposite() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ ScheduleDraw();
+#else
+ NOTREACHED();
+#endif
+}
+
+void Layer::paintContents(WebKit::WebCanvas* web_canvas,
+ const WebKit::WebRect& clip) {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ gfx::CanvasSkia canvas(web_canvas);
+ delegate_->OnPaintLayer(&canvas);
+#else
+ NOTREACHED();
+#endif
}
float Layer::GetCombinedOpacity() const {
@@ -296,6 +364,9 @@ float Layer::GetCombinedOpacity() const {
}
void Layer::UpdateLayerCanvas() {
+#if defined(USE_WEBKIT_COMPOSITOR)
+ NOTREACHED();
+#else
// If we have no delegate, that means that whoever constructed the Layer is
// setting its canvas directly with SetCanvas().
if (!delegate_ || layer_updated_externally_)
@@ -312,6 +383,7 @@ void Layer::UpdateLayerCanvas() {
canvas->TranslateInt(-draw_rect.x(), -draw_rect.y());
delegate_->OnPaintLayer(canvas.get());
SetCanvas(*canvas->GetSkCanvas(), draw_rect.origin());
+#endif
}
void Layer::RecomputeHole() {
@@ -357,6 +429,10 @@ void Layer::RecomputeHole() {
// Free up texture memory if the hole fills bounds of layer.
if (!ShouldDraw() && !layer_updated_externally_)
texture_ = NULL;
+
+#if defined(USE_WEBKIT_COMPOSITOR)
+ RecomputeDrawsContent();
+#endif
}
bool Layer::IsCompletelyOpaque() const {
@@ -466,6 +542,11 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
if (parent())
parent()->RecomputeHole();
+#if defined(USE_WEBKIT_COMPOSITOR)
+ web_layer_.setBounds(bounds.size());
+ RecomputeTransform();
+ RecomputeDrawsContent();
+#endif
}
void Layer::SetTransformImmediately(const ui::Transform& transform) {
@@ -473,6 +554,9 @@ void Layer::SetTransformImmediately(const ui::Transform& transform) {
if (parent())
parent()->RecomputeHole();
+#if defined(USE_WEBKIT_COMPOSITOR)
+ RecomputeTransform();
+#endif
}
void Layer::SetOpacityImmediately(float opacity) {
@@ -495,6 +579,11 @@ void Layer::SetOpacityImmediately(float opacity) {
to_process.push(current->children_.at(i));
}
}
+#if defined(USE_WEBKIT_COMPOSITOR)
+ if (visible_)
+ web_layer_.setOpacity(opacity);
+ RecomputeDrawsContent();
+#endif
}
void Layer::SetBoundsFromAnimator(const gfx::Rect& bounds) {
@@ -509,4 +598,23 @@ void Layer::SetOpacityFromAnimator(float opacity) {
SetOpacityImmediately(opacity);
}
+#if defined(USE_WEBKIT_COMPOSITOR)
+void Layer::CreateWebLayer() {
+ web_layer_ = WebKit::WebContentLayer::create(this, this);
+ web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
+ web_layer_.setOpaque(true);
+ RecomputeDrawsContent();
+}
+
+void Layer::RecomputeTransform() {
+ ui::Transform transform = transform_;
+ transform.ConcatTranslate(bounds_.x(), bounds_.y());
+ web_layer_.setTransform(transform.matrix());
+}
+
+void Layer::RecomputeDrawsContent() {
+ web_layer_.setDrawsContent(ShouldDraw());
+}
+#endif
+
} // namespace ui
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 86ae4fd..9e3a2d0 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -12,6 +12,9 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
#include "ui/gfx/compositor/compositor.h"
@@ -35,7 +38,9 @@ class Texture;
// NOTE: unlike Views, each Layer does *not* own its children views. If you
// delete a Layer and it has children, the parent of each child layer is set to
// NULL, but the children are not deleted.
-class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
+class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate,
+ public WebKit::WebLayerClient,
+ public WebKit::WebContentLayerClient {
public:
enum LayerType {
LAYER_HAS_NO_TEXTURE = 0,
@@ -117,7 +122,7 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
// Returns true if this layer can have a texture (has_texture_ is true)
// and is not completely obscured by a child.
- bool ShouldDraw();
+ bool ShouldDraw() const;
// Converts a point from the coordinates of |source| to the coordinates of
// |target|. Necessarily, |source| and |target| must inhabit the same Layer
@@ -165,6 +170,16 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
// (e.g. the GPU process on TOUCH_UI).
bool layer_updated_externally() const { return layer_updated_externally_; }
+ // WebLayerClient
+ virtual void notifyNeedsComposite();
+
+ // WebContentLayerClient
+ virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip);
+
+#if defined(USE_WEBKIT_COMPOSITOR)
+ WebKit::WebContentLayer web_layer() { return web_layer_; }
+#endif
+
private:
// TODO(vollick): Eventually, if a non-leaf node has an opacity of less than
// 1.0, we'll render to a separate texture, and then apply the alpha.
@@ -239,6 +254,12 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE;
virtual void SetOpacityFromAnimator(float opacity) OVERRIDE;
+#if defined(USE_WEBKIT_COMPOSITOR)
+ void CreateWebLayer();
+ void RecomputeTransform();
+ void RecomputeDrawsContent();
+#endif
+
const LayerType type_;
Compositor* compositor_;
@@ -271,6 +292,10 @@ class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate {
scoped_ptr<LayerAnimator> animator_;
+#if defined(USE_WEBKIT_COMPOSITOR)
+ WebKit::WebContentLayer web_layer_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(Layer);
};
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index 6c5efb7..46e9851 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -25,6 +25,26 @@ namespace {
// - LayerWithRealCompositorTest when a real compositor is required for testing.
// - Slow because they bring up a window and run the real compositor. This
// is typically not what you want.
+
+class ColoredLayer : public Layer, public LayerDelegate {
+ public:
+ ColoredLayer(Compositor* compositor, SkColor color)
+ : Layer(compositor, Layer::LAYER_HAS_TEXTURE),
+ color_(color) {
+ set_delegate(this);
+ }
+
+ virtual ~ColoredLayer() { }
+
+ // Overridden from LayerDelegate:
+ virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE {
+ canvas->GetSkCanvas()->drawColor(color_);
+ }
+
+ private:
+ SkColor color_;
+};
+
class LayerWithRealCompositorTest : public testing::Test {
public:
LayerWithRealCompositorTest() {}
@@ -49,9 +69,8 @@ class LayerWithRealCompositorTest : public testing::Test {
}
Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
- Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
+ Layer* layer = new ColoredLayer(GetCompositor(), color);
layer->SetBounds(bounds);
- PaintColorToLayer(layer, color);
return layer;
}
@@ -67,13 +86,6 @@ class LayerWithRealCompositorTest : public testing::Test {
false);
}
- void PaintColorToLayer(Layer* layer, SkColor color) {
- scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
- canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
- layer->bounds().height());
- layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
- }
-
void DrawTree(Layer* root) {
GetCompositor()->SetRootLayer(root);
GetCompositor()->Draw(false);
@@ -90,7 +102,6 @@ class LayerWithRealCompositorTest : public testing::Test {
}
private:
- MessageLoopForUI message_loop_;
scoped_ptr<TestCompositorHost> window_;
DISALLOW_COPY_AND_ASSIGN(LayerWithRealCompositorTest);
@@ -99,7 +110,7 @@ class LayerWithRealCompositorTest : public testing::Test {
// LayerDelegate that paints colors to the layer.
class TestLayerDelegate : public LayerDelegate {
public:
- explicit TestLayerDelegate(Layer* owner) : owner_(owner), color_index_(0) {}
+ explicit TestLayerDelegate() : color_index_(0) {}
virtual ~TestLayerDelegate() {}
void AddColor(SkColor color) {
@@ -120,7 +131,6 @@ class TestLayerDelegate : public LayerDelegate {
}
private:
- Layer* owner_;
std::vector<SkColor> colors_;
int color_index_;
gfx::Size paint_size_;
@@ -170,11 +180,17 @@ class NullLayerDelegate : public LayerDelegate {
#if defined(OS_WIN)
// These are disabled on windows as they don't run correctly on the buildbot.
// Reenable once we move to the real compositor.
+#define MAYBE_Delegate DISABLED_Delegate
#define MAYBE_Draw DISABLED_Draw
+#define MAYBE_DrawTree DISABLED_DrawTree
#define MAYBE_Hierarchy DISABLED_Hierarchy
+#define MAYBE_HierarchyNoTexture DISABLED_HierarchyNoTexture
#else
+#define MAYBE_Delegate Delegate
#define MAYBE_Draw Draw
+#define MAYBE_DrawTree DrawTree
#define MAYBE_Hierarchy Hierarchy
+#define MAYBE_HierarchyNoTexture HierarchyNoTexture
#endif
TEST_F(LayerWithRealCompositorTest, MAYBE_Draw) {
@@ -226,9 +242,8 @@ class LayerWithDelegateTest : public testing::Test {
}
Layer* CreateColorLayer(SkColor color, const gfx::Rect& bounds) {
- Layer* layer = CreateLayer(Layer::LAYER_HAS_TEXTURE);
+ Layer* layer = new ColoredLayer(compositor(), color);
layer->SetBounds(bounds);
- PaintColorToLayer(layer, color);
return layer;
}
@@ -244,13 +259,6 @@ class LayerWithDelegateTest : public testing::Test {
false);
}
- void PaintColorToLayer(Layer* layer, SkColor color) {
- scoped_ptr<gfx::Canvas> canvas(CreateCanvasForLayer(layer));
- canvas->FillRectInt(color, 0, 0, layer->bounds().width(),
- layer->bounds().height());
- layer->SetCanvas(*canvas->GetSkCanvas(), layer->bounds().origin());
- }
-
void DrawTree(Layer* root) {
compositor()->SetRootLayer(root);
compositor()->Draw(false);
@@ -264,7 +272,7 @@ class LayerWithDelegateTest : public testing::Test {
// Invokes DrawTree on the compositor.
void Draw() {
- compositor_->root_layer()->DrawTree();
+ compositor_->Draw(false);
}
private:
@@ -319,34 +327,35 @@ TEST_F(LayerWithDelegateTest, ConvertPointToLayer_Medium) {
EXPECT_EQ(point2_in_l3_coords, point2_in_l1_coords);
}
-TEST_F(LayerWithDelegateTest, Delegate) {
+TEST_F(LayerWithRealCompositorTest, MAYBE_Delegate) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorBLACK,
gfx::Rect(20, 20, 400, 400)));
- TestLayerDelegate delegate(l1.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
+ TestLayerDelegate delegate;
l1->set_delegate(&delegate);
delegate.AddColor(SK_ColorWHITE);
delegate.AddColor(SK_ColorYELLOW);
delegate.AddColor(SK_ColorGREEN);
- compositor()->SetRootLayer(l1.get());
-
l1->SchedulePaint(gfx::Rect(0, 0, 400, 400));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 1);
EXPECT_EQ(delegate.paint_size(), l1->bounds().size());
l1->SchedulePaint(gfx::Rect(10, 10, 200, 200));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 2);
EXPECT_EQ(delegate.paint_size(), gfx::Size(200, 200));
l1->SchedulePaint(gfx::Rect(5, 5, 50, 50));
- Draw();
+ RunPendingMessages();
EXPECT_EQ(delegate.color_index(), 0);
EXPECT_EQ(delegate.paint_size(), gfx::Size(50, 50));
}
-TEST_F(LayerWithDelegateTest, DrawTree) {
+TEST_F(LayerWithRealCompositorTest, MAYBE_DrawTree) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 400, 400)));
scoped_ptr<Layer> l2(CreateColorLayer(SK_ColorBLUE,
@@ -356,6 +365,9 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
l1->Add(l2.get());
l2->Add(l3.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
DrawTreeLayerDelegate d1;
l1->set_delegate(&d1);
DrawTreeLayerDelegate d2;
@@ -363,10 +375,8 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- compositor()->SetRootLayer(l1.get());
-
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- Draw();
+ RunPendingMessages();
EXPECT_FALSE(d1.painted());
EXPECT_TRUE(d2.painted());
EXPECT_FALSE(d3.painted());
@@ -379,7 +389,7 @@ TEST_F(LayerWithDelegateTest, DrawTree) {
// | +-- L3 - yellow
// +-- L4 - magenta
//
-TEST_F(LayerWithDelegateTest, HierarchyNoTexture) {
+TEST_F(LayerWithRealCompositorTest, MAYBE_HierarchyNoTexture) {
scoped_ptr<Layer> l1(CreateColorLayer(SK_ColorRED,
gfx::Rect(20, 20, 400, 400)));
scoped_ptr<Layer> l2(CreateNoTextureLayer(gfx::Rect(10, 10, 350, 350)));
@@ -392,16 +402,17 @@ TEST_F(LayerWithDelegateTest, HierarchyNoTexture) {
l1->Add(l4.get());
l2->Add(l3.get());
+ GetCompositor()->SetRootLayer(l1.get());
+ RunPendingMessages();
+
DrawTreeLayerDelegate d2;
l2->set_delegate(&d2);
DrawTreeLayerDelegate d3;
l3->set_delegate(&d3);
- compositor()->SetRootLayer(l1.get());
-
l2->SchedulePaint(gfx::Rect(5, 5, 5, 5));
l3->SchedulePaint(gfx::Rect(5, 5, 5, 5));
- Draw();
+ RunPendingMessages();
// |d2| should not have received a paint notification since it has no texture.
EXPECT_FALSE(d2.painted());
@@ -466,9 +477,18 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureSetFillsBoundsOpaquely) {
EXPECT_TRUE(parent->texture() == NULL);
}
+// With the webkit compositor, we don't explicitly textures for layers, making
+// tests that check that we do fail.
+#if defined(USE_WEBKIT_COMPOSITOR)
+#define WEBKIT_COMPOSITOR_FAILS(X) FAILS_ ## X
+#else
+#define WEBKIT_COMPOSITOR_FAILS(X) X
+#endif
+
// Verifies that a layer does not have a texture when the hole is the size
// of the parent layer.
-TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerNoTextureHoleSizeOfLayer)) {
scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
parent->Add(child.get());
@@ -483,7 +503,8 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureHoleSizeOfLayer) {
}
// Verifies that a layer which has opacity == 0 does not have a texture.
-TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerNoTextureTransparent)) {
scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
parent->Add(child.get());
@@ -506,7 +527,8 @@ TEST_F(LayerWithNullDelegateTest, LayerNoTextureTransparent) {
}
// Verifies that no texture is created for a layer with empty bounds.
-TEST_F(LayerWithNullDelegateTest, LayerTextureNonEmptySchedulePaint) {
+TEST_F(LayerWithNullDelegateTest,
+ WEBKIT_COMPOSITOR_FAILS(LayerTextureNonEmptySchedulePaint)) {
scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
Draw();
EXPECT_TRUE(layer->texture() == NULL);
@@ -589,7 +611,7 @@ TEST_F(LayerWithNullDelegateTest, HoleWithNinetyDegreeTransforms) {
// +- L12 (no texture) (added after L1 is already set as root-layer)
// +- L121 (texture)
// +- L122 (texture)
-TEST_F(LayerWithNullDelegateTest, NoCompositor) {
+TEST_F(LayerWithNullDelegateTest, WEBKIT_COMPOSITOR_FAILS(NoCompositor)) {
scoped_ptr<Layer> l1(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
scoped_ptr<Layer> l11(CreateLayer(Layer::LAYER_HAS_TEXTURE));
scoped_ptr<Layer> l12(CreateLayer(Layer::LAYER_HAS_NO_TEXTURE));
diff --git a/ui/gfx/compositor/test_compositor.cc b/ui/gfx/compositor/test_compositor.cc
index 311a923..f34021e 100644
--- a/ui/gfx/compositor/test_compositor.cc
+++ b/ui/gfx/compositor/test_compositor.cc
@@ -40,6 +40,12 @@ void TestCompositor::OnNotifyEnd() {
void TestCompositor::Blur(const gfx::Rect& bounds) {
}
+void TestCompositor::DrawTree() {
+#if !defined(USE_WEBKIT_COMPOSITOR)
+ Compositor::DrawTree();
+#endif
+}
+
void TestCompositor::OnWidgetSizeChanged() {
}
diff --git a/ui/gfx/compositor/test_compositor.h b/ui/gfx/compositor/test_compositor.h
index b7d2cfa..6af5a94 100644
--- a/ui/gfx/compositor/test_compositor.h
+++ b/ui/gfx/compositor/test_compositor.h
@@ -26,6 +26,7 @@ class TestCompositor : public ui::Compositor {
virtual void OnNotifyStart(bool clear) OVERRIDE;
virtual void OnNotifyEnd() OVERRIDE;
virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
+ virtual void DrawTree() OVERRIDE;
protected:
virtual void OnWidgetSizeChanged() OVERRIDE;
diff --git a/ui/gfx/compositor/test_compositor_host_linux.cc b/ui/gfx/compositor/test_compositor_host_linux.cc
index c6ea0c5..f3dba94 100644
--- a/ui/gfx/compositor/test_compositor_host_linux.cc
+++ b/ui/gfx/compositor/test_compositor_host_linux.cc
@@ -90,7 +90,8 @@ ui::Compositor* TestCompositorHostLinux::GetCompositor() {
}
void TestCompositorHostLinux::ScheduleDraw() {
- compositor_->Draw(false);
+ if (compositor_)
+ compositor_->Draw(false);
}
#if defined(TOUCH_UI) || defined(USE_AURA)
diff --git a/ui/gfx/compositor/test_suite.cc b/ui/gfx/compositor/test_suite.cc
index f26cd31..66d4b26 100644
--- a/ui/gfx/compositor/test_suite.cc
+++ b/ui/gfx/compositor/test_suite.cc
@@ -4,14 +4,23 @@
#include "ui/gfx/compositor/test_suite.h"
+#include "base/message_loop.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_test_support.h"
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/gl/gl_implementation.h"
+#if defined(USE_WEBKIT_COMPOSITOR)
+#include "ui/gfx/compositor/compositor_cc.h"
+#endif
+
CompositorTestSuite::CompositorTestSuite(int argc, char** argv)
: TestSuite(argc, argv) {}
+CompositorTestSuite::~CompositorTestSuite() {}
+
void CompositorTestSuite::Initialize() {
#if defined(OS_LINUX)
gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
@@ -24,9 +33,15 @@ void CompositorTestSuite::Initialize() {
// Force unittests to run using en-US so if we test against string
// output, it'll pass regardless of the system language.
ui::ResourceBundle::InitSharedInstance("en-US");
+
+ message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
+ ui::CompositorTestSupport::Initialize();
}
void CompositorTestSuite::Shutdown() {
+ ui::CompositorTestSupport::Terminate();
+ message_loop_.reset();
+
ui::ResourceBundle::CleanupSharedInstance();
base::TestSuite::Shutdown();
diff --git a/ui/gfx/compositor/test_suite.h b/ui/gfx/compositor/test_suite.h
index 0472a24..5566282 100644
--- a/ui/gfx/compositor/test_suite.h
+++ b/ui/gfx/compositor/test_suite.h
@@ -7,16 +7,27 @@
#pragma once
#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
#include "base/test/test_suite.h"
+namespace ui {
+class WebKitPlatformSupportImpl;
+} // namespace ui
+
+class MessageLoop;
+
class CompositorTestSuite : public base::TestSuite {
public:
CompositorTestSuite(int argc, char** argv);
+ ~CompositorTestSuite();
protected:
// base::TestSuite:
virtual void Initialize() OVERRIDE;
virtual void Shutdown() OVERRIDE;
+
+ private:
+ scoped_ptr<MessageLoop> message_loop_;
};
#endif // UI_GFX_COMPOSITOR_TEST_SUITE_H_