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

Commit 93856250 authored by Matt Sarett's avatar Matt Sarett Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'BitmapFactory'

* changes:
  Allow SkAndroidCodec to compute the decode color type and alpha type
  Modify BitmapFactory to use SkAndroidCodec
  Make NinePatchPeeker inherit from SkPngChunkReader
parents 2336f716 9e7cd635
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -96,7 +96,6 @@ LOCAL_SRC_FILES:= \
    android_util_jar_StrictJarFile.cpp \
    android_graphics_Canvas.cpp \
    android_graphics_Picture.cpp \
    android/graphics/AutoDecodeCancel.cpp \
    android/graphics/AvoidXfermode.cpp \
    android/graphics/Bitmap.cpp \
    android/graphics/BitmapFactory.cpp \
+0 −101
Original line number Diff line number Diff line
#include "AutoDecodeCancel.h"
#include "SkMutex.h"

SK_DECLARE_STATIC_MUTEX(gAutoDecoderCancelMutex);
static AutoDecoderCancel* gAutoDecoderCancel;
#ifdef SK_DEBUG
static int gAutoDecoderCancelCount;
#endif

AutoDecoderCancel::AutoDecoderCancel(jobject joptions,
                                       SkImageDecoder* decoder) {
    fJOptions = joptions;
    fDecoder = decoder;

    if (NULL != joptions) {
        SkAutoMutexAcquire ac(gAutoDecoderCancelMutex);

        // Add us as the head of the list
        fPrev = NULL;
        fNext = gAutoDecoderCancel;
        if (gAutoDecoderCancel) {
            gAutoDecoderCancel->fPrev = this;
        }
        gAutoDecoderCancel = this;

        SkDEBUGCODE(gAutoDecoderCancelCount += 1;)
        Validate();
    }
}

AutoDecoderCancel::~AutoDecoderCancel() {
    if (NULL != fJOptions) {
        SkAutoMutexAcquire ac(gAutoDecoderCancelMutex);

        // take us out of the dllist
        AutoDecoderCancel* prev = fPrev;
        AutoDecoderCancel* next = fNext;

        if (prev) {
            SkASSERT(prev->fNext == this);
            prev->fNext = next;
        } else {
            SkASSERT(gAutoDecoderCancel == this);
            gAutoDecoderCancel = next;
        }
        if (next) {
            SkASSERT(next->fPrev == this);
            next->fPrev = prev;
        }

        SkDEBUGCODE(gAutoDecoderCancelCount -= 1;)
        Validate();
    }
}

bool AutoDecoderCancel::RequestCancel(jobject joptions) {
    SkAutoMutexAcquire ac(gAutoDecoderCancelMutex);

    Validate();

    AutoDecoderCancel* pair = gAutoDecoderCancel;
    while (pair != NULL) {
        if (pair->fJOptions == joptions) {
            pair->fDecoder->cancelDecode();
            return true;
        }
        pair = pair->fNext;
    }
    return false;
}

#ifdef SK_DEBUG
// can only call this inside a lock on gAutoDecoderCancelMutex
void AutoDecoderCancel::Validate() {
    const int gCount = gAutoDecoderCancelCount;

    if (gCount == 0) {
        SkASSERT(gAutoDecoderCancel == NULL);
    } else {
        SkASSERT(gCount > 0);

        AutoDecoderCancel* curr = gAutoDecoderCancel;
        SkASSERT(curr);
        SkASSERT(curr->fPrev == NULL);

        int count = 0;
        while (curr) {
            count += 1;
            SkASSERT(count <= gCount);
            if (curr->fPrev) {
                SkASSERT(curr->fPrev->fNext == curr);
            }
            if (curr->fNext) {
                SkASSERT(curr->fNext->fPrev == curr);
            }
            curr = curr->fNext;
        }
        SkASSERT(count == gCount);
    }
}
#endif
+0 −27
Original line number Diff line number Diff line
#ifndef _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_
#define _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_

#include <jni.h>
#include "SkImageDecoder.h"

class AutoDecoderCancel {
public:
    AutoDecoderCancel(jobject options, SkImageDecoder* decoder);
    ~AutoDecoderCancel();

    static bool RequestCancel(jobject options);

private:
    AutoDecoderCancel*  fNext;
    AutoDecoderCancel*  fPrev;
    jobject             fJOptions;  // java options object
    SkImageDecoder*     fDecoder;

#ifdef SK_DEBUG
    static void Validate();
#else
    static void Validate() {}
#endif
};

#endif  // _ANDROID_GRAPHICS_AUTO_DECODE_CANCEL_H_
+179 −118

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#define _ANDROID_GRAPHICS_BITMAP_FACTORY_H_

#include "GraphicsJNI.h"
#include "SkEncodedFormat.h"

extern jclass gOptions_class;
extern jfieldID gOptions_justBoundsFieldID;
@@ -19,7 +20,7 @@ extern jfieldID gOptions_mimeFieldID;
extern jfieldID gOptions_mCancelID;
extern jfieldID gOptions_bitmapFieldID;

jstring getMimeTypeString(JNIEnv* env, SkImageDecoder::Format format);
jstring encodedFormatToString(JNIEnv* env, SkEncodedFormat format);

jobject decodeBitmap(JNIEnv* env, void* data, size_t size);

Loading