diff options
29 files changed, 883 insertions, 306 deletions
@@ -58,6 +58,8 @@ 'draw_properties.h', 'draw_quad.cc', 'draw_quad.h', + 'fake_web_graphics_context_3d.cc', + 'fake_web_graphics_context_3d.h', 'font_atlas.cc', 'font_atlas.h', 'frame_rate_controller.cc', diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index d4dd681..1f8d69c 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -102,8 +102,6 @@ 'test/fake_software_output_device.h', 'test/fake_video_frame_provider.cc', 'test/fake_video_frame_provider.h', - 'test/fake_web_graphics_context_3d.cc', - 'test/fake_web_graphics_context_3d.h', 'test/fake_web_scrollbar.cc', 'test/fake_web_scrollbar.h', 'test/fake_web_scrollbar_theme_geometry.cc', @@ -129,6 +127,8 @@ 'test/render_pass_test_utils.h', 'test/scheduler_test_common.cc', 'test/scheduler_test_common.h', + 'test/test_web_graphics_context_3d.cc', + 'test/test_web_graphics_context_3d.h', 'test/tiled_layer_test_common.cc', 'test/tiled_layer_test_common.h', ], diff --git a/cc/delegated_renderer_layer_impl_unittest.cc b/cc/delegated_renderer_layer_impl_unittest.cc index 66429e1..e2e74d2 100644 --- a/cc/delegated_renderer_layer_impl_unittest.cc +++ b/cc/delegated_renderer_layer_impl_unittest.cc @@ -17,11 +17,11 @@ #include "cc/test/fake_layer_tree_host_impl_client.h" #include "cc/test/fake_output_surface.h" #include "cc/test/fake_proxy.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/mock_quad_culler.h" #include "cc/test/render_pass_test_common.h" #include "cc/test/render_pass_test_utils.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/transform.h" diff --git a/cc/delegating_renderer_unittest.cc b/cc/delegating_renderer_unittest.cc index de96046..8b35f1b 100644 --- a/cc/delegating_renderer_unittest.cc +++ b/cc/delegating_renderer_unittest.cc @@ -18,8 +18,8 @@ class DelegatingRendererTest : public ThreadedTest { virtual ~DelegatingRendererTest() {} virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { - scoped_ptr<FakeWebGraphicsContext3D> context3d = - FakeWebGraphicsContext3D::Create( + scoped_ptr<TestWebGraphicsContext3D> context3d = + TestWebGraphicsContext3D::Create( WebKit::WebGraphicsContext3D::Attributes()); context3d_ = context3d.get(); scoped_ptr<FakeOutputSurface> output_surface = @@ -30,7 +30,7 @@ class DelegatingRendererTest : public ThreadedTest { } protected: - FakeWebGraphicsContext3D* context3d_; + TestWebGraphicsContext3D* context3d_; FakeOutputSurface* output_surface_; }; diff --git a/cc/test/fake_web_graphics_context_3d.cc b/cc/fake_web_graphics_context_3d.cc index b5ee805..cd03d37 100644 --- a/cc/test/fake_web_graphics_context_3d.cc +++ b/cc/fake_web_graphics_context_3d.cc @@ -1,16 +1,10 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. +// Copyright 2013 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 "cc/test/fake_web_graphics_context_3d.h" +#include "cc/fake_web_graphics_context_3d.h" -#include <algorithm> -#include <string> - -#include "base/logging.h" -#include "gpu/GLES2/gl2extchromium.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "third_party/khronos/GLES2/gl2ext.h" +#include "third_party/khronos/GLES2/gl2.h" using WebKit::WGC3Dboolean; using WebKit::WGC3Denum; @@ -19,71 +13,26 @@ using WebKit::WebGraphicsContext3D; namespace cc { -static const WebGLId kBufferId = 1; -static const WebGLId kFramebufferId = 2; -static const WebGLId kProgramId = 3; -static const WebGLId kRenderbufferId = 4; -static const WebGLId kShaderId = 5; - -static unsigned s_context_id = 1; - -const WebGLId FakeWebGraphicsContext3D::kExternalTextureId = 1337; - FakeWebGraphicsContext3D::FakeWebGraphicsContext3D() - : context_id_(s_context_id++), - next_texture_id_(1), - have_extension_io_surface_(false), - have_extension_egl_image_(false), - times_make_current_succeeds_(-1), - times_bind_texture_succeeds_(-1), - times_end_query_succeeds_(-1), - context_lost_(false), - context_lost_callback_(NULL), - width_(0), - height_(0) { -} - -FakeWebGraphicsContext3D::FakeWebGraphicsContext3D( - const WebGraphicsContext3D::Attributes& attributes) - : context_id_(s_context_id++), - next_texture_id_(1), - attributes_(attributes), - have_extension_io_surface_(false), - have_extension_egl_image_(false), - times_make_current_succeeds_(-1), - times_bind_texture_succeeds_(-1), - times_end_query_succeeds_(-1), - context_lost_(false), - context_lost_callback_(NULL), - width_(0), - height_(0) { + : WebKit::WebGraphicsContext3D() { } FakeWebGraphicsContext3D::~FakeWebGraphicsContext3D() { } bool FakeWebGraphicsContext3D::makeContextCurrent() { - if (times_make_current_succeeds_ >= 0) { - if (!times_make_current_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_make_current_succeeds_; - } - return !context_lost_; + return true; } int FakeWebGraphicsContext3D::width() { - return width_; + return 1; } int FakeWebGraphicsContext3D::height() { - return height_; + return 1; } void FakeWebGraphicsContext3D::reshape(int width, int height) { - width_ = width; - height_ = height; } bool FakeWebGraphicsContext3D::isGLES2Compliant() { @@ -104,11 +53,11 @@ WebGLId FakeWebGraphicsContext3D::getPlatformTextureId() { } bool FakeWebGraphicsContext3D::isContextLost() { - return context_lost_; + return false; } WGC3Denum FakeWebGraphicsContext3D::getGraphicsResetStatusARB() { - return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; + return GL_NO_ERROR; } void* FakeWebGraphicsContext3D::mapBufferSubDataCHROMIUM( @@ -138,8 +87,6 @@ WebKit::WebString FakeWebGraphicsContext3D::getRequestableExtensionsCHROMIUM() { WGC3Denum FakeWebGraphicsContext3D::checkFramebufferStatus( WGC3Denum target) { - if (context_lost_) - return GL_FRAMEBUFFER_UNDEFINED_OES; return GL_FRAMEBUFFER_COMPLETE; } @@ -165,7 +112,7 @@ WebKit::WGC3Dint FakeWebGraphicsContext3D::getAttribLocation( WebGraphicsContext3D::Attributes FakeWebGraphicsContext3D::getContextAttributes() { - return attributes_; + return WebGraphicsContext3D::Attributes(); } WGC3Denum FakeWebGraphicsContext3D::getError() { @@ -211,16 +158,7 @@ WebKit::WebString FakeWebGraphicsContext3D::getShaderSource( } WebKit::WebString FakeWebGraphicsContext3D::getString(WGC3Denum name) { - std::string string; - - if (name == GL_EXTENSIONS) { - if (have_extension_io_surface_) - string += "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle "; - if (have_extension_egl_image_) - string += "GL_OES_EGL_image_external"; - } - - return WebKit::WebString::fromUTF8(string.c_str()); + return WebKit::WebString(); } WebKit::WGC3Dint FakeWebGraphicsContext3D::getUniformLocation( @@ -271,106 +209,66 @@ WGC3Dboolean FakeWebGraphicsContext3D::isTexture( } WebGLId FakeWebGraphicsContext3D::createBuffer() { - return kBufferId | context_id_ << 16; + return 1; } void FakeWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) { - EXPECT_EQ(kBufferId | context_id_ << 16, id); } WebGLId FakeWebGraphicsContext3D::createFramebuffer() { - return kFramebufferId | context_id_ << 16; + return 1; } void FakeWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) { - EXPECT_EQ(kFramebufferId | context_id_ << 16, id); } WebGLId FakeWebGraphicsContext3D::createProgram() { - return kProgramId | context_id_ << 16; + return 1; } void FakeWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) { - EXPECT_EQ(kProgramId | context_id_ << 16, id); } WebGLId FakeWebGraphicsContext3D::createRenderbuffer() { - return kRenderbufferId | context_id_ << 16; + return 1; } void FakeWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) { - EXPECT_EQ(kRenderbufferId | context_id_ << 16, id); } WebGLId FakeWebGraphicsContext3D::createShader(WGC3Denum) { - return kShaderId | context_id_ << 16; + return 1; } void FakeWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) { - EXPECT_EQ(kShaderId | context_id_ << 16, id); } WebGLId FakeWebGraphicsContext3D::createTexture() { - WebGLId texture_id = NextTextureId(); - DCHECK_NE(texture_id, kExternalTextureId); - textures_.push_back(texture_id); - return texture_id; + return 1; } void FakeWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { - DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != - textures_.end()); - textures_.erase(std::find(textures_.begin(), textures_.end(), texture_id)); } void FakeWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { - EXPECT_EQ(kProgramId | context_id_ << 16, program); - EXPECT_EQ(kShaderId | context_id_ << 16, shader); } void FakeWebGraphicsContext3D::useProgram(WebGLId program) { - if (!program) - return; - EXPECT_EQ(kProgramId | context_id_ << 16, program); } void FakeWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) { - if (!buffer) - return; - EXPECT_EQ(kBufferId | context_id_ << 16, buffer); } void FakeWebGraphicsContext3D::bindFramebuffer( WGC3Denum target, WebGLId framebuffer) { - if (!framebuffer) - return; - EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); } void FakeWebGraphicsContext3D::bindRenderbuffer( - WGC3Denum target, WebGLId renderbuffer) { - if (!renderbuffer) - return; - EXPECT_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); + WGC3Denum target, WebGLId renderbuffer) { } void FakeWebGraphicsContext3D::bindTexture( WGC3Denum target, WebGLId texture_id) { - if (times_bind_texture_succeeds_ >= 0) { - if (!times_bind_texture_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_bind_texture_succeeds_; - } - - if (!texture_id) - return; - if (texture_id == kExternalTextureId) - return; - DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != - textures_.end()); - used_textures_.insert(texture_id); } WebGLId FakeWebGraphicsContext3D::createQueryEXT() { @@ -382,43 +280,20 @@ WGC3Dboolean FakeWebGraphicsContext3D::isQueryEXT(WebGLId query) { } void FakeWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) { - if (times_end_query_succeeds_ >= 0) { - if (!times_end_query_succeeds_) { - loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, - GL_INNOCENT_CONTEXT_RESET_ARB); - } - --times_end_query_succeeds_; - } } void FakeWebGraphicsContext3D::getQueryObjectuivEXT( WebKit::WebGLId query, WebKit::WGC3Denum pname, WebKit::WGC3Duint* params) { - // If the context is lost, behave as if result is available. - if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) - *params = 1; } void FakeWebGraphicsContext3D::setContextLostCallback( WebGraphicsContextLostCallback* callback) { - context_lost_callback_ = callback; } void FakeWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, WGC3Denum other) { - if (context_lost_) - return; - context_lost_ = true; - if (context_lost_callback_) - context_lost_callback_->onContextLost(); -} - -WebKit::WebGLId FakeWebGraphicsContext3D::NextTextureId() { - WebGLId texture_id = next_texture_id_++; - DCHECK(texture_id < (1 << 16)); - texture_id |= context_id_ << 16; - return texture_id; } } // namespace cc diff --git a/cc/test/fake_web_graphics_context_3d.h b/cc/fake_web_graphics_context_3d.h index 8c28efe..42a3151 100644 --- a/cc/test/fake_web_graphics_context_3d.h +++ b/cc/fake_web_graphics_context_3d.h @@ -1,31 +1,22 @@ -// Copyright 2011 The Chromium Authors. All rights reserved. +// Copyright 2013 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 CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ -#define CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ +#ifndef CC_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ +#define CC_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ -#include <vector> - -#include "base/hash_tables.h" -#include "base/memory/scoped_ptr.h" -#include "base/stl_util.h" +#include "base/compiler_specific.h" +#include "cc/cc_export.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" -#include "third_party/khronos/GLES2/gl2.h" namespace cc { -// WebGraphicsContext3D base class for use in WebKit unit tests. +// WebGraphicsContext3D base class for use in unit tests. // All operations are no-ops (returning 0 if necessary). -class FakeWebGraphicsContext3D : public WebKit::WebGraphicsContext3D { +class CC_EXPORT FakeWebGraphicsContext3D : + public NON_EXPORTED_BASE(WebKit::WebGraphicsContext3D) { public: - static scoped_ptr<FakeWebGraphicsContext3D> Create() { - return make_scoped_ptr(new FakeWebGraphicsContext3D()); - } - static scoped_ptr<FakeWebGraphicsContext3D> Create( - const WebKit::WebGraphicsContext3D::Attributes& attributes) { - return make_scoped_ptr(new FakeWebGraphicsContext3D(attributes)); - } + FakeWebGraphicsContext3D(); virtual ~FakeWebGraphicsContext3D(); virtual bool makeContextCurrent(); @@ -591,58 +582,8 @@ class FakeWebGraphicsContext3D : public WebKit::WebGraphicsContext3D { virtual void loseContextCHROMIUM(WebKit::WGC3Denum current, WebKit::WGC3Denum other); - - // When set, MakeCurrent() will fail after this many times. - void set_times_make_current_succeeds(int times) { - times_make_current_succeeds_ = times; - } - void set_times_bind_texture_succeeds(int times) { - times_bind_texture_succeeds_ = times; - } - void set_times_end_query_succeeds(int times) { - times_end_query_succeeds_ = times; - } - - size_t NumTextures() const { return textures_.size(); } - WebKit::WebGLId TextureAt(int i) const { return textures_[i]; } - - size_t NumUsedTextures() const { return used_textures_.size(); } - bool UsedTexture(int texture) const { - return ContainsKey(used_textures_, texture); - } - void ResetUsedTextures() { used_textures_.clear(); } - - void set_have_extension_io_surface(bool have) { - have_extension_io_surface_ = have; - } - void set_have_extension_egl_image(bool have) { - have_extension_egl_image_ = have; - } - - static const WebKit::WebGLId kExternalTextureId; - virtual WebKit::WebGLId NextTextureId(); - - protected: - FakeWebGraphicsContext3D(); - FakeWebGraphicsContext3D( - const WebKit::WebGraphicsContext3D::Attributes& attributes); - - unsigned context_id_; - unsigned next_texture_id_; - Attributes attributes_; - bool have_extension_io_surface_; - bool have_extension_egl_image_; - int times_make_current_succeeds_; - int times_bind_texture_succeeds_; - int times_end_query_succeeds_; - bool context_lost_; - WebGraphicsContextLostCallback* context_lost_callback_; - std::vector<WebKit::WebGLId> textures_; - base::hash_set<WebKit::WebGLId> used_textures_; - int width_; - int height_; }; } // namespace cc -#endif // CC_TEST_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ +#endif // CC_FAKE_WEB_GRAPHICS_CONTEXT_3D_H_ diff --git a/cc/gl_renderer_unittest.cc b/cc/gl_renderer_unittest.cc index 23c48f7..d7e9b71 100644 --- a/cc/gl_renderer_unittest.cc +++ b/cc/gl_renderer_unittest.cc @@ -11,9 +11,9 @@ #include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_output_surface.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/render_pass_test_common.h" #include "cc/test/render_pass_test_utils.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2.h" @@ -31,7 +31,7 @@ using testing::Mock; namespace cc { namespace { -class FrameCountingMemoryAllocationSettingContext : public FakeWebGraphicsContext3D { +class FrameCountingMemoryAllocationSettingContext : public TestWebGraphicsContext3D { public: FrameCountingMemoryAllocationSettingContext() : m_frame(0) { } @@ -238,7 +238,7 @@ TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) EXPECT_EQ(2, m_mockClient.setFullRootLayerDamageCount()); } -class ForbidSynchronousCallContext : public FakeWebGraphicsContext3D { +class ForbidSynchronousCallContext : public TestWebGraphicsContext3D { public: ForbidSynchronousCallContext() { } @@ -315,7 +315,7 @@ TEST(GLRendererTest2, initializationDoesNotMakeSynchronousCalls) EXPECT_TRUE(renderer.initialize()); } -class LoseContextOnFirstGetContext : public FakeWebGraphicsContext3D { +class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D { public: LoseContextOnFirstGetContext() : m_contextLost(false) @@ -358,7 +358,7 @@ TEST(GLRendererTest2, initializationWithQuicklyLostContextDoesNotAssert) renderer.initialize(); } -class ContextThatDoesNotSupportMemoryManagmentExtensions : public FakeWebGraphicsContext3D { +class ContextThatDoesNotSupportMemoryManagmentExtensions : public TestWebGraphicsContext3D { public: ContextThatDoesNotSupportMemoryManagmentExtensions() { } @@ -382,7 +382,7 @@ TEST(GLRendererTest2, initializationWithoutGpuMemoryManagerExtensionSupportShoul EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul); } -class ClearCountingContext : public FakeWebGraphicsContext3D { +class ClearCountingContext : public TestWebGraphicsContext3D { public: ClearCountingContext() : m_clear(0) { } @@ -437,7 +437,7 @@ TEST(GLRendererTest2, transparentBackground) EXPECT_EQ(1, context->clearCount()); } -class VisibilityChangeIsLastCallTrackingContext : public FakeWebGraphicsContext3D { +class VisibilityChangeIsLastCallTrackingContext : public TestWebGraphicsContext3D { public: VisibilityChangeIsLastCallTrackingContext() : m_lastCallWasSetVisibility(0) @@ -494,7 +494,7 @@ TEST(GLRendererTest2, visibilityChangeIsLastCall) EXPECT_TRUE(lastCallWasSetVisiblity); } -class TextureStateTrackingContext : public FakeWebGraphicsContext3D { +class TextureStateTrackingContext : public TestWebGraphicsContext3D { public: TextureStateTrackingContext() : m_activeTexture(GL_INVALID_ENUM) @@ -584,7 +584,7 @@ public: virtual bool shouldClearRootRenderPass() const OVERRIDE { return false; } }; -class NoClearRootRenderPassMockContext : public FakeWebGraphicsContext3D { +class NoClearRootRenderPassMockContext : public TestWebGraphicsContext3D { public: MOCK_METHOD1(clear, void(WGC3Dbitfield mask)); MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum type, WGC3Dintptr offset)); @@ -636,7 +636,7 @@ TEST(GLRendererTest2, shouldClearRootRenderPass) Mock::VerifyAndClearExpectations(&mockContext); } -class ScissorTestOnClearCheckingContext : public FakeWebGraphicsContext3D { +class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { public: ScissorTestOnClearCheckingContext() : m_scissorEnabled(false) { } diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc index c116d93..2c6eefc 100644 --- a/cc/layer_tree_host_impl_unittest.cc +++ b/cc/layer_tree_host_impl_unittest.cc @@ -28,11 +28,11 @@ #include "cc/test/fake_output_surface.h" #include "cc/test/fake_proxy.h" #include "cc/test/fake_video_frame_provider.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_test_common.h" #include "cc/test/render_pass_test_common.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "cc/texture_draw_quad.h" #include "cc/texture_layer_impl.h" #include "cc/tile_draw_quad.h" @@ -232,7 +232,7 @@ protected: bool m_reduceMemoryResult; }; -class FakeWebGraphicsContext3DMakeCurrentFails : public FakeWebGraphicsContext3D { +class TestWebGraphicsContext3DMakeCurrentFails : public TestWebGraphicsContext3D { public: virtual bool makeContextCurrent() { return false; } }; @@ -387,7 +387,7 @@ TEST_P(LayerTreeHostImplTest, scrollWithoutRenderer) m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); // Initialization will fail here. - m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)).PassAs<OutputSurface>()); + m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new TestWebGraphicsContext3DMakeCurrentFails)).PassAs<OutputSurface>()); m_hostImpl->setViewportSize(gfx::Size(10, 10), gfx::Size(10, 10)); setupScrollAndContentsLayers(gfx::Size(100, 100)); @@ -1717,7 +1717,7 @@ TEST_P(LayerTreeHostImplTest, scrollScaledLayer) expectContains(*scrollInfo.get(), m_hostImpl->rootLayer()->id(), wheelScrollDelta); } -class BlendStateTrackerContext: public FakeWebGraphicsContext3D { +class BlendStateTrackerContext: public TestWebGraphicsContext3D { public: BlendStateTrackerContext() : m_blend(false) { } @@ -2079,7 +2079,7 @@ TEST_P(LayerTreeHostImplTest, viewportCovered) } -class ReshapeTrackerContext: public FakeWebGraphicsContext3D { +class ReshapeTrackerContext: public TestWebGraphicsContext3D { public: ReshapeTrackerContext() : m_reshapeCalled(false) { } @@ -2124,7 +2124,7 @@ TEST_P(LayerTreeHostImplTest, reshapeNotCalledUntilDraw) m_hostImpl->didDrawAllLayers(frame); } -class PartialSwapTrackerContext : public FakeWebGraphicsContext3D { +class PartialSwapTrackerContext : public TestWebGraphicsContext3D { public: virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) { @@ -2268,7 +2268,7 @@ private: } }; -class MockContext : public FakeWebGraphicsContext3D { +class MockContext : public TestWebGraphicsContext3D { public: MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); MOCK_METHOD5(uniform4f, void(WebKit::WGC3Dint location, WebKit::WGC3Dfloat x, WebKit::WGC3Dfloat y, WebKit::WGC3Dfloat z, WebKit::WGC3Dfloat w)); @@ -2426,7 +2426,7 @@ TEST_P(LayerTreeHostImplTest, partialSwap) Mock::VerifyAndClearExpectations(&mockContext); } -class PartialSwapContext : public FakeWebGraphicsContext3D { +class PartialSwapContext : public TestWebGraphicsContext3D { public: virtual WebKit::WebString getString(WebKit::WGC3Denum name) { @@ -2557,16 +2557,16 @@ TEST_P(LayerTreeHostImplTest, contributingLayerEmptyScissorNoPartialSwap) } // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. -class TrackingWebGraphicsContext3D : public FakeWebGraphicsContext3D { +class TrackingWebGraphicsContext3D : public TestWebGraphicsContext3D { public: TrackingWebGraphicsContext3D() - : FakeWebGraphicsContext3D() + : TestWebGraphicsContext3D() , m_numTextures(0) { } virtual WebKit::WebGLId createTexture() OVERRIDE { - WebKit::WebGLId id = FakeWebGraphicsContext3D::createTexture(); + WebKit::WebGLId id = TestWebGraphicsContext3D::createTexture(); m_textures[id] = true; ++m_numTextures; @@ -2613,9 +2613,9 @@ static unsigned createTextureId(ResourceProvider* resourceProvider) TEST_P(LayerTreeHostImplTest, layersFreeTextures) { - scoped_ptr<FakeWebGraphicsContext3D> context = - FakeWebGraphicsContext3D::Create(); - FakeWebGraphicsContext3D* context3d = context.get(); + scoped_ptr<TestWebGraphicsContext3D> context = + TestWebGraphicsContext3D::Create(); + TestWebGraphicsContext3D* context3d = context.get(); scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d( context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); m_hostImpl->initializeRenderer(outputSurface.Pass()); @@ -2661,7 +2661,7 @@ TEST_P(LayerTreeHostImplTest, layersFreeTextures) EXPECT_EQ(0u, context3d->NumTextures()); } -class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D { +class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D { public: MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei count, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); @@ -4044,7 +4044,7 @@ protected: { // Creates an output surface with a parent to use a delegating renderer. WebKit::WebGraphicsContext3D::Attributes attrs; - return FakeOutputSurface::CreateDelegating3d(FakeWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); + return FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); } void drawFrameAndTestDamage(const gfx::RectF& expectedDamage) { diff --git a/cc/layer_tree_host_unittest.cc b/cc/layer_tree_host_unittest.cc index 63799bf..acb7a08 100644 --- a/cc/layer_tree_host_unittest.cc +++ b/cc/layer_tree_host_unittest.cc @@ -1040,7 +1040,7 @@ public: { ASSERT_EQ(0u, m_layerTreeHost->settings().maxPartialTextureUpdates); - FakeWebGraphicsContext3D* context = static_cast<FakeWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); + TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); switch (impl->activeTree()->source_frame_number()) { case 0: @@ -1082,7 +1082,7 @@ public: virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { - FakeWebGraphicsContext3D* context = static_cast<FakeWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); + TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); // Number of textures used for draw should always be one for each layer. EXPECT_EQ(2, context->NumUsedTextures()); @@ -1172,7 +1172,7 @@ public: { ASSERT_EQ(1u, m_layerTreeHost->settings().maxPartialTextureUpdates); - FakeWebGraphicsContext3D* context = static_cast<FakeWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); + TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); switch (impl->activeTree()->source_frame_number()) { case 0: @@ -1257,7 +1257,7 @@ public: virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE { - FakeWebGraphicsContext3D* context = static_cast<FakeWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); + TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D()); // Number of textures used for drawing should one per layer except for // frame 3 where the viewport only contains one layer. diff --git a/cc/layer_tree_host_unittest_context.cc b/cc/layer_tree_host_unittest_context.cc index 7b84656..41ebbfd 100644 --- a/cc/layer_tree_host_unittest_context.cc +++ b/cc/layer_tree_host_unittest_context.cc @@ -23,11 +23,11 @@ #include "cc/test/fake_scrollbar_layer.h" #include "cc/test/fake_scrollbar_theme_painter.h" #include "cc/test/fake_video_frame_provider.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/fake_web_scrollbar.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" #include "cc/test/layer_tree_test_common.h" #include "cc/test/render_pass_test_common.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "cc/texture_layer.h" #include "cc/video_layer.h" #include "cc/video_layer_impl.h" @@ -63,8 +63,8 @@ class LayerTreeHostContextTest : public ThreadedTest { context3d_ = NULL; } - virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() { - return FakeWebGraphicsContext3D::Create(); + virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() { + return TestWebGraphicsContext3D::Create(); } virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE { @@ -73,7 +73,7 @@ class LayerTreeHostContextTest : public ThreadedTest { return scoped_ptr<OutputSurface>(); } - scoped_ptr<FakeWebGraphicsContext3D> context3d = CreateContext3d(); + scoped_ptr<TestWebGraphicsContext3D> context3d = CreateContext3d(); context3d_ = context3d.get(); if (times_to_fail_initialize_) { @@ -119,7 +119,7 @@ class LayerTreeHostContextTest : public ThreadedTest { } protected: - FakeWebGraphicsContext3D* context3d_; + TestWebGraphicsContext3D* context3d_; int times_to_fail_create_; int times_to_fail_initialize_; int times_to_lose_on_create_; @@ -304,7 +304,7 @@ class LayerTreeHostContextTestLostContextSucceedsWithContent : FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( host_impl->rootLayer()->children()[0]); // Even though the context was lost, we should have a resource. The - // FakeWebGraphicsContext3D ensures that this resource is created with + // TestWebGraphicsContext3D ensures that this resource is created with // the active context. EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); } @@ -549,8 +549,8 @@ class LayerTreeHostContextTestLostContextWhileUpdatingResources : times_to_lose_on_end_query_(3) { } - virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() OVERRIDE { - scoped_ptr<FakeWebGraphicsContext3D> context = + virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() OVERRIDE { + scoped_ptr<TestWebGraphicsContext3D> context = LayerTreeHostContextTest::CreateContext3d(); if (times_to_lose_on_end_query_) { --times_to_lose_on_end_query_; @@ -710,7 +710,7 @@ class LayerTreeHostContextTestDontUseLostResources : scoped_refptr<TextureLayer> texture_ = TextureLayer::create(NULL); texture_->setBounds(gfx::Size(10, 10)); texture_->setAnchorPoint(gfx::PointF()); - texture_->setTextureId(FakeWebGraphicsContext3D::kExternalTextureId); + texture_->setTextureId(TestWebGraphicsContext3D::kExternalTextureId); texture_->setIsDrawable(true); root_->addChild(texture_); @@ -915,8 +915,8 @@ class LayerTreeHostContextTestFailsImmediately : virtual void afterTest() OVERRIDE { } - virtual scoped_ptr<FakeWebGraphicsContext3D> CreateContext3d() OVERRIDE { - scoped_ptr<FakeWebGraphicsContext3D> context = + virtual scoped_ptr<TestWebGraphicsContext3D> CreateContext3d() OVERRIDE { + scoped_ptr<TestWebGraphicsContext3D> context = LayerTreeHostContextTest::CreateContext3d(); context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); diff --git a/cc/resource_provider_unittest.cc b/cc/resource_provider_unittest.cc index 8665bd5..2c28d02 100644 --- a/cc/resource_provider_unittest.cc +++ b/cc/resource_provider_unittest.cc @@ -9,7 +9,7 @@ #include "cc/scoped_ptr_deque.h" #include "cc/scoped_ptr_hash_map.h" #include "cc/test/fake_output_surface.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "gpu/GLES2/gl2extchromium.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -101,7 +101,7 @@ private: base::hash_map<unsigned, unsigned> m_syncPointForMailbox; }; -class ResourceProviderContext : public FakeWebGraphicsContext3D { +class ResourceProviderContext : public TestWebGraphicsContext3D { public: static scoped_ptr<ResourceProviderContext> create(ContextSharedData* sharedData) { return make_scoped_ptr(new ResourceProviderContext(Attributes(), sharedData)); } @@ -130,7 +130,7 @@ public: virtual WebGLId createTexture() { - WebGLId id = FakeWebGraphicsContext3D::createTexture(); + WebGLId id = TestWebGraphicsContext3D::createTexture(); m_textures.add(id, scoped_ptr<Texture>()); return id; } @@ -228,7 +228,7 @@ public: protected: ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedData) - : FakeWebGraphicsContext3D(attrs) + : TestWebGraphicsContext3D(attrs) , m_sharedData(sharedData) , m_currentTexture(0) , m_lastWaitedSyncPoint(0) @@ -564,7 +564,7 @@ TEST_P(ResourceProviderTest, DeleteTransferredResources) EXPECT_EQ(0u, childResourceProvider->numResources()); } -class TextureStateTrackingContext : public FakeWebGraphicsContext3D { +class TextureStateTrackingContext : public TestWebGraphicsContext3D { public: MOCK_METHOD2(bindTexture, void(WGC3Denum target, WebGLId texture)); MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); @@ -650,7 +650,7 @@ TEST_P(ResourceProviderTest, ManagedResource) Mock::VerifyAndClearExpectations(context); } -class AllocationTrackingContext3D : public FakeWebGraphicsContext3D { +class AllocationTrackingContext3D : public TestWebGraphicsContext3D { public: MOCK_METHOD0(createTexture, WebGLId()); MOCK_METHOD1(deleteTexture, void(WebGLId texture_id)); diff --git a/cc/resource_update_controller_unittest.cc b/cc/resource_update_controller_unittest.cc index 8fb7d18..9dfcb3e 100644 --- a/cc/resource_update_controller_unittest.cc +++ b/cc/resource_update_controller_unittest.cc @@ -8,8 +8,8 @@ #include "cc/single_thread_proxy.h" // For DebugScopedSetImplThread #include "cc/test/fake_output_surface.h" #include "cc/test/fake_proxy.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/scheduler_test_common.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "cc/test/tiled_layer_test_common.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2ext.h" @@ -25,7 +25,7 @@ const int kFlushPeriodPartial = kFlushPeriodFull; class ResourceUpdateControllerTest; -class WebGraphicsContext3DForUploadTest : public FakeWebGraphicsContext3D { +class WebGraphicsContext3DForUploadTest : public TestWebGraphicsContext3D { public: WebGraphicsContext3DForUploadTest(ResourceUpdateControllerTest *test) : m_test(test) diff --git a/cc/scrollbar_layer_unittest.cc b/cc/scrollbar_layer_unittest.cc index e6a7bff..fa5cd63 100644 --- a/cc/scrollbar_layer_unittest.cc +++ b/cc/scrollbar_layer_unittest.cc @@ -10,10 +10,10 @@ #include "cc/test/fake_impl_proxy.h" #include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/fake_scrollbar_theme_painter.h" -#include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/fake_web_scrollbar.h" #include "cc/test/fake_web_scrollbar_theme_geometry.h" #include "cc/test/layer_tree_test_common.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "cc/tree_synchronizer.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebScrollbar.h" @@ -187,7 +187,7 @@ private: }; TEST_F(ScrollbarLayerTestMaxTextureSize, runTest) { - scoped_ptr<FakeWebGraphicsContext3D> context = FakeWebGraphicsContext3D::Create(); + scoped_ptr<TestWebGraphicsContext3D> context = TestWebGraphicsContext3D::Create(); int max_size = 0; context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); setScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); diff --git a/cc/test/fake_graphics_context_3d_unittest.cc b/cc/test/fake_graphics_context_3d_unittest.cc index 01f1fbf..f5e0c66 100644 --- a/cc/test/fake_graphics_context_3d_unittest.cc +++ b/cc/test/fake_graphics_context_3d_unittest.cc @@ -4,14 +4,14 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" namespace cc { namespace { -class ContextThatCountsMakeCurrents : public WebKit::FakeWebGraphicsContext3D { +class ContextThatCountsMakeCurrents : public TestWebGraphicsContext3D { public: ContextThatCountsMakeCurrents() : m_makeCurrentCount(0) { } virtual bool makeContextCurrent() OVERRIDE diff --git a/cc/test/fake_layer_tree_host_client.cc b/cc/test/fake_layer_tree_host_client.cc index f7d9ac0..077cf18 100644 --- a/cc/test/fake_layer_tree_host_client.cc +++ b/cc/test/fake_layer_tree_host_client.cc @@ -17,9 +17,9 @@ scoped_ptr<OutputSurface> FakeLayerImplTreeHostClient::createOutputSurface() WebKit::WebGraphicsContext3D::Attributes attrs; if (m_useDelegatingRenderer) - return FakeOutputSurface::CreateDelegating3d(FakeWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); + return FakeOutputSurface::CreateDelegating3d(TestWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); - return FakeOutputSurface::Create3d(FakeWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); + return FakeOutputSurface::Create3d(TestWebGraphicsContext3D::Create(attrs).PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); } scoped_ptr<InputHandler> FakeLayerImplTreeHostClient::createInputHandler() diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h index a2dd67c..360e253 100644 --- a/cc/test/fake_output_surface.h +++ b/cc/test/fake_output_surface.h @@ -10,7 +10,7 @@ #include "cc/compositor_frame.h" #include "cc/output_surface.h" #include "cc/test/fake_software_output_device.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" namespace cc { @@ -26,7 +26,7 @@ class FakeOutputSurface : public OutputSurface { static inline scoped_ptr<FakeOutputSurface> Create3d() { scoped_ptr<WebKit::WebGraphicsContext3D> context3d = - FakeWebGraphicsContext3D::Create( + TestWebGraphicsContext3D::Create( WebKit::WebGraphicsContext3D::Attributes()) .PassAs<WebKit::WebGraphicsContext3D>(); return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), false)); @@ -45,7 +45,7 @@ class FakeOutputSurface : public OutputSurface { static inline scoped_ptr<FakeOutputSurface> CreateDelegating3d() { scoped_ptr<WebKit::WebGraphicsContext3D> context3d = - FakeWebGraphicsContext3D::Create( + TestWebGraphicsContext3D::Create( WebKit::WebGraphicsContext3D::Attributes()) .PassAs<WebKit::WebGraphicsContext3D>(); return make_scoped_ptr(new FakeOutputSurface(context3d.Pass(), true)); @@ -86,7 +86,7 @@ private: static inline scoped_ptr<cc::OutputSurface> createFakeOutputSurface() { return FakeOutputSurface::Create3d( - FakeWebGraphicsContext3D::Create( + TestWebGraphicsContext3D::Create( WebKit::WebGraphicsContext3D::Attributes()) .PassAs<WebKit::WebGraphicsContext3D>()) .PassAs<cc::OutputSurface>(); diff --git a/cc/test/fake_web_graphics_context_3d_unittest.cc b/cc/test/fake_web_graphics_context_3d_unittest.cc index e099408..9f7228b 100644 --- a/cc/test/fake_web_graphics_context_3d_unittest.cc +++ b/cc/test/fake_web_graphics_context_3d_unittest.cc @@ -4,7 +4,7 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc new file mode 100644 index 0000000..c1ac0e7 --- /dev/null +++ b/cc/test/test_web_graphics_context_3d.cc @@ -0,0 +1,314 @@ +// Copyright 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 "cc/test/test_web_graphics_context_3d.h" + +#include <algorithm> +#include <string> + +#include "base/logging.h" +#include "gpu/GLES2/gl2extchromium.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "third_party/khronos/GLES2/gl2ext.h" + +using WebKit::WGC3Dboolean; +using WebKit::WGC3Denum; +using WebKit::WebGLId; +using WebKit::WebGraphicsContext3D; + +namespace cc { + +static const WebGLId kBufferId = 1; +static const WebGLId kFramebufferId = 2; +static const WebGLId kProgramId = 3; +static const WebGLId kRenderbufferId = 4; +static const WebGLId kShaderId = 5; + +static unsigned s_context_id = 1; + +const WebGLId TestWebGraphicsContext3D::kExternalTextureId = 1337; + +TestWebGraphicsContext3D::TestWebGraphicsContext3D() + : FakeWebGraphicsContext3D(), + context_id_(s_context_id++), + next_texture_id_(1), + have_extension_io_surface_(false), + have_extension_egl_image_(false), + times_make_current_succeeds_(-1), + times_bind_texture_succeeds_(-1), + times_end_query_succeeds_(-1), + context_lost_(false), + context_lost_callback_(NULL), + width_(0), + height_(0) { +} + +TestWebGraphicsContext3D::TestWebGraphicsContext3D( + const WebGraphicsContext3D::Attributes& attributes) + : FakeWebGraphicsContext3D(), + context_id_(s_context_id++), + next_texture_id_(1), + attributes_(attributes), + have_extension_io_surface_(false), + have_extension_egl_image_(false), + times_make_current_succeeds_(-1), + times_bind_texture_succeeds_(-1), + times_end_query_succeeds_(-1), + context_lost_(false), + context_lost_callback_(NULL), + width_(0), + height_(0) { +} + +TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { +} + +bool TestWebGraphicsContext3D::makeContextCurrent() { + if (times_make_current_succeeds_ >= 0) { + if (!times_make_current_succeeds_) { + loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, + GL_INNOCENT_CONTEXT_RESET_ARB); + } + --times_make_current_succeeds_; + } + return !context_lost_; +} + +int TestWebGraphicsContext3D::width() { + return width_; +} + +int TestWebGraphicsContext3D::height() { + return height_; +} + +void TestWebGraphicsContext3D::reshape(int width, int height) { + width_ = width; + height_ = height; +} + +bool TestWebGraphicsContext3D::isContextLost() { + return context_lost_; +} + +WGC3Denum TestWebGraphicsContext3D::getGraphicsResetStatusARB() { + return context_lost_ ? GL_UNKNOWN_CONTEXT_RESET_ARB : GL_NO_ERROR; +} + +WGC3Denum TestWebGraphicsContext3D::checkFramebufferStatus( + WGC3Denum target) { + if (context_lost_) + return GL_FRAMEBUFFER_UNDEFINED_OES; + return GL_FRAMEBUFFER_COMPLETE; +} + +WebGraphicsContext3D::Attributes + TestWebGraphicsContext3D::getContextAttributes() { + return attributes_; +} + +WebKit::WebString TestWebGraphicsContext3D::getString(WGC3Denum name) { + std::string string; + + if (name == GL_EXTENSIONS) { + if (have_extension_io_surface_) + string += "GL_CHROMIUM_iosurface GL_ARB_texture_rectangle "; + if (have_extension_egl_image_) + string += "GL_OES_EGL_image_external"; + } + + return WebKit::WebString::fromUTF8(string.c_str()); +} + +WebKit::WGC3Dint TestWebGraphicsContext3D::getUniformLocation( + WebGLId program, + const WebKit::WGC3Dchar* name) { + return 0; +} + +WebKit::WGC3Dsizeiptr TestWebGraphicsContext3D::getVertexAttribOffset( + WebKit::WGC3Duint index, + WGC3Denum pname) { + return 0; +} + +WGC3Dboolean TestWebGraphicsContext3D::isBuffer( + WebGLId buffer) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isEnabled( + WGC3Denum cap) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isFramebuffer( + WebGLId framebuffer) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isProgram( + WebGLId program) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isRenderbuffer( + WebGLId renderbuffer) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isShader( + WebGLId shader) { + return false; +} + +WGC3Dboolean TestWebGraphicsContext3D::isTexture( + WebGLId texture) { + return false; +} + +WebGLId TestWebGraphicsContext3D::createBuffer() { + return kBufferId | context_id_ << 16; +} + +void TestWebGraphicsContext3D::deleteBuffer(WebKit::WebGLId id) { + EXPECT_EQ(kBufferId | context_id_ << 16, id); +} + +WebGLId TestWebGraphicsContext3D::createFramebuffer() { + return kFramebufferId | context_id_ << 16; +} + +void TestWebGraphicsContext3D::deleteFramebuffer(WebKit::WebGLId id) { + EXPECT_EQ(kFramebufferId | context_id_ << 16, id); +} + +WebGLId TestWebGraphicsContext3D::createProgram() { + return kProgramId | context_id_ << 16; +} + +void TestWebGraphicsContext3D::deleteProgram(WebKit::WebGLId id) { + EXPECT_EQ(kProgramId | context_id_ << 16, id); +} + +WebGLId TestWebGraphicsContext3D::createRenderbuffer() { + return kRenderbufferId | context_id_ << 16; +} + +void TestWebGraphicsContext3D::deleteRenderbuffer(WebKit::WebGLId id) { + EXPECT_EQ(kRenderbufferId | context_id_ << 16, id); +} + +WebGLId TestWebGraphicsContext3D::createShader(WGC3Denum) { + return kShaderId | context_id_ << 16; +} + +void TestWebGraphicsContext3D::deleteShader(WebKit::WebGLId id) { + EXPECT_EQ(kShaderId | context_id_ << 16, id); +} + +WebGLId TestWebGraphicsContext3D::createTexture() { + WebGLId texture_id = NextTextureId(); + DCHECK_NE(texture_id, kExternalTextureId); + textures_.push_back(texture_id); + return texture_id; +} + +void TestWebGraphicsContext3D::deleteTexture(WebGLId texture_id) { + DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != + textures_.end()); + textures_.erase(std::find(textures_.begin(), textures_.end(), texture_id)); +} + +void TestWebGraphicsContext3D::attachShader(WebGLId program, WebGLId shader) { + EXPECT_EQ(kProgramId | context_id_ << 16, program); + EXPECT_EQ(kShaderId | context_id_ << 16, shader); +} + +void TestWebGraphicsContext3D::useProgram(WebGLId program) { + if (!program) + return; + EXPECT_EQ(kProgramId | context_id_ << 16, program); +} + +void TestWebGraphicsContext3D::bindBuffer(WGC3Denum target, WebGLId buffer) { + if (!buffer) + return; + EXPECT_EQ(kBufferId | context_id_ << 16, buffer); +} + +void TestWebGraphicsContext3D::bindFramebuffer( + WGC3Denum target, WebGLId framebuffer) { + if (!framebuffer) + return; + EXPECT_EQ(kFramebufferId | context_id_ << 16, framebuffer); +} + +void TestWebGraphicsContext3D::bindRenderbuffer( + WGC3Denum target, WebGLId renderbuffer) { + if (!renderbuffer) + return; + EXPECT_EQ(kRenderbufferId | context_id_ << 16, renderbuffer); +} + +void TestWebGraphicsContext3D::bindTexture( + WGC3Denum target, WebGLId texture_id) { + if (times_bind_texture_succeeds_ >= 0) { + if (!times_bind_texture_succeeds_) { + loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, + GL_INNOCENT_CONTEXT_RESET_ARB); + } + --times_bind_texture_succeeds_; + } + + if (!texture_id) + return; + if (texture_id == kExternalTextureId) + return; + DCHECK(std::find(textures_.begin(), textures_.end(), texture_id) != + textures_.end()); + used_textures_.insert(texture_id); +} + +void TestWebGraphicsContext3D::endQueryEXT(WebKit::WGC3Denum target) { + if (times_end_query_succeeds_ >= 0) { + if (!times_end_query_succeeds_) { + loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, + GL_INNOCENT_CONTEXT_RESET_ARB); + } + --times_end_query_succeeds_; + } +} + +void TestWebGraphicsContext3D::getQueryObjectuivEXT( + WebKit::WebGLId query, + WebKit::WGC3Denum pname, + WebKit::WGC3Duint* params) { + // If the context is lost, behave as if result is available. + if (pname == GL_QUERY_RESULT_AVAILABLE_EXT) + *params = 1; +} + +void TestWebGraphicsContext3D::setContextLostCallback( + WebGraphicsContextLostCallback* callback) { + context_lost_callback_ = callback; +} + +void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, + WGC3Denum other) { + if (context_lost_) + return; + context_lost_ = true; + if (context_lost_callback_) + context_lost_callback_->onContextLost(); +} + +WebKit::WebGLId TestWebGraphicsContext3D::NextTextureId() { + WebGLId texture_id = next_texture_id_++; + DCHECK(texture_id < (1 << 16)); + texture_id |= context_id_ << 16; + return texture_id; +} + +} // namespace cc diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h new file mode 100644 index 0000000..abfd9c9 --- /dev/null +++ b/cc/test/test_web_graphics_context_3d.h @@ -0,0 +1,151 @@ +// Copyright 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 CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ +#define CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ + +#include <vector> + +#include "base/compiler_specific.h" +#include "base/hash_tables.h" +#include "base/memory/scoped_ptr.h" +#include "base/stl_util.h" +#include "cc/fake_web_graphics_context_3d.h" +#include "third_party/khronos/GLES2/gl2.h" + +namespace cc { + +class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { + public: + static scoped_ptr<TestWebGraphicsContext3D> Create() { + return make_scoped_ptr(new TestWebGraphicsContext3D()); + } + static scoped_ptr<TestWebGraphicsContext3D> Create( + const WebKit::WebGraphicsContext3D::Attributes& attributes) { + return make_scoped_ptr(new TestWebGraphicsContext3D(attributes)); + } + virtual ~TestWebGraphicsContext3D(); + + virtual bool makeContextCurrent(); + + virtual int width(); + virtual int height(); + + virtual void reshape(int width, int height); + + virtual bool isContextLost(); + virtual WebKit::WGC3Denum getGraphicsResetStatusARB(); + + virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader); + virtual void bindBuffer(WebKit::WGC3Denum target, WebKit::WebGLId buffer); + virtual void bindFramebuffer( + WebKit::WGC3Denum target, WebKit::WebGLId framebuffer); + virtual void bindRenderbuffer( + WebKit::WGC3Denum target, WebKit::WebGLId renderbuffer); + virtual void bindTexture( + WebKit::WGC3Denum target, + WebKit::WebGLId texture_id); + + virtual WebKit::WGC3Denum checkFramebufferStatus(WebKit::WGC3Denum target); + + virtual Attributes getContextAttributes(); + + virtual WebKit::WebString getString(WebKit::WGC3Denum name); + virtual WebKit::WGC3Dint getUniformLocation( + WebKit::WebGLId program, + const WebKit::WGC3Dchar* name); + virtual WebKit::WGC3Dsizeiptr getVertexAttribOffset( + WebKit::WGC3Duint index, + WebKit::WGC3Denum pname); + + virtual WebKit::WGC3Dboolean isBuffer(WebKit::WebGLId buffer); + virtual WebKit::WGC3Dboolean isEnabled(WebKit::WGC3Denum cap); + virtual WebKit::WGC3Dboolean isFramebuffer(WebKit::WebGLId framebuffer); + virtual WebKit::WGC3Dboolean isProgram(WebKit::WebGLId program); + virtual WebKit::WGC3Dboolean isRenderbuffer(WebKit::WebGLId renderbuffer); + virtual WebKit::WGC3Dboolean isShader(WebKit::WebGLId shader); + virtual WebKit::WGC3Dboolean isTexture(WebKit::WebGLId texture); + + virtual void useProgram(WebKit::WebGLId program); + + virtual WebKit::WebGLId createBuffer(); + virtual WebKit::WebGLId createFramebuffer(); + virtual WebKit::WebGLId createProgram(); + virtual WebKit::WebGLId createRenderbuffer(); + virtual WebKit::WebGLId createShader(WebKit::WGC3Denum); + virtual WebKit::WebGLId createTexture(); + + virtual void deleteBuffer(WebKit::WebGLId id); + virtual void deleteFramebuffer(WebKit::WebGLId id); + virtual void deleteProgram(WebKit::WebGLId id); + virtual void deleteRenderbuffer(WebKit::WebGLId id); + virtual void deleteShader(WebKit::WebGLId id); + virtual void deleteTexture(WebKit::WebGLId texture_id); + + virtual void endQueryEXT(WebKit::WGC3Denum target); + virtual void getQueryObjectuivEXT( + WebKit::WebGLId query, + WebKit::WGC3Denum pname, + WebKit::WGC3Duint* params); + + virtual void setContextLostCallback( + WebGraphicsContextLostCallback* callback); + + virtual void loseContextCHROMIUM(WebKit::WGC3Denum current, + WebKit::WGC3Denum other); + + // When set, MakeCurrent() will fail after this many times. + void set_times_make_current_succeeds(int times) { + times_make_current_succeeds_ = times; + } + void set_times_bind_texture_succeeds(int times) { + times_bind_texture_succeeds_ = times; + } + void set_times_end_query_succeeds(int times) { + times_end_query_succeeds_ = times; + } + + size_t NumTextures() const { return textures_.size(); } + WebKit::WebGLId TextureAt(int i) const { return textures_[i]; } + + size_t NumUsedTextures() const { return used_textures_.size(); } + bool UsedTexture(int texture) const { + return ContainsKey(used_textures_, texture); + } + void ResetUsedTextures() { used_textures_.clear(); } + + void set_have_extension_io_surface(bool have) { + have_extension_io_surface_ = have; + } + void set_have_extension_egl_image(bool have) { + have_extension_egl_image_ = have; + } + + static const WebKit::WebGLId kExternalTextureId; + virtual WebKit::WebGLId NextTextureId(); + + protected: + TestWebGraphicsContext3D(); + TestWebGraphicsContext3D( + const WebKit::WebGraphicsContext3D::Attributes& attributes); + + unsigned context_id_; + unsigned next_texture_id_; + Attributes attributes_; + bool have_extension_io_surface_; + bool have_extension_egl_image_; + int times_make_current_succeeds_; + int times_bind_texture_succeeds_; + int times_end_query_succeeds_; + bool context_lost_; + WebGraphicsContextLostCallback* context_lost_callback_; + std::vector<WebKit::WebGLId> textures_; + base::hash_set<WebKit::WebGLId> used_textures_; + int width_; + int height_; +}; + +} // namespace cc + +#endif // CC_TEST_TEST_WEB_GRAPHICS_CONTEXT_3D_H_ diff --git a/cc/texture_copier_unittest.cc b/cc/texture_copier_unittest.cc index d22df6c..42a4d3c 100644 --- a/cc/texture_copier_unittest.cc +++ b/cc/texture_copier_unittest.cc @@ -4,7 +4,7 @@ #include "cc/texture_copier.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2.h" @@ -17,7 +17,7 @@ using testing::_; namespace cc { namespace { -class MockContext : public FakeWebGraphicsContext3D { +class MockContext : public TestWebGraphicsContext3D { public: MOCK_METHOD2(bindFramebuffer, void(WGC3Denum, WebGLId)); MOCK_METHOD3(texParameteri, void(WGC3Denum target, WGC3Denum pname, WGC3Dint param)); diff --git a/cc/texture_uploader_unittest.cc b/cc/texture_uploader_unittest.cc index a975c16..4e95628 100644 --- a/cc/texture_uploader_unittest.cc +++ b/cc/texture_uploader_unittest.cc @@ -5,7 +5,7 @@ #include "cc/texture_uploader.h" #include "cc/prioritized_resource.h" -#include "cc/test/fake_web_graphics_context_3d.h" +#include "cc/test/test_web_graphics_context_3d.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2.h" @@ -21,9 +21,9 @@ unsigned int RoundUp(unsigned int n, unsigned int mul) return (((n - 1) / mul) * mul) + mul; } -class FakeWebGraphicsContext3DTextureUpload : public FakeWebGraphicsContext3D { +class TestWebGraphicsContext3DTextureUpload : public TestWebGraphicsContext3D { public: - FakeWebGraphicsContext3DTextureUpload() + TestWebGraphicsContext3DTextureUpload() : m_resultAvailable(0) , m_unpackAlignment(4) { @@ -151,7 +151,7 @@ void uploadTexture(TextureUploader* uploader, WGC3Denum format, const gfx::Size& TEST(TextureUploaderTest, NumBlockingUploads) { - scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload); + scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGraphicsContext3DTextureUpload); scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false); fakeContext->setResultAvailable(0); @@ -172,7 +172,7 @@ TEST(TextureUploaderTest, NumBlockingUploads) TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) { - scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload); + scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGraphicsContext3DTextureUpload); scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false); fakeContext->setResultAvailable(0); @@ -195,7 +195,7 @@ TEST(TextureUploaderTest, MarkPendingUploadsAsNonBlocking) TEST(TextureUploaderTest, UploadContentsTest) { - scoped_ptr<FakeWebGraphicsContext3DTextureUpload> fakeContext(new FakeWebGraphicsContext3DTextureUpload); + scoped_ptr<TestWebGraphicsContext3DTextureUpload> fakeContext(new TestWebGraphicsContext3DTextureUpload); scoped_ptr<TextureUploader> uploader = TextureUploader::create(fakeContext.get(), false, false); uint8 buffer[256 * 256 * 4]; diff --git a/webkit/compositor_bindings/compositor_bindings.gyp b/webkit/compositor_bindings/compositor_bindings.gyp index 5d6f9cf..b1d87b2 100644 --- a/webkit/compositor_bindings/compositor_bindings.gyp +++ b/webkit/compositor_bindings/compositor_bindings.gyp @@ -37,6 +37,8 @@ 'web_to_ccvideo_frame_provider.h', 'web_layer_tree_view_impl.cc', 'web_layer_tree_view_impl.h', + 'web_layer_tree_view_impl_for_testing.cc', + 'web_layer_tree_view_impl_for_testing.h', 'web_scrollbar_layer_impl.cc', 'web_scrollbar_layer_impl.h', 'web_solid_color_layer_impl.cc', diff --git a/webkit/compositor_bindings/web_compositor_support_impl.cc b/webkit/compositor_bindings/web_compositor_support_impl.cc index 067f384..705f74f 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.cc +++ b/webkit/compositor_bindings/web_compositor_support_impl.cc @@ -80,22 +80,6 @@ void WebCompositorSupportImpl::shutdown() { impl_thread_message_loop_proxy_ = NULL; } -WebLayerTreeView* WebCompositorSupportImpl::createLayerTreeView( - WebLayerTreeViewClient* client, const WebLayer& root, - const WebLayerTreeView::Settings& settings) { - DCHECK(initialized_); - scoped_ptr<WebKit::WebLayerTreeViewImpl> layerTreeViewImpl( - new WebKit::WebLayerTreeViewImpl(client)); - scoped_ptr<cc::Thread> impl_thread; - if (impl_thread_message_loop_proxy_) - impl_thread = cc::ThreadImpl::createForDifferentThread( - impl_thread_message_loop_proxy_); - if (!layerTreeViewImpl->initialize(settings, impl_thread.Pass())) - return NULL; - layerTreeViewImpl->setRootLayer(root); - return layerTreeViewImpl.release(); -} - WebKit::WebCompositorOutputSurface* WebCompositorSupportImpl::createOutputSurfaceFor3D( WebKit::WebGraphicsContext3D* context) { @@ -171,4 +155,20 @@ WebTransformOperations* WebCompositorSupportImpl::createTransformOperations() { return new WebTransformOperationsImpl(); } +WebLayerTreeView* WebCompositorSupportImpl::createLayerTreeView( + WebLayerTreeViewClient* client, const WebLayer& root, + const WebLayerTreeView::Settings& settings) { + DCHECK(initialized_); + scoped_ptr<WebKit::WebLayerTreeViewImpl> layerTreeViewImpl( + new WebKit::WebLayerTreeViewImpl(client)); + scoped_ptr<cc::Thread> impl_thread; + if (impl_thread_message_loop_proxy_) + impl_thread = cc::ThreadImpl::createForDifferentThread( + impl_thread_message_loop_proxy_); + if (!layerTreeViewImpl->initialize(settings, impl_thread.Pass())) + return NULL; + layerTreeViewImpl->setRootLayer(root); + return layerTreeViewImpl.release(); +} + } // namespace webkit diff --git a/webkit/compositor_bindings/web_compositor_support_impl.h b/webkit/compositor_bindings/web_compositor_support_impl.h index d964613..1765b0f 100644 --- a/webkit/compositor_bindings/web_compositor_support_impl.h +++ b/webkit/compositor_bindings/web_compositor_support_impl.h @@ -29,9 +29,6 @@ class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { virtual void initialize(WebKit::WebThread* implThread); virtual bool isThreadingEnabled(); virtual void shutdown(); - virtual WebKit::WebLayerTreeView* createLayerTreeView( - WebKit::WebLayerTreeViewClient* client, const WebKit::WebLayer& root, - const WebKit::WebLayerTreeView::Settings& settings); virtual WebKit::WebCompositorOutputSurface* createOutputSurfaceFor3D( WebKit::WebGraphicsContext3D* context); virtual WebKit::WebCompositorOutputSurface* createOutputSurfaceForSoftware(); @@ -62,6 +59,9 @@ class WebCompositorSupportImpl : public WebKit::WebCompositorSupport { virtual WebKit::WebTransformOperations* createTransformOperations(); + virtual WebKit::WebLayerTreeView* createLayerTreeView( + WebKit::WebLayerTreeViewClient* client, const WebKit::WebLayer& root, + const WebKit::WebLayerTreeView::Settings& settings); private: scoped_refptr<base::MessageLoopProxy> impl_thread_message_loop_proxy_; bool initialized_; diff --git a/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.cc b/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.cc new file mode 100644 index 0000000..41e089f --- /dev/null +++ b/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.cc @@ -0,0 +1,187 @@ +// Copyright 2013 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 "webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h" + +#include "base/command_line.h" +#include "base/string_number_conversions.h" +#include "cc/fake_web_graphics_context_3d.h" +#include "cc/font_atlas.h" +#include "cc/input_handler.h" +#include "cc/layer.h" +#include "cc/layer_tree_host.h" +#include "cc/switches.h" +#include "cc/thread.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebInputHandler.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewClient.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebRenderingStats.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h" +#include "webkit/compositor_bindings/web_compositor_support_output_surface.h" +#include "webkit/compositor_bindings/web_layer_impl.h" +#include "webkit/compositor_bindings/web_rendering_stats_impl.h" +#include "webkit/compositor_bindings/web_to_ccinput_handler_adapter.h" + +namespace WebKit { + +WebLayerTreeViewImplForTesting::WebLayerTreeViewImplForTesting() {} + +WebLayerTreeViewImplForTesting::~WebLayerTreeViewImplForTesting() {} + +bool WebLayerTreeViewImplForTesting::initialize() { + layer_tree_host_ = cc::LayerTreeHost::create(this, cc::LayerTreeSettings(), + scoped_ptr<cc::Thread>()); + if (!layer_tree_host_.get()) + return false; + return true; +} + +void WebLayerTreeViewImplForTesting::setSurfaceReady() { + layer_tree_host_->setSurfaceReady(); +} + +void WebLayerTreeViewImplForTesting::setRootLayer(const WebLayer& root) { + layer_tree_host_->setRootLayer( + static_cast<const WebLayerImpl*>(&root)->layer()); +} + +void WebLayerTreeViewImplForTesting::clearRootLayer() { + layer_tree_host_->setRootLayer(scoped_refptr<cc::Layer>()); +} + +void WebLayerTreeViewImplForTesting::setViewportSize( + const WebSize& layout_viewport_size, const WebSize& device_viewport_size) { + layer_tree_host_->setViewportSize(layout_viewport_size, device_viewport_size); +} + +WebSize WebLayerTreeViewImplForTesting::layoutViewportSize() const { + return layer_tree_host_->layoutViewportSize(); +} + +WebSize WebLayerTreeViewImplForTesting::deviceViewportSize() const { + return layer_tree_host_->deviceViewportSize(); +} + +void WebLayerTreeViewImplForTesting::setDeviceScaleFactor( + float device_scale_factor) { + layer_tree_host_->setDeviceScaleFactor(device_scale_factor); +} + +float WebLayerTreeViewImplForTesting::deviceScaleFactor() const { + return layer_tree_host_->deviceScaleFactor(); +} + +void WebLayerTreeViewImplForTesting::setBackgroundColor(WebColor color) { + layer_tree_host_->setBackgroundColor(color); +} + +void WebLayerTreeViewImplForTesting::setHasTransparentBackground( + bool transparent) { + layer_tree_host_->setHasTransparentBackground(transparent); +} + +void WebLayerTreeViewImplForTesting::setVisible(bool visible) { + layer_tree_host_->setVisible(visible); +} + +void WebLayerTreeViewImplForTesting::setPageScaleFactorAndLimits( + float page_scale_factor, float minimum, float maximum) { + layer_tree_host_->setPageScaleFactorAndLimits(page_scale_factor, minimum, + maximum); +} + +void WebLayerTreeViewImplForTesting::startPageScaleAnimation( + const WebPoint& scroll, bool use_anchor, float new_page_scale, + double duration_sec) { +} + +void WebLayerTreeViewImplForTesting::setNeedsAnimate() { + layer_tree_host_->setNeedsAnimate(); +} + +void WebLayerTreeViewImplForTesting::setNeedsRedraw() { + layer_tree_host_->setNeedsRedraw(); +} + +bool WebLayerTreeViewImplForTesting::commitRequested() const { + return layer_tree_host_->commitRequested(); +} + +void WebLayerTreeViewImplForTesting::composite() { + layer_tree_host_->composite(); +} + +void WebLayerTreeViewImplForTesting::updateAnimations( + double frame_begin_timeSeconds) { + base::TimeTicks frame_begin_time = base::TimeTicks::FromInternalValue( + frame_begin_timeSeconds * base::Time::kMicrosecondsPerMillisecond); + layer_tree_host_->updateAnimations(frame_begin_time); +} + +void WebLayerTreeViewImplForTesting::didStopFlinging() { +} + +bool WebLayerTreeViewImplForTesting::compositeAndReadback(void* pixels, + const WebRect& rect) { + return layer_tree_host_->compositeAndReadback(pixels, rect); +} + +void WebLayerTreeViewImplForTesting::finishAllRendering() { + layer_tree_host_->finishAllRendering(); +} + +void WebLayerTreeViewImplForTesting::setDeferCommits(bool defer_commits) { + layer_tree_host_->setDeferCommits(defer_commits); +} + +void WebLayerTreeViewImplForTesting::renderingStats(WebRenderingStats&) const { +} + +void WebLayerTreeViewImplForTesting::willBeginFrame() { +} + +void WebLayerTreeViewImplForTesting::didBeginFrame() { +} + +void WebLayerTreeViewImplForTesting::animate( + double monotonic_frame_begin_time) { } + +void WebLayerTreeViewImplForTesting::layout() { } + +void WebLayerTreeViewImplForTesting::applyScrollAndScale( + gfx::Vector2d scroll_delta, float page_scale) { +} + +scoped_ptr<cc::OutputSurface> + WebLayerTreeViewImplForTesting::createOutputSurface() { + scoped_ptr<WebGraphicsContext3D> context3d( + new cc::FakeWebGraphicsContext3D); + return webkit::WebCompositorSupportOutputSurface::Create3d( + context3d.Pass()).PassAs<cc::OutputSurface>(); +} + +void WebLayerTreeViewImplForTesting::didRecreateOutputSurface(bool success) { } + +scoped_ptr<cc::InputHandler> + WebLayerTreeViewImplForTesting::createInputHandler() { + return scoped_ptr<cc::InputHandler>(); +} + +void WebLayerTreeViewImplForTesting::willCommit() { } + +void WebLayerTreeViewImplForTesting::didCommit() { } + +void WebLayerTreeViewImplForTesting::didCommitAndDrawFrame() { } + +void WebLayerTreeViewImplForTesting::didCompleteSwapBuffers() { } + +void WebLayerTreeViewImplForTesting::scheduleComposite() { } + +scoped_ptr<cc::FontAtlas> WebLayerTreeViewImplForTesting::createFontAtlas() { + return scoped_ptr<cc::FontAtlas>(); +} + +} // namespace WebKit diff --git a/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h b/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h new file mode 100644 index 0000000..72d39b2 --- /dev/null +++ b/webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h @@ -0,0 +1,84 @@ +// Copyright 2013 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 WEBKIT_COMPOSITOR_BINDINGS_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ +#define WEBKIT_COMPOSITOR_BINDINGS_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ + +#include "base/memory/scoped_ptr.h" +#include "cc/layer_tree_host_client.h" +#include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" +#include "webkit/compositor_bindings/webkit_compositor_bindings_export.h" + +namespace cc { +class FontAtlas; +class LayerTreeHost; +} + +namespace WebKit { +class WebLayer; +class WebLayerTreeViewClient; +class WebLayerTreeViewClientAdapter; + +class WebLayerTreeViewImplForTesting : public WebKit::WebLayerTreeView, + public cc::LayerTreeHostClient { + public: + WEBKIT_COMPOSITOR_BINDINGS_EXPORT WebLayerTreeViewImplForTesting(); + virtual ~WebLayerTreeViewImplForTesting(); + + WEBKIT_COMPOSITOR_BINDINGS_EXPORT bool initialize(); + + // WebLayerTreeView implementation. + virtual void setSurfaceReady(); + virtual void setRootLayer(const WebLayer&); + virtual void clearRootLayer(); + virtual void setViewportSize(const WebSize& layout_viewport_size, + const WebSize& device_viewport_size); + virtual WebSize layoutViewportSize() const; + virtual WebSize deviceViewportSize() const; + virtual void setDeviceScaleFactor(float); + virtual float deviceScaleFactor() const; + virtual void setBackgroundColor(WebColor); + virtual void setHasTransparentBackground(bool); + virtual void setVisible(bool); + virtual void setPageScaleFactorAndLimits(float page_scale_factor, + float minimum, + float maximum); + virtual void startPageScaleAnimation(const WebPoint& destination, + bool use_anchor, float new_page_scale, + double duration_sec); + virtual void setNeedsAnimate(); + virtual void setNeedsRedraw(); + virtual bool commitRequested() const; + virtual void composite(); + virtual void updateAnimations(double frame_begin_time); + virtual void didStopFlinging(); + virtual bool compositeAndReadback(void* pixels, const WebRect&); + virtual void finishAllRendering(); + virtual void setDeferCommits(bool defer_commits); + virtual void renderingStats(WebRenderingStats&) const; + + // cc::LayerTreeHostClient implementation. + virtual void willBeginFrame() OVERRIDE; + virtual void didBeginFrame() OVERRIDE; + virtual void animate(double monotonic_frame_begin_time) OVERRIDE; + virtual void layout() OVERRIDE; + virtual void applyScrollAndScale(gfx::Vector2d scroll_delta, float page_scale) + OVERRIDE; + virtual scoped_ptr<cc::OutputSurface> createOutputSurface() OVERRIDE; + virtual void didRecreateOutputSurface(bool success) OVERRIDE; + virtual scoped_ptr<cc::InputHandler> createInputHandler() OVERRIDE; + virtual void willCommit() OVERRIDE; + virtual void didCommit() OVERRIDE; + virtual void didCommitAndDrawFrame() OVERRIDE; + virtual void didCompleteSwapBuffers() OVERRIDE; + virtual void scheduleComposite() OVERRIDE; + virtual scoped_ptr<cc::FontAtlas> createFontAtlas(); + + private: + scoped_ptr<cc::LayerTreeHost> layer_tree_host_; +}; + +} // namespace Web_kit + +#endif // WEBKIT_COMPOSITOR_BINDINGS_WEB_LAYER_TREE_VIEW_IMPL_FOR_TESTING_H_ diff --git a/webkit/support/test_webkit_platform_support.cc b/webkit/support/test_webkit_platform_support.cc index c4ea206..e9f1961 100644 --- a/webkit/support/test_webkit_platform_support.cc +++ b/webkit/support/test_webkit_platform_support.cc @@ -31,6 +31,7 @@ #include "third_party/hyphen/hyphen.h" #include "v8/include/v8.h" #include "webkit/appcache/web_application_cache_host_impl.h" +#include "webkit/compositor_bindings/web_layer_tree_view_impl_for_testing.h" #include "webkit/database/vfs_backend.h" #include "webkit/glue/simple_webmimeregistry_impl.h" #include "webkit/glue/webclipboard_impl.h" @@ -648,3 +649,17 @@ WebKit::WebString TestWebKitPlatformSupport::webKitRootDir() { return webkit_support::GetWebKitRootDir(); } +#if HAVE_CREATELAYERTREEVIEWFORTESTING +WebKit::WebLayerTreeView* + TestWebKitPlatformSupport::createLayerTreeViewForTesting( + TestViewType type) { + // TODO(jamesr): Support TestViewTypeLayoutTest. + DCHECK_EQ(TestViewTypeUnitTest, type); + scoped_ptr<WebKit::WebLayerTreeViewImplForTesting> view( + new WebKit::WebLayerTreeViewImplForTesting); + if (!view->initialize()) + return NULL; + return view.release(); +} +#endif + diff --git a/webkit/support/test_webkit_platform_support.h b/webkit/support/test_webkit_platform_support.h index 8bf4f5a..ac824f2 100644 --- a/webkit/support/test_webkit_platform_support.h +++ b/webkit/support/test_webkit_platform_support.h @@ -27,7 +27,8 @@ class TestShellWebBlobRegistryImpl; namespace WebKit { - class WebAudioDevice; +class WebAudioDevice; +class WebLayerTreeView; } typedef struct _HyphenDict HyphenDict; @@ -159,6 +160,10 @@ class TestWebKitPlatformSupport : virtual void unregisterAllMockedURLs(); virtual void serveAsynchronousMockedRequests(); virtual WebKit::WebString webKitRootDir(); +#if HAVE_CREATELAYERTREEVIEWFORTESTING + virtual WebKit::WebLayerTreeView* createLayerTreeViewForTesting( + TestViewType type); +#endif private: TestShellWebMimeRegistryImpl mime_registry_; diff --git a/webkit/support/webkit_support.gypi b/webkit/support/webkit_support.gypi index a15b168..b3be7fa 100644 --- a/webkit/support/webkit_support.gypi +++ b/webkit/support/webkit_support.gypi @@ -23,6 +23,7 @@ '<(DEPTH)/ui/gl/gl.gyp:gl', '<(DEPTH)/ui/ui.gyp:shell_dialogs', '<(DEPTH)/ui/ui.gyp:ui', + '<(DEPTH)/webkit/compositor_bindings/compositor_bindings.gyp:webkit_compositor_bindings', 'glue', 'user_agent', 'webkit_base', |