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

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

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

Powered by Google App Engine
This is Rietveld 408576698