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

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