Loading core/jni/android/graphics/NinePatch.cpp +30 −8 Original line number Diff line number Diff line Loading @@ -26,10 +26,10 @@ #include <ResourceCache.h> #include "SkCanvas.h" #include "SkLatticeIter.h" #include "SkRegion.h" #include "GraphicsJNI.h" #include "utils/NinePatch.h" #include "NinePatchUtils.h" #include "JNIHelp.h" #include "core_jni_helpers.h" Loading Loading @@ -88,18 +88,40 @@ public: } static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap, jlong chunkHandle, jobject boundsRect) { jlong chunkHandle, jobject dstRect) { Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle); SkASSERT(chunk); SkASSERT(boundsRect); SkBitmap bitmap; GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); SkRect bounds; GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds); SkRect dst; GraphicsJNI::jrect_to_rect(env, dstRect, &dst); SkCanvas::Lattice lattice; SkIRect src = SkIRect::MakeWH(bitmap.width(), bitmap.height()); lattice.fBounds = &src; NinePatchUtils::SetLatticeDivs(&lattice, *chunk, bitmap.width(), bitmap.height()); lattice.fFlags = nullptr; SkRegion* region = nullptr; if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { SkLatticeIter iter(lattice, dst); if (iter.numRectsToDraw() == chunk->numColors) { SkRect dummy; SkRect iterDst; int index = 0; while (iter.next(&dummy, &iterDst)) { if (0 == chunk->getColors()[index++] && !iterDst.isEmpty()) { if (!region) { region = new SkRegion(); } SkRegion* region = NULL; NinePatch::Draw(NULL, bounds, bitmap, *chunk, NULL, ®ion); region->op(iterDst.round(), SkRegion::kUnion_Op); } } } } return reinterpret_cast<jlong>(region); } Loading libs/hwui/Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ hwui_src_files := \ utils/Blur.cpp \ utils/GLUtils.cpp \ utils/LinearAllocator.cpp \ utils/NinePatchImpl.cpp \ utils/StringUtils.cpp \ utils/TestWindowContext.cpp \ utils/VectorDrawableUtils.cpp \ Loading libs/hwui/NinePatchUtils.h 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace android { namespace NinePatchUtils { static inline void SetLatticeDivs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk, int width, int height) { lattice->fXCount = chunk.numXDivs; lattice->fYCount = chunk.numYDivs; lattice->fXDivs = chunk.getXDivs(); lattice->fYDivs = chunk.getYDivs(); // We'll often see ninepatches where the last div is equal to the width or height. // This doesn't provide any additional information and is not supported by Skia. if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) { lattice->fXCount--; } if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) { lattice->fYCount--; } } }; // namespace NinePatchUtils }; // namespace android libs/hwui/RecordingCanvas.h +0 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ #include "hwui/Canvas.h" #include "utils/LinearAllocator.h" #include "utils/Macros.h" #include "utils/NinePatch.h" #include <SkDrawFilter.h> #include <SkPaint.h> Loading libs/hwui/SkiaCanvas.cpp +2 −18 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include "SkiaCanvas.h" #include "CanvasProperty.h" #include "NinePatchUtils.h" #include "VectorDrawable.h" #include "hwui/Bitmap.h" #include "hwui/MinikinUtils.h" Loading Loading @@ -670,23 +671,6 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeigh indexCount, tmpPaint); } static inline void set_lattice_divs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk, int width, int height) { lattice->fXCount = chunk.numXDivs; lattice->fYCount = chunk.numYDivs; lattice->fXDivs = chunk.getXDivs(); lattice->fYDivs = chunk.getYDivs(); // We'll often see ninepatches where the last div is equal to the width or height. // This doesn't provide any additional information and is not supported by Skia. if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) { lattice->fXCount--; } if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) { lattice->fYCount--; } } static inline int num_distinct_rects(const SkCanvas::Lattice& lattice) { int xRects; if (lattice.fXCount > 0) { Loading Loading @@ -750,7 +734,7 @@ void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk, hwuiBitmap.getSkBitmap(&bitmap); SkCanvas::Lattice lattice; set_lattice_divs(&lattice, chunk, bitmap.width(), bitmap.height()); NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height()); lattice.fFlags = nullptr; int numFlags = 0; Loading Loading
core/jni/android/graphics/NinePatch.cpp +30 −8 Original line number Diff line number Diff line Loading @@ -26,10 +26,10 @@ #include <ResourceCache.h> #include "SkCanvas.h" #include "SkLatticeIter.h" #include "SkRegion.h" #include "GraphicsJNI.h" #include "utils/NinePatch.h" #include "NinePatchUtils.h" #include "JNIHelp.h" #include "core_jni_helpers.h" Loading Loading @@ -88,18 +88,40 @@ public: } static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap, jlong chunkHandle, jobject boundsRect) { jlong chunkHandle, jobject dstRect) { Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle); SkASSERT(chunk); SkASSERT(boundsRect); SkBitmap bitmap; GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap); SkRect bounds; GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds); SkRect dst; GraphicsJNI::jrect_to_rect(env, dstRect, &dst); SkCanvas::Lattice lattice; SkIRect src = SkIRect::MakeWH(bitmap.width(), bitmap.height()); lattice.fBounds = &src; NinePatchUtils::SetLatticeDivs(&lattice, *chunk, bitmap.width(), bitmap.height()); lattice.fFlags = nullptr; SkRegion* region = nullptr; if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) { SkLatticeIter iter(lattice, dst); if (iter.numRectsToDraw() == chunk->numColors) { SkRect dummy; SkRect iterDst; int index = 0; while (iter.next(&dummy, &iterDst)) { if (0 == chunk->getColors()[index++] && !iterDst.isEmpty()) { if (!region) { region = new SkRegion(); } SkRegion* region = NULL; NinePatch::Draw(NULL, bounds, bitmap, *chunk, NULL, ®ion); region->op(iterDst.round(), SkRegion::kUnion_Op); } } } } return reinterpret_cast<jlong>(region); } Loading
libs/hwui/Android.mk +0 −1 Original line number Diff line number Diff line Loading @@ -38,7 +38,6 @@ hwui_src_files := \ utils/Blur.cpp \ utils/GLUtils.cpp \ utils/LinearAllocator.cpp \ utils/NinePatchImpl.cpp \ utils/StringUtils.cpp \ utils/TestWindowContext.cpp \ utils/VectorDrawableUtils.cpp \ Loading
libs/hwui/NinePatchUtils.h 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace android { namespace NinePatchUtils { static inline void SetLatticeDivs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk, int width, int height) { lattice->fXCount = chunk.numXDivs; lattice->fYCount = chunk.numYDivs; lattice->fXDivs = chunk.getXDivs(); lattice->fYDivs = chunk.getYDivs(); // We'll often see ninepatches where the last div is equal to the width or height. // This doesn't provide any additional information and is not supported by Skia. if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) { lattice->fXCount--; } if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) { lattice->fYCount--; } } }; // namespace NinePatchUtils }; // namespace android
libs/hwui/RecordingCanvas.h +0 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,6 @@ #include "hwui/Canvas.h" #include "utils/LinearAllocator.h" #include "utils/Macros.h" #include "utils/NinePatch.h" #include <SkDrawFilter.h> #include <SkPaint.h> Loading
libs/hwui/SkiaCanvas.cpp +2 −18 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ #include "SkiaCanvas.h" #include "CanvasProperty.h" #include "NinePatchUtils.h" #include "VectorDrawable.h" #include "hwui/Bitmap.h" #include "hwui/MinikinUtils.h" Loading Loading @@ -670,23 +671,6 @@ void SkiaCanvas::drawBitmapMesh(Bitmap& hwuiBitmap, int meshWidth, int meshHeigh indexCount, tmpPaint); } static inline void set_lattice_divs(SkCanvas::Lattice* lattice, const Res_png_9patch& chunk, int width, int height) { lattice->fXCount = chunk.numXDivs; lattice->fYCount = chunk.numYDivs; lattice->fXDivs = chunk.getXDivs(); lattice->fYDivs = chunk.getYDivs(); // We'll often see ninepatches where the last div is equal to the width or height. // This doesn't provide any additional information and is not supported by Skia. if (lattice->fXCount > 0 && width == lattice->fXDivs[lattice->fXCount - 1]) { lattice->fXCount--; } if (lattice->fYCount > 0 && height == lattice->fYDivs[lattice->fYCount - 1]) { lattice->fYCount--; } } static inline int num_distinct_rects(const SkCanvas::Lattice& lattice) { int xRects; if (lattice.fXCount > 0) { Loading Loading @@ -750,7 +734,7 @@ void SkiaCanvas::drawNinePatch(Bitmap& hwuiBitmap, const Res_png_9patch& chunk, hwuiBitmap.getSkBitmap(&bitmap); SkCanvas::Lattice lattice; set_lattice_divs(&lattice, chunk, bitmap.width(), bitmap.height()); NinePatchUtils::SetLatticeDivs(&lattice, chunk, bitmap.width(), bitmap.height()); lattice.fFlags = nullptr; int numFlags = 0; Loading