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