From 8e26f1db0f6923fd3ecb87853ecbd97567a9ab29 Mon Sep 17 00:00:00 2001 From: "jamesr@chromium.org" Date: Sat, 10 Nov 2012 01:32:53 +0000 Subject: Avoid setting activeTexture redundantly We use GL_TEXTURE0 for nearly all operations, so it's cheaper to leave this as the default for all draws and have quads that use other texture units reset to 0. BUG= Review URL: https://chromiumcodereview.appspot.com/11275222 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167030 0039d316-1c4b-4281-b951-d872f2087c98 --- cc/gl_renderer_unittest.cc | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'cc/gl_renderer_unittest.cc') 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 outputSurface(FakeWebCompositorOutputSurface::create(scoped_ptr(new ActiveTextureTrackingContext))); + ActiveTextureTrackingContext* context = static_cast(outputSurface->context3D()); + scoped_ptr resourceProvider(ResourceProvider::create(outputSurface.get())); + FakeRendererGL renderer(&fakeClient, resourceProvider.get()); + + EXPECT_TRUE(renderer.initialize()); + + cc::RenderPass::Id id(1, 1); + scoped_ptr 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 -- cgit v1.1