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

Commit f7faa164 authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "SkAndroidCodec: Use getGainmapAndroidCodec" into main

parents 8aa53611 cf3d3fc3
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -501,18 +501,13 @@ SkCodec::Result ImageDecoder::decode(void* pixels, size_t rowBytes) {
SkCodec::Result ImageDecoder::extractGainmap(Bitmap* destination, bool isShared) {
    ATRACE_CALL();
    SkGainmapInfo gainmapInfo;
    std::unique_ptr<SkStream> gainmapStream;
    std::unique_ptr<SkAndroidCodec> gainmapCodec;
    {
        ATRACE_NAME("getAndroidGainmap");
        if (!mCodec->getAndroidGainmap(&gainmapInfo, &gainmapStream)) {
        ATRACE_NAME("getGainmapAndroidCodec");
        if (!mCodec->getGainmapAndroidCodec(&gainmapInfo, &gainmapCodec)) {
            return SkCodec::kSuccess;
        }
    }
    auto gainmapCodec = SkAndroidCodec::MakeFromStream(std::move(gainmapStream));
    if (!gainmapCodec) {
        ALOGW("Failed to create codec for gainmap stream");
        return SkCodec::kInvalidInput;
    }
    ImageDecoder decoder{std::move(gainmapCodec)};
    // Gainmap inherits the origin of the containing image
    decoder.mOverrideOrigin.emplace(getOrigin());
+4 −10
Original line number Diff line number Diff line
@@ -183,14 +183,8 @@ static bool needsFineScale(const SkISize fullSize, const SkISize decodedSize,
           needsFineScale(fullSize.height(), decodedSize.height(), sampleSize);
}

static bool decodeGainmap(std::unique_ptr<SkStream> gainmapStream, const SkGainmapInfo& gainmapInfo,
static bool decodeGainmap(std::unique_ptr<SkAndroidCodec> codec, const SkGainmapInfo& gainmapInfo,
                          sp<uirenderer::Gainmap>* outGainmap, const int sampleSize, float scale) {
    std::unique_ptr<SkAndroidCodec> codec;
    codec = SkAndroidCodec::MakeFromStream(std::move(gainmapStream), nullptr);
    if (!codec) {
        ALOGE("Can not create a codec for Gainmap.");
        return false;
    }
    SkColorType decodeColorType = kN32_SkColorType;
    if (codec->getInfo().colorType() == kGray_8_SkColorType) {
        decodeColorType = kGray_8_SkColorType;
@@ -613,15 +607,15 @@ static jobject doDecode(JNIEnv* env, std::unique_ptr<SkStreamRewindable> stream,

    bool hasGainmap = false;
    SkGainmapInfo gainmapInfo;
    std::unique_ptr<SkStream> gainmapStream = nullptr;
    std::unique_ptr<SkAndroidCodec> gainmapCodec;
    sp<uirenderer::Gainmap> gainmap = nullptr;
    if (result == SkCodec::kSuccess) {
        hasGainmap = codec->getAndroidGainmap(&gainmapInfo, &gainmapStream);
        hasGainmap = codec->getGainmapAndroidCodec(&gainmapInfo, &gainmapCodec);
    }

    if (hasGainmap) {
        hasGainmap =
                decodeGainmap(std::move(gainmapStream), gainmapInfo, &gainmap, sampleSize, scale);
                decodeGainmap(std::move(gainmapCodec), gainmapInfo, &gainmap, sampleSize, scale);
    }

    if (!isMutable && javaBitmap == NULL) {
+7 −20
Original line number Diff line number Diff line
@@ -48,25 +48,14 @@ public:
        }

        SkGainmapInfo gainmapInfo;
        std::unique_ptr<SkStream> gainmapStream;
        std::unique_ptr<SkAndroidCodec> gainmapCodec;
        std::unique_ptr<skia::BitmapRegionDecoder> gainmapBRD = nullptr;
        if (mainImageBRD->getAndroidGainmap(&gainmapInfo, &gainmapStream)) {
            sk_sp<SkData> data = nullptr;
            if (gainmapStream->getMemoryBase()) {
                // It is safe to make without copy because we'll hold onto the stream.
                data = SkData::MakeWithoutCopy(gainmapStream->getMemoryBase(),
                                               gainmapStream->getLength());
            } else {
                data = SkCopyStreamToData(gainmapStream.get());
                // We don't need to hold the stream anymore
                gainmapStream = nullptr;
            }
            gainmapBRD = skia::BitmapRegionDecoder::Make(std::move(data));
        if (!mainImageBRD->getGainmapBitmapRegionDecoder(&gainmapInfo, &gainmapBRD)) {
            gainmapBRD = nullptr;
        }

        return std::unique_ptr<BitmapRegionDecoderWrapper>(
                new BitmapRegionDecoderWrapper(std::move(mainImageBRD), std::move(gainmapBRD),
                                               gainmapInfo, std::move(gainmapStream)));
        return std::unique_ptr<BitmapRegionDecoderWrapper>(new BitmapRegionDecoderWrapper(
                std::move(mainImageBRD), std::move(gainmapBRD), gainmapInfo));
    }

    SkEncodedImageFormat getEncodedFormat() { return mMainImageBRD->getEncodedFormat(); }
@@ -191,16 +180,14 @@ public:
private:
    BitmapRegionDecoderWrapper(std::unique_ptr<skia::BitmapRegionDecoder> mainImageBRD,
                               std::unique_ptr<skia::BitmapRegionDecoder> gainmapBRD,
                               SkGainmapInfo info, std::unique_ptr<SkStream> stream)
                               SkGainmapInfo info)
            : mMainImageBRD(std::move(mainImageBRD))
            , mGainmapBRD(std::move(gainmapBRD))
            , mGainmapInfo(info)
            , mGainmapStream(std::move(stream)) {}
            , mGainmapInfo(info) {}

    std::unique_ptr<skia::BitmapRegionDecoder> mMainImageBRD;
    std::unique_ptr<skia::BitmapRegionDecoder> mGainmapBRD;
    SkGainmapInfo mGainmapInfo;
    std::unique_ptr<SkStream> mGainmapStream;
};
}  // namespace android