diff options
Diffstat (limited to 'core/jni/android')
-rwxr-xr-x | core/jni/android/graphics/Bitmap.cpp | 10 | ||||
-rw-r--r-- | core/jni/android/graphics/BitmapFactory.cpp | 3 | ||||
-rw-r--r-- | core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp | 5 | ||||
-rw-r--r-- | core/jni/android/graphics/Matrix.cpp | 81 | ||||
-rw-r--r-- | core/jni/android/graphics/NinePatch.cpp | 6 | ||||
-rw-r--r-- | core/jni/android/graphics/Paint.cpp | 109 | ||||
-rw-r--r-- | core/jni/android/graphics/Path.cpp | 6 | ||||
-rw-r--r-- | core/jni/android/graphics/SurfaceTexture.cpp | 4 | ||||
-rw-r--r-- | core/jni/android/graphics/pdf/PdfEditor.cpp | 217 | ||||
-rw-r--r-- | core/jni/android/graphics/pdf/PdfRenderer.cpp | 13 |
10 files changed, 341 insertions, 113 deletions
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 70cf9a8..d7eef6e 100755 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -17,7 +17,7 @@ #include <jni.h> -#include <Caches.h> +#include <ResourceCache.h> #if 0 #define TRACE_BITMAP(code) code @@ -365,8 +365,8 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle, static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) { SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); #ifdef USE_OPENGL_RENDERER - if (android::uirenderer::Caches::hasInstance()) { - android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap); + if (android::uirenderer::ResourceCache::hasInstance()) { + android::uirenderer::ResourceCache::getInstance().destructor(bitmap); return; } #endif // USE_OPENGL_RENDERER @@ -376,9 +376,9 @@ static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) { static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) { SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); #ifdef USE_OPENGL_RENDERER - if (android::uirenderer::Caches::hasInstance()) { + if (android::uirenderer::ResourceCache::hasInstance()) { bool result; - result = android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap); + result = android::uirenderer::ResourceCache::getInstance().recycle(bitmap); return result ? JNI_TRUE : JNI_FALSE; } #endif // USE_OPENGL_RENDERER diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index e0abc24..a578b5d 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -315,7 +315,8 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding } SkBitmap decodingBitmap; - if (!decoder->decode(stream, &decodingBitmap, prefColorType, decodeMode)) { + if (decoder->decode(stream, &decodingBitmap, prefColorType, decodeMode) + != SkImageDecoder::kSuccess) { return nullObjectReturn("decoder->decode returned false"); } diff --git a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp index b64ab0d..a67740c 100644 --- a/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp +++ b/core/jni/android/graphics/CreateJavaOutputStreamAdaptor.cpp @@ -78,6 +78,8 @@ private: env->ExceptionDescribe(); env->ExceptionClear(); SkDebugf("---- read threw an exception\n"); + // Consider the stream to be at the end, since there was an error. + fIsAtEnd = true; return 0; } @@ -92,6 +94,9 @@ private: env->ExceptionDescribe(); env->ExceptionClear(); SkDebugf("---- read:GetByteArrayRegion threw an exception\n"); + // The error was not with the stream itself, but consider it to be at the + // end, since we do not have a way to recover. + fIsAtEnd = true; return 0; } diff --git a/core/jni/android/graphics/Matrix.cpp b/core/jni/android/graphics/Matrix.cpp index cbd20e9..01ab699 100644 --- a/core/jni/android/graphics/Matrix.cpp +++ b/core/jni/android/graphics/Matrix.cpp @@ -308,46 +308,47 @@ public: static JNINativeMethod methods[] = { {"finalizer", "(J)V", (void*) SkMatrixGlue::finalizer}, {"native_create","(J)J", (void*) SkMatrixGlue::create}, - {"native_isIdentity","(J)Z", (void*) SkMatrixGlue::isIdentity}, - {"native_isAffine","(J)Z", (void*) SkMatrixGlue::isAffine}, - {"native_rectStaysRect","(J)Z", (void*) SkMatrixGlue::rectStaysRect}, - {"native_reset","(J)V", (void*) SkMatrixGlue::reset}, - {"native_set","(JJ)V", (void*) SkMatrixGlue::set}, - {"native_setTranslate","(JFF)V", (void*) SkMatrixGlue::setTranslate}, - {"native_setScale","(JFFFF)V", (void*) SkMatrixGlue::setScale__FFFF}, - {"native_setScale","(JFF)V", (void*) SkMatrixGlue::setScale__FF}, - {"native_setRotate","(JFFF)V", (void*) SkMatrixGlue::setRotate__FFF}, - {"native_setRotate","(JF)V", (void*) SkMatrixGlue::setRotate__F}, - {"native_setSinCos","(JFFFF)V", (void*) SkMatrixGlue::setSinCos__FFFF}, - {"native_setSinCos","(JFF)V", (void*) SkMatrixGlue::setSinCos__FF}, - {"native_setSkew","(JFFFF)V", (void*) SkMatrixGlue::setSkew__FFFF}, - {"native_setSkew","(JFF)V", (void*) SkMatrixGlue::setSkew__FF}, - {"native_setConcat","(JJJ)V", (void*) SkMatrixGlue::setConcat}, - {"native_preTranslate","(JFF)V", (void*) SkMatrixGlue::preTranslate}, - {"native_preScale","(JFFFF)V", (void*) SkMatrixGlue::preScale__FFFF}, - {"native_preScale","(JFF)V", (void*) SkMatrixGlue::preScale__FF}, - {"native_preRotate","(JFFF)V", (void*) SkMatrixGlue::preRotate__FFF}, - {"native_preRotate","(JF)V", (void*) SkMatrixGlue::preRotate__F}, - {"native_preSkew","(JFFFF)V", (void*) SkMatrixGlue::preSkew__FFFF}, - {"native_preSkew","(JFF)V", (void*) SkMatrixGlue::preSkew__FF}, - {"native_preConcat","(JJ)V", (void*) SkMatrixGlue::preConcat}, - {"native_postTranslate","(JFF)V", (void*) SkMatrixGlue::postTranslate}, - {"native_postScale","(JFFFF)V", (void*) SkMatrixGlue::postScale__FFFF}, - {"native_postScale","(JFF)V", (void*) SkMatrixGlue::postScale__FF}, - {"native_postRotate","(JFFF)V", (void*) SkMatrixGlue::postRotate__FFF}, - {"native_postRotate","(JF)V", (void*) SkMatrixGlue::postRotate__F}, - {"native_postSkew","(JFFFF)V", (void*) SkMatrixGlue::postSkew__FFFF}, - {"native_postSkew","(JFF)V", (void*) SkMatrixGlue::postSkew__FF}, - {"native_postConcat","(JJ)V", (void*) SkMatrixGlue::postConcat}, - {"native_setRectToRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;I)Z", (void*) SkMatrixGlue::setRectToRect}, - {"native_setPolyToPoly","(J[FI[FII)Z", (void*) SkMatrixGlue::setPolyToPoly}, - {"native_invert","(JJ)Z", (void*) SkMatrixGlue::invert}, - {"native_mapPoints","(J[FI[FIIZ)V", (void*) SkMatrixGlue::mapPoints}, - {"native_mapRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;)Z", (void*) SkMatrixGlue::mapRect__RectFRectF}, - {"native_mapRadius","(JF)F", (void*) SkMatrixGlue::mapRadius}, - {"native_getValues","(J[F)V", (void*) SkMatrixGlue::getValues}, - {"native_setValues","(J[F)V", (void*) SkMatrixGlue::setValues}, - {"native_equals", "(JJ)Z", (void*) SkMatrixGlue::equals} + + {"native_isIdentity","!(J)Z", (void*) SkMatrixGlue::isIdentity}, + {"native_isAffine","!(J)Z", (void*) SkMatrixGlue::isAffine}, + {"native_rectStaysRect","!(J)Z", (void*) SkMatrixGlue::rectStaysRect}, + {"native_reset","!(J)V", (void*) SkMatrixGlue::reset}, + {"native_set","!(JJ)V", (void*) SkMatrixGlue::set}, + {"native_setTranslate","!(JFF)V", (void*) SkMatrixGlue::setTranslate}, + {"native_setScale","!(JFFFF)V", (void*) SkMatrixGlue::setScale__FFFF}, + {"native_setScale","!(JFF)V", (void*) SkMatrixGlue::setScale__FF}, + {"native_setRotate","!(JFFF)V", (void*) SkMatrixGlue::setRotate__FFF}, + {"native_setRotate","!(JF)V", (void*) SkMatrixGlue::setRotate__F}, + {"native_setSinCos","!(JFFFF)V", (void*) SkMatrixGlue::setSinCos__FFFF}, + {"native_setSinCos","!(JFF)V", (void*) SkMatrixGlue::setSinCos__FF}, + {"native_setSkew","!(JFFFF)V", (void*) SkMatrixGlue::setSkew__FFFF}, + {"native_setSkew","!(JFF)V", (void*) SkMatrixGlue::setSkew__FF}, + {"native_setConcat","!(JJJ)V", (void*) SkMatrixGlue::setConcat}, + {"native_preTranslate","!(JFF)V", (void*) SkMatrixGlue::preTranslate}, + {"native_preScale","!(JFFFF)V", (void*) SkMatrixGlue::preScale__FFFF}, + {"native_preScale","!(JFF)V", (void*) SkMatrixGlue::preScale__FF}, + {"native_preRotate","!(JFFF)V", (void*) SkMatrixGlue::preRotate__FFF}, + {"native_preRotate","!(JF)V", (void*) SkMatrixGlue::preRotate__F}, + {"native_preSkew","!(JFFFF)V", (void*) SkMatrixGlue::preSkew__FFFF}, + {"native_preSkew","!(JFF)V", (void*) SkMatrixGlue::preSkew__FF}, + {"native_preConcat","!(JJ)V", (void*) SkMatrixGlue::preConcat}, + {"native_postTranslate","!(JFF)V", (void*) SkMatrixGlue::postTranslate}, + {"native_postScale","!(JFFFF)V", (void*) SkMatrixGlue::postScale__FFFF}, + {"native_postScale","!(JFF)V", (void*) SkMatrixGlue::postScale__FF}, + {"native_postRotate","!(JFFF)V", (void*) SkMatrixGlue::postRotate__FFF}, + {"native_postRotate","!(JF)V", (void*) SkMatrixGlue::postRotate__F}, + {"native_postSkew","!(JFFFF)V", (void*) SkMatrixGlue::postSkew__FFFF}, + {"native_postSkew","!(JFF)V", (void*) SkMatrixGlue::postSkew__FF}, + {"native_postConcat","!(JJ)V", (void*) SkMatrixGlue::postConcat}, + {"native_setRectToRect","!(JLandroid/graphics/RectF;Landroid/graphics/RectF;I)Z", (void*) SkMatrixGlue::setRectToRect}, + {"native_setPolyToPoly","!(J[FI[FII)Z", (void*) SkMatrixGlue::setPolyToPoly}, + {"native_invert","!(JJ)Z", (void*) SkMatrixGlue::invert}, + {"native_mapPoints","!(J[FI[FIIZ)V", (void*) SkMatrixGlue::mapPoints}, + {"native_mapRect","!(JLandroid/graphics/RectF;Landroid/graphics/RectF;)Z", (void*) SkMatrixGlue::mapRect__RectFRectF}, + {"native_mapRadius","!(JF)F", (void*) SkMatrixGlue::mapRadius}, + {"native_getValues","!(J[F)V", (void*) SkMatrixGlue::getValues}, + {"native_setValues","!(J[F)V", (void*) SkMatrixGlue::setValues}, + {"native_equals", "!(JJ)Z", (void*) SkMatrixGlue::equals} }; static jfieldID sNativeInstanceField; diff --git a/core/jni/android/graphics/NinePatch.cpp b/core/jni/android/graphics/NinePatch.cpp index cf23771..be62fdd 100644 --- a/core/jni/android/graphics/NinePatch.cpp +++ b/core/jni/android/graphics/NinePatch.cpp @@ -21,7 +21,7 @@ #include <androidfw/ResourceTypes.h> #include <utils/Log.h> -#include <Caches.h> +#include <ResourceCache.h> #include "Paint.h" #include "Canvas.h" @@ -80,9 +80,9 @@ public: static void finalize(JNIEnv* env, jobject, jlong patchHandle) { int8_t* patch = reinterpret_cast<int8_t*>(patchHandle); #ifdef USE_OPENGL_RENDERER - if (android::uirenderer::Caches::hasInstance()) { + if (android::uirenderer::ResourceCache::hasInstance()) { Res_png_9patch* p = (Res_png_9patch*) patch; - android::uirenderer::Caches::getInstance().resourceCache.destructor(p); + android::uirenderer::ResourceCache::getInstance().destructor(p); return; } #endif // USE_OPENGL_RENDERER diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 4bb31fc..6b02326 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -939,58 +939,60 @@ static JNINativeMethod methods[] = { {"finalizer", "(J)V", (void*) PaintGlue::finalizer}, {"native_init","()J", (void*) PaintGlue::init}, {"native_initWithPaint","(J)J", (void*) PaintGlue::initWithPaint}, - {"native_reset","(J)V", (void*) PaintGlue::reset}, - {"native_set","(JJ)V", (void*) PaintGlue::assign}, - {"getFlags","()I", (void*) PaintGlue::getFlags}, - {"setFlags","(I)V", (void*) PaintGlue::setFlags}, - {"getHinting","()I", (void*) PaintGlue::getHinting}, - {"setHinting","(I)V", (void*) PaintGlue::setHinting}, - {"setAntiAlias","(Z)V", (void*) PaintGlue::setAntiAlias}, - {"setSubpixelText","(Z)V", (void*) PaintGlue::setSubpixelText}, - {"setLinearText","(Z)V", (void*) PaintGlue::setLinearText}, - {"setUnderlineText","(Z)V", (void*) PaintGlue::setUnderlineText}, - {"setStrikeThruText","(Z)V", (void*) PaintGlue::setStrikeThruText}, - {"setFakeBoldText","(Z)V", (void*) PaintGlue::setFakeBoldText}, - {"setFilterBitmap","(Z)V", (void*) PaintGlue::setFilterBitmap}, - {"setDither","(Z)V", (void*) PaintGlue::setDither}, - {"native_getStyle","(J)I", (void*) PaintGlue::getStyle}, - {"native_setStyle","(JI)V", (void*) PaintGlue::setStyle}, - {"getColor","()I", (void*) PaintGlue::getColor}, - {"setColor","(I)V", (void*) PaintGlue::setColor}, - {"getAlpha","()I", (void*) PaintGlue::getAlpha}, - {"setAlpha","(I)V", (void*) PaintGlue::setAlpha}, - {"getStrokeWidth","()F", (void*) PaintGlue::getStrokeWidth}, - {"setStrokeWidth","(F)V", (void*) PaintGlue::setStrokeWidth}, - {"getStrokeMiter","()F", (void*) PaintGlue::getStrokeMiter}, - {"setStrokeMiter","(F)V", (void*) PaintGlue::setStrokeMiter}, - {"native_getStrokeCap","(J)I", (void*) PaintGlue::getStrokeCap}, - {"native_setStrokeCap","(JI)V", (void*) PaintGlue::setStrokeCap}, - {"native_getStrokeJoin","(J)I", (void*) PaintGlue::getStrokeJoin}, - {"native_setStrokeJoin","(JI)V", (void*) PaintGlue::setStrokeJoin}, - {"native_getFillPath","(JJJ)Z", (void*) PaintGlue::getFillPath}, - {"native_setShader","(JJ)J", (void*) PaintGlue::setShader}, - {"native_setColorFilter","(JJ)J", (void*) PaintGlue::setColorFilter}, - {"native_setXfermode","(JJ)J", (void*) PaintGlue::setXfermode}, - {"native_setPathEffect","(JJ)J", (void*) PaintGlue::setPathEffect}, - {"native_setMaskFilter","(JJ)J", (void*) PaintGlue::setMaskFilter}, - {"native_setTypeface","(JJ)J", (void*) PaintGlue::setTypeface}, - {"native_setRasterizer","(JJ)J", (void*) PaintGlue::setRasterizer}, - {"native_getTextAlign","(J)I", (void*) PaintGlue::getTextAlign}, - {"native_setTextAlign","(JI)V", (void*) PaintGlue::setTextAlign}, - {"native_setTextLocale","(JLjava/lang/String;)V", (void*) PaintGlue::setTextLocale}, - {"isElegantTextHeight","()Z", (void*) PaintGlue::isElegantTextHeight}, - {"setElegantTextHeight","(Z)V", (void*) PaintGlue::setElegantTextHeight}, - {"getTextSize","()F", (void*) PaintGlue::getTextSize}, - {"setTextSize","(F)V", (void*) PaintGlue::setTextSize}, - {"getTextScaleX","()F", (void*) PaintGlue::getTextScaleX}, - {"setTextScaleX","(F)V", (void*) PaintGlue::setTextScaleX}, - {"getTextSkewX","()F", (void*) PaintGlue::getTextSkewX}, - {"setTextSkewX","(F)V", (void*) PaintGlue::setTextSkewX}, - {"native_getLetterSpacing","(J)F", (void*) PaintGlue::getLetterSpacing}, - {"native_setLetterSpacing","(JF)V", (void*) PaintGlue::setLetterSpacing}, + + {"native_reset","!(J)V", (void*) PaintGlue::reset}, + {"native_set","!(JJ)V", (void*) PaintGlue::assign}, + {"getFlags","!()I", (void*) PaintGlue::getFlags}, + {"setFlags","!(I)V", (void*) PaintGlue::setFlags}, + {"getHinting","!()I", (void*) PaintGlue::getHinting}, + {"setHinting","!(I)V", (void*) PaintGlue::setHinting}, + {"setAntiAlias","!(Z)V", (void*) PaintGlue::setAntiAlias}, + {"setSubpixelText","!(Z)V", (void*) PaintGlue::setSubpixelText}, + {"setLinearText","!(Z)V", (void*) PaintGlue::setLinearText}, + {"setUnderlineText","!(Z)V", (void*) PaintGlue::setUnderlineText}, + {"setStrikeThruText","!(Z)V", (void*) PaintGlue::setStrikeThruText}, + {"setFakeBoldText","!(Z)V", (void*) PaintGlue::setFakeBoldText}, + {"setFilterBitmap","!(Z)V", (void*) PaintGlue::setFilterBitmap}, + {"setDither","!(Z)V", (void*) PaintGlue::setDither}, + {"native_getStyle","!(J)I", (void*) PaintGlue::getStyle}, + {"native_setStyle","!(JI)V", (void*) PaintGlue::setStyle}, + {"getColor","!()I", (void*) PaintGlue::getColor}, + {"setColor","!(I)V", (void*) PaintGlue::setColor}, + {"getAlpha","!()I", (void*) PaintGlue::getAlpha}, + {"setAlpha","!(I)V", (void*) PaintGlue::setAlpha}, + {"getStrokeWidth","!()F", (void*) PaintGlue::getStrokeWidth}, + {"setStrokeWidth","!(F)V", (void*) PaintGlue::setStrokeWidth}, + {"getStrokeMiter","!()F", (void*) PaintGlue::getStrokeMiter}, + {"setStrokeMiter","!(F)V", (void*) PaintGlue::setStrokeMiter}, + {"native_getStrokeCap","!(J)I", (void*) PaintGlue::getStrokeCap}, + {"native_setStrokeCap","!(JI)V", (void*) PaintGlue::setStrokeCap}, + {"native_getStrokeJoin","!(J)I", (void*) PaintGlue::getStrokeJoin}, + {"native_setStrokeJoin","!(JI)V", (void*) PaintGlue::setStrokeJoin}, + {"native_getFillPath","!(JJJ)Z", (void*) PaintGlue::getFillPath}, + {"native_setShader","!(JJ)J", (void*) PaintGlue::setShader}, + {"native_setColorFilter","!(JJ)J", (void*) PaintGlue::setColorFilter}, + {"native_setXfermode","!(JJ)J", (void*) PaintGlue::setXfermode}, + {"native_setPathEffect","!(JJ)J", (void*) PaintGlue::setPathEffect}, + {"native_setMaskFilter","!(JJ)J", (void*) PaintGlue::setMaskFilter}, + {"native_setTypeface","!(JJ)J", (void*) PaintGlue::setTypeface}, + {"native_setRasterizer","!(JJ)J", (void*) PaintGlue::setRasterizer}, + {"native_getTextAlign","!(J)I", (void*) PaintGlue::getTextAlign}, + {"native_setTextAlign","!(JI)V", (void*) PaintGlue::setTextAlign}, + {"native_setTextLocale","!(JLjava/lang/String;)V", (void*) PaintGlue::setTextLocale}, + {"isElegantTextHeight","!()Z", (void*) PaintGlue::isElegantTextHeight}, + {"setElegantTextHeight","!(Z)V", (void*) PaintGlue::setElegantTextHeight}, + {"getTextSize","!()F", (void*) PaintGlue::getTextSize}, + {"setTextSize","!(F)V", (void*) PaintGlue::setTextSize}, + {"getTextScaleX","!()F", (void*) PaintGlue::getTextScaleX}, + {"setTextScaleX","!(F)V", (void*) PaintGlue::setTextScaleX}, + {"getTextSkewX","!()F", (void*) PaintGlue::getTextSkewX}, + {"setTextSkewX","!(F)V", (void*) PaintGlue::setTextSkewX}, + {"native_getLetterSpacing","!(J)F", (void*) PaintGlue::getLetterSpacing}, + {"native_setLetterSpacing","!(JF)V", (void*) PaintGlue::setLetterSpacing}, {"native_setFontFeatureSettings","(JLjava/lang/String;)V", (void*) PaintGlue::setFontFeatureSettings}, - {"ascent","()F", (void*) PaintGlue::ascent}, - {"descent","()F", (void*) PaintGlue::descent}, + {"ascent","!()F", (void*) PaintGlue::ascent}, + {"descent","!()F", (void*) PaintGlue::descent}, + {"getFontMetrics", "(Landroid/graphics/Paint$FontMetrics;)F", (void*)PaintGlue::getFontMetrics}, {"getFontMetricsInt", "(Landroid/graphics/Paint$FontMetricsInt;)I", (void*)PaintGlue::getFontMetricsInt}, {"native_measureText","([CIII)F", (void*) PaintGlue::measureText_CIII}, @@ -1014,8 +1016,9 @@ static JNINativeMethod methods[] = { (void*) PaintGlue::getStringBounds }, {"nativeGetCharArrayBounds", "(JJ[CIIILandroid/graphics/Rect;)V", (void*) PaintGlue::getCharArrayBounds }, - {"native_setShadowLayer", "(JFFFI)V", (void*)PaintGlue::setShadowLayer}, - {"native_hasShadowLayer", "(J)Z", (void*)PaintGlue::hasShadowLayer} + + {"native_setShadowLayer", "!(JFFFI)V", (void*)PaintGlue::setShadowLayer}, + {"native_hasShadowLayer", "!(J)Z", (void*)PaintGlue::hasShadowLayer} }; static jfieldID req_fieldID(jfieldID id) { diff --git a/core/jni/android/graphics/Path.cpp b/core/jni/android/graphics/Path.cpp index 9d3e74b..30ce58d 100644 --- a/core/jni/android/graphics/Path.cpp +++ b/core/jni/android/graphics/Path.cpp @@ -27,7 +27,7 @@ #include "SkPath.h" #include "SkPathOps.h" -#include <Caches.h> +#include <ResourceCache.h> #include <vector> #include <map> @@ -39,8 +39,8 @@ public: static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { SkPath* obj = reinterpret_cast<SkPath*>(objHandle); #ifdef USE_OPENGL_RENDERER - if (android::uirenderer::Caches::hasInstance()) { - android::uirenderer::Caches::getInstance().resourceCache.destructor(obj); + if (android::uirenderer::ResourceCache::hasInstance()) { + android::uirenderer::ResourceCache::getInstance().destructor(obj); return; } #endif diff --git a/core/jni/android/graphics/SurfaceTexture.cpp b/core/jni/android/graphics/SurfaceTexture.cpp index eea16f1..eaca6d2 100644 --- a/core/jni/android/graphics/SurfaceTexture.cpp +++ b/core/jni/android/graphics/SurfaceTexture.cpp @@ -121,7 +121,7 @@ class JNISurfaceTextureContext : public GLConsumer::FrameAvailableListener public: JNISurfaceTextureContext(JNIEnv* env, jobject weakThiz, jclass clazz); virtual ~JNISurfaceTextureContext(); - virtual void onFrameAvailable(); + virtual void onFrameAvailable(const BufferItem& item); private: static JNIEnv* getJNIEnv(bool* needsDetach); @@ -177,7 +177,7 @@ JNISurfaceTextureContext::~JNISurfaceTextureContext() } } -void JNISurfaceTextureContext::onFrameAvailable() +void JNISurfaceTextureContext::onFrameAvailable(const BufferItem& /* item */) { bool needsDetach = false; JNIEnv* env = getJNIEnv(&needsDetach); diff --git a/core/jni/android/graphics/pdf/PdfEditor.cpp b/core/jni/android/graphics/pdf/PdfEditor.cpp index 5f60c9e..ed6f1d6 100644 --- a/core/jni/android/graphics/pdf/PdfEditor.cpp +++ b/core/jni/android/graphics/pdf/PdfEditor.cpp @@ -19,6 +19,9 @@ #include "fpdfview.h" #include "fpdfedit.h" #include "fpdfsave.h" +#include "fsdk_rendercontext.h" +#include "fpdf_transformpage.h" +#include "SkMatrix.h" #include <android_runtime/AndroidRuntime.h> #include <vector> @@ -29,6 +32,20 @@ namespace android { +enum PageBox {PAGE_BOX_MEDIA, PAGE_BOX_CROP}; + +static struct { + jfieldID x; + jfieldID y; +} gPointClassInfo; + +static struct { + jfieldID left; + jfieldID top; + jfieldID right; + jfieldID bottom; +} gRectClassInfo; + static Mutex sLock; static int sUnmatchedInitRequestCount = 0; @@ -72,8 +89,17 @@ static jlong nativeOpen(JNIEnv* env, jclass thiz, jint fd, jlong size) { if (!document) { const long error = FPDF_GetLastError(); - jniThrowException(env, "java/io/IOException", - "cannot create document. Error:" + error); + switch (error) { + case FPDF_ERR_PASSWORD: + case FPDF_ERR_SECURITY: { + jniThrowException(env, "java/lang/SecurityException", + "cannot create document. Error:" + error); + } break; + default: { + jniThrowException(env, "java/io/IOException", + "cannot create document. Error:" + error); + } break; + } destroyLibraryIfNeeded(); return -1; } @@ -144,18 +170,201 @@ static void nativeWrite(JNIEnv* env, jclass thiz, jlong documentPtr, jint fd) { } } +static void nativeSetTransformAndClip(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + jlong transformPtr, jint clipLeft, jint clipTop, jint clipRight, jint clipBottom) { + FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); + + CPDF_Page* page = (CPDF_Page*) FPDF_LoadPage(document, pageIndex); + if (!page) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot open page"); + return; + } + + double width = 0; + double height = 0; + + const int result = FPDF_GetPageSizeByIndex(document, pageIndex, &width, &height); + if (!result) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot get page size"); + return; + } + + CFX_AffineMatrix matrix; + + SkMatrix* skTransform = reinterpret_cast<SkMatrix*>(transformPtr); + + SkScalar transformValues[6]; + skTransform->asAffine(transformValues); + + // PDF's coordinate system origin is left-bottom while in graphics it + // is the top-left. So, translate the PDF coordinates to ours. + matrix.Set(1, 0, 0, -1, 0, page->GetPageHeight()); + + // Apply the transformation what was created in our coordinates. + matrix.Concat(transformValues[SkMatrix::kAScaleX], transformValues[SkMatrix::kASkewY], + transformValues[SkMatrix::kASkewX], transformValues[SkMatrix::kAScaleY], + transformValues[SkMatrix::kATransX], transformValues[SkMatrix::kATransY]); + + // Translate the result back to PDF coordinates. + matrix.Concat(1, 0, 0, -1, 0, page->GetPageHeight()); + + FS_MATRIX transform = {matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f}; + FS_RECTF clip = {(float) clipLeft, (float) clipTop, (float) clipRight, (float) clipBottom}; + + FPDFPage_TransFormWithClip(page, &transform, &clip); + + FPDF_ClosePage(page); +} + +static void nativeGetPageSize(JNIEnv* env, jclass thiz, jlong documentPtr, + jint pageIndex, jobject outSize) { + FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); + + FPDF_PAGE page = FPDF_LoadPage(document, pageIndex); + if (!page) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot open page"); + return; + } + + double width = 0; + double height = 0; + + const int result = FPDF_GetPageSizeByIndex(document, pageIndex, &width, &height); + if (!result) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot get page size"); + return; + } + + env->SetIntField(outSize, gPointClassInfo.x, width); + env->SetIntField(outSize, gPointClassInfo.y, height); + + FPDF_ClosePage(page); +} + +static jboolean nativeScaleForPrinting(JNIEnv* env, jclass thiz, jlong documentPtr) { + FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); + FPDF_BOOL success = FPDF_VIEWERREF_GetPrintScaling(document); + return success ? JNI_TRUE : JNI_FALSE; +} + +static bool nativeGetPageBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + PageBox pageBox, jobject outBox) { + FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); + + FPDF_PAGE page = FPDF_LoadPage(document, pageIndex); + if (!page) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot open page"); + return false; + } + + float left; + float top; + float right; + float bottom; + + const FPDF_BOOL success = (pageBox == PAGE_BOX_MEDIA) + ? FPDFPage_GetMediaBox(page, &left, &top, &right, &bottom) + : FPDFPage_GetCropBox(page, &left, &top, &right, &bottom); + + FPDF_ClosePage(page); + + if (!success) { + return false; + } + + env->SetIntField(outBox, gRectClassInfo.left, (int) left); + env->SetIntField(outBox, gRectClassInfo.top, (int) top); + env->SetIntField(outBox, gRectClassInfo.right, (int) right); + env->SetIntField(outBox, gRectClassInfo.bottom, (int) bottom); + + return true; +} + +static jboolean nativeGetPageMediaBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + jobject outMediaBox) { + const bool success = nativeGetPageBox(env, thiz, documentPtr, pageIndex, PAGE_BOX_MEDIA, + outMediaBox); + return success ? JNI_TRUE : JNI_FALSE; +} + +static jboolean nativeGetPageCropBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + jobject outMediaBox) { + const bool success = nativeGetPageBox(env, thiz, documentPtr, pageIndex, PAGE_BOX_CROP, + outMediaBox); + return success ? JNI_TRUE : JNI_FALSE; +} + +static void nativeSetPageBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + PageBox pageBox, jobject box) { + FPDF_DOCUMENT document = reinterpret_cast<FPDF_DOCUMENT>(documentPtr); + + FPDF_PAGE page = FPDF_LoadPage(document, pageIndex); + if (!page) { + jniThrowException(env, "java/lang/IllegalStateException", + "cannot open page"); + return; + } + + const int left = env->GetIntField(box, gRectClassInfo.left); + const int top = env->GetIntField(box, gRectClassInfo.top); + const int right = env->GetIntField(box, gRectClassInfo.right); + const int bottom = env->GetIntField(box, gRectClassInfo.bottom); + + if (pageBox == PAGE_BOX_MEDIA) { + FPDFPage_SetMediaBox(page, left, top, right, bottom); + } else { + FPDFPage_SetCropBox(page, left, top, right, bottom); + } + + FPDF_ClosePage(page); +} + +static void nativeSetPageMediaBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + jobject mediaBox) { + nativeSetPageBox(env, thiz, documentPtr, pageIndex, PAGE_BOX_MEDIA, mediaBox); +} + +static void nativeSetPageCropBox(JNIEnv* env, jclass thiz, jlong documentPtr, jint pageIndex, + jobject mediaBox) { + nativeSetPageBox(env, thiz, documentPtr, pageIndex, PAGE_BOX_CROP, mediaBox); +} + static JNINativeMethod gPdfEditor_Methods[] = { {"nativeOpen", "(IJ)J", (void*) nativeOpen}, {"nativeClose", "(J)V", (void*) nativeClose}, {"nativeGetPageCount", "(J)I", (void*) nativeGetPageCount}, {"nativeRemovePage", "(JI)I", (void*) nativeRemovePage}, - {"nativeWrite", "(JI)V", (void*) nativeWrite} + {"nativeWrite", "(JI)V", (void*) nativeWrite}, + {"nativeSetTransformAndClip", "(JIJIIII)V", (void*) nativeSetTransformAndClip}, + {"nativeGetPageSize", "(JILandroid/graphics/Point;)V", (void*) nativeGetPageSize}, + {"nativeScaleForPrinting", "(J)Z", (void*) nativeScaleForPrinting}, + {"nativeGetPageMediaBox", "(JILandroid/graphics/Rect;)Z", (void*) nativeGetPageMediaBox}, + {"nativeSetPageMediaBox", "(JILandroid/graphics/Rect;)V", (void*) nativeSetPageMediaBox}, + {"nativeGetPageCropBox", "(JILandroid/graphics/Rect;)Z", (void*) nativeGetPageCropBox}, + {"nativeSetPageCropBox", "(JILandroid/graphics/Rect;)V", (void*) nativeSetPageCropBox} }; int register_android_graphics_pdf_PdfEditor(JNIEnv* env) { - return android::AndroidRuntime::registerNativeMethods( + const int result = android::AndroidRuntime::registerNativeMethods( env, "android/graphics/pdf/PdfEditor", gPdfEditor_Methods, NELEM(gPdfEditor_Methods)); + + jclass pointClass = env->FindClass("android/graphics/Point"); + gPointClassInfo.x = env->GetFieldID(pointClass, "x", "I"); + gPointClassInfo.y = env->GetFieldID(pointClass, "y", "I"); + + jclass rectClass = env->FindClass("android/graphics/Rect"); + gRectClassInfo.left = env->GetFieldID(rectClass, "left", "I"); + gRectClassInfo.top = env->GetFieldID(rectClass, "top", "I"); + gRectClassInfo.right = env->GetFieldID(rectClass, "right", "I"); + gRectClassInfo.bottom = env->GetFieldID(rectClass, "bottom", "I"); + + return result; }; }; diff --git a/core/jni/android/graphics/pdf/PdfRenderer.cpp b/core/jni/android/graphics/pdf/PdfRenderer.cpp index 303ddea..357d3c0 100644 --- a/core/jni/android/graphics/pdf/PdfRenderer.cpp +++ b/core/jni/android/graphics/pdf/PdfRenderer.cpp @@ -82,8 +82,17 @@ static jlong nativeCreate(JNIEnv* env, jclass thiz, jint fd, jlong size) { if (!document) { const long error = FPDF_GetLastError(); - jniThrowException(env, "java/io/IOException", - "cannot create document. Error:" + error); + switch (error) { + case FPDF_ERR_PASSWORD: + case FPDF_ERR_SECURITY: { + jniThrowException(env, "java/lang/SecurityException", + "cannot create document. Error:" + error); + } break; + default: { + jniThrowException(env, "java/io/IOException", + "cannot create document. Error:" + error); + } break; + } destroyLibraryIfNeeded(); return -1; } |