diff options
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index fd9ce44..bd3b18d 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -18,6 +18,7 @@ #include <nativehelper/JNIHelp.h> #include <android_runtime/AndroidRuntime.h> +#include <SkBitmap.h> #include <SkCanvas.h> #include <SkMatrix.h> #include <SkPaint.h> @@ -44,11 +45,11 @@ static struct { // Constructors // ---------------------------------------------------------------------------- -static OpenGLRenderer* android_view_GLES20Renderer_createRenderer(JNIEnv* env, jobject canvas) { +static OpenGLRenderer* android_view_GLES20Canvas_createRenderer(JNIEnv* env, jobject canvas) { return new OpenGLRenderer; } -static void android_view_GLES20Renderer_destroyRenderer(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_destroyRenderer(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer) { delete renderer; } @@ -57,12 +58,12 @@ static void android_view_GLES20Renderer_destroyRenderer(JNIEnv* env, jobject can // Setup // ---------------------------------------------------------------------------- -static void android_view_GLES20Renderer_setViewport(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_setViewport(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jint width, jint height) { renderer->setViewport(width, height); } -static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_prepare(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer) { renderer->prepare(); } @@ -71,22 +72,22 @@ static void android_view_GLES20Renderer_prepare(JNIEnv* env, jobject canvas, // State // ---------------------------------------------------------------------------- -static jint android_view_GLES20Renderer_save(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, +static jint android_view_GLES20Canvas_save(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jint flags) { return renderer->save(flags); } -static jint android_view_GLES20Renderer_getSaveCount(JNIEnv* env, jobject canvas, +static jint android_view_GLES20Canvas_getSaveCount(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer) { return renderer->getSaveCount(); } -static void android_view_GLES20Renderer_restore(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_restore(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer) { renderer->restore(); } -static void android_view_GLES20Renderer_restoreToCount(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_restoreToCount(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jint saveCount) { renderer->restoreToCount(saveCount); } @@ -95,13 +96,13 @@ static void android_view_GLES20Renderer_restoreToCount(JNIEnv* env, jobject canv // Layers // ---------------------------------------------------------------------------- -static jint android_view_GLES20Renderer_saveLayer(JNIEnv* env, jobject canvas, +static jint android_view_GLES20Canvas_saveLayer(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, SkPaint* paint, jint saveFlags) { return renderer->saveLayer(left, top, right, bottom, paint, saveFlags); } -static jint android_view_GLES20Renderer_saveLayerAlpha(JNIEnv* env, jobject canvas, +static jint android_view_GLES20Canvas_saveLayerAlpha(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, jint alpha, jint saveFlags) { return renderer->saveLayerAlpha(left, top, right, bottom, alpha, saveFlags); @@ -111,25 +112,24 @@ static jint android_view_GLES20Renderer_saveLayerAlpha(JNIEnv* env, jobject canv // Clipping // ---------------------------------------------------------------------------- -static bool android_view_GLES20Renderer_quickReject(JNIEnv* env, jobject canvas, +static bool android_view_GLES20Canvas_quickReject(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, SkCanvas::EdgeType edge) { return renderer->quickReject(left, top, right, bottom); } -static bool android_view_GLES20Renderer_clipRectF(JNIEnv* env, jobject canvas, +static bool android_view_GLES20Canvas_clipRectF(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom) { return renderer->clipRect(left, top, right, bottom); } -static bool android_view_GLES20Renderer_clipRect(JNIEnv* env, jobject canvas, +static bool android_view_GLES20Canvas_clipRect(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jint left, jint top, jint right, jint bottom) { return renderer->clipRect(float(left), float(top), float(right), float(bottom)); } -static bool android_view_GLES20Renderer_getClipBounds(JNIEnv* env, jobject canvas, +static bool android_view_GLES20Canvas_getClipBounds(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jobject rect) { - const android::uirenderer::Rect& bounds(renderer->getClipBounds()); env->CallVoidMethod(rect, gRectClassInfo.set, @@ -142,32 +142,32 @@ static bool android_view_GLES20Renderer_getClipBounds(JNIEnv* env, jobject canva // Transforms // ---------------------------------------------------------------------------- -static void android_view_GLES20Renderer_translate(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_translate(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat dx, jfloat dy) { renderer->translate(dx, dy); } -static void android_view_GLES20Renderer_rotate(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_rotate(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat degrees) { renderer->rotate(degrees); } -static void android_view_GLES20Renderer_scale(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_scale(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat sx, jfloat sy) { renderer->scale(sx, sy); } -static void android_view_GLES20Renderer_setMatrix(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_setMatrix(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, SkMatrix* matrix) { renderer->setMatrix(matrix); } -static void android_view_GLES20Renderer_getMatrix(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_getMatrix(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, SkMatrix* matrix) { renderer->getMatrix(matrix); } -static void android_view_GLES20Renderer_concatMatrix(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, SkMatrix* matrix) { renderer->concatMatrix(matrix); } @@ -176,12 +176,37 @@ static void android_view_GLES20Renderer_concatMatrix(JNIEnv* env, jobject canvas // Drawing // ---------------------------------------------------------------------------- -static void android_view_GLES20Renderer_drawColor(JNIEnv* env, jobject canvas, - OpenGLRenderer* renderer, jint color, jint mode) { - renderer->drawColor(color, (SkXfermode::Mode) mode); +static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject canvas, + OpenGLRenderer* renderer, SkBitmap* bitmap, float left, float top, + SkPaint* paint, jint bitmapDensity, jint canvasDensity,jint screenDensity) { + if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) { + renderer->drawBitmap(bitmap, left, top, paint); + } else { + renderer->save(0); + const float scale = canvasDensity / float(bitmapDensity); + renderer->translate(left, top); + renderer->scale(scale, scale); + renderer->drawBitmap(bitmap, left, top, paint); + renderer->restore(); + } +} + +static void android_view_GLES20Canvas_drawBitmapRect(JNIEnv* env, jobject canvas, + OpenGLRenderer* renderer, SkBitmap* bitmap, + float srcLeft, float srcTop, float srcRight, float srcBottom, + float dstLeft, float dstTop, float dstRight, float dstBottom, + SkMatrix* matrix, SkPaint* paint, + jint bitmapDenstiy, jint canvasDensity, jint screenDensity) { + // TODO: Implement! + LOGE("Not implemented: drawBitmap(IIFFFFFFFFIIIII)V"); +} + +static void android_view_GLES20Canvas_drawColor(JNIEnv* env, jobject canvas, + OpenGLRenderer* renderer, jint color, SkXfermode::Mode mode) { + renderer->drawColor(color, mode); } -static void android_view_GLES20Renderer_drawRect(JNIEnv* env, jobject canvas, +static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject canvas, OpenGLRenderer* renderer, jfloat left, jfloat top, jfloat right, jfloat bottom, SkPaint* paint) { renderer->drawRect(left, top, right, bottom, paint); @@ -194,36 +219,38 @@ static void android_view_GLES20Renderer_drawRect(JNIEnv* env, jobject canvas, const char* const kClassPathName = "android/view/GLES20Canvas"; static JNINativeMethod gMethods[] = { - { "nCreateRenderer", "()I", (void*) android_view_GLES20Renderer_createRenderer }, - { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Renderer_destroyRenderer }, - { "nSetViewport", "(III)V", (void*) android_view_GLES20Renderer_setViewport }, - { "nPrepare", "(I)V", (void*) android_view_GLES20Renderer_prepare }, + { "nCreateRenderer", "()I", (void*) android_view_GLES20Canvas_createRenderer }, + { "nDestroyRenderer", "(I)V", (void*) android_view_GLES20Canvas_destroyRenderer }, + { "nSetViewport", "(III)V", (void*) android_view_GLES20Canvas_setViewport }, + { "nPrepare", "(I)V", (void*) android_view_GLES20Canvas_prepare }, - { "nSave", "(II)I", (void*) android_view_GLES20Renderer_save }, - { "nRestore", "(I)V", (void*) android_view_GLES20Renderer_restore }, - { "nRestoreToCount", "(II)V", (void*) android_view_GLES20Renderer_restoreToCount }, - { "nGetSaveCount", "(I)I", (void*) android_view_GLES20Renderer_getSaveCount }, + { "nSave", "(II)I", (void*) android_view_GLES20Canvas_save }, + { "nRestore", "(I)V", (void*) android_view_GLES20Canvas_restore }, + { "nRestoreToCount", "(II)V", (void*) android_view_GLES20Canvas_restoreToCount }, + { "nGetSaveCount", "(I)I", (void*) android_view_GLES20Canvas_getSaveCount }, - { "nSaveLayer", "(IFFFFII)I", (void*) android_view_GLES20Renderer_saveLayer }, - { "nSaveLayerAlpha", "(IFFFFII)I", (void*) android_view_GLES20Renderer_saveLayerAlpha }, + { "nSaveLayer", "(IFFFFII)I", (void*) android_view_GLES20Canvas_saveLayer }, + { "nSaveLayerAlpha", "(IFFFFII)I", (void*) android_view_GLES20Canvas_saveLayerAlpha }, - { "nQuickReject", "(IFFFFI)Z", (void*) android_view_GLES20Renderer_quickReject }, - { "nClipRect", "(IFFFF)Z", (void*) android_view_GLES20Renderer_clipRectF }, - { "nClipRect", "(IIIII)Z", (void*) android_view_GLES20Renderer_clipRect }, + { "nQuickReject", "(IFFFFI)Z", (void*) android_view_GLES20Canvas_quickReject }, + { "nClipRect", "(IFFFF)Z", (void*) android_view_GLES20Canvas_clipRectF }, + { "nClipRect", "(IIIII)Z", (void*) android_view_GLES20Canvas_clipRect }, - { "nTranslate", "(IFF)V", (void*) android_view_GLES20Renderer_translate }, - { "nRotate", "(IF)V", (void*) android_view_GLES20Renderer_rotate }, - { "nScale", "(IFF)V", (void*) android_view_GLES20Renderer_scale }, + { "nTranslate", "(IFF)V", (void*) android_view_GLES20Canvas_translate }, + { "nRotate", "(IF)V", (void*) android_view_GLES20Canvas_rotate }, + { "nScale", "(IFF)V", (void*) android_view_GLES20Canvas_scale }, - { "nSetMatrix", "(II)V", (void*) android_view_GLES20Renderer_setMatrix }, - { "nGetMatrix", "(II)V", (void*) android_view_GLES20Renderer_getMatrix }, - { "nConcatMatrix", "(II)V", (void*) android_view_GLES20Renderer_concatMatrix }, + { "nSetMatrix", "(II)V", (void*) android_view_GLES20Canvas_setMatrix }, + { "nGetMatrix", "(II)V", (void*) android_view_GLES20Canvas_getMatrix }, + { "nConcatMatrix", "(II)V", (void*) android_view_GLES20Canvas_concatMatrix }, - { "nDrawColor", "(III)V", (void*) android_view_GLES20Renderer_drawColor }, - { "nDrawRect", "(IFFFFI)V", (void*) android_view_GLES20Renderer_drawRect }, + { "nDrawBitmap", "(IIFFIIII)V", (void*) android_view_GLES20Canvas_drawBitmap }, + { "nDrawBitmap", "(IIFFFFFFFFIIIII)V", (void*) android_view_GLES20Canvas_drawBitmapRect }, + { "nDrawColor", "(III)V", (void*) android_view_GLES20Canvas_drawColor }, + { "nDrawRect", "(IFFFFI)V", (void*) android_view_GLES20Canvas_drawRect }, { "nGetClipBounds", "(ILandroid/graphics/Rect;)Z", - (void*) android_view_GLES20Renderer_getClipBounds }, + (void*) android_view_GLES20Canvas_getClipBounds }, }; #define FIND_CLASS(var, className) \ |