Skip to content

Commit

Permalink
Added support for YUV videos to the software compositor.
Browse files Browse the repository at this point in the history
Those Layout Tests pass with this patch (minus filtering differences):

platform/chromium/virtual/softwarecompositing/geometry/video-fixed-scrolling.html
platform/chromium/virtual/softwarecompositing/geometry/video-opacity-overlay.html
platform/chromium/virtual/softwarecompositing/layers-inside-overflow-scroll.html
platform/chromium/virtual/softwarecompositing/overflow/scroll-ancestor-update.html
platform/chromium/virtual/softwarecompositing/self-painting-layers.html
platform/chromium/virtual/softwarecompositing/reflections/load-video-in-reflection.html
platform/chromium/virtual/softwarecompositing/video-page-visibility.html                                                                                                                                            
platform/chromium/virtual/softwarecompositing/visibility/visibility-simple-video-layer.html



BUG=150016


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164871 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
skaslev@chromium.org committed Oct 30, 2012
1 parent f450de7 commit 59cb7b3
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 119 deletions.
1 change: 1 addition & 0 deletions cc/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include_rules = [
"+third_party/khronos/GLES2/gl2.h",
"+third_party/khronos/GLES2/gl2ext.h",
"+ui/gfx",
"+media",
# http://crbug.com/144542
"+third_party/WebKit/Source/WebCore/platform/graphics/FloatPoint.h",
"+third_party/WebKit/Source/WebCore/platform/graphics/FloatPoint3D.h",
Expand Down
1 change: 1 addition & 0 deletions cc/cc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations',
'<(DEPTH)/skia/skia.gyp:skia',
'<(DEPTH)/media/media.gyp:media',
'<(DEPTH)/ui/gl/gl.gyp:gl',
'<(DEPTH)/ui/ui.gyp:ui',
'<(webkit_src_dir)/Source/WTF/WTF.gyp/WTF.gyp:wtf',
Expand Down
1 change: 1 addition & 0 deletions cc/cc_tests.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'type': '<(gtest_target_type)',
'dependencies': [
'../base/base.gyp:test_support_base',
'../media/media.gyp:media',
'../skia/skia.gyp:skia',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
Expand Down
1 change: 0 additions & 1 deletion cc/gl_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "ui/gfx/rect_conversions.h"
#include <public/WebGraphicsContext3D.h>
#include <public/WebSharedGraphicsContext3D.h>
#include <public/WebVideoFrame.h>
#include <set>
#include <string>
#include <vector>
Expand Down
73 changes: 51 additions & 22 deletions cc/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "cc/layer_tree_host_impl.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "base/hash_tables.h"
#include "cc/delegated_renderer_layer_impl.h"
Expand Down Expand Up @@ -34,6 +35,8 @@
#include "cc/tile_draw_quad.h"
#include "cc/tiled_layer_impl.h"
#include "cc/video_layer_impl.h"
#include "media/base/media.h"
#include "media/base/video_frame.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <public/WebVideoFrame.h>
Expand All @@ -44,6 +47,7 @@ using namespace LayerTestCommon;
using namespace WebKit;
using namespace WebKitTests;

using media::VideoFrame;
using ::testing::Mock;
using ::testing::Return;
using ::testing::AnyNumber;
Expand All @@ -63,6 +67,7 @@ class LayerTreeHostImplTest : public testing::TestWithParam<bool>,
, m_didRequestRedraw(false)
, m_reduceMemoryResult(true)
{
media::InitializeMediaLibraryForTesting();
}

virtual void SetUp()
Expand Down Expand Up @@ -2532,25 +2537,31 @@ class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D {
base::hash_set<unsigned> m_allocatedTextureIds;
};

// Fake video frame that represents a 4x4 YUV video frame.
// Fake WebVideoFrame wrapper of media::VideoFrame.
class FakeVideoFrame: public WebVideoFrame {
public:
FakeVideoFrame() : m_textureId(0) { memset(m_data, 0x80, sizeof(m_data)); }
explicit FakeVideoFrame(const scoped_refptr<VideoFrame>& frame) : m_frame(frame) { }
virtual ~FakeVideoFrame() { }
virtual Format format() const { return m_textureId ? FormatNativeTexture : FormatYV12; }
virtual unsigned width() const { return 4; }
virtual unsigned height() const { return 4; }
virtual unsigned planes() const { return m_textureId ? 0 : 3; }
virtual int stride(unsigned plane) const { return 4; }
virtual const void* data(unsigned plane) const { return m_data; }
virtual unsigned textureId() const { return m_textureId; }
virtual unsigned textureTarget() const { return m_textureId ? GL_TEXTURE_2D : 0; }

void setTextureId(unsigned id) { m_textureId = id; }
virtual Format format() const { NOTREACHED(); return FormatInvalid; }
virtual unsigned width() const { NOTREACHED(); return 0; }
virtual unsigned height() const { NOTREACHED(); return 0; }
virtual unsigned planes() const { NOTREACHED(); return 0; }
virtual int stride(unsigned plane) const { NOTREACHED(); return 0; }
virtual const void* data(unsigned plane) const { NOTREACHED(); return NULL; }
virtual unsigned textureId() const { NOTREACHED(); return 0; }
virtual unsigned textureTarget() const { NOTREACHED(); return 0; }

static VideoFrame* toVideoFrame(WebVideoFrame* web_video_frame) {
FakeVideoFrame* wrapped_frame =
static_cast<FakeVideoFrame*>(web_video_frame);
if (wrapped_frame)
return wrapped_frame->m_frame.get();
return NULL;
}

private:
char m_data[16];
unsigned m_textureId;
scoped_refptr<VideoFrame> m_frame;
};

// Fake video frame provider that always provides the same FakeVideoFrame.
Expand Down Expand Up @@ -2695,21 +2706,25 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostContext)
textureLayerWithMask->setMaskLayer(maskLayer.PassAs<LayerImpl>());
rootLayer->addChild(textureLayerWithMask.PassAs<LayerImpl>());

FakeVideoFrame videoFrame;
FakeVideoFrame videoFrame(VideoFrame::CreateColorFrame(gfx::Size(4, 4),
0x80, 0x80, 0x80,
base::TimeDelta()));
VideoLayerImpl::FrameUnwrapper unwrapper =
base::Bind(FakeVideoFrame::toVideoFrame);
FakeVideoFrameProvider provider;
provider.setFrame(&videoFrame);
scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(layerId++, &provider);
scoped_ptr<VideoLayerImpl> videoLayer =
VideoLayerImpl::create(layerId++, &provider, unwrapper);
videoLayer->setBounds(IntSize(10, 10));
videoLayer->setAnchorPoint(FloatPoint(0, 0));
videoLayer->setContentBounds(IntSize(10, 10));
videoLayer->setDrawsContent(true);
videoLayer->setLayerTreeHostImpl(m_hostImpl.get());
rootLayer->addChild(videoLayer.PassAs<LayerImpl>());

FakeVideoFrame hwVideoFrame;
FakeVideoFrameProvider hwProvider;
hwProvider.setFrame(&hwVideoFrame);
scoped_ptr<VideoLayerImpl> hwVideoLayer = VideoLayerImpl::create(layerId++, &hwProvider);
scoped_ptr<VideoLayerImpl> hwVideoLayer =
VideoLayerImpl::create(layerId++, &hwProvider, unwrapper);
hwVideoLayer->setBounds(IntSize(10, 10));
hwVideoLayer->setAnchorPoint(FloatPoint(0, 0));
hwVideoLayer->setContentBounds(IntSize(10, 10));
Expand Down Expand Up @@ -2756,7 +2771,13 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostContext)
// Use a context that supports IOSurfaces
m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DWithIOSurface)).PassAs<GraphicsContext>());

