Skip to content

Commit

Permalink
Have a common implementation of cc::OutputSurface instead of multiple…
Browse files Browse the repository at this point in the history
… duplicated ones.

Review URL: https://codereview.chromium.org/12041062

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182345 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skaslev@chromium.org committed Feb 13, 2013
1 parent 490ccaf commit 79a1be5
Show file tree
Hide file tree
Showing 31 changed files with 199 additions and 470 deletions.
2 changes: 2 additions & 0 deletions cc/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ include_rules = [
"+ui/gl",
# TODO(danakj): Drop dependencies on WebKit Platform API from cc.
"+third_party/WebKit/Source/Platform/chromium/public",
# TODO(jamesr): Remove once cc depends on GLES2Interface instead of WGC3D
"+webkit/gpu",
]
1 change: 1 addition & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
'nine_patch_layer_impl.h',
'occlusion_tracker.cc',
'occlusion_tracker.h',
'output_surface.cc',
'output_surface.h',
'output_surface_client.h',
'overdraw_metrics.cc',
Expand Down
2 changes: 0 additions & 2 deletions cc/cc_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@
'test/occlusion_tracker_test_common.h',
'test/paths.cc',
'test/paths.h',
'test/pixel_test_output_surface.cc',
'test/pixel_test_output_surface.h',
'test/render_pass_test_common.cc',
'test/render_pass_test_common.h',
'test/render_pass_test_utils.cc',
Expand Down
2 changes: 1 addition & 1 deletion cc/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ GLRenderer::GLRenderer(RendererClient* client, OutputSurface* outputSurface, Res
, m_offscreenFramebufferId(0)
, m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f))
, m_outputSurface(outputSurface)
, m_context(outputSurface->Context3D())
, m_context(outputSurface->context3d())
, m_isViewportChanged(false)
, m_isBackbufferDiscarded(false)
, m_discardBackbufferWhenNotVisible(false)
Expand Down
8 changes: 6 additions & 2 deletions cc/gl_renderer_pixeltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#include "cc/prioritized_resource_manager.h"
#include "cc/resource_provider.h"
#include "cc/test/paths.h"
#include "cc/test/pixel_test_output_surface.h"
#include "cc/test/pixel_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gl/gl_implementation.h"
#include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"

