| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 DCHECK_LE(border_.x(), border_.width()); | 86 DCHECK_LE(border_.x(), border_.width()); |
| 87 DCHECK_LE(border_.y(), border_.height()); | 87 DCHECK_LE(border_.y(), border_.height()); |
| 88 DCHECK_GE(border_.x(), 0); | 88 DCHECK_GE(border_.x(), 0); |
| 89 DCHECK_GE(border_.y(), 0); | 89 DCHECK_GE(border_.y(), 0); |
| 90 | 90 |
| 91 // |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. |
| 92 DCHECK(!image_aperture_.size().IsEmpty()); | 92 DCHECK(!image_aperture_.size().IsEmpty()); |
| 93 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) | 93 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) |
| 94 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() | 94 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() |
| 95 << " image_aperture_ " << image_aperture_.ToString(); | 95 << " image_aperture_ " << image_aperture_.ToString(); |
| 96 |
| 97 // Sanity check on |layer_occlusion_|. It should always be within the |
| 98 // border. |
| 99 gfx::Rect border_rect(border_.x(), border_.y(), |
| 100 bounds().width() - border_.width(), |
| 101 bounds().height() - border_.height()); |
| 102 DCHECK(layer_occlusion_.IsEmpty() || layer_occlusion_.Contains(border_rect)) |
| 103 << "border_rect " << border_rect.ToString() << " layer_occlusion_ " |
| 104 << layer_occlusion_.ToString(); |
| 96 } | 105 } |
| 97 | 106 |
| 98 std::vector<NinePatchLayerImpl::Patch> | 107 std::vector<NinePatchLayerImpl::Patch> |
| 99 NinePatchLayerImpl::ComputeQuadsWithoutOcclusion() const { | 108 NinePatchLayerImpl::ComputeQuadsWithoutOcclusion() const { |
| 100 float image_width = image_bounds_.width(); | 109 float image_width = image_bounds_.width(); |
| 101 float image_height = image_bounds_.height(); | 110 float image_height = image_bounds_.height(); |
| 102 int layer_width = bounds().width(); | 111 int layer_width = bounds().width(); |
| 103 int layer_height = bounds().height(); | 112 int layer_height = bounds().height(); |
| 104 gfx::Rect layer_aperture(border_.x(), border_.y(), | 113 gfx::Rect layer_aperture(border_.x(), border_.y(), |
| 105 layer_width - border_.width(), | 114 layer_width - border_.width(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 image_aperture_.right(), image_aperture_.bottom()), | 176 image_aperture_.right(), image_aperture_.bottom()), |
| 168 BoundsToRect(layer_aperture.x(), layer_aperture.y(), | 177 BoundsToRect(layer_aperture.x(), layer_aperture.y(), |
| 169 layer_aperture.right(), layer_aperture.bottom()))); | 178 layer_aperture.right(), layer_aperture.bottom()))); |
| 170 } | 179 } |
| 171 | 180 |
| 172 return patches; | 181 return patches; |
| 173 } | 182 } |
| 174 | 183 |
| 175 std::vector<NinePatchLayerImpl::Patch> | 184 std::vector<NinePatchLayerImpl::Patch> |
| 176 NinePatchLayerImpl::ComputeQuadsWithOcclusion() const { | 185 NinePatchLayerImpl::ComputeQuadsWithOcclusion() const { |
| 177 float image_width = image_bounds_.width(); | 186 float image_width = image_bounds_.width(), |
| 178 float image_height = image_bounds_.height(); | 187 image_height = image_bounds_.height(); |
| 179 int layer_width = bounds().width(); | 188 int layer_width = bounds().width(), layer_height = bounds().height(); |
| 180 int layer_height = bounds().height(); | 189 int layer_border_right = border_.width() - border_.x(), |
| 181 gfx::Rect image_occlusion( | 190 layer_border_bottom = border_.height() - border_.y(); |
| 182 BoundsToRect(layer_occlusion_.x(), layer_occlusion_.y(), | 191 int image_aperture_right = image_width - image_aperture_.right(), |
| 183 image_width - (layer_width - layer_occlusion_.right()), | 192 image_aperture_bottom = image_height - image_aperture_.bottom(); |
| 184 image_height - (layer_height - layer_occlusion_.bottom()))); | 193 int layer_occlusion_right = layer_width - layer_occlusion_.right(), |
| 185 gfx::Rect layer_aperture( | 194 layer_occlusion_bottom = layer_height - layer_occlusion_.bottom(); |
| 186 BoundsToRect(image_aperture_.x(), image_aperture_.y(), | 195 gfx::Rect image_occlusion(BoundsToRect( |
| 187 layer_width - (image_width - image_aperture_.right()), | 196 border_.x() == 0 ? 0 : (layer_occlusion_.x() * image_aperture_.x() / |
| 188 layer_height - (image_height - image_aperture_.bottom()))); | 197 border_.x()), |
| 198 border_.y() == 0 ? 0 : (layer_occlusion_.y() * image_aperture_.y() / |
| 199 border_.y()), |
| 200 image_width - (layer_border_right == 0 ? 0 : layer_occlusion_right * |
| 201 image_aperture_right / |
| 202 layer_border_right), |
| 203 image_height - (layer_border_bottom == 0 ? 0 : layer_occlusion_bottom * |
| 204 image_aperture_bottom / |
| 205 layer_border_bottom))); |
| 206 gfx::Rect layer_aperture(border_.x(), border_.y(), |
| 207 layer_width - border_.width(), |
| 208 layer_height - border_.height()); |
| 189 | 209 |
| 190 std::vector<Patch> patches; | 210 std::vector<Patch> patches; |
| 191 patches.reserve(kMaxOcclusionPatches); | 211 patches.reserve(kMaxOcclusionPatches); |
| 192 | 212 |
| 193 // Top-left-left. | 213 // Top-left-left. |
| 194 patches.push_back( | 214 patches.push_back( |
| 195 Patch(BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()), | 215 Patch(BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y()), |
| 196 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()))); | 216 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y()))); |
| 197 | 217 |
| 198 // Top-left-right. | 218 // Top-left-right. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 215 image_occlusion.y()), | 235 image_occlusion.y()), |
| 216 BoundsToRect(layer_aperture.right(), 0, layer_occlusion_.right(), | 236 BoundsToRect(layer_aperture.right(), 0, layer_occlusion_.right(), |
| 217 layer_occlusion_.y()))); | 237 layer_occlusion_.y()))); |
| 218 | 238 |
| 219 // Top-right-right. | 239 // Top-right-right. |
| 220 patches.push_back(Patch(BoundsToRect(image_occlusion.right(), 0, image_width, | 240 patches.push_back(Patch(BoundsToRect(image_occlusion.right(), 0, image_width, |
| 221 image_aperture_.y()), | 241 image_aperture_.y()), |
| 222 BoundsToRect(layer_occlusion_.right(), 0, layer_width, | 242 BoundsToRect(layer_occlusion_.right(), 0, layer_width, |
| 223 layer_aperture.y()))); | 243 layer_aperture.y()))); |
| 224 | 244 |
| 225 // Right-center. | 245 // Left-center. |
| 226 patches.push_back( | 246 patches.push_back( |
| 227 Patch(BoundsToRect(0, image_aperture_.y(), image_occlusion.x(), | 247 Patch(BoundsToRect(0, image_aperture_.y(), image_occlusion.x(), |
| 228 image_aperture_.bottom()), | 248 image_aperture_.bottom()), |
| 229 BoundsToRect(0, layer_aperture.y(), layer_occlusion_.x(), | 249 BoundsToRect(0, layer_aperture.y(), layer_occlusion_.x(), |
| 230 layer_aperture.bottom()))); | 250 layer_aperture.bottom()))); |
| 231 | 251 |
| 232 // Left-center. | 252 // Right-center. |
| 233 patches.push_back( | 253 patches.push_back( |
| 234 Patch(BoundsToRect(image_occlusion.right(), image_aperture_.y(), | 254 Patch(BoundsToRect(image_occlusion.right(), image_aperture_.y(), |
| 235 image_width, image_aperture_.bottom()), | 255 image_width, image_aperture_.bottom()), |
| 236 BoundsToRect(layer_occlusion_.right(), layer_aperture.y(), | 256 BoundsToRect(layer_occlusion_.right(), layer_aperture.y(), |
| 237 layer_width, layer_aperture.bottom()))); | 257 layer_width, layer_aperture.bottom()))); |
| 238 | 258 |
| 239 // Bottom-left-left. | 259 // Bottom-left-left. |
| 240 patches.push_back(Patch(BoundsToRect(0, image_aperture_.bottom(), | 260 patches.push_back(Patch(BoundsToRect(0, image_aperture_.bottom(), |
| 241 image_occlusion.x(), image_height), | 261 image_occlusion.x(), image_height), |
| 242 BoundsToRect(0, layer_aperture.bottom(), | 262 BoundsToRect(0, layer_aperture.bottom(), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 ResourceId resource = | 310 ResourceId resource = |
| 291 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | 311 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
| 292 | 312 |
| 293 if (!resource) | 313 if (!resource) |
| 294 return; | 314 return; |
| 295 | 315 |
| 296 DCHECK(!bounds().IsEmpty()); | 316 DCHECK(!bounds().IsEmpty()); |
| 297 | 317 |
| 298 std::vector<Patch> patches; | 318 std::vector<Patch> patches; |
| 299 | 319 |
| 300 if (!layer_occlusion_.IsEmpty() && border_.IsEmpty() && !fill_center_) | 320 if (layer_occlusion_.IsEmpty() || fill_center_) |
| 321 patches = ComputeQuadsWithoutOcclusion(); |
| 322 else |
| 301 patches = ComputeQuadsWithOcclusion(); | 323 patches = ComputeQuadsWithOcclusion(); |
| 302 else | |
| 303 patches = ComputeQuadsWithoutOcclusion(); | |
| 304 | 324 |
| 305 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 325 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 306 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); | 326 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); |
| 307 static const bool flipped = false; | 327 static const bool flipped = false; |
| 308 static const bool premultiplied_alpha = true; | 328 static const bool premultiplied_alpha = true; |
| 309 | 329 |
| 310 for (const auto& patch : patches) { | 330 for (const auto& patch : patches) { |
| 311 gfx::Rect visible_rect = | 331 gfx::Rect visible_rect = |
| 312 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | 332 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( |
| 313 patch.layer_rect); | 333 patch.layer_rect); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 list->AppendInteger(layer_occlusion_.x()); | 374 list->AppendInteger(layer_occlusion_.x()); |
| 355 list->AppendInteger(layer_occlusion_.y()); | 375 list->AppendInteger(layer_occlusion_.y()); |
| 356 list->AppendInteger(layer_occlusion_.width()); | 376 list->AppendInteger(layer_occlusion_.width()); |
| 357 list->AppendInteger(layer_occlusion_.height()); | 377 list->AppendInteger(layer_occlusion_.height()); |
| 358 result->Set("LayerOcclusion", list); | 378 result->Set("LayerOcclusion", list); |
| 359 | 379 |
| 360 return result; | 380 return result; |
| 361 } | 381 } |
| 362 | 382 |
| 363 } // namespace cc | 383 } // namespace cc |
| OLD | NEW |