Index: cc/texture_draw_quad.cc |
diff --git a/cc/texture_draw_quad.cc b/cc/texture_draw_quad.cc |
index 5ad73b69dc28731925dcf31518cd61148feedc72..adce50fb648676c5c6c4637da6b047e79e3e2092 100644 |
--- a/cc/texture_draw_quad.cc |
+++ b/cc/texture_draw_quad.cc |
@@ -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; |
} |