hwVideoFrame.setTextureId(m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture());
FakeVideoFrame hwVideoFrame(
VideoFrame::WrapNativeTexture(
m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture(),
GL_TEXTURE_2D,
gfx::Size(4, 4), gfx::Size(4, 4), base::TimeDelta(),
VideoFrame::ReadPixelsCB(), base::Closure()));
hwProvider.setFrame(&hwVideoFrame);

m_hostImpl->setRootLayer(rootLayer.Pass());

Expand Down Expand Up @@ -2786,8 +2807,13 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostContext)
m_hostImpl->didDrawAllLayers(frame);
m_hostImpl->swapBuffers();

hwVideoFrame.setTextureId(m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture());
hwProvider.setFrame(&hwVideoFrame);
FakeVideoFrame hwVideoFrame2(
VideoFrame::WrapNativeTexture(
m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture(),
GL_TEXTURE_2D,
gfx::Size(4, 4), gfx::Size(4, 4), base::TimeDelta(),
VideoFrame::ReadPixelsCB(), base::Closure()));
hwProvider.setFrame(&hwVideoFrame2);

EXPECT_TRUE(m_hostImpl->prepareToDraw(frame));
m_hostImpl->drawLayers(frame);
Expand Down Expand Up @@ -2862,8 +2888,11 @@ TEST_P(LayerTreeHostImplTest, layersFreeTextures)
textureLayer->setTextureId(1);
rootLayer->addChild(textureLayer.PassAs<LayerImpl>());

