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

Commit 4a857b1d authored by Leon Scroggins's avatar Leon Scroggins Committed by Android (Google) Code Review
Browse files

Merge "Update framework to use M34 version of Skia."

parents 9ad8a533 46cb9bdb
Loading
Loading
Loading
Loading
+26 −18
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@
#include "SkImageDecoder.h"
#include "SkImageDecoder.h"
#include "SkImageRef_ashmem.h"
#include "SkImageRef_ashmem.h"
#include "SkImageRef_GlobalPool.h"
#include "SkImageRef_GlobalPool.h"
#include "SkMath.h"
#include "SkPixelRef.h"
#include "SkPixelRef.h"
#include "SkStream.h"
#include "SkStream.h"
#include "SkTemplates.h"
#include "SkTemplates.h"
@@ -146,15 +147,15 @@ static SkPixelRef* installPixelRef(SkBitmap* bitmap, SkStreamRewindable* stream,
    return pr;
    return pr;
}
}


static SkBitmap::Config configForScaledOutput(SkBitmap::Config config) {
static SkColorType colorTypeForScaledOutput(SkColorType colorType) {
    switch (config) {
    switch (colorType) {
        case SkBitmap::kNo_Config:
        case kUnknown_SkColorType:
        case SkBitmap::kIndex8_Config:
        case kIndex_8_SkColorType:
            return SkBitmap::kARGB_8888_Config;
            return kPMColor_SkColorType;
        default:
        default:
            break;
            break;
    }
    }
    return config;
    return colorType;
}
}


class ScaleCheckingAllocator : public SkBitmap::HeapAllocator {
class ScaleCheckingAllocator : public SkBitmap::HeapAllocator {
@@ -165,8 +166,8 @@ public:


    virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
    virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
        // accounts for scale in final allocation, using eventual size and config
        // accounts for scale in final allocation, using eventual size and config
        const int bytesPerPixel = SkBitmap::ComputeBytesPerPixel(
        const int bytesPerPixel = SkColorTypeBytesPerPixel(
                configForScaledOutput(bitmap->config()));
                colorTypeForScaledOutput(bitmap->colorType()));
        const int requestedSize = bytesPerPixel *
        const int requestedSize = bytesPerPixel *
                int(bitmap->width() * mScale + 0.5f) *
                int(bitmap->width() * mScale + 0.5f) *
                int(bitmap->height() * mScale + 0.5f);
                int(bitmap->height() * mScale + 0.5f);
@@ -194,21 +195,28 @@ public:
    }
    }


    virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
    virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
        if (!bitmap->getSize64().is32() || bitmap->getSize() > mSize) {
        const SkImageInfo& info = bitmap->info();
            ALOGW("bitmap marked for reuse (%d bytes) can't fit new bitmap (%d bytes)",
        if (info.fColorType == kUnknown_SkColorType) {
                    mSize, bitmap->getSize());
            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
            return false;
            return false;
        }
        }


        SkImageInfo bitmapInfo;
        const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
        if (!bitmap->asImageInfo(&bitmapInfo)) {
        if (!sk_64_isS32(size64)) {
            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
            ALOGW("bitmap is too large");
            return false;
        }

        const size_t size = sk_64_asS32(size64);
        if (size > mSize) {
            ALOGW("bitmap marked for reuse (%d bytes) can't fit new bitmap (%d bytes)",
                    mSize, size);
            return false;
            return false;
        }
        }


        // Create a new pixelref with the new ctable that wraps the previous pixelref
        // Create a new pixelref with the new ctable that wraps the previous pixelref
        SkPixelRef* pr = new AndroidPixelRef(*static_cast<AndroidPixelRef*>(mPixelRef),
        SkPixelRef* pr = new AndroidPixelRef(*static_cast<AndroidPixelRef*>(mPixelRef),
                bitmapInfo, bitmap->rowBytes(), ctable);
                info, bitmap->rowBytes(), ctable);


        bitmap->setPixelRef(pr)->unref();
        bitmap->setPixelRef(pr)->unref();
        // since we're already allocated, we lockPixels right away
        // since we're already allocated, we lockPixels right away
