Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: cc/texture_draw_quad.cc

Issue 11783094: cc: Add point-based UV coordinate on TextureLayer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed unittest and abreviations Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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, gfx::Rect opaque_rect, 22 gfx::Rect rect, gfx::Rect opaque_rect,
23 unsigned resource_id, bool premultiplied_alpha, 23 unsigned resource_id, bool premultiplied_alpha,
24 const gfx::RectF& uv_rect, 24 const gfx::PointF& uv_top_left,
25 const gfx::PointF& uv_bottom_right,
25 const float vertex_opacity[4], bool flipped) { 26 const float vertex_opacity[4], bool flipped) {
26 gfx::Rect visible_rect = rect; 27 gfx::Rect visible_rect = rect;
27 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f 28 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f
28 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f; 29 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f;
29 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 30 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
30 opaque_rect, visible_rect, needs_blending); 31 opaque_rect, visible_rect, needs_blending);
31 this->resource_id = resource_id; 32 this->resource_id = resource_id;
32 this->premultiplied_alpha = premultiplied_alpha; 33 this->premultiplied_alpha = premultiplied_alpha;
33 this->uv_rect = uv_rect; 34 this->uv_top_left = uv_top_left;
35 this->uv_bottom_right = uv_bottom_right;
34 this->vertex_opacity[0] = vertex_opacity[0]; 36 this->vertex_opacity[0] = vertex_opacity[0];
35 this->vertex_opacity[1] = vertex_opacity[1]; 37 this->vertex_opacity[1] = vertex_opacity[1];
36 this->vertex_opacity[2] = vertex_opacity[2]; 38 this->vertex_opacity[2] = vertex_opacity[2];
37 this->vertex_opacity[3] = vertex_opacity[3]; 39 this->vertex_opacity[3] = vertex_opacity[3];
38 this->flipped = flipped; 40 this->flipped = flipped;
39 } 41 }
40 42
41 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, 43 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
42 gfx::Rect rect, gfx::Rect opaque_rect, 44 gfx::Rect rect, gfx::Rect opaque_rect,
43 gfx::Rect visible_rect, bool needs_blending, 45 gfx::Rect visible_rect, bool needs_blending,
44 unsigned resource_id, bool premultiplied_alpha, 46 unsigned resource_id, bool premultiplied_alpha,
45 const gfx::RectF& uv_rect, 47 const gfx::PointF& uv_top_left,
48 const gfx::PointF& uv_bottom_right,
46 const float vertex_opacity[4], bool flipped) { 49 const float vertex_opacity[4], bool flipped) {
47 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 50 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
48 opaque_rect, visible_rect, needs_blending); 51 opaque_rect, visible_rect, needs_blending);
49 this->resource_id = resource_id; 52 this->resource_id = resource_id;
50 this->premultiplied_alpha = premultiplied_alpha; 53 this->premultiplied_alpha = premultiplied_alpha;
51 this->uv_rect = uv_rect; 54 this->uv_top_left = uv_top_left;
55 this->uv_bottom_right = uv_bottom_right;
52 this->vertex_opacity[0] = vertex_opacity[0]; 56 this->vertex_opacity[0] = vertex_opacity[0];
53 this->vertex_opacity[1] = vertex_opacity[1]; 57 this->vertex_opacity[1] = vertex_opacity[1];
54 this->vertex_opacity[2] = vertex_opacity[2]; 58 this->vertex_opacity[2] = vertex_opacity[2];
55 this->vertex_opacity[3] = vertex_opacity[3]; 59 this->vertex_opacity[3] = vertex_opacity[3];
56 this->flipped = flipped; 60 this->flipped = flipped;
57 } 61 }
58 62
59 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) { 63 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) {
60 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); 64 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT);
61 return static_cast<const TextureDrawQuad*>(quad); 65 return static_cast<const TextureDrawQuad*>(quad);
(...skipping 17 matching lines...) Expand all
79 83
80 // Transform the rect by the scale and offset. 84 // Transform the rect by the scale and offset.
81 gfx::RectF rectF = rect; 85 gfx::RectF rectF = rect;
82 rectF.Scale(x_scale, y_scale); 86 rectF.Scale(x_scale, y_scale);
83 rectF += offset; 87 rectF += offset;
84 88
85 // Perform clipping and check to see if the result is empty. 89 // Perform clipping and check to see if the result is empty.
86 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); 90 gfx::RectF clippedRect = IntersectRects(rectF, clipRect());
87 if (clippedRect.IsEmpty()) { 91 if (clippedRect.IsEmpty()) {
88 rect = gfx::Rect(); 92 rect = gfx::Rect();
89 uv_rect = gfx::RectF(); 93 uv_top_left = gfx::PointF();
94 uv_bottom_right = gfx::PointF();
danakj 2013/01/11 02:21:51 should this be PointF(1.f, 1.f)
Jerome 2013/01/11 18:00:01 To keep the previous behavior uv_bottom_right shou
90 return true; 95 return true;
91 } 96 }
92 97
93 // Create a new uv-rect by clipping the old one to the new bounds. 98 // Create a new uv-rect by clipping the old one to the new bounds.
94 uv_rect = gfx::RectF( 99 float u_scale = (uv_bottom_right.x() - uv_top_left.x()) / rectF.width();
danakj 2013/01/11 02:21:51 I might have messed this up, or you might see a mo
Jerome 2013/01/11 18:00:01 LGTM. Any reason why there is no void Vector2dF::
danakj 2013/01/11 20:00:12 Ya, I thought about this too.. Ill file a bug
95 uv_rect.x() 100 float v_scale = (uv_bottom_right.y() - uv_top_left.y()) / rectF.height();
96 + uv_rect.width() / rectF.width() * (clippedRect.x() - rectF.x()), 101 uv_bottom_right = gfx::PointF(
97 uv_rect.y() 102 uv_top_left.x() + u_scale * (clippedRect.right() - rectF.x()),
98 + uv_rect.height() / rectF.height() * (clippedRect.y() - rectF.y()), 103 uv_top_left.y() + v_scale * (clippedRect.bottom() - rectF.y()));
99 uv_rect.width() / rectF.width() * clippedRect.width(), 104 uv_top_left = gfx::PointF(
100 uv_rect.height() / rectF.height() * clippedRect.height()); 105 uv_top_left.x() + u_scale * (clippedRect.x() - rectF.x()),
106 uv_top_left.y() + v_scale * (clippedRect.y() - rectF.y()));
101 107
102 // Indexing according to the quad vertex generation: 108 // Indexing according to the quad vertex generation:
103 // 1--2 109 // 1--2
104 // | | 110 // | |
105 // 0--3 111 // 0--3
106 if (vertex_opacity[0] != vertex_opacity[1] 112 if (vertex_opacity[0] != vertex_opacity[1]
107 || vertex_opacity[0] != vertex_opacity[2] 113 || vertex_opacity[0] != vertex_opacity[2]
108 || vertex_opacity[0] != vertex_opacity[3]) { 114 || vertex_opacity[0] != vertex_opacity[3]) {
109 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); 115 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width();
110 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); 116 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height();
(...skipping 13 matching lines...) Expand all
124 clippedRect -= offset; 130 clippedRect -= offset;
125 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); 131 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale);
126 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f), 132 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f),
127 static_cast<int>(clippedRect.y() + 0.5f), 133 static_cast<int>(clippedRect.y() + 0.5f),
128 static_cast<int>(clippedRect.width() + 0.5f), 134 static_cast<int>(clippedRect.width() + 0.5f),
129 static_cast<int>(clippedRect.height() + 0.5f)); 135 static_cast<int>(clippedRect.height() + 0.5f));
130 return true; 136 return true;
131 } 137 }
132 138
133 } // namespace cc 139 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698