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

Side by Side Diff: cc/layers/nine_patch_layer_impl.cc

Issue 1889153002: cc: nine patch: add occlusion support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Daniel's nits Created 4 years, 8 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
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/layers/nine_patch_layer_impl.h" 5 #include "cc/layers/nine_patch_layer_impl.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/quads/solid_color_draw_quad.h"
10 #include "cc/quads/texture_draw_quad.h" 11 #include "cc/quads/texture_draw_quad.h"
11 #include "cc/trees/layer_tree_impl.h" 12 #include "cc/trees/layer_tree_impl.h"
12 #include "cc/trees/occlusion.h" 13 #include "cc/trees/occlusion.h"
13 #include "ui/gfx/geometry/rect_f.h" 14 #include "ui/gfx/geometry/rect_f.h"
14 15
15 namespace cc { 16 namespace cc {
16 17
18 // Maximum number of patches that can be produced for one NinePatchLayer.
19 static const int kMaxPatches = 12;
20
17 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) 21 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
18 : UIResourceLayerImpl(tree_impl, id), 22 : UIResourceLayerImpl(tree_impl, id),
19 fill_center_(false), 23 fill_center_(false),
20 nearest_neighbor_(false) {} 24 nearest_neighbor_(false) {}
21 25
22 NinePatchLayerImpl::~NinePatchLayerImpl() {} 26 NinePatchLayerImpl::~NinePatchLayerImpl() {}
23 27
24 scoped_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl( 28 scoped_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl(
25 LayerTreeImpl* tree_impl) { 29 LayerTreeImpl* tree_impl) {
26 return NinePatchLayerImpl::Create(tree_impl, id()); 30 return NinePatchLayerImpl::Create(tree_impl, id());
27 } 31 }
28 32
29 void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { 33 void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) {
30 UIResourceLayerImpl::PushPropertiesTo(layer); 34 UIResourceLayerImpl::PushPropertiesTo(layer);
31 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); 35 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
32 36
33 layer_impl->SetLayout(image_aperture_, border_, fill_center_, 37 layer_impl->SetLayout(image_aperture_, border_, fill_center_,
34 nearest_neighbor_); 38 nearest_neighbor_, layer_occlusion_);
35 } 39 }
36 40
37 static gfx::RectF NormalizedRect(float x, 41 static gfx::Rect BoundsToRect(int x1, int y1, int x2, int y2) {
38 float y, 42 return gfx::Rect(x1, y1, x2 - x1, y2 - y1);
39 float width, 43 }
40 float height, 44
45 static gfx::RectF NormalizedRect(const gfx::Rect& rect,
aelias_OOO_until_Jul13 2016/04/20 05:54:57 This argument change loses precision, use a gfx::R
llandwerlin-old 2016/04/21 09:53:14 I could be missing something, but I don't think we
41 float total_width, 46 float total_width,
42 float total_height) { 47 float total_height) {
43 return gfx::RectF(x / total_width, 48 return gfx::RectF(rect.x() / total_width, rect.y() / total_height,
44 y / total_height, 49 rect.width() / total_width, rect.height() / total_height);
45 width / total_width,
46 height / total_height);
47 } 50 }
48 51
49 void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, 52 void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture,
50 const gfx::Rect& border, 53 const gfx::Rect& border,
51 bool fill_center, 54 bool fill_center,
52 bool nearest_neighbor) { 55 bool nearest_neighbor,
56 const gfx::Rect& layer_occlusion) {
53 // This check imposes an ordering on the call sequence. An UIResource must 57 // This check imposes an ordering on the call sequence. An UIResource must
54 // exist before SetLayout can be called. 58 // exist before SetLayout can be called.
55 DCHECK(ui_resource_id_); 59 DCHECK(ui_resource_id_);
56 60
57 if (image_aperture_ == aperture && border_ == border && 61 if (image_aperture_ == aperture && border_ == border &&
58 fill_center_ == fill_center && nearest_neighbor_ == nearest_neighbor) 62 fill_center_ == fill_center && nearest_neighbor_ == nearest_neighbor &&
63 layer_occlusion_ == layer_occlusion)
59 return; 64 return;
60 65
61 image_aperture_ = aperture; 66 image_aperture_ = aperture;
62 border_ = border; 67 border_ = border;
63 fill_center_ = fill_center; 68 fill_center_ = fill_center;
64 nearest_neighbor_ = nearest_neighbor; 69 nearest_neighbor_ = nearest_neighbor;
70 layer_occlusion_ = layer_occlusion;
65 71
66 NoteLayerPropertyChanged(); 72 NoteLayerPropertyChanged();
67 } 73 }
68 74
69 void NinePatchLayerImpl::CheckGeometryLimitations() { 75 void NinePatchLayerImpl::CheckGeometryLimitations() {
70 // |border| is in layer space. It cannot exceed the bounds of the layer. 76 // |border| is in layer space. It cannot exceed the bounds of the layer.
71 DCHECK_GE(bounds().width(), border_.width()); 77 DCHECK_GE(bounds().width(), border_.width());
72 DCHECK_GE(bounds().height(), border_.height()); 78 DCHECK_GE(bounds().height(), border_.height());
73 79
74 // Sanity Check on |border| 80 // Sanity Check on |border|
75 DCHECK_LE(border_.x(), border_.width()); 81 DCHECK_LE(border_.x(), border_.width());
76 DCHECK_LE(border_.y(), border_.height()); 82 DCHECK_LE(border_.y(), border_.height());
77 DCHECK_GE(border_.x(), 0); 83 DCHECK_GE(border_.x(), 0);
78 DCHECK_GE(border_.y(), 0); 84 DCHECK_GE(border_.y(), 0);
79 85
80 // |aperture| is in image space. It cannot exceed the bounds of the bitmap. 86 // |aperture| is in image space. It cannot exceed the bounds of the bitmap.
81 DCHECK(!image_aperture_.size().IsEmpty()); 87 DCHECK(!image_aperture_.size().IsEmpty());
82 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) 88 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_))
83 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() 89 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString()
84 << " image_aperture_ " << image_aperture_.ToString(); 90 << " image_aperture_ " << image_aperture_.ToString();
85 } 91 }
86 92
93 void NinePatchLayerImpl::AppendQuadsWithoutOcclusion(
aelias_OOO_until_Jul13 2016/04/20 05:54:57 These functions aren't actually appending the quad
llandwerlin-old 2016/04/21 09:53:14 Done.
94 RenderPass* render_pass,
aelias_OOO_until_Jul13 2016/04/20 05:54:57 This doesn't use render_pass, resource or shared_q
llandwerlin-old 2016/04/21 09:53:14 Done.
95 ResourceId resource,
96 SharedQuadState* shared_quad_state,
97 std::vector<gfx::Rect>* image_rects,
98 std::vector<gfx::Rect>* layer_rects) {
99 // Utility values.
100 float image_width = image_bounds_.width();
101 float image_height = image_bounds_.height();
102 int layer_width = bounds().width();
103 int layer_height = bounds().height();
104 gfx::Rect layer_aperture(border_.x(), border_.y(),
105 layer_width - border_.width(),
106 layer_height - border_.height());
107
108 // Top-left.
109 image_rects->push_back(
110 BoundsToRect(0, 0, image_aperture_.x(), image_aperture_.y()));
111 layer_rects->push_back(
112 BoundsToRect(0, 0, layer_aperture.x(), layer_aperture.y()));
113
114 // Top-right.
115 image_rects->push_back(BoundsToRect(image_aperture_.right(), 0, image_width,
116 image_aperture_.y()));
117 layer_rects->push_back(
118 BoundsToRect(layer_aperture.right(), 0, layer_width, layer_aperture.y()));
119
120 // Bottom-left.
121 image_rects->push_back(BoundsToRect(0, image_aperture_.bottom(),
122 image_aperture_.x(), image_height));
123 layer_rects->push_back(BoundsToRect(0, layer_aperture.bottom(),
124 layer_aperture.x(), layer_height));
125
126 // Bottom-right.
127 image_rects->push_back(BoundsToRect(image_aperture_.right(),
128 image_aperture_.bottom(), image_width,
129 image_height));
130 layer_rects->push_back(BoundsToRect(layer_aperture.right(),
131 layer_aperture.bottom(), layer_width,
132 layer_height));
133
134 // Top.
135 image_rects->push_back(BoundsToRect(
136 image_aperture_.x(), 0, image_aperture_.right(), image_aperture_.y()));
137 layer_rects->push_back(BoundsToRect(
138 layer_aperture.x(), 0, layer_aperture.right(), layer_aperture.y()));
139
140 // Left.
141 image_rects->push_back(BoundsToRect(
142 0, image_aperture_.y(), image_aperture_.x(), image_aperture_.bottom()));
143 layer_rects->push_back(BoundsToRect(0, layer_aperture.y(), layer_aperture.x(),
144 layer_aperture.bottom()));
145
146 // Right.
147 image_rects->push_back(BoundsToRect(image_aperture_.right(),
148 image_aperture_.y(), image_width,
149 image_aperture_.bottom()));
150 layer_rects->push_back(BoundsToRect(layer_aperture.right(),
151 layer_aperture.y(), layer_width,
152 layer_aperture.bottom()));
153
154 // Bottom.
155 image_rects->push_back(BoundsToRect(image_aperture_.x(),
156 image_aperture_.bottom(),
157 image_aperture_.right(), image_height));
158 layer_rects->push_back(BoundsToRect(layer_aperture.x(),
159 layer_aperture.bottom(),
160 layer_aperture.right(), layer_height));
161
162 // Center.
163 if (fill_center_) {
164 image_rects->push_back(
165 BoundsToRect(image_aperture_.x(), image_aperture_.y(),
166 image_aperture_.right(), image_aperture_.bottom()));
167 layer_rects->push_back(BoundsToRect(layer_aperture.x(), layer_aperture.y(),
168 layer_aperture.right(),
169 layer_aperture.bottom()));
170 }
171 }
172
173 void NinePatchLayerImpl::AppendQuadsWithOcclusion(
174 RenderPass* render_pass,
175 ResourceId resource,
176 SharedQuadState* shared_quad_state,
177 std::vector<gfx::Rect>* image_rects,
178 std::vector<gfx::Rect>* layer_rects) {
179 // Helper values.
180 float image_width = image_bounds_.width();
181 float image_height = image_bounds_.height();
182 int layer_width = bounds().width();
183 int layer_height = bounds().height();
184 gfx::Rect image_occlusion(
185 BoundsToRect(layer_occlusion_.x(), layer_occlusion_.y(),
186 image_width - (layer_width - layer_occlusion_.right()),
187 image_height - (layer_height - layer_occlusion_.bottom())));
188 gfx::Rect layer_aperture(
189 BoundsToRect(image_aperture_.x(), image_aperture_.y(),
190 layer_width - (image_width - image_aperture_.right()),
191 layer_height - (image_height - image_aperture_.bottom())));
192
193 // Top-left-left.
194 image_rects->push_back(
195 BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()));
196 layer_rects->push_back(
197 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()));
198
199 // Top-left-right.
200 image_rects->push_back(BoundsToRect(
201 image_occlusion.x(), 0, image_aperture_.x(), image_occlusion.y()));
202 layer_rects->push_back(BoundsToRect(
203 layer_occlusion_.x(), 0, layer_aperture.x(), layer_occlusion_.y()));
204
205 // Top-center.
206 image_rects->push_back(BoundsToRect(
207 image_aperture_.x(), 0, image_aperture_.right(), image_occlusion.y()));
208 layer_rects->push_back(BoundsToRect(
209 layer_aperture.x(), 0, layer_aperture.right(), layer_occlusion_.y()));
210
211 // Top-right-left.
212 image_rects->push_back(BoundsToRect(image_aperture_.right(), 0,
213 image_occlusion.right(),
214 image_occlusion.y()));
215 layer_rects->push_back(BoundsToRect(layer_aperture.right(), 0,
216 layer_occlusion_.right(),
217 layer_occlusion_.y()));
218
219 // Top-right-right.
220 image_rects->push_back(BoundsToRect(image_occlusion.right(), 0, image_width,
221 image_aperture_.y()));
222 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(), 0, layer_width,
223 layer_aperture.y()));
224
225 // Right-center.
226 image_rects->push_back(BoundsToRect(
227 0, image_aperture_.y(), image_occlusion.x(), image_aperture_.bottom()));
228 layer_rects->push_back(BoundsToRect(
229 0, layer_aperture.y(), layer_occlusion_.x(), layer_aperture.bottom()));
230
231 // Left-center.
232 image_rects->push_back(BoundsToRect(image_occlusion.right(),
233 image_aperture_.y(), image_width,
234 image_aperture_.bottom()));
235 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(),
236 layer_aperture.y(), layer_width,
237 layer_aperture.bottom()));
238
239 // Bottom-left-left.
240 image_rects->push_back(BoundsToRect(0, image_aperture_.bottom(),
241 image_occlusion.x(), image_height));
242 layer_rects->push_back(BoundsToRect(0, layer_aperture.bottom(),
243 layer_occlusion_.x(), layer_height));
244
245 // Bottom-left-right.
246 image_rects->push_back(BoundsToRect(image_occlusion.x(),
247 image_occlusion.bottom(),
248 image_aperture_.x(), image_height));
249 layer_rects->push_back(BoundsToRect(layer_occlusion_.x(),
250 layer_occlusion_.bottom(),
251 layer_aperture.x(), layer_height));
252
253 // Bottom-center.
254 image_rects->push_back(BoundsToRect(image_aperture_.x(),
255 image_occlusion.bottom(),
256 image_aperture_.right(), image_height));
257 layer_rects->push_back(BoundsToRect(layer_aperture.x(),
258 layer_occlusion_.bottom(),
259 layer_aperture.right(), layer_height));
260
261 // Bottom-right-left.
262 image_rects->push_back(BoundsToRect(image_aperture_.right(),
263 image_occlusion.bottom(),
264 image_occlusion.right(), image_height));
265 layer_rects->push_back(BoundsToRect(layer_aperture.right(),
266 layer_occlusion_.bottom(),
267 layer_occlusion_.right(), layer_height));
268
269 // Bottom-right-right.
270 image_rects->push_back(BoundsToRect(image_occlusion.right(),
271 image_aperture_.bottom(), image_width,
272 image_height));
273 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(),
274 layer_aperture.bottom(), layer_width,
275 layer_height));
276 }
277
87 void NinePatchLayerImpl::AppendQuads( 278 void NinePatchLayerImpl::AppendQuads(
88 RenderPass* render_pass, 279 RenderPass* render_pass,
89 AppendQuadsData* append_quads_data) { 280 AppendQuadsData* append_quads_data) {
90 CheckGeometryLimitations(); 281 CheckGeometryLimitations();
91 SharedQuadState* shared_quad_state = 282 SharedQuadState* shared_quad_state =
92 render_pass->CreateAndAppendSharedQuadState(); 283 render_pass->CreateAndAppendSharedQuadState();
93 PopulateSharedQuadState(shared_quad_state); 284 PopulateSharedQuadState(shared_quad_state);
94 285
95 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, 286 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state,
96 append_quads_data); 287 append_quads_data);
97 288
98 if (!ui_resource_id_) 289 if (!ui_resource_id_)
99 return; 290 return;
100 291
101 ResourceId resource = 292 ResourceId resource =
102 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); 293 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
103 294
104 if (!resource) 295 if (!resource)
105 return; 296 return;
106 297
107 static const bool flipped = false;
108 static const bool premultiplied_alpha = true;
109
110 DCHECK(!bounds().IsEmpty()); 298 DCHECK(!bounds().IsEmpty());
111 299
112 // NinePatch border widths in layer space. 300 // Patch positions in bitmap UV space (from zero to one).
113 int layer_left_width = border_.x(); 301 std::vector<gfx::Rect> image_rects;
114 int layer_top_height = border_.y(); 302 image_rects.reserve(kMaxPatches);
115 int layer_right_width = border_.width() - layer_left_width; 303 // Patch positions in layer space.
116 int layer_bottom_height = border_.height() - layer_top_height; 304 std::vector<gfx::Rect> layer_rects;
305 layer_rects.reserve(kMaxPatches);
117 306
118 int layer_middle_width = bounds().width() - border_.width(); 307 if (!layer_occlusion_.IsEmpty() && border_.IsEmpty() && !fill_center_)
119 int layer_middle_height = bounds().height() - border_.height(); 308 AppendQuadsWithOcclusion(render_pass, resource, shared_quad_state,
309 &image_rects, &layer_rects);
310 else
311 AppendQuadsWithoutOcclusion(render_pass, resource, shared_quad_state,
312 &image_rects, &layer_rects);
120 313
121 // Patch positions in layer space 314 DCHECK_EQ(image_rects.size(), layer_rects.size());
122 gfx::Rect layer_top_left(0, 0, layer_left_width, layer_top_height);
123 gfx::Rect layer_top_right(bounds().width() - layer_right_width,
124 0,
125 layer_right_width,
126 layer_top_height);
127 gfx::Rect layer_bottom_left(0,
128 bounds().height() - layer_bottom_height,
129 layer_left_width,
130 layer_bottom_height);
131 gfx::Rect layer_bottom_right(layer_top_right.x(),
132 layer_bottom_left.y(),
133 layer_right_width,
134 layer_bottom_height);
135 gfx::Rect layer_top(
136 layer_top_left.right(), 0, layer_middle_width, layer_top_height);
137 gfx::Rect layer_left(
138 0, layer_top_left.bottom(), layer_left_width, layer_middle_height);
139 gfx::Rect layer_right(layer_top_right.x(),
140 layer_top_right.bottom(),
141 layer_right_width,
142 layer_left.height());
143 gfx::Rect layer_bottom(layer_top.x(),
144 layer_bottom_left.y(),
145 layer_top.width(),
146 layer_bottom_height);
147 gfx::Rect layer_center(layer_left_width,
148 layer_top_height,
149 layer_middle_width,
150 layer_middle_height);
151
152 // Note the following values are in image (bitmap) space.
153 float image_width = image_bounds_.width();
154 float image_height = image_bounds_.height();
155
156 int image_aperture_left_width = image_aperture_.x();
157 int image_aperture_top_height = image_aperture_.y();
158 int image_aperture_right_width = image_width - image_aperture_.right();
159 int image_aperture_bottom_height = image_height - image_aperture_.bottom();
160 // Patch positions in bitmap UV space (from zero to one)
161 gfx::RectF uv_top_left = NormalizedRect(0,
162 0,
163 image_aperture_left_width,
164 image_aperture_top_height,
165 image_width,
166 image_height);
167 gfx::RectF uv_top_right =
168 NormalizedRect(image_width - image_aperture_right_width,
169 0,
170 image_aperture_right_width,
171 image_aperture_top_height,
172 image_width,
173 image_height);
174 gfx::RectF uv_bottom_left =
175 NormalizedRect(0,
176 image_height - image_aperture_bottom_height,
177 image_aperture_left_width,
178 image_aperture_bottom_height,
179 image_width,
180 image_height);
181 gfx::RectF uv_bottom_right =
182 NormalizedRect(image_width - image_aperture_right_width,
183 image_height - image_aperture_bottom_height,
184 image_aperture_right_width,
185 image_aperture_bottom_height,
186 image_width,
187 image_height);
188 gfx::RectF uv_top(
189 uv_top_left.right(),
190 0,
191 (image_width - image_aperture_left_width - image_aperture_right_width) /
192 image_width,
193 (image_aperture_top_height) / image_height);
194 gfx::RectF uv_left(0,
195 uv_top_left.bottom(),
196 image_aperture_left_width / image_width,
197 (image_height - image_aperture_top_height -
198 image_aperture_bottom_height) /
199 image_height);
200 gfx::RectF uv_right(uv_top_right.x(),
201 uv_top_right.bottom(),
202 image_aperture_right_width / image_width,
203 uv_left.height());
204 gfx::RectF uv_bottom(uv_top.x(),
205 uv_bottom_left.y(),
206 uv_top.width(),
207 image_aperture_bottom_height / image_height);
208 gfx::RectF uv_center(uv_top_left.right(),
209 uv_top_left.bottom(),
210 uv_top.width(),
211 uv_left.height());
212 315
213 gfx::Rect opaque_rect; 316 gfx::Rect opaque_rect;
214 gfx::Rect visible_rect; 317 gfx::Rect visible_rect;
215 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; 318 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
216 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); 319 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_);
320 static const bool flipped = false;
321 static const bool premultiplied_alpha = true;
217 322
218 visible_rect = 323 for (size_t i = 0; i < image_rects.size(); i++) {
219 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( 324 const gfx::Rect& layer_rect(layer_rects[i]);
220 layer_top_left);
221 opaque_rect = opaque ? visible_rect : gfx::Rect();
222 if (!visible_rect.IsEmpty()) {
223 TextureDrawQuad* quad =
224 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
225 quad->SetNew(shared_quad_state, layer_top_left, opaque_rect, visible_rect,
226 resource, premultiplied_alpha, uv_top_left.origin(),
227 uv_top_left.bottom_right(), SK_ColorTRANSPARENT,
228 vertex_opacity, flipped, nearest_neighbor_);
229 ValidateQuadResources(quad);
230 }
231 325
232 visible_rect =
233 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
234 layer_top_right);
235 opaque_rect = opaque ? visible_rect : gfx::Rect();
236 if (!visible_rect.IsEmpty()) {
237 TextureDrawQuad* quad =
238 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
239 quad->SetNew(shared_quad_state, layer_top_right, opaque_rect, visible_rect,
240 resource, premultiplied_alpha, uv_top_right.origin(),
241 uv_top_right.bottom_right(), SK_ColorTRANSPARENT,
242 vertex_opacity, flipped, nearest_neighbor_);
243 ValidateQuadResources(quad);
244 }
245
246 visible_rect =
247 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
248 layer_bottom_left);
249 opaque_rect = opaque ? visible_rect : gfx::Rect();
250 if (!visible_rect.IsEmpty()) {
251 TextureDrawQuad* quad =
252 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
253 quad->SetNew(shared_quad_state, layer_bottom_left, opaque_rect,
254 visible_rect, resource, premultiplied_alpha,
255 uv_bottom_left.origin(), uv_bottom_left.bottom_right(),
256 SK_ColorTRANSPARENT, vertex_opacity, flipped,
257 nearest_neighbor_);
258 ValidateQuadResources(quad);
259 }
260
261 visible_rect =
262 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
263 layer_bottom_right);
264 opaque_rect = opaque ? visible_rect : gfx::Rect();
265 if (!visible_rect.IsEmpty()) {
266 TextureDrawQuad* quad =
267 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
268 quad->SetNew(shared_quad_state, layer_bottom_right, opaque_rect,
269 visible_rect, resource, premultiplied_alpha,
270 uv_bottom_right.origin(), uv_bottom_right.bottom_right(),
271 SK_ColorTRANSPARENT, vertex_opacity, flipped,
272 nearest_neighbor_);
273 ValidateQuadResources(quad);
274 }
275
276 visible_rect =
277 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
278 layer_top);
279 opaque_rect = opaque ? visible_rect : gfx::Rect();
280 if (!visible_rect.IsEmpty()) {
281 TextureDrawQuad* quad =
282 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
283 quad->SetNew(shared_quad_state, layer_top, opaque_rect, visible_rect,
284 resource, premultiplied_alpha, uv_top.origin(),
285 uv_top.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity,
286 flipped, nearest_neighbor_);
287 ValidateQuadResources(quad);
288 }
289
290 visible_rect =
291 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
292 layer_left);
293 opaque_rect = opaque ? visible_rect : gfx::Rect();
294 if (!visible_rect.IsEmpty()) {
295 TextureDrawQuad* quad =
296 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
297 quad->SetNew(shared_quad_state, layer_left, opaque_rect, visible_rect,
298 resource, premultiplied_alpha, uv_left.origin(),
299 uv_left.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity,
300 flipped, nearest_neighbor_);
301 ValidateQuadResources(quad);
302 }
303
304 visible_rect =
305 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
306 layer_right);
307 opaque_rect = opaque ? visible_rect : gfx::Rect();
308 if (!visible_rect.IsEmpty()) {
309 TextureDrawQuad* quad =
310 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
311 quad->SetNew(shared_quad_state, layer_right, opaque_rect, layer_right,
312 resource, premultiplied_alpha, uv_right.origin(),
313 uv_right.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity,
314 flipped, nearest_neighbor_);
315 ValidateQuadResources(quad);
316 }
317
318 visible_rect =
319 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
320 layer_bottom);
321 opaque_rect = opaque ? visible_rect : gfx::Rect();
322 if (!visible_rect.IsEmpty()) {
323 TextureDrawQuad* quad =
324 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
325 quad->SetNew(shared_quad_state, layer_bottom, opaque_rect, visible_rect,
326 resource, premultiplied_alpha, uv_bottom.origin(),
327 uv_bottom.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity,
328 flipped, nearest_neighbor_);
329 ValidateQuadResources(quad);
330 }
331
332 if (fill_center_) {
333 visible_rect = 326 visible_rect =
334 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( 327 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect(
335 layer_center); 328 layer_rect);
336 opaque_rect = opaque ? visible_rect : gfx::Rect(); 329 opaque_rect = opaque ? visible_rect : gfx::Rect();
337 if (!visible_rect.IsEmpty()) { 330 if (!visible_rect.IsEmpty()) {
331 gfx::RectF image_rect(NormalizedRect(
332 image_rects[i], image_bounds_.width(), image_bounds_.height()));
338 TextureDrawQuad* quad = 333 TextureDrawQuad* quad =
339 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); 334 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
340 quad->SetNew(shared_quad_state, layer_center, opaque_rect, visible_rect, 335 quad->SetNew(shared_quad_state, layer_rect, opaque_rect, visible_rect,
341 resource, premultiplied_alpha, uv_center.origin(), 336 resource, premultiplied_alpha, image_rect.origin(),
342 uv_center.bottom_right(), SK_ColorTRANSPARENT, 337 image_rect.bottom_right(), SK_ColorTRANSPARENT,
343 vertex_opacity, flipped, nearest_neighbor_); 338 vertex_opacity, flipped, nearest_neighbor_);
344 ValidateQuadResources(quad); 339 ValidateQuadResources(quad);
345 } 340 }
346 } 341 }
347 } 342 }
348 343
349 const char* NinePatchLayerImpl::LayerTypeAsString() const { 344 const char* NinePatchLayerImpl::LayerTypeAsString() const {
350 return "cc::NinePatchLayerImpl"; 345 return "cc::NinePatchLayerImpl";
351 } 346 }
352 347
353 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { 348 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const {
354 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); 349 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson();
355 350
356 base::ListValue* list = new base::ListValue; 351 base::ListValue* list = new base::ListValue;
357 list->AppendInteger(image_aperture_.origin().x()); 352 list->AppendInteger(image_aperture_.origin().x());
358 list->AppendInteger(image_aperture_.origin().y()); 353 list->AppendInteger(image_aperture_.origin().y());
359 list->AppendInteger(image_aperture_.size().width()); 354 list->AppendInteger(image_aperture_.size().width());
360 list->AppendInteger(image_aperture_.size().height()); 355 list->AppendInteger(image_aperture_.size().height());
361 result->Set("ImageAperture", list); 356 result->Set("ImageAperture", list);
362 357
363 list = new base::ListValue; 358 list = new base::ListValue;
364 list->AppendInteger(image_bounds_.width()); 359 list->AppendInteger(image_bounds_.width());
365 list->AppendInteger(image_bounds_.height()); 360 list->AppendInteger(image_bounds_.height());
366 result->Set("ImageBounds", list); 361 result->Set("ImageBounds", list);
367 362
368 result->Set("Border", MathUtil::AsValue(border_).release()); 363 result->Set("Border", MathUtil::AsValue(border_).release());
369 364
370 result->SetBoolean("FillCenter", fill_center_); 365 result->SetBoolean("FillCenter", fill_center_);
371 366
367 list = new base::ListValue;
368 list->AppendInteger(layer_occlusion_.x());
369 list->AppendInteger(layer_occlusion_.y());
370 list->AppendInteger(layer_occlusion_.width());
371 list->AppendInteger(layer_occlusion_.height());
372 result->Set("LayerOcclusion", list);
373
372 return result; 374 return result;
373 } 375 }
374 376
375 } // namespace cc 377 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698