summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 07:25:02 +0000
committerpiman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-27 07:25:02 +0000
commit578c81bf2adf9cb973f6a8e759a81bbdf5416226 (patch)
treed58c67c0d302abaa157d1f94a6f80f964b9b6294 /ui
parenta0e1adc59387bb3560c3b36c64a180fc4ff9eab7 (diff)
downloadchromium_src-578c81bf2adf9cb973f6a8e759a81bbdf5416226.zip
chromium_src-578c81bf2adf9cb973f6a8e759a81bbdf5416226.tar.gz
chromium_src-578c81bf2adf9cb973f6a8e759a81bbdf5416226.tar.bz2
Remove old (pre-webkit) compositor
BUG=103948 TEST=builds, tests pass Review URL: http://codereview.chromium.org/9288053 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/aura/aura.gyp17
-rw-r--r--ui/aura/root_window.cc22
-rw-r--r--ui/aura/test/test_suite.cc13
-rw-r--r--ui/gfx/compositor/compositor.cc4
-rw-r--r--ui/gfx/compositor/compositor.gyp107
-rw-r--r--ui/gfx/compositor/compositor.h16
-rw-r--r--ui/gfx/compositor/compositor_gl.cc655
-rw-r--r--ui/gfx/compositor/compositor_gl.h134
-rw-r--r--ui/gfx/compositor/compositor_stub.cc16
-rw-r--r--ui/gfx/compositor/compositor_win.cc810
-rw-r--r--ui/gfx/compositor/debug_utils.cc7
-rw-r--r--ui/gfx/compositor/layer.cc295
-rw-r--r--ui/gfx/compositor/layer.h75
-rw-r--r--ui/gfx/compositor/layer_unittest.cc443
-rw-r--r--ui/gfx/compositor/test/compositor_test_support.cc10
-rw-r--r--ui/gfx/compositor/test/test_compositor.cc62
-rw-r--r--ui/gfx/compositor/test/test_compositor.h46
-rw-r--r--ui/gfx/compositor/test/test_suite.cc15
-rw-r--r--ui/gfx/gfx_resources.grd2
-rw-r--r--ui/gfx/resources/blur.fx74
-rw-r--r--ui/gfx/resources/compositor.fx69
-rw-r--r--ui/gfx/test/gfx_test_utils.cc36
-rw-r--r--ui/gfx/test/gfx_test_utils.h19
-rw-r--r--ui/views/run_all_unittests.cc13
-rw-r--r--ui/views/view.cc11
-rw-r--r--ui/views/view_unittest.cc164
-rw-r--r--ui/views/views.gyp10
-rw-r--r--ui/views/widget/native_widget_gtk.cc14
28 files changed, 32 insertions, 3127 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index 827da52..8e805ee 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -101,13 +101,6 @@
'test/test_window_delegate.cc',
'test/test_window_delegate.h',
],
- 'conditions': [
- ['use_webkit_compositor==0', {
- 'dependencies': [
- '../gfx/compositor/compositor.gyp:test_compositor',
- ],
- }],
- ],
},
{
'target_name': 'aura_demo',
@@ -143,6 +136,7 @@
'../../skia/skia.gyp:skia',
'../../testing/gtest.gyp:gtest',
'../gfx/compositor/compositor.gyp:compositor_test_support',
+ '../gfx/compositor/compositor.gyp:compositor',
'../gfx/gl/gl.gyp:gl',
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
@@ -172,15 +166,6 @@
'<(DEPTH)/third_party/mesa/mesa.gyp:osmesa',
],
}],
- ['use_webkit_compositor==1', {
- 'dependencies': [
- '../gfx/compositor/compositor.gyp:compositor',
- ],
- }, { # use_webkit_compositor!=1
- 'dependencies': [
- '../gfx/compositor/compositor.gyp:test_compositor',
- ],
- }],
],
},
],
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 2b72290..984cd308 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -26,13 +26,10 @@
#include "ui/aura/window_delegate.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/compositor/compositor.h"
+#include "ui/gfx/compositor/compositor_cc.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animator.h"
-#ifdef USE_WEBKIT_COMPOSITOR
-#include "ui/gfx/compositor/compositor_cc.h"
-#endif
-
using std::string;
using std::vector;
@@ -406,15 +403,9 @@ RootWindow::RootWindow()
gfx::Screen::SetInstance(screen_);
last_mouse_location_ = host_->QueryMouseLocation();
- if (ui::Compositor::compositor_factory()) {
- compositor_ = (*ui::Compositor::compositor_factory())(this);
- } else {
-#ifdef USE_WEBKIT_COMPOSITOR
- ui::CompositorCC::Initialize(false);
-#endif
- compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
- host_->GetSize());
- }
+ ui::CompositorCC::Initialize(false);
+ compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
+ host_->GetSize());
DCHECK(compositor_.get());
}
@@ -424,10 +415,7 @@ RootWindow::~RootWindow() {
compositor_ = NULL;
// An observer may have been added by an animation on the RootWindow.
layer()->GetAnimator()->RemoveObserver(this);
-#ifdef USE_WEBKIT_COMPOSITOR
- if (!ui::Compositor::compositor_factory())
- ui::CompositorCC::Terminate();
-#endif
+ ui::CompositorCC::Terminate();
if (instance_ == this)
instance_ = NULL;
}
diff --git a/ui/aura/test/test_suite.cc b/ui/aura/test/test_suite.cc
index 8fb8d2e..3d6c1b2 100644
--- a/ui/aura/test/test_suite.cc
+++ b/ui/aura/test/test_suite.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.
@@ -9,16 +9,11 @@
#include "build/build_config.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_setup.h"
#include "ui/gfx/compositor/test/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_setup.h"
-#else
-#include "ui/gfx/test/gfx_test_utils.h"
-#endif
-
namespace aura {
namespace test {
@@ -36,11 +31,7 @@ void AuraTestSuite::Initialize() {
ui::ResourceBundle::InitSharedInstance("en-US");
ui::CompositorTestSupport::Initialize();
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::SetupTestCompositor();
-#else
- ui::gfx_test_utils::SetupTestCompositor();
-#endif
}
void AuraTestSuite::Shutdown() {
diff --git a/ui/gfx/compositor/compositor.cc b/ui/gfx/compositor/compositor.cc
index 96595b5..4fbd94c 100644
--- a/ui/gfx/compositor/compositor.cc
+++ b/ui/gfx/compositor/compositor.cc
@@ -16,9 +16,6 @@ TextureDrawParams::TextureDrawParams()
vertically_flipped(false) {
}
-// static
-Compositor*(*Compositor::compositor_factory_)(CompositorDelegate*) = NULL;
-
Compositor::Compositor(CompositorDelegate* delegate, const gfx::Size& size)
: delegate_(delegate),
size_(size),
@@ -73,7 +70,6 @@ void Compositor::OnRootLayerChanged() {
}
void Compositor::DrawTree() {
- root_layer_->DrawTree();
}
bool Compositor::CompositesAsynchronously() {
diff --git a/ui/gfx/compositor/compositor.gyp b/ui/gfx/compositor/compositor.gyp
index 8d2c659..82ede85 100644
--- a/ui/gfx/compositor/compositor.gyp
+++ b/ui/gfx/compositor/compositor.gyp
@@ -6,19 +6,6 @@
'variables': {
'chromium_code': 1,
},
- 'target_defaults': {
- 'sources/': [
- ['exclude', '_(gl|win)\\.(cc?)$'],
- ],
- 'conditions': [
- ['os_posix == 1 and OS != "mac"', {
- 'sources/': [['include', '_(gl)\\.(h|cc)$'],]
- }],
- ['OS == "win"', {
- 'sources/': [['include', '_(win)\\.(h|cc)$'],]
- }],
- ],
- },
'targets': [
{
'target_name': 'compositor',
@@ -27,8 +14,12 @@
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'<(DEPTH)/skia/skia.gyp:skia',
+ '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
'<(DEPTH)/ui/gfx/gl/gl.gyp:gl',
'<(DEPTH)/ui/ui.gyp:ui',
+ '<(DEPTH)/webkit/support/webkit_support.gyp:fileapi',
+ '<(DEPTH)/webkit/support/webkit_support.gyp:glue',
+ '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_gpu',
],
'defines': [
'COMPOSITOR_IMPLEMENTATION',
@@ -37,16 +28,12 @@
'compositor.cc',
'compositor.h',
'compositor_export.h',
- 'compositor_gl.cc',
- 'compositor_gl.h',
'compositor_cc.cc',
'compositor_cc.h',
'compositor_observer.h',
'compositor_setup.h',
- 'compositor_stub.cc',
'compositor_switches.cc',
'compositor_switches.h',
- 'compositor_win.cc',
'debug_utils.cc',
'debug_utils.h',
'layer.cc',
@@ -69,15 +56,7 @@
'test_web_graphics_context_3d.h',
],
'conditions': [
- ['os_posix == 1', {
- 'sources!': [
- 'compositor_stub.cc',
- ],
- }],
['OS == "win" and views_compositor == 1', {
- 'sources!': [
- 'compositor_stub.cc',
- ],
# TODO(sky): before we make this real need to remove
# IDR_BITMAP_BRUSH_IMAGE.
'dependencies': [
@@ -85,40 +64,7 @@
'<(DEPTH)/third_party/angle/src/build_angle.gyp:libEGL',
'<(DEPTH)/third_party/angle/src/build_angle.gyp:libGLESv2',
],
- 'link_settings': {
- 'libraries': [
- '-ld3d10.lib',
- '-ld3dx10d.lib',
- '-ldxerr.lib',
- '-ldxguid.lib',
- ]
- },
}],
- ['OS == "win" and views_compositor == 0', {
- 'sources/': [
- ['exclude', '^compositor_win.cc'],
- ],
- }],
- ['use_webkit_compositor == 1', {
- 'sources/': [
- ['exclude', '^compositor_(gl|mac|win|stub).(h|cc|mm)$'],
- ],
- 'dependencies': [
- '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
- '<(DEPTH)/webkit/support/webkit_support.gyp:fileapi',
- '<(DEPTH)/webkit/support/webkit_support.gyp:glue',
- '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_gpu',
- ],
- }, {
- 'sources!': [
- 'compositor_cc.cc',
- 'compositor_cc.h',
- 'compositor_setup.h',
- 'test_web_graphics_context_3d.cc',
- 'test_web_graphics_context_3d.h',
- ],
- }
- ],
],
},
{
@@ -126,18 +72,14 @@
'type': 'static_library',
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
+ '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_support',
+ '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
],
'sources': [
'test/compositor_test_support.cc',
'test/compositor_test_support.h',
],
'conditions': [
- ['use_webkit_compositor == 1', {
- 'dependencies': [
- '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_support',
- '<(DEPTH)/third_party/WebKit/Source/WebKit/chromium/WebKit.gyp:webkit',
- ],
- }],
['os_posix == 1 and OS != "mac"', {
'conditions': [
['linux_use_tcmalloc==1', {
@@ -155,13 +97,10 @@
'dependencies': [
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/base.gyp:test_support_base',
- '<(DEPTH)/chrome/chrome_resources.gyp:packed_resources',
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/testing/gtest.gyp:gtest',
'<(DEPTH)/ui/gfx/gl/gl.gyp:gl',
- '<(DEPTH)/ui/ui.gyp:gfx_resources',
'<(DEPTH)/ui/ui.gyp:ui',
- '<(DEPTH)/ui/ui.gyp:ui_resources',
'compositor',
'compositor_test_support',
],
@@ -184,7 +123,7 @@
'test/test_utils.cc',
'test/test_utils.h',
'<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc',
- '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc',
+ '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc'
],
'conditions': [
# osmesa GL implementation is used on linux.
@@ -193,38 +132,6 @@
'<(DEPTH)/third_party/mesa/mesa.gyp:osmesa',
],
}],
- ['use_webkit_compositor==0', {
- 'dependencies': [
- 'test_compositor',
- ],
- }],
- ],
- },
- {
- 'target_name': 'test_compositor',
- 'type': 'static_library',
- 'dependencies': [
- '<(DEPTH)/base/base.gyp:base',
- ],
- 'sources': [
- '../test/gfx_test_utils.cc',
- '../test/gfx_test_utils.h',
- ],
- 'conditions': [
- # We allow on platforms without a compositor (such as OS_WIN).
- # They will use compositor_stub.cc.
- ['toolkit_views == 1 or os_posix==1', {
- 'dependencies': [
- '<(DEPTH)/skia/skia.gyp:skia',
- 'compositor',
- ],
- 'sources': [
- 'test/test_compositor.cc',
- 'test/test_compositor.h',
- 'test/test_texture.cc',
- 'test/test_texture.h',
- ],
- }],
],
},
],
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 5068946..226adfd 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -159,16 +159,6 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
void RemoveObserver(CompositorObserver* observer);
bool HasObserver(CompositorObserver* observer);
- static void set_compositor_factory_for_testing(
- ui::Compositor*(*factory)(ui::CompositorDelegate* owner)) {
- compositor_factory_ = factory;
- }
-
- static ui::Compositor* (*compositor_factory())(
- ui::CompositorDelegate* owner) {
- return compositor_factory_;
- }
-
protected:
Compositor(CompositorDelegate* delegate, const gfx::Size& size);
virtual ~Compositor();
@@ -207,12 +197,6 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
ObserverList<CompositorObserver> observer_list_;
- // Factory used to create Compositors. Settable by tests.
- // The delegate can be NULL if you don't wish to catch the ScheduleDraw()
- // calls to it.
- static ui::Compositor*(*compositor_factory_)(
- ui::CompositorDelegate* delegate);
-
friend class base::RefCounted<Compositor>;
};
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
deleted file mode 100644
index 1c54ae2..0000000
--- a/ui/gfx/compositor/compositor_gl.cc
+++ /dev/null
@@ -1,655 +0,0 @@
-// 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_gl.h"
-
-#include "base/basictypes.h"
-#include "base/command_line.h"
-#include "base/compiler_specific.h"
-#include "base/debug/trace_event.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/singleton.h"
-#include "base/threading/thread_restrictions.h"
-#include "third_party/skia/include/core/SkBitmap.h"
-#include "third_party/skia/include/core/SkDevice.h"
-#include "third_party/skia/include/core/SkMatrix.h"
-#include "third_party/skia/include/core/SkPoint.h"
-#include "third_party/skia/include/core/SkRect.h"
-#include "third_party/skia/include/core/SkScalar.h"
-#include "ui/gfx/compositor/compositor_switches.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/transform.h"
-#include "ui/gfx/gl/gl_bindings.h"
-#include "ui/gfx/gl/gl_context.h"
-#include "ui/gfx/gl/gl_implementation.h"
-#include "ui/gfx/gl/gl_surface.h"
-
-// Wraps a simple GL program for drawing textures to the screen.
-// Need the declaration before the subclasses in the anonymous namespace below.
-class ui::TextureProgramGL {
- public:
- TextureProgramGL();
- virtual ~TextureProgramGL() {}
-
- // Returns false if it was unable to initialize properly.
- //
- // Host GL context must be current when this is called.
- virtual bool Initialize() = 0;
-
- // Make the program active in the current GL context.
- void Use() const { glUseProgram(program_); }
-
- // Location of vertex position attribute in vertex shader.
- GLuint a_pos_loc() const { return a_pos_loc_; }
-
- // Location of texture co-ordinate attribute in vertex shader.
- GLuint a_tex_loc() const { return a_tex_loc_; }
-
- // Location of the alpha multiplier uniform in the vertex shader.
- GLuint u_alpha_loc() const { return u_alpha_loc_; }
-
- // Location of transformation matrix uniform in vertex shader.
- GLuint u_mat_loc() const { return u_mat_loc_; }
-
- // Location of texture unit uniform that we texture map from
- // in the fragment shader.
- GLuint u_tex_loc() const { return u_tex_loc_; }
-
- protected:
- // Only the fragment shaders differ. This handles the initialization
- // of all the other fields.
- bool InitializeCommon();
-
- GLuint frag_shader_;
-
- private:
- GLuint program_;
- GLuint vertex_shader_;
-
- GLuint a_pos_loc_;
- GLuint a_tex_loc_;
- GLuint u_alpha_loc_;
- GLuint u_tex_loc_;
- GLuint u_mat_loc_;
-};
-
-namespace {
-
-class TextureProgramNoSwizzleGL : public ui::TextureProgramGL {
- public:
- TextureProgramNoSwizzleGL() {}
- virtual bool Initialize();
- private:
- DISALLOW_COPY_AND_ASSIGN(TextureProgramNoSwizzleGL);
-};
-
-class TextureProgramSwizzleGL : public ui::TextureProgramGL {
- public:
- TextureProgramSwizzleGL() {}
- virtual bool Initialize();
- private:
- DISALLOW_COPY_AND_ASSIGN(TextureProgramSwizzleGL);
-};
-
-GLuint CompileShader(GLenum type, const GLchar* source) {
- GLuint shader = glCreateShader(type);
- if (!shader)
- return 0;
-
- glShaderSource(shader, 1, &source, 0);
- glCompileShader(shader);
-
- GLint compiled;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
- if (!compiled) {
- GLint info_len = 0;
- glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len);
-
- if (info_len > 0) {
- scoped_array<char> info_log(new char[info_len]);
- glGetShaderInfoLog(shader, info_len, NULL, info_log.get());
- LOG(ERROR) << "Compile error: " << info_log.get();
- return 0;
- }
- }
- return shader;
-}
-
-bool TextureProgramNoSwizzleGL::Initialize() {
- const bool debug_overdraw = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableCompositorOverdrawDebugging);
-
- if (debug_overdraw) {
- const GLchar* frag_shader_source =
- "#ifdef GL_ES\n"
- "precision mediump float;\n"
- "#endif\n"
- "uniform sampler2D u_tex;"
- "varying vec2 v_texCoord;"
- "void main()"
- "{"
- " gl_FragColor = texture2D(u_tex, v_texCoord);"
- " gl_FragColor.a = 1.0;"
- " gl_FragColor = gl_FragColor * 0.25;"
- " gl_FragColor = gl_FragColor + vec4(0.75, 0.75, 0.75, 0.75);"
- " gl_FragColor = gl_FragColor * 0.3333333;"
- "}";
- frag_shader_ = CompileShader(GL_FRAGMENT_SHADER, frag_shader_source);
- } else {
- const GLchar* frag_shader_source =
- "#ifdef GL_ES\n"
- "precision mediump float;\n"
- "#endif\n"
- "uniform float u_alpha;"
- "uniform sampler2D u_tex;"
- "varying vec2 v_texCoord;"
- "void main()"
- "{"
- " gl_FragColor = texture2D(u_tex, v_texCoord);"
- " if (u_alpha > 0.0)"
- " gl_FragColor.a = u_alpha;"
- " else"
- " gl_FragColor.a = gl_FragColor.a * -u_alpha;"
- "}";
- frag_shader_ = CompileShader(GL_FRAGMENT_SHADER, frag_shader_source);
- }
-
- if (!frag_shader_)
- return false;
-
- return InitializeCommon();
-}
-
-bool TextureProgramSwizzleGL::Initialize() {
- const bool debug_overdraw = CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableCompositorOverdrawDebugging);
-
- if (debug_overdraw) {
- const GLchar* frag_shader_source =
- "#ifdef GL_ES\n"
- "precision mediump float;\n"
- "#endif\n"
- "uniform sampler2D u_tex;"
- "varying vec2 v_texCoord;"
- "void main()"
- "{"
- " gl_FragColor = texture2D(u_tex, v_texCoord).zyxw;"
- " gl_FragColor.a = 1.0;"
- " gl_FragColor = gl_FragColor * 0.25;"
- " gl_FragColor = gl_FragColor + vec4(0.75, 0.75, 0.75, 0.75);"
- " gl_FragColor = gl_FragColor * 0.3333333;"
- "}";
- frag_shader_ = CompileShader(GL_FRAGMENT_SHADER, frag_shader_source);
- } else {
- const GLchar* frag_shader_source =
- "#ifdef GL_ES\n"
- "precision mediump float;\n"
- "#endif\n"
- "uniform float u_alpha;"
- "uniform sampler2D u_tex;"
- "varying vec2 v_texCoord;"
- "void main()"
- "{"
- " gl_FragColor = texture2D(u_tex, v_texCoord).zyxw;"
- " if (u_alpha > 0.0)"
- " gl_FragColor.a = u_alpha;"
- " else"
- " gl_FragColor.a = gl_FragColor.a * -u_alpha;"
- "}";
- frag_shader_ = CompileShader(GL_FRAGMENT_SHADER, frag_shader_source);
- }
-
- if (!frag_shader_)
- return false;
-
- return InitializeCommon();
-}
-
-} // namespace
-
-namespace ui {
-
-TextureProgramGL::TextureProgramGL()
- : program_(0),
- a_pos_loc_(0),
- a_tex_loc_(0),
- u_alpha_loc_(0),
- u_tex_loc_(0),
- u_mat_loc_(0) {
-}
-
-bool TextureProgramGL::InitializeCommon() {
- const GLchar* vertex_shader_source =
- "attribute vec4 a_position;"
- "attribute vec2 a_texCoord;"
- "uniform mat4 u_matViewProjection;"
- "varying vec2 v_texCoord;"
- "void main()"
- "{"
- " gl_Position = u_matViewProjection * a_position;"
- " v_texCoord = a_texCoord;"
- "}";
-
- vertex_shader_ = CompileShader(GL_VERTEX_SHADER, vertex_shader_source);
- if (!vertex_shader_)
- return false;
-
- program_ = glCreateProgram();
- glAttachShader(program_, vertex_shader_);
- glAttachShader(program_, frag_shader_);
- glLinkProgram(program_);
-
- if (glGetError() != GL_NO_ERROR)
- return false;
-
- // Store locations of program inputs.
- a_pos_loc_ = glGetAttribLocation(program_, "a_position");
- a_tex_loc_ = glGetAttribLocation(program_, "a_texCoord");
- u_alpha_loc_ = glGetUniformLocation(program_, "u_alpha");
- u_tex_loc_ = glGetUniformLocation(program_, "u_tex");
- u_mat_loc_ = glGetUniformLocation(program_, "u_matViewProjection");
-
- return true;
-}
-
-SharedResourcesGL::SharedResourcesGL() : initialized_(false) {
-}
-
-
-SharedResourcesGL::~SharedResourcesGL() {
-}
-
-// static
-SharedResourcesGL* SharedResourcesGL::GetInstance() {
- // We use LeakySingletonTraits so that we don't race with
- // the tear down of the gl_bindings.
- SharedResourcesGL* instance = Singleton<SharedResourcesGL,
- LeakySingletonTraits<SharedResourcesGL> >::get();
- if (instance->Initialize()) {
- return instance;
- } else {
- instance->Destroy();
- return NULL;
- }
-}
-
-bool SharedResourcesGL::Initialize() {
- if (initialized_)
- return true;
-
- {
- // The following line of code exists soley to disable IO restrictions
- // on this thread long enough to perform the GL bindings.
- // TODO(wjmaclean) Remove this when GL initialisation cleaned up.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- if (!gfx::GLSurface::InitializeOneOff() ||
- gfx::GetGLImplementation() == gfx::kGLImplementationNone) {
- LOG(ERROR) << "Could not load the GL bindings";
- return false;
- }
- }
-
- surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1));
- if (!surface_.get()) {
- LOG(ERROR) << "Unable to create offscreen GL surface.";
- return false;
- }
-
- context_ = gfx::GLContext::CreateGLContext(
- NULL,
- surface_.get(),
- gfx::PreferIntegratedGpu);
- if (!context_.get()) {
- LOG(ERROR) << "Unable to create GL context.";
- return false;
- }
-
- program_no_swizzle_.reset();
- program_swizzle_.reset();
-
- context_->MakeCurrent(surface_.get());
-
- scoped_ptr<ui::TextureProgramGL> temp_program_no_swizzle(
- new TextureProgramNoSwizzleGL());
- if (!temp_program_no_swizzle->Initialize()) {
- LOG(ERROR) << "Unable to initialize shader.";
- return false;
- }
-
- scoped_ptr<ui::TextureProgramGL> temp_program_swizzle(
- new TextureProgramSwizzleGL());
- if (!temp_program_swizzle->Initialize()) {
- LOG(ERROR) << "Unable to initialize shader.";
- return false;
- }
-
- program_no_swizzle_.swap(temp_program_no_swizzle);
- program_swizzle_.swap(temp_program_swizzle);
-
- initialized_ = true;
- return true;
-}
-
-void SharedResourcesGL::Destroy() {
- program_swizzle_.reset();
- program_no_swizzle_.reset();
-
- context_ = NULL;
- surface_ = NULL;
-
- initialized_ = false;
-}
-
-gfx::ScopedMakeCurrent* SharedResourcesGL::GetScopedMakeCurrent() {
- DCHECK(initialized_);
- if (initialized_)
- return new gfx::ScopedMakeCurrent(context_.get(), surface_.get());
- else
- return NULL;
-}
-
-scoped_refptr<gfx::GLContext> SharedResourcesGL::CreateContext(
- gfx::GLSurface* surface) {
- if (initialized_)
- return gfx::GLContext::CreateGLContext(
- context_->share_group(),
- surface,
- gfx::PreferIntegratedGpu);
- else
- return NULL;
-}
-
-void* SharedResourcesGL::GetDisplay() {
- return surface_->GetDisplay();
-}
-
-TextureGL::TextureGL() : texture_id_(0) {
-}
-
-TextureGL::TextureGL(const gfx::Size& size) : texture_id_(0), size_(size) {
-}
-
-TextureGL::~TextureGL() {
- if (texture_id_) {
- SharedResourcesGL* instance = SharedResourcesGL::GetInstance();
- DCHECK(instance);
- scoped_ptr<gfx::ScopedMakeCurrent> bind(instance->GetScopedMakeCurrent());
- glDeleteTextures(1, &texture_id_);
- }
-}
-
-void TextureGL::SetCanvas(const SkCanvas& canvas,
- const gfx::Point& origin,
- const gfx::Size& overall_size) {
- TRACE_EVENT0("ui", "TextureGL::SetCanvas");
- const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false);
- // Verify bitmap pixels are contiguous.
- DCHECK_EQ(bitmap.rowBytes(),
- SkBitmap::ComputeRowBytes(bitmap.config(), bitmap.width()));
- SkAutoLockPixels lock(bitmap);
- void* pixels = bitmap.getPixels();
-
- if (!texture_id_) {
- // Texture needs to be created. We assume the first call is for
- // a full-sized canvas.
- size_ = overall_size;
-
- glGenTextures(1, &texture_id_);
- glBindTexture(GL_TEXTURE_2D, texture_id_);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- size_.width(), size_.height(), 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- } else if (size_ != overall_size) { // Size has changed.
- size_ = overall_size;
- glBindTexture(GL_TEXTURE_2D, texture_id_);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
- size_.width(), size_.height(), 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- } else {
- glBindTexture(GL_TEXTURE_2D, texture_id_);
- }
- glTexSubImage2D(GL_TEXTURE_2D, 0, origin.x(), origin.y(),
- bitmap.width(), bitmap.height(),
- GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-}
-
-void TextureGL::Draw(const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds_in_texture) {
- TRACE_EVENT0("ui", "TextureGL::Draw");
- SharedResourcesGL* instance = SharedResourcesGL::GetInstance();
- DCHECK(instance);
- DrawInternal(*instance->program_swizzle(),
- params,
- clip_bounds_in_texture);
-}
-
-void TextureGL::DrawInternal(const ui::TextureProgramGL& program,
- const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds_in_texture) {
- // Clip clip_bounds_in_texture to size of texture.
- gfx::Rect clip_bounds = clip_bounds_in_texture.Intersect(
- gfx::Rect(gfx::Point(0, 0), size_));
-
- // Verify that compositor_size has been set.
- DCHECK(params.compositor_size != gfx::Size(0, 0));
-
- if (params.blend)
- glEnable(GL_BLEND);
- else
- glDisable(GL_BLEND);
-
- program.Use();
-
- glActiveTexture(GL_TEXTURE0);
- glUniform1i(program.u_tex_loc(), 0);
- glBindTexture(GL_TEXTURE_2D, texture_id_);
-
- ui::Transform t;
- t.ConcatTranslate(1, 1);
- t.ConcatScale(size_.width()/2.0f, size_.height()/2.0f);
- t.ConcatTranslate(0, -size_.height());
- t.ConcatScale(1, -1);
-
- t.ConcatTransform(params.transform); // Add view transform.
-
- t.ConcatTranslate(0, -params.compositor_size.height());
- t.ConcatScale(1, -1);
- t.ConcatTranslate(-params.compositor_size.width() / 2.0f,
- -params.compositor_size.height() / 2.0f);
- t.ConcatScale(2.0f / params.compositor_size.width(),
- 2.0f / params.compositor_size.height());
-
- GLfloat m[16];
- t.matrix().asColMajorf(m);
-
- SkPoint texture_points[4];
- texture_points[0] = SkPoint::Make(clip_bounds.x(),
- clip_bounds.y() + clip_bounds.height());
- texture_points[1] = SkPoint::Make(clip_bounds.x() + clip_bounds.width(),
- clip_bounds.y() + clip_bounds.height());
- texture_points[2] = SkPoint::Make(clip_bounds.x() + clip_bounds.width(),
- clip_bounds.y());
- texture_points[3] = SkPoint::Make(clip_bounds.x(), clip_bounds.y());
-
- ui::Transform texture_rect_transform;
- texture_rect_transform.ConcatScale(1.0f / size_.width(),
- 1.0f / size_.height());
- if (params.vertically_flipped) {
- ui::Transform vertical_flip;
- vertical_flip.SetScaleY(-1.0);
- vertical_flip.SetTranslateY(1.0);
- texture_rect_transform.ConcatTransform(vertical_flip);
- }
- SkMatrix texture_transform_matrix = texture_rect_transform.matrix();
- texture_transform_matrix.mapPoints(texture_points, 4);
-
- SkRect clip_rect = SkRect::MakeXYWH(
- clip_bounds.x(),
- clip_bounds.y(),
- clip_bounds.width(),
- clip_bounds.height());
-
- ui::Transform clip_rect_transform;
- clip_rect_transform.ConcatScale(2.0f / size_.width(),
- 2.0f / size_.height());
- clip_rect_transform.ConcatScale(1, -1);
- clip_rect_transform.ConcatTranslate(-1.0f, 1.0f);
- SkMatrix clip_transform_matrix = clip_rect_transform.matrix();
- clip_transform_matrix.mapRect(&clip_rect);
-
- GLfloat clip_vertices[] = { clip_rect.left(), clip_rect.top(), +0.,
- clip_rect.right(), clip_rect.top(), +0.,
- clip_rect.right(), clip_rect.bottom(), +0.,
- clip_rect.left(), clip_rect.bottom(), +0.};
-
- GLfloat texture_vertices[] = { texture_points[0].x(), texture_points[0].y(),
- texture_points[1].x(), texture_points[1].y(),
- texture_points[2].x(), texture_points[2].y(),
- texture_points[3].x(), texture_points[3].y()};
-
- glVertexAttribPointer(program.a_pos_loc(), 3, GL_FLOAT,
- GL_FALSE, 3 * sizeof(GLfloat), clip_vertices);
- glVertexAttribPointer(program.a_tex_loc(), 2, GL_FLOAT,
- GL_FALSE, 2 * sizeof(GLfloat), texture_vertices);
- glEnableVertexAttribArray(program.a_pos_loc());
- glEnableVertexAttribArray(program.a_tex_loc());
-
- glUniformMatrix4fv(program.u_mat_loc(), 1, GL_FALSE, m);
-
- // negative means multiply, positive means clobber.
- float alpha = params.has_valid_alpha_channel
- ? -params.opacity
- : params.opacity;
-
- glUniform1fv(program.u_alpha_loc(), 1, &alpha);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-}
-
-CompositorGL::CompositorGL(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size)
- : Compositor(delegate, size),
- started_(false) {
- gl_surface_ = gfx::GLSurface::CreateViewGLSurface(false, widget);
- gl_context_ = SharedResourcesGL::GetInstance()->
- CreateContext(gl_surface_.get());
- gl_context_->MakeCurrent(gl_surface_.get());
-
- CommandLine* command_line = CommandLine::ForCurrentProcess();
-
- if (!command_line->HasSwitch(switches::kDisableUIVsync))
- gl_context_->SetSwapInterval(1);
-
- glColorMask(true, true, true, true);
-
- const bool debug_overdraw = command_line->HasSwitch(
- switches::kEnableCompositorOverdrawDebugging);
-
- if (debug_overdraw)
- glBlendFunc(GL_ONE, GL_ONE);
- else
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-CompositorGL::~CompositorGL() {
- gl_context_ = NULL;
-}
-
-bool CompositorGL::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) {
- MakeCurrent();
-
- if (bounds.right() > size().width() || bounds.bottom() > size().height())
- return false;
-
- bitmap->setConfig(SkBitmap::kARGB_8888_Config,
- bounds.width(),
- bounds.height());
- bitmap->allocPixels();
- SkAutoLockPixels lock(*bitmap);
- unsigned char* pixels = static_cast<unsigned char*>(bitmap->getPixels());
-
- // Check that it's a tight pixel packing
- DCHECK_EQ(bitmap->rowBytes(),
- SkBitmap::ComputeRowBytes(bitmap->config(), bitmap->width()));
-
- GLint current_alignment = 0;
- glGetIntegerv(GL_PACK_ALIGNMENT, &current_alignment);
- glPixelStorei(GL_PACK_ALIGNMENT, 4);
-
- // Flip vertically to convert to OpenGL coordinates.
- glReadPixels(bounds.x(),
- size().height() - bounds.y() - bounds.height(),
- bounds.width(),
- bounds.height(),
- GL_RGBA,
- GL_UNSIGNED_BYTE,
- pixels);
- glPixelStorei(GL_PACK_ALIGNMENT, current_alignment);
-
- SwizzleRGBAToBGRAAndFlip(pixels, bounds.size());
- return true;
-}
-
-void CompositorGL::MakeCurrent() {
- gl_context_->MakeCurrent(gl_surface_.get());
-}
-
-void CompositorGL::OnWidgetSizeChanged() {
-}
-
-Texture* CompositorGL::CreateTexture() {
- Texture* texture = new TextureGL();
- return texture;
-}
-
-void CompositorGL::OnNotifyStart(bool clear) {
- TRACE_EVENT0("ui", "CompositorGL::OnNotifyStart");
- started_ = true;
- gl_context_->MakeCurrent(gl_surface_.get());
- glViewport(0, 0, size().width(), size().height());
- glColorMask(true, true, true, true);
-
- if (clear) {
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT);
- }
-#if !defined(NDEBUG)
- else {
- // In debug mode, when we're not forcing a clear, clear to 'psychedelic'
- // purple to make it easy to spot un-rendered regions.
- glClearColor(223.0 / 255, 0, 1, 1);
- glClear(GL_COLOR_BUFFER_BIT);
- }
-#endif
-}
-
-void CompositorGL::OnNotifyEnd() {
- TRACE_EVENT0("ui", "CompositorGL::OnNotifyEnd");
- DCHECK(started_);
- gl_surface_->SwapBuffers();
- started_ = false;
-}
-
-void CompositorGL::Blur(const gfx::Rect& bounds) {
- NOTIMPLEMENTED();
-}
-
-// static
-Compositor* Compositor::Create(CompositorDelegate* owner,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size) {
- if (SharedResourcesGL::GetInstance() == NULL)
- return NULL;
- else
- return new CompositorGL(owner, widget, size);
-}
-
-} // namespace ui
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h
deleted file mode 100644
index ec55ae4..0000000
--- a/ui/gfx/compositor/compositor_gl.h
+++ /dev/null
@@ -1,134 +0,0 @@
-// 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_GL_H_
-#define UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_
-#pragma once
-
-#include "base/compiler_specific.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/singleton.h"
-#include "base/memory/ref_counted.h"
-#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/gl/scoped_make_current.h"
-#include "ui/gfx/size.h"
-
-namespace gfx {
-class GLContext;
-class GLSurface;
-class Rect;
-}
-
-namespace ui {
-
-class CompositorGL;
-class TextureProgramGL;
-
-// We share resources (such as shaders) between different Compositors via
-// GLContext sharing so that we only have to create/destroy them once.
-class COMPOSITOR_EXPORT SharedResourcesGL : public SharedResources {
- public:
- static SharedResourcesGL* GetInstance();
-
- virtual gfx::ScopedMakeCurrent* GetScopedMakeCurrent() OVERRIDE;
-
- // Creates a context that shares the resources hosted by this singleton.
- scoped_refptr<gfx::GLContext> CreateContext(gfx::GLSurface* surface);
-
- virtual void* GetDisplay() OVERRIDE;
-
- ui::TextureProgramGL* program_no_swizzle() {
- return program_no_swizzle_.get();
- }
-
- ui::TextureProgramGL* program_swizzle() {
- return program_swizzle_.get();
- }
-
- private:
- friend struct DefaultSingletonTraits<SharedResourcesGL>;
-
- SharedResourcesGL();
- virtual ~SharedResourcesGL();
-
- bool Initialize();
- void Destroy();
-
- bool initialized_;
-
- scoped_refptr<gfx::GLContext> context_;
- scoped_refptr<gfx::GLSurface> surface_;
-
- scoped_ptr<ui::TextureProgramGL> program_swizzle_;
- scoped_ptr<ui::TextureProgramGL> program_no_swizzle_;
-
- DISALLOW_COPY_AND_ASSIGN(SharedResourcesGL);
-};
-
-class COMPOSITOR_EXPORT TextureGL : public Texture {
- public:
- TextureGL();
-
- 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;
-
- const gfx::Size& size() const { return size_; }
-
- protected:
- explicit TextureGL(const gfx::Size& size);
- virtual ~TextureGL();
-
- // Actually draws the texture.
- // Only the region defined by draw_bounds will be drawn.
- void DrawInternal(const TextureProgramGL& program,
- const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds_in_texture);
-
- unsigned int texture_id_;
- gfx::Size size_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TextureGL);
-};
-
-class COMPOSITOR_EXPORT CompositorGL : public Compositor {
- public:
- CompositorGL(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size);
- virtual ~CompositorGL();
-
- // Overridden from Compositor.
- virtual bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) OVERRIDE;
-
- void MakeCurrent();
- gfx::Size GetSize();
-
- protected:
- virtual void OnWidgetSizeChanged() OVERRIDE;
-
- private:
- // Overridden from Compositor.
- virtual Texture* CreateTexture() OVERRIDE;
- virtual void OnNotifyStart(bool clear) OVERRIDE;
- virtual void OnNotifyEnd() OVERRIDE;
- virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
-
- // The GL context used for compositing.
- scoped_refptr<gfx::GLSurface> gl_surface_;
- scoped_refptr<gfx::GLContext> gl_context_;
-
- // Keep track of whether compositing has started or not.
- bool started_;
-
- DISALLOW_COPY_AND_ASSIGN(CompositorGL);
-};
-
-} // namespace ui
-
-#endif // UI_GFX_COMPOSITOR_COMPOSITOR_GL_H_
diff --git a/ui/gfx/compositor/compositor_stub.cc b/ui/gfx/compositor/compositor_stub.cc
deleted file mode 100644
index ed7a4dd..0000000
--- a/ui/gfx/compositor/compositor_stub.cc
+++ /dev/null
@@ -1,16 +0,0 @@
-// 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.h"
-
-namespace ui {
-
-// static
-Compositor* Compositor::Create(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size) {
- return NULL;
-}
-
-} // namespace ui
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc
deleted file mode 100644
index 36de648..0000000
--- a/ui/gfx/compositor/compositor_win.cc
+++ /dev/null
@@ -1,810 +0,0 @@
-// 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.h"
-
-#include <algorithm>
-#include <d3dx10.h>
-#include <vector>
-
-#include "base/compiler_specific.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "base/string_piece.h"
-#include "base/win/scoped_comptr.h"
-#include "grit/gfx_resources.h"
-#include "third_party/skia/include/core/SkCanvas.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/gfx/canvas_skia.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/transform.h"
-
-// TODO(sky): this is a hack, figure out real error handling.
-#define RETURN_IF_FAILED(error) \
- if (error != S_OK) { \
- this->Errored(error); \
- VLOG(1) << "D3D failed" << error; \
- return; \
- }
-
-using base::win::ScopedComPtr;
-
-namespace ui {
-
-namespace {
-
-class CompositorWin;
-
-// Vertex structure used by the compositor.
-struct Vertex {
- D3DXVECTOR3 position;
- D3DXVECTOR2 texture_offset;
-};
-
-// D3D 10 Texture implementation. Creates a quad representing the view and
-// a texture with the bitmap data. The quad has an origin of 0,0,0 with a size
-// matching that of |SetCanvas|.
-class ViewTexture : public Texture {
- public:
- ViewTexture(CompositorWin* compositor,
- ID3D10Device* device,
- ID3D10Effect* effect);
-
- // Texture:
- 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:
- ~ViewTexture();
-
- void Errored(HRESULT result);
-
- void ConvertBitmapToD3DData(const SkBitmap& bitmap,
- scoped_array<uint32>* converted_data);
-
- // Creates vertex buffer for specified region
- void CreateVertexBufferForRegion(const gfx::Rect& bounds);
-
- scoped_refptr<CompositorWin> compositor_;
-
- // Size of the corresponding View.
- gfx::Size view_size_;
-
- ScopedComPtr<ID3D10Device> device_;
- ScopedComPtr<ID3D10Effect, NULL> effect_;
- ScopedComPtr<ID3D10Texture2D> texture_;
- ScopedComPtr<ID3D10ShaderResourceView> shader_view_;
- ScopedComPtr<ID3D10Buffer> vertex_buffer_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewTexture);
-};
-
-// D3D 10 Compositor implementation.
-class CompositorWin : public Compositor {
- public:
- CompositorWin(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size);
-
- void Init();
-
- // Invoked to update the perspective needed by this texture. |transform| is
- // the transform for the texture, and |size| the size of the texture.
- void UpdatePerspective(const ui::Transform& transform,
- const gfx::Size& view_size);
-
- // Returns the index buffer used for drawing a texture.
- ID3D10Buffer* GetTextureIndexBuffer();
-
- // Compositor:
- virtual Texture* CreateTexture() OVERRIDE;
-
- virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
-
- virtual bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) OVERRIDE;
-
- protected:
- virtual void OnNotifyStart(bool clear) OVERRIDE;
- virtual void OnNotifyEnd() OVERRIDE;
- virtual void OnWidgetSizeChanged() OVERRIDE;
-
- private:
- enum Direction {
- HORIZONTAL,
- VERTICAL
- };
-
- ~CompositorWin();
-
- void Errored(HRESULT error_code);
-
- void CreateDevice();
-
- void LoadEffects();
-
- void InitVertexLayout();
-
- // Updates the kernel used for blurring. Size is the size of the texture
- // being drawn to along the appropriate axis.
- void UpdateBlurKernel(Direction direction, int size);
-
- // Creates a texture, render target view and shader.
- void CreateTexture(const gfx::Size& size,
- ID3D10Texture2D** texture,
- ID3D10RenderTargetView** render_target_view,
- ID3D10ShaderResourceView** shader_resource_view);
-
- // Creates |vertex_buffer_|.
- void CreateVertexBuffer();
-
- // Creates |index_buffer_|.
- void CreateIndexBuffer();
-
- // Creates a vertex buffer for the specified region. The caller owns the
- // return value.
- ID3D10Buffer* CreateVertexBufferForRegion(const gfx::Rect& bounds);
-
- gfx::AcceleratedWidget host_;
-
- ScopedComPtr<ID3D10Device> device_;
- ScopedComPtr<IDXGISwapChain> swap_chain_;
- ScopedComPtr<ID3D10RenderTargetView> dest_render_target_view_;
- ScopedComPtr<ID3D10Texture2D> depth_stencil_buffer_;
- ScopedComPtr<ID3D10DepthStencilView> depth_stencil_view_;
- ScopedComPtr<ID3D10Effect, NULL> fx_;
- ID3D10EffectTechnique* technique_;
-
- // Layout for Vertex.
- ScopedComPtr<ID3D10InputLayout> vertex_layout_;
-
- // Identity vertext buffer. Used when copying from main back to dest.
- ScopedComPtr<ID3D10Buffer> vertex_buffer_;
-
- // Index buffer used for drawing a rectangle.
- ScopedComPtr<ID3D10Buffer> index_buffer_;
-
- // Used for bluring.
- ScopedComPtr<ID3D10Effect, NULL> blur_fx_;
- ID3D10EffectTechnique* blur_technique_;
-
- // All rendering is done to the main_texture. Effects (such as bloom) render
- // into the blur texture, and are then copied back to the main texture. When
- // rendering is done |main_texture_| is drawn back to
- // |dest_render_target_view_|.
- ScopedComPtr<ID3D10Texture2D> main_texture_;
- ScopedComPtr<ID3D10RenderTargetView> main_render_target_view_;
- ScopedComPtr<ID3D10ShaderResourceView> main_texture_shader_view_;
-
- ScopedComPtr<ID3D10Texture2D> blur_texture_;
- ScopedComPtr<ID3D10RenderTargetView> blur_render_target_view_;
- ScopedComPtr<ID3D10ShaderResourceView> blur_texture_shader_view_;
-
- DISALLOW_COPY_AND_ASSIGN(CompositorWin);
-};
-
-ViewTexture::ViewTexture(CompositorWin* compositor,
- ID3D10Device* device,
- ID3D10Effect* effect)
- : compositor_(compositor),
- device_(device),
- effect_(effect) {
-}
-
-ViewTexture::~ViewTexture() {
-}
-
-void ViewTexture::SetCanvas(const SkCanvas& canvas,
- const gfx::Point& origin,
- const gfx::Size& overall_size) {
- view_size_ = overall_size;
-
- scoped_array<uint32> converted_data;
- const SkBitmap& bitmap = canvas.getDevice()->accessBitmap(false);
- ConvertBitmapToD3DData(bitmap, &converted_data);
- if (gfx::Size(bitmap.width(), bitmap.height()) == overall_size) {
- shader_view_.Release();
- texture_.Release();
-
- D3D10_TEXTURE2D_DESC texture_desc;
- texture_desc.Width = bitmap.width();
- texture_desc.Height = bitmap.height();
- texture_desc.MipLevels = 1;
- texture_desc.ArraySize = 1;
- texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- texture_desc.SampleDesc.Count = 1;
- texture_desc.SampleDesc.Quality = 0;
- texture_desc.Usage = D3D10_USAGE_DEFAULT;
- texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
- texture_desc.CPUAccessFlags = 0;
- texture_desc.MiscFlags = 0;
- RETURN_IF_FAILED(device_->CreateTexture2D(&texture_desc,
- NULL, texture_.Receive()));
- RETURN_IF_FAILED(
- device_->CreateShaderResourceView(texture_.get(), NULL,
- shader_view_.Receive()));
- }
- DCHECK(texture_.get());
- D3D10_BOX dst_box = { origin.x(), origin.y(), 0,
- origin.x() + bitmap.width(),
- origin.y() + bitmap.height(), 1 };
- device_->UpdateSubresource(texture_.get(), 0, &dst_box,
- converted_data.get(), bitmap.width() * 4, 0);
-}
-
-void ViewTexture::Draw(const ui::TextureDrawParams& params,
- const gfx::Rect& clip_bounds) {
- if (params.vertically_flipped)
- NOTIMPLEMENTED();
-
- compositor_->UpdatePerspective(params.transform, view_size_);
-
- // Make texture active.
- RETURN_IF_FAILED(
- effect_->GetVariableByName("textureMap")->AsShaderResource()->
- SetResource(shader_view_.get()));
-
- RETURN_IF_FAILED(effect_->GetVariableByName("alpha")->AsScalar()->SetFloat(
- params.opacity));
-
- ID3D10EffectTechnique* technique = effect_->GetTechniqueByName("ViewTech");
- DCHECK(technique);
- D3D10_TECHNIQUE_DESC tech_desc;
- technique->GetDesc(&tech_desc);
- for(UINT p = 0; p < tech_desc.Passes; ++p)
- technique->GetPassByIndex(p)->Apply(0);
-
- UINT stride = sizeof(Vertex);
- UINT offset = 0;
- CreateVertexBufferForRegion(clip_bounds);
- ID3D10Buffer* vertex_buffer = vertex_buffer_.get();
- device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset);
- device_->IASetIndexBuffer(compositor_->GetTextureIndexBuffer(),
- DXGI_FORMAT_R32_UINT, 0);
- device_->DrawIndexed(6, 0, 0);
-}
-
-void ViewTexture::Errored(HRESULT result) {
- // TODO: figure out error handling.
- DCHECK(false);
-}
-
-void ViewTexture::ConvertBitmapToD3DData(
- const SkBitmap& bitmap,
- scoped_array<uint32>* converted_data) {
- int width = bitmap.width();
- int height = bitmap.height();
- SkAutoLockPixels pixel_lock(bitmap);
- // D3D wants colors in ABGR format (premultiplied).
- converted_data->reset(new uint32[width * height]);
- uint32_t* bitmap_data = bitmap.getAddr32(0, 0);
- for (int x = 0, offset = 0; x < width; ++x) {
- for (int y = 0; y < height; ++y, ++offset) {
- SkColor color = bitmap_data[offset];
- (*converted_data)[offset] =
- (SkColorGetA(color) << 24) |
- (SkColorGetB(color) << 16) |
- (SkColorGetG(color) << 8) |
- (SkColorGetR(color));
- }
- }
-}
-
-void ViewTexture::CreateVertexBufferForRegion(const gfx::Rect& bounds) {
- vertex_buffer_.Release();
- float x = bounds.x();
- float max_x = bounds.right();
- float y = bounds.y();
- float max_y = bounds.bottom();
- float tex_x = x / static_cast<float>(view_size_.width());
- float max_tex_x = max_x / static_cast<float>(view_size_.width());
- float tex_y = y / static_cast<float>(view_size_.width());
- float max_tex_y = max_y / static_cast<float>(view_size_.height());
- Vertex vertices[] = {
- { D3DXVECTOR3( x, -max_y, 0.0f), D3DXVECTOR2( tex_x, max_tex_y) },
- { D3DXVECTOR3( x, -y, 0.0f), D3DXVECTOR2( tex_x, tex_y) },
- { D3DXVECTOR3(max_x, -y, 0.0f), D3DXVECTOR2(max_tex_x, tex_y) },
- { D3DXVECTOR3(max_x, -max_y, 0.0f), D3DXVECTOR2(max_tex_x, max_tex_y) }
- };
-
- // Create the vertex buffer containing the points.
- D3D10_BUFFER_DESC buffer_desc;
- buffer_desc.Usage = D3D10_USAGE_IMMUTABLE;
- buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices);
- buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
- buffer_desc.CPUAccessFlags = 0;
- buffer_desc.MiscFlags = 0;
- D3D10_SUBRESOURCE_DATA init_data;
- init_data.pSysMem = vertices;
- RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data,
- vertex_buffer_.Receive()));
-}
-
-CompositorWin::CompositorWin(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size)
- : Compositor(delegate, size),
- host_(widget),
- technique_(NULL) {
-}
-
-void CompositorWin::Init() {
- CreateDevice();
- LoadEffects();
- OnWidgetSizeChanged();
- InitVertexLayout();
- CreateVertexBuffer();
- CreateIndexBuffer();
-}
-
-void CompositorWin::UpdatePerspective(const ui::Transform& transform,
- const gfx::Size& view_size) {
- float transform_data_buffer[16];
- transform.matrix().asColMajorf(transform_data_buffer);
- D3DXMATRIX transform_matrix(&transform_data_buffer[0]);
- std::swap(transform_matrix._12, transform_matrix._21);
- std::swap(transform_matrix._13, transform_matrix._31);
- std::swap(transform_matrix._23, transform_matrix._32);
-
- // Different coordinate system; flip the y.
- transform_matrix._42 *= -1;
-
- // Scale so x and y are from 0-2.
- D3DXMATRIX scale_matrix;
- D3DXMatrixScaling(
- &scale_matrix,
- 2.0f / static_cast<float>(size().width()),
- 2.0f / static_cast<float>(size().height()),
- 1.0f);
-
- // Translate so x and y are from -1,-1 to 1,1.
- D3DXMATRIX translate_matrix;
- D3DXMatrixTranslation(&translate_matrix, -1.0f, 1.0f, 0.0f);
-
- D3DXMATRIX projection_matrix;
- D3DXMatrixIdentity(&projection_matrix);
- D3DXMatrixPerspectiveFovLH(&projection_matrix,
- atanf(.5f) * 2.0f, 1.0f, 1.0f, 1000.0f);
- D3DXVECTOR3 pos(0.0f, 0.0f, -2.0f);
- D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
- D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
- D3DXMATRIX view;
- D3DXMatrixIdentity(&view);
- D3DXMatrixLookAtLH(&view, &pos, &target, &up);
-
- D3DXMATRIX wvp = transform_matrix * scale_matrix * translate_matrix * view *
- projection_matrix;
-
- fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(wvp);
-}
-
-ID3D10Buffer* CompositorWin::GetTextureIndexBuffer() {
- return index_buffer_.get();
-}
-
-Texture* CompositorWin::CreateTexture() {
- return new ViewTexture(this, device_.get(), fx_.get());
-}
-
-void CompositorWin::OnNotifyStart(bool clear) {
- ID3D10RenderTargetView* target_view = main_render_target_view_.get();
- device_->OMSetRenderTargets(1, &target_view, depth_stencil_view_.get());
-
- // Clear the background and stencil view.
- // TODO(vollick) see if |clear| can be used to avoid unnecessary clearing.
- device_->ClearRenderTargetView(target_view,
- D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
- device_->ClearDepthStencilView(
- depth_stencil_view_.get(), D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL,
- 1.0f, 0);
-
- // TODO: these steps may not be necessary each time through.
- device_->OMSetDepthStencilState(0, 0);
- float blend_factors[] = {0.0f, 0.0f, 0.0f, 0.0f};
- device_->OMSetBlendState(0, blend_factors, 0xffffffff);
- device_->IASetInputLayout(vertex_layout_.get());
- device_->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-}
-
-void CompositorWin::OnNotifyEnd() {
- // Copy from main_render_target_view_| (where all are rendering was done) back
- // to |dest_render_target_view_|.
- ID3D10RenderTargetView* target_view = dest_render_target_view_.get();
- device_->OMSetRenderTargets(1, &target_view, NULL);
- device_->ClearRenderTargetView(target_view,
- D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
- RETURN_IF_FAILED(
- fx_->GetVariableByName("textureMap")->AsShaderResource()->
- SetResource(main_texture_shader_view_.get()));
- D3DXMATRIX identify_matrix;
- D3DXMatrixIdentity(&identify_matrix);
- fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(identify_matrix);
- ID3D10EffectTechnique* technique = fx_->GetTechniqueByName("ViewTech");
- DCHECK(technique);
- D3D10_TECHNIQUE_DESC tech_desc;
- technique->GetDesc(&tech_desc);
- for(UINT p = 0; p < tech_desc.Passes; ++p)
- technique->GetPassByIndex(p)->Apply(0);
- UINT stride = sizeof(Vertex);
- UINT offset = 0;
- ID3D10Buffer* vertex_buffer = vertex_buffer_.get();
- device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset);
- device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0);
- device_->DrawIndexed(6, 0, 0);
- RETURN_IF_FAILED(
- fx_->GetVariableByName("textureMap")->AsShaderResource()->
- SetResource(NULL));
- swap_chain_->Present(0, 0);
-
- // We may delete the shader resource view before drawing again. Unset it so
- // that d3d doesn't generate a warning when we do that.
- fx_->GetVariableByName("textureMap")->AsShaderResource()->SetResource(NULL);
- for(UINT i = 0; i < tech_desc.Passes; ++i)
- technique_->GetPassByIndex(i)->Apply(0);
-}
-
-void CompositorWin::Blur(const gfx::Rect& bounds) {
- // Set up the vertex buffer for the region we're going to blur.
- ScopedComPtr<ID3D10Buffer> scoped_vertex_buffer(
- CreateVertexBufferForRegion(bounds));
- ID3D10Buffer* vertex_buffer = scoped_vertex_buffer.get();
- UINT stride = sizeof(Vertex);
- UINT offset = 0;
- device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset);
- device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0);
- device_->DrawIndexed(6, 0, 0);
- D3DXMATRIX identity_matrix;
- D3DXMatrixIdentity(&identity_matrix);
-
- // Horizontal blur from the main texture to blur texture.
- UpdateBlurKernel(HORIZONTAL, size().width());
- ID3D10RenderTargetView* target_view = blur_render_target_view_.get();
- device_->OMSetRenderTargets(1, &target_view, NULL);
- RETURN_IF_FAILED(
- blur_fx_->GetVariableByName("textureMap")->AsShaderResource()->
- SetResource(main_texture_shader_view_.get()));
- blur_fx_->GetVariableByName("gWVP")->AsMatrix()->SetMatrix(
- identity_matrix);
- ID3D10EffectTechnique* technique = blur_fx_->GetTechniqueByName("ViewTech");
- DCHECK(technique);
- D3D10_TECHNIQUE_DESC tech_desc;
- technique->GetDesc(&tech_desc);
- for(UINT p = 0; p < tech_desc.Passes; ++p)
- technique->GetPassByIndex(p)->Apply(0);
- device_->DrawIndexed(6, 0, 0);
-
- {
- // We do this to avoid a warning.
- ID3D10ShaderResourceView* tmp = NULL;
- device_->PSSetShaderResources(0, 1, &tmp);
- }
-
- // Vertical blur from the blur texture back to main buffer.
- RETURN_IF_FAILED(
- blur_fx_->GetVariableByName("textureMap")->AsShaderResource()->
- SetResource(blur_texture_shader_view_.get()));
- UpdateBlurKernel(VERTICAL, size().height());
- target_view = main_render_target_view_.get();
- device_->OMSetRenderTargets(1, &target_view, NULL);
- for(UINT p = 0; p < tech_desc.Passes; ++p)
- technique->GetPassByIndex(p)->Apply(0);
- device_->DrawIndexed(6, 0, 0);
-
-#if !defined(NDEBUG)
- // A warning is generated if a bound vertexbuffer is deleted. To avoid that
- // warning we reset the buffer here. We only do it for debug builds as it's
- // ok to effectively unbind the vertex buffer.
- vertex_buffer = vertex_buffer_.get();
- device_->IASetVertexBuffers(0, 1, &vertex_buffer, &stride, &offset);
- device_->IASetIndexBuffer(index_buffer_.get(), DXGI_FORMAT_R32_UINT, 0);
-#endif
-}
-
-bool CompositorWin::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) {
- NOTIMPLEMENTED();
- return false;
-}
-
-void CompositorWin::OnWidgetSizeChanged() {
- dest_render_target_view_ = NULL;
- depth_stencil_buffer_ = NULL;
- depth_stencil_view_ = NULL;
-
- main_render_target_view_ = NULL;
- main_texture_ = NULL;
- main_texture_shader_view_ = NULL;
-
- blur_render_target_view_ = NULL;
- blur_texture_ = NULL;
- blur_texture_shader_view_ = NULL;
-
- CreateTexture(size(), main_texture_.Receive(),
- main_render_target_view_.Receive(),
- main_texture_shader_view_.Receive());
-
- CreateTexture(size(), blur_texture_.Receive(),
- blur_render_target_view_.Receive(),
- blur_texture_shader_view_.Receive());
-
- // Resize the swap chain and recreate the render target view.
- RETURN_IF_FAILED(swap_chain_->ResizeBuffers(
- 1, size().width(), size().height(), DXGI_FORMAT_R8G8B8A8_UNORM, 0));
- ScopedComPtr<ID3D10Texture2D> back_buffer;
- RETURN_IF_FAILED(swap_chain_->GetBuffer(
- 0, __uuidof(ID3D10Texture2D),
- reinterpret_cast<void**>(back_buffer.Receive())));
- RETURN_IF_FAILED(device_->CreateRenderTargetView(
- back_buffer.get(), 0,
- dest_render_target_view_.Receive()));
-
- // Create the depth/stencil buffer and view.
- D3D10_TEXTURE2D_DESC depth_stencil_desc;
- depth_stencil_desc.Width = size().width();
- depth_stencil_desc.Height = size().height();
- depth_stencil_desc.MipLevels = 1;
- depth_stencil_desc.ArraySize = 1;
- depth_stencil_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
- depth_stencil_desc.SampleDesc.Count = 1; // multisampling must match
- depth_stencil_desc.SampleDesc.Quality = 0; // swap chain values.
- depth_stencil_desc.Usage = D3D10_USAGE_DEFAULT;
- depth_stencil_desc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
- depth_stencil_desc.CPUAccessFlags = 0;
- depth_stencil_desc.MiscFlags = 0;
-
- RETURN_IF_FAILED(device_->CreateTexture2D(&depth_stencil_desc, 0,
- depth_stencil_buffer_.Receive()));
- RETURN_IF_FAILED(device_->CreateDepthStencilView(
- depth_stencil_buffer_.get(), 0,
- depth_stencil_view_.Receive()));
-
-
- // Set the viewport transform.
- D3D10_VIEWPORT vp;
- vp.TopLeftX = 0;
- vp.TopLeftY = 0;
- vp.Width = size().width();
- vp.Height = size().height();
- vp.MinDepth = 0.0f;
- vp.MaxDepth = 1.0f;
-
- device_->RSSetViewports(1, &vp);
-}
-
-CompositorWin::~CompositorWin() {
-}
-
-void CompositorWin::Errored(HRESULT error_code) {
- // TODO: figure out error handling.
- DCHECK(false);
-}
-
-void CompositorWin::CreateDevice() {
- DXGI_SWAP_CHAIN_DESC sd;
- sd.BufferDesc.Width = size().width();
- sd.BufferDesc.Height = size().height();
- sd.BufferDesc.RefreshRate.Numerator = 60;
- sd.BufferDesc.RefreshRate.Denominator = 1;
- sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
- sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
-
- // No multisampling.
- sd.SampleDesc.Count = 1;
- sd.SampleDesc.Quality = 0;
-
- sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
- sd.BufferCount = 1;
- sd.OutputWindow = host_;
- sd.Windowed = true;
- sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
- sd.Flags = 0;
-
- // Create the device.
- UINT createDeviceFlags = 0;
-#if !defined(NDEBUG)
- createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
-#endif
- RETURN_IF_FAILED(
- D3D10CreateDeviceAndSwapChain(
- 0, //default adapter
- D3D10_DRIVER_TYPE_HARDWARE,
- 0, // no software device
- createDeviceFlags,
- D3D10_SDK_VERSION,
- &sd,
- swap_chain_.Receive(),
- device_.Receive()));
-}
-
-void CompositorWin::LoadEffects() {
- DWORD shader_flags = D3D10_SHADER_ENABLE_STRICTNESS;
-#if !defined(NDEBUG)
- shader_flags |= D3D10_SHADER_DEBUG | D3D10_SHADER_SKIP_OPTIMIZATION;
-#endif
- ScopedComPtr<ID3D10Blob> compilation_errors;
- const base::StringPiece& fx_data = ResourceBundle::GetSharedInstance().
- GetRawDataResource(IDR_COMPOSITOR_FX);
- DCHECK(!fx_data.empty());
- RETURN_IF_FAILED(
- D3DX10CreateEffectFromMemory(
- fx_data.data(), fx_data.size(), "compositor.fx", NULL, NULL,
- "fx_4_0", shader_flags, 0, device_.get(), NULL, NULL, fx_.Receive(),
- compilation_errors.Receive(), NULL));
- technique_ = fx_->GetTechniqueByName("ViewTech");
- DCHECK(technique_);
-
- const base::StringPiece& blur_data = ResourceBundle::GetSharedInstance().
- GetRawDataResource(IDR_BLUR_FX);
- DCHECK(!blur_data.empty());
- compilation_errors = NULL;
- RETURN_IF_FAILED(
- D3DX10CreateEffectFromMemory(
- blur_data.data(), blur_data.size(), "bloom.fx", NULL, NULL,
- "fx_4_0", shader_flags, 0, device_.get(), NULL, NULL,
- blur_fx_.Receive(), compilation_errors.Receive(), NULL));
- blur_technique_ = blur_fx_->GetTechniqueByName("ViewTech");
- DCHECK(blur_technique_);
-}
-
-void CompositorWin::InitVertexLayout() {
- D3D10_INPUT_ELEMENT_DESC vertex_desc[] = {
- { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,
- D3D10_INPUT_PER_VERTEX_DATA, 0 },
- { "TEXC", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12,
- D3D10_INPUT_PER_VERTEX_DATA, 0 },
- };
-
- // Create the input layout
- D3D10_PASS_DESC pass_desc;
- RETURN_IF_FAILED(technique_->GetPassByIndex(0)->GetDesc(&pass_desc));
- RETURN_IF_FAILED(
- device_->CreateInputLayout(vertex_desc, ARRAYSIZE_UNSAFE(vertex_desc),
- pass_desc.pIAInputSignature,
- pass_desc.IAInputSignatureSize,
- vertex_layout_.Receive()));
-}
-
-void CompositorWin::UpdateBlurKernel(Direction direction, int size) {
- // Update the blur data.
- const int kSize = 13;
- float pixel_data[4 * kSize];
- memset(pixel_data, 0, sizeof(float) * 4 * kSize);
- for (int i = 0; i < kSize; ++i) {
- pixel_data[i * 4 + ((direction == HORIZONTAL) ? 0 : 1)] =
- static_cast<float>(i - (kSize / 2)) / static_cast<float>(size);
- }
- RETURN_IF_FAILED(blur_fx_->GetVariableByName("TexelKernel")->AsVector()->
- SetFloatVectorArray(pixel_data, 0, kSize));
-}
-
-void CompositorWin::CreateTexture(
- const gfx::Size& size,
- ID3D10Texture2D** texture,
- ID3D10RenderTargetView** render_target_view,
- ID3D10ShaderResourceView** shader_resource_view) {
- D3D10_TEXTURE2D_DESC texture_desc;
- texture_desc.Width = size.width();
- texture_desc.Height = size.height();
- texture_desc.MipLevels = 1;
- texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
- texture_desc.SampleDesc.Count = 1;
- texture_desc.SampleDesc.Quality = 0;
- texture_desc.Usage = D3D10_USAGE_DEFAULT;
- texture_desc.BindFlags =
- D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
- texture_desc.CPUAccessFlags = 0;
- texture_desc.MiscFlags = 0;
- texture_desc.ArraySize = 1;
- RETURN_IF_FAILED(device_->CreateTexture2D(&texture_desc, NULL, texture));
-
- RETURN_IF_FAILED(
- device_->CreateShaderResourceView(*texture, NULL, shader_resource_view));
-
- D3D10_RENDER_TARGET_VIEW_DESC render_target_view_desc;
- render_target_view_desc.Format = texture_desc.Format;
- render_target_view_desc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
- render_target_view_desc.Texture2D.MipSlice = 0;
- RETURN_IF_FAILED(device_->CreateRenderTargetView(
- *texture, &render_target_view_desc, render_target_view));
-}
-
-void CompositorWin::CreateVertexBuffer() {
- vertex_buffer_.Release();
-
- Vertex vertices[] = {
- { D3DXVECTOR3(-1.0f, -1.0f, 0.0f), D3DXVECTOR2(0.0f, 1.0f) },
- { D3DXVECTOR3(-1.0f, 1.0f, 0.0f), D3DXVECTOR2(0.0f, 0.0f) },
- { D3DXVECTOR3( 1.0f, 1.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f) },
- { D3DXVECTOR3( 1.0f, -1.0f, 0.0f), D3DXVECTOR2(1.0f, 1.0f) },
- };
-
- // Create the vertex buffer containing the points.
- D3D10_BUFFER_DESC buffer_desc;
- buffer_desc.Usage = D3D10_USAGE_IMMUTABLE;
- buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices);
- buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
- buffer_desc.CPUAccessFlags = 0;
- buffer_desc.MiscFlags = 0;
- D3D10_SUBRESOURCE_DATA init_data;
- init_data.pSysMem = vertices;
- RETURN_IF_FAILED(device_->CreateBuffer(&buffer_desc, &init_data,
- vertex_buffer_.Receive()));
-}
-
-void CompositorWin::CreateIndexBuffer() {
- index_buffer_.Release();
-
- // Then the index buffer.
- DWORD indices[] = {
- 0, 1, 2,
- 0, 2, 3,
- };
- D3D10_BUFFER_DESC index_buffer;
- index_buffer.Usage = D3D10_USAGE_IMMUTABLE;
- index_buffer.ByteWidth = sizeof(DWORD) * ARRAYSIZE_UNSAFE(indices);
- index_buffer.BindFlags = D3D10_BIND_INDEX_BUFFER;
- index_buffer.CPUAccessFlags = 0;
- index_buffer.MiscFlags = 0;
- D3D10_SUBRESOURCE_DATA init_data;
- init_data.pSysMem = indices;
- RETURN_IF_FAILED(device_->CreateBuffer(&index_buffer, &init_data,
- index_buffer_.Receive()));
-}
-
-ID3D10Buffer* CompositorWin::CreateVertexBufferForRegion(
- const gfx::Rect& bounds) {
- float x = static_cast<float>(bounds.x()) /
- static_cast<float>(size().width()) * 2.0f - 1.0f;
- float max_x =
- x + bounds.width() / static_cast<float>(size().width()) * 2.0f;
- float y =
- static_cast<float>(size().height() - bounds.y() - bounds.height()) /
- static_cast<float>(size().height()) * 2.0f - 1.0f;
- float max_y =
- y + bounds.height() / static_cast<float>(size().height()) * 2.0f;
- float tex_x = x / 2.0f + .5f;
- float max_tex_x = max_x / 2.0f + .5f;
- float tex_y = 1.0f - (max_y + 1.0f) / 2.0f;
- float max_tex_y = tex_y + (max_y - y) / 2.0f;
- Vertex vertices[] = {
- { D3DXVECTOR3( x, y, 0.0f), D3DXVECTOR2( tex_x, max_tex_y) },
- { D3DXVECTOR3( x, max_y, 0.0f), D3DXVECTOR2( tex_x, tex_y) },
- { D3DXVECTOR3(max_x, max_y, 0.0f), D3DXVECTOR2(max_tex_x, tex_y) },
- { D3DXVECTOR3(max_x, y, 0.0f), D3DXVECTOR2(max_tex_x, max_tex_y) },
- };
-
- // Create the vertex buffer containing the points.
- D3D10_BUFFER_DESC buffer_desc;
- buffer_desc.Usage = D3D10_USAGE_IMMUTABLE;
- buffer_desc.ByteWidth = sizeof(Vertex) * ARRAYSIZE_UNSAFE(vertices);
- buffer_desc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
- buffer_desc.CPUAccessFlags = 0;
- buffer_desc.MiscFlags = 0;
- D3D10_SUBRESOURCE_DATA init_data;
- init_data.pSysMem = vertices;
- ID3D10Buffer* vertex_buffer = NULL;
- // TODO: better error handling.
- int error_code =
- device_->CreateBuffer(&buffer_desc, &init_data, &vertex_buffer);
- if (error_code != S_OK) {
- Errored(error_code);
- return NULL;
- }
- return vertex_buffer;
-}
-
-} // namespace
-
-// static
-Compositor* Compositor::Create(CompositorDelegate* delegate,
- gfx::AcceleratedWidget widget,
- const gfx::Size& size) {
- CompositorWin* compositor = new CompositorWin(delegate, widget, size);
- compositor->Init();
- return compositor;
-}
-
-} // namespace ui
diff --git a/ui/gfx/compositor/debug_utils.cc b/ui/gfx/compositor/debug_utils.cc
index 52597e8..0176ece 100644
--- a/ui/gfx/compositor/debug_utils.cc
+++ b/ui/gfx/compositor/debug_utils.cc
@@ -46,13 +46,6 @@ void PrintLayerHierarchyImp(const Layer* layer, int indent,
buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y();
buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height();
- if (!layer->hole_rect().IsEmpty()) {
- buf << L'\n' << UTF8ToWide(content_indent_str);
- gfx::Rect hole_rect = layer->hole_rect();
- buf << L"hole: " << hole_rect.x() << L',' << hole_rect.y();
- buf << L' ' << hole_rect.width() << L'x' << hole_rect.height();
- }
-
if (layer->opacity() != 1.0f) {
buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"opacity: " << std::setprecision(2) << layer->opacity();
diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc
index 4b7529e..2220f82 100644
--- a/ui/gfx/compositor/layer.cc
+++ b/ui/gfx/compositor/layer.cc
@@ -22,9 +22,7 @@
#include "ui/gfx/interpolated_transform.h"
#include "ui/gfx/point3.h"
-#if defined(USE_WEBKIT_COMPOSITOR)
#include "ui/gfx/compositor/compositor_cc.h"
-#endif
namespace {
@@ -49,13 +47,10 @@ Layer::Layer()
parent_(NULL),
visible_(true),
fills_bounds_opaquely_(true),
- recompute_hole_(false),
layer_updated_externally_(false),
opacity_(1.0f),
delegate_(NULL) {
-#if defined(USE_WEBKIT_COMPOSITOR)
CreateWebLayer();
-#endif
}
Layer::Layer(LayerType type)
@@ -64,13 +59,10 @@ Layer::Layer(LayerType type)
parent_(NULL),
visible_(true),
fills_bounds_opaquely_(true),
- recompute_hole_(false),
layer_updated_externally_(false),
opacity_(1.0f),
delegate_(NULL) {
-#if defined(USE_WEBKIT_COMPOSITOR)
CreateWebLayer();
-#endif
}
Layer::~Layer() {
@@ -80,9 +72,7 @@ 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() {
@@ -104,11 +94,7 @@ 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
-
- SetNeedsToRecomputeHole();
}
void Layer::Remove(Layer* child) {
@@ -117,13 +103,7 @@ 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
-
- SetNeedsToRecomputeHole();
-
- child->DropTextures();
}
void Layer::StackAtTop(Layer* child) {
@@ -200,19 +180,9 @@ void Layer::SetVisible(bool visible) {
if (visible_ == visible)
return;
- bool was_drawn = IsDrawn();
visible_ = visible;
-#if defined(USE_WEBKIT_COMPOSITOR)
// TODO(piman): Expose a visibility flag on WebLayer.
web_layer_.setOpacity(visible_ ? opacity_ : 0.f);
-#endif
- bool is_drawn = IsDrawn();
- if (was_drawn == is_drawn)
- return;
-
- if (!is_drawn)
- DropTextures();
- SetNeedsToRecomputeHole();
}
bool Layer::IsDrawn() const {
@@ -223,8 +193,7 @@ bool Layer::IsDrawn() const {
}
bool Layer::ShouldDraw() const {
- return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f &&
- !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size()));
+ return type_ == LAYER_HAS_TEXTURE && GetCombinedOpacity() > 0.0f;
}
// static
@@ -249,17 +218,13 @@ void Layer::SetFillsBoundsOpaquely(bool fills_bounds_opaquely) {
fills_bounds_opaquely_ = fills_bounds_opaquely;
- SetNeedsToRecomputeHole();
-#if defined(USE_WEBKIT_COMPOSITOR)
web_layer_.setOpaque(fills_bounds_opaquely);
RecomputeDebugBorderColor();
-#endif
}
void Layer::SetExternalTexture(ui::Texture* texture) {
layer_updated_externally_ = !!texture;
texture_ = texture;
-#if defined(USE_WEBKIT_COMPOSITOR)
if (web_layer_is_accelerated_ != layer_updated_externally_) {
// Switch to a different type of layer.
web_layer_.removeAllChildren();
@@ -293,25 +258,13 @@ void Layer::SetExternalTexture(ui::Texture* texture) {
texture_layer.setFlipped(texture_cc->flipped());
}
RecomputeDrawsContentAndUVRect();
-#endif
}
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())
- texture_ = GetCompositor()->CreateTexture();
-
- 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(),
@@ -321,10 +274,6 @@ void Layer::SchedulePaint(const gfx::Rect& invalid_rect) {
web_layer_.to<WebKit::WebContentLayer>().invalidateRect(web_rect);
else
web_layer_.to<WebKit::WebExternalTextureLayer>().invalidateRect(web_rect);
-#else
- invalid_rect_ = invalid_rect_.Union(invalid_rect);
- ScheduleDraw();
-#endif
}
void Layer::ScheduleDraw() {
@@ -333,87 +282,12 @@ void Layer::ScheduleDraw() {
compositor->ScheduleDraw();
}
-void Layer::Draw() {
- TRACE_EVENT0("ui", "Layer::Draw");
-#if defined(USE_WEBKIT_COMPOSITOR)
- NOTREACHED();
-#else
- DCHECK(GetCompositor());
-
- if (recompute_hole_ && !parent_)
- RecomputeHole();
-
- if (!ShouldDraw())
- return;
-
- UpdateLayerCanvas();
-
- // Layer drew nothing, no texture was created.
- if (!texture_.get())
- return;
-
- ui::TextureDrawParams texture_draw_params;
- for (Layer* layer = this; layer; layer = layer->parent_) {
- texture_draw_params.transform.ConcatTransform(layer->transform_);
- texture_draw_params.transform.ConcatTranslate(
- static_cast<float>(layer->bounds_.x()),
- static_cast<float>(layer->bounds_.y()));
- }
-
- const float combined_opacity = GetCombinedOpacity();
-
- // Only blend for transparent child layers (and when we're forcing
- // transparency). The root layer will clobber the cleared bg.
- const bool is_root = parent_ == NULL;
- const bool forcing_transparency = combined_opacity < 1.0f;
- const bool is_opaque = fills_bounds_opaquely_ || !has_valid_alpha_channel();
- texture_draw_params.blend = !is_root && (forcing_transparency || !is_opaque);
-
- texture_draw_params.compositor_size = GetCompositor()->size();
- texture_draw_params.opacity = combined_opacity;
- texture_draw_params.has_valid_alpha_channel = has_valid_alpha_channel();
-
-#if defined(OS_WIN)
- // TODO(beng): figure out why the other branch of this code renders improperly
- // on Windows, and fix it, otherwise just remove all of this when
- // WK compositor is default.
- texture_->Draw(texture_draw_params, gfx::Rect(gfx::Point(), bounds().size()));
-#else
- std::vector<gfx::Rect> regions_to_draw;
- PunchHole(gfx::Rect(gfx::Point(), bounds().size()), hole_rect_,
- &regions_to_draw);
-
- for (size_t i = 0; i < regions_to_draw.size(); ++i) {
- if (!regions_to_draw[i].IsEmpty())
- texture_->Draw(texture_draw_params, regions_to_draw[i]);
- }
-#endif
-#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::paintContents(WebKit::WebCanvas* web_canvas,
const WebKit::WebRect& clip) {
TRACE_EVENT0("ui", "Layer::paintContents");
-#if defined(USE_WEBKIT_COMPOSITOR)
gfx::CanvasSkia canvas(web_canvas);
if (delegate_)
delegate_->OnPaintLayer(&canvas);
-#else
- NOTREACHED();
-#endif
}
float Layer::GetCombinedOpacity() const {
@@ -426,31 +300,6 @@ float Layer::GetCombinedOpacity() const {
return opacity;
}
-void Layer::UpdateLayerCanvas() {
- TRACE_EVENT0("ui", "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_)
- return;
- gfx::Rect local_bounds = gfx::Rect(gfx::Point(), bounds_.size());
- gfx::Rect draw_rect = texture_.get() ? invalid_rect_.Intersect(local_bounds) :
- local_bounds;
- if (draw_rect.IsEmpty()) {
- invalid_rect_ = gfx::Rect();
- return;
- }
- scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas(draw_rect.size(),
- false));
- canvas->Translate(gfx::Point().Subtract(draw_rect.origin()));
- if (delegate_)
- delegate_->OnPaintLayer(canvas.get());
- SetCanvas(*canvas->GetSkCanvas(), draw_rect.origin());
-#endif
-}
-
void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) {
DCHECK_NE(child, other);
DCHECK_EQ(this, child->parent());
@@ -470,27 +319,8 @@ void Layer::StackRelativeTo(Layer* child, Layer* other, bool above) {
children_.erase(children_.begin() + child_i);
children_.insert(children_.begin() + dest_i, child);
- SetNeedsToRecomputeHole();
-
-#if defined(USE_WEBKIT_COMPOSITOR)
child->web_layer_.removeFromParent();
web_layer_.insertChild(child->web_layer_, dest_i);
-#endif
-}
-
-void Layer::SetNeedsToRecomputeHole() {
- Layer* root_layer = this;
- while (root_layer->parent_)
- root_layer = root_layer->parent_;
-
- root_layer->recompute_hole_ = true;
-}
-
-void Layer::ClearHoleRects() {
- hole_rect_ = gfx::Rect();
-
- for (size_t i = 0; i < children_.size(); i++)
- children_[i]->ClearHoleRects();
}
void Layer::GetLayerProperties(const ui::Transform& parent_transform,
@@ -517,110 +347,6 @@ void Layer::GetLayerProperties(const ui::Transform& parent_transform,
children_[i]->GetLayerProperties(current_transform, traversal);
}
-void Layer::RecomputeHole() {
- std::vector<LayerProperties> traversal;
- ui::Transform transform;
-
- ClearHoleRects();
- GetLayerProperties(transform, &traversal);
-
- for (size_t i = 0; i < traversal.size(); i++) {
- Layer* layer = traversal[i].layer;
- gfx::Rect bounds = gfx::Rect(layer->bounds().size());
-
- // Iterate through layers which are after traversal[i] in draw order
- // and find the largest candidate hole.
- for (size_t j = i + 1; j < traversal.size(); j++) {
- gfx::Rect candidate_hole = gfx::Rect(traversal[j].layer->bounds().size());
-
- // Compute transform to go from bounds of layer |j| to local bounds of
- // layer |i|.
- ui::Transform candidate_hole_transform;
- ui::Transform inverted;
-
- candidate_hole_transform.ConcatTransform(
- traversal[j].transform_relative_to_root);
-
- if (!traversal[i].transform_relative_to_root.GetInverse(&inverted))
- continue;
-
- candidate_hole_transform.ConcatTransform(inverted);
-
- // cannot punch a hole if the relative transform between the two layers
- // is not multiple of 90.
- float degrees;
- gfx::Point p;
- if (!InterpolatedTransform::FactorTRS(candidate_hole_transform, &p,
- &degrees, NULL) || !IsApproximateMultilpleOf(degrees, 90.0f))
- continue;
-
- candidate_hole_transform.TransformRect(&candidate_hole);
- candidate_hole = candidate_hole.Intersect(bounds);
-
- if (candidate_hole.size().GetArea() >
- layer->hole_rect().size().GetArea()) {
- layer->set_hole_rect(candidate_hole);
- }
- }
- // Free up texture memory if the hole fills bounds of layer.
- if (!layer->ShouldDraw() && !layer_updated_externally())
- layer->DropTexture();
-
-#if defined(USE_WEBKIT_COMPOSITOR)
- RecomputeDrawsContentAndUVRect();
-#endif
- }
-
- recompute_hole_ = false;
-}
-
-// static
-void Layer::PunchHole(const gfx::Rect& rect,
- const gfx::Rect& region_to_punch_out,
- std::vector<gfx::Rect>* sides) {
- gfx::Rect trimmed_rect = rect.Intersect(region_to_punch_out);
-
- if (trimmed_rect.IsEmpty()) {
- sides->push_back(rect);
- return;
- }
-
- // Top (above the hole).
- sides->push_back(gfx::Rect(rect.x(),
- rect.y(),
- rect.width(),
- trimmed_rect.y() - rect.y()));
-
- // Left (of the hole).
- sides->push_back(gfx::Rect(rect.x(),
- trimmed_rect.y(),
- trimmed_rect.x() - rect.x(),
- trimmed_rect.height()));
-
- // Right (of the hole).
- sides->push_back(gfx::Rect(trimmed_rect.right(),
- trimmed_rect.y(),
- rect.right() - trimmed_rect.right(),
- trimmed_rect.height()));
-
- // Bottom (below the hole).
- sides->push_back(gfx::Rect(rect.x(),
- trimmed_rect.bottom(),
- rect.width(),
- rect.bottom() - trimmed_rect.bottom()));
-}
-
-void Layer::DropTexture() {
- if (!layer_updated_externally_)
- texture_ = NULL;
-}
-
-void Layer::DropTextures() {
- DropTexture();
- for (size_t i = 0; i < children_.size(); ++i)
- children_[i]->DropTextures();
-}
-
bool Layer::ConvertPointForAncestor(const Layer* ancestor,
gfx::Point* point) const {
ui::Transform transform;
@@ -666,37 +392,23 @@ void Layer::SetBoundsImmediately(const gfx::Rect& bounds) {
SchedulePaint(gfx::Rect(bounds.size()));
}
- SetNeedsToRecomputeHole();
-#if defined(USE_WEBKIT_COMPOSITOR)
RecomputeTransform();
RecomputeDrawsContentAndUVRect();
-#endif
}
void Layer::SetTransformImmediately(const ui::Transform& transform) {
transform_ = transform;
- SetNeedsToRecomputeHole();
-#if defined(USE_WEBKIT_COMPOSITOR)
RecomputeTransform();
-#endif
}
void Layer::SetOpacityImmediately(float opacity) {
bool schedule_draw = (opacity != opacity_ && IsDrawn());
- bool was_opaque = GetCombinedOpacity() == 1.0f;
opacity_ = opacity;
- bool is_opaque = GetCombinedOpacity() == 1.0f;
- // If our opacity has changed we need to recompute our hole, our parent's hole
- // and the holes of all our descendants.
- if (was_opaque != is_opaque)
- SetNeedsToRecomputeHole();
-#if defined(USE_WEBKIT_COMPOSITOR)
if (visible_)
web_layer_.setOpacity(opacity);
RecomputeDebugBorderColor();
-#endif
if (schedule_draw)
ScheduleDraw();
}
@@ -729,7 +441,6 @@ float Layer::GetOpacityForAnimation() const {
return opacity();
}
-#if defined(USE_WEBKIT_COMPOSITOR)
void Layer::CreateWebLayer() {
web_layer_ = WebKit::WebContentLayer::create(this);
web_layer_.setAnchorPoint(WebKit::WebFloatPoint(0.f, 0.f));
@@ -750,8 +461,7 @@ void Layer::RecomputeTransform() {
void Layer::RecomputeDrawsContentAndUVRect() {
DCHECK(!web_layer_.isNull());
- bool should_draw = type_ == LAYER_HAS_TEXTURE &&
- !hole_rect_.Contains(gfx::Rect(gfx::Point(0, 0), bounds_.size()));
+ bool should_draw = type_ == LAYER_HAS_TEXTURE;
if (!web_layer_is_accelerated_) {
web_layer_.to<WebKit::WebContentLayer>().setDrawsContent(should_draw);
web_layer_.setBounds(bounds_.size());
@@ -784,6 +494,5 @@ void Layer::RecomputeDebugBorderColor() {
color |= 0xFF;
web_layer_.setDebugBorderColor(color);
}
-#endif
} // namespace ui
diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h
index 51dd4ca..b1477cb 100644
--- a/ui/gfx/compositor/layer.h
+++ b/ui/gfx/compositor/layer.h
@@ -152,12 +152,6 @@ class COMPOSITOR_EXPORT Layer :
void SetFillsBoundsOpaquely(bool fills_bounds_opaquely);
bool fills_bounds_opaquely() const { return fills_bounds_opaquely_; }
- // Returns the invalid rectangle. That is, the region of the layer that needs
- // to be repainted. This is exposed for testing and isn't generally useful.
- const gfx::Rect& invalid_rect() const { return invalid_rect_; }
-
- const gfx::Rect& hole_rect() const { return hole_rect_; }
-
const std::string& name() const { return name_; }
void set_name(const std::string& name) { name_ = name; }
@@ -179,13 +173,6 @@ class COMPOSITOR_EXPORT Layer :
// Schedules a redraw of the layer tree at the compositor.
void ScheduleDraw();
- // Does drawing for the layer.
- void Draw();
-
- // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting
- // with the receiver.
- void DrawTree();
-
// Sometimes the Layer is being updated by something other than SetCanvas
// (e.g. the GPU process on UI_COMPOSITOR_IMAGE_TRANSPORT).
bool layer_updated_externally() const { return layer_updated_externally_; }
@@ -193,9 +180,7 @@ class COMPOSITOR_EXPORT Layer :
// WebContentLayerClient
virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip);
-#if defined(USE_WEBKIT_COMPOSITOR)
WebKit::WebLayer web_layer() { return web_layer_; }
-#endif
private:
struct LayerProperties {
@@ -210,66 +195,16 @@ class COMPOSITOR_EXPORT Layer :
// use the combined result, but this is only temporary.
float GetCombinedOpacity() const;
- // Called during the Draw() pass to freshen the Layer's contents from the
- // delegate.
- void UpdateLayerCanvas();
-
// Stacks |child| above or below |other|. Helper method for StackAbove() and
// StackBelow().
void StackRelativeTo(Layer* child, Layer* other, bool above);
- // Called to indicate that a layer's properties have changed and that the
- // holes for the layers must be recomputed.
- void SetNeedsToRecomputeHole();
-
- // Resets |hole_rect_| to the empty rect for all layers below and
- // including this one.
- void ClearHoleRects();
-
// Does a preorder traversal of layers starting with this layer. Omits layers
// which cannot punch a hole in another layer such as non visible layers
// and layers which don't fill their bounds opaquely.
void GetLayerProperties(const ui::Transform& current_transform,
std::vector<LayerProperties>* traverasal);
- // A hole in a layer is an area in the layer that does not get drawn
- // because this area is covered up with another layer which is known to be
- // opaque.
- // This method computes the dimension of the hole (if there is one)
- // based on whether one of its child nodes is always opaque.
- // Note: This method should only be called from the root.
- void RecomputeHole();
-
- void set_hole_rect(const gfx::Rect& hole_rect) {
- hole_rect_ = hole_rect;
- }
-
- // Determines the regions that don't intersect |rect| and places the
- // result in |sides|.
- //
- // rect_____________________________
- // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
- // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx|
- // |________________________________|
- // |xxxxx| |xxxxx|
- // |xxxxx|region_to_punch_out |xxxxx|
- // |left | |right|
- // |_____|____________________|_____|
- // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx|
- // |xxxxxxxxxx bottom xxxxxxxxxxxxxx|
- // |________________________________|
- static void PunchHole(const gfx::Rect& rect,
- const gfx::Rect& region_to_punch_out,
- std::vector<gfx::Rect>* sides);
-
- // Drops texture just for this layer.
- void DropTexture();
-
- // Drop all textures for layers below and including this one. Called when
- // the layer is removed from a hierarchy. Textures will be re-generated if
- // the layer is subsequently re-attached and needs to be drawn.
- void DropTextures();
-
bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const;
bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
@@ -296,12 +231,10 @@ class COMPOSITOR_EXPORT Layer :
virtual const Transform& GetTransformForAnimation() const OVERRIDE;
virtual float GetOpacityForAnimation() const OVERRIDE;
-#if defined(USE_WEBKIT_COMPOSITOR)
void CreateWebLayer();
void RecomputeTransform();
void RecomputeDrawsContentAndUVRect();
void RecomputeDebugBorderColor();
-#endif
const LayerType type_;
@@ -323,12 +256,6 @@ class COMPOSITOR_EXPORT Layer :
bool fills_bounds_opaquely_;
- gfx::Rect hole_rect_;
-
- bool recompute_hole_;
-
- gfx::Rect invalid_rect_;
-
// If true the layer is always up to date.
bool layer_updated_externally_;
@@ -340,11 +267,9 @@ class COMPOSITOR_EXPORT Layer :
scoped_ptr<LayerAnimator> animator_;
-#if defined(USE_WEBKIT_COMPOSITOR)
WebKit::WebLayer web_layer_;
bool web_layer_is_accelerated_;
bool show_debug_borders_;
-#endif
DISALLOW_COPY_AND_ASSIGN(Layer);
};
diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc
index 0140660..f5d3ac7 100644
--- a/ui/gfx/compositor/layer_unittest.cc
+++ b/ui/gfx/compositor/layer_unittest.cc
@@ -19,11 +19,7 @@
#include "ui/gfx/gfx_paths.h"
#include "ui/gfx/skia_util.h"
-#if defined(USE_WEBKIT_COMPOSITOR)
#include "ui/gfx/compositor/compositor_setup.h"
-#else
-#include "ui/gfx/compositor/test/test_compositor.h"
-#endif
namespace ui {
@@ -151,9 +147,7 @@ class LayerWithRealCompositorTest : public testing::Test {
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::DisableTestCompositor();
-#endif
const gfx::Rect host_bounds(10, 10, 500, 500);
window_.reset(TestCompositorHost::Create(host_bounds));
window_->Show();
@@ -367,12 +361,8 @@ class LayerWithDelegateTest : public testing::Test, public CompositorDelegate {
// Overridden from testing::Test:
virtual void SetUp() OVERRIDE {
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::SetupTestCompositor();
compositor_ = ui::Compositor::Create(this, NULL, gfx::Size(1000, 1000));
-#else
- compositor_ = new TestCompositor(this);
-#endif
}
virtual void TearDown() OVERRIDE {
@@ -618,409 +608,6 @@ class LayerWithNullDelegateTest : public LayerWithDelegateTest {
DISALLOW_COPY_AND_ASSIGN(LayerWithNullDelegateTest);
};
-// 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 NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) DISABLED_ ## X
-#else
-#define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) X
-#endif
-
-// Verifies that a layer which is set never to have a texture does not
-// get a texture when SetFillsBoundsOpaquely is called.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(
- LayerNoTextureSetFillsBoundsOpaquely)) {
- scoped_ptr<Layer> parent(CreateNoTextureLayer(gfx::Rect(0, 0, 400, 400)));
- scoped_ptr<Layer> child(CreateNoTextureLayer(gfx::Rect(50, 50, 100, 100)));
- parent->Add(child.get());
-
- compositor()->SetRootLayer(parent.get());
- parent->SetFillsBoundsOpaquely(true);
- child->SetFillsBoundsOpaquely(true);
- Draw();
- RunPendingMessages();
- EXPECT_TRUE(child->texture() == NULL);
- EXPECT_TRUE(parent->texture() == NULL);
-
- parent->SetFillsBoundsOpaquely(false);
- child->SetFillsBoundsOpaquely(false);
- Draw();
- RunPendingMessages();
- EXPECT_TRUE(child->texture() == NULL);
- EXPECT_TRUE(parent->texture() == NULL);
-}
-
-// Verifies that a layer does not have a texture when the hole is the size
-// of the parent layer.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(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());
-
- Draw();
- EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
- EXPECT_TRUE(parent->texture() != NULL);
-
- child->SetBounds(gfx::Rect(0, 0, 400, 400));
- Draw();
- EXPECT_TRUE(parent->texture() == NULL);
-}
-
-// Verifies that a layer which has opacity == 0 does not have a texture.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(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());
-
- parent->SetOpacity(0.0f);
- child->SetOpacity(0.0f);
- Draw();
- EXPECT_TRUE(parent->texture() == NULL);
- EXPECT_TRUE(child->texture() == NULL);
-
- parent->SetOpacity(1.0f);
- Draw();
- EXPECT_TRUE(parent->texture() != NULL);
- EXPECT_TRUE(child->texture() == NULL);
-
- child->SetOpacity(1.0f);
- Draw();
- EXPECT_TRUE(parent->texture() != NULL);
- EXPECT_TRUE(child->texture() != NULL);
-}
-
-// Verifies that no texture is created for a layer with empty bounds.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(LayerTextureNonEmptySchedulePaint)) {
- scoped_ptr<Layer> layer(CreateTextureRootLayer(gfx::Rect(0, 0, 0, 0)));
- Draw();
- EXPECT_TRUE(layer->texture() == NULL);
-
- layer->SetBounds(gfx::Rect(0, 0, 400, 400));
- Draw();
- EXPECT_TRUE(layer->texture() != NULL);
-}
-
-// Verifies that when there are many potential holes, the largest one is picked.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(LargestHole)) {
- scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> child1(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- parent->Add(child1.get());
-
- scoped_ptr<Layer> child2(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
- parent->Add(child2.get());
-
- Draw();
-
- EXPECT_EQ(gfx::Rect(75, 75, 200, 200), parent->hole_rect());
-}
-
-// Verifies that the largest hole in the draw order is picked
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(HoleGeneratedFromLeaf)) {
- // Layer tree looks like:
- // node 1
- // |_ node 11
- // |_ node 111
- // |_ node 12
- // |_ node 121
-
- scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- node1->Add(node11.get());
-
- scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(75, 75, 200, 200)));
- node1->Add(node12.get());
-
- scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
- node11->Add(node111.get());
-
- scoped_ptr<Layer> node121(CreateTextureLayer(gfx::Rect(10, 10, 190, 190)));
- node12->Add(node121.get());
-
- Draw();
-
- EXPECT_EQ(gfx::Rect(75, 75, 200, 200), node1->hole_rect());
- EXPECT_EQ(gfx::Rect(25, 25, 75, 75), node11->hole_rect());
- EXPECT_EQ(gfx::Rect(10, 10, 190, 190), node12->hole_rect());
-}
-
-// Verifies that a hole can only punched into a layer with opacity = 1.0f.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoHoleWhenPartialOpacity)) {
- // Layer tree looks like:
- // node 1
- // |_ node 11
- // |_ node 111
-
- scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- node1->Add(node11.get());
-
- scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
- node11->Add(node111.get());
-
- Draw();
- EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
- EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
-
-
- node11->SetOpacity(0.5f);
- Draw();
- EXPECT_TRUE(node1->hole_rect().IsEmpty());
- EXPECT_TRUE(node11->hole_rect().IsEmpty());
-}
-
-// Verifies that a non visible layer or any of its children is not a hole.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NonVisibleLayerCannotBeHole)) {
- // Layer tree looks like:
- // node 1
- // |_ node 11
- // |_ node 111
-
- scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- node1->Add(node11.get());
-
- scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
- node11->Add(node111.get());
-
- Draw();
- EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
- EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
-
-
- node11->SetVisible(false);
- Draw();
- EXPECT_TRUE(node1->hole_rect().IsEmpty());
- EXPECT_TRUE(node11->hole_rect().IsEmpty());
-}
-
-// Verifies that a layer which doesn't fill its bounds opaquely cannot punch a
-// hole. However its children should still be able to punch a hole.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(
- LayerNotFillingBoundsOpaquelyCannotBeHole)) {
- // Layer tree looks like:
- // node 1
- // |_ node 11
- // |_ node 111
-
- scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- node1->Add(node11.get());
-
- scoped_ptr<Layer> node111(CreateTextureLayer(gfx::Rect(10, 10, 20, 20)));
- node11->Add(node111.get());
-
- Draw();
- EXPECT_EQ(gfx::Rect(50, 50, 100, 100), node1->hole_rect());
- EXPECT_EQ(gfx::Rect(10, 10, 20, 20), node11->hole_rect());
-
-
- node11->SetFillsBoundsOpaquely(false);
- Draw();
- EXPECT_EQ(gfx::Rect(60, 60, 20, 20), node1->hole_rect());
- EXPECT_TRUE(node11->hole_rect().IsEmpty());
-}
-
-// Verifies that the hole is with respect to the local bounds of its parent.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(HoleLocalBounds)) {
- scoped_ptr<Layer> parent(CreateTextureRootLayer(
- gfx::Rect(100, 100, 150, 150)));
-
- scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 100, 100)));
- parent->Add(child.get());
-
- Draw();
-
- EXPECT_EQ(gfx::Rect(50, 50, 100, 100), parent->hole_rect());
-}
-
-// Verifies that there is no hole present when one of the child layers has a
-// transform.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(NoHoleWithTransform)) {
- 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());
-
- Draw();
-
- EXPECT_TRUE(!parent->hole_rect().IsEmpty());
-
- ui::Transform t;
- t.SetTranslate(-50, -50);
- t.ConcatRotate(45.0f);
- t.ConcatTranslate(50, 50);
- child->SetTransform(t);
-
- Draw();
-
- EXPECT_EQ(gfx::Rect(0, 0, 0, 0), parent->hole_rect());
-}
-
-// Verifies that if the child layer is rotated by a multiple of ninety degrees
-// we punch a hole
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(HoleWithNinetyDegreeTransforms)) {
- scoped_ptr<Layer> parent(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
- scoped_ptr<Layer> child(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
- parent->Add(child.get());
-
- Draw();
-
- EXPECT_TRUE(!parent->hole_rect().IsEmpty());
-
- for (int i = -4; i <= 4; ++i) {
- SCOPED_TRACE(::testing::Message() << "Iteration " << i);
-
- ui::Transform t;
- // Need to rotate in local coordinates.
- t.SetTranslate(-25, -25);
- t.ConcatRotate(90.0f * i);
- t.ConcatTranslate(25, 25);
- child->SetTransform(t);
-
- gfx::Rect target_rect(child->bounds().size());
- t.ConcatTranslate(child->bounds().x(), child->bounds().y());
- t.TransformRect(&target_rect);
-
- Draw();
-
- EXPECT_EQ(target_rect, parent->hole_rect());
- }
-}
-
-// Verifies that a layer which doesn't have a texture cannot punch a
-// hole. However its children should still be able to punch a hole.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(
- HoleWithRelativeNinetyDegreeTransforms)) {
- // Layer tree looks like:
- // node 1
- // |_ node 11
- // |_ node 12
-
- scoped_ptr<Layer> node1(CreateTextureRootLayer(gfx::Rect(0, 0, 400, 400)));
-
- scoped_ptr<Layer> node11(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
- node1->Add(node11.get());
-
- scoped_ptr<Layer> node12(CreateTextureLayer(gfx::Rect(50, 50, 50, 50)));
- node1->Add(node12.get());
-
- Draw();
-
- EXPECT_EQ(gfx::Rect(0, 0, 50, 50), node11->hole_rect());
- EXPECT_TRUE(node12->hole_rect().IsEmpty());
-
- ui::Transform t1;
- // Need to rotate in local coordinates.
- t1.SetTranslate(-25, -25);
- t1.ConcatRotate(45.0f);
- t1.ConcatTranslate(25, 25);
- node11->SetTransform(t1);
-
- Draw();
-
- EXPECT_TRUE(node12->hole_rect().IsEmpty());
- EXPECT_TRUE(node11->hole_rect().IsEmpty());
-
- ui::Transform t2;
- // Need to rotate in local coordinates.
- t2.SetTranslate(-25, -25);
- t2.ConcatRotate(-135.0f);
- t2.ConcatTranslate(25, 25);
- node12->SetTransform(t2);
-
- // Do translation of target rect in order to account for inprecision of
- // using floating point matrices vs integer rects.
- ui::Transform t3;
- gfx::Rect target_rect = gfx::Rect(node11->bounds().size());
- t3.ConcatTransform(t2);
- t1.GetInverse(&t1);
- t3.ConcatTransform(t1);
- t3.TransformRect(&target_rect);
-
- Draw();
-
- EXPECT_TRUE(node12->hole_rect().IsEmpty());
- EXPECT_EQ(target_rect, node11->hole_rect());
-}
-
-// Create this hierarchy:
-// L1 (no texture)
-// +- L11 (texture)
-// +- L12 (no texture) (added after L1 is already set as root-layer)
-// +- L121 (texture)
-// +- L122 (texture)
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(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));
- scoped_ptr<Layer> l121(CreateLayer(Layer::LAYER_HAS_TEXTURE));
- scoped_ptr<Layer> l122(CreateLayer(Layer::LAYER_HAS_TEXTURE));
-
- EXPECT_EQ(NULL, l1->texture());
- EXPECT_EQ(NULL, l11->texture());
- EXPECT_EQ(NULL, l12->texture());
- EXPECT_EQ(NULL, l121->texture());
- EXPECT_EQ(NULL, l122->texture());
-
- l1->Add(l11.get());
- l1->SetBounds(gfx::Rect(0, 0, 500, 500));
- l11->SetBounds(gfx::Rect(5, 5, 490, 490));
-
- EXPECT_EQ(NULL, l11->texture());
-
- compositor()->SetRootLayer(l1.get());
-
- EXPECT_EQ(NULL, l1->texture());
-
- // Despite having type LAYER_HAS_TEXTURE, l11 will not have one set yet
- // because it has never been asked to draw.
- EXPECT_EQ(NULL, l11->texture());
-
- l12->Add(l121.get());
- l12->Add(l122.get());
- l12->SetBounds(gfx::Rect(5, 5, 480, 480));
- l121->SetBounds(gfx::Rect(5, 5, 100, 100));
- l122->SetBounds(gfx::Rect(110, 110, 100, 100));
-
- EXPECT_EQ(NULL, l121->texture());
- EXPECT_EQ(NULL, l122->texture());
-
- l1->Add(l12.get());
-
- // By asking l121 and l122 to paint, we cause them to generate a texture.
- SchedulePaintForLayer(l121.get());
- SchedulePaintForLayer(l122.get());
- Draw();
-
- EXPECT_EQ(NULL, l12->texture());
- EXPECT_TRUE(NULL != l121->texture());
- EXPECT_TRUE(NULL != l122->texture());
-
- // Toggling l2's visibility should drop all sub-layer textures.
- l12->SetVisible(false);
- EXPECT_EQ(NULL, l12->texture());
- EXPECT_EQ(NULL, l121->texture());
- EXPECT_EQ(NULL, l122->texture());
-}
-
// Various visibile/drawn assertions.
TEST_F(LayerWithNullDelegateTest, Visibility) {
scoped_ptr<Layer> l1(new Layer(Layer::LAYER_HAS_TEXTURE));
@@ -1038,11 +625,9 @@ TEST_F(LayerWithNullDelegateTest, Visibility) {
EXPECT_TRUE(l1->IsDrawn());
EXPECT_TRUE(l2->IsDrawn());
EXPECT_TRUE(l3->IsDrawn());
-#if defined(USE_WEBKIT_COMPOSITOR)
EXPECT_EQ(1.f, l1->web_layer().opacity());
EXPECT_EQ(1.f, l2->web_layer().opacity());
EXPECT_EQ(1.f, l3->web_layer().opacity());
-#endif
compositor()->SetRootLayer(l1.get());
@@ -1052,25 +637,19 @@ TEST_F(LayerWithNullDelegateTest, Visibility) {
EXPECT_FALSE(l1->IsDrawn());
EXPECT_FALSE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
-#if defined(USE_WEBKIT_COMPOSITOR)
EXPECT_EQ(0.f, l1->web_layer().opacity());
-#endif
l3->SetVisible(false);
EXPECT_FALSE(l1->IsDrawn());
EXPECT_FALSE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
-#if defined(USE_WEBKIT_COMPOSITOR)
EXPECT_EQ(0.f, l3->web_layer().opacity());
-#endif
l1->SetVisible(true);
EXPECT_TRUE(l1->IsDrawn());
EXPECT_TRUE(l2->IsDrawn());
EXPECT_FALSE(l3->IsDrawn());
-#if defined(USE_WEBKIT_COMPOSITOR)
EXPECT_EQ(1.f, l1->web_layer().opacity());
-#endif
}
// Checks that stacking-related methods behave as advertised.
@@ -1132,28 +711,6 @@ TEST_F(LayerWithNullDelegateTest, Stacking) {
EXPECT_EQ("2,3,1", GetLayerChildrenNames(*root.get()));
}
-// Checks that the invalid rect assumes correct values when setting bounds.
-// TODO(vollick): for USE_WEBKIT_COMPOSITOR, use WebKit's dirty rect.
-TEST_F(LayerWithNullDelegateTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(SetBoundsInvalidRect)) {
- scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200)));
- compositor()->SetRootLayer(l1.get());
-
- // After a draw the invalid rect should be empty.
- Draw();
- EXPECT_TRUE(l1->invalid_rect().IsEmpty());
-
- // After a move the invalid rect should be empty.
- l1->SetBounds(gfx::Rect(5, 5, 200, 200));
- EXPECT_TRUE(l1->invalid_rect().IsEmpty());
-
- // Bounds change should trigger both the invalid rect to update as well as
- // CompositorDelegate being told to draw.
- l1->SetBounds(gfx::Rect(5, 5, 100, 100));
- EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
- l1->invalid_rect().ToString());
-}
-
// Verifies SetBounds triggers the appropriate painting/drawing.
TEST_F(LayerWithNullDelegateTest, SetBoundsSchedulesPaint) {
scoped_ptr<Layer> l1(CreateTextureLayer(gfx::Rect(0, 0, 200, 200)));
diff --git a/ui/gfx/compositor/test/compositor_test_support.cc b/ui/gfx/compositor/test/compositor_test_support.cc
index 20b0f49..ba76f62 100644
--- a/ui/gfx/compositor/test/compositor_test_support.cc
+++ b/ui/gfx/compositor/test/compositor_test_support.cc
@@ -1,18 +1,15 @@
-// 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.
#include "ui/gfx/compositor/test/compositor_test_support.h"
-#if defined(USE_WEBKIT_COMPOSITOR)
#include "base/compiler_specific.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
#include "webkit/glue/webkitplatformsupport_impl.h"
-#endif
namespace ui {
-#if defined(USE_WEBKIT_COMPOSITOR)
class CompositorTestPlatformSupport:
public NON_EXPORTED_BASE(webkit_glue::WebKitPlatformSupportImpl) {
public:
@@ -44,23 +41,18 @@ class CompositorTestPlatformSupport:
};
static CompositorTestPlatformSupport* g_webkit_support;
-#endif
void CompositorTestSupport::Initialize() {
-#if defined(USE_WEBKIT_COMPOSITOR)
DCHECK(!g_webkit_support);
g_webkit_support = new CompositorTestPlatformSupport;
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/test/test_compositor.cc b/ui/gfx/compositor/test/test_compositor.cc
deleted file mode 100644
index f3eb7ec..0000000
--- a/ui/gfx/compositor/test/test_compositor.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// 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/test/test_compositor.h"
-
-#include "ui/gfx/compositor/test/test_texture.h"
-
-namespace ui {
-
-class TestCompositorDelegate : public ui::CompositorDelegate {
- public:
- TestCompositorDelegate() {}
- virtual ~TestCompositorDelegate() {}
-
- virtual void ScheduleDraw() OVERRIDE {}
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestCompositorDelegate);
-};
-
-TestCompositor::TestCompositor(CompositorDelegate *owner)
- : Compositor((owner ? owner : new TestCompositorDelegate),
- gfx::Size(100, 100)) {
- if (!owner)
- owned_delegate_.reset(static_cast<TestCompositorDelegate*>(delegate()));
-}
-
-TestCompositor::~TestCompositor() {
-}
-
-ui::Texture* TestCompositor::CreateTexture() {
- return new TestTexture();
-}
-
-void TestCompositor::OnNotifyStart(bool clear) {
-}
-
-void TestCompositor::OnNotifyEnd() {
-}
-
-void TestCompositor::Blur(const gfx::Rect& bounds) {
-}
-
-void TestCompositor::DrawTree() {
-#if !defined(USE_WEBKIT_COMPOSITOR)
- Compositor::DrawTree();
-#endif
-}
-
-bool TestCompositor::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) {
- return false;
-}
-
-ui::Compositor* TestCompositor::Create(ui::CompositorDelegate* owner) {
- return new ui::TestCompositor(owner);
-}
-
-void TestCompositor::OnWidgetSizeChanged() {
-}
-
-} // namespace ui
diff --git a/ui/gfx/compositor/test/test_compositor.h b/ui/gfx/compositor/test/test_compositor.h
deleted file mode 100644
index 8cfc251..0000000
--- a/ui/gfx/compositor/test/test_compositor.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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_TEST_COMPOSITOR_H_
-#define UI_GFX_COMPOSITOR_TEST_TEST_COMPOSITOR_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/compiler_specific.h"
-#include "ui/gfx/compositor/compositor.h"
-
-namespace ui {
-
-class TestCompositorDelegate;
-
-// Trivial Compositor implementation that creates Textures of type TestTexture.
-class TestCompositor : public ui::Compositor {
- public:
- explicit TestCompositor(CompositorDelegate* owner);
- virtual ~TestCompositor();
-
- // ui::Compositor:
- virtual ui::Texture* CreateTexture() OVERRIDE;
- virtual void OnNotifyStart(bool clear) OVERRIDE;
- virtual void OnNotifyEnd() OVERRIDE;
- virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
- virtual void DrawTree() OVERRIDE;
- virtual bool ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds) OVERRIDE;
-
- // A simple factory that creates a test compositor with a given delegate
- static ui::Compositor* Create(ui::CompositorDelegate* owner);
-
- protected:
- virtual void OnWidgetSizeChanged() OVERRIDE;
-
- private:
- scoped_ptr<TestCompositorDelegate> owned_delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(TestCompositor);
-};
-
-} // namespace ui
-
-#endif // UI_GFX_COMPOSITOR_TEST_TEST_COMPOSITOR_H_
diff --git a/ui/gfx/compositor/test/test_suite.cc b/ui/gfx/compositor/test/test_suite.cc
index 2ac22d4..0072fe4 100644
--- a/ui/gfx/compositor/test/test_suite.cc
+++ b/ui/gfx/compositor/test/test_suite.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.
@@ -6,16 +6,12 @@
#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_cc.h"
#include "ui/gfx/compositor/test/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) {}
@@ -28,23 +24,16 @@ void CompositorTestSuite::Initialize() {
base::TestSuite::Initialize();
gfx::RegisterPathProvider();
- ui::RegisterPathProvider();
message_loop_.reset(new MessageLoop(MessageLoop::TYPE_UI));
ui::CompositorTestSupport::Initialize();
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::CompositorCC::Initialize(false);
-#endif
}
void CompositorTestSuite::Shutdown() {
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::CompositorCC::Terminate();
-#endif
ui::CompositorTestSupport::Terminate();
message_loop_.reset();
- ui::ResourceBundle::CleanupSharedInstance();
-
base::TestSuite::Shutdown();
}
diff --git a/ui/gfx/gfx_resources.grd b/ui/gfx/gfx_resources.grd
index 971b990..aa9be6a 100644
--- a/ui/gfx/gfx_resources.grd
+++ b/ui/gfx/gfx_resources.grd
@@ -15,8 +15,6 @@
<!-- IDR_BITMAP_BRUSH_IMAGE is for canvas_direct2d_unittest on win -->
<!-- TODO(sky): we don't want a test only image in the release builds -->
<include name="IDR_BITMAP_BRUSH_IMAGE" file="resources\bitmap_brush_image.png" type="BINDATA" />
- <include name="IDR_COMPOSITOR_FX" file="resources\compositor.fx" type="BINDATA" />
- <include name="IDR_BLUR_FX" file="resources\blur.fx" type="BINDATA" />
</if>
<if expr="is_posix and not is_macosx and not pp_ifdef('use_aura')">
diff --git a/ui/gfx/resources/blur.fx b/ui/gfx/resources/blur.fx
deleted file mode 100644
index 2f0de7a..0000000
--- a/ui/gfx/resources/blur.fx
+++ /dev/null
@@ -1,74 +0,0 @@
-// 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.
-
-// Pixel shader used to do a bloom. It's expected that the consumers set
-// TexelKernel before using.
-
-Texture2D textureMap;
-
-cbuffer cbPerObject {
- float4x4 gWVP;
-};
-
-struct VS_IN {
- float3 posL : POSITION;
- float2 texC : TEXC;
-};
-
-struct VS_OUT {
- float4 posW : SV_POSITION;
- float2 texC : TEXC;
-};
-
-SamplerState Sampler {
- Filter = MIN_MAG_MIP_POINT;
- AddressU = Clamp;
- AddressV = Clamp;
-};
-
-VS_OUT VS(VS_IN vIn) {
- VS_OUT vOut;
- vOut.posW = mul(float4(vIn.posL, 1.0f), gWVP);
- vOut.texC = vIn.texC;
- return vOut;
-}
-
-// Size of the kernel.
-static const int g_cKernelSize = 13;
-
-static const float BlurWeights[g_cKernelSize] = {
-1.0f / 4096.0f,
-12.0f / 4096.0f,
-66.0f / 4096.0f,
-220.0f / 4096.0f,
-495.0f / 4096.0f,
-792.0f / 4096.0f,
-924.0f / 4096.0f,
-792.0f / 4096.0f,
-495.0f / 4096.0f,
-220.0f / 4096.0f,
-66.0f / 4096.0f,
-12.0f / 4096.0f,
-1.0f / 4096.0f,
-};
-
-// Set by consumer as it depends upon width/height of viewport.
-float4 TexelKernel[g_cKernelSize];
-
-float4 PS(VS_OUT pIn) : SV_Target {
- float4 c = 0;
- for (int i = 0; i < g_cKernelSize; i++) {
- c += textureMap.Sample(Sampler, float2(pIn.texC) + TexelKernel[i].xy) *
- BlurWeights[i];
- }
- return c;
-}
-
-technique10 ViewTech {
- pass P0 {
- SetVertexShader(CompileShader(vs_4_0, VS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(ps_4_0, PS()));
- }
-}
diff --git a/ui/gfx/resources/compositor.fx b/ui/gfx/resources/compositor.fx
deleted file mode 100644
index 5dee8e2..0000000
--- a/ui/gfx/resources/compositor.fx
+++ /dev/null
@@ -1,69 +0,0 @@
-// 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.
-
-// HLSL file used by views.
-
-Texture2D textureMap;
-
-// Blender to give source-over for textures.
-BlendState SrcAlphaBlendingAdd {
- BlendEnable[0] = TRUE;
- SrcBlend = ONE;
- DestBlend = INV_SRC_ALPHA;
- BlendOp = ADD;
- SrcBlendAlpha = ONE;
- DestBlendAlpha = INV_SRC_ALPHA;
- BlendOpAlpha = ADD;
- RenderTargetWriteMask[0] = 0x0F; // Enables for all color components.
-};
-
-// Avoids doing depth detection, which would normally mean only the frontmost
-// texture is drawn.
-DepthStencilState StencilState {
- DepthEnable = false;
-};
-
-cbuffer cbPerObject {
- float4x4 gWVP;
-};
-
-struct VS_IN {
- float3 posL : POSITION;
- float2 texC : TEXC;
-};
-
-struct VS_OUT {
- float4 posW : SV_POSITION;
- float2 texC : TEXC;
-};
-
-SamplerState Sampler {
- Filter = MIN_MAG_MIP_POINT;
- AddressU = Wrap;
- AddressV = Wrap;
-};
-
-VS_OUT VS(VS_IN vIn) {
- VS_OUT vOut;
- vOut.posW = mul(float4(vIn.posL, 1.0f), gWVP);
- vOut.texC = vIn.texC;
- return vOut;
-}
-
-float alpha = 1.0f;
-
-float4 PS(VS_OUT pIn) : SV_Target {
- return textureMap.Sample(Sampler, float2(pIn.texC)) * alpha;
-}
-
-technique10 ViewTech {
- pass P0 {
- SetVertexShader(CompileShader(vs_4_0, VS()));
- SetGeometryShader(NULL);
- SetPixelShader(CompileShader(ps_4_0, PS()));
- SetDepthStencilState(StencilState, 0);
- SetBlendState(SrcAlphaBlendingAdd, float4(0.0f, 0.0f, 0.0f, 0.0f),
- 0xFFFFFFFF);
- }
-}
diff --git a/ui/gfx/test/gfx_test_utils.cc b/ui/gfx/test/gfx_test_utils.cc
deleted file mode 100644
index 1d66ed7..0000000
--- a/ui/gfx/test/gfx_test_utils.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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/test/gfx_test_utils.h"
-
-#if defined(VIEWS_COMPOSITOR)
-#include "base/command_line.h"
-#include "ui/gfx/compositor/compositor.h"
-#include "ui/gfx/compositor/test/test_compositor.h"
-#endif
-
-#if defined(VIEWS_COMPOSITOR)
-namespace switches {
-
-const char kDisableTestCompositor[] = "disable-test-compositor";
-
-}
-#endif
-
-namespace ui {
-namespace gfx_test_utils {
-
-void SetupTestCompositor() {
-#if defined(VIEWS_COMPOSITOR)
- if (!CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableTestCompositor)) {
- // Use a mock compositor that noops draws.
- ui::Compositor::set_compositor_factory_for_testing(
- ui::TestCompositor::Create);
- }
-#endif
-}
-
-} // namespace gfx_test_utils
-} // namespace ui
diff --git a/ui/gfx/test/gfx_test_utils.h b/ui/gfx/test/gfx_test_utils.h
deleted file mode 100644
index da2b2be..0000000
--- a/ui/gfx/test/gfx_test_utils.h
+++ /dev/null
@@ -1,19 +0,0 @@
-// 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_GFX_TEST_UTILS_H_
-#define UI_GFX_GFX_TEST_UTILS_H_
-#pragma once
-
-namespace ui {
-namespace gfx_test_utils {
-
-// Called by tests that want to use a mocked compositor.
-// Implementation is no-oped on platforms that don't use a compositor.
-void SetupTestCompositor();
-
-} // namespace gfx_test_utils
-} // namespace ui
-
-#endif // UI_GFX_GFX_TEST_UTILS_H_
diff --git a/ui/views/run_all_unittests.cc b/ui/views/run_all_unittests.cc
index 9273994..8458072 100644
--- a/ui/views/run_all_unittests.cc
+++ b/ui/views/run_all_unittests.cc
@@ -1,19 +1,14 @@
-// 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.
#include "base/test/test_suite.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
+#include "ui/gfx/compositor/compositor_setup.h"
#include "ui/gfx/compositor/test/compositor_test_support.h"
#include "ui/views/view.h"
-#if defined(USE_WEBKIT_COMPOSITOR)
-#include "ui/gfx/compositor/compositor_setup.h"
-#else
-#include "ui/gfx/test/gfx_test_utils.h"
-#endif
-
class ViewTestSuite : public base::TestSuite {
public:
ViewTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {}
@@ -26,11 +21,7 @@ class ViewTestSuite : public base::TestSuite {
ui::ResourceBundle::InitSharedInstance("en-US");
ui::CompositorTestSupport::Initialize();
-#if defined(USE_WEBKIT_COMPOSITOR)
ui::SetupTestCompositor();
-#else
- ui::gfx_test_utils::SetupTestCompositor();
-#endif
}
virtual void Shutdown() {
diff --git a/ui/views/view.cc b/ui/views/view.cc
index 5dfe97f..ce35899 100644
--- a/ui/views/view.cc
+++ b/ui/views/view.cc
@@ -1379,17 +1379,6 @@ std::string View::DoPrintViewGraph(bool first, View* view_with_children) {
this->bounds().height());
result.append(bounds_buffer);
- if (layer() && !layer()->hole_rect().IsEmpty()) {
- base::snprintf(bounds_buffer,
- arraysize(bounds_buffer),
- "\\n hole bounds: (%d, %d), (%dx%d)",
- layer()->hole_rect().x(),
- layer()->hole_rect().y(),
- layer()->hole_rect().width(),
- layer()->hole_rect().height());
- result.append(bounds_buffer);
- }
-
if (GetTransform().HasChange()) {
gfx::Point translation;
float rotation;
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 8179f68..ea383bc 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -43,9 +43,6 @@
#include "ui/aura/root_window.h"
#include "ui/aura/gestures/gesture_recognizer.h"
#endif
-#if !defined(USE_WEBKIT_COMPOSITOR)
-#include "ui/gfx/compositor/test/test_texture.h"
-#endif
using ::testing::_;
@@ -2593,10 +2590,6 @@ class ViewLayerTest : public ViewsTestBase {
old_use_acceleration_ = View::get_use_acceleration_when_possible();
View::set_use_acceleration_when_possible(true);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- ui::TestTexture::reset_live_count();
-#endif
-
widget_ = new Widget;
Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
params.bounds = gfx::Rect(50, 50, 200, 200);
@@ -2661,28 +2654,12 @@ TEST_F(ViewLayerTest, LayerToggling) {
View* content_view = new View;
widget()->SetContentsView(content_view);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- // TODO(piman): with the webkit compositor, we don't create Textures on
- // Layers. We're not supposed to be calling Layer::DrawTree. This test needs
- // refactoring to fully work in that case.
- root_layer->DrawTree();
- ui::TestTexture::reset_live_count();
-#endif
-
// Create v1, give it a bounds and verify everything is set up correctly.
View* v1 = new View;
v1->SetPaintToLayer(true);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- root_layer->DrawTree();
- EXPECT_EQ(0, ui::TestTexture::live_count());
-#endif
EXPECT_TRUE(v1->layer() != NULL);
v1->SetBounds(20, 30, 140, 150);
content_view->AddChildView(v1);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- root_layer->DrawTree();
- EXPECT_EQ(1, ui::TestTexture::live_count());
-#endif
ASSERT_TRUE(v1->layer() != NULL);
EXPECT_EQ(root_layer, v1->layer()->parent());
EXPECT_EQ(gfx::Rect(20, 30, 140, 150), v1->layer()->bounds());
@@ -2693,10 +2670,6 @@ TEST_F(ViewLayerTest, LayerToggling) {
EXPECT_TRUE(v2->layer() == NULL);
v2->SetBounds(10, 20, 30, 40);
v2->SetPaintToLayer(true);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- root_layer->DrawTree();
- EXPECT_EQ(2, ui::TestTexture::live_count());
-#endif
ASSERT_TRUE(v2->layer() != NULL);
EXPECT_EQ(v1->layer(), v2->layer()->parent());
EXPECT_EQ(gfx::Rect(10, 20, 30, 40), v2->layer()->bounds());
@@ -2704,10 +2677,6 @@ TEST_F(ViewLayerTest, LayerToggling) {
// Turn off v1s layer. v2 should still have a layer but its parent should have
// changed.
v1->SetPaintToLayer(false);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- root_layer->DrawTree();
- EXPECT_EQ(1, ui::TestTexture::live_count());
-#endif
EXPECT_TRUE(v1->layer() == NULL);
EXPECT_TRUE(v2->layer() != NULL);
EXPECT_EQ(root_layer, v2->layer()->parent());
@@ -2721,10 +2690,6 @@ TEST_F(ViewLayerTest, LayerToggling) {
ui::Transform transform;
transform.SetScale(2.0f, 2.0f);
v1->SetTransform(transform);
-#if !defined(USE_WEBKIT_COMPOSITOR)
- root_layer->DrawTree();
- EXPECT_EQ(2, ui::TestTexture::live_count());
-#endif
EXPECT_TRUE(v1->layer() != NULL);
EXPECT_TRUE(v2->layer() != NULL);
EXPECT_EQ(root_layer, v1->layer()->parent());
@@ -2882,121 +2847,6 @@ TEST_F(ViewLayerTest, ToggleVisibilityWithLayer) {
EXPECT_TRUE(v1->layer()->IsDrawn());
}
-// We don't set the hole in the webkit compositor, so disable tests that rely on
-// it.
-#if defined(USE_WEBKIT_COMPOSITOR)
-#define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) DISABLED_ ## X
-#else
-#define NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(X) X
-#endif
-
-// Test that a hole in a layer is correctly created regardless of whether
-// the opacity attribute is set before or after the layer is created.
-TEST_F(ViewLayerTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleOpacityWithLayer)) {
- View* content_view = new View;
- widget()->SetContentsView(content_view);
-
- View* parent_view = new View;
- content_view->AddChildView(parent_view);
- parent_view->SetPaintToLayer(true);
- parent_view->SetBounds(0, 0, 400, 400);
-
- View* child_view = new View;
- child_view->SetBounds(50, 50, 100, 100);
- parent_view->AddChildView(child_view);
-
- widget()->GetCompositor()->Draw(false);
-
- ASSERT_TRUE(child_view->layer() == NULL);
- child_view->SetPaintToLayer(true);
- child_view->SetFillsBoundsOpaquely(true);
- widget()->GetCompositor()->Draw(false);
- ASSERT_TRUE(child_view->layer());
- EXPECT_EQ(
- gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
-
- child_view->SetFillsBoundsOpaquely(false);
- widget()->GetCompositor()->Draw(false);
- EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty());
-}
-
-// Test that a hole in a layer always corresponds to the bounds of opaque
-// layers.
-TEST_F(ViewLayerTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(MultipleOpaqueLayers)) {
- View* content_view = new View;
- widget()->SetContentsView(content_view);
-
- View* parent_view = new View;
- parent_view->SetPaintToLayer(true);
- parent_view->SetBounds(0, 0, 400, 400);
- content_view->AddChildView(parent_view);
-
- View* child_view1 = new View;
- child_view1->SetPaintToLayer(true);
- child_view1->SetFillsBoundsOpaquely(true);
- child_view1->SetBounds(50, 50, 100, 100);
- parent_view->AddChildView(child_view1);
-
- View* child_view2 = new View;
- child_view2->SetPaintToLayer(true);
- child_view2->SetFillsBoundsOpaquely(false);
- child_view2->SetBounds(150, 150, 200, 200);
- parent_view->AddChildView(child_view2);
-
- widget()->GetCompositor()->Draw(false);
-
- // Only child_view1 is opaque
- EXPECT_EQ(
- gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
-
- // Both child views are opaque
- child_view2->SetFillsBoundsOpaquely(true);
- widget()->GetCompositor()->Draw(false);
- EXPECT_TRUE(
- gfx::Rect(50, 50, 100, 100) == parent_view->layer()->hole_rect() ||
- gfx::Rect(150, 150, 200, 200) == parent_view->layer()->hole_rect());
-
- // Only child_view2 is opaque
- delete child_view1;
- EXPECT_EQ(
- gfx::Rect(150, 150, 200, 200), parent_view->layer()->hole_rect());
-}
-
-// Makes sure that opacity of layer persists after toggling visibilty.
-TEST_F(ViewLayerTest,
- NOT_APPLICABLE_TO_WEBKIT_COMPOSITOR(ToggleVisibilityWithOpaqueLayer)) {
- View* content_view = new View;
- widget()->SetContentsView(content_view);
-
- View* parent_view = new View;
- parent_view->SetPaintToLayer(true);
- parent_view->SetBounds(0, 0, 400, 400);
- content_view->AddChildView(parent_view);
-
- parent_view->SetPaintToLayer(true);
- parent_view->SetBounds(0, 0, 400, 400);
-
- View* child_view = new View;
- child_view->SetBounds(50, 50, 100, 100);
- child_view->SetPaintToLayer(true);
- child_view->SetFillsBoundsOpaquely(true);
- parent_view->AddChildView(child_view);
- widget()->GetCompositor()->Draw(false);
- EXPECT_EQ(
- gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
-
- child_view->SetVisible(false);
- widget()->GetCompositor()->Draw(false);
- EXPECT_TRUE(parent_view->layer()->hole_rect().IsEmpty());
-
- child_view->SetVisible(true);
- widget()->GetCompositor()->Draw(false);
- EXPECT_EQ(
- gfx::Rect(50, 50, 100, 100), parent_view->layer()->hole_rect());
-}
-
// Tests that the layers in the subtree are orphaned after a View is removed
// from the parent.
TEST_F(ViewLayerTest, OrphanLayerAfterViewRemove) {
@@ -3042,33 +2892,27 @@ class PaintTrackingView : public View {
DISALLOW_COPY_AND_ASSIGN(PaintTrackingView);
};
-#if !defined(USE_WEBKIT_COMPOSITOR)
-// TODO(piman): this test relies on the way the non-webkit compositor works.
-// Layer::DrawTree should not be called with the webkit compositor. In the
-// WebKit case, it needs to go through the "real" compositor (not the test one)
-// to do the paints on the layer/views.
-
// Makes sure child views with layers aren't painted when paint starts at an
// ancestor.
TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
PaintTrackingView* content_view = new PaintTrackingView;
widget()->SetContentsView(content_view);
content_view->SetPaintToLayer(true);
- GetRootLayer()->DrawTree();
+ // TODO(piman): Compositor::Draw() won't work for the threaded compositor.
+ GetRootLayer()->GetCompositor()->Draw(false);
GetRootLayer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
content_view->set_painted(false);
// content_view no longer has a dirty rect. Paint from the root and make sure
// PaintTrackingView isn't painted.
- GetRootLayer()->DrawTree();
+ GetRootLayer()->GetCompositor()->Draw(false);
EXPECT_FALSE(content_view->painted());
// Make content_view have a dirty rect, paint the layers and make sure
// PaintTrackingView is painted.
content_view->layer()->SchedulePaint(gfx::Rect(0, 0, 10, 10));
- GetRootLayer()->DrawTree();
+ GetRootLayer()->GetCompositor()->Draw(false);
EXPECT_TRUE(content_view->painted());
}
-#endif
// Tests that the visibility of child layers are updated correctly when a View's
// visibility changes.
diff --git a/ui/views/views.gyp b/ui/views/views.gyp
index 409d773..76d4bca 100644
--- a/ui/views/views.gyp
+++ b/ui/views/views.gyp
@@ -495,6 +495,7 @@
'../../third_party/icu/icu.gyp:icui18n',
'../../third_party/icu/icu.gyp:icuuc',
'../base/strings/ui_strings.gyp:ui_strings',
+ '../gfx/compositor/compositor.gyp:compositor',
'../gfx/compositor/compositor.gyp:compositor_test_support',
'../ui.gyp:gfx_resources',
'../ui.gyp:ui',
@@ -598,15 +599,6 @@
['exclude', 'widget/native_widget_aura_unittest.cc'],
],
}],
- ['use_webkit_compositor==1', {
- 'dependencies': [
- '../gfx/compositor/compositor.gyp:compositor',
- ],
- }, { # use_webkit_compositor!=1
- 'dependencies': [
- '../gfx/compositor/compositor.gyp:test_compositor',
- ],
- }],
],
}, # target_name: views_unittests
{
diff --git a/ui/views/widget/native_widget_gtk.cc b/ui/views/widget/native_widget_gtk.cc
index e4a3d67..410fada 100644
--- a/ui/views/widget/native_widget_gtk.cc
+++ b/ui/views/widget/native_widget_gtk.cc
@@ -649,15 +649,11 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
}
if (View::get_use_acceleration_when_possible()) {
- if (ui::Compositor::compositor_factory()) {
- compositor_ = (*ui::Compositor::compositor_factory())(this);
- } else {
- gint width, height;
- gdk_drawable_get_size(window_contents_->window, &width, &height);
- compositor_ = ui::Compositor::Create(this,
- GDK_WINDOW_XID(window_contents_->window),
- gfx::Size(width, height));
- }
+ gint width, height;
+ gdk_drawable_get_size(window_contents_->window, &width, &height);
+ compositor_ = ui::Compositor::Create(this,
+ GDK_WINDOW_XID(window_contents_->window),
+ gfx::Size(width, height));
if (compositor_.get()) {
View* root_view = delegate_->AsWidget()->GetRootView();
root_view->SetPaintToLayer(true);