OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/texture_draw_quad.h" | 5 #include "cc/texture_draw_quad.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/gfx/vector2d_f.h" |
8 | 9 |
9 namespace cc { | 10 namespace cc { |
10 | 11 |
11 TextureDrawQuad::TextureDrawQuad() | 12 TextureDrawQuad::TextureDrawQuad() |
12 : resource_id(0), | 13 : resource_id(0), |
13 premultiplied_alpha(false), | 14 premultiplied_alpha(false), |
14 flipped(false) { | 15 flipped(false) { |
15 } | 16 } |
16 | 17 |
17 scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { | 18 scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { |
18 return make_scoped_ptr(new TextureDrawQuad); | 19 return make_scoped_ptr(new TextureDrawQuad); |
19 } | 20 } |
20 | 21 |
21 void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, | 22 void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, |
22 gfx::Rect rect, gfx::Rect opaque_rect, | 23 gfx::Rect rect, gfx::Rect opaque_rect, |
23 unsigned resource_id, bool premultiplied_alpha, | 24 unsigned resource_id, bool premultiplied_alpha, |
24 const gfx::RectF& uv_rect, | 25 gfx::PointF uv_top_left, |
| 26 gfx::PointF uv_bottom_right, |
25 const float vertex_opacity[4], bool flipped) { | 27 const float vertex_opacity[4], bool flipped) { |
26 gfx::Rect visible_rect = rect; | 28 gfx::Rect visible_rect = rect; |
27 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f | 29 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f |
28 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f; | 30 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f; |
29 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, | 31 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, |
30 opaque_rect, visible_rect, needs_blending); | 32 opaque_rect, visible_rect, needs_blending); |
31 this->resource_id = resource_id; | 33 this->resource_id = resource_id; |
32 this->premultiplied_alpha = premultiplied_alpha; | 34 this->premultiplied_alpha = premultiplied_alpha; |
33 this->uv_rect = uv_rect; | 35 this->uv_top_left = uv_top_left; |
| 36 this->uv_bottom_right = uv_bottom_right; |
34 this->vertex_opacity[0] = vertex_opacity[0]; | 37 this->vertex_opacity[0] = vertex_opacity[0]; |
35 this->vertex_opacity[1] = vertex_opacity[1]; | 38 this->vertex_opacity[1] = vertex_opacity[1]; |
36 this->vertex_opacity[2] = vertex_opacity[2]; | 39 this->vertex_opacity[2] = vertex_opacity[2]; |
37 this->vertex_opacity[3] = vertex_opacity[3]; | 40 this->vertex_opacity[3] = vertex_opacity[3]; |
38 this->flipped = flipped; | 41 this->flipped = flipped; |
39 } | 42 } |
40 | 43 |
41 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, | 44 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, |
42 gfx::Rect rect, gfx::Rect opaque_rect, | 45 gfx::Rect rect, gfx::Rect opaque_rect, |
43 gfx::Rect visible_rect, bool needs_blending, | 46 gfx::Rect visible_rect, bool needs_blending, |
44 unsigned resource_id, bool premultiplied_alpha, | 47 unsigned resource_id, bool premultiplied_alpha, |
45 const gfx::RectF& uv_rect, | 48 gfx::PointF uv_top_left, |
| 49 gfx::PointF uv_bottom_right, |
46 const float vertex_opacity[4], bool flipped) { | 50 const float vertex_opacity[4], bool flipped) { |
47 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, | 51 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, |
48 opaque_rect, visible_rect, needs_blending); | 52 opaque_rect, visible_rect, needs_blending); |
49 this->resource_id = resource_id; | 53 this->resource_id = resource_id; |
50 this->premultiplied_alpha = premultiplied_alpha; | 54 this->premultiplied_alpha = premultiplied_alpha; |
51 this->uv_rect = uv_rect; | 55 this->uv_top_left = uv_top_left; |
| 56 this->uv_bottom_right = uv_bottom_right; |
52 this->vertex_opacity[0] = vertex_opacity[0]; | 57 this->vertex_opacity[0] = vertex_opacity[0]; |
53 this->vertex_opacity[1] = vertex_opacity[1]; | 58 this->vertex_opacity[1] = vertex_opacity[1]; |
54 this->vertex_opacity[2] = vertex_opacity[2]; | 59 this->vertex_opacity[2] = vertex_opacity[2]; |
55 this->vertex_opacity[3] = vertex_opacity[3]; | 60 this->vertex_opacity[3] = vertex_opacity[3]; |
56 this->flipped = flipped; | 61 this->flipped = flipped; |
57 } | 62 } |
58 | 63 |
59 void TextureDrawQuad::AppendResources( | 64 void TextureDrawQuad::AppendResources( |
60 ResourceProvider::ResourceIdArray* resources) { | 65 ResourceProvider::ResourceIdArray* resources) { |
61 resources->push_back(resource_id); | 66 resources->push_back(resource_id); |
(...skipping 21 matching lines...) Expand all Loading... |
83 | 88 |
84 // Transform the rect by the scale and offset. | 89 // Transform the rect by the scale and offset. |
85 gfx::RectF rectF = rect; | 90 gfx::RectF rectF = rect; |
86 rectF.Scale(x_scale, y_scale); | 91 rectF.Scale(x_scale, y_scale); |
87 rectF += offset; | 92 rectF += offset; |
88 | 93 |
89 // Perform clipping and check to see if the result is empty. | 94 // Perform clipping and check to see if the result is empty. |
90 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); | 95 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); |
91 if (clippedRect.IsEmpty()) { | 96 if (clippedRect.IsEmpty()) { |
92 rect = gfx::Rect(); | 97 rect = gfx::Rect(); |
93 uv_rect = gfx::RectF(); | 98 uv_top_left = gfx::PointF(); |
| 99 uv_bottom_right = gfx::PointF(); |
94 return true; | 100 return true; |
95 } | 101 } |
96 | 102 |
97 // Create a new uv-rect by clipping the old one to the new bounds. | 103 // Create a new uv-rect by clipping the old one to the new bounds. |
98 uv_rect = gfx::RectF( | 104 gfx::Vector2dF uv_scale(uv_bottom_right - uv_top_left); |
99 uv_rect.x() | 105 uv_scale.Scale(1.f / rectF.width(), 1.f / rectF.height()); |
100 + uv_rect.width() / rectF.width() * (clippedRect.x() - rectF.x()), | 106 uv_bottom_right = uv_top_left + |
101 uv_rect.y() | 107 gfx::ScaleVector2d( |
102 + uv_rect.height() / rectF.height() * (clippedRect.y() - rectF.y()), | 108 clippedRect.bottom_right() - rectF.origin(), |
103 uv_rect.width() / rectF.width() * clippedRect.width(), | 109 uv_scale.x(), |
104 uv_rect.height() / rectF.height() * clippedRect.height()); | 110 uv_scale.y()); |
| 111 uv_top_left = uv_top_left + |
| 112 gfx::ScaleVector2d( |
| 113 clippedRect.origin() - rectF.origin(), |
| 114 uv_scale.x(), |
| 115 uv_scale.y()); |
105 | 116 |
106 // Indexing according to the quad vertex generation: | 117 // Indexing according to the quad vertex generation: |
107 // 1--2 | 118 // 1--2 |
108 // | | | 119 // | | |
109 // 0--3 | 120 // 0--3 |
110 if (vertex_opacity[0] != vertex_opacity[1] | 121 if (vertex_opacity[0] != vertex_opacity[1] |
111 || vertex_opacity[0] != vertex_opacity[2] | 122 || vertex_opacity[0] != vertex_opacity[2] |
112 || vertex_opacity[0] != vertex_opacity[3]) { | 123 || vertex_opacity[0] != vertex_opacity[3]) { |
113 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); | 124 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); |
114 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); | 125 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); |
(...skipping 13 matching lines...) Expand all Loading... |
128 clippedRect -= offset; | 139 clippedRect -= offset; |
129 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); | 140 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); |
130 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f), | 141 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f), |
131 static_cast<int>(clippedRect.y() + 0.5f), | 142 static_cast<int>(clippedRect.y() + 0.5f), |
132 static_cast<int>(clippedRect.width() + 0.5f), | 143 static_cast<int>(clippedRect.width() + 0.5f), |
133 static_cast<int>(clippedRect.height() + 0.5f)); | 144 static_cast<int>(clippedRect.height() + 0.5f)); |
134 return true; | 145 return true; |
135 } | 146 } |
136 | 147 |
137 } // namespace cc | 148 } // namespace cc |
OLD | NEW |