Adding support for per vertex opacity on textured layer
BUG=165509 Review URL: https://chromiumcodereview.appspot.com/11570027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173310 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
cc
draw_quad_unittest.ccgeometry_binding.ccgl_renderer.ccgl_renderer.hgl_renderer_draw_cache.hheads_up_display_layer_impl.cclayer_tree_host_impl_unittest.ccnine_patch_layer_impl.ccscrollbar_layer_impl.ccshader.ccshader.h
test
texture_draw_quad.cctexture_draw_quad.htexture_layer.cctexture_layer.htexture_layer_impl.cctexture_layer_impl.hvideo_layer_impl.cc@ -336,22 +336,25 @@ TEST(DrawQuadTest, copyTextureDrawQuad)
|
||||
unsigned resourceId = 82;
|
||||
bool premultipliedAlpha = true;
|
||||
gfx::RectF uvRect(0.5, 224, -51, 36);
|
||||
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
bool flipped = true;
|
||||
CREATE_SHARED_STATE();
|
||||
|
||||
CREATE_QUAD_5_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvRect, flipped);
|
||||
CREATE_QUAD_6_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvRect, vertex_opacity, flipped);
|
||||
EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material);
|
||||
EXPECT_RECT_EQ(opaqueRect, copyQuad->opaque_rect);
|
||||
EXPECT_EQ(resourceId, copyQuad->resource_id);
|
||||
EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha);
|
||||
EXPECT_FLOAT_RECT_EQ(uvRect, copyQuad->uv_rect);
|
||||
EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4);
|
||||
EXPECT_EQ(flipped, copyQuad->flipped);
|
||||
|
||||
CREATE_QUAD_4_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvRect, flipped);
|
||||
CREATE_QUAD_5_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvRect, vertex_opacity, flipped);
|
||||
EXPECT_EQ(DrawQuad::TEXTURE_CONTENT, copyQuad->material);
|
||||
EXPECT_EQ(resourceId, copyQuad->resource_id);
|
||||
EXPECT_EQ(premultipliedAlpha, copyQuad->premultiplied_alpha);
|
||||
EXPECT_FLOAT_RECT_EQ(uvRect, copyQuad->uv_rect);
|
||||
EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4);
|
||||
EXPECT_EQ(flipped, copyQuad->flipped);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gf
|
||||
struct Vertex {
|
||||
float a_position[3];
|
||||
float a_texCoord[2];
|
||||
float a_index; // index into the matrix array for this quad
|
||||
float a_index; // index of the vertex, divide by 4 to have the matrix for this quad
|
||||
};
|
||||
struct Quad { Vertex v0, v1, v2, v3; };
|
||||
struct QuadIndex { uint16_t data[6]; };
|
||||
@ -36,10 +36,10 @@ GeometryBinding::GeometryBinding(WebKit::WebGraphicsContext3D* context, const gf
|
||||
Quad quad_list[8];
|
||||
QuadIndex quad_index_list[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
Vertex v0 = { quadVertexRect.x() , quadVertexRect.bottom(), 0.0f, 0.0f, 1.0f, (float)i };
|
||||
Vertex v1 = { quadVertexRect.x() , quadVertexRect.y() , 0.0f, 0.0f, 0.0f, (float)i };
|
||||
Vertex v2 = { quadVertexRect.right(), quadVertexRect.y() , 0.0f, 1.0f, 0.0f, (float)i };
|
||||
Vertex v3 = { quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f, (float)i };
|
||||
Vertex v0 = { quadVertexRect.x() , quadVertexRect.bottom(), 0.0f, 0.0f, 1.0f, i * 4.0f + 0.0f };
|
||||
Vertex v1 = { quadVertexRect.x() , quadVertexRect.y() , 0.0f, 0.0f, 0.0f, i * 4.0f + 1.0f };
|
||||
Vertex v2 = { quadVertexRect.right(), quadVertexRect.y() , 0.0f, 1.0f, 0.0f, i * 4.0f + 2.0f };
|
||||
Vertex v3 = { quadVertexRect.right(), quadVertexRect.bottom(), 0.0f, 1.0f, 1.0f, i * 4.0f + 3.0f };
|
||||
Quad x = { v0, v1, v2, v3 };
|
||||
quad_list[i] = x;
|
||||
QuadIndex y = { 0 + 4 * i, 1 + 4 * i, 2 + 4 * i, 3 + 4 * i, 0 + 4 * i, 2 + 4 * i };
|
||||
|
@ -994,8 +994,10 @@ struct TexTransformTextureProgramBinding : TextureProgramBinding {
|
||||
{
|
||||
TextureProgramBinding::set(program, context);
|
||||
texTransformLocation = program->vertexShader().texTransformLocation();
|
||||
vertexOpacityLocation = program->vertexShader().vertexOpacityLocation();
|
||||
}
|
||||
int texTransformLocation;
|
||||
int vertexOpacityLocation;
|
||||
};
|
||||
|
||||
void GLRenderer::flushTextureQuadCache()
|
||||
@ -1030,15 +1032,13 @@ void GLRenderer::flushTextureQuadCache()
|
||||
GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE));
|
||||
}
|
||||
|
||||
// Set the shader opacity.
|
||||
setShaderOpacity(m_drawCache.alpha, m_drawCache.alpha_location);
|
||||
|
||||
COMPILE_ASSERT(sizeof(Float4) == 4 * sizeof(float), struct_is_densely_packed);
|
||||
COMPILE_ASSERT(sizeof(Float16) == 16 * sizeof(float), struct_is_densely_packed);
|
||||
|
||||
// Upload the tranforms for both points and uvs.
|
||||
GLC(m_context, m_context->uniformMatrix4fv((int)m_drawCache.matrix_location, (int)m_drawCache.matrix_data.size(), false, (float*)&m_drawCache.matrix_data.front()));
|
||||
GLC(m_context, m_context->uniform4fv((int)m_drawCache.uv_xform_location, (int)m_drawCache.uv_xform_data.size(), (float*)&m_drawCache.uv_xform_data.front()));
|
||||
GLC(m_context, m_context->uniformMatrix4fv(static_cast<int>(m_drawCache.matrix_location), static_cast<int>(m_drawCache.matrix_data.size()), false, reinterpret_cast<float*>(&m_drawCache.matrix_data.front())));
|
||||
GLC(m_context, m_context->uniform4fv(static_cast<int>(m_drawCache.uv_xform_location), static_cast<int>(m_drawCache.uv_xform_data.size()), reinterpret_cast<float*>(&m_drawCache.uv_xform_data.front())));
|
||||
GLC(m_context, m_context->uniform1fv(static_cast<int>(m_drawCache.vertex_opacity_location), static_cast<int>(m_drawCache.vertex_opacity_data.size()), static_cast<float*>(&m_drawCache.vertex_opacity_data.front())));
|
||||
|
||||
// Draw the quads!
|
||||
GLC(m_context, m_context->drawElements(GL_TRIANGLES, 6 * m_drawCache.matrix_data.size(), GL_UNSIGNED_SHORT, 0));
|
||||
@ -1050,12 +1050,13 @@ void GLRenderer::flushTextureQuadCache()
|
||||
// Clear the cache.
|
||||
m_drawCache.program_id = 0;
|
||||
m_drawCache.uv_xform_data.resize(0);
|
||||
m_drawCache.vertex_opacity_data.resize(0);
|
||||
m_drawCache.matrix_data.resize(0);
|
||||
}
|
||||
|
||||
void GLRenderer::enqueueTextureQuad(const DrawingFrame& frame, const TextureDrawQuad* quad)
|
||||
{
|
||||
// Choose the correcte texture program binding
|
||||
// Choose the correct texture program binding
|
||||
TexTransformTextureProgramBinding binding;
|
||||
if (quad->flipped)
|
||||
binding.set(textureProgramFlip(), context());
|
||||
@ -1066,19 +1067,17 @@ void GLRenderer::enqueueTextureQuad(const DrawingFrame& frame, const TextureDraw
|
||||
|
||||
if (m_drawCache.program_id != binding.programId ||
|
||||
m_drawCache.resource_id != resourceID ||
|
||||
m_drawCache.alpha != quad->opacity() ||
|
||||
m_drawCache.use_premultiplied_alpha != quad->premultiplied_alpha ||
|
||||
m_drawCache.needs_blending != quad->ShouldDrawWithBlending() ||
|
||||
m_drawCache.matrix_data.size() >= 8) {
|
||||
flushTextureQuadCache();
|
||||
m_drawCache.program_id = binding.programId;
|
||||
m_drawCache.resource_id = resourceID;
|
||||
m_drawCache.alpha = quad->opacity();
|
||||
m_drawCache.use_premultiplied_alpha = quad->premultiplied_alpha;
|
||||
m_drawCache.needs_blending = quad->ShouldDrawWithBlending();
|
||||
|
||||
m_drawCache.alpha_location = binding.alphaLocation;
|
||||
m_drawCache.uv_xform_location = binding.texTransformLocation;
|
||||
m_drawCache.vertex_opacity_location = binding.vertexOpacityLocation;
|
||||
m_drawCache.matrix_location = binding.matrixLocation;
|
||||
m_drawCache.sampler_location = binding.samplerLocation;
|
||||
}
|
||||
@ -1088,6 +1087,13 @@ void GLRenderer::enqueueTextureQuad(const DrawingFrame& frame, const TextureDraw
|
||||
Float4 uv = {uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height()};
|
||||
m_drawCache.uv_xform_data.push_back(uv);
|
||||
|
||||
// Generate the vertex opacity
|
||||
const float opacity = quad->opacity();
|
||||
m_drawCache.vertex_opacity_data.push_back(quad->vertex_opacity[0] * opacity);
|
||||
m_drawCache.vertex_opacity_data.push_back(quad->vertex_opacity[1] * opacity);
|
||||
m_drawCache.vertex_opacity_data.push_back(quad->vertex_opacity[2] * opacity);
|
||||
m_drawCache.vertex_opacity_data.push_back(quad->vertex_opacity[3] * opacity);
|
||||
|
||||
// Generate the transform matrix
|
||||
gfx::Transform quadRectMatrix;
|
||||
quadRectTransform(&quadRectMatrix, quad->quadTransform(), quad->rect);
|
||||
@ -1110,6 +1116,8 @@ void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
|
||||
const gfx::RectF& uvRect = quad->uv_rect;
|
||||
GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height()));
|
||||
|
||||
GLC(context(), context()->uniform1fv(binding.vertexOpacityLocation, 4, quad->vertex_opacity));
|
||||
|
||||
ResourceProvider::ScopedSamplerGL quadResourceLock(m_resourceProvider, quad->resource_id, GL_TEXTURE_2D, GL_LINEAR);
|
||||
|
||||
if (!quad->premultiplied_alpha) {
|
||||
@ -1124,7 +1132,6 @@ void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua
|
||||
GLC(context(), context()->blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ZERO, GL_ONE));
|
||||
}
|
||||
|
||||
setShaderOpacity(quad->opacity(), binding.alphaLocation);
|
||||
drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLocation);
|
||||
|
||||
if (!quad->premultiplied_alpha)
|
||||
@ -1143,9 +1150,11 @@ void GLRenderer::drawIOSurfaceQuad(const DrawingFrame& frame, const IOSurfaceDra
|
||||
else
|
||||
GLC(context(), context()->uniform4f(binding.texTransformLocation, 0, 0, quad->io_surface_size.width(), quad->io_surface_size.height()));
|
||||
|
||||
const float vertex_opacity[] = {quad->opacity(), quad->opacity(), quad->opacity(), quad->opacity()};
|
||||
GLC(context(), context()->uniform1fv(binding.vertexOpacityLocation, 4, vertex_opacity));
|
||||
|
||||
GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, quad->io_surface_texture_id));
|
||||
|
||||
setShaderOpacity(quad->opacity(), binding.alphaLocation);
|
||||
drawQuadGeometry(frame, quad->quadTransform(), quad->rect, binding.matrixLocation);
|
||||
|
||||
GLC(context(), context()->bindTexture(GL_TEXTURE_RECTANGLE_ARB, 0));
|
||||
|
@ -163,9 +163,9 @@ private:
|
||||
typedef ProgramBinding<VertexShaderQuad, FragmentShaderRGBATexAlphaMaskAA> RenderPassMaskProgramAA;
|
||||
|
||||
// Texture shaders.
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexAlpha> TextureProgram;
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipAlpha> TextureProgramFlip;
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexRectAlpha> TextureIOSurfaceProgram;
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexVaryingAlpha> TextureProgram;
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexFlipVaryingAlpha> TextureProgramFlip;
|
||||
typedef ProgramBinding<VertexShaderPosTexTransform, FragmentShaderRGBATexRectVaryingAlpha> TextureIOSurfaceProgram;
|
||||
|
||||
// Video shaders.
|
||||
typedef ProgramBinding<VertexShaderVideoTransform, FragmentShaderOESImageExternal> VideoStreamTextureProgram;
|
||||
|
@ -24,18 +24,18 @@ struct TexturedQuadDrawCache {
|
||||
// Values tracked to determine if textured quads may be coalesced.
|
||||
int program_id;
|
||||
int resource_id;
|
||||
float alpha;
|
||||
bool use_premultiplied_alpha;
|
||||
bool needs_blending;
|
||||
|
||||
// Information about the program binding that is required to draw.
|
||||
int alpha_location;
|
||||
int uv_xform_location;
|
||||
int vertex_opacity_location;
|
||||
int matrix_location;
|
||||
int sampler_location;
|
||||
|
||||
// A cache for the coalesced quad data.
|
||||
std::vector<Float4> uv_xform_data;
|
||||
std::vector<float> vertex_opacity_data;
|
||||
std::vector<Float16> matrix_data;
|
||||
};
|
||||
|
||||
|
@ -91,9 +91,10 @@ void HeadsUpDisplayLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& a
|
||||
gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
|
||||
bool premultipliedAlpha = true;
|
||||
gfx::RectF uvRect(0, 0, 1, 1);
|
||||
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
bool flipped = false;
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_hudTexture->id(), premultipliedAlpha, uvRect, flipped);
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_hudTexture->id(), premultipliedAlpha, uvRect, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
}
|
||||
|
||||
|
@ -2775,8 +2775,9 @@ static inline scoped_ptr<RenderPass> createRenderPassWithResource(ResourceProvid
|
||||
pass->SetNew(RenderPass::Id(1, 1), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), gfx::Transform());
|
||||
scoped_ptr<SharedQuadState> sharedState = SharedQuadState::Create();
|
||||
sharedState->SetAll(gfx::Transform(), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), false, 1);
|
||||
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedState.get(), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), resourceId, false, gfx::RectF(0, 0, 1, 1), false);
|
||||
quad->SetNew(sharedState.get(), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1), resourceId, false, gfx::RectF(0, 0, 1, 1), vertex_opacity, false);
|
||||
|
||||
pass->AppendSharedQuadState(sharedState.Pass());
|
||||
pass->AppendQuad(quad.PassAs<DrawQuad>());
|
||||
@ -4273,7 +4274,7 @@ static void configureRenderPassTestData(const char* testScript, RenderPassRemova
|
||||
// Solid color draw quad
|
||||
scoped_ptr<SolidColorDrawQuad> quad = SolidColorDrawQuad::Create();
|
||||
quad->SetNew(testData.sharedQuadState.get(), gfx::Rect(0, 0, 10, 10), SK_ColorWHITE);
|
||||
|
||||
|
||||
renderPass->AppendQuad(quad.PassAs<DrawQuad>());
|
||||
currentChar++;
|
||||
} else if ((*currentChar >= 'A') && (*currentChar <= 'Z')) {
|
||||
@ -4287,7 +4288,7 @@ static void configureRenderPassTestData(const char* testScript, RenderPassRemova
|
||||
ASSERT_NE(rootRenderPassId, newRenderPassId);
|
||||
bool hasTexture = false;
|
||||
bool contentsChanged = true;
|
||||
|
||||
|
||||
if (*currentChar == '[') {
|
||||
currentChar++;
|
||||
while (*currentChar && *currentChar != ']') {
|
||||
@ -4357,7 +4358,7 @@ void dumpRenderPassTestData(const RenderPassRemovalTestData& testData, char* buf
|
||||
pos++;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
quadListIterator++;
|
||||
}
|
||||
*pos = '\n';
|
||||
@ -4459,7 +4460,7 @@ TestCase removeRenderPassesCases[] =
|
||||
"H0sssI0sss\n"
|
||||
"I0J0\n"
|
||||
"J0ssss\n",
|
||||
|
||||
|
||||
"R0sssssA0ssss\n"
|
||||
}, {
|
||||
"Wide recursion, remove all",
|
||||
@ -4474,7 +4475,7 @@ TestCase removeRenderPassesCases[] =
|
||||
"H0s\n"
|
||||
"I0s\n"
|
||||
"J0ssss\n",
|
||||
|
||||
|
||||
"R0A0B0C0D0E0F0G0H0I0J0\n"
|
||||
}, {
|
||||
"Remove passes regardless of cache state",
|
||||
@ -4695,7 +4696,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollTest(const float device
|
||||
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor));
|
||||
float pageScale = 2;
|
||||
scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize);
|
||||
// For this test we want to scrolls to move both the document and the
|
||||
// For this test we want to scrolls to move both the document and the
|
||||
// pinchZoomViewport so we can see some scroll component on the implTransform.
|
||||
root->setMaxScrollOffset(gfx::Vector2d(3, 4));
|
||||
m_hostImpl->setRootLayer(root.Pass());
|
||||
@ -4814,7 +4815,7 @@ void LayerTreeHostImplTest::pinchZoomPanViewportAndScrollBoundaryTest(const floa
|
||||
layoutSurfaceSize.height() * static_cast<int>(deviceScaleFactor));
|
||||
float pageScale = 2;
|
||||
scoped_ptr<LayerImpl> root = createScrollableLayer(1, layoutSurfaceSize);
|
||||
// For this test we want to scrolls to move both the document and the
|
||||
// For this test we want to scrolls to move both the document and the
|
||||
// pinchZoomViewport so we can see some scroll component on the implTransform.
|
||||
root->setMaxScrollOffset(gfx::Vector2d(3, 4));
|
||||
m_hostImpl->setRootLayer(root.Pass());
|
||||
|
@ -108,38 +108,39 @@ void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
|
||||
// Nothing is opaque here.
|
||||
// TODO(danakj): Should we look at the SkBitmaps to determine opaqueness?
|
||||
gfx::Rect opaqueRect;
|
||||
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
scoped_ptr<TextureDrawQuad> quad;
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, topLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvTopLeft, flipped);
|
||||
quad->SetNew(sharedQuadState, topLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvTopLeft, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, topRight, opaqueRect, m_resourceId, premultipliedAlpha, uvTopRight, flipped);
|
||||
quad->SetNew(sharedQuadState, topRight, opaqueRect, m_resourceId, premultipliedAlpha, uvTopRight, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, bottomLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomLeft, flipped);
|
||||
quad->SetNew(sharedQuadState, bottomLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomLeft, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, bottomRight, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomRight, flipped);
|
||||
quad->SetNew(sharedQuadState, bottomRight, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomRight, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, top, opaqueRect, m_resourceId, premultipliedAlpha, uvTop, flipped);
|
||||
quad->SetNew(sharedQuadState, top, opaqueRect, m_resourceId, premultipliedAlpha, uvTop, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, left, opaqueRect, m_resourceId, premultipliedAlpha, uvLeft, flipped);
|
||||
quad->SetNew(sharedQuadState, left, opaqueRect, m_resourceId, premultipliedAlpha, uvLeft, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, right, opaqueRect, m_resourceId, premultipliedAlpha, uvRight, flipped);
|
||||
quad->SetNew(sharedQuadState, right, opaqueRect, m_resourceId, premultipliedAlpha, uvRight, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
|
||||
quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, bottom, opaqueRect, m_resourceId, premultipliedAlpha, uvBottom, flipped);
|
||||
quad->SetNew(sharedQuadState, bottom, opaqueRect, m_resourceId, premultipliedAlpha, uvBottom, vertex_opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,9 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
|
||||
if (m_thumbResourceId && !thumbRect.isEmpty()) {
|
||||
gfx::Rect quadRect(scrollbarLayerRectToContentRect(thumbRect));
|
||||
gfx::Rect opaqueRect;
|
||||
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_thumbResourceId, premultipledAlpha, uvRect, flipped);
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_thumbResourceId, premultipledAlpha, uvRect, opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
}
|
||||
|
||||
@ -109,8 +110,9 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
|
||||
if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) {
|
||||
gfx::Rect quadRect(scrollbarLayerRectToContentRect(foreTrackRect));
|
||||
gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
|
||||
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_foreTrackResourceId, premultipledAlpha, toUVRect(foreTrackRect, boundsRect), flipped);
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_foreTrackResourceId, premultipledAlpha, toUVRect(foreTrackRect, boundsRect), opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
}
|
||||
|
||||
@ -119,8 +121,9 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
|
||||
if (!contentBoundsRect.IsEmpty()) {
|
||||
gfx::Rect quadRect(contentBoundsRect);
|
||||
gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
|
||||
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_backTrackResourceId, premultipledAlpha, uvRect, flipped);
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_backTrackResourceId, premultipledAlpha, uvRect, opacity, flipped);
|
||||
quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
}
|
||||
}
|
||||
|
48
cc/shader.cc
48
cc/shader.cc
@ -136,6 +136,7 @@ std::string VertexShaderPos::getShaderString() const
|
||||
VertexShaderPosTexTransform::VertexShaderPosTexTransform()
|
||||
: m_matrixLocation(-1)
|
||||
, m_texTransformLocation(-1)
|
||||
, m_vertexOpacityLocation(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -144,14 +145,16 @@ void VertexShaderPosTexTransform::init(WebGraphicsContext3D* context, unsigned p
|
||||
static const char* shaderUniforms[] = {
|
||||
"matrix",
|
||||
"texTransform",
|
||||
"opacity",
|
||||
};
|
||||
int locations[2];
|
||||
int locations[3];
|
||||
|
||||
getProgramUniformLocations(context, program, shaderUniforms, arraysize(shaderUniforms), arraysize(locations), locations, usingBindUniform, baseUniformIndex);
|
||||
|
||||
m_matrixLocation = locations[0];
|
||||
m_texTransformLocation = locations[1];
|
||||
DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1);
|
||||
m_vertexOpacityLocation = locations[2];
|
||||
DCHECK(m_matrixLocation != -1 && m_texTransformLocation != -1 && m_vertexOpacityLocation != -1);
|
||||
}
|
||||
|
||||
std::string VertexShaderPosTexTransform::getShaderString() const
|
||||
@ -162,11 +165,15 @@ std::string VertexShaderPosTexTransform::getShaderString() const
|
||||
attribute float a_index;
|
||||
uniform mat4 matrix[8];
|
||||
uniform vec4 texTransform[8];
|
||||
uniform float opacity[32];
|
||||
varying vec2 v_texCoord;
|
||||
varying float v_alpha;
|
||||
void main()
|
||||
{
|
||||
gl_Position = matrix[int(a_index)] * a_position;
|
||||
v_texCoord = a_texCoord * texTransform[int(a_index)].zw + texTransform[int(a_index)].xy;
|
||||
gl_Position = matrix[int(a_index * 0.25)] * a_position;
|
||||
vec4 texTrans = texTransform[int(a_index * 0.25)];
|
||||
v_texCoord = a_texCoord * texTrans.zw + texTrans.xy;
|
||||
v_alpha = opacity[int(a_index)];
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -356,17 +363,17 @@ void FragmentTexOpaqueBinding::init(WebGraphicsContext3D* context, unsigned prog
|
||||
DCHECK(m_samplerLocation != -1);
|
||||
}
|
||||
|
||||
std::string FragmentShaderRGBATexFlipAlpha::getShaderString() const
|
||||
std::string FragmentShaderRGBATexFlipVaryingAlpha::getShaderString() const
|
||||
{
|
||||
return SHADER(
|
||||
precision mediump float;
|
||||
varying vec2 v_texCoord;
|
||||
varying float v_alpha;
|
||||
uniform sampler2D s_texture;
|
||||
uniform float alpha;
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture2D(s_texture, vec2(v_texCoord.x, 1.0 - v_texCoord.y));
|
||||
gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha;
|
||||
gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha;
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -413,34 +420,49 @@ std::string FragmentShaderRGBATexAlpha::getShaderString() const
|
||||
);
|
||||
}
|
||||
|
||||
std::string FragmentShaderRGBATexRectFlipAlpha::getShaderString() const
|
||||
std::string FragmentShaderRGBATexVaryingAlpha::getShaderString() const
|
||||
{
|
||||
return SHADER(
|
||||
precision mediump float;
|
||||
varying vec2 v_texCoord;
|
||||
varying float v_alpha;
|
||||
uniform sampler2D s_texture;
|
||||
void main()
|
||||
{
|
||||
vec4 texColor = texture2D(s_texture, v_texCoord);
|
||||
gl_FragColor = texColor * v_alpha;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::string FragmentShaderRGBATexRectFlipVaryingAlpha::getShaderString() const
|
||||
{
|
||||
// This must be paired with VertexShaderPosTexTransform to pick up the texTransform uniform.
|
||||
// The necessary #extension preprocessing directive breaks the SHADER and SHADER0 macros.
|
||||
return "#extension GL_ARB_texture_rectangle : require\n"
|
||||
"precision mediump float;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"varying float v_alpha;\n"
|
||||
"uniform vec4 texTransform;\n"
|
||||
"uniform sampler2DRect s_texture;\n"
|
||||
"uniform float alpha;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 texColor = texture2DRect(s_texture, vec2(v_texCoord.x, texTransform.w - v_texCoord.y));\n"
|
||||
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * alpha;\n"
|
||||
" gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w) * v_alpha;\n"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
std::string FragmentShaderRGBATexRectAlpha::getShaderString() const
|
||||
std::string FragmentShaderRGBATexRectVaryingAlpha::getShaderString() const
|
||||
{
|
||||
return "#extension GL_ARB_texture_rectangle : require\n"
|
||||
"precision mediump float;\n"
|
||||
"varying vec2 v_texCoord;\n"
|
||||
"varying float v_alpha;\n"
|
||||
"uniform sampler2DRect s_texture;\n"
|
||||
"uniform float alpha;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 texColor = texture2DRect(s_texture, v_texCoord);\n"
|
||||
" gl_FragColor = texColor * alpha;\n"
|
||||
" gl_FragColor = texColor * v_alpha;\n"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
|
13
cc/shader.h
13
cc/shader.h
@ -70,10 +70,12 @@ public:
|
||||
|
||||
int matrixLocation() const { return m_matrixLocation; }
|
||||
int texTransformLocation() const { return m_texTransformLocation; }
|
||||
int vertexOpacityLocation() const { return m_vertexOpacityLocation; }
|
||||
|
||||
private:
|
||||
int m_matrixLocation;
|
||||
int m_texTransformLocation;
|
||||
int m_vertexOpacityLocation;
|
||||
};
|
||||
|
||||
class VertexShaderQuad {
|
||||
@ -154,7 +156,12 @@ private:
|
||||
int m_samplerLocation;
|
||||
};
|
||||
|
||||
class FragmentShaderRGBATexFlipAlpha : public FragmentTexAlphaBinding {
|
||||
class FragmentShaderRGBATexFlipVaryingAlpha : public FragmentTexOpaqueBinding {
|
||||
public:
|
||||
std::string getShaderString() const;
|
||||
};
|
||||
|
||||
class FragmentShaderRGBATexVaryingAlpha : public FragmentTexOpaqueBinding {
|
||||
public:
|
||||
std::string getShaderString() const;
|
||||
};
|
||||
@ -164,12 +171,12 @@ public:
|
||||
std::string getShaderString() const;
|
||||
};
|
||||
|
||||
class FragmentShaderRGBATexRectFlipAlpha : public FragmentTexAlphaBinding {
|
||||
class FragmentShaderRGBATexRectFlipVaryingAlpha : public FragmentTexAlphaBinding {
|
||||
public:
|
||||
std::string getShaderString() const;
|
||||
};
|
||||
|
||||
class FragmentShaderRGBATexRectAlpha : public FragmentTexAlphaBinding {
|
||||
class FragmentShaderRGBATexRectVaryingAlpha : public FragmentTexAlphaBinding {
|
||||
public:
|
||||
std::string getShaderString() const;
|
||||
};
|
||||
|
@ -50,6 +50,13 @@ do { \
|
||||
EXPECT_EQ((expected).y(), (actual).y()); \
|
||||
} while (false)
|
||||
|
||||
#define EXPECT_FLOAT_ARRAY_EQ(expected, actual, count) \
|
||||
do { \
|
||||
for (int i = 0; i < count; i++) {\
|
||||
EXPECT_FLOAT_EQ((expected)[i], (actual)[i]); \
|
||||
}\
|
||||
} while (false)
|
||||
|
||||
// This is a function rather than a macro because when this is included as a macro
|
||||
// in bulk, it causes a significant slow-down in compilation time. This problem
|
||||
// exists with both gcc and clang, and bugs have been filed at
|
||||
|
@ -24,6 +24,7 @@ using cc::DrawQuad;
|
||||
void TestRenderPass::AppendOneOfEveryQuadType(cc::ResourceProvider* resourceProvider) {
|
||||
gfx::Rect rect(0, 0, 100, 100);
|
||||
gfx::Rect opaque_rect(10, 10, 80, 80);
|
||||
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
cc::ResourceProvider::ResourceId texture_resource =
|
||||
resourceProvider->createResourceFromExternalTexture(1);
|
||||
scoped_ptr<cc::SharedQuadState> shared_state = cc::SharedQuadState::Create();
|
||||
@ -94,6 +95,7 @@ void TestRenderPass::AppendOneOfEveryQuadType(cc::ResourceProvider* resourceProv
|
||||
texture_resource,
|
||||
false,
|
||||
rect,
|
||||
vertex_opacity,
|
||||
false);
|
||||
AppendQuad(texture_quad.PassAs<DrawQuad>());
|
||||
|
||||
|
@ -19,41 +19,44 @@ scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() {
|
||||
}
|
||||
|
||||
void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state,
|
||||
gfx::Rect rect,
|
||||
gfx::Rect opaque_rect,
|
||||
unsigned resource_id,
|
||||
bool premultiplied_alpha,
|
||||
gfx::Rect rect, gfx::Rect opaque_rect,
|
||||
unsigned resource_id, bool premultiplied_alpha,
|
||||
const gfx::RectF& uv_rect,
|
||||
bool flipped) {
|
||||
const float vertex_opacity[4], bool flipped) {
|
||||
gfx::Rect visible_rect = rect;
|
||||
bool needs_blending = false;
|
||||
bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f
|
||||
|| vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f;
|
||||
DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
|
||||
opaque_rect, visible_rect, needs_blending);
|
||||
this->resource_id = resource_id;
|
||||
this->premultiplied_alpha = premultiplied_alpha;
|
||||
this->uv_rect = uv_rect;
|
||||
this->vertex_opacity[0] = vertex_opacity[0];
|
||||
this->vertex_opacity[1] = vertex_opacity[1];
|
||||
this->vertex_opacity[2] = vertex_opacity[2];
|
||||
this->vertex_opacity[3] = vertex_opacity[3];
|
||||
this->flipped = flipped;
|
||||
}
|
||||
|
||||
void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
|
||||
gfx::Rect rect,
|
||||
gfx::Rect opaque_rect,
|
||||
gfx::Rect visible_rect,
|
||||
bool needs_blending,
|
||||
unsigned resource_id,
|
||||
bool premultiplied_alpha,
|
||||
gfx::Rect rect, gfx::Rect opaque_rect,
|
||||
gfx::Rect visible_rect, bool needs_blending,
|
||||
unsigned resource_id, bool premultiplied_alpha,
|
||||
const gfx::RectF& uv_rect,
|
||||
bool flipped) {
|
||||
const float vertex_opacity[4], bool flipped) {
|
||||
DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
|
||||
opaque_rect, visible_rect, needs_blending);
|
||||
this->resource_id = resource_id;
|
||||
this->premultiplied_alpha = premultiplied_alpha;
|
||||
this->uv_rect = uv_rect;
|
||||
this->vertex_opacity[0] = vertex_opacity[0];
|
||||
this->vertex_opacity[1] = vertex_opacity[1];
|
||||
this->vertex_opacity[2] = vertex_opacity[2];
|
||||
this->vertex_opacity[3] = vertex_opacity[3];
|
||||
this->flipped = flipped;
|
||||
}
|
||||
|
||||
const TextureDrawQuad* TextureDrawQuad::MaterialCast(
|
||||
const DrawQuad* quad) {
|
||||
const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) {
|
||||
DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT);
|
||||
return static_cast<const TextureDrawQuad*>(quad);
|
||||
}
|
||||
@ -65,15 +68,14 @@ bool TextureDrawQuad::PerformClipping() {
|
||||
return false;
|
||||
|
||||
// Grab our scale and make sure it's positive.
|
||||
float x_scale = quadTransform().matrix().getDouble(0,0);
|
||||
float y_scale = quadTransform().matrix().getDouble(1,1);
|
||||
float x_scale = quadTransform().matrix().getDouble(0, 0);
|
||||
float y_scale = quadTransform().matrix().getDouble(1, 1);
|
||||
if (x_scale <= 0.0f || y_scale <= 0.0f)
|
||||
return false;
|
||||
|
||||
// Grab our offset.
|
||||
gfx::Vector2dF offset(
|
||||
quadTransform().matrix().getDouble(0,3),
|
||||
quadTransform().matrix().getDouble(1,3));
|
||||
gfx::Vector2dF offset(quadTransform().matrix().getDouble(0, 3),
|
||||
quadTransform().matrix().getDouble(1, 3));
|
||||
|
||||
// Transform the rect by the scale and offset.
|
||||
gfx::RectF rectF = rect;
|
||||
@ -90,19 +92,41 @@ bool TextureDrawQuad::PerformClipping() {
|
||||
|
||||
// Create a new uv-rect by clipping the old one to the new bounds.
|
||||
uv_rect = gfx::RectF(
|
||||
uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()),
|
||||
uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()),
|
||||
uv_rect.width () / rectF.width () * clippedRect.width (),
|
||||
uv_rect.x()
|
||||
+ uv_rect.width() / rectF.width() * (clippedRect.x() - rectF.x()),
|
||||
uv_rect.y()
|
||||
+ uv_rect.height() / rectF.height() * (clippedRect.y() - rectF.y()),
|
||||
uv_rect.width() / rectF.width() * clippedRect.width(),
|
||||
uv_rect.height() / rectF.height() * clippedRect.height());
|
||||
|
||||
// Indexing according to the quad vertex generation:
|
||||
// 1--2
|
||||
// | |
|
||||
// 0--3
|
||||
if (vertex_opacity[0] != vertex_opacity[1]
|
||||
|| vertex_opacity[0] != vertex_opacity[2]
|
||||
|| vertex_opacity[0] != vertex_opacity[3]) {
|
||||
const float x1 = (clippedRect.x() - rectF.x()) / rectF.width();
|
||||
const float y1 = (clippedRect.y() - rectF.y()) / rectF.height();
|
||||
const float x3 = (clippedRect.right() - rectF.x()) / rectF.width();
|
||||
const float y3 = (clippedRect.bottom() - rectF.y()) / rectF.height();
|
||||
const float x1y1 = x1 * vertex_opacity[2] + (1.0f - x1) * vertex_opacity[1];
|
||||
const float x1y3 = x1 * vertex_opacity[3] + (1.0f - x1) * vertex_opacity[0];
|
||||
const float x3y1 = x3 * vertex_opacity[2] + (1.0f - x3) * vertex_opacity[1];
|
||||
const float x3y3 = x3 * vertex_opacity[3] + (1.0f - x3) * vertex_opacity[0];
|
||||
vertex_opacity[0] = y3 * x1y3 + (1.0f - y3) * x1y1;
|
||||
vertex_opacity[1] = y1 * x1y3 + (1.0f - y1) * x1y1;
|
||||
vertex_opacity[2] = y1 * x3y3 + (1.0f - y1) * x3y1;
|
||||
vertex_opacity[3] = y3 * x3y3 + (1.0f - y3) * x3y1;
|
||||
}
|
||||
|
||||
// Move the clipped rectangle back into its space.
|
||||
clippedRect -= offset;
|
||||
clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale);
|
||||
rect = gfx::Rect(
|
||||
static_cast<int>(clippedRect.x() + 0.5f),
|
||||
static_cast<int>(clippedRect.y() + 0.5f),
|
||||
static_cast<int>(clippedRect.width() + 0.5f),
|
||||
static_cast<int>(clippedRect.height() + 0.5f));
|
||||
rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f),
|
||||
static_cast<int>(clippedRect.y() + 0.5f),
|
||||
static_cast<int>(clippedRect.width() + 0.5f),
|
||||
static_cast<int>(clippedRect.height() + 0.5f));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad {
|
||||
unsigned resource_id,
|
||||
bool premultiplied_alpha,
|
||||
const gfx::RectF& uv_rect,
|
||||
const float vertex_opacity[4],
|
||||
bool flipped);
|
||||
|
||||
void SetAll(const SharedQuadState* shared_quad_state,
|
||||
@ -32,11 +33,13 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad {
|
||||
unsigned resource_id,
|
||||
bool premultiplied_alpha,
|
||||
const gfx::RectF& uv_rect,
|
||||
const float vertex_opacity[4],
|
||||
bool flipped);
|
||||
|
||||
unsigned resource_id;
|
||||
bool premultiplied_alpha;
|
||||
gfx::RectF uv_rect;
|
||||
float vertex_opacity[4];
|
||||
bool flipped;
|
||||
|
||||
static const TextureDrawQuad* MaterialCast(const DrawQuad*);
|
||||
|
@ -28,6 +28,10 @@ TextureLayer::TextureLayer(TextureLayerClient* client)
|
||||
, m_textureId(0)
|
||||
, m_contentCommitted(false)
|
||||
{
|
||||
m_vertexOpacity[0] = 1.0f;
|
||||
m_vertexOpacity[1] = 1.0f;
|
||||
m_vertexOpacity[2] = 1.0f;
|
||||
m_vertexOpacity[3] = 1.0f;
|
||||
}
|
||||
|
||||
TextureLayer::~TextureLayer()
|
||||
@ -57,6 +61,21 @@ void TextureLayer::setUVRect(const gfx::RectF& rect)
|
||||
setNeedsCommit();
|
||||
}
|
||||
|
||||
void TextureLayer::setVertexOpacity(float bottomLeft,
|
||||
float topLeft,
|
||||
float topRight,
|
||||
float bottomRight) {
|
||||
// Indexing according to the quad vertex generation:
|
||||
// 1--2
|
||||
// | |
|
||||
// 0--3
|
||||
m_vertexOpacity[0] = bottomLeft;
|
||||
m_vertexOpacity[1] = topLeft;
|
||||
m_vertexOpacity[2] = topRight;
|
||||
m_vertexOpacity[3] = bottomRight;
|
||||
setNeedsCommit();
|
||||
}
|
||||
|
||||
void TextureLayer::setPremultipliedAlpha(bool premultipliedAlpha)
|
||||
{
|
||||
m_premultipliedAlpha = premultipliedAlpha;
|
||||
@ -126,6 +145,7 @@ void TextureLayer::pushPropertiesTo(LayerImpl* layer)
|
||||
TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer);
|
||||
textureLayer->setFlipped(m_flipped);
|
||||
textureLayer->setUVRect(m_uvRect);
|
||||
textureLayer->setVertexOpacity(m_vertexOpacity);
|
||||
textureLayer->setPremultipliedAlpha(m_premultipliedAlpha);
|
||||
textureLayer->setTextureId(m_textureId);
|
||||
m_contentCommitted = drawsContent();
|
||||
|
@ -34,6 +34,9 @@ public:
|
||||
// Sets a UV transform to be used at draw time. Defaults to (0, 0, 1, 1).
|
||||
void setUVRect(const gfx::RectF&);
|
||||
|
||||
// Sets an opacity value per vertex. It will be multiplied by the layer opacity value.
|
||||
void setVertexOpacity(float bottomLeft, float topLeft, float topRight, float bottomRight);
|
||||
|
||||
// Sets whether the alpha channel is premultiplied or unpremultiplied. Defaults to true.
|
||||
void setPremultipliedAlpha(bool);
|
||||
|
||||
@ -64,6 +67,8 @@ private:
|
||||
|
||||
bool m_flipped;
|
||||
gfx::RectF m_uvRect;
|
||||
// [bottom left, top left, top right, bottom right]
|
||||
float m_vertexOpacity[4];
|
||||
bool m_premultipliedAlpha;
|
||||
bool m_rateLimitContext;
|
||||
bool m_contextLost;
|
||||
|
@ -19,6 +19,10 @@ TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* treeImpl, int id)
|
||||
, m_flipped(true)
|
||||
, m_uvRect(0, 0, 1, 1)
|
||||
{
|
||||
m_vertexOpacity[0] = 1.0f;
|
||||
m_vertexOpacity[1] = 1.0f;
|
||||
m_vertexOpacity[2] = 1.0f;
|
||||
m_vertexOpacity[3] = 1.0f;
|
||||
}
|
||||
|
||||
TextureLayerImpl::~TextureLayerImpl()
|
||||
@ -44,7 +48,7 @@ void TextureLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQu
|
||||
gfx::Rect quadRect(gfx::Point(), contentBounds());
|
||||
gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect());
|
||||
scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create();
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, m_premultipliedAlpha, m_uvRect, m_flipped);
|
||||
quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, m_premultipliedAlpha, m_uvRect, m_vertexOpacity, m_flipped);
|
||||
|
||||
// Perform explicit clipping on a quad to avoid setting a scissor later.
|
||||
if (sharedQuadState->is_clipped && quad->PerformClipping())
|
||||
@ -72,6 +76,13 @@ void TextureLayerImpl::dumpLayerProperties(std::string* str, int indent) const
|
||||
LayerImpl::dumpLayerProperties(str, indent);
|
||||
}
|
||||
|
||||
void TextureLayerImpl::setVertexOpacity(const float vertexOpacity[4]) {
|
||||
m_vertexOpacity[0] = vertexOpacity[0];
|
||||
m_vertexOpacity[1] = vertexOpacity[1];
|
||||
m_vertexOpacity[2] = vertexOpacity[2];
|
||||
m_vertexOpacity[3] = vertexOpacity[3];
|
||||
}
|
||||
|
||||
void TextureLayerImpl::didLoseOutputSurface()
|
||||
{
|
||||
m_textureId = 0;
|
||||
|
@ -32,6 +32,11 @@ public:
|
||||
void setFlipped(bool flipped) { m_flipped = flipped; }
|
||||
void setUVRect(const gfx::RectF& rect) { m_uvRect = rect; }
|
||||
|
||||
// 1--2
|
||||
// | |
|
||||
// 0--3
|
||||
void setVertexOpacity(const float vertexOpacity[4]);
|
||||
|
||||
private:
|
||||
TextureLayerImpl(LayerTreeImpl* treeImpl, int id);
|
||||
|
||||
@ -42,6 +47,7 @@ private:
|
||||
bool m_premultipliedAlpha;
|
||||
bool m_flipped;
|
||||
gfx::RectF m_uvRect;
|
||||
float m_vertexOpacity[4];
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -229,9 +229,10 @@ void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
|
||||
const FramePlane& plane = m_framePlanes[media::VideoFrame::kRGBPlane];
|
||||
bool premultipliedAlpha = true;
|
||||
gfx::RectF uvRect(0, 0, texWidthScale, texHeightScale);
|
||||
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
bool flipped = false;
|
||||
scoped_ptr<TextureDrawQuad> textureQuad = TextureDrawQuad::Create();
|
||||
textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, plane.resourceId, premultipliedAlpha, uvRect, flipped);
|
||||
textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, plane.resourceId, premultipliedAlpha, uvRect, opacity, flipped);
|
||||
quadSink.append(textureQuad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
break;
|
||||
}
|
||||
@ -239,9 +240,10 @@ void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad
|
||||
// NativeTexture hardware decoder.
|
||||
bool premultipliedAlpha = true;
|
||||
gfx::RectF uvRect(0, 0, texWidthScale, texHeightScale);
|
||||
const float opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
bool flipped = false;
|
||||
scoped_ptr<TextureDrawQuad> textureQuad = TextureDrawQuad::Create();
|
||||
textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, premultipliedAlpha, uvRect, flipped);
|
||||
textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, premultipliedAlpha, uvRect, opacity, flipped);
|
||||
quadSink.append(textureQuad.PassAs<DrawQuad>(), appendQuadsData);
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user