Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0385dc8d authored by John Reck's avatar John Reck Committed by Android Git Automerger
Browse files

am 1d8aae3b: am db672b03: Merge "Change how Java Bitmaps are accessed in a few places" into mnc-dev

* commit '1d8aae3b':
  Change how Java Bitmaps are accessed in a few places
parents c9122d6f 1d8aae3b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -261,7 +261,7 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
    SkBitmap* outputBitmap = NULL;
    unsigned int existingBufferSize = 0;
    if (javaBitmap != NULL) {
        outputBitmap = GraphicsJNI::getSkBitmap(env, javaBitmap);
        outputBitmap = GraphicsJNI::getSkBitmapDeprecated(env, javaBitmap);
        if (outputBitmap->isImmutable()) {
            ALOGW("Unable to reuse an immutable bitmap as an image decoder target.");
            javaBitmap = NULL;
+1 −1
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, jlong brdHandle,

    if (tileBitmap != NULL) {
        // Re-use bitmap.
        bitmap = GraphicsJNI::getSkBitmap(env, tileBitmap);
        bitmap = GraphicsJNI::getSkBitmapDeprecated(env, tileBitmap);
    }
    if (bitmap == NULL) {
        bitmap = new SkBitmap;
+14 −1
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ SkColorType GraphicsJNI::legacyBitmapConfigToColorType(jint legacyConfig) {
    return static_cast<SkColorType>(gConfig2ColorType[legacyConfig]);
}

SkBitmap* GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap) {
SkBitmap* GraphicsJNI::getSkBitmapDeprecated(JNIEnv* env, jobject bitmap) {
    SkASSERT(env);
    SkASSERT(bitmap);
    SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
@@ -348,6 +348,19 @@ SkBitmap* GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap) {
    return b;
}

void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) {
    // TODO: We have to copy from the existing bitmap due to rowBytes not
    // being updated on the SkPixelRef at reconfigure time. This is a short term
    // problem that will be fixed with the specialized wrapper
    *outBitmap = *getSkBitmapDeprecated(env, bitmap);
}

SkPixelRef* GraphicsJNI::getSkPixelRef(JNIEnv* env, jobject bitmap) {
    jlong bitmapHandle = env->GetLongField(bitmap, gBitmap_skBitmapPtr);
    SkBitmap* b = reinterpret_cast<SkBitmap*>(bitmapHandle);
    return b->pixelRef();
}

SkColorType GraphicsJNI::getNativeBitmapColorType(JNIEnv* env, jobject jconfig) {
    SkASSERT(env);
    if (NULL == jconfig) {
+3 −1
Original line number Diff line number Diff line
@@ -49,7 +49,9 @@ public:
    static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf);

    static android::Canvas* getNativeCanvas(JNIEnv*, jobject canvas);
    static SkBitmap* getSkBitmap(JNIEnv*, jobject bitmap);
    static SkBitmap* getSkBitmapDeprecated(JNIEnv*, jobject bitmap);
    static void getSkBitmap(JNIEnv*, jobject bitmap, SkBitmap* outBitmap);
    static SkPixelRef* getSkPixelRef(JNIEnv*, jobject bitmap);
    static SkRegion* getNativeRegion(JNIEnv*, jobject region);

    // Given the 'native' long held by the Rasterizer.java object, return a
+10 −9
Original line number Diff line number Diff line
@@ -243,19 +243,21 @@ static void renderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int destLeft, i
}

static void nativeRenderPage(JNIEnv* env, jclass thiz, jlong documentPtr, jlong pagePtr,
        jlong bitmapPtr, jint destLeft, jint destTop, jint destRight, jint destBottom,
        jobject jbitmap, jint destLeft, jint destTop, jint destRight, jint destBottom,
        jlong matrixPtr, jint renderMode) {

    FPDF_PAGE page = reinterpret_cast<FPDF_PAGE>(pagePtr);
    SkBitmap* skBitmap = reinterpret_cast<SkBitmap*>(bitmapPtr);
    SkMatrix* skMatrix = reinterpret_cast<SkMatrix*>(matrixPtr);

    skBitmap->lockPixels();
    SkBitmap skBitmap;
    GraphicsJNI::getSkBitmap(env, jbitmap, &skBitmap);

    const int stride = skBitmap->width() * 4;
    SkAutoLockPixels alp(skBitmap);

    FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(skBitmap->width(), skBitmap->height(),
            FPDFBitmap_BGRA, skBitmap->getPixels(), stride);
    const int stride = skBitmap.width() * 4;

    FPDF_BITMAP bitmap = FPDFBitmap_CreateEx(skBitmap.width(), skBitmap.height(),
            FPDFBitmap_BGRA, skBitmap.getPixels(), stride);

    if (!bitmap) {
        ALOGE("Erorr creating bitmap");
@@ -278,8 +280,7 @@ static void nativeRenderPage(JNIEnv* env, jclass thiz, jlong documentPtr, jlong
    renderPageBitmap(bitmap, page, destLeft, destTop, destRight,
            destBottom, skMatrix, renderFlags);

    skBitmap->notifyPixelsChanged();
    skBitmap->unlockPixels();
    skBitmap.notifyPixelsChanged();
}

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