diff options
-rw-r--r-- | cc/draw_quad_unittest.cc | 81 | ||||
-rw-r--r-- | cc/gl_renderer.cc | 10 | ||||
-rw-r--r-- | cc/heads_up_display_layer_impl.cc | 7 | ||||
-rw-r--r-- | cc/nine_patch_layer_impl.cc | 16 | ||||
-rw-r--r-- | cc/nine_patch_layer_impl_unittest.cc | 4 | ||||
-rw-r--r-- | cc/scrollbar_layer_impl.cc | 10 | ||||
-rw-r--r-- | cc/software_renderer.cc | 4 | ||||
-rw-r--r-- | cc/test/render_pass_test_common.cc | 3 | ||||
-rw-r--r-- | cc/texture_draw_quad.cc | 35 | ||||
-rw-r--r-- | cc/texture_draw_quad.h | 9 | ||||
-rw-r--r-- | cc/texture_layer.cc | 11 | ||||
-rw-r--r-- | cc/texture_layer.h | 7 | ||||
-rw-r--r-- | cc/texture_layer_impl.cc | 5 | ||||
-rw-r--r-- | cc/texture_layer_impl.h | 6 | ||||
-rw-r--r-- | cc/video_layer_impl.cc | 10 | ||||
-rw-r--r-- | content/common/cc_messages.h | 3 | ||||
-rw-r--r-- | content/common/cc_messages_unittest.cc | 3 | ||||
-rw-r--r-- | content/renderer/browser_plugin/browser_plugin_compositing_helper.cc | 2 | ||||
-rw-r--r-- | ui/compositor/layer.cc | 7 | ||||
-rw-r--r-- | ui/gfx/size_base_impl.h | 7 | ||||
-rw-r--r-- | webkit/compositor_bindings/web_external_texture_layer_impl.cc | 2 |
21 files changed, 169 insertions, 73 deletions
diff --git a/cc/draw_quad_unittest.cc b/cc/draw_quad_unittest.cc index 41e1d2e..bd02ccf 100644 --- a/cc/draw_quad_unittest.cc +++ b/cc/draw_quad_unittest.cc @@ -362,29 +362,100 @@ TEST(DrawQuadTest, copyTextureDrawQuad) gfx::Rect opaqueRect(3, 7, 10, 12); unsigned resourceId = 82; bool premultipliedAlpha = true; - gfx::RectF uvRect(0.5f, 224.f, 51.f, 36.f); + gfx::PointF uvTopLeft(0.5f, 224.f); + gfx::PointF uvBottomRight(51.5f, 260.f); const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; bool flipped = true; CREATE_SHARED_STATE(); - CREATE_QUAD_6_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvRect, vertex_opacity, flipped); + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, 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_EQ(uvTopLeft, copyQuad->uv_top_left); + EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right); EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); EXPECT_EQ(flipped, copyQuad->flipped); - CREATE_QUAD_5_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvRect, vertex_opacity, flipped); + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, 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_EQ(uvTopLeft, copyQuad->uv_top_left); + EXPECT_EQ(uvBottomRight, copyQuad->uv_bottom_right); EXPECT_FLOAT_ARRAY_EQ(vertex_opacity, copyQuad->vertex_opacity, 4); EXPECT_EQ(flipped, copyQuad->flipped); } +TEST(DrawQuadTest, clipTextureDrawQuad) +{ + gfx::Rect opaqueRect(3, 7, 10, 12); + unsigned resourceId = 82; + bool premultipliedAlpha = true; + bool flipped = true; + CREATE_SHARED_STATE(); + // The original quad position is (30, 40) its size is 50*60. + sharedState->content_to_target_transform = gfx::Transform(1.f, 0.f, 0.f, 1.f, 10.f, 20.f); + // After transformation, the quad position is (40, 60) its size is 50*60. + sharedState->clip_rect = gfx::Rect(50, 70, 30, 20); + + // The original quad is 'ABCD', the clipped quad is 'abcd': + //40 50 90 + // B--:-------C 60 + // | b----c -|-70 + // | | | | + // | a----d -|-90 + // | | + // A----------D 120 + // UV and vertex opacity are stored per vertex on the parent rectangle 'ABCD'. + + // This is the UV value for vertex 'B'. + gfx::PointF uvTopLeft(0.1f, 0.2f); + // This is the UV value for vertex 'D'. + gfx::PointF uvBottomRight(0.9f, 0.8f); + // This the vertex opacity for the vertices 'ABCD'. + const float vertexOpacity[] = {0.3f, 0.4f, 0.7f, 0.8f}; + + { + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + EXPECT_TRUE(quadAll->PerformClipping()); + + // This is the expected UV value for vertex 'b'. + // uv(b) = uv(B) + (Bb / BD) * (uv(D) - uv(B)) + // 0.3 = 0.2 + (10 / 60) * (0.8 - 0.2) + gfx::PointF uvTopLeftClipped(0.26f, 0.3f); + // This is the expected UV value for vertex 'd'. + // uv(d) = uv(B) + (Bd / BD) * (uv(D) - uv(B)) + gfx::PointF uvBottomRightClipped(0.74f, 0.5f); + // This the expected vertex opacity for the vertices 'abcd'. + // They are computed with a bilinear interpolation of the corner values. + const float vertexOpacityClipped[] = {0.43f, 0.45f, 0.65f, 0.67f}; + + EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left); + EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right); + EXPECT_FLOAT_ARRAY_EQ(vertexOpacityClipped, quadAll->vertex_opacity, 4); + } + + uvTopLeft = gfx::PointF(0.8f, 0.7f); + uvBottomRight = gfx::PointF(0.2f, 0.1f); + + { + CREATE_QUAD_7_NEW(TextureDrawQuad, opaqueRect, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + CREATE_QUAD_6_ALL(TextureDrawQuad, resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, vertexOpacity, flipped); + EXPECT_TRUE(quadAll->PerformClipping()); + + // This is the expected UV value for vertex 'b'. + gfx::PointF uvTopLeftClipped(0.68f, 0.6f); + // This is the expected UV value for vertex 'd'. + gfx::PointF uvBottomRightClipped(0.32f, 0.4f); + + EXPECT_EQ(uvTopLeftClipped, quadAll->uv_top_left); + EXPECT_EQ(uvBottomRightClipped, quadAll->uv_bottom_right); + } +} + TEST(DrawQuadTest, copyTileDrawQuad) { gfx::Rect opaqueRect(33, 44, 22, 33); diff --git a/cc/gl_renderer.cc b/cc/gl_renderer.cc index 9bb2fde..219d60f 100644 --- a/cc/gl_renderer.cc +++ b/cc/gl_renderer.cc @@ -1087,8 +1087,9 @@ void GLRenderer::enqueueTextureQuad(const DrawingFrame& frame, const TextureDraw } // Generate the uv-transform - const gfx::RectF& uvRect = quad->uv_rect; - Float4 uv = {uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height()}; + const gfx::PointF& uv0 = quad->uv_top_left; + const gfx::PointF& uv1 = quad->uv_bottom_right; + Float4 uv = {uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}; m_drawCache.uv_xform_data.push_back(uv); // Generate the vertex opacity @@ -1117,8 +1118,9 @@ void GLRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureDrawQua binding.set(textureProgram(), context()); setUseProgram(binding.programId); GLC(context(), context()->uniform1i(binding.samplerLocation, 0)); - const gfx::RectF& uvRect = quad->uv_rect; - GLC(context(), context()->uniform4f(binding.texTransformLocation, uvRect.x(), uvRect.y(), uvRect.width(), uvRect.height())); + const gfx::PointF& uv0 = quad->uv_top_left; + const gfx::PointF& uv1 = quad->uv_bottom_right; + GLC(context(), context()->uniform4f(binding.texTransformLocation, uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y())); GLC(context(), context()->uniform1fv(binding.vertexOpacityLocation, 4, quad->vertex_opacity)); diff --git a/cc/heads_up_display_layer_impl.cc b/cc/heads_up_display_layer_impl.cc index 1902296..5dbe328 100644 --- a/cc/heads_up_display_layer_impl.cc +++ b/cc/heads_up_display_layer_impl.cc @@ -98,11 +98,12 @@ void HeadsUpDisplayLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& a gfx::Rect quadRect(gfx::Point(), bounds()); 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}; + gfx::PointF uv_top_left(0.f, 0.f); + gfx::PointF uv_bottom_right(1.f, 1.f); + const float vertex_opacity[] = {1.f, 1.f, 1.f, 1.f}; bool flipped = false; scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_hudTexture->id(), premultipliedAlpha, uvRect, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_hudTexture->id(), premultipliedAlpha, uv_top_left, uv_bottom_right, vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); } diff --git a/cc/nine_patch_layer_impl.cc b/cc/nine_patch_layer_impl.cc index 8b5415b..85ae221 100644 --- a/cc/nine_patch_layer_impl.cc +++ b/cc/nine_patch_layer_impl.cc @@ -112,35 +112,35 @@ void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append scoped_ptr<TextureDrawQuad> quad; quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, topLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvTopLeft, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, topLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvTopLeft.origin(), uvTopLeft.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, topRight, opaqueRect, m_resourceId, premultipliedAlpha, uvTopRight, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, topRight, opaqueRect, m_resourceId, premultipliedAlpha, uvTopRight.origin(), uvTopRight.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, bottomLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomLeft, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, bottomLeft, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomLeft.origin(), uvBottomLeft.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, bottomRight, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomRight, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, bottomRight, opaqueRect, m_resourceId, premultipliedAlpha, uvBottomRight.origin(), uvBottomRight.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, top, opaqueRect, m_resourceId, premultipliedAlpha, uvTop, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, top, opaqueRect, m_resourceId, premultipliedAlpha, uvTop.origin(), uvTop.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, left, opaqueRect, m_resourceId, premultipliedAlpha, uvLeft, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, left, opaqueRect, m_resourceId, premultipliedAlpha, uvLeft.origin(), uvLeft.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, right, opaqueRect, m_resourceId, premultipliedAlpha, uvRight, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, right, opaqueRect, m_resourceId, premultipliedAlpha, uvRight.origin(), uvRight.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); quad = TextureDrawQuad::Create(); - quad->SetNew(sharedQuadState, bottom, opaqueRect, m_resourceId, premultipliedAlpha, uvBottom, vertex_opacity, flipped); + quad->SetNew(sharedQuadState, bottom, opaqueRect, m_resourceId, premultipliedAlpha, uvBottom.origin(), uvBottom.bottom_right(), vertex_opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); } diff --git a/cc/nine_patch_layer_impl_unittest.cc b/cc/nine_patch_layer_impl_unittest.cc index aa9bc01..fbf765b 100644 --- a/cc/nine_patch_layer_impl_unittest.cc +++ b/cc/nine_patch_layer_impl_unittest.cc @@ -82,7 +82,7 @@ TEST(NinePatchLayerImplTest, verifyDrawQuads) for (size_t i = 0; i < quads.size(); ++i) { DrawQuad* quad = quads[i]; const TextureDrawQuad* texQuad = TextureDrawQuad::MaterialCast(quad); - gfx::RectF texRect = texQuad->uv_rect; + gfx::RectF texRect = gfx::BoundingRect(texQuad->uv_top_left, texQuad->uv_bottom_right); texRect.Scale(bitmapSize.width(), bitmapSize.height()); texRemaining.Subtract(Region(ToRoundedIntRect(texRect))); } @@ -135,7 +135,7 @@ TEST(NinePatchLayerImplTest, verifyDrawQuadsForSqueezedLayer) for (size_t i = 0; i < quads.size(); ++i) { DrawQuad* quad = quads[i]; const TextureDrawQuad* texQuad = TextureDrawQuad::MaterialCast(quad); - gfx::RectF texRect = texQuad->uv_rect; + gfx::RectF texRect = gfx::BoundingRect(texQuad->uv_top_left, texQuad->uv_bottom_right); texRect.Scale(bitmapSize.width(), bitmapSize.height()); texRemaining.Subtract(Region(ToRoundedIntRect(texRect))); } diff --git a/cc/scrollbar_layer_impl.cc b/cc/scrollbar_layer_impl.cc index 81f817d..f82a1dc 100644 --- a/cc/scrollbar_layer_impl.cc +++ b/cc/scrollbar_layer_impl.cc @@ -105,7 +105,8 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append { bool premultipledAlpha = false; bool flipped = false; - gfx::RectF uvRect(0, 0, 1, 1); + gfx::PointF uvTopLeft(0.f, 0.f); + gfx::PointF uvBottomRight(1.f, 1.f); gfx::Rect boundsRect(gfx::Point(), bounds()); gfx::Rect contentBoundsRect(gfx::Point(), contentBounds()); @@ -122,7 +123,7 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append 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, opacity, flipped); + quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_thumbResourceId, premultipledAlpha, uvTopLeft, uvBottomRight, opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); } @@ -133,9 +134,10 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append if (m_foreTrackResourceId && !foreTrackRect.isEmpty()) { gfx::Rect quadRect(scrollbarLayerRectToContentRect(foreTrackRect)); gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); + gfx::RectF uvRect(toUVRect(foreTrackRect, boundsRect)); 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), opacity, flipped); + quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_foreTrackResourceId, premultipledAlpha, uvRect.origin(), uvRect.bottom_right(), opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); } @@ -146,7 +148,7 @@ void ScrollbarLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append 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, opacity, flipped); + quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_backTrackResourceId, premultipledAlpha, uvTopLeft, uvBottomRight, opacity, flipped); quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); } } diff --git a/cc/software_renderer.cc b/cc/software_renderer.cc index 785ed6b..11466da 100644 --- a/cc/software_renderer.cc +++ b/cc/software_renderer.cc @@ -259,7 +259,9 @@ void SoftwareRenderer::drawTextureQuad(const DrawingFrame& frame, const TextureD // FIXME: Add support for non-premultiplied alpha. ResourceProvider::ScopedReadLockSoftware lock(m_resourceProvider, quad->resource_id); const SkBitmap* bitmap = lock.skBitmap(); - gfx::RectF uvRect = gfx::ScaleRect(quad->uv_rect, bitmap->width(), bitmap->height()); + gfx::RectF uvRect = gfx::ScaleRect(gfx::BoundingRect(quad->uv_top_left, quad->uv_bottom_right), + bitmap->width(), + bitmap->height()); SkRect skUvRect = gfx::RectFToSkRect(uvRect); if (quad->flipped) m_skCurrentCanvas->scale(1, -1); diff --git a/cc/test/render_pass_test_common.cc b/cc/test/render_pass_test_common.cc index fafb84b..eca8684 100644 --- a/cc/test/render_pass_test_common.cc +++ b/cc/test/render_pass_test_common.cc @@ -158,7 +158,8 @@ void TestRenderPass::AppendOneOfEveryQuadType( opaque_rect, resource1, false, - rect, + gfx::PointF(0.f, 0.f), + gfx::PointF(1.f, 1.f), vertex_opacity, false); AppendQuad(texture_quad.PassAs<DrawQuad>()); diff --git a/cc/texture_draw_quad.cc b/cc/texture_draw_quad.cc index 6ce491a..9a657a7 100644 --- a/cc/texture_draw_quad.cc +++ b/cc/texture_draw_quad.cc @@ -5,6 +5,7 @@ #include "cc/texture_draw_quad.h" #include "base/logging.h" +#include "ui/gfx/vector2d_f.h" namespace cc { @@ -21,7 +22,8 @@ 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, - const gfx::RectF& uv_rect, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, const float vertex_opacity[4], bool flipped) { gfx::Rect visible_rect = rect; bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f @@ -30,7 +32,8 @@ void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, opaque_rect, visible_rect, needs_blending); this->resource_id = resource_id; this->premultiplied_alpha = premultiplied_alpha; - this->uv_rect = uv_rect; + this->uv_top_left = uv_top_left; + this->uv_bottom_right = uv_bottom_right; this->vertex_opacity[0] = vertex_opacity[0]; this->vertex_opacity[1] = vertex_opacity[1]; this->vertex_opacity[2] = vertex_opacity[2]; @@ -42,13 +45,15 @@ 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, - const gfx::RectF& uv_rect, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, 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->uv_top_left = uv_top_left; + this->uv_bottom_right = uv_bottom_right; this->vertex_opacity[0] = vertex_opacity[0]; this->vertex_opacity[1] = vertex_opacity[1]; this->vertex_opacity[2] = vertex_opacity[2]; @@ -90,18 +95,24 @@ bool TextureDrawQuad::PerformClipping() { gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); if (clippedRect.IsEmpty()) { rect = gfx::Rect(); - uv_rect = gfx::RectF(); + uv_top_left = gfx::PointF(); + uv_bottom_right = gfx::PointF(); return true; } // 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.height() / rectF.height() * clippedRect.height()); + gfx::Vector2dF uv_scale(uv_bottom_right - uv_top_left); + uv_scale.Scale(1.f / rectF.width(), 1.f / rectF.height()); + uv_bottom_right = uv_top_left + + gfx::ScaleVector2d( + clippedRect.bottom_right() - rectF.origin(), + uv_scale.x(), + uv_scale.y()); + uv_top_left = uv_top_left + + gfx::ScaleVector2d( + clippedRect.origin() - rectF.origin(), + uv_scale.x(), + uv_scale.y()); // Indexing according to the quad vertex generation: // 1--2 diff --git a/cc/texture_draw_quad.h b/cc/texture_draw_quad.h index 6ec2934..df50558 100644 --- a/cc/texture_draw_quad.h +++ b/cc/texture_draw_quad.h @@ -21,7 +21,8 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad { gfx::Rect opaque_rect, unsigned resource_id, bool premultiplied_alpha, - const gfx::RectF& uv_rect, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, const float vertex_opacity[4], bool flipped); @@ -32,13 +33,15 @@ class CC_EXPORT TextureDrawQuad : public DrawQuad { bool needs_blending, unsigned resource_id, bool premultiplied_alpha, - const gfx::RectF& uv_rect, + gfx::PointF uv_top_left, + gfx::PointF uv_bottom_right, const float vertex_opacity[4], bool flipped); unsigned resource_id; bool premultiplied_alpha; - gfx::RectF uv_rect; + gfx::PointF uv_top_left; + gfx::PointF uv_bottom_right; float vertex_opacity[4]; bool flipped; diff --git a/cc/texture_layer.cc b/cc/texture_layer.cc index 575fd5f..dd12abd 100644 --- a/cc/texture_layer.cc +++ b/cc/texture_layer.cc @@ -37,7 +37,8 @@ TextureLayer::TextureLayer(TextureLayerClient* client, bool usesMailbox) , m_client(client) , m_usesMailbox(usesMailbox) , m_flipped(true) - , m_uvRect(0, 0, 1, 1) + , m_uvTopLeft(0.f, 0.f) + , m_uvBottomRight(1.f, 1.f) , m_premultipliedAlpha(true) , m_rateLimitContext(false) , m_contextLost(false) @@ -73,9 +74,10 @@ void TextureLayer::setFlipped(bool flipped) setNeedsCommit(); } -void TextureLayer::setUVRect(const gfx::RectF& rect) +void TextureLayer::setUV(gfx::PointF topLeft, gfx::PointF bottomRight) { - m_uvRect = rect; + m_uvTopLeft = topLeft; + m_uvBottomRight = bottomRight; setNeedsCommit(); } @@ -178,7 +180,8 @@ void TextureLayer::pushPropertiesTo(LayerImpl* layer) TextureLayerImpl* textureLayer = static_cast<TextureLayerImpl*>(layer); textureLayer->setFlipped(m_flipped); - textureLayer->setUVRect(m_uvRect); + textureLayer->setUVTopLeft(m_uvTopLeft); + textureLayer->setUVBottomRight(m_uvBottomRight); textureLayer->setVertexOpacity(m_vertexOpacity); textureLayer->setPremultipliedAlpha(m_premultipliedAlpha); if (m_usesMailbox) { diff --git a/cc/texture_layer.h b/cc/texture_layer.h index 36aa866..bf6ac46 100644 --- a/cc/texture_layer.h +++ b/cc/texture_layer.h @@ -39,8 +39,8 @@ public: // Sets whether this texture should be Y-flipped at draw time. Defaults to true. void setFlipped(bool); - // Sets a UV transform to be used at draw time. Defaults to (0, 0, 1, 1). - void setUVRect(const gfx::RectF&); + // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1). + void setUV(gfx::PointF topLeft, gfx::PointF bottomRight); // 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); @@ -81,7 +81,8 @@ private: MailboxCallback m_mailboxReleaseCallback; bool m_flipped; - gfx::RectF m_uvRect; + gfx::PointF m_uvTopLeft; + gfx::PointF m_uvBottomRight; // [bottom left, top left, top right, bottom right] float m_vertexOpacity[4]; bool m_premultipliedAlpha; diff --git a/cc/texture_layer_impl.cc b/cc/texture_layer_impl.cc index b94fe13..d1a48da 100644 --- a/cc/texture_layer_impl.cc +++ b/cc/texture_layer_impl.cc @@ -18,7 +18,8 @@ TextureLayerImpl::TextureLayerImpl(LayerTreeImpl* treeImpl, int id, bool usesMai , m_externalTextureResource(0) , m_premultipliedAlpha(true) , m_flipped(true) - , m_uvRect(0, 0, 1, 1) + , m_uvTopLeft(0.f, 0.f) + , m_uvBottomRight(1.f, 1.f) , m_hasPendingMailbox(false) , m_usesMailbox(usesMailbox) { @@ -87,7 +88,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_vertexOpacity, m_flipped); + quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, m_premultipliedAlpha, m_uvTopLeft, m_uvBottomRight, m_vertexOpacity, m_flipped); // Perform explicit clipping on a quad to avoid setting a scissor later. if (sharedQuadState->is_clipped && quad->PerformClipping()) diff --git a/cc/texture_layer_impl.h b/cc/texture_layer_impl.h index 0f0ac3e..b7e5998 100644 --- a/cc/texture_layer_impl.h +++ b/cc/texture_layer_impl.h @@ -33,7 +33,8 @@ public: void setTextureId(unsigned id) { m_textureId = id; } void setPremultipliedAlpha(bool premultipliedAlpha) { m_premultipliedAlpha = premultipliedAlpha; } void setFlipped(bool flipped) { m_flipped = flipped; } - void setUVRect(const gfx::RectF& rect) { m_uvRect = rect; } + void setUVTopLeft(gfx::PointF topLeft) { m_uvTopLeft = topLeft; } + void setUVBottomRight(gfx::PointF bottomRight) { m_uvBottomRight = bottomRight; } // 1--2 // | | @@ -52,7 +53,8 @@ private: ResourceProvider::ResourceId m_externalTextureResource; bool m_premultipliedAlpha; bool m_flipped; - gfx::RectF m_uvRect; + gfx::PointF m_uvTopLeft; + gfx::PointF m_uvBottomRight; float m_vertexOpacity[4]; bool m_hasPendingMailbox; diff --git a/cc/video_layer_impl.cc b/cc/video_layer_impl.cc index 908472c..b536bbe 100644 --- a/cc/video_layer_impl.cc +++ b/cc/video_layer_impl.cc @@ -225,22 +225,24 @@ void VideoLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuad // RGBA software decoder. const FramePlane& plane = m_framePlanes[media::VideoFrame::kRGBPlane]; bool premultipliedAlpha = true; - gfx::RectF uvRect(0, 0, texWidthScale, texHeightScale); + gfx::PointF uvTopLeft(0.f, 0.f); + gfx::PointF uvBottomRight(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, opacity, flipped); + textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, plane.resourceId, premultipliedAlpha, uvTopLeft, uvBottomRight, opacity, flipped); quadSink.append(textureQuad.PassAs<DrawQuad>(), appendQuadsData); break; } case GL_TEXTURE_2D: { // NativeTexture hardware decoder. bool premultipliedAlpha = true; - gfx::RectF uvRect(0, 0, texWidthScale, texHeightScale); + gfx::PointF uvTopLeft(0.f, 0.f); + gfx::PointF uvBottomRight(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, opacity, flipped); + textureQuad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResource, premultipliedAlpha, uvTopLeft, uvBottomRight, opacity, flipped); quadSink.append(textureQuad.PassAs<DrawQuad>(), appendQuadsData); break; } diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index 1a7bcc0..d0d1da6 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -176,7 +176,8 @@ IPC_STRUCT_TRAITS_BEGIN(cc::TextureDrawQuad) IPC_STRUCT_TRAITS_PARENT(cc::DrawQuad) IPC_STRUCT_TRAITS_MEMBER(resource_id) IPC_STRUCT_TRAITS_MEMBER(premultiplied_alpha) - IPC_STRUCT_TRAITS_MEMBER(uv_rect) + IPC_STRUCT_TRAITS_MEMBER(uv_top_left) + IPC_STRUCT_TRAITS_MEMBER(uv_bottom_right) IPC_STRUCT_TRAITS_MEMBER(flipped) IPC_STRUCT_TRAITS_END() diff --git a/content/common/cc_messages_unittest.cc b/content/common/cc_messages_unittest.cc index 7261439..efa840d 100644 --- a/content/common/cc_messages_unittest.cc +++ b/content/common/cc_messages_unittest.cc @@ -144,7 +144,8 @@ class CCMessagesTest : public testing::Test { void Compare(const TextureDrawQuad* a, const TextureDrawQuad* b) { EXPECT_EQ(a->resource_id, b->resource_id); EXPECT_EQ(a->premultiplied_alpha, b->premultiplied_alpha); - EXPECT_EQ(a->uv_rect, b->uv_rect); + EXPECT_EQ(a->uv_top_left, b->uv_top_left); + EXPECT_EQ(a->uv_bottom_right, b->uv_bottom_right); EXPECT_EQ(a->flipped, b->flipped); } diff --git a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc index dd7d84f..df54f1a 100644 --- a/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc +++ b/content/renderer/browser_plugin/browser_plugin_compositing_helper.cc @@ -94,7 +94,7 @@ void BrowserPluginCompositingHelper::UpdateUVRect() { uv_rect.set_height(static_cast<float>(container_size_.height()) / static_cast<float>(buffer_size_.height())); } - texture_layer_->setUVRect(uv_rect); + texture_layer_->setUV(uv_rect.origin(), uv_rect.bottom_right()); } } // namespace content diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc index 053ddac..119a1cf 100644 --- a/ui/compositor/layer.cc +++ b/ui/compositor/layer.cc @@ -786,12 +786,11 @@ void Layer::RecomputeDrawsContentAndUVRect() { gfx::Size size(std::min(bounds().width(), texture_size.width()), std::min(bounds().height(), texture_size.height())); - gfx::RectF rect( - 0, - 0, + gfx::PointF uv_top_left(0.f, 0.f); + gfx::PointF uv_bottom_right( static_cast<float>(size.width())/texture_size.width(), static_cast<float>(size.height())/texture_size.height()); - texture_layer_->setUVRect(rect); + texture_layer_->setUV(uv_top_left, uv_bottom_right); cc_layer_->setBounds(ConvertSizeToPixel(this, size)); } diff --git a/ui/gfx/size_base_impl.h b/ui/gfx/size_base_impl.h index 99b1145..9e87468 100644 --- a/ui/gfx/size_base_impl.h +++ b/ui/gfx/size_base_impl.h @@ -16,18 +16,13 @@ namespace gfx { template<typename Class, typename Type> void SizeBase<Class, Type>::set_width(Type width) { -#if !defined(OS_ANDROID) - // TODO(aelias): Remove these ifdefs for Android. See http://crbug.com/168927 DCHECK(!(width < 0)); -#endif width_ = width < 0 ? 0 : width; } template<typename Class, typename Type> void SizeBase<Class, Type>::set_height(Type height) { -#if !defined(OS_ANDROID) DCHECK(!(height < 0)); -#endif height_ = height < 0 ? 0 : height; } @@ -35,10 +30,8 @@ template<typename Class, typename Type> SizeBase<Class, Type>::SizeBase(Type width, Type height) : width_(width < 0 ? 0 : width), height_(height < 0 ? 0 : height) { -#if !defined(OS_ANDROID) DCHECK(!(width < 0)); DCHECK(!(height < 0)); -#endif } } // namespace gfx diff --git a/webkit/compositor_bindings/web_external_texture_layer_impl.cc b/webkit/compositor_bindings/web_external_texture_layer_impl.cc index 08d8f11..e3479f2 100644 --- a/webkit/compositor_bindings/web_external_texture_layer_impl.cc +++ b/webkit/compositor_bindings/web_external_texture_layer_impl.cc @@ -49,7 +49,7 @@ void WebExternalTextureLayerImpl::setFlipped(bool flipped) void WebExternalTextureLayerImpl::setUVRect(const WebFloatRect& rect) { - static_cast<TextureLayer*>(m_layer->layer())->setUVRect(rect); + static_cast<TextureLayer*>(m_layer->layer())->setUV(gfx::PointF(rect.x, rect.y), gfx::PointF(rect.x + rect.width, rect.y + rect.height)); } void WebExternalTextureLayerImpl::setOpaque(bool opaque) |