namespace cc {
namespace {
Expand Down Expand Up @@ -53,7 +53,11 @@ class GLRendererPixelTest : public testing::Test {

virtual void SetUp() {
gfx::InitializeGLBindings(gfx::kGLImplementationOSMesaGL);
output_surface_ = PixelTestOutputSurface::create();
scoped_ptr<webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl> context3d(
new webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl);
context3d->Initialize(WebKit::WebGraphicsContext3D::Attributes(), NULL);
output_surface_.reset(new OutputSurface(
context3d.PassAs<WebKit::WebGraphicsContext3D>()));
resource_provider_ = ResourceProvider::create(output_surface_.get());
renderer_ = GLRenderer::create(&fake_client_,
output_surface_.get(),
Expand Down
12 changes: 6 additions & 6 deletions cc/gl_renderer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class GLRendererTest : public testing::Test {
m_renderer.swapBuffers();
}

FrameCountingMemoryAllocationSettingContext* context() { return static_cast<FrameCountingMemoryAllocationSettingContext*>(m_outputSurface->Context3D()); }
FrameCountingMemoryAllocationSettingContext* context() { return static_cast<FrameCountingMemoryAllocationSettingContext*>(m_outputSurface->context3d()); }

WebGraphicsMemoryAllocation m_suggestHaveBackbufferYes;
WebGraphicsMemoryAllocation m_suggestHaveBackbufferNo;
Expand Down Expand Up @@ -401,7 +401,7 @@ TEST(GLRendererTest2, opaqueBackground)
{
FakeRendererClient mockClient;
scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSurface->Context3D());
ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.get());

Expand All @@ -424,7 +424,7 @@ TEST(GLRendererTest2, transparentBackground)
{
FakeRendererClient mockClient;
scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSurface->Context3D());
ClearCountingContext* context = static_cast<ClearCountingContext*>(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.get());

Expand Down Expand Up @@ -475,7 +475,7 @@ TEST(GLRendererTest2, visibilityChangeIsLastCall)
{
FakeRendererClient mockClient;
scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new VisibilityChangeIsLastCallTrackingContext)));
VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityChangeIsLastCallTrackingContext*>(outputSurface->Context3D());
VisibilityChangeIsLastCallTrackingContext* context = static_cast<VisibilityChangeIsLastCallTrackingContext*>(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.get());

Expand Down Expand Up @@ -527,7 +527,7 @@ TEST(GLRendererTest2, activeTextureState)
{
FakeRendererClient fakeClient;
scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new TextureStateTrackingContext)));
TextureStateTrackingContext* context = static_cast<TextureStateTrackingContext*>(outputSurface->Context3D());
TextureStateTrackingContext* context = static_cast<TextureStateTrackingContext*>(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
FakeRendererGL renderer(&fakeClient, outputSurface.get(), resourceProvider.get());

Expand Down Expand Up @@ -594,7 +594,7 @@ TEST(GLRendererTest2, shouldClearRootRenderPass)
{
NoClearRootRenderPassFakeClient mockClient;
scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new NoClearRootRenderPassMockContext)));
NoClearRootRenderPassMockContext* mockContext = static_cast<NoClearRootRenderPassMockContext*>(outputSurface->Context3D());
NoClearRootRenderPassMockContext* mockContext = static_cast<NoClearRootRenderPassMockContext*>(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));
FakeRendererGL renderer(&mockClient, outputSurface.get(), resourceProvider.get());
EXPECT_TRUE(renderer.initialize());
Expand Down
2 changes: 1 addition & 1 deletion cc/io_surface_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ IOSurfaceLayerImpl::~IOSurfaceLayerImpl()

OutputSurface* outputSurface = layerTreeImpl()->output_surface();
// FIXME: Implement this path for software compositing.
WebKit::WebGraphicsContext3D* context3d = outputSurface->Context3D();
WebKit::WebGraphicsContext3D* context3d = outputSurface->context3d();
if (context3d)
context3d->deleteTexture(m_ioSurfaceTextureId);
}
Expand Down
8 changes: 4 additions & 4 deletions cc/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,12 @@ bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
m_tileManager->SetRecordRenderingStats(m_debugState.recordRenderingStats());
}

if (outputSurface->Capabilities().has_parent_compositor)
if (outputSurface->capabilities().has_parent_compositor)
m_renderer = DelegatingRenderer::Create(this, outputSurface.get(), resourceProvider.get());
else if (outputSurface->Context3D())
else if (outputSurface->context3d())
m_renderer = GLRenderer::create(this, outputSurface.get(), resourceProvider.get());
else if (outputSurface->SoftwareDevice())
m_renderer = SoftwareRenderer::create(this, resourceProvider.get(), outputSurface->SoftwareDevice());
else if (outputSurface->software_device())
m_renderer = SoftwareRenderer::create(this, resourceProvider.get(), outputSurface->software_device());
if (!m_renderer)
return false;

Expand Down
12 changes: 6 additions & 6 deletions cc/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,7 @@ class FakeDrawableLayerImpl: public LayerImpl {
TEST_P(LayerTreeHostImplTest, reshapeNotCalledUntilDraw)
{
scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new ReshapeTrackerContext)).PassAs<OutputSurface>();
ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(outputSurface->Context3D());
ReshapeTrackerContext* reshapeTracker = static_cast<ReshapeTrackerContext*>(outputSurface->context3d());
m_hostImpl->initializeRenderer(outputSurface.Pass());