@@ -416,12 +424,12 @@ static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding
        const float sy = scaledHeight / float(decodingBitmap.height());
        const float sy = scaledHeight / float(decodingBitmap.height());


        // TODO: avoid copying when scaled size equals decodingBitmap size
        // TODO: avoid copying when scaled size equals decodingBitmap size
        SkBitmap::Config config = configForScaledOutput(decodingBitmap.config());
        SkColorType colorType = colorTypeForScaledOutput(decodingBitmap.colorType());
        // FIXME: If the alphaType is kUnpremul and the image has alpha, the
        // FIXME: If the alphaType is kUnpremul and the image has alpha, the
        // colors may not be correct, since Skia does not yet support drawing
        // colors may not be correct, since Skia does not yet support drawing
        // to/from unpremultiplied bitmaps.
        // to/from unpremultiplied bitmaps.
        outputBitmap->setConfig(config, scaledWidth, scaledHeight, 0,
        outputBitmap->setConfig(SkImageInfo::Make(scaledWidth, scaledHeight,
                                decodingBitmap.alphaType());
                colorType, decodingBitmap.alphaType()));
        if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
        if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
            return nullObjectReturn("allocation failed for scaled bitmap");
            return nullObjectReturn("allocation failed for scaled bitmap");
        }
        }
+2 −32
Original line number Original line Diff line number Diff line
@@ -680,9 +680,6 @@ public:
            indices [ptCount * sizeof(uint16_t)]
            indices [ptCount * sizeof(uint16_t)]
        */
        */
        ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
        ssize_t storageSize = ptCount * sizeof(SkPoint); // texs[]
#ifdef SK_SCALAR_IS_FIXED
        storageSize += ptCount * sizeof(SkPoint);  // storage for verts
#endif
        storageSize += indexCount * sizeof(uint16_t);  // indices[]
        storageSize += indexCount * sizeof(uint16_t);  // indices[]


        SkAutoMalloc storage(storageSize);
        SkAutoMalloc storage(storageSize);
@@ -693,16 +690,7 @@ public:
        verts = (SkPoint*)(vertA.ptr() + vertIndex);
        verts = (SkPoint*)(vertA.ptr() + vertIndex);
        indices = (uint16_t*)(texs + ptCount);
        indices = (uint16_t*)(texs + ptCount);
#else
#else
        verts = texs + ptCount;
        SkASSERT(false);
        indices = (uint16_t*)(verts + ptCount);
        // convert floats to fixed
        {
            const float* src = vertA.ptr() + vertIndex;
            for (int i = 0; i < ptCount; i++) {
                verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
                src += 2;
            }
        }
#endif
#endif


        // cons up texture coordinates and indices
        // cons up texture coordinates and indices
@@ -804,25 +792,7 @@ public:
            texs = (SkPoint*)(texA.ptr() + texIndex);
            texs = (SkPoint*)(texA.ptr() + texIndex);
        }
        }
#else
#else
        int count = ptCount;    // for verts
        SkASSERT(false);
        if (jtexs != NULL) {
            count += ptCount;   // += for texs
        }
        SkAutoMalloc storage(count * sizeof(SkPoint));
        verts = (SkPoint*)storage.get();
        const float* src = vertA.ptr() + vertIndex;
        for (int i = 0; i < ptCount; i++) {
            verts[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
            src += 2;
        }
        if (jtexs != NULL) {
            texs = verts + ptCount;
            src = texA.ptr() + texIndex;
            for (int i = 0; i < ptCount; i++) {
                texs[i].set(SkFloatToFixed(src[0]), SkFloatToFixed(src[1]));
                src += 2;
            }
        }
#endif
#endif


        const SkColor* colors = NULL;
        const SkColor* colors = NULL;
+3 −7
Original line number Original line Diff line number Diff line
@@ -50,14 +50,10 @@ public:
        AutoJavaFloatArray autoArray(env, jarray, 20);
        AutoJavaFloatArray autoArray(env, jarray, 20);
        const float* src = autoArray.ptr();
        const float* src = autoArray.ptr();


#ifdef SK_SCALAR_IS_FIXED
#ifdef SK_SCALAR_IS_FLOAT
        SkFixed array[20];
        for (int i = 0; i < 20; i++) {
            array[i] = SkFloatToScalar(src[i]);
        }
        return reinterpret_cast<jlong>(new SkColorMatrixFilter(array));
#else
        return reinterpret_cast<jlong>(new SkColorMatrixFilter(src));
        return reinterpret_cast<jlong>(new SkColorMatrixFilter(src));
#else
        SkASSERT(false);
#endif
#endif
    }
    }
};
};
+10 −10
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@


