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 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
11 TextureDrawQuad::TextureDrawQuad() | 11 TextureDrawQuad::TextureDrawQuad() |
12 : resource_id(0), | 12 : resource_id(0), |
13 premultiplied_alpha(false), | 13 premultiplied_alpha(false), |
14 flipped(false) { | 14 flipped(false) { |
15 } | 15 } |
16 | 16 |
17 scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { | 17 scoped_ptr<TextureDrawQuad> TextureDrawQuad::Create() { |
18 return make_scoped_ptr(new TextureDrawQuad); | 18 return make_scoped_ptr(new TextureDrawQuad); |
19 } | 19 } |
20 | 20 |
21 void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, | 21 void TextureDrawQuad::SetNew(const SharedQuadState* shared_quad_state, |
22 gfx::Rect rect, | 22 gfx::Rect rect, |
23 gfx::Rect opaque_rect, | 23 gfx::Rect opaque_rect, |
24 unsigned resource_id, | 24 unsigned resource_id, |
25 bool premultiplied_alpha, | 25 bool premultiplied_alpha, |
26 const gfx::RectF& uv_rect, | 26 const gfx::RectF& uv_rect, |
27 const float vertex_opacity[4], | |
27 bool flipped) { | 28 bool flipped) { |
28 gfx::Rect visible_rect = rect; | 29 gfx::Rect visible_rect = rect; |
29 bool needs_blending = false; | 30 bool needs_blending = vertex_opacity[0] != 1.0f |
31 || vertex_opacity[1] != 1.0f | |
jamesr
2012/12/14 21:18:20
chromium style is to have the operator on the prev
Jerome
2012/12/14 21:48:47
Done.
| |
32 || vertex_opacity[2] != 1.0f | |
33 || vertex_opacity[3] != 1.0f; | |
30 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, | 34 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, |
31 opaque_rect, visible_rect, needs_blending); | 35 opaque_rect, visible_rect, needs_blending); |
32 this->resource_id = resource_id; | 36 this->resource_id = resource_id; |
33 this->premultiplied_alpha = premultiplied_alpha; | 37 this->premultiplied_alpha = premultiplied_alpha; |
34 this->uv_rect = uv_rect; | 38 this->uv_rect = uv_rect; |
39 this->vertex_opacity[0] = vertex_opacity[0]; | |
40 this->vertex_opacity[1] = vertex_opacity[1]; | |
41 this->vertex_opacity[2] = vertex_opacity[2]; | |
42 this->vertex_opacity[3] = vertex_opacity[3]; | |
35 this->flipped = flipped; | 43 this->flipped = flipped; |
36 } | 44 } |
37 | 45 |
38 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, | 46 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, |
39 gfx::Rect rect, | 47 gfx::Rect rect, |
40 gfx::Rect opaque_rect, | 48 gfx::Rect opaque_rect, |
41 gfx::Rect visible_rect, | 49 gfx::Rect visible_rect, |
42 bool needs_blending, | 50 bool needs_blending, |
43 unsigned resource_id, | 51 unsigned resource_id, |
44 bool premultiplied_alpha, | 52 bool premultiplied_alpha, |
45 const gfx::RectF& uv_rect, | 53 const gfx::RectF& uv_rect, |
54 const float vertex_opacity[4], | |
46 bool flipped) { | 55 bool flipped) { |
47 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, | 56 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, |
48 opaque_rect, visible_rect, needs_blending); | 57 opaque_rect, visible_rect, needs_blending); |
49 this->resource_id = resource_id; | 58 this->resource_id = resource_id; |
50 this->premultiplied_alpha = premultiplied_alpha; | 59 this->premultiplied_alpha = premultiplied_alpha; |
51 this->uv_rect = uv_rect; | 60 this->uv_rect = uv_rect; |
61 this->vertex_opacity[0] = vertex_opacity[0]; | |
62 this->vertex_opacity[1] = vertex_opacity[1]; | |
63 this->vertex_opacity[2] = vertex_opacity[2]; | |
64 this->vertex_opacity[3] = vertex_opacity[3]; | |
52 this->flipped = flipped; | 65 this->flipped = flipped; |
53 } | 66 } |
54 | 67 |
55 const TextureDrawQuad* TextureDrawQuad::MaterialCast( | 68 const TextureDrawQuad* TextureDrawQuad::MaterialCast( |
56 const DrawQuad* quad) { | 69 const DrawQuad* quad) { |
57 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); | 70 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); |
58 return static_cast<const TextureDrawQuad*>(quad); | 71 return static_cast<const TextureDrawQuad*>(quad); |
59 } | 72 } |
60 | 73 |
61 bool TextureDrawQuad::PerformClipping() { | 74 bool TextureDrawQuad::PerformClipping() { |
(...skipping 26 matching lines...) Expand all Loading... | |
88 return true; | 101 return true; |
89 } | 102 } |
90 | 103 |
91 // Create a new uv-rect by clipping the old one to the new bounds. | 104 // Create a new uv-rect by clipping the old one to the new bounds. |
92 uv_rect = gfx::RectF( | 105 uv_rect = gfx::RectF( |
93 uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()), | 106 uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()), |
94 uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()), | 107 uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()), |
95 uv_rect.width () / rectF.width () * clippedRect.width (), | 108 uv_rect.width () / rectF.width () * clippedRect.width (), |
96 uv_rect.height() / rectF.height() * clippedRect.height()); | 109 uv_rect.height() / rectF.height() * clippedRect.height()); |
97 | 110 |
111 // Indexing according to the quad vertex generation: | |
112 // 1--2 | |
113 // | | | |
114 // 0--3 | |
115 if (vertex_opacity[0] != vertex_opacity[1] | |
116 || vertex_opacity[0] != vertex_opacity[2] | |
jamesr
2012/12/14 21:18:20
||s on previous line
Jerome
2012/12/14 21:48:47
Done.
| |
117 || vertex_opacity[0] != vertex_opacity[3]) { | |
118 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); | |
119 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); | |
120 const float x3 = (clippedRect.right() - rectF.x()) / rectF.width(); | |
121 const float y3 = (clippedRect.bottom() - rectF.y()) / rectF.height(); | |
122 const float x1y1 = x1 * vertex_opacity[2] + (1.0f - x1) * vertex_opacity[1]; | |
123 const float x1y3 = x1 * vertex_opacity[3] + (1.0f - x1) * vertex_opacity[0]; | |
124 const float x3y1 = x3 * vertex_opacity[2] + (1.0f - x3) * vertex_opacity[1]; | |
125 const float x3y3 = x3 * vertex_opacity[3] + (1.0f - x3) * vertex_opacity[0]; | |
126 vertex_opacity[0] = y3 * x1y3 + (1.0f - y3) * x1y1; | |
127 vertex_opacity[1] = y1 * x1y3 + (1.0f - y1) * x1y1; | |
128 vertex_opacity[2] = y1 * x3y3 + (1.0f - y1) * x3y1; | |
129 vertex_opacity[3] = y3 * x3y3 + (1.0f - y3) * x3y1; | |
130 } | |
131 | |
98 // Move the clipped rectangle back into its space. | 132 // Move the clipped rectangle back into its space. |
99 clippedRect -= offset; | 133 clippedRect -= offset; |
100 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); | 134 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); |
101 rect = gfx::Rect( | 135 rect = gfx::Rect( |
102 static_cast<int>(clippedRect.x() + 0.5f), | 136 static_cast<int>(clippedRect.x() + 0.5f), |
103 static_cast<int>(clippedRect.y() + 0.5f), | 137 static_cast<int>(clippedRect.y() + 0.5f), |
104 static_cast<int>(clippedRect.width() + 0.5f), | 138 static_cast<int>(clippedRect.width() + 0.5f), |
105 static_cast<int>(clippedRect.height() + 0.5f)); | 139 static_cast<int>(clippedRect.height() + 0.5f)); |
106 return true; | 140 return true; |
107 } | 141 } |
108 | 142 |
109 } // namespace cc | 143 } // namespace cc |
OLD | NEW |