diff options
author | sievers <sievers@chromium.org> | 2014-10-10 13:21:50 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-10 20:22:12 +0000 |
commit | 0668048aef27305171af88d6f870f0a041e2b2b7 (patch) | |
tree | 741605e2a505ec03699a48a123b4f7bb54695048 | |
parent | d19c6afcdf3d786de4e782a62e81fc75058f7b23 (diff) | |
download | chromium_src-0668048aef27305171af88d6f870f0a041e2b2b7.zip chromium_src-0668048aef27305171af88d6f870f0a041e2b2b7.tar.gz chromium_src-0668048aef27305171af88d6f870f0a041e2b2b7.tar.bz2 |
cc: Make OutputSurface::SwapBuffers pure virtual
The current implementation is not used in production code
and there is no reasonable common denominator anymore between
the different implementations.
Also removing the compositor example app (which was using
cc::OutputSurface) since James says it's not incredibly useful anymore.
Review URL: https://codereview.chromium.org/640023004
Cr-Commit-Position: refs/heads/master@{#299173}
27 files changed, 148 insertions, 393 deletions
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc index f0cbf5d..3502927 100644 --- a/cc/output/output_surface.cc +++ b/cc/output/output_surface.cc @@ -4,33 +4,16 @@ #include "cc/output/output_surface.h" -#include <algorithm> -#include <set> -#include <string> -#include <vector> - #include "base/bind.h" #include "base/debug/trace_event.h" -#include "base/logging.h" #include "base/message_loop/message_loop.h" -#include "base/metrics/histogram.h" -#include "base/strings/string_split.h" -#include "base/strings/string_util.h" -#include "cc/output/compositor_frame.h" -#include "cc/output/compositor_frame_ack.h" #include "cc/output/managed_memory_policy.h" #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 "gpu/command_buffer/client/gles2_interface.h" -#include "ui/gfx/frame_time.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" -using std::set; -using std::string; -using std::vector; namespace cc { @@ -222,35 +205,6 @@ void OutputSurface::BindFramebuffer() { context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); } -void OutputSurface::SwapBuffers(CompositorFrame* frame) { - // TODO(sievers): Make OutputSurface::SwapBuffers() pure virtual. - // The implementation here is used for tests only. - if (frame->software_frame_data) { - PostSwapBuffersComplete(); - client_->DidSwapBuffers(); - return; - } - - DCHECK(context_provider_.get()); - DCHECK(frame->gl_frame_data); - - if (frame->gl_frame_data->sub_buffer_rect == - gfx::Rect(frame->gl_frame_data->size)) { - context_provider_->ContextSupport()->Swap(); - } else { - context_provider_->ContextSupport()->PartialSwapBuffers( - frame->gl_frame_data->sub_buffer_rect); - } - uint32_t sync_point = - context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); - context_provider_->ContextSupport()->SignalSyncPoint( - sync_point, - base::Bind(&OutputSurface::OnSwapBuffersComplete, - weak_ptr_factory_.GetWeakPtr())); - - client_->DidSwapBuffers(); -} - void OutputSurface::PostSwapBuffersComplete() { base::MessageLoop::current()->PostTask( FROM_HERE, diff --git a/cc/output/output_surface.h b/cc/output/output_surface.h index c79f770..2cc43a3 100644 --- a/cc/output/output_surface.h +++ b/cc/output/output_surface.h @@ -12,7 +12,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "cc/base/cc_export.h" -#include "cc/base/rolling_time_delta_history.h" #include "cc/output/context_provider.h" #include "cc/output/overlay_candidate_validator.h" #include "cc/output/software_output_device.h" @@ -113,8 +112,10 @@ class CC_EXPORT OutputSurface { // The implementation may destroy or steal the contents of the CompositorFrame // passed in (though it will not take ownership of the CompositorFrame - // itself). - virtual void SwapBuffers(CompositorFrame* frame); + // itself). For successful swaps, the implementation must call + // OutputSurfaceClient::DidSwapBuffers() and eventually + // DidSwapBuffersComplete(). + virtual void SwapBuffers(CompositorFrame* frame) = 0; virtual void OnSwapBuffersComplete(); // Notifies frame-rate smoothness preference. If true, all non-critical diff --git a/cc/output/output_surface_unittest.cc b/cc/output/output_surface_unittest.cc index aca1d27..b70e344 100644 --- a/cc/output/output_surface_unittest.cc +++ b/cc/output/output_surface_unittest.cc @@ -32,6 +32,11 @@ class TestOutputSurface : public OutputSurface { scoped_ptr<SoftwareOutputDevice> software_device) : OutputSurface(context_provider, software_device.Pass()) {} + virtual void SwapBuffers(CompositorFrame* frame) override { + client_->DidSwapBuffers(); + client_->DidSwapBuffersComplete(); + } + bool InitializeNewContext3d( scoped_refptr<ContextProvider> new_context_provider) { return InitializeAndSetContext3d(new_context_provider); diff --git a/cc/output/overlay_unittest.cc b/cc/output/overlay_unittest.cc index 698b42b..9e837d5 100644 --- a/cc/output/overlay_unittest.cc +++ b/cc/output/overlay_unittest.cc @@ -102,11 +102,19 @@ class OverlayOutputSurface : public OutputSurface { explicit OverlayOutputSurface(scoped_refptr<ContextProvider> context_provider) : OutputSurface(context_provider) {} + // OutputSurface implementation + virtual void SwapBuffers(CompositorFrame* frame) override; + void InitWithSingleOverlayValidator() { overlay_candidate_validator_.reset(new SingleOverlayValidator); } }; +void OverlayOutputSurface::SwapBuffers(CompositorFrame* frame) { + client_->DidSwapBuffers(); + client_->DidSwapBuffersComplete(); +} + scoped_ptr<RenderPass> CreateRenderPass() { RenderPassId id(1, 0); gfx::Rect output_rect(0, 0, 256, 256); diff --git a/cc/output/renderer_unittest.cc b/cc/output/renderer_unittest.cc index 99ff89d..23719ed 100644 --- a/cc/output/renderer_unittest.cc +++ b/cc/output/renderer_unittest.cc @@ -15,6 +15,29 @@ namespace cc { namespace { +class TestOutputSurface : public OutputSurface { + public: + explicit TestOutputSurface( + const scoped_refptr<ContextProvider>& context_provider); + virtual ~TestOutputSurface() override; + + // OutputSurface implementation + virtual void SwapBuffers(CompositorFrame* frame) override; +}; + +TestOutputSurface::TestOutputSurface( + const scoped_refptr<ContextProvider>& context_provider) + : OutputSurface(context_provider) { +} + +TestOutputSurface::~TestOutputSurface() { +} + +void TestOutputSurface::SwapBuffers(CompositorFrame* frame) { + client_->DidSwapBuffers(); + client_->DidSwapBuffersComplete(); +} + class MockContextProvider : public TestContextProvider { public: explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context) @@ -57,7 +80,7 @@ class RendererTest : public ::testing::Test { virtual void SetUp() { context_provider_ = new MockContextProvider(TestWebGraphicsContext3D::Create()); - output_surface_.reset(new OutputSurface(context_provider_)); + output_surface_.reset(new TestOutputSurface(context_provider_)); output_surface_->BindToClient(&output_surface_client_); resource_provider_ = ResourceProvider::Create( output_surface_.get(), NULL, NULL, 0, false, 1, false); diff --git a/cc/test/fake_output_surface.cc b/cc/test/fake_output_surface.cc index 29680de..df9c0f7 100644 --- a/cc/test/fake_output_surface.cc +++ b/cc/test/fake_output_surface.cc @@ -73,13 +73,13 @@ void FakeOutputSurface::SwapBuffers(CompositorFrame* frame) { } ++num_sent_frames_; - PostSwapBuffersComplete(); - client_->DidSwapBuffers(); } else { - OutputSurface::SwapBuffers(frame); + last_swap_rect_ = frame->gl_frame_data->sub_buffer_rect; frame->AssignTo(&last_sent_frame_); ++num_sent_frames_; } + PostSwapBuffersComplete(); + client_->DidSwapBuffers(); } void FakeOutputSurface::SetNeedsBeginFrame(bool enable) { diff --git a/cc/test/fake_output_surface.h b/cc/test/fake_output_surface.h index 306879b..37c0c54 100644 --- a/cc/test/fake_output_surface.h +++ b/cc/test/fake_output_surface.h @@ -119,6 +119,10 @@ class FakeOutputSurface : public OutputSurface { void SetMemoryPolicyToSetAtBind( scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind); + gfx::Rect last_swap_rect() const { + return last_swap_rect_; + } + protected: FakeOutputSurface( scoped_refptr<ContextProvider> context_provider, @@ -142,6 +146,7 @@ class FakeOutputSurface : public OutputSurface { bool has_external_stencil_test_; TransferableResourceArray resources_held_by_parent_; scoped_ptr<ManagedMemoryPolicy> memory_policy_to_set_at_bind_; + gfx::Rect last_swap_rect_; base::WeakPtrFactory<FakeOutputSurface> fake_weak_ptr_factory_; }; diff --git a/cc/test/pixel_test_output_surface.cc b/cc/test/pixel_test_output_surface.cc index c773a52..640c118 100644 --- a/cc/test/pixel_test_output_surface.cc +++ b/cc/test/pixel_test_output_surface.cc @@ -28,4 +28,9 @@ bool PixelTestOutputSurface::HasExternalStencilTest() const { return external_stencil_test_; } +void PixelTestOutputSurface::SwapBuffers(CompositorFrame* frame) { + PostSwapBuffersComplete(); + client_->DidSwapBuffers(); +} + } // namespace cc diff --git a/cc/test/pixel_test_output_surface.h b/cc/test/pixel_test_output_surface.h index ce9d79c..eaa2675 100644 --- a/cc/test/pixel_test_output_surface.h +++ b/cc/test/pixel_test_output_surface.h @@ -18,6 +18,7 @@ class PixelTestOutputSurface : public OutputSurface { virtual void Reshape(const gfx::Size& size, float scale_factor) override; virtual bool HasExternalStencilTest() const override; + virtual void SwapBuffers(CompositorFrame* frame) override; void set_surface_expansion_size(const gfx::Size& surface_expansion_size) { surface_expansion_size_ = surface_expansion_size; diff --git a/cc/test/test_context_support.cc b/cc/test/test_context_support.cc index 88127d5..f74f692 100644 --- a/cc/test/test_context_support.cc +++ b/cc/test/test_context_support.cc @@ -10,8 +10,7 @@ namespace cc { TestContextSupport::TestContextSupport() - : last_swap_type_(NO_SWAP), - weak_ptr_factory_(this) { + : weak_ptr_factory_(this) { } TestContextSupport::~TestContextSupport() {} @@ -59,7 +58,6 @@ void TestContextSupport::SetScheduleOverlayPlaneCallback( } void TestContextSupport::Swap() { - last_swap_type_ = SWAP; } uint32 TestContextSupport::InsertFutureSyncPointCHROMIUM() { @@ -72,8 +70,6 @@ void TestContextSupport::RetireSyncPointCHROMIUM(uint32 sync_point) { } void TestContextSupport::PartialSwapBuffers(const gfx::Rect& sub_buffer) { - last_swap_type_ = PARTIAL_SWAP; - last_partial_swap_rect_ = sub_buffer; } void TestContextSupport::ScheduleOverlayPlane( diff --git a/cc/test/test_context_support.h b/cc/test/test_context_support.h index c9b0d14..ceadd93 100644 --- a/cc/test/test_context_support.h +++ b/cc/test/test_context_support.h @@ -48,25 +48,11 @@ class TestContextSupport : public gpu::ContextSupport { void SetScheduleOverlayPlaneCallback( const ScheduleOverlayPlaneCallback& schedule_overlay_plane_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: std::vector<base::Closure> sync_point_callbacks_; SurfaceVisibleCallback set_visible_callback_; ScheduleOverlayPlaneCallback schedule_overlay_plane_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/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index a3a578f..9085594 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -4399,8 +4399,9 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { context_provider->BindToCurrentThread(); context_provider->TestContext3d()->set_have_post_sub_buffer(true); - scoped_ptr<OutputSurface> output_surface( + scoped_ptr<FakeOutputSurface> output_surface( FakeOutputSurface::Create3d(context_provider)); + FakeOutputSurface* fake_output_surface = output_surface.get(); // This test creates its own LayerTreeHostImpl, so // that we can force partial swap enabled. @@ -4439,8 +4440,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); - EXPECT_EQ(TestContextSupport::SWAP, - context_provider->support()->last_swap_type()); + gfx::Rect expected_swap_rect(0, 0, 500, 500); + EXPECT_EQ(expected_swap_rect.ToString(), + fake_output_surface->last_swap_rect().ToString()); // Second frame, only the damaged area should get swapped. Damage should be // the union of old and new child rects. @@ -4456,12 +4458,9 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { // 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); + expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); EXPECT_EQ(expected_swap_rect.ToString(), - context_provider->support()-> - last_partial_swap_rect().ToString()); + fake_output_surface->last_swap_rect().ToString()); layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); // This will damage everything. @@ -4472,8 +4471,9 @@ TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { host_impl_->DidDrawAllLayers(frame); layer_tree_host_impl->SwapBuffers(frame); - EXPECT_EQ(TestContextSupport::SWAP, - context_provider->support()->last_swap_type()); + expected_swap_rect = gfx::Rect(0, 0, 10, 10); + EXPECT_EQ(expected_swap_rect.ToString(), + fake_output_surface->last_swap_rect().ToString()); } TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { diff --git a/content/test/web_layer_tree_view_impl_for_testing.cc b/content/test/web_layer_tree_view_impl_for_testing.cc index 5714a2f..24c1ed6 100644 --- a/content/test/web_layer_tree_view_impl_for_testing.cc +++ b/content/test/web_layer_tree_view_impl_for_testing.cc @@ -11,7 +11,7 @@ #include "cc/blink/web_layer_impl.h" #include "cc/input/input_handler.h" #include "cc/layers/layer.h" -#include "cc/output/output_surface.h" +#include "cc/test/pixel_test_output_surface.h" #include "cc/test/test_context_provider.h" #include "cc/trees/layer_tree_host.h" #include "content/test/test_blink_web_unit_test_support.h" @@ -151,7 +151,7 @@ void WebLayerTreeViewImplForTesting::ApplyViewportDeltas( void WebLayerTreeViewImplForTesting::RequestNewOutputSurface( bool fallback) { layer_tree_host_->SetOutputSurface(make_scoped_ptr( - new cc::OutputSurface(cc::TestContextProvider::Create()))); + new cc::PixelTestOutputSurface(cc::TestContextProvider::Create()))); } void WebLayerTreeViewImplForTesting::registerViewportLayers( diff --git a/mojo/cc/BUILD.gn b/mojo/cc/BUILD.gn index 4f67ec6..1a78c01 100644 --- a/mojo/cc/BUILD.gn +++ b/mojo/cc/BUILD.gn @@ -18,6 +18,8 @@ source_set("cc") { sources = [ "context_provider_mojo.cc", "context_provider_mojo.h", + "direct_output_surface.cc", + "direct_output_surface.h", "output_surface_mojo.cc", "output_surface_mojo.h", ] diff --git a/mojo/cc/DEPS b/mojo/cc/DEPS index f789994..9390f5e 100644 --- a/mojo/cc/DEPS +++ b/mojo/cc/DEPS @@ -1,4 +1,5 @@ include_rules = [ "+cc", "-cc/blink", + "+gpu/command_buffer/client", ] diff --git a/mojo/cc/direct_output_surface.cc b/mojo/cc/direct_output_surface.cc new file mode 100644 index 0000000..0899c4e --- /dev/null +++ b/mojo/cc/direct_output_surface.cc @@ -0,0 +1,42 @@ +// Copyright 2014 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 "mojo/cc/direct_output_surface.h" + +#include "base/bind.h" +#include "cc/output/compositor_frame.h" +#include "cc/output/context_provider.h" +#include "cc/output/output_surface_client.h" +#include "gpu/command_buffer/client/context_support.h" +#include "gpu/command_buffer/client/gles2_interface.h" + +namespace mojo { + +DirectOutputSurface::DirectOutputSurface( + const scoped_refptr<cc::ContextProvider>& context_provider) + : cc::OutputSurface(context_provider), weak_ptr_factory_(this) { +} + +DirectOutputSurface::~DirectOutputSurface() {} + +void DirectOutputSurface::SwapBuffers(cc::CompositorFrame* frame) { + DCHECK(context_provider_.get()); + DCHECK(frame->gl_frame_data); + if (frame->gl_frame_data->sub_buffer_rect == + gfx::Rect(frame->gl_frame_data->size)) { + context_provider_->ContextSupport()->Swap(); + } else { + context_provider_->ContextSupport()->PartialSwapBuffers( + frame->gl_frame_data->sub_buffer_rect); + } + uint32_t sync_point = + context_provider_->ContextGL()->InsertSyncPointCHROMIUM(); + context_provider_->ContextSupport()->SignalSyncPoint( + sync_point, + base::Bind(&OutputSurface::OnSwapBuffersComplete, + weak_ptr_factory_.GetWeakPtr())); + client_->DidSwapBuffers(); +} + +} // namespace mojo diff --git a/mojo/cc/direct_output_surface.h b/mojo/cc/direct_output_surface.h new file mode 100644 index 0000000..50e6c40 --- /dev/null +++ b/mojo/cc/direct_output_surface.h @@ -0,0 +1,29 @@ +// Copyright 2014 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 MOJO_CC_DIRECT_OUTPUT_SURFACE_H_ +#define MOJO_CC_DIRECT_OUTPUT_SURFACE_H_ + +#include "cc/output/output_surface.h" + +namespace mojo { + +// An OutputSurface implementation that directly draws and +// swaps to an actual GL surface. +class DirectOutputSurface : public cc::OutputSurface { + public: + explicit DirectOutputSurface( + const scoped_refptr<cc::ContextProvider>& context_provider); + virtual ~DirectOutputSurface() override; + + // cc::OutputSurface implementation + virtual void SwapBuffers(cc::CompositorFrame* frame) override; + +private: + base::WeakPtrFactory<DirectOutputSurface> weak_ptr_factory_; +}; + +} // namespace mojo + +#endif // MOJO_CC_DIRECT_OUTPUT_SURFACE_H_ diff --git a/mojo/examples/BUILD.gn b/mojo/examples/BUILD.gn index 5aa136d..bdd09f7 100644 --- a/mojo/examples/BUILD.gn +++ b/mojo/examples/BUILD.gn @@ -9,7 +9,6 @@ group("examples") { deps = [ "//mojo/examples/apptest", - "//mojo/examples/compositor_app", "//mojo/examples/content_handler_demo", "//mojo/examples/echo", "//mojo/examples/http_server", diff --git a/mojo/examples/compositor_app/BUILD.gn b/mojo/examples/compositor_app/BUILD.gn deleted file mode 100644 index ff8b4ae..0000000 --- a/mojo/examples/compositor_app/BUILD.gn +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2014 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. - -# GYP version mojo/mojo_examples.gypi:mojo_compositor_app -shared_library("compositor_app") { - output_name = "mojo_compositor_app" - - sources = [ - "compositor_app.cc", - "compositor_host.cc", - "compositor_host.h", - ] - - deps = [ - "//base", - "//cc", - "//mojo/application", - "//mojo/cc", - "//mojo/common", - "//mojo/converters/geometry", - "//mojo/public/c/system:for_shared_library", - "//mojo/public/gles2:for_shared_library", - "//mojo/services/public/interfaces/geometry", - "//mojo/services/public/interfaces/gpu", - "//mojo/services/public/interfaces/native_viewport", - ] -} diff --git a/mojo/examples/compositor_app/DEPS b/mojo/examples/compositor_app/DEPS deleted file mode 100644 index 70688d6..0000000 --- a/mojo/examples/compositor_app/DEPS +++ /dev/null @@ -1,6 +0,0 @@ -include_rules = [ - "+cc", - "-cc/blink", - "+ui/gfx", - "+gpu/command_buffer/client", -] diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc deleted file mode 100644 index 3a29ed21..0000000 --- a/mojo/examples/compositor_app/compositor_app.cc +++ /dev/null @@ -1,78 +0,0 @@ -// 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 <stdio.h> -#include <string> - -#include "base/bind.h" -#include "base/macros.h" -#include "base/memory/weak_ptr.h" -#include "mojo/application/application_runner_chromium.h" -#include "mojo/converters/geometry/geometry_type_converters.h" -#include "mojo/examples/compositor_app/compositor_host.h" -#include "mojo/public/c/system/main.h" -#include "mojo/public/cpp/application/application_delegate.h" -#include "mojo/public/cpp/application/application_impl.h" -#include "mojo/public/cpp/system/core.h" -#include "mojo/services/public/interfaces/gpu/gpu.mojom.h" -#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" -#include "ui/gfx/rect.h" - -namespace mojo { -namespace examples { - -class SampleApp : public ApplicationDelegate, public NativeViewportClient { - public: - SampleApp() : weak_factory_(this) {} - virtual ~SampleApp() {} - - virtual void Initialize(ApplicationImpl* app) override { - app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); - viewport_.set_client(this); - viewport_->Create(Size::From(gfx::Size(800, 600)), - base::Bind(&SampleApp::OnCreatedNativeViewport, - weak_factory_.GetWeakPtr())); - viewport_->Show(); - - // TODO(jamesr): Should be mojo:mojo_gpu_service - app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); - } - - virtual void OnDestroyed() override { base::MessageLoop::current()->Quit(); } - - virtual void OnSizeChanged(SizePtr size) override { - if (host_) - host_->SetSize(size.To<gfx::Size>()); - } - - virtual void OnEvent(EventPtr event, - const mojo::Callback<void()>& callback) override { - callback.Run(); - } - - private: - void OnCreatedNativeViewport(uint64_t native_viewport_id) { - CommandBufferPtr cb; - // TODO(jamesr): Output to a surface instead. - gpu_service_->CreateOnscreenGLES2Context( - native_viewport_id, Size::From(gfx::Size(800, 600)), GetProxy(&cb)); - host_.reset(new CompositorHost(cb.PassMessagePipe())); - } - - - NativeViewportPtr viewport_; - GpuPtr gpu_service_; - scoped_ptr<CompositorHost> host_; - base::WeakPtrFactory<SampleApp> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(SampleApp); -}; - -} // namespace examples -} // namespace mojo - -MojoResult MojoMain(MojoHandle shell_handle) { - mojo::ApplicationRunnerChromium runner(new mojo::examples::SampleApp); - return runner.Run(shell_handle); -} diff --git a/mojo/examples/compositor_app/compositor_host.cc b/mojo/examples/compositor_app/compositor_host.cc deleted file mode 100644 index 0cd6fb9..0000000 --- a/mojo/examples/compositor_app/compositor_host.cc +++ /dev/null @@ -1,97 +0,0 @@ -// 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 "mojo/examples/compositor_app/compositor_host.h" - -#include "cc/layers/layer.h" -#include "cc/layers/solid_color_layer.h" -#include "cc/output/begin_frame_args.h" -#include "cc/output/context_provider.h" -#include "cc/output/output_surface.h" -#include "cc/trees/layer_tree_host.h" -#include "mojo/cc/context_provider_mojo.h" - -namespace mojo { -namespace examples { - -CompositorHost::CompositorHost(ScopedMessagePipeHandle command_buffer_handle) - : command_buffer_handle_(command_buffer_handle.Pass()), - compositor_thread_("compositor") { - DCHECK(command_buffer_handle_.is_valid()); - bool started = compositor_thread_.Start(); - DCHECK(started); - - cc::LayerTreeSettings settings; - tree_ = cc::LayerTreeHost::CreateThreaded( - this, - NULL, - settings, - base::MessageLoopProxy::current(), - compositor_thread_.message_loop_proxy()); - SetupScene(); -} - -CompositorHost::~CompositorHost() {} - -void CompositorHost::SetSize(const gfx::Size& viewport_size) { - tree_->SetViewportSize(viewport_size); - tree_->SetLayerTreeHostClientReady(); -} - -void CompositorHost::SetupScene() { - scoped_refptr<cc::Layer> root_layer = cc::SolidColorLayer::Create(); - root_layer->SetBounds(gfx::Size(500, 500)); - root_layer->SetBackgroundColor(SK_ColorBLUE); - root_layer->SetIsDrawable(true); - tree_->SetRootLayer(root_layer); - - child_layer_ = cc::SolidColorLayer::Create(); - child_layer_->SetBounds(gfx::Size(100, 100)); - child_layer_->SetBackgroundColor(SK_ColorGREEN); - child_layer_->SetIsDrawable(true); - gfx::Transform child_transform; - child_transform.Translate(200, 200); - child_layer_->SetTransform(child_transform); - root_layer->AddChild(child_layer_); -} - -void CompositorHost::WillBeginMainFrame(int frame_id) {} -void CompositorHost::DidBeginMainFrame() {} - -void CompositorHost::BeginMainFrame(const cc::BeginFrameArgs& args) { - // TODO(jamesr): Should use cc's animation system. - static const double kDegreesPerSecond = 70.0; - double time_in_seconds = (args.frame_time - base::TimeTicks()).InSecondsF(); - double child_rotation_degrees = kDegreesPerSecond * time_in_seconds; - gfx::Transform child_transform; - child_transform.Translate(200, 200); - child_transform.Rotate(child_rotation_degrees); - child_layer_->SetTransform(child_transform); - tree_->SetNeedsAnimate(); -} - -void CompositorHost::Layout() {} -void CompositorHost::ApplyViewportDeltas(const gfx::Vector2d& inner_delta, - const gfx::Vector2d& outer_delta, - float page_scale, - float top_controls_delta) {} -void CompositorHost::ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, - float page_scale, - float top_controls_delta) {} - -void CompositorHost::RequestNewOutputSurface(bool fallback) { - tree_->SetOutputSurface(make_scoped_ptr(new cc::OutputSurface( - new ContextProviderMojo(command_buffer_handle_.Pass())))); -} - -void CompositorHost::DidInitializeOutputSurface() { -} - -void CompositorHost::WillCommit() {} -void CompositorHost::DidCommit() {} -void CompositorHost::DidCommitAndDrawFrame() {} -void CompositorHost::DidCompleteSwapBuffers() {} - -} // namespace examples -} // namespace mojo diff --git a/mojo/examples/compositor_app/compositor_host.h b/mojo/examples/compositor_app/compositor_host.h deleted file mode 100644 index 3725212..0000000 --- a/mojo/examples/compositor_app/compositor_host.h +++ /dev/null @@ -1,61 +0,0 @@ -// 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 MOJO_EXAMPLES_COMPOSITOR_APP_COMPOSITOR_HOST_H_ -#define MOJO_EXAMPLES_COMPOSITOR_APP_COMPOSITOR_HOST_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/threading/thread.h" -#include "cc/trees/layer_tree_host_client.h" -#include "mojo/public/cpp/system/core.h" -#include "ui/gfx/size.h" - -namespace cc { -class Layer; -class LayerTreeHost; -} // namespace cc - -namespace mojo { -namespace examples { -class GLES2ClientImpl; - -class CompositorHost : public cc::LayerTreeHostClient { - public: - explicit CompositorHost(ScopedMessagePipeHandle command_buffer_handle); - virtual ~CompositorHost(); - - void SetSize(const gfx::Size& viewport_size); - - // cc::LayerTreeHostClient implementation. - virtual void WillBeginMainFrame(int frame_id) override; - virtual void DidBeginMainFrame() override; - virtual void BeginMainFrame(const cc::BeginFrameArgs& args) override; - virtual void Layout() override; - virtual void ApplyViewportDeltas(const gfx::Vector2d& inner_delta, - const gfx::Vector2d& outer_delta, - float page_scale, - float top_controls_delta) override; - virtual void ApplyViewportDeltas(const gfx::Vector2d& scroll_delta, - float page_scale, - float top_controls_delta) override; - virtual void RequestNewOutputSurface(bool fallback) override; - virtual void DidInitializeOutputSurface() override; - virtual void WillCommit() override; - virtual void DidCommit() override; - virtual void DidCommitAndDrawFrame() override; - virtual void DidCompleteSwapBuffers() override; - - private: - void SetupScene(); - - ScopedMessagePipeHandle command_buffer_handle_; - scoped_ptr<cc::LayerTreeHost> tree_; - scoped_refptr<cc::Layer> child_layer_; - base::Thread compositor_thread_; -}; - -} // namespace examples -} // namespace mojo - -#endif // MOJO_EXAMPLES_COMPOSITOR_APP_COMPOSITOR_HOST_H_ diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index 66694e1..2ffb1e5 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -33,7 +33,6 @@ 'mojo_base.gyp:mojo_base', 'mojo_clipboard', 'mojo_clipboard_unittests', - 'mojo_compositor_app', 'mojo_content_handler_demo', 'mojo_echo_client', 'mojo_echo_service', @@ -374,6 +373,8 @@ 'sources': [ 'cc/context_provider_mojo.cc', 'cc/context_provider_mojo.h', + 'cc/direct_output_surface.cc', + 'cc/direct_output_surface.h', 'cc/output_surface_mojo.cc', 'cc/output_surface_mojo.h', ], diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi index 3cadf02..087f5cc 100644 --- a/mojo/mojo_examples.gypi +++ b/mojo/mojo_examples.gypi @@ -156,40 +156,6 @@ 'includes': [ 'build/package_app.gypi' ], }, { - # GN version: //mojo/examples/compositor_app - 'target_name': 'mojo_compositor_app', - 'type': 'loadable_module', - 'dependencies': [ - '../base/base.gyp:base', - '../cc/cc.gyp:cc', - '../ui/gfx/gfx.gyp:gfx', - '../ui/gfx/gfx.gyp:gfx_geometry', - 'mojo_base.gyp:mojo_application_chromium', - 'mojo_base.gyp:mojo_common_lib', - 'mojo_cc_support', - 'mojo_geometry_lib', - 'services/public/mojo_services_public.gyp:mojo_geometry_bindings', - 'services/public/mojo_services_public.gyp:mojo_gpu_bindings', - 'services/public/mojo_services_public.gyp:mojo_native_viewport_bindings', - '<(mojo_system_for_loadable_module)', - ], - 'includes': [ - 'mojo_public_gles2_for_loadable_module.gypi', - ], - 'sources': [ - 'examples/compositor_app/compositor_app.cc', - 'examples/compositor_app/compositor_host.cc', - 'examples/compositor_app/compositor_host.h', - ], - }, - { - 'target_name': 'package_mojo_compositor_app', - 'variables': { - 'app_name': 'mojo_compositor_app', - }, - 'includes': [ 'build/package_app.gypi' ], - }, - { # GN version: //mojo/examples/http_server 'target_name': 'mojo_http_server', 'type': 'loadable_module', diff --git a/mojo/services/surfaces/surfaces_impl.cc b/mojo/services/surfaces/surfaces_impl.cc index a73aaa6..1e6e070 100644 --- a/mojo/services/surfaces/surfaces_impl.cc +++ b/mojo/services/surfaces/surfaces_impl.cc @@ -9,6 +9,7 @@ #include "cc/surfaces/display.h" #include "cc/surfaces/surface_id_allocator.h" #include "mojo/cc/context_provider_mojo.h" +#include "mojo/cc/direct_output_surface.h" #include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/converters/surfaces/surfaces_type_converters.h" @@ -77,7 +78,7 @@ void SurfacesImpl::CreateGLES2BoundSurface(CommandBufferPtr gles2_client, if (!display_) { display_.reset(new cc::Display(this, manager_, NULL)); client_->SetDisplay(display_.get()); - display_->Initialize(make_scoped_ptr(new cc::OutputSurface( + display_->Initialize(make_scoped_ptr(new DirectOutputSurface( new ContextProviderMojo(command_buffer_handle_.Pass())))); } factory_.Create(cc_id, size.To<gfx::Size>()); diff --git a/ui/compositor/test/in_process_context_factory.cc b/ui/compositor/test/in_process_context_factory.cc index d815a5c..d87d75b 100644 --- a/ui/compositor/test/in_process_context_factory.cc +++ b/ui/compositor/test/in_process_context_factory.cc @@ -6,8 +6,8 @@ #include "base/command_line.h" #include "base/threading/thread.h" -#include "cc/output/output_surface.h" #include "cc/surfaces/surface_id_allocator.h" +#include "cc/test/pixel_test_output_surface.h" #include "cc/test/test_shared_bitmap_manager.h" #include "ui/compositor/compositor_switches.h" #include "ui/compositor/reflector.h" @@ -61,7 +61,7 @@ scoped_ptr<cc::OutputSurface> InProcessContextFactory::CreateOutputSurface( scoped_refptr<ContextProviderInProcess> context_provider = ContextProviderInProcess::Create(context3d.Pass(), "UICompositor"); - return make_scoped_ptr(new cc::OutputSurface(context_provider)); + return make_scoped_ptr(new cc::PixelTestOutputSurface(context_provider)); } scoped_refptr<Reflector> InProcessContextFactory::CreateReflector( |