#include "SkCanvas.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkDevice.h"
#include "SkMath.h"
#include "SkPicture.h"
#include "SkPicture.h"
#include "SkRegion.h"
#include "SkRegion.h"
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/AndroidRuntime.h>
@@ -564,21 +565,20 @@ void AndroidPixelRef::globalUnref() {


jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
                                             SkColorTable* ctable) {
                                             SkColorTable* ctable) {
    Sk64 size64 = bitmap->getSize64();
    const SkImageInfo& info = bitmap->info();
    if (size64.isNeg() || !size64.is32()) {
    if (info.fColorType == kUnknown_SkColorType) {
        jniThrowException(env, "java/lang/IllegalArgumentException",
        doThrowIAE(env, "unknown bitmap configuration");
                          "bitmap size exceeds 32bits");
        return NULL;
        return NULL;
    }
    }


    SkImageInfo bitmapInfo;
    const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
    if (!bitmap->asImageInfo(&bitmapInfo)) {
    if (!sk_64_isS32(size64)) {
        jniThrowException(env, "java/lang/IllegalArgumentException",
        doThrowIAE(env, "bitmap size exceeds 32bits");
                "unknown bitmap configuration");
        return NULL;
        return NULL;
    }
    }
    const size_t size = sk_64_asS32(size64);
    SkASSERT(size == info.getSafeSize(bitmap->rowBytes()));


    size_t size = size64.get32();
    jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
    jbyteArray arrayObj = (jbyteArray) env->CallObjectMethod(gVMRuntime,
                                                             gVMRuntime_newNonMovableArray,
                                                             gVMRuntime_newNonMovableArray,
                                                             gByte_class, size);
                                                             gByte_class, size);
@@ -591,7 +591,7 @@ jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
        return NULL;
        return NULL;
    }
    }
    SkASSERT(addr);
    SkASSERT(addr);
    SkPixelRef* pr = new AndroidPixelRef(env, bitmapInfo, (void*) addr,
    SkPixelRef* pr = new AndroidPixelRef(env, info, (void*) addr,
            bitmap->rowBytes(), arrayObj, ctable);
            bitmap->rowBytes(), arrayObj, ctable);
    bitmap->setPixelRef(pr)->unref();
    bitmap->setPixelRef(pr)->unref();
    // since we're already allocated, we lockPixels right away
    // since we're already allocated, we lockPixels right away
+12 −51
Original line number Original line Diff line number Diff line
@@ -272,18 +272,11 @@ public:
        float* dst = autoDst.ptr() + dstIndex;
        float* dst = autoDst.ptr() + dstIndex;
        bool result;
        bool result;


#ifdef SK_SCALAR_IS_FIXED        
#ifdef SK_SCALAR_IS_FLOAT
        SkPoint srcPt[4], dstPt[4];
        for (int i = 0; i < ptCount; i++) {
            int x = i << 1;
            int y = x + 1;
            srcPt[i].set(SkFloatToScalar(src[x]), SkFloatToScalar(src[y]));
            dstPt[i].set(SkFloatToScalar(dst[x]), SkFloatToScalar(dst[y]));
        }
        result = matrix->setPolyToPoly(srcPt, dstPt, ptCount);
#else
        result = matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
        result = matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
                                     ptCount);
                                     ptCount);
