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

Commit ef89fa3e authored by John Reck's avatar John Reck
Browse files

Have all ColorFilters work in sRGB

Test: demo app in bug
Fixes: 289571232
Change-Id: I38cf82903cbb15a53c48240eb001be40454e7234
parent 73a196df
Loading
Loading
Loading
Loading
+27 −2
Original line number Original line Diff line number Diff line
@@ -23,17 +23,42 @@


#include "GraphicsJNI.h"
#include "GraphicsJNI.h"
#include "SkColorFilter.h"
#include "SkColorFilter.h"
#include "SkiaWrapper.h"


namespace android {
namespace android {
namespace uirenderer {
namespace uirenderer {


class ColorFilter : public SkiaWrapper<SkColorFilter> {
class ColorFilter : public VirtualLightRefBase {
public:
public:
    static ColorFilter* fromJava(jlong handle) { return reinterpret_cast<ColorFilter*>(handle); }
    static ColorFilter* fromJava(jlong handle) { return reinterpret_cast<ColorFilter*>(handle); }


    sk_sp<SkColorFilter> getInstance() {
        if (mInstance != nullptr && shouldDiscardInstance()) {
            mInstance = nullptr;
        }

        if (mInstance == nullptr) {
            mInstance = createInstance();
            if (mInstance) {
                mInstance = mInstance->makeWithWorkingColorSpace(SkColorSpace::MakeSRGB());
            }
            mGenerationId++;
        }
        return mInstance;
    }

    virtual bool shouldDiscardInstance() const { return false; }

    void discardInstance() { mInstance = nullptr; }

    [[nodiscard]] int32_t getGenerationId() const { return mGenerationId; }

protected:
protected:
    ColorFilter() = default;
    ColorFilter() = default;
    virtual sk_sp<SkColorFilter> createInstance() = 0;

private:
    sk_sp<SkColorFilter> mInstance = nullptr;
    int32_t mGenerationId = 0;
};
};


class BlendModeColorFilter : public ColorFilter {
class BlendModeColorFilter : public ColorFilter {

libs/hwui/SkiaWrapper.h

deleted100644 → 0
+0 −56
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SKIA_WRAPPER_H_
#define SKIA_WRAPPER_H_

#include <SkRefCnt.h>
#include <utils/RefBase.h>

namespace android::uirenderer {

template <typename T>
class SkiaWrapper : public VirtualLightRefBase {
public:
    sk_sp<T> getInstance() {
        if (mInstance != nullptr && shouldDiscardInstance()) {
            mInstance = nullptr;
        }

        if (mInstance == nullptr) {
            mInstance = createInstance();
            mGenerationId++;
        }
        return mInstance;
    }

    virtual bool shouldDiscardInstance() const { return false; }

    void discardInstance() { mInstance = nullptr; }

    [[nodiscard]] int32_t getGenerationId() const { return mGenerationId; }

protected:
    virtual sk_sp<T> createInstance() = 0;

private:
    sk_sp<T> mInstance = nullptr;
    int32_t mGenerationId = 0;
};

}  // namespace android::uirenderer

#endif  // SKIA_WRAPPER_H_