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

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: fixing danakj comments 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
« no previous file with comments | « cc/texture_draw_quad.h ('k') | cc/texture_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) { 64 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) {
60 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); 65 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT);
61 return static_cast<const TextureDrawQuad*>(quad); 66 return static_cast<const TextureDrawQuad*>(quad);
(...skipping 16 matching lines...) Expand all
78 83
79 // Transform the rect by the scale and offset. 84 // Transform the rect by the scale and offset.
80 gfx::RectF rectF = rect; 85 gfx::RectF rectF = rect;
81 rectF.Scale(x_scale, y_scale); 86 rectF.Scale(x_scale, y_scale);
82 rectF += offset; 87 rectF += offset;
83 88
84 // Perform clipping and check to see if the result is empty. 89 // Perform clipping and check to see if the result is empty.
85 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); 90 gfx::RectF clippedRect = IntersectRects(rectF, clipRect());
86 if (clippedRect.IsEmpty()) { 91 if (clippedRect.IsEmpty()) {
87 rect = gfx::Rect(); 92 rect = gfx::Rect();
88 uv_rect = gfx::RectF(); 93 uv_top_left = gfx::PointF();
94 uv_bottom_right = gfx::PointF();
89 return true; 95 return true;
90 } 96 }
91 97
92 // 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.
93 uv_rect = gfx::RectF( 99 /*
enne (OOO) 2013/01/14 17:58:40 ...
Jerome 2013/01/14 23:47:08 Whoops...
94 uv_rect.x() 100 float u_scale = (uv_bottom_right.x() - uv_top_left.x()) / rectF.width();
95 + uv_rect.width() / rectF.width() * (clippedRect.x() - rectF.x()), 101 float v_scale = (uv_bottom_right.y() - uv_top_left.y()) / rectF.height();
96 uv_rect.y() 102 uv_bottom_right = gfx::PointF(
97 + uv_rect.height() / rectF.height() * (clippedRect.y() - rectF.y()), 103 uv_top_left.x() + u_scale * (clippedRect.right() - rectF.x()),
98 uv_rect.width() / rectF.width() * clippedRect.width(), 104 uv_top_left.y() + v_scale * (clippedRect.bottom() - rectF.y()));
99 uv_rect.height() / rectF.height() * clippedRect.height()); 105 uv_top_left = gfx::PointF(
106 uv_top_left.x() + u_scale * (clippedRect.x() - rectF.x()),
107 uv_top_left.y() + v_scale * (clippedRect.y() - rectF.y()));
108 */
109 gfx::Vector2dF uv_scale(uv_bottom_right - uv_top_left);
enne (OOO) 2013/01/14 17:58:40 Are there unit tests for this texture clipping and
Jerome 2013/01/14 23:47:08 Done.
110 uv_scale.Scale(1.f / rectF.width(), 1.f / rectF.height());
111 uv_bottom_right = uv_top_left +
112 gfx::ScaleVector2d(
113 clippedRect.bottom_right() - rectF.origin(),
114 uv_scale.x(),
115 uv_scale.y());
116 uv_top_left = uv_top_left +
117 gfx::ScaleVector2d(
118 clippedRect.origin() - rectF.origin(),
119 uv_scale.x(),
120 uv_scale.y());
100 121
101 // Indexing according to the quad vertex generation: 122 // Indexing according to the quad vertex generation:
102 // 1--2 123 // 1--2
103 // | | 124 // | |
104 // 0--3 125 // 0--3
105 if (vertex_opacity[0] != vertex_opacity[1] 126 if (vertex_opacity[0] != vertex_opacity[1]
106 || vertex_opacity[0] != vertex_opacity[2] 127 || vertex_opacity[0] != vertex_opacity[2]
107 || vertex_opacity[0] != vertex_opacity[3]) { 128 || vertex_opacity[0] != vertex_opacity[3]) {
108 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width(); 129 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width();
109 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height(); 130 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height();
(...skipping 13 matching lines...) Expand all
123 clippedRect -= offset; 144 clippedRect -= offset;
124 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); 145 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale);
125 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f), 146 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f),
126 static_cast<int>(clippedRect.y() + 0.5f), 147 static_cast<int>(clippedRect.y() + 0.5f),
127 static_cast<int>(clippedRect.width() + 0.5f), 148 static_cast<int>(clippedRect.width() + 0.5f),
128 static_cast<int>(clippedRect.height() + 0.5f)); 149 static_cast<int>(clippedRect.height() + 0.5f));
129 return true; 150 return true;
130 } 151 }
131 152
132 } // namespace cc 153 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_draw_quad.h ('k') | cc/texture_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698