diff options
author | Derek Sollenberger <djsollen@google.com> | 2011-08-16 09:25:01 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2011-08-16 09:25:01 -0400 |
commit | e370de1d415855eb14e8f917acf5217c5ab5a2f9 (patch) | |
tree | 3ad66d4ac9663019804977d61793e32940297b86 /Source/WebKit/android/RenderSkinNinePatch.cpp | |
parent | 48aa257d7bbfcd76e4daf76d16b9b1f27220e854 (diff) | |
download | external_webkit-e370de1d415855eb14e8f917acf5217c5ab5a2f9.zip external_webkit-e370de1d415855eb14e8f917acf5217c5ab5a2f9.tar.gz external_webkit-e370de1d415855eb14e8f917acf5217c5ab5a2f9.tar.bz2 |
Fix NinePatch issue when the destination is smaller than the asset
bug: 5041053
Change-Id: Ic06d6d161a04d2d501ad629ba24f827ac6f98331
Diffstat (limited to 'Source/WebKit/android/RenderSkinNinePatch.cpp')
-rw-r--r-- | Source/WebKit/android/RenderSkinNinePatch.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/Source/WebKit/android/RenderSkinNinePatch.cpp b/Source/WebKit/android/RenderSkinNinePatch.cpp index 074a65a..faa9dc4 100644 --- a/Source/WebKit/android/RenderSkinNinePatch.cpp +++ b/Source/WebKit/android/RenderSkinNinePatch.cpp @@ -20,6 +20,7 @@ #include "NinePatchPeeker.h" #include "SkCanvas.h" #include "SkImageDecoder.h" +#include "SkNinePatch.h" #include "SkRect.h" #include "SkStream.h" #include "SkTemplates.h" @@ -85,5 +86,20 @@ bool RenderSkinNinePatch::decodeAsset(AssetManager* am, const char* filename, Ni void RenderSkinNinePatch::DrawNinePatch(SkCanvas* canvas, const SkRect& bounds, const NinePatch& patch) { Res_png_9patch* data = Res_png_9patch::deserialize(patch.m_serializedPatchData); - NinePatch_Draw(canvas, bounds, patch.m_bitmap, *data, 0, 0); + + // if the NinePatch is bigger than the destination on a given axis the default + // decoder will not stretch properly, therefore we fall back to skia's decoder + // which if needed will down-sample and draw the bitmap as best as possible. + if (patch.m_bitmap.width() >= bounds.width() || patch.m_bitmap.height() >= bounds.height()) { + + SkPaint defaultPaint; + // matches default dither in NinePatchDrawable.java. + defaultPaint.setDither(true); + SkNinePatch::DrawMesh(canvas, bounds, patch.m_bitmap, + data->xDivs, data->numXDivs, + data->yDivs, data->numYDivs, + &defaultPaint); + } else { + NinePatch_Draw(canvas, bounds, patch.m_bitmap, *data, 0, 0); + } } |