Chromium Code Reviews| 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/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 | 70 |
| 71 image_aperture_ = aperture; | 71 image_aperture_ = aperture; |
| 72 border_ = border; | 72 border_ = border; |
| 73 fill_center_ = fill_center; | 73 fill_center_ = fill_center; |
| 74 nearest_neighbor_ = nearest_neighbor; | 74 nearest_neighbor_ = nearest_neighbor; |
| 75 layer_occlusion_ = layer_occlusion; | 75 layer_occlusion_ = layer_occlusion; |
| 76 | 76 |
| 77 NoteLayerPropertyChanged(); | 77 NoteLayerPropertyChanged(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool NinePatchLayerImpl::CanUseOcclusion() { | |
| 81 if (layer_occlusion_.IsEmpty()) | |
| 82 return false; | |
| 83 | |
| 84 if (fill_center_) | |
| 85 return false; | |
| 86 | |
| 87 if (border_.x() == 0 || border_.y() == 0 || | |
|
aelias_OOO_until_Jul13
2016/05/05 04:17:57
All this state is known to the client-side code in
llandwerlin-old
2016/05/06 16:26:48
Done.
| |
| 88 (border_.width() - border_.x()) == 0 || | |
| 89 (border_.height() - border_.y()) == 0) | |
| 90 return false; | |
| 91 | |
| 92 if (layer_occlusion_.x() == 0 || layer_occlusion_.y() == 0 || | |
| 93 layer_occlusion_.right() == bounds().width() || | |
| 94 layer_occlusion_.bottom() == bounds().height()) | |
| 95 return false; | |
| 96 | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 80 void NinePatchLayerImpl::CheckGeometryLimitations() { | 100 void NinePatchLayerImpl::CheckGeometryLimitations() { |
| 81 // |border| is in layer space. It cannot exceed the bounds of the layer. | 101 // |border| is in layer space. It cannot exceed the bounds of the layer. |
| 82 DCHECK_GE(bounds().width(), border_.width()); | 102 DCHECK_GE(bounds().width(), border_.width()); |
| 83 DCHECK_GE(bounds().height(), border_.height()); | 103 DCHECK_GE(bounds().height(), border_.height()); |
| 84 | 104 |
| 85 // Sanity Check on |border| | 105 // Sanity Check on |border| |
| 86 DCHECK_LE(border_.x(), border_.width()); | 106 DCHECK_LE(border_.x(), border_.width()); |
| 87 DCHECK_LE(border_.y(), border_.height()); | 107 DCHECK_LE(border_.y(), border_.height()); |
| 88 DCHECK_GE(border_.x(), 0); | 108 DCHECK_GE(border_.x(), 0); |
| 89 DCHECK_GE(border_.y(), 0); | 109 DCHECK_GE(border_.y(), 0); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 171 | 191 |
| 172 return patches; | 192 return patches; |
| 173 } | 193 } |
| 174 | 194 |
| 175 std::vector<NinePatchLayerImpl::Patch> | 195 std::vector<NinePatchLayerImpl::Patch> |
| 176 NinePatchLayerImpl::ComputeQuadsWithOcclusion() const { | 196 NinePatchLayerImpl::ComputeQuadsWithOcclusion() const { |
| 177 float image_width = image_bounds_.width(); | 197 float image_width = image_bounds_.width(); |
| 178 float image_height = image_bounds_.height(); | 198 float image_height = image_bounds_.height(); |
| 179 int layer_width = bounds().width(); | 199 int layer_width = bounds().width(); |
| 180 int layer_height = bounds().height(); | 200 int layer_height = bounds().height(); |
| 181 gfx::Rect image_occlusion( | 201 int layer_border_right = border_.width() - border_.x(); |
| 182 BoundsToRect(layer_occlusion_.x(), layer_occlusion_.y(), | 202 int layer_border_bottom = border_.height() - border_.y(); |
| 183 image_width - (layer_width - layer_occlusion_.right()), | 203 int image_aperture_right = image_width - image_aperture_.right(); |
| 184 image_height - (layer_height - layer_occlusion_.bottom()))); | 204 int image_aperture_bottom = image_height - image_aperture_.bottom(); |
| 185 gfx::Rect layer_aperture( | 205 int layer_occlusion_right = layer_width - layer_occlusion_.right(); |
| 186 BoundsToRect(image_aperture_.x(), image_aperture_.y(), | 206 int layer_occlusion_bottom = layer_height - layer_occlusion_.bottom(); |
| 187 layer_width - (image_width - image_aperture_.right()), | 207 gfx::Rect image_occlusion(BoundsToRect( |
| 188 layer_height - (image_height - image_aperture_.bottom()))); | 208 layer_occlusion_.x() * image_aperture_.x() / border_.x(), |
| 209 layer_occlusion_.y() * image_aperture_.y() / border_.y(), | |
| 210 image_width - | |
| 211 layer_occlusion_right * image_aperture_right / layer_border_right, | |
| 212 image_height - | |
| 213 layer_occlusion_bottom * image_aperture_bottom / | |
| 214 layer_border_bottom)); | |
| 215 gfx::Rect layer_aperture(border_.x(), border_.y(), | |
| 216 layer_width - border_.width(), | |
| 217 layer_height - border_.height()); | |
| 189 | 218 |
| 190 std::vector<Patch> patches; | 219 std::vector<Patch> patches; |
| 191 patches.reserve(kMaxOcclusionPatches); | 220 patches.reserve(kMaxOcclusionPatches); |
| 192 | 221 |
| 193 // Top-left-left. | 222 // Top-left-left. |
| 194 patches.push_back( | 223 patches.push_back( |
| 195 Patch(BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()), | 224 Patch(BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()), |
| 196 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()))); | 225 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()))); |
| 197 | 226 |
| 198 // Top-left-right. | 227 // Top-left-right. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 ResourceId resource = | 319 ResourceId resource = |
| 291 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | 320 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
| 292 | 321 |
| 293 if (!resource) | 322 if (!resource) |
| 294 return; | 323 return; |
| 295 | 324 |
| 296 DCHECK(!bounds().IsEmpty()); | 325 DCHECK(!bounds().IsEmpty()); |
| 297 | 326 |
| 298 std::vector<Patch> patches; | 327 std::vector<Patch> patches; |
| 299 | 328 |
| 300 if (!layer_occlusion_.IsEmpty() && border_.IsEmpty() && !fill_center_) | 329 if (CanUseOcclusion()) |
| 301 patches = ComputeQuadsWithOcclusion(); | 330 patches = ComputeQuadsWithOcclusion(); |
| 302 else | 331 else |
| 303 patches = ComputeQuadsWithoutOcclusion(); | 332 patches = ComputeQuadsWithoutOcclusion(); |
| 304 | 333 |
| 305 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 334 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 306 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); | 335 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); |
| 307 static const bool flipped = false; | 336 static const bool flipped = false; |
| 308 static const bool premultiplied_alpha = true; | 337 static const bool premultiplied_alpha = true; |
| 309 | 338 |
| 310 for (const auto& patch : patches) { | 339 for (const auto& patch : patches) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 list->AppendInteger(layer_occlusion_.x()); | 383 list->AppendInteger(layer_occlusion_.x()); |
| 355 list->AppendInteger(layer_occlusion_.y()); | 384 list->AppendInteger(layer_occlusion_.y()); |
| 356 list->AppendInteger(layer_occlusion_.width()); | 385 list->AppendInteger(layer_occlusion_.width()); |
| 357 list->AppendInteger(layer_occlusion_.height()); | 386 list->AppendInteger(layer_occlusion_.height()); |
| 358 result->Set("LayerOcclusion", list); | 387 result->Set("LayerOcclusion", list); |
| 359 | 388 |
| 360 return result; | 389 return result; |
| 361 } | 390 } |
| 362 | 391 |
| 363 } // namespace cc | 392 } // namespace cc |
| OLD | NEW |