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

Commit 6f634e54 authored by Leon Scroggins III's avatar Leon Scroggins III Committed by Matt Sarett
Browse files

Make NinePatchPeeker inherit from SkPngChunkReader

SkImageDecoder is being phased out. The SkImageDecoder::Peeker has been
repurposed as SkPngChunkReader, which is shared by SkImageDecoder and
SkCodec (SkImageDecoder's replacement). Make NinePatchPeeker inherit
from the new class, and make its SkImageDecoder mHost optional, so we
can easily switch to SkCodec.

Change-Id: I74eeb909d1a4f4fe928d079857f92c142351b496
parent 90c9a00d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -17,10 +17,11 @@
#include "NinePatchPeeker.h"

#include "SkBitmap.h"
#include "SkImageDecoder.h"

using namespace android;

bool NinePatchPeeker::peek(const char tag[], const void* data, size_t length) {
bool NinePatchPeeker::readChunk(const char tag[], const void* data, size_t length) {
    if (!strcmp("npTc", tag) && length >= sizeof(Res_png_9patch)) {
        Res_png_9patch* patch = (Res_png_9patch*) data;
        size_t patchSize = patch->serializedSize();
@@ -39,7 +40,9 @@ bool NinePatchPeeker::peek(const char tag[], const void* data, size_t length) {
        // now update our host to force index or 32bit config
        // 'cause we don't want 565 predithered, since as a 9patch, we know
        // we will be stretched, and therefore we want to dither afterwards.
        if (mHost) {
            mHost->setPreserveSrcDepth(true);
        }
    } else if (!strcmp("npLb", tag) && length == sizeof(int32_t) * 4) {
        mHasInsets = true;
        memcpy(&mOpticalInsets, data, sizeof(int32_t) * 4);
+5 −3
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
#ifndef _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_
#define _ANDROID_GRAPHICS_NINE_PATCH_PEEKER_H_

#include "SkImageDecoder.h"
#include "SkPngChunkReader.h"
#include <androidfw/ResourceTypes.h>

class SkImageDecoder;

using namespace android;

class NinePatchPeeker : public SkImageDecoder::Peeker {
class NinePatchPeeker : public SkPngChunkReader {
private:
    // the host lives longer than we do, so a raw ptr is safe
    SkImageDecoder* mHost;
@@ -42,7 +44,7 @@ public:
        free(mPatch);
    }

    virtual bool peek(const char tag[], const void* data, size_t length);
    bool readChunk(const char tag[], const void* data, size_t length) override;

    Res_png_9patch* mPatch;
    size_t mPatchSize;