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

Side by Side Diff: cc/texture_draw_quad.cc

Issue 11570027: Adding support for per vertex opacity on textured layer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ping Created 8 years 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, 22 gfx::Rect rect, gfx::Rect opaque_rect,
23 gfx::Rect opaque_rect, 23 unsigned resource_id, bool premultiplied_alpha,
24 unsigned resource_id,
25 bool premultiplied_alpha,
26 const gfx::RectF& uv_rect, 24 const gfx::RectF& uv_rect,
27 bool flipped) { 25 const float vertex_opacity[4], bool flipped) {
28 gfx::Rect visible_rect = rect; 26 gfx::Rect visible_rect = rect;
29 bool needs_blending = false; 27 bool needs_blending = vertex_opacity[0] != 1.0f || vertex_opacity[1] != 1.0f
jamesr 2012/12/15 00:48:19 line's too long - need to stick to 80col
28 || vertex_opacity[2] != 1.0f || vertex_opacity[3] != 1.0f;
30 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 29 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
31 opaque_rect, visible_rect, needs_blending); 30 opaque_rect, visible_rect, needs_blending);
32 this->resource_id = resource_id; 31 this->resource_id = resource_id;
33 this->premultiplied_alpha = premultiplied_alpha; 32 this->premultiplied_alpha = premultiplied_alpha;
34 this->uv_rect = uv_rect; 33 this->uv_rect = uv_rect;
34 this->vertex_opacity[0] = vertex_opacity[0];
35 this->vertex_opacity[1] = vertex_opacity[1];
36 this->vertex_opacity[2] = vertex_opacity[2];
37 this->vertex_opacity[3] = vertex_opacity[3];
35 this->flipped = flipped; 38 this->flipped = flipped;
36 } 39 }
37 40
38 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state, 41 void TextureDrawQuad::SetAll(const SharedQuadState* shared_quad_state,
39 gfx::Rect rect, 42 gfx::Rect rect, gfx::Rect opaque_rect,
40 gfx::Rect opaque_rect, 43 gfx::Rect visible_rect, bool needs_blending,
41 gfx::Rect visible_rect, 44 unsigned resource_id, bool premultiplied_alpha,
42 bool needs_blending,
43 unsigned resource_id,
44 bool premultiplied_alpha,
45 const gfx::RectF& uv_rect, 45 const gfx::RectF& uv_rect,
46 bool flipped) { 46 const float vertex_opacity[4], bool flipped) {
47 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect, 47 DrawQuad::SetAll(shared_quad_state, DrawQuad::TEXTURE_CONTENT, rect,
48 opaque_rect, visible_rect, needs_blending); 48 opaque_rect, visible_rect, needs_blending);
49 this->resource_id = resource_id; 49 this->resource_id = resource_id;
50 this->premultiplied_alpha = premultiplied_alpha; 50 this->premultiplied_alpha = premultiplied_alpha;
51 this->uv_rect = uv_rect; 51 this->uv_rect = uv_rect;
52 this->vertex_opacity[0] = vertex_opacity[0];
53 this->vertex_opacity[1] = vertex_opacity[1];
54 this->vertex_opacity[2] = vertex_opacity[2];
55 this->vertex_opacity[3] = vertex_opacity[3];
52 this->flipped = flipped; 56 this->flipped = flipped;
53 } 57 }
54 58
55 const TextureDrawQuad* TextureDrawQuad::MaterialCast( 59 const TextureDrawQuad* TextureDrawQuad::MaterialCast(const DrawQuad* quad) {
56 const DrawQuad* quad) {
57 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); 60 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT);
58 return static_cast<const TextureDrawQuad*>(quad); 61 return static_cast<const TextureDrawQuad*>(quad);
59 } 62 }
60 63
61 bool TextureDrawQuad::PerformClipping() { 64 bool TextureDrawQuad::PerformClipping() {
62 // This only occurs if the rect is only scaled and translated (and thus still 65 // This only occurs if the rect is only scaled and translated (and thus still
63 // axis aligned). 66 // axis aligned).
64 if (!quadTransform().IsScaleOrTranslation()) 67 if (!quadTransform().IsScaleOrTranslation())
65 return false; 68 return false;
66 69
67 // Grab our scale and make sure it's positive. 70 // Grab our scale and make sure it's positive.
whunt 2012/12/15 00:55:00 We're going to get a collision at some point becau
68 float x_scale = quadTransform().matrix().getDouble(0,0); 71 float x_scale = quadTransform().matrix().getDouble(0, 0);
69 float y_scale = quadTransform().matrix().getDouble(1,1); 72 float y_scale = quadTransform().matrix().getDouble(1, 1);
70 if (x_scale <= 0.0f || y_scale <= 0.0f) 73 if (x_scale <= 0.0f || y_scale <= 0.0f)
71 return false; 74 return false;
72 75
73 // Grab our offset. 76 // Grab our offset.
74 gfx::Vector2dF offset( 77 gfx::Vector2dF offset(quadTransform().matrix().getDouble(0, 3),
75 quadTransform().matrix().getDouble(0,3), 78 quadTransform().matrix().getDouble(1, 3));
76 quadTransform().matrix().getDouble(1,3));
77 79
78 // Transform the rect by the scale and offset. 80 // Transform the rect by the scale and offset.
79 gfx::RectF rectF = rect; 81 gfx::RectF rectF = rect;
80 rectF.Scale(x_scale, y_scale); 82 rectF.Scale(x_scale, y_scale);
81 rectF += offset; 83 rectF += offset;
82 84
83 // Perform clipping and check to see if the result is empty. 85 // Perform clipping and check to see if the result is empty.
84 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); 86 gfx::RectF clippedRect = IntersectRects(rectF, clipRect());
85 if (clippedRect.IsEmpty()) { 87 if (clippedRect.IsEmpty()) {
86 rect = gfx::Rect(); 88 rect = gfx::Rect();
87 uv_rect = gfx::RectF(); 89 uv_rect = gfx::RectF();
88 return true; 90 return true;
89 } 91 }
90 92
91 // Create a new uv-rect by clipping the old one to the new bounds. 93 // Create a new uv-rect by clipping the old one to the new bounds.
92 uv_rect = gfx::RectF( 94 uv_rect = gfx::RectF(
93 uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()), 95 uv_rect.x()
94 uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()), 96 + uv_rect.width() / rectF.width() * (clippedRect.x() - rectF.x()),
95 uv_rect.width () / rectF.width () * clippedRect.width (), 97 uv_rect.y()
98 + uv_rect.height() / rectF.height() * (clippedRect.y() - rectF.y()),
99 uv_rect.width() / rectF.width() * clippedRect.width(),
96 uv_rect.height() / rectF.height() * clippedRect.height()); 100 uv_rect.height() / rectF.height() * clippedRect.height());
97 101
102 // Indexing according to the quad vertex generation:
103 // 1--2
104 // | |
105 // 0--3
106 if (vertex_opacity[0] != vertex_opacity[1]
107 || vertex_opacity[0] != vertex_opacity[2]
108 || vertex_opacity[0] != vertex_opacity[3]) {
109 const float x1 = (clippedRect.x() - rectF.x()) / rectF.width();
110 const float y1 = (clippedRect.y() - rectF.y()) / rectF.height();
111 const float x3 = (clippedRect.right() - rectF.x()) / rectF.width();
112 const float y3 = (clippedRect.bottom() - rectF.y()) / rectF.height();
113 const float x1y1 = x1 * vertex_opacity[2] + (1.0f - x1) * vertex_opacity[1];
114 const float x1y3 = x1 * vertex_opacity[3] + (1.0f - x1) * vertex_opacity[0];
115 const float x3y1 = x3 * vertex_opacity[2] + (1.0f - x3) * vertex_opacity[1];
116 const float x3y3 = x3 * vertex_opacity[3] + (1.0f - x3) * vertex_opacity[0];
117 vertex_opacity[0] = y3 * x1y3 + (1.0f - y3) * x1y1;
118 vertex_opacity[1] = y1 * x1y3 + (1.0f - y1) * x1y1;
119 vertex_opacity[2] = y1 * x3y3 + (1.0f - y1) * x3y1;
120 vertex_opacity[3] = y3 * x3y3 + (1.0f - y3) * x3y1;
121 }
122
98 // Move the clipped rectangle back into its space. 123 // Move the clipped rectangle back into its space.
99 clippedRect -= offset; 124 clippedRect -= offset;
100 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); 125 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale);
101 rect = gfx::Rect( 126 rect = gfx::Rect(static_cast<int>(clippedRect.x() + 0.5f),
102 static_cast<int>(clippedRect.x() + 0.5f), 127 static_cast<int>(clippedRect.y() + 0.5f),
103 static_cast<int>(clippedRect.y() + 0.5f), 128 static_cast<int>(clippedRect.width() + 0.5f),
104 static_cast<int>(clippedRect.width() + 0.5f), 129 static_cast<int>(clippedRect.height() + 0.5f));
105 static_cast<int>(clippedRect.height() + 0.5f));
106 return true; 130 return true;
107 } 131 }
108 132
109 } // namespace cc 133 } // namespace cc
OLDNEW
« cc/shader.cc ('K') | « 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