#else
        SkASSERT(false);
#endif
#endif
        return result ? JNI_TRUE : JNI_FALSE;
        return result ? JNI_TRUE : JNI_FALSE;
    }
    }
@@ -304,36 +297,15 @@ public:
        AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
        AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
        float* srcArray = autoSrc.ptr() + srcIndex;
        float* srcArray = autoSrc.ptr() + srcIndex;
        float* dstArray = autoDst.ptr() + dstIndex;
        float* dstArray = autoDst.ptr() + dstIndex;
        
#ifdef SK_SCALAR_IS_FLOAT
#ifdef SK_SCALAR_IS_FIXED        
        // we allocate twice the count, 1 set for src, 1 for dst
        SkAutoSTMalloc<32, SkPoint> storage(ptCount * 2);
        SkPoint* pts = storage.get();
        SkPoint* srcPt = pts;
        SkPoint* dstPt = pts + ptCount;
        
        int i;
        for (i = 0; i < ptCount; i++) {
            srcPt[i].set(SkFloatToScalar(srcArray[i << 1]),
                         SkFloatToScalar(srcArray[(i << 1) + 1]));
        }
        
        if (isPts)
            matrix->mapPoints(dstPt, srcPt, ptCount);
        else
            matrix->mapVectors(dstPt, srcPt, ptCount);
        
        for (i = 0; i < ptCount; i++) {
            dstArray[i << 1]  = SkScalarToFloat(dstPt[i].fX);
            dstArray[(i << 1) + 1]  = SkScalarToFloat(dstPt[i].fY);
        }
#else
        if (isPts)
        if (isPts)
            matrix->mapPoints((SkPoint*)dstArray, (const SkPoint*)srcArray,
            matrix->mapPoints((SkPoint*)dstArray, (const SkPoint*)srcArray,
                              ptCount);
                              ptCount);
        else
        else
            matrix->mapVectors((SkVector*)dstArray, (const SkVector*)srcArray,
            matrix->mapVectors((SkVector*)dstArray, (const SkVector*)srcArray,
                               ptCount);
                               ptCount);
#else
        SkASSERT(false);
#endif
#endif
    }
    }


@@ -356,18 +328,12 @@ public:
        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
        SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
        AutoJavaFloatArray autoValues(env, values, 9, kRW_JNIAccess);
        AutoJavaFloatArray autoValues(env, values, 9, kRW_JNIAccess);
        float* dst = autoValues.ptr();
        float* dst = autoValues.ptr();

#ifdef SK_SCALAR_IS_FLOAT
#ifdef SK_SCALAR_IS_FIXED
        for (int i = 0; i < 6; i++) {
            dst[i] = SkFixedToFloat(matrix->get(i));
        }
        for (int j = 6; j < 9; j++) {
            dst[j] = SkFractToFloat(matrix->get(j));
        }
#else
        for (int i = 0; i < 9; i++) {
        for (int i = 0; i < 9; i++) {
            dst[i] = matrix->get(i);
            dst[i] = matrix->get(i);
        }
        }
#else
        SkASSERT(false);
#endif
#endif
    }
    }


@@ -376,17 +342,12 @@ public:
        AutoJavaFloatArray autoValues(env, values, 9, kRO_JNIAccess);
        AutoJavaFloatArray autoValues(env, values, 9, kRO_JNIAccess);
        const float* src = autoValues.ptr();
        const float* src = autoValues.ptr();


#ifdef SK_SCALAR_IS_FIXED
#ifdef SK_SCALAR_IS_FLOAT
        for (int i = 0; i < 6; i++) {
            matrix->set(i, SkFloatToFixed(src[i]));
        }
        for (int j = 6; j < 9; j++) {
            matrix->set(j, SkFloatToFract(src[j]));
        }
#else
        for (int i = 0; i < 9; i++) {
        for (int i = 0; i < 9; i++) {
            matrix->set(i, src[i]);
            matrix->set(i, src[i]);
        }
        }
#else
        SkASSERT(false);
#endif
#endif
    }
    }


Loading