Browse Source

Pass Bitmap's native instance to JNI where feasible

Test: CtsGraphicsTestCases, CtsUiRenderingTestCases,
      CtsRenderscriptTestCases

This is significantly faster than passing the Java object down and then
calling a JNI method to retrieve the pointer. See
https://buganizer.corp.google.com/issues/16656908#comment19

In some cases this changes what used to be native crashes (due to
android::BitmapWrapper:assertValid's LOG_ALWAYS_FATAL_IF) into
NullPointerExceptions (if a caller used a null Bitmap).

In addition:
- Remove unnecessary JNIEnv param from toBitmap(jlong)
- Change instances of toBitmap(JNIEnv*, jobject) to the above
- Replace calls to GraphicsJNI::getSkBitmap() to inline calls to
  toBitmap/getSkBitmap
- make Canvas#nInitRaster @FastNative (FIXME: Could these be
  @CriticalNative?)

Change-Id: I6194097be1b6e6952eba70e1e7052a5a250eed93
ten
Leon Scroggins III 2 years ago
parent
commit
71fae62f5f

+ 1
- 2
core/jni/android/graphics/Bitmap.cpp View File

@@ -230,8 +230,7 @@ Bitmap& toBitmap(JNIEnv* env, jobject bitmap) {
return localBitmap->bitmap();
}

Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle) {
SkASSERT(env);
Bitmap& toBitmap(jlong bitmapHandle) {
LocalScopedBitmap localBitmap(bitmapHandle);
return localBitmap->bitmap();
}

+ 1
- 1
core/jni/android/graphics/Bitmap.h View File

@@ -41,7 +41,7 @@ jobject createBitmap(JNIEnv* env, Bitmap* bitmap,
void toSkBitmap(jlong bitmapHandle, SkBitmap* outBitmap);

Bitmap& toBitmap(JNIEnv* env, jobject bitmap);
Bitmap& toBitmap(JNIEnv* env, jlong bitmapHandle);
Bitmap& toBitmap(jlong bitmapHandle);

// NDK access
void imageInfo(JNIEnv* env, jobject bitmap, AndroidBitmapInfo* info);

+ 19
- 16
core/jni/android/graphics/BitmapFactory.cpp View File

@@ -180,7 +180,8 @@ static bool needsFineScale(const SkISize fullSize, const SkISize decodedSize,
}

static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,
jobject padding, jobject options, jlong colorSpaceHandle) {
jobject padding, jobject options, jlong inBitmapHandle,
jlong colorSpaceHandle) {
// Set default values for the options parameters.
int sampleSize = 1;
bool onlyDecodeSize = false;
@@ -323,8 +324,8 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,

android::Bitmap* reuseBitmap = nullptr;
unsigned int existingBufferSize = 0;
if (javaBitmap != NULL) {
reuseBitmap = &bitmap::toBitmap(env, javaBitmap);
if (javaBitmap != nullptr) {
reuseBitmap = &bitmap::toBitmap(inBitmapHandle);
if (reuseBitmap->isImmutable()) {
ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
javaBitmap = nullptr;
@@ -513,7 +514,7 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,
}

static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage,
jobject padding, jobject options, jlong colorSpaceHandle) {
jobject padding, jobject options, jlong inBitmapHandle, jlong colorSpaceHandle) {

jobject bitmap = NULL;
std::unique_ptr<SkStream> stream(CreateJavaInputStreamAdaptor(env, is, storage));
@@ -522,13 +523,14 @@ static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteA
std::unique_ptr<SkStreamRewindable> bufferedStream(
SkFrontBufferedStream::Make(std::move(stream), SkCodec::MinBufferedBytesNeeded()));
SkASSERT(bufferedStream.get() != NULL);
bitmap = doDecode(env, std::move(bufferedStream), padding, options, colorSpaceHandle);
bitmap = doDecode(env, std::move(bufferedStream), padding, options, inBitmapHandle,
colorSpaceHandle);
}
return bitmap;
}

static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fileDescriptor,
jobject padding, jobject bitmapFactoryOptions, jlong colorSpaceHandle) {
jobject padding, jobject bitmapFactoryOptions, jlong inBitmapHandle, jlong colorSpaceHandle) {

NPE_CHECK_RETURN_ZERO(env, fileDescriptor);

@@ -565,7 +567,7 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
if (::lseek(descriptor, 0, SEEK_CUR) == 0) {
assert(isSeekable(dupDescriptor));
return doDecode(env, std::move(fileStream), padding, bitmapFactoryOptions,
colorSpaceHandle);
inBitmapHandle, colorSpaceHandle);
}

// Use a buffered stream. Although an SkFILEStream can be rewound, this
@@ -574,25 +576,26 @@ static jobject nativeDecodeFileDescriptor(JNIEnv* env, jobject clazz, jobject fi
std::unique_ptr<SkStreamRewindable> stream(SkFrontBufferedStream::Make(std::move(fileStream),
SkCodec::MinBufferedBytesNeeded()));

return doDecode(env, std::move(stream), padding, bitmapFactoryOptions, colorSpaceHandle);
return doDecode(env, std::move(stream), padding, bitmapFactoryOptions, inBitmapHandle,
colorSpaceHandle);
}

static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jlong native_asset,
jobject padding, jobject options, jlong colorSpaceHandle) {
jobject padding, jobject options, jlong inBitmapHandle, jlong colorSpaceHandle) {

Asset* asset = reinterpret_cast<Asset*>(native_asset);
// since we know we'll be done with the asset when we return, we can
// just use a simple wrapper
return doDecode(env, skstd::make_unique<AssetStreamAdaptor>(asset), padding, options,
colorSpaceHandle);
inBitmapHandle, colorSpaceHandle);
}

static jobject nativeDecodeByteArray(JNIEnv* env, jobject, jbyteArray byteArray,
jint offset, jint length, jobject options, jlong colorSpaceHandle) {
jint offset, jint length, jobject options, jlong inBitmapHandle, jlong colorSpaceHandle) {

AutoJavaByteArray ar(env, byteArray);
return doDecode(env, skstd::make_unique<SkMemoryStream>(ar.ptr() + offset, length, false),
nullptr, options, colorSpaceHandle);
nullptr, options, inBitmapHandle, colorSpaceHandle);
}

