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

Commit 3b26c211 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Various fixes for linear blending and gradients"

parents 751e9c28 8762e332
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -45,13 +45,18 @@ Extensions::Extensions() {
    mHas1BitStencil = extensions.has("GL_OES_stencil1");
    mHas4BitStencil = extensions.has("GL_OES_stencil4");
    mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage");
    mHasSRGB = extensions.has("GL_EXT_sRGB");
    mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");

    // If linear blending is enabled, the device must have ES3.0 and GL_EXT_sRGB_write_control
#ifdef ANDROID_ENABLE_LINEAR_BLENDING
    assert(mVersionMajor >= 3 || mHasSRGB);
    assert(mHasSRGBWriteControl);
    mHasSRGB = mVersionMajor >= 3 || extensions.has("GL_EXT_sRGB");
    mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");

    // If linear blending is enabled, the device must have (ES3.0 or EXT_sRGB)
    // and EXT_sRGB_write_control
    LOG_ALWAYS_FATAL_IF(!mHasSRGB, "Linear blending requires ES 3.0 or EXT_sRGB");
    LOG_ALWAYS_FATAL_IF(!mHasSRGBWriteControl, "Linear blending requires EXT_sRGB_write_control");
#else
    mHasSRGB = false;
    mHasSRGBWriteControl = false;
#endif

    const char* version = (const char*) glGetString(GL_VERSION);
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ public:
    inline bool hasPixelBufferObjects() const { return mVersionMajor >= 3; }
    inline bool hasOcclusionQueries() const { return mVersionMajor >= 3; }
    inline bool hasFloatTextures() const { return mVersionMajor >= 3; }
    inline bool hasSRGB() const { return mVersionMajor >= 3 || mHasSRGB; }
    inline bool hasSRGB() const { return mHasSRGB; }
    inline bool hasSRGBWriteControl() const { return hasSRGB() && mHasSRGBWriteControl; }

    inline int getMajorGlVersion() const { return mVersionMajor; }
+12 −0
Original line number Diff line number Diff line
@@ -28,7 +28,19 @@ namespace uirenderer {
struct FloatColor {
    // "color" is a gamma-encoded sRGB color
    // After calling this method, the color is stored as a pre-multiplied linear color
    // if linear blending is enabled. Otherwise, the color is stored as a pre-multiplied
    // gamma-encoded sRGB color
    void set(uint32_t color) {
        a = ((color >> 24) & 0xff) / 255.0f;
        r = a * EOCF(((color >> 16) & 0xff) / 255.0f);
        g = a * EOCF(((color >>  8) & 0xff) / 255.0f);
        b = a * EOCF(((color      ) & 0xff) / 255.0f);
    }

    // "color" is a gamma-encoded sRGB color
    // After calling this method, the color is stored as a pre-multiplied linear color
    // if linear blending is enabled.
    void setSRGB(uint32_t color) {
        a = ((color >> 24) & 0xff) / 255.0f;
        r = a * EOCF_sRGB(((color >> 16) & 0xff) / 255.0f);
        g = a * EOCF_sRGB(((color >>  8) & 0xff) / 255.0f);
+4 −4
Original line number Diff line number Diff line
@@ -289,10 +289,10 @@ void GlopBuilder::setFill(int color, float alphaScale,
            // Skia uses the range [0..255] for the addition vector, but we need
            // the [0..1] range to apply the vector in GLSL
            float* colorVector = mOutGlop->fill.filter.matrix.vector;
            colorVector[0] = EOCF_sRGB(srcColorMatrix[4]  / 255.0f);
            colorVector[1] = EOCF_sRGB(srcColorMatrix[9]  / 255.0f);
            colorVector[2] = EOCF_sRGB(srcColorMatrix[14] / 255.0f);
            colorVector[3] = EOCF_sRGB(srcColorMatrix[19] / 255.0f);
            colorVector[0] = EOCF(srcColorMatrix[4]  / 255.0f);
            colorVector[1] = EOCF(srcColorMatrix[9]  / 255.0f);
            colorVector[2] = EOCF(srcColorMatrix[14] / 255.0f);
            colorVector[3] =      srcColorMatrix[19] / 255.0f;  // alpha is linear
        } else {
            LOG_ALWAYS_FATAL("unsupported ColorFilter");
        }
+17 −11
Original line number Diff line number Diff line
@@ -185,22 +185,28 @@ size_t GradientCache::sourceBytesPerPixel() const {
    return 4 * (mUseFloatTexture ? sizeof(float) : sizeof(uint8_t));
}

void GradientCache::mixBytes(FloatColor& start, FloatColor& end, float amount,
        uint8_t*& dst) const {
void GradientCache::mixBytes(const FloatColor& start, const FloatColor& end,
        float amount, uint8_t*& dst) const {
    float oppAmount = 1.0f - amount;
    *dst++ = uint8_t(OECF_sRGB((start.r * oppAmount + end.r * amount) * 255.0f));
    *dst++ = uint8_t(OECF_sRGB((start.g * oppAmount + end.g * amount) * 255.0f));
    *dst++ = uint8_t(OECF_sRGB((start.b * oppAmount + end.b * amount) * 255.0f));
    *dst++ = uint8_t(OECF_sRGB(start.r * oppAmount + end.r * amount) * 255.0f);
    *dst++ = uint8_t(OECF_sRGB(start.g * oppAmount + end.g * amount) * 255.0f);
    *dst++ = uint8_t(OECF_sRGB(start.b * oppAmount + end.b * amount) * 255.0f);
    *dst++ = uint8_t(         (start.a * oppAmount + end.a * amount) * 255.0f);
}

void GradientCache::mixFloats(FloatColor& start, FloatColor& end, float amount,
        uint8_t*& dst) const {
void GradientCache::mixFloats(const FloatColor& start, const FloatColor& end,
        float amount, uint8_t*& dst) const {
    float oppAmount = 1.0f - amount;
    float* d = (float*) dst;
#if ANDROID_LINEAR_BLENDING_ENABLED
    *d++ = start.r * oppAmount + end.r * amount;
    *d++ = start.g * oppAmount + end.g * amount;
    *d++ = start.b * oppAmount + end.b * amount;
#else
    *d++ = OECF_sRGB(start.r * oppAmount + end.r * amount);
    *d++ = OECF_sRGB(start.g * oppAmount + end.g * amount);
    *d++ = OECF_sRGB(start.b * oppAmount + end.b * amount);
#endif
    *d++ = start.a * oppAmount + end.a * amount;
    dst += 4 * sizeof(float);
}
@@ -217,10 +223,10 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions,
    ChannelMixer mix = gMixers[mUseFloatTexture];

    FloatColor start;
    start.set(colors[0]);
    start.setSRGB(colors[0]);

    FloatColor end;
    end.set(colors[1]);
    end.setSRGB(colors[1]);

    int currentPos = 1;
    float startPos = positions[0];
@@ -235,7 +241,7 @@ void GradientCache::generateTexture(uint32_t* colors, float* positions,

            currentPos++;

            end.set(colors[currentPos]);
            end.setSRGB(colors[currentPos]);
            distance = positions[currentPos] - startPos;
        }

Loading