diff options
44 files changed, 187 insertions, 385 deletions
diff --git a/cc/output/context_provider.cc b/cc/output/context_provider.cc index 454d96b..11b4bc5 100644 --- a/cc/output/context_provider.cc +++ b/cc/output/context_provider.cc @@ -14,7 +14,6 @@ ContextProvider::Capabilities::Capabilities() iosurface(false), map_image(false), post_sub_buffer(false), - swapbuffers_complete_callback(false), texture_format_bgra8888(false), texture_format_etc1(false), texture_rectangle(false), @@ -30,7 +29,6 @@ ContextProvider::Capabilities::Capabilities( iosurface(gpu_capabilities.iosurface), map_image(gpu_capabilities.map_image), post_sub_buffer(gpu_capabilities.post_sub_buffer), - swapbuffers_complete_callback(false), texture_format_bgra8888(gpu_capabilities.texture_format_bgra8888), texture_format_etc1(gpu_capabilities.texture_format_etc1), texture_rectangle(gpu_capabilities.texture_rectangle), diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h index ef46d09..54e75e9 100644 --- a/cc/output/context_provider.h +++ b/cc/output/context_provider.h @@ -41,7 +41,6 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { bool iosurface : 1; bool map_image : 1; bool post_sub_buffer : 1; - bool swapbuffers_complete_callback : 1; bool texture_format_bgra8888 : 1; bool texture_format_etc1 : 1; bool texture_rectangle : 1; @@ -79,12 +78,6 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> { virtual void SetLostContextCallback( const LostContextCallback& lost_context_callback) = 0; - // Sets a callback to be called when swap buffers completes. This should be - // called from the same thread that the context is bound to. - typedef base::Closure SwapBuffersCompleteCallback; - virtual void SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& swap_buffers_complete_callback) = 0; - // Sets a callback to be called when the memory policy changes. This should be // called from the same thread that the context is bound to. typedef base::Callback<void(const cc::ManagedMemoryPolicy& policy)> diff --git a/cc/output/gl_renderer_unittest.cc b/cc/output/gl_renderer_unittest.cc index 1760bc5..838d485 100644 --- a/cc/output/gl_renderer_unittest.cc +++ b/cc/output/gl_renderer_unittest.cc @@ -129,23 +129,6 @@ namespace { TEST_F(GLRendererShaderPixelTest, AllShadersCompile) { TestShaders(); } #endif -class FrameCountingContext : public TestWebGraphicsContext3D { - public: - FrameCountingContext() - : frame_(0) {} - - // WebGraphicsContext3D methods. - - // This method would normally do a glSwapBuffers under the hood. - virtual void prepareTexture() { frame_++; } - - // Methods added for test. - int frame_count() { return frame_; } - - private: - int frame_; -}; - class FakeRendererClient : public RendererClient { public: FakeRendererClient() @@ -218,11 +201,8 @@ class FakeRendererGL : public GLRenderer { class GLRendererTest : public testing::Test { protected: GLRendererTest() { - scoped_ptr<FrameCountingContext> context3d(new FrameCountingContext); - context3d_ = context3d.get(); - output_surface_ = FakeOutputSurface::Create3d( - context3d.PassAs<TestWebGraphicsContext3D>()).Pass(); + TestWebGraphicsContext3D::Create()).Pass(); CHECK(output_surface_->BindToClient(&output_surface_client_)); resource_provider_ = ResourceProvider::Create( @@ -236,7 +216,6 @@ class GLRendererTest : public testing::Test { void SwapBuffers() { renderer_->SwapBuffers(CompositorFrameMetadata()); } LayerTreeSettings settings_; - FrameCountingContext* context3d_; FakeOutputSurfaceClient output_surface_client_; scoped_ptr<FakeOutputSurface> output_surface_; FakeRendererClient renderer_client_; @@ -382,7 +361,7 @@ TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) { EXPECT_FALSE(renderer_->IsBackbufferDiscarded()); SwapBuffers(); - EXPECT_EQ(1, context3d_->frame_count()); + EXPECT_EQ(1u, output_surface_->num_sent_frames()); } TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) { @@ -1589,7 +1568,6 @@ class OutputSurfaceMockContext : public TestWebGraphicsContext3D { MOCK_METHOD0(ensureBackbufferCHROMIUM, void()); MOCK_METHOD0(discardBackbufferCHROMIUM, void()); MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer)); - MOCK_METHOD0(prepareTexture, void()); MOCK_METHOD3(reshapeWithScaleFactor, void(int width, int height, float scale_factor)); MOCK_METHOD4(drawElements, diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc index 7c56eea..c2f89e2 100644 --- a/cc/output/output_surface.cc +++ b/cc/output/output_surface.cc @@ -22,6 +22,7 @@ #include "cc/output/output_surface_client.h" #include "cc/scheduler/delay_based_time_source.h" #include "gpu/GLES2/gl2extchromium.h" +#include "gpu/command_buffer/client/context_support.h" #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" #include "third_party/khronos/GLES2/gl2.h" #include "third_party/khronos/GLES2/gl2ext.h" @@ -44,7 +45,6 @@ namespace cc { OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) : context_provider_(context_provider), - has_swap_buffers_complete_callback_(false), device_scale_factor_(-1), max_frames_pending_(0), pending_swap_buffers_(0), @@ -59,7 +59,6 @@ OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) OutputSurface::OutputSurface( scoped_ptr<cc::SoftwareOutputDevice> software_device) : software_device_(software_device.Pass()), - has_swap_buffers_complete_callback_(false), device_scale_factor_(-1), max_frames_pending_(0), pending_swap_buffers_(0), @@ -76,7 +75,6 @@ OutputSurface::OutputSurface( scoped_ptr<cc::SoftwareOutputDevice> software_device) : context_provider_(context_provider), software_device_(software_device.Pass()), - has_swap_buffers_complete_callback_(false), device_scale_factor_(-1), max_frames_pending_(0), pending_swap_buffers_(0), @@ -314,16 +312,12 @@ void OutputSurface::SetUpContext3d() { DCHECK(context_provider_); DCHECK(client_); - const ContextProvider::Capabilities& caps = - context_provider_->ContextCapabilities(); - - has_swap_buffers_complete_callback_ = caps.swapbuffers_complete_callback; - context_provider_->SetLostContextCallback( base::Bind(&OutputSurface::DidLoseOutputSurface, base::Unretained(this))); - context_provider_->SetSwapBuffersCompleteCallback(base::Bind( - &OutputSurface::OnSwapBuffersComplete, base::Unretained(this))); + context_provider_->ContextSupport()->SetSwapBuffersCompleteCallback( + base::Bind(&OutputSurface::OnSwapBuffersComplete, + base::Unretained(this))); context_provider_->SetMemoryPolicyChangedCallback( base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); @@ -343,10 +337,10 @@ void OutputSurface::ResetContext3d() { } context_provider_->SetLostContextCallback( ContextProvider::LostContextCallback()); - context_provider_->SetSwapBuffersCompleteCallback( - ContextProvider::SwapBuffersCompleteCallback()); context_provider_->SetMemoryPolicyChangedCallback( ContextProvider::MemoryPolicyChangedCallback()); + if (gpu::ContextSupport* support = context_provider_->ContextSupport()) + support->SetSwapBuffersCompleteCallback(base::Closure()); } context_provider_ = NULL; } @@ -401,21 +395,12 @@ void OutputSurface::SwapBuffers(cc::CompositorFrame* frame) { UpdateAndMeasureGpuLatency(); if (frame->gl_frame_data->sub_buffer_rect == gfx::Rect(frame->gl_frame_data->size)) { - // Note that currently this has the same effect as SwapBuffers; we should - // consider exposing a different entry point on WebGraphicsContext3D. - context_provider_->Context3d()->prepareTexture(); + context_provider_->ContextSupport()->Swap(); } else { - gfx::Rect sub_buffer_rect = frame->gl_frame_data->sub_buffer_rect; - context_provider_->Context3d()->postSubBufferCHROMIUM( - sub_buffer_rect.x(), - sub_buffer_rect.y(), - sub_buffer_rect.width(), - sub_buffer_rect.height()); + context_provider_->ContextSupport()->PartialSwapBuffers( + frame->gl_frame_data->sub_buffer_rect); } - if (!has_swap_buffers_complete_callback_) - PostSwapBuffersComplete(); - DidSwapBuffers(); } diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h index d724465..2d5dda8 100644 --- a/cc/output/output_surface.h +++ b/cc/output/output_surface.h @@ -154,7 +154,6 @@ class CC_EXPORT OutputSurface : public FrameRateControllerClient { struct cc::OutputSurface::Capabilities capabilities_; scoped_refptr<ContextProvider> context_provider_; scoped_ptr<cc::SoftwareOutputDevice> software_device_; - bool has_swap_buffers_complete_callback_; gfx::Size surface_size_; float device_scale_factor_; diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc index 3705a60..626b587 100644 --- a/cc/test/test_context_provider.cc +++ b/cc/test/test_context_provider.cc @@ -10,7 +10,6 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/logging.h" -#include "base/strings/string_split.h" #include "cc/test/test_gles2_interface.h" #include "cc/test/test_web_graphics_context_3d.h" @@ -36,27 +35,6 @@ class TestContextProvider::LostContextCallbackProxy TestContextProvider* provider_; }; -class TestContextProvider::SwapBuffersCompleteCallbackProxy - : public blink::WebGraphicsContext3D:: - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM { - public: - explicit SwapBuffersCompleteCallbackProxy(TestContextProvider* provider) - : provider_(provider) { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this); - } - - virtual ~SwapBuffersCompleteCallbackProxy() { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); - } - - virtual void onSwapBuffersComplete() { - provider_->OnSwapBuffersComplete(); - } - - private: - TestContextProvider* provider_; -}; - // static scoped_refptr<TestContextProvider> TestContextProvider::Create() { return Create(TestWebGraphicsContext3D::Create().Pass()); @@ -75,7 +53,8 @@ TestContextProvider::TestContextProvider( : context3d_(context.Pass()), context_gl_(new TestGLES2Interface(context3d_.get())), bound_(false), - destroyed_(false) { + destroyed_(false), + weak_ptr_factory_(this) { DCHECK(main_thread_checker_.CalledOnValidThread()); DCHECK(context3d_); context_thread_checker_.DetachFromThread(); @@ -102,8 +81,6 @@ bool TestContextProvider::BindToCurrentThread() { bound_ = true; lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); - swap_buffers_complete_callback_proxy_.reset( - new SwapBuffersCompleteCallbackProxy(this)); return true; } @@ -131,9 +108,6 @@ gpu::gles2::GLES2Interface* TestContextProvider::ContextGL() { } gpu::ContextSupport* TestContextProvider::ContextSupport() { - DCHECK(bound_); - DCHECK(context_thread_checker_.CalledOnValidThread()); - return &support_; } @@ -183,12 +157,6 @@ void TestContextProvider::OnLostContext() { base::ResetAndReturn(&lost_context_callback_).Run(); } -void TestContextProvider::OnSwapBuffersComplete() { - DCHECK(context_thread_checker_.CalledOnValidThread()); - if (!swap_buffers_complete_callback_.is_null()) - swap_buffers_complete_callback_.Run(); -} - TestWebGraphicsContext3D* TestContextProvider::TestContext3d() { DCHECK(bound_); DCHECK(context_thread_checker_.CalledOnValidThread()); @@ -214,13 +182,6 @@ void TestContextProvider::SetLostContextCallback( lost_context_callback_ = cb; } -void TestContextProvider::SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& cb) { - DCHECK(context_thread_checker_.CalledOnValidThread()); - DCHECK(swap_buffers_complete_callback_.is_null() || cb.is_null()); - swap_buffers_complete_callback_ = cb; -} - void TestContextProvider::SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& cb) { DCHECK(context_thread_checker_.CalledOnValidThread()); diff --git a/cc/test/test_context_provider.h b/cc/test/test_context_provider.h index 9eed424..cea9b35 100644 --- a/cc/test/test_context_provider.h +++ b/cc/test/test_context_provider.h @@ -7,6 +7,7 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" #include "cc/output/context_provider.h" @@ -39,8 +40,6 @@ class TestContextProvider : public cc::ContextProvider { virtual void VerifyContexts() OVERRIDE; virtual bool DestroyedOnMainThread() OVERRIDE; virtual void SetLostContextCallback(const LostContextCallback& cb) OVERRIDE; - virtual void SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& cb) OVERRIDE; virtual void SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& cb) OVERRIDE; @@ -62,8 +61,8 @@ class TestContextProvider : public cc::ContextProvider { explicit TestContextProvider(scoped_ptr<TestWebGraphicsContext3D> context); virtual ~TestContextProvider(); + private: void OnLostContext(); - void OnSwapBuffersComplete(); TestContextSupport support_; @@ -78,15 +77,14 @@ class TestContextProvider : public cc::ContextProvider { bool destroyed_; LostContextCallback lost_context_callback_; - SwapBuffersCompleteCallback swap_buffers_complete_callback_; MemoryPolicyChangedCallback memory_policy_changed_callback_; class LostContextCallbackProxy; scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_; - class SwapBuffersCompleteCallbackProxy; - scoped_ptr<SwapBuffersCompleteCallbackProxy> - swap_buffers_complete_callback_proxy_; + base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(TestContextProvider); }; } // namespace cc diff --git a/cc/test/test_context_support.cc b/cc/test/test_context_support.cc index be0d363..ec010fc 100644 --- a/cc/test/test_context_support.cc +++ b/cc/test/test_context_support.cc @@ -4,11 +4,16 @@ #include "cc/test/test_context_support.h" +#include "base/bind.h" #include "base/message_loop/message_loop.h" namespace cc { -TestContextSupport::TestContextSupport() {} +TestContextSupport::TestContextSupport() + : last_swap_type_(NO_SWAP), + weak_ptr_factory_(this) { +} + TestContextSupport::~TestContextSupport() {} void TestContextSupport::SignalSyncPoint(uint32 sync_point, @@ -43,4 +48,31 @@ void TestContextSupport::SetSurfaceVisibleCallback( set_visible_callback_ = set_visible_callback; } +void TestContextSupport::Swap() { + last_swap_type_ = SWAP; + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete, + weak_ptr_factory_.GetWeakPtr())); + CallAllSyncPointCallbacks(); +} + +void TestContextSupport::PartialSwapBuffers(gfx::Rect sub_buffer) { + last_swap_type_ = PARTIAL_SWAP; + last_partial_swap_rect_ = sub_buffer; + base::MessageLoop::current()->PostTask( + FROM_HERE, base::Bind(&TestContextSupport::OnSwapBuffersComplete, + weak_ptr_factory_.GetWeakPtr())); + CallAllSyncPointCallbacks(); +} + +void TestContextSupport::SetSwapBuffersCompleteCallback( + const base::Closure& callback) { + swap_buffers_complete_callback_ = callback; +} + +void TestContextSupport::OnSwapBuffersComplete() { + if (!swap_buffers_complete_callback_.is_null()) + swap_buffers_complete_callback_.Run(); +} + } // namespace cc diff --git a/cc/test/test_context_support.h b/cc/test/test_context_support.h index 9455e15..225ab7a 100644 --- a/cc/test/test_context_support.h +++ b/cc/test/test_context_support.h @@ -7,6 +7,7 @@ #include <vector> +#include "base/memory/weak_ptr.h" #include "gpu/command_buffer/client/context_support.h" namespace cc { @@ -24,6 +25,10 @@ class TestContextSupport : public gpu::ContextSupport { virtual void SetSurfaceVisible(bool visible) OVERRIDE; virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) OVERRIDE; + virtual void Swap() OVERRIDE; + virtual void PartialSwapBuffers(gfx::Rect sub_buffer) OVERRIDE; + virtual void SetSwapBuffersCompleteCallback( + const base::Closure& callback) OVERRIDE; void CallAllSyncPointCallbacks(); @@ -31,10 +36,30 @@ class TestContextSupport : public gpu::ContextSupport { void SetSurfaceVisibleCallback( const SurfaceVisibleCallback& set_visible_callback); + enum SwapType { + NO_SWAP, + SWAP, + PARTIAL_SWAP + }; + + SwapType last_swap_type() const { return last_swap_type_; } + gfx::Rect last_partial_swap_rect() const { + return last_partial_swap_rect_; + } + private: + void OnSwapBuffersComplete(); + std::vector<base::Closure> sync_point_callbacks_; SurfaceVisibleCallback set_visible_callback_; + base::Closure swap_buffers_complete_callback_; + + SwapType last_swap_type_; + gfx::Rect last_partial_swap_rect_; + + base::WeakPtrFactory<TestContextSupport> weak_ptr_factory_; + DISALLOW_COPY_AND_ASSIGN(TestContextSupport); }; diff --git a/cc/test/test_web_graphics_context_3d.cc b/cc/test/test_web_graphics_context_3d.cc index 7e972f7..91c8657 100644 --- a/cc/test/test_web_graphics_context_3d.cc +++ b/cc/test/test_web_graphics_context_3d.cc @@ -68,7 +68,6 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D() times_map_image_chromium_succeeds_(-1), times_map_buffer_chromium_succeeds_(-1), context_lost_callback_(NULL), - swap_buffers_callback_(NULL), next_program_id_(1000), next_shader_id_(2000), max_texture_size_(2048), @@ -84,7 +83,6 @@ TestWebGraphicsContext3D::TestWebGraphicsContext3D() peak_transfer_buffer_memory_used_bytes_(0), weak_ptr_factory_(this) { CreateNamespace(); - test_capabilities_.swapbuffers_complete_callback = true; } TestWebGraphicsContext3D::~TestWebGraphicsContext3D() { @@ -437,31 +435,6 @@ void TestWebGraphicsContext3D::loseContextCHROMIUM(WGC3Denum current, shared_contexts_.clear(); } -void TestWebGraphicsContext3D::setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback) { - if (test_capabilities_.swapbuffers_complete_callback) - swap_buffers_callback_ = callback; -} - -void TestWebGraphicsContext3D::prepareTexture() { - update_rect_ = gfx::Rect(width_, height_); - last_update_type_ = PrepareTexture; - - // TODO(jamesr): This should implemented as ContextSupport::SwapBuffers(). - if (swap_buffers_callback_) { - base::MessageLoop::current()->PostTask( - FROM_HERE, base::Bind(&TestWebGraphicsContext3D::SwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); - } - test_support_->CallAllSyncPointCallbacks(); -} - -void TestWebGraphicsContext3D::postSubBufferCHROMIUM( - int x, int y, int width, int height) { - update_rect_ = gfx::Rect(x, y, width, height); - last_update_type_ = PostSubBuffer; -} - void TestWebGraphicsContext3D::finish() { test_support_->CallAllSyncPointCallbacks(); } @@ -470,11 +443,6 @@ void TestWebGraphicsContext3D::flush() { test_support_->CallAllSyncPointCallbacks(); } -void TestWebGraphicsContext3D::SwapBuffersComplete() { - if (swap_buffers_callback_) - swap_buffers_callback_->onSwapBuffersComplete(); -} - void TestWebGraphicsContext3D::bindBuffer(blink::WGC3Denum target, blink::WebGLId buffer) { bound_buffer_ = buffer; diff --git a/cc/test/test_web_graphics_context_3d.h b/cc/test/test_web_graphics_context_3d.h index 8ad285a..8ea74f3 100644 --- a/cc/test/test_web_graphics_context_3d.h +++ b/cc/test/test_web_graphics_context_3d.h @@ -125,11 +125,6 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { virtual void loseContextCHROMIUM(blink::WGC3Denum current, blink::WGC3Denum other); - virtual void setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); - - virtual void prepareTexture(); - virtual void postSubBufferCHROMIUM(int x, int y, int width, int height); virtual void finish(); virtual void flush(); @@ -194,9 +189,6 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { } void ResetUsedTextures() { used_textures_.clear(); } - void set_support_swapbuffers_complete_callback(bool support) { - test_capabilities_.swapbuffers_complete_callback = support; - } void set_have_extension_io_surface(bool have) { test_capabilities_.iosurface = have; test_capabilities_.texture_rectangle = have; @@ -319,8 +311,6 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { TestWebGraphicsContext3D(); - void CallAllSyncPointCallbacks(); - void SwapBuffersComplete(); void CreateNamespace(); blink::WebGLId BoundTextureId(blink::WGC3Denum target); scoped_refptr<TestTexture> BoundTexture(blink::WGC3Denum target); @@ -336,7 +326,6 @@ class TestWebGraphicsContext3D : public FakeWebGraphicsContext3D { int times_map_image_chromium_succeeds_; int times_map_buffer_chromium_succeeds_; WebGraphicsContextLostCallback* context_lost_callback_; - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* swap_buffers_callback_; base::hash_set<unsigned> used_textures_; unsigned next_program_id_; base::hash_set<unsigned> program_set_; diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index 59ee586..4630adc 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -3399,14 +3399,13 @@ TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) { // Make sure damage tracking propagates all the way to the graphics context, // where it should request to swap only the sub-buffer that is damaged. TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { - scoped_refptr<TestContextProvider> provider( + scoped_refptr<TestContextProvider> context_provider( TestContextProvider::Create()); - scoped_ptr<OutputSurface> output_surface( - FakeOutputSurface::Create3d(provider)); + context_provider->BindToCurrentThread(); + context_provider->TestContext3d()->set_have_post_sub_buffer(true); - provider->BindToCurrentThread(); - TestWebGraphicsContext3D* context = provider->TestContext3d(); - context->set_have_post_sub_buffer(true); + scoped_ptr<OutputSurface> output_surface( + FakeOutputSurface::Create3d(context_provider)); // This test creates its own LayerTreeHostImpl, so // that we can force partial swap enabled. @@ -3441,14 +3440,9 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); layer_tree_host_impl->DidDrawAllLayers(frame); layer_tree_host_impl->SwapBuffers(frame); - gfx::Rect actual_swap_rect = context->update_rect(); - gfx::Rect expected_swap_rect = gfx::Rect(0, 0, 500, 500); - EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); - EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); - EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); - EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); - EXPECT_EQ(context->last_update_type(), - TestWebGraphicsContext3D::PrepareTexture); + EXPECT_EQ(TestContextSupport::SWAP, + context_provider->support()->last_swap_type()); + // Second frame, only the damaged area should get swapped. Damage should be // the union of old and new child rects. // expected damage rect: gfx::Rect(26, 28); @@ -3459,18 +3453,17 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); host_impl_->DidDrawAllLayers(frame); layer_tree_host_impl->SwapBuffers(frame); - actual_swap_rect = context->update_rect(); - expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); - EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); - EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); - EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); - EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); - EXPECT_EQ(context->last_update_type(), - TestWebGraphicsContext3D::PostSubBuffer); // Make sure that partial swap is constrained to the viewport dimensions // expected damage rect: gfx::Rect(500, 500); // expected swap rect: flipped damage rect, but also clamped to viewport + EXPECT_EQ(TestContextSupport::PARTIAL_SWAP, + context_provider->support()->last_swap_type()); + gfx::Rect expected_swap_rect(0, 500-28, 26, 28); + EXPECT_EQ(expected_swap_rect.ToString(), + context_provider->support()-> + last_partial_swap_rect().ToString()); + layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); // This will damage everything. layer_tree_host_impl->active_tree()->root_layer()->SetBackgroundColor( @@ -3479,14 +3472,9 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); host_impl_->DidDrawAllLayers(frame); layer_tree_host_impl->SwapBuffers(frame); - actual_swap_rect = context->update_rect(); - expected_swap_rect = gfx::Rect(10, 10); - EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); - EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); - EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); - EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); - EXPECT_EQ(context->last_update_type(), - TestWebGraphicsContext3D::PrepareTexture); + + EXPECT_EQ(TestContextSupport::SWAP, + context_provider->support()->last_swap_type()); } TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index f6db62a..2d1357f 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -3025,7 +3025,6 @@ class LayerTreeHostTestDeferredInitialize : public LayerTreeHostTest { OVERRIDE { scoped_ptr<TestWebGraphicsContext3D> context3d( TestWebGraphicsContext3D::Create()); - context3d->set_support_swapbuffers_complete_callback(false); return FakeOutputSurface::CreateDeferredGL( scoped_ptr<SoftwareOutputDevice>(new SoftwareOutputDevice)) diff --git a/content/browser/aura/gpu_process_transport_factory.cc b/content/browser/aura/gpu_process_transport_factory.cc index b5a8e7a4..2109134 100644 --- a/content/browser/aura/gpu_process_transport_factory.cc +++ b/content/browser/aura/gpu_process_transport_factory.cc @@ -453,13 +453,11 @@ GpuProcessTransportFactory::CreateContextCommon(int surface_id) { if (!gpu_channel_host) return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>(); GURL url("chrome://gpu/GpuProcessTransportFactory::CreateContextCommon"); - bool use_echo_for_swap_ack = true; scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( new WebGraphicsContext3DCommandBufferImpl( surface_id, url, gpu_channel_host.get(), - use_echo_for_swap_ack, attrs, false, WebGraphicsContext3DCommandBufferImpl::SharedMemoryLimits())); diff --git a/content/browser/renderer_host/compositor_impl_android.cc b/content/browser/renderer_host/compositor_impl_android.cc index b2e33c8..78b2398 100644 --- a/content/browser/renderer_host/compositor_impl_android.cc +++ b/content/browser/renderer_host/compositor_impl_android.cc @@ -377,12 +377,10 @@ CreateGpuProcessViewContext( limits.max_transfer_buffer_size = std::min( 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize); limits.mapped_memory_reclaim_limit = 2 * 1024 * 1024; - bool use_echo_for_swap_ack = true; return make_scoped_ptr( new WebGraphicsContext3DCommandBufferImpl(surface_id, url, gpu_channel_host.get(), - use_echo_for_swap_ack, attributes, false, limits)); diff --git a/content/browser/renderer_host/image_transport_factory_android.cc b/content/browser/renderer_host/image_transport_factory_android.cc index d11b0b7..5fa9a7e 100644 --- a/content/browser/renderer_host/image_transport_factory_android.cc +++ b/content/browser/renderer_host/image_transport_factory_android.cc @@ -81,12 +81,10 @@ CmdBufferImageTransportFactory::CmdBufferImageTransportFactory() { 3 * full_screen_texture_size_in_bytes, kDefaultMaxTransferBufferSize); limits.mapped_memory_reclaim_limit = WebGraphicsContext3DCommandBufferImpl::kNoLimit; - bool use_echo_for_swap_ack = true; context_.reset( new WebGraphicsContext3DCommandBufferImpl(0, // offscreen url, gpu_channel_host.get(), - use_echo_for_swap_ack, attrs, false, limits)); diff --git a/content/common/gpu/client/command_buffer_proxy_impl.cc b/content/common/gpu/client/command_buffer_proxy_impl.cc index 3cc39a6..1c8d45c 100644 --- a/content/common/gpu/client/command_buffer_proxy_impl.cc +++ b/content/common/gpu/client/command_buffer_proxy_impl.cc @@ -435,19 +435,17 @@ int CommandBufferProxyImpl::GetRouteID() const { return route_id_; } -bool CommandBufferProxyImpl::Echo(const base::Closure& callback) { +void CommandBufferProxyImpl::Echo(const base::Closure& callback) { if (last_state_.error != gpu::error::kNoError) { - return false; + return; } - if (!Send(new GpuCommandBufferMsg_Echo(route_id_, - GpuCommandBufferMsg_EchoAck(route_id_)))) { - return false; + if (!Send(new GpuCommandBufferMsg_Echo( + route_id_, GpuCommandBufferMsg_EchoAck(route_id_)))) { + return; } echo_tasks_.push(callback); - - return true; } bool CommandBufferProxyImpl::DiscardBackbuffer() { diff --git a/content/common/gpu/client/command_buffer_proxy_impl.h b/content/common/gpu/client/command_buffer_proxy_impl.h index fab196f..078c572 100644 --- a/content/common/gpu/client/command_buffer_proxy_impl.h +++ b/content/common/gpu/client/command_buffer_proxy_impl.h @@ -113,9 +113,9 @@ class CommandBufferProxyImpl virtual void SetSurfaceVisible(bool visible) OVERRIDE; virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; int GetRouteID() const; - bool Echo(const base::Closure& callback); bool ProduceFrontBuffer(const gpu::Mailbox& mailbox); void SetChannelErrorCallback(const base::Closure& callback); diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc index 9297a64..359ba4d 100644 --- a/content/common/gpu/client/context_provider_command_buffer.cc +++ b/content/common/gpu/client/context_provider_command_buffer.cc @@ -35,28 +35,6 @@ class ContextProviderCommandBuffer::LostContextCallbackProxy ContextProviderCommandBuffer* provider_; }; -class ContextProviderCommandBuffer::SwapBuffersCompleteCallbackProxy - : public blink::WebGraphicsContext3D:: - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM { - public: - explicit SwapBuffersCompleteCallbackProxy( - ContextProviderCommandBuffer* provider) - : provider_(provider) { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this); - } - - virtual ~SwapBuffersCompleteCallbackProxy() { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); - } - - virtual void onSwapBuffersComplete() { - provider_->OnSwapBuffersComplete(); - } - - private: - ContextProviderCommandBuffer* provider_; -}; - scoped_refptr<ContextProviderCommandBuffer> ContextProviderCommandBuffer::Create( scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d, @@ -90,7 +68,6 @@ ContextProviderCommandBuffer::~ContextProviderCommandBuffer() { context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( CommandBufferProxyImpl::MemoryAllocationChangedCallback()); } - swap_buffers_complete_callback_proxy_.reset(); lost_context_callback_proxy_.reset(); if (leak_on_destroy_) { @@ -118,8 +95,6 @@ bool ContextProviderCommandBuffer::BindToCurrentThread() { context3d_->pushGroupMarkerEXT(unique_context_name.c_str()); lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); - swap_buffers_complete_callback_proxy_.reset( - new SwapBuffersCompleteCallbackProxy(this)); context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback( base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged, base::Unretained(this))); @@ -201,12 +176,6 @@ void ContextProviderCommandBuffer::OnLostContext() { base::ResetAndReturn(&lost_context_callback_).Run(); } -void ContextProviderCommandBuffer::OnSwapBuffersComplete() { - DCHECK(context_thread_checker_.CalledOnValidThread()); - if (!swap_buffers_complete_callback_.is_null()) - swap_buffers_complete_callback_.Run(); -} - void ContextProviderCommandBuffer::OnMemoryAllocationChanged( const gpu::MemoryAllocation& allocation) { DCHECK(context_thread_checker_.CalledOnValidThread()); @@ -225,10 +194,6 @@ void ContextProviderCommandBuffer::OnMemoryAllocationChanged( void ContextProviderCommandBuffer::InitializeCapabilities() { Capabilities caps(context3d_->GetImplementation()->capabilities()); - // The swapbuffers complete callback is always supported by multi-process - // command buffer implementations. - caps.swapbuffers_complete_callback = true; - size_t mapped_memory_limit = context3d_->GetMappedMemoryLimit(); caps.max_transfer_buffer_usage_bytes = mapped_memory_limit == WebGraphicsContext3DCommandBufferImpl::kNoLimit @@ -253,14 +218,6 @@ void ContextProviderCommandBuffer::SetLostContextCallback( lost_context_callback_ = lost_context_callback; } -void ContextProviderCommandBuffer::SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& swap_buffers_complete_callback) { - DCHECK(context_thread_checker_.CalledOnValidThread()); - DCHECK(swap_buffers_complete_callback_.is_null() || - swap_buffers_complete_callback.is_null()); - swap_buffers_complete_callback_ = swap_buffers_complete_callback; -} - void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& memory_policy_changed_callback) { DCHECK(context_thread_checker_.CalledOnValidThread()); diff --git a/content/common/gpu/client/context_provider_command_buffer.h b/content/common/gpu/client/context_provider_command_buffer.h index 5b04cf4f..2f8e4f2 100644 --- a/content/common/gpu/client/context_provider_command_buffer.h +++ b/content/common/gpu/client/context_provider_command_buffer.h @@ -42,9 +42,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer virtual bool DestroyedOnMainThread() OVERRIDE; virtual void SetLostContextCallback( const LostContextCallback& lost_context_callback) OVERRIDE; - virtual void SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& swap_buffers_complete_callback) - OVERRIDE; virtual void SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& memory_policy_changed_callback) OVERRIDE; @@ -61,7 +58,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer virtual ~ContextProviderCommandBuffer(); void OnLostContext(); - void OnSwapBuffersComplete(); void OnMemoryAllocationChanged(const gpu::MemoryAllocation& allocation); private: @@ -77,7 +73,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer std::string debug_name_; LostContextCallback lost_context_callback_; - SwapBuffersCompleteCallback swap_buffers_complete_callback_; MemoryPolicyChangedCallback memory_policy_changed_callback_; base::Lock main_thread_lock_; @@ -86,10 +81,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer class LostContextCallbackProxy; scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_; - - class SwapBuffersCompleteCallbackProxy; - scoped_ptr<SwapBuffersCompleteCallbackProxy> - swap_buffers_complete_callback_proxy_; }; } // namespace content diff --git a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc index b3a356e..52e99bc 100644 --- a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc +++ b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.cc @@ -206,7 +206,6 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( int surface_id, const GURL& active_url, GpuChannelHost* host, - bool use_echo_for_swap_ack, const Attributes& attributes, bool bind_generates_resources, const SharedMemoryLimits& limits) @@ -218,16 +217,13 @@ WebGraphicsContext3DCommandBufferImpl::WebGraphicsContext3DCommandBufferImpl( context_lost_callback_(0), context_lost_reason_(GL_NO_ERROR), error_message_callback_(0), - swapbuffers_complete_callback_(0), attributes_(attributes), gpu_preference_(attributes.preferDiscreteGPU ? gfx::PreferDiscreteGpu : gfx::PreferIntegratedGpu), weak_ptr_factory_(this), initialized_(false), gl_(NULL), - frame_number_(0), bind_generates_resources_(bind_generates_resources), - use_echo_for_swap_ack_(use_echo_for_swap_ack), mem_limits_(limits), flush_id_(0) { } @@ -492,36 +488,12 @@ WebGraphicsContext3DCommandBufferImpl::GetContextSupport() { } void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { - TRACE_EVENT1("gpu", - "WebGraphicsContext3DCommandBufferImpl::SwapBuffers", - "frame", frame_number_); - frame_number_++; - - if (command_buffer_->GetLastState().error == gpu::error::kNoError) - gl_->SwapBuffers(); - - if (use_echo_for_swap_ack_) { - command_buffer_->Echo(base::Bind( - &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); - } - -#if defined(OS_MACOSX) - // It appears that making the compositor's on-screen context current on - // other platforms implies this flush. TODO(kbr): this means that the - // TOUCH build and, in the future, other platforms might need this. - gl_->Flush(); -#endif + NOTREACHED(); } void WebGraphicsContext3DCommandBufferImpl::postSubBufferCHROMIUM( int x, int y, int width, int height) { - // Same flow control as WebGraphicsContext3DCommandBufferImpl::prepareTexture - // (see above). - gl_->PostSubBufferCHROMIUM(x, y, width, height); - command_buffer_->Echo(base::Bind( - &WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); + NOTREACHED(); } DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float) @@ -1186,11 +1158,6 @@ DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId) DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId) -void WebGraphicsContext3DCommandBufferImpl::OnSwapBuffersComplete() { - if (swapbuffers_complete_callback_) - swapbuffers_complete_callback_->onSwapBuffersComplete(); -} - void WebGraphicsContext3DCommandBufferImpl::setErrorMessageCallback( WebGraphicsContext3D::WebGraphicsErrorMessageCallback* cb) { error_message_callback_ = cb; @@ -1228,22 +1195,14 @@ WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( const SharedMemoryLimits& limits) { if (!host) return NULL; - bool use_echo_for_swap_ack = true; return new WebGraphicsContext3DCommandBufferImpl(0, active_url, host, - use_echo_for_swap_ack, attributes, false, limits); } -void WebGraphicsContext3DCommandBufferImpl:: - setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* cb) { - swapbuffers_complete_callback_ = cb; -} - DELEGATE_TO_GL_5(texImageIOSurface2DCHROMIUM, TexImageIOSurface2DCHROMIUM, WGC3Denum, WGC3Dint, WGC3Dint, WGC3Duint, WGC3Duint) diff --git a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h index d38dacc..a50c9d5 100644 --- a/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h +++ b/content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h @@ -77,7 +77,6 @@ class WebGraphicsContext3DCommandBufferImpl int surface_id, const GURL& active_url, GpuChannelHost* host, - bool use_echo_for_swap_ack, const Attributes& attributes, bool bind_generates_resources, const SharedMemoryLimits& limits); @@ -527,10 +526,6 @@ class WebGraphicsContext3DCommandBufferImpl virtual void setErrorMessageCallback( WebGraphicsContext3D::WebGraphicsErrorMessageCallback* callback); - virtual void setSwapBuffersCompleteCallbackCHROMIUM( - WebGraphicsContext3D:: - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* callback); - virtual void texImageIOSurface2DCHROMIUM( WGC3Denum target, WGC3Dint width, WGC3Dint height, WGC3Duint ioSurfaceId, WGC3Duint plane); @@ -688,8 +683,6 @@ class WebGraphicsContext3DCommandBufferImpl // unnecessary complexity at the moment. bool CreateContext(bool onscreen); - // SwapBuffers callback. - void OnSwapBuffersComplete(); virtual void OnGpuChannelLost(); virtual void OnErrorMessage(const std::string& message, int id); @@ -710,9 +703,6 @@ class WebGraphicsContext3DCommandBufferImpl scoped_ptr<WebGraphicsContext3DErrorMessageCallback> client_error_message_callback_; - WebGraphicsContext3D::WebGraphicsSwapBuffersCompleteCallbackCHROMIUM* - swapbuffers_complete_callback_; - blink::WebGraphicsContext3D::Attributes attributes_; gfx::GpuPreference gpu_preference_; @@ -729,9 +719,7 @@ class WebGraphicsContext3DCommandBufferImpl scoped_ptr<gpu::gles2::GLES2Implementation> real_gl_; scoped_ptr<gpu::gles2::GLES2Interface> trace_gl_; Error last_error_; - int frame_number_; bool bind_generates_resources_; - bool use_echo_for_swap_ack_; SharedMemoryLimits mem_limits_; uint32_t flush_id_; diff --git a/content/renderer/pepper/pepper_platform_context_3d.cc b/content/renderer/pepper/pepper_platform_context_3d.cc index fab9c00..b9fd07b 100644 --- a/content/renderer/pepper/pepper_platform_context_3d.cc +++ b/content/renderer/pepper/pepper_platform_context_3d.cc @@ -149,8 +149,8 @@ void PlatformContext3D::SetOnConsoleMessageCallback( console_message_callback_ = task; } -bool PlatformContext3D::Echo(const base::Closure& task) { - return command_buffer_->Echo(task); +void PlatformContext3D::Echo(const base::Closure& task) { + command_buffer_->Echo(task); } void PlatformContext3D::OnContextLost() { diff --git a/content/renderer/pepper/pepper_platform_context_3d.h b/content/renderer/pepper/pepper_platform_context_3d.h index 4170e18..2520bbd 100644 --- a/content/renderer/pepper/pepper_platform_context_3d.h +++ b/content/renderer/pepper/pepper_platform_context_3d.h @@ -59,7 +59,7 @@ class PlatformContext3D { void SetOnConsoleMessageCallback(const ConsoleMessageCallback& callback); // Run the callback once the channel has been flushed. - bool Echo(const base::Closure& task); + void Echo(const base::Closure& task); private: bool InitRaw(); diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc index 48ddf43..b44c0f7 100644 --- a/content/renderer/render_widget.cc +++ b/content/renderer/render_widget.cc @@ -2855,20 +2855,11 @@ RenderWidget::CreateGraphicsContext3D( max_transfer_buffer_usage_mb * kBytesPerMegabyte; #endif - bool use_echo_for_swap_ack = true; - if (!is_threaded_compositing_enabled_) { -#if (defined(OS_MACOSX) || defined(OS_WIN)) && !defined(USE_AURA) - // ViewMsg_SwapBuffers_ACK is used instead for single-threaded path. - use_echo_for_swap_ack = false; -#endif - } - scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context( new WebGraphicsContext3DCommandBufferImpl( surface_id(), GetURLForGraphicsContext3D(), gpu_channel_host.get(), - use_echo_for_swap_ack, attributes, false /* bind generates resources */, limits)); diff --git a/gpu/command_buffer/client/client_test_helper.h b/gpu/command_buffer/client/client_test_helper.h index 6f0bc6d..e071f5a 100644 --- a/gpu/command_buffer/client/client_test_helper.h +++ b/gpu/command_buffer/client/client_test_helper.h @@ -99,6 +99,7 @@ class MockClientGpuControl : public GpuControl { MOCK_METHOD0(InsertSyncPoint, uint32()); MOCK_METHOD2(SignalSyncPoint, void(uint32 id, const base::Closure& callback)); + MOCK_METHOD1(Echo, void(const base::Closure& callback)); MOCK_METHOD2(SignalQuery, void(uint32 query, const base::Closure& callback)); MOCK_METHOD1(SetSurfaceVisible, void(bool visible)); diff --git a/gpu/command_buffer/client/context_support.h b/gpu/command_buffer/client/context_support.h index dcb0842..6a897208 100644 --- a/gpu/command_buffer/client/context_support.h +++ b/gpu/command_buffer/client/context_support.h @@ -6,6 +6,7 @@ #define GPU_COMMAND_BUFFER_CLIENT_CONTEXT_SUPPORT_H_ #include "base/callback.h" +#include "ui/gfx/rect.h" namespace gpu { struct ManagedMemoryStats; @@ -26,6 +27,12 @@ class ContextSupport { virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats) = 0; + virtual void Swap() = 0; + virtual void PartialSwapBuffers(gfx::Rect sub_buffer) = 0; + + virtual void SetSwapBuffersCompleteCallback( + const base::Closure& callback) = 0; + protected: ContextSupport() {} virtual ~ContextSupport() {} diff --git a/gpu/command_buffer/client/gles2_implementation.cc b/gpu/command_buffer/client/gles2_implementation.cc index 62fc6d2..b0efc37 100644 --- a/gpu/command_buffer/client/gles2_implementation.cc +++ b/gpu/command_buffer/client/gles2_implementation.cc @@ -2775,6 +2775,32 @@ void GLES2Implementation::GetVertexAttribiv( CheckGLError(); } +void GLES2Implementation::Swap() { + SwapBuffers(); + gpu_control_->Echo( + base::Bind(&GLES2Implementation::OnSwapBuffersComplete, + weak_ptr_factory_.GetWeakPtr())); +} + +void GLES2Implementation::PartialSwapBuffers(gfx::Rect sub_buffer) { + PostSubBufferCHROMIUM(sub_buffer.x(), + sub_buffer.y(), + sub_buffer.width(), + sub_buffer.height()); + gpu_control_->Echo(base::Bind(&GLES2Implementation::OnSwapBuffersComplete, + weak_ptr_factory_.GetWeakPtr())); +} + +void GLES2Implementation::SetSwapBuffersCompleteCallback( + const base::Closure& swap_buffers_complete_callback) { + swap_buffers_complete_callback_ = swap_buffers_complete_callback; +} + +void GLES2Implementation::OnSwapBuffersComplete() { + if (!swap_buffers_complete_callback_.is_null()) + swap_buffers_complete_callback_.Run(); +} + GLboolean GLES2Implementation::EnableFeatureCHROMIUM( const char* feature) { GPU_CLIENT_SINGLE_THREAD_CHECK(); diff --git a/gpu/command_buffer/client/gles2_implementation.h b/gpu/command_buffer/client/gles2_implementation.h index 66b33d9..6b6877f 100644 --- a/gpu/command_buffer/client/gles2_implementation.h +++ b/gpu/command_buffer/client/gles2_implementation.h @@ -215,6 +215,13 @@ class GLES2_IMPL_EXPORT GLES2Implementation virtual void GetVertexAttribiv( GLuint index, GLenum pname, GLint* params) OVERRIDE; + // ContextSupport implementation. + virtual void Swap() OVERRIDE; + virtual void PartialSwapBuffers(gfx::Rect sub_buffer) OVERRIDE; + virtual void SetSwapBuffersCompleteCallback( + const base::Closure& swap_buffers_complete_callback) + OVERRIDE; + void GetProgramInfoCHROMIUMHelper(GLuint program, std::vector<int8>* result); GLint GetAttribLocationHelper(GLuint program, const char* name); GLint GetUniformLocationHelper(GLuint program, const char* name); @@ -249,6 +256,10 @@ class GLES2_IMPL_EXPORT GLES2Implementation return capabilities_; } + GpuControl* gpu_control() { + return gpu_control_; + } + private: friend class GLES2ImplementationTest; friend class VertexArrayObjectManager; @@ -578,6 +589,8 @@ class GLES2_IMPL_EXPORT GLES2Implementation void RunIfContextNotLost(const base::Closure& callback); + void OnSwapBuffersComplete(); + bool GetBoundPixelTransferBuffer( GLenum target, const char* function_name, GLuint* buffer_id); BufferTracker::Buffer* GetBoundPixelUnpackTransferBufferIfValid( @@ -702,6 +715,9 @@ class GLES2_IMPL_EXPORT GLES2Implementation Capabilities capabilities_; + bool use_echo_for_swap_ack_; + base::Closure swap_buffers_complete_callback_; + base::WeakPtrFactory<GLES2Implementation> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(GLES2Implementation); diff --git a/gpu/command_buffer/common/gpu_control.h b/gpu/command_buffer/common/gpu_control.h index 1331a25..d971972 100644 --- a/gpu/command_buffer/common/gpu_control.h +++ b/gpu/command_buffer/common/gpu_control.h @@ -60,6 +60,9 @@ class GPU_EXPORT GpuControl { virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats) = 0; + // Invokes the callback once the context has been flushed. + virtual void Echo(const base::Closure& callback) = 0; + private: DISALLOW_COPY_AND_ASSIGN(GpuControl); }; diff --git a/gpu/command_buffer/service/feature_info.cc b/gpu/command_buffer/service/feature_info.cc index c9f0733..cbcf968 100644 --- a/gpu/command_buffer/service/feature_info.cc +++ b/gpu/command_buffer/service/feature_info.cc @@ -694,9 +694,6 @@ void FeatureInfo::InitializeFeatures() { feature_flags_.ext_frag_depth = true; } - if (!disallowed_features_.swap_buffer_complete_callback) - AddExtensionString("GL_CHROMIUM_swapbuffers_complete_callback"); - bool ui_gl_fence_works = extensions.Contains("GL_NV_fence") || extensions.Contains("GL_ARB_sync") || extensions.Contains("EGL_KHR_fence_sync"); diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.h b/gpu/command_buffer/service/gles2_cmd_decoder.h index ce65f7e..87c9335 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder.h @@ -43,12 +43,10 @@ class VertexArrayManager; struct DisallowedFeatures { DisallowedFeatures() : multisampling(false), - swap_buffer_complete_callback(false), gpu_memory_manager(false) { } bool multisampling; - bool swap_buffer_complete_callback; bool gpu_memory_manager; }; diff --git a/gpu/command_buffer/service/gpu_control_service.cc b/gpu/command_buffer/service/gpu_control_service.cc index abb8e91..7c0eb8c 100644 --- a/gpu/command_buffer/service/gpu_control_service.cc +++ b/gpu/command_buffer/service/gpu_control_service.cc @@ -101,6 +101,10 @@ void GpuControlService::SendManagedMemoryStats( NOTREACHED(); } +void GpuControlService::Echo(const base::Closure& callback) { + NOTREACHED(); +} + bool GpuControlService::RegisterGpuMemoryBuffer( int32 id, gfx::GpuMemoryBufferHandle buffer, diff --git a/gpu/command_buffer/service/gpu_control_service.h b/gpu/command_buffer/service/gpu_control_service.h index 13bb3c0..3764ad4 100644 --- a/gpu/command_buffer/service/gpu_control_service.h +++ b/gpu/command_buffer/service/gpu_control_service.h @@ -29,10 +29,9 @@ class GPU_EXPORT GpuControlService : public GpuControl { const gpu::Capabilities& decoder_capabilities); virtual ~GpuControlService(); - // Overridden from GpuControl: + // GpuControl implementation. virtual gpu::Capabilities GetCapabilities() OVERRIDE; - virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer( size_t width, size_t height, @@ -49,6 +48,7 @@ class GPU_EXPORT GpuControlService : public GpuControl { virtual void SetSurfaceVisible(bool visible) OVERRIDE; virtual void SendManagedMemoryStats(const ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; // Register an existing gpu memory buffer and get an ID that can be used // to identify it in the command buffer. diff --git a/gpu/command_buffer/service/in_process_command_buffer.cc b/gpu/command_buffer/service/in_process_command_buffer.cc index 4de4531..af14778 100644 --- a/gpu/command_buffer/service/in_process_command_buffer.cc +++ b/gpu/command_buffer/service/in_process_command_buffer.cc @@ -464,7 +464,6 @@ bool InProcessCommandBuffer::InitializeOnGpuThread( } gles2::DisallowedFeatures disallowed_features; - disallowed_features.swap_buffer_complete_callback = true; disallowed_features.gpu_memory_manager = true; if (!decoder_->Initialize(surface_, context_, @@ -735,6 +734,10 @@ void InProcessCommandBuffer::SendManagedMemoryStats( const gpu::ManagedMemoryStats& stats) { } +void InProcessCommandBuffer::Echo(const base::Closure& callback) { + QueueTask(WrapCallback(callback)); +} + gpu::error::Error InProcessCommandBuffer::GetLastError() { CheckSequencedThread(); return last_state_.error; diff --git a/gpu/command_buffer/service/in_process_command_buffer.h b/gpu/command_buffer/service/in_process_command_buffer.h index 6665b9f..b00f25b 100644 --- a/gpu/command_buffer/service/in_process_command_buffer.h +++ b/gpu/command_buffer/service/in_process_command_buffer.h @@ -125,6 +125,7 @@ class GPU_EXPORT InProcessCommandBuffer : public CommandBuffer, virtual void SetSurfaceVisible(bool visible) OVERRIDE; virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; // The serializer interface to the GPU service (i.e. thread). class SchedulerClient { diff --git a/gpu/gpu.gyp b/gpu/gpu.gyp index fdb2372..f809c1f 100644 --- a/gpu/gpu.gyp +++ b/gpu/gpu.gyp @@ -46,6 +46,7 @@ '../base/base.gyp:base', '../third_party/khronos/khronos.gyp:khronos_headers', '../ui/gl/gl.gyp:gl', + '../ui/gfx/gfx.gyp:gfx', 'command_buffer/command_buffer.gyp:gles2_utils', 'gles2_cmd_helper', ], @@ -67,6 +68,7 @@ 'dependencies': [ '../base/base.gyp:base', '../third_party/khronos/khronos.gyp:khronos_headers', + '../ui/gfx/gfx.gyp:gfx', 'command_buffer/command_buffer.gyp:gles2_utils', 'gles2_cmd_helper', ], diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.cc b/ppapi/proxy/ppapi_command_buffer_proxy.cc index 8af9e89..a6da2107 100644 --- a/ppapi/proxy/ppapi_command_buffer_proxy.cc +++ b/ppapi/proxy/ppapi_command_buffer_proxy.cc @@ -139,6 +139,10 @@ void PpapiCommandBufferProxy::DestroyTransferBuffer(int32 id) { ppapi::API_ID_PPB_GRAPHICS_3D, resource_, id)); } +void PpapiCommandBufferProxy::Echo(const base::Closure& callback) { + NOTREACHED(); +} + gpu::Buffer PpapiCommandBufferProxy::GetTransferBuffer(int32 id) { if (last_state_.error != gpu::error::kNoError) return gpu::Buffer(); diff --git a/ppapi/proxy/ppapi_command_buffer_proxy.h b/ppapi/proxy/ppapi_command_buffer_proxy.h index 05085f5..16809bd 100644 --- a/ppapi/proxy/ppapi_command_buffer_proxy.h +++ b/ppapi/proxy/ppapi_command_buffer_proxy.h @@ -21,9 +21,8 @@ namespace proxy { class ProxyChannel; -class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy - : public gpu::CommandBuffer, - public gpu::GpuControl { +class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer, + public gpu::GpuControl { public: PpapiCommandBufferProxy(const HostResource& resource, ProxyChannel* channel); @@ -64,6 +63,7 @@ class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy virtual void SetSurfaceVisible(bool visible) OVERRIDE; virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) OVERRIDE; + virtual void Echo(const base::Closure& callback) OVERRIDE; private: bool Send(IPC::Message* msg); diff --git a/ppapi/shared_impl/ppb_graphics_3d_shared.cc b/ppapi/shared_impl/ppb_graphics_3d_shared.cc index d134b51..be8ee76 100644 --- a/ppapi/shared_impl/ppb_graphics_3d_shared.cc +++ b/ppapi/shared_impl/ppb_graphics_3d_shared.cc @@ -118,8 +118,8 @@ bool PPB_Graphics3D_Shared::CreateGLES2Impl( const int32 kMaxTransferBufferSize = 16 * 1024 * 1024; transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); - bool bind_creates_resources = true; - bool free_everything_when_invisible = false; + const bool bind_creates_resources = true; + const bool free_everything_when_invisible = false; // Create the object exposing the OpenGL API. gles2_impl_.reset(new gpu::gles2::GLES2Implementation( diff --git a/webkit/common/gpu/context_provider_in_process.cc b/webkit/common/gpu/context_provider_in_process.cc index 570ef40..99359de 100644 --- a/webkit/common/gpu/context_provider_in_process.cc +++ b/webkit/common/gpu/context_provider_in_process.cc @@ -37,27 +37,6 @@ class ContextProviderInProcess::LostContextCallbackProxy ContextProviderInProcess* provider_; }; -class ContextProviderInProcess::SwapBuffersCompleteCallbackProxy - : public blink::WebGraphicsContext3D:: - WebGraphicsSwapBuffersCompleteCallbackCHROMIUM { - public: - explicit SwapBuffersCompleteCallbackProxy(ContextProviderInProcess* provider) - : provider_(provider) { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(this); - } - - virtual ~SwapBuffersCompleteCallbackProxy() { - provider_->context3d_->setSwapBuffersCompleteCallbackCHROMIUM(NULL); - } - - virtual void onSwapBuffersComplete() { - provider_->OnSwapBuffersComplete(); - } - - private: - ContextProviderInProcess* provider_; -}; - // static scoped_refptr<ContextProviderInProcess> ContextProviderInProcess::Create( scoped_ptr<WebGraphicsContext3DInProcessCommandBufferImpl> context3d, @@ -117,8 +96,6 @@ bool ContextProviderInProcess::BindToCurrentThread() { context3d_->pushGroupMarkerEXT(unique_context_name.c_str()); lost_context_callback_proxy_.reset(new LostContextCallbackProxy(this)); - swap_buffers_complete_callback_proxy_.reset( - new SwapBuffersCompleteCallbackProxy(this)); return true; } @@ -149,7 +126,10 @@ blink::WebGraphicsContext3D* ContextProviderInProcess::Context3d() { } ::gpu::ContextSupport* ContextProviderInProcess::ContextSupport() { - DCHECK(lost_context_callback_proxy_); // Is bound to thread. + DCHECK(context3d_); + if (!lost_context_callback_proxy_) + return NULL; // Not bound to anything. + DCHECK(context_thread_checker_.CalledOnValidThread()); return context3d_->GetContextSupport(); @@ -202,12 +182,6 @@ void ContextProviderInProcess::OnLostContext() { base::ResetAndReturn(&lost_context_callback_).Run(); } -void ContextProviderInProcess::OnSwapBuffersComplete() { - DCHECK(context_thread_checker_.CalledOnValidThread()); - if (!swap_buffers_complete_callback_.is_null()) - swap_buffers_complete_callback_.Run(); -} - bool ContextProviderInProcess::DestroyedOnMainThread() { DCHECK(main_thread_checker_.CalledOnValidThread()); @@ -223,14 +197,6 @@ void ContextProviderInProcess::SetLostContextCallback( lost_context_callback_ = lost_context_callback; } -void ContextProviderInProcess::SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& swap_buffers_complete_callback) { - DCHECK(context_thread_checker_.CalledOnValidThread()); - DCHECK(swap_buffers_complete_callback_.is_null() || - swap_buffers_complete_callback.is_null()); - swap_buffers_complete_callback_ = swap_buffers_complete_callback; -} - void ContextProviderInProcess::SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& memory_policy_changed_callback) { // There's no memory manager for the in-process implementation. diff --git a/webkit/common/gpu/context_provider_in_process.h b/webkit/common/gpu/context_provider_in_process.h index 91cdc58..72098b2 100644 --- a/webkit/common/gpu/context_provider_in_process.h +++ b/webkit/common/gpu/context_provider_in_process.h @@ -42,9 +42,6 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess virtual bool DestroyedOnMainThread() OVERRIDE; virtual void SetLostContextCallback( const LostContextCallback& lost_context_callback) OVERRIDE; - virtual void SetSwapBuffersCompleteCallback( - const SwapBuffersCompleteCallback& swap_buffers_complete_callback) - OVERRIDE; virtual void SetMemoryPolicyChangedCallback( const MemoryPolicyChangedCallback& memory_policy_changed_callback) OVERRIDE; @@ -56,7 +53,6 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess virtual ~ContextProviderInProcess(); void OnLostContext(); - void OnSwapBuffersComplete(); private: void InitializeCapabilities(); @@ -69,7 +65,6 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_; LostContextCallback lost_context_callback_; - SwapBuffersCompleteCallback swap_buffers_complete_callback_; base::Lock destroyed_lock_; bool destroyed_; @@ -78,10 +73,6 @@ class WEBKIT_GPU_EXPORT ContextProviderInProcess class LostContextCallbackProxy; scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_; - class SwapBuffersCompleteCallbackProxy; - scoped_ptr<SwapBuffersCompleteCallbackProxy> - swap_buffers_complete_callback_proxy_; - cc::ContextProvider::Capabilities capabilities_; DISALLOW_COPY_AND_ASSIGN(ContextProviderInProcess); diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc index f406af3..2eb2471 100644 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc +++ b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc @@ -334,15 +334,12 @@ void WebGraphicsContext3DInProcessCommandBufferImpl::name( \ } void WebGraphicsContext3DInProcessCommandBufferImpl::prepareTexture() { - if (!isContextLost()) { - gl_->SwapBuffers(); - gl_->ShallowFlushCHROMIUM(); - } + NOTREACHED(); } void WebGraphicsContext3DInProcessCommandBufferImpl::postSubBufferCHROMIUM( int x, int y, int width, int height) { - gl_->PostSubBufferCHROMIUM(x, y, width, height); + NOTREACHED(); } DELEGATE_TO_GL_3(reshapeWithScaleFactor, ResizeCHROMIUM, int, int, float) @@ -1057,9 +1054,6 @@ DELEGATE_TO_GL_1(deleteProgram, DeleteProgram, WebGLId); DELEGATE_TO_GL_1(deleteShader, DeleteShader, WebGLId); -void WebGraphicsContext3DInProcessCommandBufferImpl::OnSwapBuffersComplete() { -} - void WebGraphicsContext3DInProcessCommandBufferImpl::setContextLostCallback( WebGraphicsContext3D::WebGraphicsContextLostCallback* cb) { context_lost_callback_ = cb; diff --git a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h index 4525ebb..d92d34329 100644 --- a/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h +++ b/webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h @@ -568,9 +568,7 @@ class WEBKIT_GPU_EXPORT WebGraphicsContext3DInProcessCommandBufferImpl bool is_offscreen, gfx::AcceleratedWidget window); - // SwapBuffers callback. - void OnSwapBuffersComplete(); - virtual void OnContextLost(); + void OnContextLost(); bool MaybeInitializeGL(); |