From 17f40b80f6f1dccd72147209aeba3f4efd2d46f2 Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Wed, 16 Nov 2016 10:29:39 -0800 Subject: [PATCH] Recreate the bitmap cache when it is smaller than needed fix:32780212 Test: Existing CTS and attached repro apk. Change-Id: Ib908319af6539b2438b850f7a50d5a539cef8368 --- libs/hwui/VectorDrawable.cpp | 2 +- libs/hwui/VectorDrawable.h | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp index aeee66106fb34..223605fa34edb 100644 --- a/libs/hwui/VectorDrawable.cpp +++ b/libs/hwui/VectorDrawable.cpp @@ -576,7 +576,7 @@ bool Tree::allocateBitmapIfNeeded(SkBitmap* outCache, int width, int height) { } bool Tree::canReuseBitmap(const SkBitmap& bitmap, int width, int height) { - return width == bitmap.width() && height == bitmap.height(); + return width <= bitmap.width() && height <= bitmap.height(); } void Tree::onPropertyChanged(TreeProperties* prop) { diff --git a/libs/hwui/VectorDrawable.h b/libs/hwui/VectorDrawable.h index a0c3d9db8ae12..54cd065049204 100644 --- a/libs/hwui/VectorDrawable.h +++ b/libs/hwui/VectorDrawable.h @@ -622,10 +622,15 @@ public: } void setScaledSize(int width, int height) { - if (mNonAnimatableProperties.scaledWidth != width - || mNonAnimatableProperties.scaledHeight != height) { - mNonAnimatableProperties.scaledWidth = width; - mNonAnimatableProperties.scaledHeight = height; + // If the requested size is bigger than what the bitmap was, then + // we increase the bitmap size to match. The width and height + // are bound by MAX_CACHED_BITMAP_SIZE. + if (mNonAnimatableProperties.scaledWidth < width + || mNonAnimatableProperties.scaledHeight < height) { + mNonAnimatableProperties.scaledWidth = std::max(width, + mNonAnimatableProperties.scaledWidth); + mNonAnimatableProperties.scaledHeight = std::max(height, + mNonAnimatableProperties.scaledHeight); mNonAnimatablePropertiesDirty = true; mTree->onPropertyChanged(this); }