Skip to content

Commit

Permalink
Changed SoftwareOutputDevice interface.
Browse files Browse the repository at this point in the history
+ Some of the necessary changes to the renderer for software compositing.


BUG=124671, 161008


Review URL: https://chromiumcodereview.appspot.com/12379055

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186310 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skaslev@chromium.org committed Mar 6, 2013
1 parent 8be1c58 commit bd3d1ce
Show file tree
Hide file tree
Showing 30 changed files with 283 additions and 307 deletions.
1 change: 1 addition & 0 deletions cc/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include_rules = [
"+third_party/khronos/GLES2/gl2ext.h",
"+ui/gfx",
"+ui/gl",
"+ui/surface",
# 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
Expand Down
4 changes: 4 additions & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@
'single_thread_proxy.h',
'skpicture_content_layer_updater.cc',
'skpicture_content_layer_updater.h',
'software_frame_data.cc',
'software_frame_data.h',
'software_output_device.cc',
'software_output_device.h',
'software_renderer.cc',
'software_renderer.h',
Expand Down Expand Up @@ -347,6 +350,7 @@
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/media/media.gyp:media',
'<(DEPTH)/ui/gl/gl.gyp:gl',
'<(DEPTH)/ui/surface/surface.gyp:surface',
'<(DEPTH)/ui/ui.gyp:ui',
'<(webkit_src_dir)/Source/WebKit/chromium/WebKit.gyp:webkit',
],
Expand Down
2 changes: 0 additions & 2 deletions cc/cc_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@
'test/fake_tile_manager_client.h',
'test/fake_output_surface.cc',
'test/fake_output_surface.h',
'test/fake_software_output_device.cc',
'test/fake_software_output_device.h',
'test/fake_video_frame_provider.cc',
'test/fake_video_frame_provider.h',
'test/fake_web_scrollbar.cc',
Expand Down
1 change: 1 addition & 0 deletions cc/compositor_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CompositorFrame::~CompositorFrame() {}
void CompositorFrame::AssignTo(CompositorFrame* target) {
target->delegated_frame_data = delegated_frame_data.Pass();
target->gl_frame_data = gl_frame_data.Pass();
target->software_frame_data = software_frame_data.Pass();
target->metadata = metadata;
}

Expand Down
2 changes: 2 additions & 0 deletions cc/compositor_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "cc/compositor_frame_metadata.h"
#include "cc/delegated_frame_data.h"
#include "cc/gl_frame_data.h"
#include "cc/software_frame_data.h"

