| Index: cc/layer_tree_host_impl_unittest.cc
|
| diff --git a/cc/layer_tree_host_impl_unittest.cc b/cc/layer_tree_host_impl_unittest.cc
|
| index 64cec3bfd0a54cd4c3f6c7829711783aaf4c7b9b..2d506540d64759ae5a204b9eb3e31167484f9823 100644
|
| --- a/cc/layer_tree_host_impl_unittest.cc
|
| +++ b/cc/layer_tree_host_impl_unittest.cc
|
| @@ -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"
|
| @@ -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>
|
| @@ -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;
|
| @@ -63,6 +67,7 @@ public:
|
| , m_didRequestRedraw(false)
|
| , m_reduceMemoryResult(true)
|
| {
|
| + media::InitializeMediaLibraryForTesting();
|
| }
|
|
|
| virtual void SetUp()
|
| @@ -2532,25 +2537,31 @@ private:
|
| 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.
|
| @@ -2695,10 +2706,15 @@ 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));
|
| @@ -2706,10 +2722,9 @@ TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostContext)
|
| 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));
|
| @@ -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());
|
|
|
| @@ -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);
|
| @@ -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));
|
|
|