static jboolean nativeIsSeekable(JNIEnv* env, jobject, jobject fileDescriptor) {
@@ -604,22 +607,22 @@ static jboolean nativeIsSeekable(JNIEnv* env, jobject, jobject fileDescriptor) {

static const JNINativeMethod gMethods[] = {
{ "nativeDecodeStream",
"(Ljava/io/InputStream;[BLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;J)Landroid/graphics/Bitmap;",
"(Ljava/io/InputStream;[BLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
(void*)nativeDecodeStream
},

{ "nativeDecodeFileDescriptor",
"(Ljava/io/FileDescriptor;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;J)Landroid/graphics/Bitmap;",
"(Ljava/io/FileDescriptor;Landroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
(void*)nativeDecodeFileDescriptor
},

{ "nativeDecodeAsset",
"(JLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;J)Landroid/graphics/Bitmap;",
"(JLandroid/graphics/Rect;Landroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
(void*)nativeDecodeAsset
},

{ "nativeDecodeByteArray",
"([BIILandroid/graphics/BitmapFactory$Options;J)Landroid/graphics/Bitmap;",
"([BIILandroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
(void*)nativeDecodeByteArray
},


+ 5
- 4
core/jni/android/graphics/BitmapRegionDecoder.cpp View File

@@ -125,13 +125,14 @@ static jobject nativeNewInstanceFromAsset(JNIEnv* env, jobject clazz,
* reportSizeToVM not supported
*/
static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint inputX,
jint inputY, jint inputWidth, jint inputHeight, jobject options, jlong colorSpaceHandle) {
jint inputY, jint inputWidth, jint inputHeight, jobject options, jlong inBitmapHandle,
jlong colorSpaceHandle) {

// Set default options.
int sampleSize = 1;
SkColorType colorType = kN32_SkColorType;
bool requireUnpremul = false;
jobject javaBitmap = NULL;
jobject javaBitmap = nullptr;
bool isHardware = false;
sk_sp<SkColorSpace> colorSpace = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
// Update the default options with any options supplied by the client.
@@ -158,7 +159,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle, jint in
android::Bitmap* recycledBitmap = nullptr;
size_t recycledBytes = 0;
if (javaBitmap) {
recycledBitmap = &bitmap::toBitmap(env, javaBitmap);
recycledBitmap = &bitmap::toBitmap(inBitmapHandle);
if (recycledBitmap->isImmutable()) {
ALOGW("Warning: Reusing an immutable bitmap as an image decoder target.");
}
@@ -258,7 +259,7 @@ static void nativeClean(JNIEnv* env, jobject, jlong brdHandle) {

static const JNINativeMethod gBitmapRegionDecoderMethods[] = {
{ "nativeDecodeRegion",
"(JIIIILandroid/graphics/BitmapFactory$Options;J)Landroid/graphics/Bitmap;",
"(JIIIILandroid/graphics/BitmapFactory$Options;JJ)Landroid/graphics/Bitmap;",
(void*)nativeDecodeRegion},

{ "nativeGetHeight", "(J)I", (void*)nativeGetHeight},

+ 3
- 3
core/jni/android/graphics/NinePatch.cpp View File

@@ -84,13 +84,13 @@ public:
delete[] patch;
}

static jlong getTransparentRegion(JNIEnv* env, jobject, jobject jbitmap,
static jlong getTransparentRegion(JNIEnv* env, jobject, jlong bitmapPtr,
jlong chunkHandle, jobject dstRect) {
Res_png_9patch* chunk = reinterpret_cast<Res_png_9patch*>(chunkHandle);
SkASSERT(chunk);

SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
SkRect dst;
GraphicsJNI::jrect_to_rect(env, dstRect, &dst);

@@ -156,7 +156,7 @@ static const JNINativeMethod gNinePatchMethods[] = {
{ "validateNinePatchChunk", "([B)J",
(void*) SkNinePatchGlue::validateNinePatchChunk },
{ "nativeFinalize", "(J)V", (void*) SkNinePatchGlue::finalize },
{ "nativeGetTransparentRegion", "(Landroid/graphics/Bitmap;JLandroid/graphics/Rect;)J",
{ "nativeGetTransparentRegion", "(JJLandroid/graphics/Rect;)J",
(void*) SkNinePatchGlue::getTransparentRegion }
};


+ 4
- 4
core/jni/android/graphics/Shader.cpp View File

@@ -62,14 +62,14 @@ static jlong Shader_getNativeFinalizer(JNIEnv*, jobject) {

///////////////////////////////////////////////////////////////////////////////////////////////

static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, jobject jbitmap,
static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong matrixPtr, jlong bitmapHandle,
jint tileModeX, jint tileModeY) {
const SkMatrix* matrix = reinterpret_cast<const SkMatrix*>(matrixPtr);
sk_sp<SkImage> image;
if (jbitmap) {
if (bitmapHandle) {
// Only pass a valid SkBitmap object to the constructor if the Bitmap exists. Otherwise,
// we'll pass an empty SkBitmap to avoid crashing/excepting for compatibility.
image = android::bitmap::toBitmap(env, jbitmap).makeImage();
image = android::bitmap::toBitmap(bitmapHandle).makeImage();
}

if (!image.get()) {
@@ -222,7 +222,7 @@ static const JNINativeMethod gShaderMethods[] = {
};

static const JNINativeMethod gBitmapShaderMethods[] = {
{ "nativeCreate", "(JLandroid/graphics/Bitmap;II)J", (void*)BitmapShader_constructor },
{ "nativeCreate", "(JJII)J", (void*)BitmapShader_constructor },
};

static const JNINativeMethod gLinearGradientMethods[] = {

+ 3
- 3
core/jni/android/graphics/pdf/PdfRenderer.cpp View File

@@ -73,12 +73,12 @@ static void nativeClosePage(JNIEnv* env, jclass thiz, jlong pagePtr) {
}

static void nativeRenderPage(JNIEnv* env, jclass thiz, jlong documentPtr, jlong pagePtr,
jobject jbitmap, jint clipLeft, jint clipTop, jint clipRight, jint clipBottom,
jlong bitmapPtr, jint clipLeft, jint clipTop, jint clipRight, jint clipBottom,
jlong transformPtr, jint renderMode) {
FPDF_PAGE page = reinterpret_cast<FPDF_PAGE>(pagePtr);

SkBitmap skBitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &skBitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&skBitmap);

const int stride = skBitmap.width() * 4;

@@ -117,7 +117,7 @@ static const JNINativeMethod gPdfRenderer_Methods[] = {
{"nativeClose", "(J)V", (void*) nativeClose},
{"nativeGetPageCount", "(J)I", (void*) nativeGetPageCount},
{"nativeScaleForPrinting", "(J)Z", (void*) nativeScaleForPrinting},
{"nativeRenderPage", "(JJLandroid/graphics/Bitmap;IIIIJI)V", (void*) nativeRenderPage},
{"nativeRenderPage", "(JJJIIIIJI)V", (void*) nativeRenderPage},
{"nativeOpenPageAndGetSize", "(JILandroid/graphics/Point;)J", (void*) nativeOpenPageAndGetSize},
{"nativeClosePage", "(J)V", (void*) nativeClosePage}
};

+ 12
- 12
core/jni/android/opengl/util.cpp View File

@@ -703,27 +703,27 @@ static int getType(SkColorType colorType)
}

static jint util_getInternalFormat(JNIEnv *env, jclass clazz,
jobject jbitmap)
jlong bitmapPtr)
{
SkBitmap nativeBitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &nativeBitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&nativeBitmap);
return getInternalFormat(nativeBitmap.colorType());
}

static jint util_getType(JNIEnv *env, jclass clazz,
jobject jbitmap)
jlong bitmapPtr)
{
SkBitmap nativeBitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &nativeBitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&nativeBitmap);
return getType(nativeBitmap.colorType());
}

static jint util_texImage2D(JNIEnv *env, jclass clazz,
jint target, jint level, jint internalformat,
jobject jbitmap, jint type, jint border)
jlong bitmapPtr, jint type, jint border)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
SkColorType colorType = bitmap.colorType();
if (internalformat < 0) {
internalformat = getInternalFormat(colorType);
@@ -748,10 +748,10 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz,

static jint util_texSubImage2D(JNIEnv *env, jclass clazz,
jint target, jint level, jint xoffset, jint yoffset,
jobject jbitmap, jint format, jint type)
jlong bitmapPtr, jint format, jint type)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
SkColorType colorType = bitmap.colorType();
int internalFormat = getInternalFormat(colorType);
if (format < 0) {
@@ -1068,10 +1068,10 @@ static const JNINativeMethod gVisibilityMethods[] = {
};

static const JNINativeMethod gUtilsMethods[] = {
{ "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat },
{ "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType },
{ "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D },
{ "native_texSubImage2D", "(IIIILandroid/graphics/Bitmap;II)I", (void*)util_texSubImage2D },
{ "native_getInternalFormat", "(J)I", (void*) util_getInternalFormat },
{ "native_getType", "(J)I", (void*) util_getType },
{ "native_texImage2D", "(IIIJII)I", (void*)util_texImage2D },
{ "native_texSubImage2D", "(IIIIJII)I", (void*)util_texSubImage2D },
};

static const JNINativeMethod gEtc1Methods[] = {

+ 21
- 21
core/jni/android_graphics_Canvas.cpp View File

@@ -54,20 +54,20 @@ static jlong getNativeFinalizer(JNIEnv* env, jobject clazz) {
}

// Native wrapper constructor used by Canvas(Bitmap)
static jlong initRaster(JNIEnv* env, jobject, jobject jbitmap) {
static jlong initRaster(JNIEnv* env, jobject, jlong bitmapHandle) {
SkBitmap bitmap;
if (jbitmap != NULL) {
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
if (bitmapHandle != 0) {
bitmap::toBitmap(bitmapHandle).getSkBitmap(&bitmap);
}
return reinterpret_cast<jlong>(Canvas::create_canvas(bitmap));
}

// Set the given bitmap as the new draw target (wrapped in a new SkCanvas),
// optionally copying canvas matrix & clip state.
static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap) {
static void setBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle) {
SkBitmap bitmap;
if (jbitmap != NULL) {
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
if (bitmapHandle != 0) {
bitmap::toBitmap(bitmapHandle).getSkBitmap(&bitmap);
}
get_canvas(canvasHandle)->setBitmap(bitmap);
}
@@ -397,7 +397,7 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap
jlong paintHandle, jint dstDensity, jint srcDensity) {

Canvas* canvas = get_canvas(canvasHandle);
Bitmap& bitmap = android::bitmap::toBitmap(env, bitmapHandle);
Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle);
const android::Res_png_9patch* chunk = reinterpret_cast<android::Res_png_9patch*>(chunkHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);

@@ -423,11 +423,11 @@ static void drawNinePatch(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmap
}
}

static void drawBitmap(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
static void drawBitmap(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,
jfloat left, jfloat top, jlong paintHandle, jint canvasDensity,
jint screenDensity, jint bitmapDensity) {
Canvas* canvas = get_canvas(canvasHandle);
Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);

if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) {
@@ -458,22 +458,22 @@ static void drawBitmap(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap
}
}

static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
static void drawBitmapMatrix(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,
jlong matrixHandle, jlong paintHandle) {
const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle);
get_canvas(canvasHandle)->drawBitmap(bitmap, *matrix, paint);
}

static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,
float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom,
jlong paintHandle, jint screenDensity, jint bitmapDensity) {
Canvas* canvas = get_canvas(canvasHandle);
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);

Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle);
if (screenDensity != 0 && screenDensity != bitmapDensity) {
Paint filteredPaint;
if (paint) {
@@ -512,7 +512,7 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle,
get_canvas(canvasHandle)->drawBitmap(*androidBitmap, x, y, paint);
}

static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap,
static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle,
jint meshWidth, jint meshHeight, jfloatArray jverts,
jint vertIndex, jintArray jcolors, jint colorIndex, jlong paintHandle) {
if (Canvas::GetApiLevel() < __ANDROID_API_P__) {
@@ -527,7 +527,7 @@ static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbi
AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount);

const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap);
Bitmap& bitmap = android::bitmap::toBitmap(bitmapHandle);
get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight,
vertA.ptr() + vertIndex*2,
colorA.ptr() + colorIndex, paint);
@@ -651,13 +651,13 @@ static void setCompatibilityVersion(JNIEnv* env, jobject, jint apiLevel) {

static const JNINativeMethod gMethods[] = {
{"nGetNativeFinalizer", "()J", (void*) CanvasJNI::getNativeFinalizer},
{"nInitRaster", "(Landroid/graphics/Bitmap;)J", (void*) CanvasJNI::initRaster},
{"nFreeCaches", "()V", (void*) CanvasJNI::freeCaches},
{"nFreeTextLayoutCaches", "()V", (void*) CanvasJNI::freeTextLayoutCaches},
{"nSetCompatibilityVersion", "(I)V", (void*) CanvasJNI::setCompatibilityVersion},

// ------------ @FastNative ----------------
{"nSetBitmap", "(JLandroid/graphics/Bitmap;)V", (void*) CanvasJNI::setBitmap},
{"nInitRaster", "(J)J", (void*) CanvasJNI::initRaster},
{"nSetBitmap", "(JJ)V", (void*) CanvasJNI::setBitmap},
{"nGetClipBounds","(JLandroid/graphics/Rect;)Z", (void*) CanvasJNI::getClipBounds},

// ------------ @CriticalNative ----------------
@@ -706,10 +706,10 @@ static const JNINativeMethod gDrawMethods[] = {
{"nDrawPath","(JJJ)V", (void*) CanvasJNI::drawPath},
{"nDrawVertices", "(JII[FI[FI[II[SIIJ)V", (void*)CanvasJNI::drawVertices},
{"nDrawNinePatch", "(JJJFFFFJII)V", (void*)CanvasJNI::drawNinePatch},
{"nDrawBitmapMatrix", "(JLandroid/graphics/Bitmap;JJ)V", (void*)CanvasJNI::drawBitmapMatrix},
{"nDrawBitmapMesh", "(JLandroid/graphics/Bitmap;II[FI[IIJ)V", (void*)CanvasJNI::drawBitmapMesh},
{"nDrawBitmap","(JLandroid/graphics/Bitmap;FFJIII)V", (void*) CanvasJNI::drawBitmap},
{"nDrawBitmap","(JLandroid/graphics/Bitmap;FFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect},
{"nDrawBitmapMatrix", "(JJJJ)V", (void*)CanvasJNI::drawBitmapMatrix},
{"nDrawBitmapMesh", "(JJII[FI[IIJ)V", (void*)CanvasJNI::drawBitmapMesh},
{"nDrawBitmap","(JJFFJIII)V", (void*) CanvasJNI::drawBitmap},
{"nDrawBitmap","(JJFFFFFFFFJII)V", (void*) CanvasJNI::drawBitmapRect},
{"nDrawBitmap", "(J[IIIFFIIZJ)V", (void*)CanvasJNI::drawBitmapArray},
{"nDrawText","(J[CIIFFIJ)V", (void*) CanvasJNI::drawTextChars},
{"nDrawText","(JLjava/lang/String;IIFFIJ)V", (void*) CanvasJNI::drawTextString},

+ 6
- 6
core/jni/android_view_ThreadedRenderer.cpp View File

@@ -736,11 +736,11 @@ static void android_view_ThreadedRenderer_buildLayer(JNIEnv* env, jobject clazz,
}

static jboolean android_view_ThreadedRenderer_copyLayerInto(JNIEnv* env, jobject clazz,
jlong proxyPtr, jlong layerPtr, jobject jbitmap) {
jlong proxyPtr, jlong layerPtr, jlong bitmapPtr) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr);
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
return proxy->copyLayerInto(layer, bitmap);
}

@@ -911,9 +911,9 @@ static void android_view_ThreadedRenderer_setFrameCompleteCallback(JNIEnv* env,

static jint android_view_ThreadedRenderer_copySurfaceInto(JNIEnv* env,
jobject clazz, jobject jsurface, jint left, jint top,
jint right, jint bottom, jobject jbitmap) {
jint right, jint bottom, jlong bitmapPtr) {
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
sp<Surface> surface = android_view_Surface_getSurface(env, jsurface);
return RenderProxy::copySurfaceInto(surface, left, top, right, bottom, &bitmap);
}
@@ -1106,7 +1106,7 @@ static const JNINativeMethod gMethods[] = {
{ "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor },
{ "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer },
{ "nBuildLayer", "(JJ)V", (void*) android_view_ThreadedRenderer_buildLayer },
{ "nCopyLayerInto", "(JJLandroid/graphics/Bitmap;)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
{ "nCopyLayerInto", "(JJJ)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
{ "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate },
{ "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate },
{ "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture },
@@ -1135,7 +1135,7 @@ static const JNINativeMethod gMethods[] = {
{ "nRemoveFrameMetricsObserver",
"(JJ)V",
(void*)android_view_ThreadedRenderer_removeFrameMetricsObserver },
{ "nCopySurfaceInto", "(Landroid/view/Surface;IIIILandroid/graphics/Bitmap;)I",
{ "nCopySurfaceInto", "(Landroid/view/Surface;IIIIJ)I",
(void*)android_view_ThreadedRenderer_copySurfaceInto },
{ "nCreateHardwareBitmap", "(JII)Landroid/graphics/Bitmap;",
(void*)android_view_ThreadedRenderer_createHardwareBitmapFromRenderNode },

+ 11
- 10
graphics/java/android/graphics/BaseCanvas.java View File

@@ -112,14 +112,14 @@ public abstract class BaseCanvas {
public void drawBitmap(@NonNull Bitmap bitmap, float left, float top, @Nullable Paint paint) {
throwIfCannotDraw(bitmap);
throwIfHasHwBitmapInSwMode(paint);
nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top,
paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity,
bitmap.mDensity);
}

public void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix, @Nullable Paint paint) {
throwIfHasHwBitmapInSwMode(paint);
nDrawBitmapMatrix(mNativeCanvasWrapper, bitmap, matrix.ni(),
nDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.getNativeInstance(), matrix.ni(),
paint != null ? paint.getNativeInstance() : 0);
}

@@ -144,7 +144,7 @@ public abstract class BaseCanvas {
bottom = src.bottom;
}

nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -170,7 +170,7 @@ public abstract class BaseCanvas {
bottom = src.bottom;
}

nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -229,7 +229,7 @@ public abstract class BaseCanvas {
// no mul by 2, since we need only 1 color per vertex
checkRange(colors.length, colorOffset, count);
}
nDrawBitmapMesh(mNativeCanvasWrapper, bitmap, meshWidth, meshHeight,
nDrawBitmapMesh(mNativeCanvasWrapper, bitmap.getNativeInstance(), meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset,
paint != null ? paint.getNativeInstance() : 0);
}
@@ -664,10 +664,11 @@ public abstract class BaseCanvas {
}
}

private static native void nDrawBitmap(long nativeCanvas, Bitmap bitmap, float left, float top,
long nativePaintOrZero, int canvasDensity, int screenDensity, int bitmapDensity);
private static native void nDrawBitmap(long nativeCanvas, long bitmapHandle, float left,
float top, long nativePaintOrZero, int canvasDensity, int screenDensity,
int bitmapDensity);

private static native void nDrawBitmap(long nativeCanvas, Bitmap bitmap, float srcLeft,
private static native void nDrawBitmap(long nativeCanvas, long bitmapHandle, float srcLeft,
float srcTop,
float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight,
float dstBottom, long nativePaintOrZero, int screenDensity, int bitmapDensity);
@@ -726,10 +727,10 @@ public abstract class BaseCanvas {
float dstLeft, float dstTop, float dstRight, float dstBottom, long nativePaintOrZero,
int screenDensity, int bitmapDensity);

private static native void nDrawBitmapMatrix(long nativeCanvas, Bitmap bitmap,
private static native void nDrawBitmapMatrix(long nativeCanvas, long bitmapHandle,
long nativeMatrix, long nativePaint);

private static native void nDrawBitmapMesh(long nativeCanvas, Bitmap bitmap, int meshWidth,
private static native void nDrawBitmapMesh(long nativeCanvas, long bitmapHandle, int meshWidth,
int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset,
long nativePaint);


+ 11
- 10
graphics/java/android/graphics/BaseRecordingCanvas.java View File

@@ -67,7 +67,7 @@ public class BaseRecordingCanvas extends Canvas {
public final void drawBitmap(@NonNull Bitmap bitmap, float left, float top,
@Nullable Paint paint) {
throwIfCannotDraw(bitmap);
nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top,
paint != null ? paint.getNativeInstance() : 0, mDensity, mScreenDensity,
bitmap.mDensity);
}
@@ -75,7 +75,7 @@ public class BaseRecordingCanvas extends Canvas {
@Override
public final void drawBitmap(@NonNull Bitmap bitmap, @NonNull Matrix matrix,
@Nullable Paint paint) {
nDrawBitmapMatrix(mNativeCanvasWrapper, bitmap, matrix.ni(),
nDrawBitmapMatrix(mNativeCanvasWrapper, bitmap.getNativeInstance(), matrix.ni(),
paint != null ? paint.getNativeInstance() : 0);
}

@@ -100,7 +100,7 @@ public class BaseRecordingCanvas extends Canvas {
bottom = src.bottom;
}

nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -126,7 +126,7 @@ public class BaseRecordingCanvas extends Canvas {
bottom = src.bottom;
}

nDrawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,
nDrawBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance(), left, top, right, bottom,
dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,
bitmap.mDensity);
}
@@ -188,7 +188,7 @@ public class BaseRecordingCanvas extends Canvas {
// no mul by 2, since we need only 1 color per vertex
checkRange(colors.length, colorOffset, count);
}
nDrawBitmapMesh(mNativeCanvasWrapper, bitmap, meshWidth, meshHeight,
nDrawBitmapMesh(mNativeCanvasWrapper, bitmap.getNativeInstance(), meshWidth, meshHeight,
verts, vertOffset, colors, colorOffset,
paint != null ? paint.getNativeInstance() : 0);
}
@@ -581,11 +581,12 @@ public class BaseRecordingCanvas extends Canvas {
}

@FastNative
private static native void nDrawBitmap(long nativeCanvas, Bitmap bitmap, float left, float top,
long nativePaintOrZero, int canvasDensity, int screenDensity, int bitmapDensity);
private static native void nDrawBitmap(long nativeCanvas, long bitmapHandle, float left,
float top, long nativePaintOrZero, int canvasDensity, int screenDensity,
int bitmapDensity);

@FastNative
private static native void nDrawBitmap(long nativeCanvas, Bitmap bitmap,
private static native void nDrawBitmap(long nativeCanvas, long bitmapHandle,
float srcLeft, float srcTop, float srcRight, float srcBottom,
float dstLeft, float dstTop, float dstRight, float dstBottom,
long nativePaintOrZero, int screenDensity, int bitmapDensity);
@@ -663,11 +664,11 @@ public class BaseRecordingCanvas extends Canvas {
int screenDensity, int bitmapDensity);

@FastNative
private static native void nDrawBitmapMatrix(long nativeCanvas, Bitmap bitmap,
private static native void nDrawBitmapMatrix(long nativeCanvas, long bitmapHandle,
long nativeMatrix, long nativePaint);

@FastNative
private static native void nDrawBitmapMesh(long nativeCanvas, Bitmap bitmap, int meshWidth,
private static native void nDrawBitmapMesh(long nativeCanvas, long bitmapHandle, int meshWidth,
int meshHeight, float[] verts, int vertOffset, int[] colors, int colorOffset,
long nativePaint);


+ 20
- 5
graphics/java/android/graphics/BitmapFactory.java View File

@@ -465,6 +465,17 @@ public class BitmapFactory {
}

/**
* Helper for passing inBitmap's native pointer to native.
*/
static long nativeInBitmap(Options opts) {
if (opts == null || opts.inBitmap == null) {
return 0;
}

return opts.inBitmap.getNativeInstance();
}

/**
* Helper for passing SkColorSpace pointer to native.
*
* @throws IllegalArgumentException if the ColorSpace is not Rgb or does
@@ -652,6 +663,7 @@ public class BitmapFactory {
Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
try {
bm = nativeDecodeByteArray(data, offset, length, opts,
Options.nativeInBitmap(opts),
Options.nativeColorSpace(opts));

if (bm == null && opts != null && opts.inBitmap != null) {
@@ -747,7 +759,8 @@ public class BitmapFactory {
try {
if (is instanceof AssetManager.AssetInputStream) {
final long asset = ((AssetManager.AssetInputStream) is).getNativeAsset();
bm = nativeDecodeAsset(asset, outPadding, opts, Options.nativeColorSpace(opts));
bm = nativeDecodeAsset(asset, outPadding, opts, Options.nativeInBitmap(opts),
Options.nativeColorSpace(opts));
} else {
bm = decodeStreamInternal(is, outPadding, opts);
}
@@ -775,6 +788,7 @@ public class BitmapFactory {
if (opts != null) tempStorage = opts.inTempStorage;
if (tempStorage == null) tempStorage = new byte[DECODE_BUFFER_SIZE];
return nativeDecodeStream(is, tempStorage, outPadding, opts,
Options.nativeInBitmap(opts),
Options.nativeColorSpace(opts));
}

@@ -819,6 +833,7 @@ public class BitmapFactory {
try {
if (nativeIsSeekable(fd)) {
bm = nativeDecodeFileDescriptor(fd, outPadding, opts,
Options.nativeInBitmap(opts),
Options.nativeColorSpace(opts));
} else {
FileInputStream fis = new FileInputStream(fd);
@@ -856,15 +871,15 @@ public class BitmapFactory {

@UnsupportedAppUsage
private static native Bitmap nativeDecodeStream(InputStream is, byte[] storage,
Rect padding, Options opts, long colorSpaceHandle);
Rect padding, Options opts, long inBitmapHandle, long colorSpaceHandle);
@UnsupportedAppUsage
private static native Bitmap nativeDecodeFileDescriptor(FileDescriptor fd,
Rect padding, Options opts, long colorSpaceHandle);
Rect padding, Options opts, long inBitmapHandle, long colorSpaceHandle);
@UnsupportedAppUsage
private static native Bitmap nativeDecodeAsset(long nativeAsset, Rect padding, Options opts,
long colorSpaceHandle);
long inBitmapHandle, long colorSpaceHandle);
@UnsupportedAppUsage
private static native Bitmap nativeDecodeByteArray(byte[] data, int offset,
int length, Options opts, long colorSpaceHandle);
int length, Options opts, long inBitmapHandle, long colorSpaceHandle);
private static native boolean nativeIsSeekable(FileDescriptor fd);
}

+ 3
- 1
graphics/java/android/graphics/BitmapRegionDecoder.java View File

@@ -196,6 +196,7 @@ public final class BitmapRegionDecoder {
throw new IllegalArgumentException("rectangle is outside the image");
return nativeDecodeRegion(mNativeBitmapRegionDecoder, rect.left, rect.top,
rect.right - rect.left, rect.bottom - rect.top, options,
BitmapFactory.Options.nativeInBitmap(options),
BitmapFactory.Options.nativeColorSpace(options));
}
}
@@ -266,7 +267,8 @@ public final class BitmapRegionDecoder {

private static native Bitmap nativeDecodeRegion(long lbm,
int start_x, int start_y, int width, int height,
BitmapFactory.Options options, long colorSpaceHandle);
BitmapFactory.Options options, long inBitmapHandle,
long colorSpaceHandle);
private static native int nativeGetWidth(long lbm);
private static native int nativeGetHeight(long lbm);
private static native void nativeClean(long lbm);

+ 2
- 2
graphics/java/android/graphics/BitmapShader.java View File

@@ -62,9 +62,9 @@ public class BitmapShader extends Shader {

@Override
long createNativeInstance(long nativeMatrix) {
return nativeCreate(nativeMatrix, mBitmap, mTileX, mTileY);
return nativeCreate(nativeMatrix, mBitmap.getNativeInstance(), mTileX, mTileY);
}

private static native long nativeCreate(long nativeMatrix, Bitmap bitmap,
private static native long nativeCreate(long nativeMatrix, long bitmapHandle,
int shaderTileModeX, int shaderTileModeY);
}

+ 8
- 6
graphics/java/android/graphics/Canvas.java View File

@@ -95,7 +95,7 @@ public class Canvas extends BaseCanvas {
public Canvas() {
if (!isHardwareAccelerated()) {
// 0 means no native bitmap
mNativeCanvasWrapper = nInitRaster(null);
mNativeCanvasWrapper = nInitRaster(0);
mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation(
this, mNativeCanvasWrapper);
} else {
@@ -117,7 +117,7 @@ public class Canvas extends BaseCanvas {
throw new IllegalStateException("Immutable bitmap passed to Canvas constructor");
}
throwIfCannotDraw(bitmap);
mNativeCanvasWrapper = nInitRaster(bitmap);
mNativeCanvasWrapper = nInitRaster(bitmap.getNativeInstance());
mFinalizer = NoImagePreloadHolder.sRegistry.registerNativeAllocation(
this, mNativeCanvasWrapper);
mBitmap = bitmap;
@@ -185,7 +185,7 @@ public class Canvas extends BaseCanvas {
}

if (bitmap == null) {
nSetBitmap(mNativeCanvasWrapper, null);
nSetBitmap(mNativeCanvasWrapper, 0);
mDensity = Bitmap.DENSITY_NONE;
} else {
if (!bitmap.isMutable()) {
@@ -193,7 +193,7 @@ public class Canvas extends BaseCanvas {
}
throwIfCannotDraw(bitmap);

nSetBitmap(mNativeCanvasWrapper, bitmap);
nSetBitmap(mNativeCanvasWrapper, bitmap.getNativeInstance());
mDensity = bitmap.mDensity;
}

@@ -1364,14 +1364,16 @@ public class Canvas extends BaseCanvas {

private static native void nFreeCaches();
private static native void nFreeTextLayoutCaches();
private static native long nInitRaster(Bitmap bitmap);
private static native long nGetNativeFinalizer();
private static native void nSetCompatibilityVersion(int apiLevel);

// ---------------- @FastNative -------------------

@FastNative
private static native void nSetBitmap(long canvasHandle, Bitmap bitmap);
private static native long nInitRaster(long bitmapHandle);

@FastNative
private static native void nSetBitmap(long canvasHandle, long bitmapHandle);

@FastNative
private static native boolean nGetClipBounds(long nativeCanvas, Rect bounds);

+ 6
- 6
graphics/java/android/graphics/HardwareRenderer.java View File

@@ -682,8 +682,8 @@ public class HardwareRenderer {

/** @hide */
public boolean copyLayerInto(final TextureLayer layer, final Bitmap bitmap) {
return nCopyLayerInto(mNativeProxy,
layer.getDeferredLayerUpdater(), bitmap);
return nCopyLayerInto(mNativeProxy, layer.getDeferredLayerUpdater(),
bitmap.getNativeInstance());
}

/**
@@ -910,10 +910,10 @@ public class HardwareRenderer {
public static int copySurfaceInto(Surface surface, Rect srcRect, Bitmap bitmap) {
if (srcRect == null) {
// Empty rect means entire surface
return nCopySurfaceInto(surface, 0, 0, 0, 0, bitmap);
return nCopySurfaceInto(surface, 0, 0, 0, 0, bitmap.getNativeInstance());
} else {
return nCopySurfaceInto(surface, srcRect.left, srcRect.top,
srcRect.right, srcRect.bottom, bitmap);
srcRect.right, srcRect.bottom, bitmap.getNativeInstance());
}
}

@@ -1115,7 +1115,7 @@ public class HardwareRenderer {

private static native void nBuildLayer(long nativeProxy, long node);

private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap);
private static native boolean nCopyLayerInto(long nativeProxy, long layer, long bitmapHandle);

private static native void nPushLayerUpdate(long nativeProxy, long layer);

@@ -1162,7 +1162,7 @@ public class HardwareRenderer {
private static native void nRemoveFrameMetricsObserver(long nativeProxy, long nativeObserver);

private static native int nCopySurfaceInto(Surface surface,
int srcLeft, int srcTop, int srcRight, int srcBottom, Bitmap bitmap);
int srcLeft, int srcTop, int srcRight, int srcBottom, long bitmapHandle);

private static native Bitmap nCreateHardwareBitmap(long renderNode, int width, int height);


+ 4
- 2
graphics/java/android/graphics/NinePatch.java View File

@@ -261,7 +261,8 @@ public class NinePatch {
* that are transparent.
*/
public final Region getTransparentRegion(Rect bounds) {
long r = nativeGetTransparentRegion(mBitmap, mNativeChunk, bounds);
long r = nativeGetTransparentRegion(mBitmap.getNativeInstance(),
mNativeChunk, bounds);
return r != 0 ? new Region(r) : null;
}

@@ -282,5 +283,6 @@ public class NinePatch {
*/
private static native long validateNinePatchChunk(byte[] chunk);
private static native void nativeFinalize(long chunk);
private static native long nativeGetTransparentRegion(Bitmap bitmap, long chunk, Rect location);
private static native long nativeGetTransparentRegion(long bitmapHandle, long chunk,
Rect location);
}

+ 4
- 3
graphics/java/android/graphics/pdf/PdfRenderer.java View File

@@ -435,8 +435,9 @@ public final class PdfRenderer implements AutoCloseable {
final long transformPtr = transform.native_instance;

synchronized (sPdfiumLock) {
nativeRenderPage(mNativeDocument, mNativePage, destination, contentLeft,
contentTop, contentRight, contentBottom, transformPtr, renderMode);
nativeRenderPage(mNativeDocument, mNativePage, destination.getNativeInstance(),
contentLeft, contentTop, contentRight, contentBottom, transformPtr,
renderMode);
}
}

@@ -487,7 +488,7 @@ public final class PdfRenderer implements AutoCloseable {
private static native void nativeClose(long documentPtr);
private static native int nativeGetPageCount(long documentPtr);
private static native boolean nativeScaleForPrinting(long documentPtr);
private static native void nativeRenderPage(long documentPtr, long pagePtr, Bitmap dest,
private static native void nativeRenderPage(long documentPtr, long pagePtr, long bitmapHandle,
int clipLeft, int clipTop, int clipRight, int clipBottom, long transformPtr,
int renderMode);
private static native long nativeOpenPageAndGetSize(long documentPtr, int pageIndex,

+ 15
- 11
opengl/java/android/opengl/GLUtils.java View File

@@ -44,7 +44,7 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
int result = native_getInternalFormat(bitmap);
int result = native_getInternalFormat(bitmap.getNativeInstance());
if (result < 0) {
throw new IllegalArgumentException("Unknown internalformat");
}
@@ -66,7 +66,7 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
int result = native_getType(bitmap);
int result = native_getType(bitmap.getNativeInstance());
if (result < 0) {
throw new IllegalArgumentException("Unknown type");
}
@@ -103,7 +103,8 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
if (native_texImage2D(target, level, internalformat, bitmap, -1, border)!=0) {
if (native_texImage2D(target, level, internalformat, bitmap.getNativeInstance(), -1,
border) != 0) {
throw new IllegalArgumentException("invalid Bitmap format");
}
}
@@ -129,7 +130,8 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
if (native_texImage2D(target, level, internalformat, bitmap, type, border)!=0) {
if (native_texImage2D(target, level, internalformat, bitmap.getNativeInstance(), type,
border) != 0) {
throw new IllegalArgumentException("invalid Bitmap format");
}
}
@@ -151,7 +153,7 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
if (native_texImage2D(target, level, -1, bitmap, -1, border)!=0) {
if (native_texImage2D(target, level, -1, bitmap.getNativeInstance(), -1, border) != 0) {
throw new IllegalArgumentException("invalid Bitmap format");
}
}
@@ -187,7 +189,8 @@ public final class GLUtils {
throw new IllegalArgumentException("bitmap is recycled");
}
int type = getType(bitmap);
if (native_texSubImage2D(target, level, xoffset, yoffset, bitmap, -1, type)!=0) {
if (native_texSubImage2D(target, level, xoffset, yoffset, bitmap.getNativeInstance(), -1,
type) != 0) {
throw new IllegalArgumentException("invalid Bitmap format");
}
}
@@ -211,7 +214,8 @@ public final class GLUtils {
if (bitmap.isRecycled()) {
throw new IllegalArgumentException("bitmap is recycled");
}
if (native_texSubImage2D(target, level, xoffset, yoffset, bitmap, format, type)!=0) {
if (native_texSubImage2D(target, level, xoffset, yoffset, bitmap.getNativeInstance(),
format, type) != 0) {
throw new IllegalArgumentException("invalid Bitmap format");
}
}
@@ -261,10 +265,10 @@ public final class GLUtils {
}
}

native private static int native_getInternalFormat(Bitmap bitmap);
native private static int native_getType(Bitmap bitmap);
native private static int native_getInternalFormat(long bitmapHandle);
native private static int native_getType(long bitmapHandle);
native private static int native_texImage2D(int target, int level, int internalformat,
Bitmap bitmap, int type, int border);
long bitmapHandle, int type, int border);
native private static int native_texSubImage2D(int target, int level, int xoffset, int yoffset,
Bitmap bitmap, int format, int type);
long bitmapHandle, int format, int type);
}

+ 23
- 15
rs/java/android/renderscript/RenderScript.java View File

@@ -447,27 +447,33 @@ public class RenderScript {
validate();
return rsnAllocationCreateTyped(mContext, type, mip, usage, pointer);
}
native long rsnAllocationCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
native long rsnAllocationCreateFromBitmap(long con, long type, int mip, long bitmapHandle,
int usage);
synchronized long nAllocationCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
validate();
return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp, usage);
return rsnAllocationCreateFromBitmap(mContext, type, mip, bmp.getNativeInstance(), usage);
}

native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, Bitmap bmp, int usage);
synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp, int usage) {
native long rsnAllocationCreateBitmapBackedAllocation(long con, long type, int mip, long bitmapHandle,
int usage);
synchronized long nAllocationCreateBitmapBackedAllocation(long type, int mip, Bitmap bmp,
int usage) {
validate();
return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp, usage);
return rsnAllocationCreateBitmapBackedAllocation(mContext, type, mip, bmp.getNativeInstance(),
usage);
}

native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, Bitmap bmp, int usage);
native long rsnAllocationCubeCreateFromBitmap(long con, long type, int mip, long bitmapHandle,
int usage);
synchronized long nAllocationCubeCreateFromBitmap(long type, int mip, Bitmap bmp, int usage) {
validate();
return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp, usage);
return rsnAllocationCubeCreateFromBitmap(mContext, type, mip, bmp.getNativeInstance(),
usage);
}
native long rsnAllocationCreateBitmapRef(long con, long type, Bitmap bmp);
native long rsnAllocationCreateBitmapRef(long con, long type, long bitmapHandle);
synchronized long nAllocationCreateBitmapRef(long type, Bitmap bmp) {
validate();
return rsnAllocationCreateBitmapRef(mContext, type, bmp);
return rsnAllocationCreateBitmapRef(mContext, type, bmp.getNativeInstance());
}
native long rsnAllocationCreateFromAssetStream(long con, int mips, int assetStream, int usage);
synchronized long nAllocationCreateFromAssetStream(int mips, int assetStream, int usage) {
@@ -475,10 +481,10 @@ public class RenderScript {
return rsnAllocationCreateFromAssetStream(mContext, mips, assetStream, usage);
}

native void rsnAllocationCopyToBitmap(long con, long alloc, Bitmap bmp);
native void rsnAllocationCopyToBitmap(long con, long alloc, long bitmapHandle);
synchronized void nAllocationCopyToBitmap(long alloc, Bitmap bmp) {
validate();
rsnAllocationCopyToBitmap(mContext, alloc, bmp);
rsnAllocationCopyToBitmap(mContext, alloc, bmp.getNativeInstance());
}

native void rsnAllocationSyncAll(long con, long alloc, int src);
@@ -487,8 +493,10 @@ public class RenderScript {
rsnAllocationSyncAll(mContext, alloc, src);
}

native ByteBuffer rsnAllocationGetByteBuffer(long con, long alloc, long[] stride, int xBytesSize, int dimY, int dimZ);
synchronized ByteBuffer nAllocationGetByteBuffer(long alloc, long[] stride, int xBytesSize, int dimY, int dimZ) {
native ByteBuffer rsnAllocationGetByteBuffer(long con, long alloc, long[] stride,
int xBytesSize, int dimY, int dimZ);
synchronized ByteBuffer nAllocationGetByteBuffer(long alloc, long[] stride, int xBytesSize,
int dimY, int dimZ) {
validate();
return rsnAllocationGetByteBuffer(mContext, alloc, stride, xBytesSize, dimY, dimZ);
}
@@ -529,10 +537,10 @@ public class RenderScript {
validate();
rsnAllocationGenerateMipmaps(mContext, alloc);
}
native void rsnAllocationCopyFromBitmap(long con, long alloc, Bitmap bmp);
native void rsnAllocationCopyFromBitmap(long con, long alloc, long bitmapHandle);
synchronized void nAllocationCopyFromBitmap(long alloc, Bitmap bmp) {
validate();
rsnAllocationCopyFromBitmap(mContext, alloc, bmp);
rsnAllocationCopyFromBitmap(mContext, alloc, bmp.getNativeInstance());
}



+ 16
- 16
rs/jni/android_renderscript_RenderScript.cpp View File

@@ -1321,10 +1321,10 @@ nAllocationGenerateMipmaps(JNIEnv *_env, jobject _this, jlong con, jlong alloc)

static jlong
nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
jobject jbitmap, jint usage)
jlong bitmapPtr, jint usage)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);

const void* ptr = bitmap.getPixels();
jlong id = (jlong)(uintptr_t)rsAllocationCreateFromBitmap((RsContext)con,
@@ -1335,10 +1335,10 @@ nAllocationCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type,

static jlong
nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con, jlong type,
jint mip, jobject jbitmap, jint usage)
jint mip, jlong bitmapPtr, jint usage)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);

const void* ptr = bitmap.getPixels();
jlong id = (jlong)(uintptr_t)rsAllocationCreateTyped((RsContext)con,
@@ -1349,10 +1349,10 @@ nAllocationCreateBitmapBackedAllocation(JNIEnv *_env, jobject _this, jlong con,

static jlong
nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong type, jint mip,
jobject jbitmap, jint usage)
jlong bitmapPtr, jint usage)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);

const void* ptr = bitmap.getPixels();
jlong id = (jlong)(uintptr_t)rsAllocationCubeCreateFromBitmap((RsContext)con,
@@ -1362,10 +1362,10 @@ nAllocationCubeCreateFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong ty
}

static void
nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jlong bitmapPtr)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);
int w = bitmap.width();
int h = bitmap.height();

@@ -1376,10 +1376,10 @@ nAllocationCopyFromBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, j
}

static void
nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jobject jbitmap)
nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jlong bitmapPtr)
{
SkBitmap bitmap;
GraphicsJNI::getSkBitmap(_env, jbitmap, &bitmap);
bitmap::toBitmap(bitmapPtr).getSkBitmap(&bitmap);

void* ptr = bitmap.getPixels();
rsAllocationCopyToBitmap((RsContext)con, (RsAllocation)alloc, ptr, bitmap.computeByteSize());
@@ -2866,13 +2866,13 @@ static const JNINativeMethod methods[] = {
{"rsnTypeCreate", "(JJIIIZZI)J", (void*)nTypeCreate },
{"rsnTypeGetNativeData", "(JJ[J)V", (void*)nTypeGetNativeData },

{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
{"rsnAllocationCreateFromBitmap", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateFromBitmap },
{"rsnAllocationCreateBitmapBackedAllocation", "(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCreateBitmapBackedAllocation },
{"rsnAllocationCubeCreateFromBitmap","(JJILandroid/graphics/Bitmap;I)J", (void*)nAllocationCubeCreateFromBitmap },
{"rsnAllocationCreateTyped", "(JJIIJ)J", (void*)nAllocationCreateTyped },
{"rsnAllocationCreateFromBitmap", "(JJIJI)J", (void*)nAllocationCreateFromBitmap },
{"rsnAllocationCreateBitmapBackedAllocation", "(JJIJI)J", (void*)nAllocationCreateBitmapBackedAllocation },
{"rsnAllocationCubeCreateFromBitmap","(JJIJI)J", (void*)nAllocationCubeCreateFromBitmap },

{"rsnAllocationCopyFromBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyFromBitmap },
{"rsnAllocationCopyToBitmap", "(JJLandroid/graphics/Bitmap;)V", (void*)nAllocationCopyToBitmap },
{"rsnAllocationCopyFromBitmap", "(JJJ)V", (void*)nAllocationCopyFromBitmap },
{"rsnAllocationCopyToBitmap", "(JJJ)V", (void*)nAllocationCopyToBitmap },

{"rsnAllocationSyncAll", "(JJI)V", (void*)nAllocationSyncAll },
{"rsnAllocationSetupBufferQueue", "(JJI)V", (void*)nAllocationSetupBufferQueue },

Loading…
Cancel
Save