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

Unified Diff: cc/layers/nine_patch_layer_impl.cc

Issue 1937493002: cc: 9patch: fix shadow scaling issue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rounded corners Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | cc/layers/nine_patch_layer_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/nine_patch_layer_impl.cc
diff --git a/cc/layers/nine_patch_layer_impl.cc b/cc/layers/nine_patch_layer_impl.cc
index 1fac38552fe0249f9775cac9e63e436bde77731f..09a47747474db9d45322698d07919b09dc03f4cd 100644
--- a/cc/layers/nine_patch_layer_impl.cc
+++ b/cc/layers/nine_patch_layer_impl.cc
@@ -93,6 +93,15 @@ void NinePatchLayerImpl::CheckGeometryLimitations() {
DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_))
<< "image_bounds_ " << gfx::Rect(image_bounds_).ToString()
<< " image_aperture_ " << image_aperture_.ToString();
+
+ // Sanity check on |layer_occlusion_|. It should always be within the
+ // border.
+ gfx::Rect border_rect(border_.x(), border_.y(),
+ bounds().width() - border_.width(),
+ bounds().height() - border_.height());
+ DCHECK(layer_occlusion_.IsEmpty() || layer_occlusion_.Contains(border_rect))
+ << "border_rect " << border_rect.ToString() << " layer_occlusion_ "
+ << layer_occlusion_.ToString();
}
std::vector<NinePatchLayerImpl::Patch>
@@ -174,18 +183,29 @@ NinePatchLayerImpl::ComputeQuadsWithoutOcclusion() const {
std::vector<NinePatchLayerImpl::Patch>
NinePatchLayerImpl::ComputeQuadsWithOcclusion() const {
- float image_width = image_bounds_.width();
- float image_height = image_bounds_.height();
- int layer_width = bounds().width();
- int layer_height = bounds().height();
- gfx::Rect image_occlusion(
- BoundsToRect(layer_occlusion_.x(), layer_occlusion_.y(),
- image_width - (layer_width - layer_occlusion_.right()),
- image_height - (layer_height - layer_occlusion_.bottom())));
- gfx::Rect layer_aperture(
- BoundsToRect(image_aperture_.x(), image_aperture_.y(),
- layer_width - (image_width - image_aperture_.right()),
- layer_height - (image_height - image_aperture_.bottom())));
+ float image_width = image_bounds_.width(),
+ image_height = image_bounds_.height();
+ int layer_width = bounds().width(), layer_height = bounds().height();
+ int layer_border_right = border_.width() - border_.x(),
+ layer_border_bottom = border_.height() - border_.y();
+ int image_aperture_right = image_width - image_aperture_.right(),
+ image_aperture_bottom = image_height - image_aperture_.bottom();
+ int layer_occlusion_right = layer_width - layer_occlusion_.right(),
+ layer_occlusion_bottom = layer_height - layer_occlusion_.bottom();
+ gfx::Rect image_occlusion(BoundsToRect(
+ border_.x() == 0 ? 0 : (layer_occlusion_.x() * image_aperture_.x() /
+ border_.x()),
+ border_.y() == 0 ? 0 : (layer_occlusion_.y() * image_aperture_.y() /
+ border_.y()),
+ image_width - (layer_border_right == 0 ? 0 : layer_occlusion_right *
+ image_aperture_right /
+ layer_border_right),
+ image_height - (layer_border_bottom == 0 ? 0 : layer_occlusion_bottom *
+ image_aperture_bottom /
+ layer_border_bottom)));
+ gfx::Rect layer_aperture(border_.x(), border_.y(),
+ layer_width - border_.width(),
+ layer_height - border_.height());
std::vector<Patch> patches;
patches.reserve(kMaxOcclusionPatches);
@@ -222,14 +242,14 @@ NinePatchLayerImpl::ComputeQuadsWithOcclusion() const {
BoundsToRect(layer_occlusion_.right(), 0, layer_width,
layer_aperture.y())));
- // Right-center.
+ // Left-center.
patches.push_back(
Patch(BoundsToRect(0, image_aperture_.y(), image_occlusion.x(),
image_aperture_.bottom()),
BoundsToRect(0, layer_aperture.y(), layer_occlusion_.x(),
layer_aperture.bottom())));
- // Left-center.
+ // Right-center.
patches.push_back(
Patch(BoundsToRect(image_occlusion.right(), image_aperture_.y(),
image_width, image_aperture_.bottom()),
@@ -297,10 +317,10 @@ void NinePatchLayerImpl::AppendQuads(
std::vector<Patch> patches;
- if (!layer_occlusion_.IsEmpty() && border_.IsEmpty() && !fill_center_)
- patches = ComputeQuadsWithOcclusion();
- else
+ if (layer_occlusion_.IsEmpty() || fill_center_)
patches = ComputeQuadsWithoutOcclusion();
+ else
+ patches = ComputeQuadsWithOcclusion();
const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f};
const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_);
« no previous file with comments | « no previous file | cc/layers/nine_patch_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698