scoped_ptr<LayerImpl> root = FakeDrawableLayerImpl::create(m_hostImpl->activeTree(), 1);
Expand Down Expand Up @@ -2150,7 +2150,7 @@ class PartialSwapTrackerContext : public TestWebGraphicsContext3D {
TEST_P(LayerTreeHostImplTest, partialSwapReceivesDamageRect)
{
scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapTrackerContext)).PassAs<OutputSurface>();
PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrackerContext*>(outputSurface->Context3D());
PartialSwapTrackerContext* partialSwapTracker = static_cast<PartialSwapTrackerContext*>(outputSurface->context3d());

// This test creates its own LayerTreeHostImpl, so
// that we can force partial swap enabled.
Expand Down Expand Up @@ -2360,7 +2360,7 @@ class MockContextHarness {
TEST_P(LayerTreeHostImplTest, noPartialSwap)
{
scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>();
MockContext* mockContext = static_cast<MockContext*>(outputSurface->Context3D());
MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3d());
MockContextHarness harness(mockContext);

// Run test case
Expand Down Expand Up @@ -2394,7 +2394,7 @@ TEST_P(LayerTreeHostImplTest, noPartialSwap)
TEST_P(LayerTreeHostImplTest, partialSwap)
{
scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockContext)).PassAs<OutputSurface>();
MockContext* mockContext = static_cast<MockContext*>(outputSurface->Context3D());
MockContext* mockContext = static_cast<MockContext*>(outputSurface->context3d());
MockContextHarness harness(mockContext);

