0

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
This commit is contained in:
jamesr@chromium.org
2012-11-10 01:32:53 +00:00
parent c0d02ed51a
commit 8e26f1db0f
6 changed files with 121 additions and 10 deletions

@ -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',

@ -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) {

@ -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));

@ -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

@ -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

@ -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) { }