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

Commit 5ca2c86c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[HWUI] Remove hardcoding around wide color gamut."

parents f1a5b6e0 3bff1355
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <ui/GraphicTypes.h>

#include <mutex>
#include <thread>
@@ -61,6 +62,50 @@ DisplayInfo QueryDisplayInfo() {
    return displayInfo;
}

static void queryWideColorGamutPreference(SkColorSpace::Gamut* colorGamut,
                                          sk_sp<SkColorSpace>* colorSpace, SkColorType* colorType) {
    if (Properties::isolatedProcess) {
        *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
        *colorSpace = SkColorSpace::MakeSRGB();
        *colorType = SkColorType::kN32_SkColorType;
        return;
    }
    ui::Dataspace defaultDataspace, wcgDataspace;
    ui::PixelFormat defaultPixelFormat, wcgPixelFormat;
    status_t status =
        SurfaceComposerClient::getCompositionPreference(&defaultDataspace, &defaultPixelFormat,
                                                        &wcgDataspace, &wcgPixelFormat);
    LOG_ALWAYS_FATAL_IF(status, "Failed to get composition preference, error %d", status);
    switch (wcgDataspace) {
        case ui::Dataspace::DISPLAY_P3:
            *colorGamut = SkColorSpace::Gamut::kDCIP3_D65_Gamut;
            *colorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
                                                SkColorSpace::Gamut::kDCIP3_D65_Gamut);
            break;
        case ui::Dataspace::V0_SCRGB:
            *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
            *colorSpace = SkColorSpace::MakeSRGB();
            break;
        case ui::Dataspace::V0_SRGB:
            // when sRGB is returned, it means wide color gamut is not supported.
            *colorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
            *colorSpace = SkColorSpace::MakeSRGB();
            break;
        default:
            LOG_ALWAYS_FATAL("Unreachable: unsupported wide color space.");
    }
    switch (wcgPixelFormat) {
        case ui::PixelFormat::RGBA_8888:
            *colorType = SkColorType::kN32_SkColorType;
            break;
        case ui::PixelFormat::RGBA_FP16:
            *colorType = SkColorType::kRGBA_F16_SkColorType;
            break;
        default:
            LOG_ALWAYS_FATAL("Unreachable: unsupported pixel format.");
    }
}

DeviceInfo::DeviceInfo() {
#if HWUI_NULL_GPU
        mMaxTextureSize = NULL_GPU_MAX_TEXTURE_SIZE;
@@ -68,6 +113,7 @@ DeviceInfo::DeviceInfo() {
        mMaxTextureSize = -1;
#endif
    mDisplayInfo = QueryDisplayInfo();
    queryWideColorGamutPreference(&mWideColorGamut, &mWideColorSpace, &mWideColorType);
}

int DeviceInfo::maxTextureSize() const {
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
#ifndef DEVICEINFO_H
#define DEVICEINFO_H

#include <SkImageInfo.h>
#include <ui/DisplayInfo.h>

#include "utils/Macros.h"
@@ -37,6 +38,9 @@ public:
    // context or if you are using the HWUI_NULL_GPU
    int maxTextureSize() const;
    const DisplayInfo& displayInfo() const { return mDisplayInfo; }
    SkColorSpace::Gamut getWideColorGamut() const { return mWideColorGamut; }
    sk_sp<SkColorSpace> getWideColorSpace() const { return mWideColorSpace; }
    SkColorType getWideColorType() const { return mWideColorType; }

private:
    friend class renderthread::RenderThread;
@@ -46,6 +50,9 @@ private:

    int mMaxTextureSize;
    DisplayInfo mDisplayInfo;
    SkColorSpace::Gamut mWideColorGamut;
    sk_sp<SkColorSpace> mWideColorSpace;
    SkColorType mWideColorType;
};

} /* namespace uirenderer */
+3 −8
Original line number Diff line number Diff line
@@ -162,22 +162,17 @@ bool SkiaOpenGLPipeline::setSurface(ANativeWindow* surface, SwapBehavior swapBeh
        mEglSurface = EGL_NO_SURFACE;
    }

    setSurfaceColorProperties(colorMode);

    if (surface) {
        mRenderThread.requireGlContext();
        auto newSurface = mEglManager.createSurface(surface, colorMode);
        auto newSurface = mEglManager.createSurface(surface, colorMode, mSurfaceColorGamut);
        if (!newSurface) {
            return false;
        }
        mEglSurface = newSurface.unwrap();
    }

    if (colorMode == ColorMode::SRGB) {
        mSurfaceColorType = SkColorType::kN32_SkColorType;
    } else if (colorMode == ColorMode::WideColorGamut) {
        mSurfaceColorType = SkColorType::kRGBA_F16_SkColorType;
    }
    mSurfaceColorSpace = SkColorSpace::MakeSRGB();

    if (mEglSurface != EGL_NO_SURFACE) {
        const bool preserveBuffer = (swapBehavior != SwapBehavior::kSwap_discardBuffer);
        mBufferPreserved = mEglManager.setPreserveBuffer(mEglSurface, preserveBuffer);
+15 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "SkiaPipeline.h"

#include <SkImageEncoder.h>
#include <SkImageInfo.h>
#include <SkImagePriv.h>
#include <SkOverdrawCanvas.h>
#include <SkOverdrawColorFilter.h>
@@ -453,6 +454,20 @@ void SkiaPipeline::dumpResourceCacheUsage() const {
    ALOGD("%s", log.c_str());
}

void SkiaPipeline::setSurfaceColorProperties(ColorMode colorMode) {
    if (colorMode == ColorMode::SRGB) {
        mSurfaceColorType = SkColorType::kN32_SkColorType;
        mSurfaceColorGamut = SkColorSpace::Gamut::kSRGB_Gamut;
        mSurfaceColorSpace = SkColorSpace::MakeSRGB();
    } else if (colorMode == ColorMode::WideColorGamut) {
        mSurfaceColorType = DeviceInfo::get()->getWideColorType();
        mSurfaceColorGamut = DeviceInfo::get()->getWideColorGamut();
        mSurfaceColorSpace = DeviceInfo::get()->getWideColorSpace();
    } else {
        LOG_ALWAYS_FATAL("Unreachable: unsupported color mode.");
    }
}

// Overdraw debugging

// These colors should be kept in sync with Caches::getOverdrawColor() with a few differences.
+2 −0
Original line number Diff line number Diff line
@@ -107,9 +107,11 @@ public:

protected:
    void dumpResourceCacheUsage() const;
    void setSurfaceColorProperties(renderthread::ColorMode colorMode);

    renderthread::RenderThread& mRenderThread;
    SkColorType mSurfaceColorType;
    SkColorSpace::Gamut mSurfaceColorGamut;
    sk_sp<SkColorSpace> mSurfaceColorSpace;

private:
Loading