createLayerTreeHost(true, outputSurface.Pass());
Expand Down Expand Up @@ -2670,7 +2670,7 @@ class MockDrawQuadsToFillScreenContext : public TestWebGraphicsContext3D {
TEST_P(LayerTreeHostImplTest, hasTransparentBackground)
{
scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(new MockDrawQuadsToFillScreenContext)).PassAs<OutputSurface>();
MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToFillScreenContext*>(outputSurface->Context3D());
MockDrawQuadsToFillScreenContext* mockContext = static_cast<MockDrawQuadsToFillScreenContext*>(outputSurface->context3d());

// Run test case
createLayerTreeHost(false, outputSurface.Pass());
Expand Down Expand Up @@ -4031,7 +4031,7 @@ static void verifyRenderPassTestData(TestCase& testCase, RenderPassRemovalTestDa
TEST_P(LayerTreeHostImplTest, testRemoveRenderPasses)
{
scoped_ptr<OutputSurface> outputSurface(createOutputSurface());
ASSERT_TRUE(outputSurface->Context3D());
ASSERT_TRUE(outputSurface->context3d());
scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get()));

scoped_ptr<TestRenderer> renderer(TestRenderer::create(resourceProvider.get(), outputSurface.get(), &m_proxy));
Expand Down
8 changes: 4 additions & 4 deletions cc/layer_tree_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest {
{
ASSERT_EQ(0u, m_layerTreeHost->settings().maxPartialTextureUpdates);

TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D());
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->context3d());

switch (impl->activeTree()->source_frame_number()) {
case 0:
Expand Down Expand Up @@ -1082,7 +1082,7 @@ class LayerTreeHostTestAtomicCommit : public LayerTreeHostTest {

virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE
{
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D());
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->context3d());

// Number of textures used for draw should always be one for each layer.
EXPECT_EQ(2, context->NumUsedTextures());
Expand Down Expand Up @@ -1172,7 +1172,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate : public LayerTreeHostTest
{
ASSERT_EQ(1u, m_layerTreeHost->settings().maxPartialTextureUpdates);

TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D());
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->context3d());

switch (impl->activeTree()->source_frame_number()) {
case 0:
Expand Down Expand Up @@ -1257,7 +1257,7 @@ class LayerTreeHostTestAtomicCommitWithPartialUpdate : public LayerTreeHostTest

virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE
{
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->Context3D());
TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>(impl->outputSurface()->context3d());

// Number of textures used for drawing should one per layer except for
// frame 3 where the viewport only contains one layer.
Expand Down
47 changes: 47 additions & 0 deletions cc/output_surface.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/output_surface.h"

#include "base/logging.h"

namespace cc {

OutputSurface::OutputSurface(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d)
: client_(NULL),
context3d_(context3d.Pass()) {
}

OutputSurface::OutputSurface(
scoped_ptr<cc::SoftwareOutputDevice> software_device)
: client_(NULL),
software_device_(software_device.Pass()) {
}

OutputSurface::OutputSurface(
scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
scoped_ptr<cc::SoftwareOutputDevice> software_device)
: client_(NULL),
context3d_(context3d.Pass()),
software_device_(software_device.Pass()) {
}

OutputSurface::~OutputSurface() {
}

bool OutputSurface::BindToClient(
cc::OutputSurfaceClient* client) {
DCHECK(client);
client_ = client;
if (!context3d_)
return true;
return context3d_->makeContextCurrent();
}

void OutputSurface::SendFrameToParentCompositor(CompositorFrame*) {
NOTIMPLEMENTED();
}

} // namespace cc
48 changes: 33 additions & 15 deletions cc/output_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@

#define USE_CC_OUTPUT_SURFACE // TODO(danakj): Remove this.

#include "base/memory/scoped_ptr.h"
#include "cc/cc_export.h"
#include "cc/software_output_device.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorOutputSurface.h"

namespace WebKit {
class WebGraphicsContext3D;
}
#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"

namespace cc {

class CompositorFrame;
class OutputSurfaceClient;
class SoftwareOutputDevice;

// Represents the output surface for a compositor. The compositor owns
// and manages its destruction. Its lifetime is:
Expand All @@ -29,13 +27,14 @@ class SoftwareOutputDevice;
// surface (on the compositor thread) and go back to step 1.
class CC_EXPORT OutputSurface : public WebKit::WebCompositorOutputSurface {
public:
virtual ~OutputSurface() {}
OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d);

// Called by the compositor on the compositor thread. This is a place where
// thread-specific data for the output surface can be initialized, since from
// this point on the output surface will only be used on the compositor
// thread.
virtual bool BindToClient(OutputSurfaceClient*) = 0;
OutputSurface(scoped_ptr<cc::SoftwareOutputDevice> software_device);

OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D> context3d,
scoped_ptr<cc::SoftwareOutputDevice> software_device);

virtual ~OutputSurface();

struct Capabilities {
Capabilities()
Expand All @@ -44,23 +43,42 @@ class CC_EXPORT OutputSurface : public WebKit::WebCompositorOutputSurface {
bool has_parent_compositor;
};

virtual const Capabilities& Capabilities() const = 0;
const Capabilities& capabilities() const {
return capabilities_;
}

// Obtain the 3d context or the software device associated with this output
// surface. Either of these may return a null pointer, but not both.
// In the event of a lost context, the entire output surface should be
// recreated.
virtual WebKit::WebGraphicsContext3D* Context3D() const = 0;
virtual SoftwareOutputDevice* SoftwareDevice() const = 0;
WebKit::WebGraphicsContext3D* context3d() const {
return context3d_.get();
}

SoftwareOutputDevice* software_device() const {
return software_device_.get();
}

// Called by the compositor on the compositor thread. This is a place where
// thread-specific data for the output surface can be initialized, since from
// this point on the output surface will only be used on the compositor
// thread.
virtual bool BindToClient(OutputSurfaceClient*);

// Sends frame data to the parent compositor. This should only be called when
// capabilities().has_parent_compositor. The implementation may destroy or
// steal the contents of the CompositorFrame passed in.
virtual void SendFrameToParentCompositor(CompositorFrame*) = 0;
virtual void SendFrameToParentCompositor(CompositorFrame*);

// Notifies frame-rate smoothness preference. If true, all non-critical
// processing should be stopped, or lowered in priority.
virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {}

protected:
OutputSurfaceClient* client_;
struct cc::OutputSurface::Capabilities capabilities_;
scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
scoped_ptr<cc::SoftwareOutputDevice> software_device_;
};

} // namespace cc
Expand Down
Loading

0 comments on commit 79a1be5

Please sign in to comment.