VideoLayerImpl::FrameUnwrapper unwrapper =
base::Bind(FakeVideoFrame::toVideoFrame);
FakeVideoFrameProvider provider;
scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(4, &provider);
scoped_ptr<VideoLayerImpl> videoLayer =
VideoLayerImpl::create(4, &provider, unwrapper);
videoLayer->setBounds(IntSize(10, 10));
videoLayer->setAnchorPoint(FloatPoint(0, 0));
videoLayer->setContentBounds(IntSize(10, 10));
Expand Down
7 changes: 4 additions & 3 deletions cc/software_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "third_party/skia/include/core/SkShader.h"
#include "third_party/skia/include/effects/SkLayerRasterizer.h"
#include "ui/gfx/rect_conversions.h"
#include <public/WebCompositorSoftwareOutputDevice.h>
#include <public/WebImage.h>
#include <public/WebSize.h>
#include <public/WebTransformationMatrix.h>

using WebKit::WebCompositorSoftwareOutputDevice;
using WebKit::WebImage;
using WebKit::WebSize;
using WebKit::WebTransformationMatrix;

Expand Down Expand Up @@ -255,11 +255,12 @@ void SoftwareRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureD

// FIXME: Add support for non-premultiplied alpha.
ResourceProvider::ScopedReadLockSoftware quadResourceLock(m_resourceProvider, quad->resourceId());
gfx::RectF uvRect = gfx::ScaleRect(quad->uvRect(), quad->quadRect().width(), quad->quadRect().height());
const SkBitmap* bitmap = quadResourceLock.skBitmap();
gfx::RectF uvRect = gfx::ScaleRect(quad->uvRect(), bitmap->width(), bitmap->height());
SkIRect skUvRect = toSkIRect(gfx::ToEnclosingRect(uvRect));
if (quad->flipped())
m_skCurrentCanvas->scale(1, -1);
m_skCurrentCanvas->drawBitmapRect(*quadResourceLock.skBitmap(), &skUvRect, toSkRect(quadVertexRect()), &m_skCurrentPaint);
m_skCurrentCanvas->drawBitmapRect(*bitmap, &skUvRect, toSkRect(quadVertexRect()), &m_skCurrentPaint);
}

void SoftwareRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* quad)
Expand Down
5 changes: 4 additions & 1 deletion cc/software_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

#include "base/basictypes.h"
#include "cc/direct_renderer.h"
#include <public/WebCompositorSoftwareOutputDevice.h>

namespace WebKit {
class WebCompositorSoftwareOutputDevice;
}

namespace cc {

Expand Down
17 changes: 10 additions & 7 deletions cc/video_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@

namespace cc {

scoped_refptr<VideoLayer> VideoLayer::create(WebKit::WebVideoFrameProvider* provider)
scoped_refptr<VideoLayer> VideoLayer::create(
WebKit::WebVideoFrameProvider* provider,
const FrameUnwrapper& unwrapper)
{
return make_scoped_refptr(new VideoLayer(provider));
return make_scoped_refptr(new VideoLayer(provider, unwrapper));
}

VideoLayer::VideoLayer(WebKit::WebVideoFrameProvider* provider)
: Layer()
, m_provider(provider)
VideoLayer::VideoLayer(WebKit::WebVideoFrameProvider* provider,
const FrameUnwrapper& unwrapper)
: m_provider(provider)
, m_unwrapper(unwrapper)
{
DCHECK(m_provider);
}
Expand All @@ -28,7 +31,7 @@ VideoLayer::~VideoLayer()

scoped_ptr<LayerImpl> VideoLayer::createLayerImpl()
{
return VideoLayerImpl::create(m_layerId, m_provider).PassAs<LayerImpl>();
return VideoLayerImpl::create(m_layerId, m_provider, m_unwrapper).PassAs<LayerImpl>();
}

} // namespace cc
} // namespace cc
17 changes: 14 additions & 3 deletions cc/video_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,41 @@
#ifndef VideoLayerChromium_h
#define VideoLayerChromium_h

#include "base/callback.h"
#include "cc/layer.h"

namespace WebKit {
class WebVideoFrame;
class WebVideoFrameProvider;
}

namespace media {
class VideoFrame;
}

namespace cc {

class VideoLayerImpl;

// A Layer that contains a Video element.
class VideoLayer : public Layer {
public:
static scoped_refptr<VideoLayer> create(WebKit::WebVideoFrameProvider*);
typedef base::Callback<media::VideoFrame* (WebKit::WebVideoFrame*)> FrameUnwrapper;

static scoped_refptr<VideoLayer> create(WebKit::WebVideoFrameProvider*,
const FrameUnwrapper&);

virtual scoped_ptr<LayerImpl> createLayerImpl() OVERRIDE;

private:
explicit VideoLayer(WebKit::WebVideoFrameProvider*);
VideoLayer(WebKit::WebVideoFrameProvider*, const FrameUnwrapper&);
virtual ~VideoLayer();

// This pointer is only for passing to VideoLayerImpl's constructor. It should never be dereferenced by this class.
WebKit::WebVideoFrameProvider* m_provider;
FrameUnwrapper m_unwrapper;
};

}
} // namespace cc

#endif
Loading

0 comments on commit 59cb7b3

Please sign in to comment.