Merge "Frameworks changes to support latest Skia (r14729)"
This commit is contained in:
committed by
Android (Google) Code Review
commit
95f7b135ce
@@ -100,7 +100,6 @@ LOCAL_SRC_FILES:= \
|
||||
android/graphics/Graphics.cpp \
|
||||
android/graphics/HarfBuzzNGFaceSkia.cpp \
|
||||
android/graphics/Interpolator.cpp \
|
||||
android/graphics/LayerRasterizer.cpp \
|
||||
android/graphics/MaskFilter.cpp \
|
||||
android/graphics/Matrix.cpp \
|
||||
android/graphics/Movie.cpp \
|
||||
|
||||
@@ -56,7 +56,6 @@ extern int register_android_graphics_Camera(JNIEnv* env);
|
||||
extern int register_android_graphics_CreateJavaOutputStreamAdaptor(JNIEnv* env);
|
||||
extern int register_android_graphics_Graphics(JNIEnv* env);
|
||||
extern int register_android_graphics_Interpolator(JNIEnv* env);
|
||||
extern int register_android_graphics_LayerRasterizer(JNIEnv*);
|
||||
extern int register_android_graphics_MaskFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_Movie(JNIEnv* env);
|
||||
extern int register_android_graphics_NinePatch(JNIEnv*);
|
||||
@@ -109,6 +108,7 @@ extern int register_android_graphics_CanvasProperty(JNIEnv* env);
|
||||
extern int register_android_graphics_ColorFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_DrawFilter(JNIEnv* env);
|
||||
extern int register_android_graphics_FontFamily(JNIEnv* env);
|
||||
extern int register_android_graphics_LayerRasterizer(JNIEnv*);
|
||||
extern int register_android_graphics_Matrix(JNIEnv* env);
|
||||
extern int register_android_graphics_Paint(JNIEnv* env);
|
||||
extern int register_android_graphics_Path(JNIEnv* env);
|
||||
|
||||
@@ -52,6 +52,10 @@ public:
|
||||
static SkPicture* getNativePicture(JNIEnv*, jobject picture);
|
||||
static SkRegion* getNativeRegion(JNIEnv*, jobject region);
|
||||
|
||||
// Given the 'native' long held by the Rasterizer.java object, return a
|
||||
// ref to its SkRasterizer* (or NULL).
|
||||
static SkRasterizer* refNativeRasterizer(jlong rasterizerHandle);
|
||||
|
||||
/** Return the corresponding native config from the java Config enum,
|
||||
or kNo_Config if the java object is null.
|
||||
*/
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#include "SkLayerRasterizer.h"
|
||||
#include <jni.h>
|
||||
|
||||
class SkLayerRasterizerGlue {
|
||||
public:
|
||||
static jlong create(JNIEnv* env, jobject) {
|
||||
return reinterpret_cast<jlong>(new SkLayerRasterizer());
|
||||
}
|
||||
|
||||
static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) {
|
||||
SkLayerRasterizer* layer = reinterpret_cast<SkLayerRasterizer *>(layerHandle);
|
||||
const SkPaint* paint = reinterpret_cast<SkPaint *>(paintHandle);
|
||||
SkASSERT(layer);
|
||||
SkASSERT(paint);
|
||||
layer->addLayer(*paint, dx, dy);
|
||||
}
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
|
||||
static JNINativeMethod gLayerRasterizerMethods[] = {
|
||||
{ "nativeConstructor", "()J", (void*)SkLayerRasterizerGlue::create },
|
||||
{ "nativeAddLayer", "(JJFF)V", (void*)SkLayerRasterizerGlue::addLayer }
|
||||
};
|
||||
|
||||
int register_android_graphics_LayerRasterizer(JNIEnv* env)
|
||||
{
|
||||
return android::AndroidRuntime::registerNativeMethods(env,
|
||||
"android/graphics/LayerRasterizer",
|
||||
gLayerRasterizerMethods,
|
||||
SK_ARRAY_COUNT(gLayerRasterizerMethods));
|
||||
}
|
||||
@@ -106,16 +106,33 @@ public:
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
// Equivalent to the Java Paint's FILTER_BITMAP_FLAG.
|
||||
static const uint32_t sFilterBitmapFlag = 0x02;
|
||||
|
||||
static jint getFlags(JNIEnv* env, jobject paint) {
|
||||
NPE_CHECK_RETURN_ZERO(env, paint);
|
||||
int result;
|
||||
result = GraphicsJNI::getNativePaint(env, paint)->getFlags();
|
||||
SkPaint* nativePaint = GraphicsJNI::getNativePaint(env, paint);
|
||||
uint32_t result = nativePaint->getFlags();
|
||||
result &= ~sFilterBitmapFlag; // Filtering no longer stored in this bit. Mask away.
|
||||
if (nativePaint->getFilterLevel() != SkPaint::kNone_FilterLevel) {
|
||||
result |= sFilterBitmapFlag;
|
||||
}
|
||||
return static_cast<jint>(result);
|
||||
}
|
||||
|
||||
static void setFlags(JNIEnv* env, jobject paint, jint flags) {
|
||||
NPE_CHECK_RETURN_VOID(env, paint);
|
||||
GraphicsJNI::getNativePaint(env, paint)->setFlags(flags);
|
||||
SkPaint* nativePaint = GraphicsJNI::getNativePaint(env, paint);
|
||||
// Instead of modifying 0x02, change the filter level.
|
||||
nativePaint->setFilterLevel(flags & sFilterBitmapFlag
|
||||
? SkPaint::kLow_FilterLevel
|
||||
: SkPaint::kNone_FilterLevel);
|
||||
// Don't pass through filter flag, which is no longer stored in paint's flags.
|
||||
flags &= ~sFilterBitmapFlag;
|
||||
// Use the existing value for 0x02.
|
||||
const uint32_t existing0x02Flag = nativePaint->getFlags() & sFilterBitmapFlag;
|
||||
flags |= existing0x02Flag;
|
||||
nativePaint->setFlags(flags);
|
||||
}
|
||||
|
||||
static jint getHinting(JNIEnv* env, jobject paint) {
|
||||
@@ -298,7 +315,7 @@ public:
|
||||
|
||||
static jlong setRasterizer(JNIEnv* env, jobject clazz, jlong objHandle, jlong rasterizerHandle) {
|
||||
SkPaint* obj = reinterpret_cast<SkPaint*>(objHandle);
|
||||
SkRasterizer* rasterizer = reinterpret_cast<SkRasterizer*>(rasterizerHandle);
|
||||
SkAutoTUnref<SkRasterizer> rasterizer(GraphicsJNI::refNativeRasterizer(rasterizerHandle));
|
||||
return reinterpret_cast<jlong>(obj->setRasterizer(rasterizer));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,30 +22,82 @@
|
||||
|
||||
#include "jni.h"
|
||||
#include "GraphicsJNI.h"
|
||||
#include "SkLayerRasterizer.h"
|
||||
#include <android_runtime/AndroidRuntime.h>
|
||||
|
||||
#include "SkRasterizer.h"
|
||||
// Rasterizer.java holds a pointer (jlong) to this guy
|
||||
class NativeRasterizer {
|
||||
public:
|
||||
NativeRasterizer() {}
|
||||
virtual ~NativeRasterizer() {}
|
||||
|
||||
// Can return NULL, or a ref to the skia rasterizer.
|
||||
virtual SkRasterizer* refRasterizer() { return NULL; }
|
||||
};
|
||||
|
||||
class NativeLayerRasterizer : public NativeRasterizer {
|
||||
public:
|
||||
SkLayerRasterizer::Builder fBuilder;
|
||||
|
||||
virtual SkRasterizer* refRasterizer() {
|
||||
return fBuilder.snapshotRasterizer();
|
||||
}
|
||||
};
|
||||
|
||||
SkRasterizer* GraphicsJNI::refNativeRasterizer(jlong rasterizerHandle) {
|
||||
NativeRasterizer* nr = reinterpret_cast<NativeRasterizer*>(rasterizerHandle);
|
||||
return nr ? nr->refRasterizer() : NULL;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace android {
|
||||
|
||||
class SkRasterizerGlue {
|
||||
public:
|
||||
|
||||
static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
|
||||
SkRasterizer* obj = reinterpret_cast<SkRasterizer *>(objHandle);
|
||||
SkSafeUnref(obj);
|
||||
delete reinterpret_cast<NativeRasterizer *>(objHandle);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static JNINativeMethod methods[] = {
|
||||
static JNINativeMethod gRasterizerMethods[] = {
|
||||
{"finalizer", "(J)V", (void*) SkRasterizerGlue::finalizer}
|
||||
};
|
||||
|
||||
int register_android_graphics_Rasterizer(JNIEnv* env) {
|
||||
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Rasterizer", methods,
|
||||
sizeof(methods) / sizeof(methods[0]));
|
||||
int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Rasterizer", gRasterizerMethods,
|
||||
sizeof(gRasterizerMethods) / sizeof(gRasterizerMethods[0]));
|
||||
return result;
|
||||
}
|
||||
|
||||
class SkLayerRasterizerGlue {
|
||||
public:
|
||||
static jlong create(JNIEnv* env, jobject) {
|
||||
return reinterpret_cast<jlong>(new NativeLayerRasterizer);
|
||||
}
|
||||
|
||||
static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) {
|
||||
NativeLayerRasterizer* nr = reinterpret_cast<NativeLayerRasterizer *>(layerHandle);
|
||||
const SkPaint* paint = reinterpret_cast<SkPaint *>(paintHandle);
|
||||
SkASSERT(nr);
|
||||
SkASSERT(paint);
|
||||
nr->fBuilder.addLayer(*paint, dx, dy);
|
||||
}
|
||||
};
|
||||
|
||||
static JNINativeMethod gLayerRasterizerMethods[] = {
|
||||
{ "nativeConstructor", "()J", (void*)SkLayerRasterizerGlue::create },
|
||||
{ "nativeAddLayer", "(JJFF)V", (void*)SkLayerRasterizerGlue::addLayer }
|
||||
};
|
||||
|
||||
int register_android_graphics_LayerRasterizer(JNIEnv* env)
|
||||
{
|
||||
return android::AndroidRuntime::registerNativeMethods(env,
|
||||
"android/graphics/LayerRasterizer",
|
||||
gLayerRasterizerMethods,
|
||||
SK_ARRAY_COUNT(gLayerRasterizerMethods));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user