From e370de1d415855eb14e8f917acf5217c5ab5a2f9 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Tue, 16 Aug 2011 09:25:01 -0400 Subject: Fix NinePatch issue when the destination is smaller than the asset bug: 5041053 Change-Id: Ic06d6d161a04d2d501ad629ba24f827ac6f98331 --- Source/WebKit/android/RenderSkinNinePatch.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'Source/WebKit/android/RenderSkinNinePatch.cpp') 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); + } } -- cgit v1.1