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

Commit 904f3ec8 authored by Leon Scroggins's avatar Leon Scroggins Committed by Android Git Automerger
Browse files

am 4a857b1d: Merge "Update framework to use M34 version of Skia."

* commit '4a857b1d':
  Update framework to use M34 version of Skia.
parents 5c421bd5 4a857b1d
Loading
Loading
Loading
Loading
+26 −18
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
#include "SkImageDecoder.h"
#include "SkImageRef_ashmem.h"
#include "SkImageRef_GlobalPool.h"
#include "SkMath.h"
#include "SkPixelRef.h"
#include "SkStream.h"
#include "SkTemplates.h"
@@ -146,15 +147,15 @@ static SkPixelRef* installPixelRef(SkBitmap* bitmap, SkStreamRewindable* stream,
    return pr;
}

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

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

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

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

        SkImageInfo bitmapInfo;
        if (!bitmap->asImageInfo(&bitmapInfo)) {
            ALOGW("unable to reuse a bitmap as the target has an unknown bitmap configuration");
        const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
        if (!sk_64_isS32(size64)) {
            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;
        }

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

        bitmap->setPixelRef(pr)->unref();
        // 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());

        // 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
        // colors may not be correct, since Skia does not yet support drawing
        // to/from unpremultiplied bitmaps.
        outputBitmap->setConfig(config, scaledWidth, scaledHeight, 0,
                                decodingBitmap.alphaType());
        outputBitmap->setConfig(SkImageInfo::Make(scaledWidth, scaledHeight,
                colorType, decodingBitmap.alphaType()));
        if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
            return nullObjectReturn("allocation failed for scaled bitmap");
        }
+2 −32
Original line number Diff line number Diff line
@@ -680,9 +680,6 @@ public:
            indices [ptCount * sizeof(uint16_t)]
        */
        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[]

        SkAutoMalloc storage(storageSize);
@@ -693,16 +690,7 @@ public:
        verts = (SkPoint*)(vertA.ptr() + vertIndex);
        indices = (uint16_t*)(texs + ptCount);
#else
        verts = texs + ptCount;
        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;
            }
        }
        SkASSERT(false);
#endif

        // cons up texture coordinates and indices
@@ -804,25 +792,7 @@ public:
            texs = (SkPoint*)(texA.ptr() + texIndex);
        }
#else
        int count = ptCount;    // for verts
        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;
            }
        }
        SkASSERT(false);
#endif

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

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

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

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

    SkImageInfo bitmapInfo;
    if (!bitmap->asImageInfo(&bitmapInfo)) {
        jniThrowException(env, "java/lang/IllegalArgumentException",
                "unknown bitmap configuration");
    const int64_t size64 = info.getSafeSize64(bitmap->rowBytes());
    if (!sk_64_isS32(size64)) {
        doThrowIAE(env, "bitmap size exceeds 32bits");
        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,
                                                             gVMRuntime_newNonMovableArray,
                                                             gByte_class, size);
@@ -591,7 +591,7 @@ jbyteArray GraphicsJNI::allocateJavaPixelRef(JNIEnv* env, SkBitmap* bitmap,
        return NULL;
    }
    SkASSERT(addr);
    SkPixelRef* pr = new AndroidPixelRef(env, bitmapInfo, (void*) addr,
    SkPixelRef* pr = new AndroidPixelRef(env, info, (void*) addr,
            bitmap->rowBytes(), arrayObj, ctable);
    bitmap->setPixelRef(pr)->unref();
    // since we're already allocated, we lockPixels right away
+12 −51
Original line number Diff line number Diff line
@@ -272,18 +272,11 @@ public:
        float* dst = autoDst.ptr() + dstIndex;
        bool result;

#ifdef SK_SCALAR_IS_FIXED        
        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
#ifdef SK_SCALAR_IS_FLOAT
        result = matrix->setPolyToPoly((const SkPoint*)src, (const SkPoint*)dst,
                                     ptCount);
#else
        SkASSERT(false);
#endif
        return result ? JNI_TRUE : JNI_FALSE;
    }
@@ -304,36 +297,15 @@ public:
        AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1), kRW_JNIAccess);
        float* srcArray = autoSrc.ptr() + srcIndex;
        float* dstArray = autoDst.ptr() + dstIndex;
        
#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
#ifdef SK_SCALAR_IS_FLOAT
        if (isPts)
            matrix->mapPoints((SkPoint*)dstArray, (const SkPoint*)srcArray,
                              ptCount);
        else
            matrix->mapVectors((SkVector*)dstArray, (const SkVector*)srcArray,
                               ptCount);
#else
        SkASSERT(false);
#endif
    }

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

#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
#ifdef SK_SCALAR_IS_FLOAT
        for (int i = 0; i < 9; i++) {
            dst[i] = matrix->get(i);
        }
#else
        SkASSERT(false);
#endif
    }

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

#ifdef SK_SCALAR_IS_FIXED
        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
#ifdef SK_SCALAR_IS_FLOAT
        for (int i = 0; i < 9; i++) {
            matrix->set(i, src[i]);
        }
#else
        SkASSERT(false);
#endif
    }

Loading