diff options
-rw-r--r-- | cc/cc_tests.gyp | 1 | ||||
-rw-r--r-- | cc/direct_renderer.h | 8 | ||||
-rw-r--r-- | cc/gl_renderer.cc | 7 | ||||
-rw-r--r-- | cc/gl_renderer_unittest.cc | 55 | ||||
-rw-r--r-- | cc/test/render_pass_test_common.cc | 54 | ||||
-rw-r--r-- | cc/test/render_pass_test_common.h | 6 |
6 files changed, 121 insertions, 10 deletions
diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index 9e94946..cf2f214 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -80,6 +80,7 @@ 'test/mock_quad_culler.cc', 'test/mock_quad_culler.h', 'test/occlusion_tracker_test_common.h', + 'test/render_pass_test_common.cc', 'test/render_pass_test_common.h', 'test/scheduler_test_common.cc', 'test/scheduler_test_common.h', diff --git a/cc/direct_renderer.h b/cc/direct_renderer.h index 25a9e46..716f858 100644 --- a/cc/direct_renderer.h +++ b/cc/direct_renderer.h @@ -28,10 +28,7 @@ public: virtual bool haveCachedResourcesForRenderPassId(RenderPass::Id) const OVERRIDE; virtual void drawFrame(const RenderPassList& renderPassesInDrawOrder, const RenderPassIdHashMap& renderPassesById) OVERRIDE; -protected: - DirectRenderer(RendererClient* client, ResourceProvider* resourceProvider); - - struct DrawingFrame { + struct CC_EXPORT DrawingFrame { DrawingFrame(); ~DrawingFrame(); @@ -48,6 +45,9 @@ protected: gfx::RectF scissorRectInRenderPassSpace; }; +protected: + DirectRenderer(RendererClient* client, ResourceProvider* resourceProvider); + class CachedResource : public ScopedResource { public: static scoped_ptr<CachedResource> create(ResourceProvider* resourceProvider) { diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc index 55e2846..c9be888 100644 --- a/cc/gl_renderer.cc +++ b/cc/gl_renderer.cc @@ -242,6 +242,7 @@ void GLRenderer::beginDrawingFrame(DrawingFrame& frame) GLC(m_context, m_context->colorMask(true, true, true, true)); GLC(m_context, m_context->enable(GL_BLEND)); GLC(m_context, m_context->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)); + GLC(context(), context()->activeTexture(GL_TEXTURE0)); } void GLRenderer::doNoOp() @@ -573,7 +574,6 @@ void GLRenderer::drawRenderPassQuad(DrawingFrame& frame, const RenderPassDrawQua // FIXME: use the backgroundTexture and blend the background in with this draw instead of having a separate copy of the background texture. - GLC(context(), context()->activeTexture(GL_TEXTURE0)); context()->bindTexture(GL_TEXTURE_2D, contentsTextureId); int shaderQuadLocation = -1; @@ -759,7 +759,6 @@ void GLRenderer::drawTileQuad(const DrawingFrame& frame, const TileDrawQuad* qua GLC(context(), context()->useProgram(uniforms.program)); GLC(context(), context()->uniform1i(uniforms.samplerLocation, 0)); - GLC(context(), context()->activeTexture(GL_TEXTURE0)); ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad->resourceId()); GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textureId())); GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, quad->textureFilter())); @@ -925,7 +924,6 @@ void GLRenderer::drawStreamVideoQuad(const DrawingFrame& frame, const StreamVide toGLMatrix(&glMatrix[0], quad->matrix()); GLC(context(), context()->uniformMatrix4fv(program->vertexShader().texMatrixLocation(), 1, false, glMatrix)); - GLC(context(), context()->activeTexture(GL_TEXTURE0)); GLC(context(), context()->bindTexture(GL_TEXTURE_EXTERNAL_OES, quad->textureId())); GLC(context(), context()->uniform1i(program->fragmentShader().samplerLocation(), 0)); @@ -970,7 +968,6 @@ void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua const gfx::RectF& uvRect = quad->uvRect(); GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height())); - GLC(context(), context()->activeTexture(GL_TEXTURE0)); ResourceProvider::ScopedReadLockGL quadResourceLock(m_resourceProvider, quad->resourceId()); GLC(context(), context()->bindTexture(GL_TEXTURE_2D, quadResourceLock.textureId())); @@ -1012,7 +1009,6 @@ void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra else GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->ioSurfaceSize().width(), quad->ioSurfaceSize().height())); - GLC(context(), context()->activeTexture(GL_TEXTURE0)); GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->ioSurfaceTextureId())); setShaderOpacity(quad->opacity(), binding.alphaLocation); @@ -1092,7 +1088,6 @@ void GLRenderer::copyTextureToFramebuffer(const DrawingFrame& frame, int texture { const RenderPassProgram* program = renderPassProgram(); - GLC(context(), context()->activeTexture(GL_TEXTURE0)); GLC(context(), context()->bindTexture(GL_TEXTURE_2D, textureId)); GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); GLC(context(), context()->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); diff --git a/cc/gl_renderer_unittest.cc b/cc/gl_renderer_unittest.cc index 0967cec..5e1e978 100644 --- a/cc/gl_renderer_unittest.cc +++ b/cc/gl_renderer_unittest.cc @@ -12,6 +12,7 @@ #include "cc/test/fake_web_compositor_output_surface.h" #include "cc/test/fake_web_graphics_context_3d.h" #include "cc/test/test_common.h" +#include "cc/test/render_pass_test_common.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/khronos/GLES2/gl2.h" @@ -104,6 +105,8 @@ public: // Changing visibility to public. using GLRenderer::initialize; using GLRenderer::isFramebufferDiscarded; + using GLRenderer::drawQuad; + using GLRenderer::beginDrawingFrame; }; class GLRendererTest : public testing::Test { @@ -482,4 +485,56 @@ TEST(GLRendererTest2, visibilityChangeIsLastCall) EXPECT_TRUE(lastCallWasSetVisiblity); } + +class ActiveTextureTrackingContext : public FakeWebGraphicsContext3D { +public: + ActiveTextureTrackingContext() + : m_activeTexture(GL_INVALID_ENUM) + { + } + + virtual WebString getString(WGC3Denum name) + { + if (name == GL_EXTENSIONS) + return WebString("GL_OES_EGL_image_external"); + return WebString(); + } + + virtual void activeTexture(WGC3Denum texture) + { + EXPECT_NE(texture, m_activeTexture); + m_activeTexture = texture; + } + + WGC3Denum activeTexture() const { return m_activeTexture; } + +private: + WGC3Denum m_activeTexture; +}; + +TEST(GLRendererTest2, activeTextureState) +{ + FakeRendererClient fakeClient; + scoped_ptr<GraphicsContext> outputSurface(FakeWebCompositorOutputSurface::create(scoped_ptr<WebKit::WebGraphicsContext3D>(new ActiveTextureTrackingContext))); + ActiveTextureTrackingContext* context = static_cast<ActiveTextureTrackingContext*>(outputSurface->context3D()); + scoped_ptr<ResourceProvider> resourceProvider(ResourceProvider::create(outputSurface.get())); + FakeRendererGL renderer(&fakeClient, resourceProvider.get()); + + EXPECT_TRUE(renderer.initialize()); + + cc::RenderPass::Id id(1, 1); + scoped_ptr<TestRenderPass> pass = TestRenderPass::create(id, gfx::Rect(0, 0, 100, 100), WebTransformationMatrix()); + pass->appendOneOfEveryQuadType(resourceProvider.get()); + + cc::DirectRenderer::DrawingFrame drawingFrame; + renderer.beginDrawingFrame(drawingFrame); + EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); + + for (cc::QuadList::backToFrontIterator it = pass->quadList().backToFrontBegin(); + it != pass->quadList().backToFrontEnd(); ++it) { + renderer.drawQuad(drawingFrame, *it); + } + EXPECT_EQ(context->activeTexture(), GL_TEXTURE0); +} + } // anonymous namespace diff --git a/cc/test/render_pass_test_common.cc b/cc/test/render_pass_test_common.cc new file mode 100644 index 0000000..d3680e6 --- /dev/null +++ b/cc/test/render_pass_test_common.cc @@ -0,0 +1,54 @@ +// Copyright 2012 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/test/render_pass_test_common.h" + +#include "cc/checkerboard_draw_quad.h" +#include "cc/debug_border_draw_quad.h" +#include "cc/io_surface_draw_quad.h" +#include "cc/render_pass_draw_quad.h" +#include "cc/solid_color_draw_quad.h" +#include "cc/shared_quad_state.h" +#include "cc/stream_video_draw_quad.h" +#include "cc/texture_draw_quad.h" +#include "cc/tile_draw_quad.h" +#include "cc/yuv_video_draw_quad.h" +#include "cc/resource_provider.h" +#include <public/WebTransformationMatrix.h> + +namespace WebKitTests { + +using cc::DrawQuad; +using WebKit::WebTransformationMatrix; + +void TestRenderPass::appendOneOfEveryQuadType(cc::ResourceProvider* resourceProvider) +{ + gfx::Rect rect(0, 0, 100, 100); + cc::ResourceProvider::ResourceId textureResource = resourceProvider->createResourceFromExternalTexture(1); + scoped_ptr<cc::SharedQuadState> sharedState = cc::SharedQuadState::create(WebTransformationMatrix(), rect, rect, 1, false); + + appendQuad(cc::CheckerboardDrawQuad::create(sharedState.get(), rect, SK_ColorRED).PassAs<DrawQuad>()); + appendQuad(cc::DebugBorderDrawQuad::create(sharedState.get(), rect, SK_ColorRED, 1).Pass().PassAs<DrawQuad>()); + appendQuad(cc::IOSurfaceDrawQuad::create(sharedState.get(), rect, gfx::Size(50, 50), 1, cc::IOSurfaceDrawQuad::Flipped).PassAs<DrawQuad>()); + + cc::RenderPass::Id passId(1, 1); + appendQuad(cc::RenderPassDrawQuad::create(sharedState.get(), rect, passId, false, 0, rect, 0, 0, 0, 0).PassAs<DrawQuad>()); + + appendQuad(cc::SolidColorDrawQuad::create(sharedState.get(), rect, SK_ColorRED).PassAs<DrawQuad>()); + appendQuad(cc::StreamVideoDrawQuad::create(sharedState.get(), rect, 1, WebKit::WebTransformationMatrix()).PassAs<DrawQuad>()); + appendQuad(cc::TextureDrawQuad::create(sharedState.get(), rect, textureResource, false, rect, false).PassAs<DrawQuad>()); + + appendQuad(cc::TileDrawQuad::create(sharedState.get(), rect, rect, textureResource, gfx::Vector2d(), gfx::Size(100, 100), GL_LINEAR, false, false, false, false, false).PassAs<DrawQuad>()); + + cc::VideoLayerImpl::FramePlane planes[3]; + for (int i = 0; i < 3; ++i) { + planes[i].resourceId = resourceProvider->createResourceFromExternalTexture(1); + planes[i].size = gfx::Size(100, 100); + planes[i].format = GL_LUMINANCE; + } + appendQuad(cc::YUVVideoDrawQuad::create(sharedState.get(), rect, gfx::Size(100, 100), planes[0], planes[1], planes[2]).PassAs<DrawQuad>()); + appendSharedQuadState(sharedState.Pass()); +} + +} // namespace WebKitTests diff --git a/cc/test/render_pass_test_common.h b/cc/test/render_pass_test_common.h index a77747e5..dede7e6 100644 --- a/cc/test/render_pass_test_common.h +++ b/cc/test/render_pass_test_common.h @@ -7,6 +7,10 @@ #include "cc/render_pass.h" +namespace cc { +class ResourceProvider; +} + namespace WebKitTests { class TestRenderPass : public cc::RenderPass { @@ -21,6 +25,8 @@ public: void appendQuad(scoped_ptr<cc::DrawQuad> quad) { m_quadList.append(quad.Pass()); } void appendSharedQuadState(scoped_ptr<cc::SharedQuadState> state) { m_sharedQuadStateList.append(state.Pass()); } + void appendOneOfEveryQuadType(cc::ResourceProvider*); + protected: TestRenderPass(Id id, gfx::Rect outputRect, const WebKit::WebTransformationMatrix& transformToRootTarget) : RenderPass(id, outputRect, transformToRootTarget) { } |