// Drawing
///////////////////////////////////////////////////////////////////////////
- // TODO: move to Canvas.java
- @Override
- public void drawPatch(NinePatch patch, Rect dst, Paint paint) {
- Bitmap bitmap = patch.getBitmap();
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
- nDrawPatch(mNativeCanvasWrapper, bitmap, patch.mNativeChunk,
- dst.left, dst.top, dst.right, dst.bottom, nativePaint);
- }
-
- // TODO: move to Canvas.java
- @Override
- public void drawPatch(NinePatch patch, RectF dst, Paint paint) {
- Bitmap bitmap = patch.getBitmap();
- throwIfCannotDraw(bitmap);
- final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
- nDrawPatch(mNativeCanvasWrapper, bitmap, patch.mNativeChunk,
- dst.left, dst.top, dst.right, dst.bottom, nativePaint);
- }
-
- private static native void nDrawPatch(long renderer, Bitmap bitmap, long chunk,
- float left, float top, float right, float bottom, long paint);
-
public void drawCircle(CanvasProperty<Float> cx, CanvasProperty<Float> cy,
CanvasProperty<Float> radius, CanvasProperty<Paint> paint) {
nDrawCircle(mNativeCanvasWrapper, cx.getNativeContainer(), cy.getNativeContainer(),
android/graphics/MinikinUtils.cpp \
android/graphics/Movie.cpp \
android/graphics/NinePatch.cpp \
- android/graphics/NinePatchImpl.cpp \
android/graphics/NinePatchPeeker.cpp \
android/graphics/Paint.cpp \
android/graphics/PaintImpl.cpp \
#include "SkRegion.h"
#include "GraphicsJNI.h"
+#include "utils/NinePatch.h"
+
#include "JNIHelp.h"
#include "core_jni_helpers.h"
-extern void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds, const SkBitmap& bitmap,
- const android::Res_png_9patch& chunk, const SkPaint* paint, SkRegion** outRegion);
-
using namespace android;
/**
}
}
- static void draw(JNIEnv* env, SkCanvas* canvas, SkRect& bounds, const SkBitmap& bitmap,
- Res_png_9patch* chunk, const SkPaint* paint, jint destDensity, jint srcDensity) {
- if (destDensity == srcDensity || destDensity == 0 || srcDensity == 0) {
- ALOGV("Drawing unscaled 9-patch: (%g,%g)-(%g,%g)",
- SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
- SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom));
- NinePatch_Draw(canvas, bounds, bitmap, *chunk, paint, NULL);
- } else {
- canvas->save();
-
- SkScalar scale = destDensity / (float)srcDensity;
- canvas->translate(bounds.fLeft, bounds.fTop);
- canvas->scale(scale, scale);
-
- bounds.fRight = (bounds.fRight-bounds.fLeft) / scale;
- bounds.fBottom = (bounds.fBottom-bounds.fTop) / scale;
- bounds.fLeft = bounds.fTop = 0;
-
- ALOGV("Drawing scaled 9-patch: (%g,%g)-(%g,%g) srcDensity=%d destDensity=%d",
- SkScalarToFloat(bounds.fLeft), SkScalarToFloat(bounds.fTop),
- SkScalarToFloat(bounds.fRight), SkScalarToFloat(bounds.fBottom),
- srcDensity, destDensity);
-
- NinePatch_Draw(canvas, bounds, bitmap, *chunk, paint, NULL);
-
- canvas->restore();
- }
- }
-
- static void drawF(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRectF,
- jobject jbitmap, jlong chunkHandle, jlong paintHandle,
- jint destDensity, jint srcDensity) {
- SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas();
- Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
- const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- SkASSERT(canvas);
- SkASSERT(boundsRectF);
- SkASSERT(chunk);
- // paint is optional
-
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- SkRect bounds;
- GraphicsJNI::jrectf_to_rect(env, boundsRectF, &bounds);
-
- draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity);
- }
-
- static void drawI(JNIEnv* env, jobject, jlong canvasHandle, jobject boundsRect,
- jobject jbitmap, jlong chunkHandle, jlong paintHandle,
- jint destDensity, jint srcDensity) {
- SkCanvas* canvas = reinterpret_cast<Canvas*>(canvasHandle)->asSkCanvas();
- Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
- const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- SkASSERT(canvas);
- SkASSERT(boundsRect);
- SkASSERT(chunk);
- // paint is optional
-
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- SkRect bounds;
- GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds);
- draw(env, canvas, bounds, bitmap, chunk, paint, destDensity, srcDensity);
- }
-
static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap,
jlong chunkHandle, jobject boundsRect) {
Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds);
SkRegion* region = NULL;
- NinePatch_Draw(NULL, bounds, bitmap, *chunk, NULL, ®ion);
+ NinePatch::Draw(NULL, bounds, bitmap, *chunk, NULL, ®ion);
return reinterpret_cast<jlong>(region);
}
{ "validateNinePatchChunk", "([B)J",
(void*) SkNinePatchGlue::validateNinePatchChunk },
{ "nativeFinalize", "(J)V", (void*) SkNinePatchGlue::finalize },
- { "nativeDraw", "(JLandroid/graphics/RectF;Landroid/graphics/Bitmap;JJII)V",
- (void*) SkNinePatchGlue::drawF },
- { "nativeDraw", "(JLandroid/graphics/Rect;Landroid/graphics/Bitmap;JJII)V",
- (void*) SkNinePatchGlue::drawI },
{ "nativeGetTransparentRegion", "(Landroid/graphics/Bitmap;JLandroid/graphics/Rect;)J",
(void*) SkNinePatchGlue::getTransparentRegion }
};
#include "GraphicsJNI.h"
#include "core_jni_helpers.h"
+#include <androidfw/ResourceTypes.h>
+
#include <Canvas.h>
#include "SkDrawFilter.h"
#include "SkGraphics.h"
indices, indexCount, *paint);
}
+static void drawNinePatch(JNIEnv* env, jlong canvasHandle, jobject jbitmap, jlong chunkHandle,
+ jfloat left, jfloat top, jfloat right, jfloat bottom,
+ jlong paintHandle, jint dstDensity, jint srcDensity) {
+
+ Canvas* canvas = get_canvas(canvasHandle);
+ SkBitmap bitmap;
+ GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
+ const android::Res_png_9patch* chunk = reinterpret_cast<android::Res_png_9patch*>(chunkHandle);
+ const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
+
+ if (CC_LIKELY(dstDensity == srcDensity || dstDensity == 0 || srcDensity == 0)) {
+ ALOGV("Drawing unscaled 9-patch: (%g,%g)-(%g,%g)", left, top, right, bottom);
+ canvas->drawNinePatch(bitmap, *chunk, left, top, right, bottom, paint);
+ } else {
+ canvas->save(SkCanvas::kMatrixClip_SaveFlag);
+
+ SkScalar scale = dstDensity / (float)srcDensity;
+ canvas->translate(left, top);
+ canvas->scale(scale, scale);
+
+ Paint filteredPaint;
+ if (paint) {
+ filteredPaint = *paint;
+ }
+ filteredPaint.setFilterQuality(kLow_SkFilterQuality);
+
+ ALOGV("Drawing scaled 9-patch: (0,0)-(%g,%g) srcDensity=%d destDensity=%d",
+ (right-left)/scale, (bottom-top)/scale, srcDensity, dstDensity);
+ canvas->drawNinePatch(bitmap, *chunk, 0, 0, (right-left)/scale, (bottom-top)/scale,
+ &filteredPaint);
+
+ canvas->restore();
+ }
+}
+
static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jobject jbitmap,
jfloat left, jfloat top, jlong paintHandle, jint canvasDensity,
jint screenDensity, jint bitmapDensity) {
{"native_drawArc","(JFFFFFFZJ)V", (void*) CanvasJNI::drawArc},
{"native_drawPath","(JJJ)V", (void*) CanvasJNI::drawPath},
{"nativeDrawVertices", "(JII[FI[FI[II[SIIJ)V", (void*)CanvasJNI::drawVertices},
+ {"native_drawNinePatch", "(JLandroid/graphics/Bitmap;JFFFFJII)V", (void*)CanvasJNI::drawNinePatch},
{"native_drawBitmap","(JLandroid/graphics/Bitmap;FFJIII)V", (void*) CanvasJNI::drawBitmap},
{"nativeDrawBitmapMatrix", "(JLandroid/graphics/Bitmap;JJ)V", (void*)CanvasJNI::drawBitmapMatrix},
{"native_drawBitmap","(JLandroid/graphics/Bitmap;FFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect},
#include <android_runtime/AndroidRuntime.h>
-#include <androidfw/ResourceTypes.h>
-
#include <cutils/properties.h>
#include <SkBitmap.h>
// Drawing
// ----------------------------------------------------------------------------
-static void android_view_DisplayListCanvas_drawPatch(JNIEnv* env, jobject clazz,
- jlong rendererPtr, jobject jbitmap, jlong patchPtr,
- float left, float top, float right, float bottom, jlong paintPtr) {
- SkBitmap bitmap;
- GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
- DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr);
- Res_png_9patch* patch = reinterpret_cast<Res_png_9patch*>(patchPtr);
- Paint* paint = reinterpret_cast<Paint*>(paintPtr);
- renderer->drawPatch(bitmap, patch, left, top, right, bottom, paint);
-}
-
static void android_view_DisplayListCanvas_drawRoundRectProps(JNIEnv* env, jobject clazz,
jlong rendererPtr, jlong leftPropPtr, jlong topPropPtr, jlong rightPropPtr,
jlong bottomPropPtr, jlong rxPropPtr, jlong ryPropPtr, jlong paintPropPtr) {
{ "nCallDrawGLFunction", "(JJ)V", (void*) android_view_DisplayListCanvas_callDrawGLFunction },
- { "nDrawPatch", "(JLandroid/graphics/Bitmap;JFFFFJ)V", (void*) android_view_DisplayListCanvas_drawPatch },
-
{ "nDrawRoundRect", "(JJJJJJJJ)V", (void*) android_view_DisplayListCanvas_drawRoundRectProps },
{ "nDrawCircle", "(JJJJJ)V", (void*) android_view_DisplayListCanvas_drawCircleProps },
* @hide
*/
public void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst, @Nullable Paint paint) {
- patch.drawSoftware(this, dst, paint);
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
+ native_drawNinePatch(mNativeCanvasWrapper, patch.getBitmap(), patch.mNativeChunk,
+ dst.left, dst.top, dst.right, dst.bottom, nativePaint,
+ mDensity, patch.getDensity());
}
/**
* @hide
*/
public void drawPatch(@NonNull NinePatch patch, @NonNull RectF dst, @Nullable Paint paint) {
- patch.drawSoftware(this, dst, paint);
+ final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
+ native_drawNinePatch(mNativeCanvasWrapper, patch.getBitmap(), patch.mNativeChunk,
+ dst.left, dst.top, dst.right, dst.bottom, nativePaint,
+ mDensity, patch.getDensity());
}
/**
long nativePaint);
private static native void native_drawRegion(long nativeCanvas,
long nativeRegion, long nativePaint);
+ private native void native_drawNinePatch(long nativeCanvas, Bitmap bitmap,
+ long ninePatch, float dstLeft, float dstTop, float dstRight, float dstBottom,
+ long nativePaintOrZero, int screenDensity, int bitmapDensity);
private native void native_drawBitmap(long nativeCanvas, Bitmap bitmap,
float left, float top,
long nativePaintOrZero,
canvas.drawPatch(this, location, paint);
}
- void drawSoftware(Canvas canvas, RectF location, Paint paint) {
- nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap, mNativeChunk,
- paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
- }
-
- void drawSoftware(Canvas canvas, Rect location, Paint paint) {
- nativeDraw(canvas.getNativeCanvasWrapper(), location, mBitmap, mNativeChunk,
- paint != null ? paint.getNativeInstance() : 0, canvas.mDensity, mBitmap.mDensity);
- }
-
/**
* Return the underlying bitmap's density, as per
* {@link Bitmap#getDensity() Bitmap.getDensity()}.
*/
private static native long validateNinePatchChunk(byte[] chunk);
private static native void nativeFinalize(long chunk);
- private static native void nativeDraw(long canvas_instance, RectF loc, Bitmap bitmap_instance,
- long c, long paint_instance_or_null, int destDensity, int srcDensity);
- private static native void nativeDraw(long canvas_instance, Rect loc, Bitmap bitmap_instance,
- long c, long paint_instance_or_null, int destDensity, int srcDensity);
private static native long nativeGetTransparentRegion(Bitmap bitmap, long chunk, Rect location);
}
utils/Blur.cpp \
utils/GLUtils.cpp \
utils/LinearAllocator.cpp \
+ utils/NinePatchImpl.cpp \
AmbientShadow.cpp \
AnimationContext.cpp \
Animator.cpp \
#include <cutils/compiler.h>
+#include "utils/NinePatch.h"
+
#include <SkBitmap.h>
#include <SkCanvas.h>
#include <SkMatrix.h>
float dstRight, float dstBottom, const SkPaint* paint) = 0;
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint) = 0;
+ virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
+ float dstLeft, float dstTop, float dstRight, float dstBottom,
+ const SkPaint* paint) = 0;
// Text
/**
vertices, colors, paint));
}
-void DisplayListCanvas::drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
- float left, float top, float right, float bottom, const SkPaint* paint) {
+void DisplayListCanvas::drawNinePatch(const SkBitmap& bitmap, const Res_png_9patch& patch,
+ float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
const SkBitmap* bitmapPtr = refBitmap(bitmap);
- patch = refPatch(patch);
+ const Res_png_9patch* patchPtr = refPatch(&patch);
paint = refPaint(paint);
- addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patch, left, top, right, bottom, paint));
+ addDrawOp(new (alloc()) DrawPatchOp(bitmapPtr, patchPtr,
+ dstLeft, dstTop, dstRight, dstBottom, paint));
}
void DisplayListCanvas::drawColor(int color, SkXfermode::Mode mode) {
// HWUI Canvas draw operations
// ----------------------------------------------------------------------------
- // TODO: move drawPatch() to Canvas.h
- void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
- float left, float top, float right, float bottom, const SkPaint* paint);
-
// Shapes
void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
float dstRight, float dstBottom, const SkPaint* paint) override;
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint) override;
+ virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
+ float dstLeft, float dstTop, float dstRight, float dstBottom,
+ const SkPaint* paint) override;
// Text
virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
float dstRight, float dstBottom, const SkPaint* paint) override;
virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
const float* vertices, const int* colors, const SkPaint* paint) override;
+ virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
+ float dstLeft, float dstTop, float dstRight, float dstBottom,
+ const SkPaint* paint) override;
virtual void drawText(const uint16_t* text, const float* positions, int count,
const SkPaint& paint, float x, float y,
indexCount, tmpPaint);
}
+void SkiaCanvas::drawNinePatch(const SkBitmap& bitmap, const Res_png_9patch& chunk,
+ float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint) {
+ SkRect bounds = SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom);
+ NinePatch::Draw(mCanvas, bounds, bitmap, chunk, paint, nullptr);
+}
+
// ----------------------------------------------------------------------------
// Canvas draw operations: Text
// ----------------------------------------------------------------------------
--- /dev/null
+/*
+**
+** Copyright 2015, 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.
+*/
+
+#ifndef ANDROID_GRAPHICS_NINEPATCH_H
+#define ANDROID_GRAPHICS_NINEPATCH_H
+
+#include <androidfw/ResourceTypes.h>
+#include <cutils/compiler.h>
+
+#include "SkCanvas.h"
+#include "SkRegion.h"
+
+namespace android {
+
+class ANDROID_API NinePatch {
+public:
+ static void Draw(SkCanvas* canvas, const SkRect& bounds, const SkBitmap& bitmap,
+ const Res_png_9patch& chunk, const SkPaint* paint, SkRegion** outRegion);
+};
+
+} // namespace android
+
+#endif // ANDROID_GRAPHICS_NINEPATCH_H
** limitations under the License.
*/
-#define LOG_TAG "NinePatch"
-#define LOG_NDEBUG 1
-
-#include <androidfw/ResourceTypes.h>
-#include <utils/Log.h>
+#include "utils/NinePatch.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include <utils/Log.h>
+namespace android {
+
static const bool kUseTrace = true;
static bool gTrace = false;
return srcSpace * stretchySpaceRemaining / numStrechyPixelsRemaining;
}
-void NinePatch_Draw(SkCanvas* canvas, const SkRect& bounds,
- const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
- const SkPaint* paint, SkRegion** outRegion) {
+void NinePatch::Draw(SkCanvas* canvas, const SkRect& bounds,
+ const SkBitmap& bitmap, const Res_png_9patch& chunk,
+ const SkPaint* paint, SkRegion** outRegion) {
if (canvas && canvas->quickReject(bounds)) {
return;
}
dstRightsHaveBeenCached = true;
}
}
+
+} // namespace android