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

Commit 8222a7ec authored by John Reck's avatar John Reck Committed by Android (Google) Code Review
Browse files

Merge "Revert "Change how Java Bitmaps are accessed in a few places""

parents 2eec3d14 edc22fba
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::getSkBitmapDeprecated(env, javaBitmap);
        outputBitmap = GraphicsJNI::getSkBitmap(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::getSkBitmapDeprecated(env, tileBitmap);
        bitmap = GraphicsJNI::getSkBitmap(env, tileBitmap);
    }
    if (bitmap == NULL) {
        bitmap = new SkBitmap;
+1 −16
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::getSkBitmapDeprecated(JNIEnv* env, jobject bitmap) {
SkBitmap* GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap) {
    SkASSERT(env);
    SkASSERT(bitmap);
    SkASSERT(env->IsInstanceOf(bitmap, gBitmap_class));
@@ -348,21 +348,6 @@ SkBitmap* GraphicsJNI::getSkBitmapDeprecated(JNIEnv* env, jobject bitmap) {
    return b;
}

void GraphicsJNI::getSkBitmap(JNIEnv* env, jobject bitmap, SkBitmap* outBitmap) {
    SkPixelRef* pixelRef = getSkPixelRef(env, bitmap);
    // TODO: pixelRef->rowBytes() is only valid if the pixels are locked
    // (which is currently always true on android), switch this to querying
    // from the wrapper once that exists instead
    outBitmap->setInfo(pixelRef->info(), pixelRef->rowBytes());
    outBitmap->setPixelRef(pixelRef);
}

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) {
+1 −3
Original line number Diff line number Diff line
@@ -48,9 +48,7 @@ public:
    static void point_to_jpointf(const SkPoint& point, JNIEnv*, jobject jpointf);

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

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

static void nativeRenderPage(JNIEnv* env, jclass thiz, jlong documentPtr, jlong pagePtr,
        jobject jbitmap, jint destLeft, jint destTop, jint destRight, jint destBottom,
        jlong bitmapPtr, 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 skBitmap;
    GraphicsJNI::getSkBitmap(env, jbitmap, &skBitmap);
    skBitmap->lockPixels();

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

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

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

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

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

static JNINativeMethod gPdfRenderer_Methods[] = {
@@ -288,7 +287,7 @@ static 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}
};
Loading