namespace cc {

Expand All @@ -21,6 +22,7 @@ class CC_EXPORT CompositorFrame {
CompositorFrameMetadata metadata;
scoped_ptr<DelegatedFrameData> delegated_frame_data;
scoped_ptr<GLFrameData> gl_frame_data;
scoped_ptr<SoftwareFrameData> software_frame_data;

void AssignTo(CompositorFrame* target);
};
Expand Down
4 changes: 3 additions & 1 deletion cc/compositor_frame_ack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

namespace cc {

CompositorFrameAck::CompositorFrameAck() {}
CompositorFrameAck::CompositorFrameAck()
: last_content_dib(TransportDIB::DefaultHandleValue()) {
}

CompositorFrameAck::~CompositorFrameAck() {}

Expand Down
2 changes: 2 additions & 0 deletions cc/compositor_frame_ack.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cc/cc_export.h"
#include "cc/gl_frame_data.h"
#include "cc/transferable_resource.h"
#include "ui/surface/transport_dib.h"

namespace cc {

Expand All @@ -19,6 +20,7 @@ class CC_EXPORT CompositorFrameAck {

TransferableResourceArray resources;
scoped_ptr<GLFrameData> gl_frame_data;
TransportDIB::Handle last_content_dib;
};

} // namespace cc
Expand Down
7 changes: 5 additions & 2 deletions cc/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cc/gl_frame_data.h"
#include "cc/layer_quad.h"
#include "cc/math_util.h"
#include "cc/output_surface.h"
#include "cc/priority_calculator.h"
#include "cc/proxy.h"
#include "cc/render_pass.h"
Expand Down Expand Up @@ -80,14 +81,16 @@ bool needsIOSurfaceReadbackWorkaround()

scoped_ptr<GLRenderer> GLRenderer::create(RendererClient* client, OutputSurface* outputSurface, ResourceProvider* resourceProvider)
{
scoped_ptr<GLRenderer> renderer(make_scoped_ptr(new GLRenderer(client, outputSurface, resourceProvider)));
scoped_ptr<GLRenderer> renderer(new GLRenderer(client, outputSurface, resourceProvider));
if (!renderer->initialize())
return scoped_ptr<GLRenderer>();

return renderer.Pass();
}

GLRenderer::GLRenderer(RendererClient* client, OutputSurface* outputSurface, ResourceProvider* resourceProvider)
GLRenderer::GLRenderer(RendererClient* client,
OutputSurface* outputSurface,
ResourceProvider* resourceProvider)
: DirectRenderer(client, resourceProvider)
, m_offscreenFramebufferId(0)
, m_sharedGeometryQuad(gfx::RectF(-0.5f, -0.5f, 1.0f, 1.0f))
Expand Down
2 changes: 1 addition & 1 deletion cc/gl_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "cc/direct_renderer.h"
#include "cc/gl_renderer_draw_cache.h"
#include "cc/io_surface_draw_quad.h"
#include "cc/output_surface.h"
#include "cc/render_pass_draw_quad.h"
#include "cc/renderer.h"
#include "cc/solid_color_draw_quad.h"
Expand All @@ -23,6 +22,7 @@

namespace cc {

class OutputSurface;
class ScopedResource;
class StreamVideoDrawQuad;
class TextureDrawQuad;
Expand Down
2 changes: 1 addition & 1 deletion cc/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ bool LayerTreeHostImpl::initializeRenderer(scoped_ptr<OutputSurface> outputSurfa
else if (outputSurface->context3d())
m_renderer = GLRenderer::create(this, outputSurface.get(), resourceProvider.get());
else if (outputSurface->software_device())
m_renderer = SoftwareRenderer::create(this, resourceProvider.get(), outputSurface->software_device());
m_renderer = SoftwareRenderer::create(this, outputSurface.get(), resourceProvider.get());
if (!m_renderer)
return false;

Expand Down
4 changes: 4 additions & 0 deletions cc/output_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "cc/cc_export.h"
#include "cc/software_output_device.h"
Expand Down Expand Up @@ -95,6 +96,9 @@ class CC_EXPORT OutputSurface : public WebKit::WebCompositorOutputSurface {
scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
scoped_ptr<cc::SoftwareOutputDevice> software_device_;
bool has_gl_discard_backbuffer_;

private:
DISALLOW_COPY_AND_ASSIGN(OutputSurface);
};

} // namespace cc
Expand Down
1 change: 1 addition & 0 deletions cc/picture_layer_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "ui/gfx/rect_conversions.h"

namespace cc {
Expand Down
14 changes: 14 additions & 0 deletions cc/software_frame_data.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/software_frame_data.h"

namespace cc {

SoftwareFrameData::SoftwareFrameData()
: content_dib(TransportDIB::DefaultHandleValue()) {
}

SoftwareFrameData::~SoftwareFrameData() {}

} // namespace cc
26 changes: 26 additions & 0 deletions cc/software_frame_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_SOFTWARE_FRAME_DATA_H_
#define CC_SOFTWARE_FRAME_DATA_H_

#include "base/basictypes.h"
#include "cc/cc_export.h"
#include "ui/gfx/rect.h"
#include "ui/surface/transport_dib.h"

namespace cc {

class CC_EXPORT SoftwareFrameData {
public:
SoftwareFrameData();
~SoftwareFrameData();

gfx::Rect damage_rect;
TransportDIB::Handle content_dib;
};

} // namespace cc

#endif // CC_SOFTWARE_FRAME_DATA_H_
61 changes: 61 additions & 0 deletions cc/software_output_device.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/software_output_device.h"

#include "base/logging.h"
#include "cc/software_frame_data.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDevice.h"

namespace cc {

SoftwareOutputDevice::SoftwareOutputDevice() {}

SoftwareOutputDevice::~SoftwareOutputDevice() {}

void SoftwareOutputDevice::Resize(const gfx::Size& viewport_size) {
if (viewport_size_ == viewport_size)
return;

viewport_size_ = viewport_size;
device_ = skia::AdoptRef(new SkDevice(SkBitmap::kARGB_8888_Config,
viewport_size.width(), viewport_size.height(), true));
canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
}

SkCanvas* SoftwareOutputDevice::BeginPaint(const gfx::Rect& damage_rect) {
DCHECK(device_);
damage_rect_ = damage_rect;
return canvas_.get();
}

void SoftwareOutputDevice::EndPaint(SoftwareFrameData* frame_data) {
DCHECK(device_);
if (frame_data) {
frame_data->damage_rect = damage_rect_;
frame_data->content_dib = TransportDIB::DefaultHandleValue();
}
}

void SoftwareOutputDevice::CopyToBitmap(
const gfx::Rect& rect, SkBitmap* output) {
DCHECK(device_);
SkIRect invertRect = SkIRect::MakeXYWH(
rect.x(), viewport_size_.height() - rect.bottom(),
rect.width(), rect.height());
const SkBitmap& bitmap = device_->accessBitmap(false);
bitmap.extractSubset(output, invertRect);
}

void SoftwareOutputDevice::Scroll(
const gfx::Vector2d& delta, const gfx::Rect& clip_rect) {
NOTIMPLEMENTED();
}

void SoftwareOutputDevice::ReclaimDIB(TransportDIB::Handle handle) {
NOTIMPLEMENTED();
}

} // namespace cc
45 changes: 35 additions & 10 deletions cc/software_output_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,50 @@
#ifndef CC_SOFTWARE_OUTPUT_DEVICE_H_
#define CC_SOFTWARE_OUTPUT_DEVICE_H_

#include "third_party/WebKit/Source/Platform/chromium/public/WebImage.h"
#include "base/basictypes.h"
#include "cc/cc_export.h"
#include "skia/ext/refptr.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/vector2d.h"
#include "ui/surface/transport_dib.h"

class SkBitmap;
class SkDevice;
class SkCanvas;

namespace cc {

class SoftwareFrameData;

// This is a "tear-off" class providing software drawing support to
// OutputSurface, such as to a platform-provided window framebuffer.
class SoftwareOutputDevice {
class CC_EXPORT SoftwareOutputDevice {
public:
virtual ~SoftwareOutputDevice() {}

// Lock the framebuffer and return a pointer to a WebImage referring to its
// pixels. Set forWrite if you intend to change the pixels. Readback
// is supported whether or not forWrite is set.
// TODO(danakj): Switch this from WebImage to a Skia type.
virtual WebKit::WebImage* Lock(bool forWrite) = 0;
virtual void Unlock() = 0;
SoftwareOutputDevice();
virtual ~SoftwareOutputDevice();

// SoftwareOutputDevice implementation
virtual void Resize(const gfx::Size& size);

virtual SkCanvas* BeginPaint(const gfx::Rect& damage_rect);
virtual void EndPaint(SoftwareFrameData* frame_data=NULL);

virtual void CopyToBitmap(const gfx::Rect& rect, SkBitmap* output);
virtual void Scroll(const gfx::Vector2d& delta,
const gfx::Rect& clip_rect);

// TODO(skaslev) Remove this after UberCompositor lands.
virtual void ReclaimDIB(TransportDIB::Handle handle);

protected:
gfx::Size viewport_size_;
gfx::Rect damage_rect_;
skia::RefPtr<SkDevice> device_;
skia::RefPtr<SkCanvas> canvas_;

virtual void DidChangeViewportSize(gfx::Size) = 0;
DISALLOW_COPY_AND_ASSIGN(SoftwareOutputDevice);
};

} // namespace cc
Expand Down
Loading

0 comments on commit bd3d1ce

Please sign in to comment.