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

Commit 70b26cee authored by Peiyong Lin's avatar Peiyong Lin
Browse files

[RenderEngine] Cleanup Description.

Make Description a struct.

Minor: Use mat4 instead of mat3.

BUG: 112585051
Test: Build, flash and boot
Change-Id: I8f4b8ac1fd847239b42af9685ba0cddb15f0fac7
parent 4298ea30
Loading
Loading
Loading
Loading
+16 −59
Original line number Diff line number Diff line
@@ -23,76 +23,33 @@
namespace android {
namespace renderengine {

void Description::setPremultipliedAlpha(bool premultipliedAlpha) {
    mPremultipliedAlpha = premultipliedAlpha;
Description::TransferFunction Description::dataSpaceToTransferFunction(ui::Dataspace dataSpace) {
    ui::Dataspace transfer = static_cast<ui::Dataspace>(dataSpace & ui::Dataspace::TRANSFER_MASK);
    switch (transfer) {
        case ui::Dataspace::TRANSFER_ST2084:
            return Description::TransferFunction::ST2084;
        case ui::Dataspace::TRANSFER_HLG:
            return Description::TransferFunction::HLG;
        case ui::Dataspace::TRANSFER_LINEAR:
            return Description::TransferFunction::LINEAR;
        default:
            return Description::TransferFunction::SRGB;
    }

void Description::setOpaque(bool opaque) {
    mOpaque = opaque;
}

void Description::setTexture(const Texture& texture) {
    mTexture = texture;
    mTextureEnabled = true;
}

void Description::disableTexture() {
    mTextureEnabled = false;
}

void Description::setColor(const half4& color) {
    mColor = color;
}

void Description::setProjectionMatrix(const mat4& mtx) {
    mProjectionMatrix = mtx;
}

void Description::setColorMatrix(const mat4& mtx) {
    mColorMatrix = mtx;
}

void Description::setInputTransformMatrix(const mat3& matrix) {
    mInputTransformMatrix = matrix;
}

void Description::setOutputTransformMatrix(const mat4& matrix) {
    mOutputTransformMatrix = matrix;
}

bool Description::hasInputTransformMatrix() const {
    const mat3 identity;
    return mInputTransformMatrix != identity;
    const mat4 identity;
    return inputTransformMatrix != identity;
}

bool Description::hasOutputTransformMatrix() const {
    const mat4 identity;
    return mOutputTransformMatrix != identity;
    return outputTransformMatrix != identity;
}

bool Description::hasColorMatrix() const {
    const mat4 identity;
    return mColorMatrix != identity;
}

const mat4& Description::getColorMatrix() const {
    return mColorMatrix;
}

void Description::setY410BT2020(bool enable) {
    mY410BT2020 = enable;
}

void Description::setInputTransferFunction(TransferFunction transferFunction) {
    mInputTransferFunction = transferFunction;
}

void Description::setOutputTransferFunction(TransferFunction transferFunction) {
    mOutputTransferFunction = transferFunction;
}

void Description::setDisplayMaxLuminance(const float maxLuminance) {
    mDisplayMaxLuminance = maxLuminance;
    return colorMatrix != identity;
}

}  // namespace renderengine
+32 −52
Original line number Diff line number Diff line
@@ -398,9 +398,9 @@ GLES20RenderEngine::GLES20RenderEngine(uint32_t featureFlags)
        mDisplayP3ToSrgb = mat4(ColorSpaceConnector(displayP3, srgb).getTransform());

        // no chromatic adaptation needed since all color spaces use D65 for their white points.
        mSrgbToXyz = srgb.getRGBtoXYZ();
        mDisplayP3ToXyz = displayP3.getRGBtoXYZ();
        mBt2020ToXyz = bt2020.getRGBtoXYZ();
        mSrgbToXyz = mat4(srgb.getRGBtoXYZ());
        mDisplayP3ToXyz = mat4(displayP3.getRGBtoXYZ());
        mBt2020ToXyz = mat4(bt2020.getRGBtoXYZ());
        mXyzToSrgb = mat4(srgb.getXYZtoRGB());
        mXyzToDisplayP3 = mat4(displayP3.getXYZtoRGB());
        mXyzToBt2020 = mat4(bt2020.getXYZtoRGB());
@@ -673,19 +673,19 @@ void GLES20RenderEngine::setViewportAndProjection(size_t vpw, size_t vph, Rect s
    }

    glViewport(0, 0, vpw, vph);
    mState.setProjectionMatrix(m);
    mState.projectionMatrix = m;
    mVpWidth = vpw;
    mVpHeight = vph;
}

void GLES20RenderEngine::setupLayerBlending(bool premultipliedAlpha, bool opaque,
                                            bool disableTexture, const half4& color) {
    mState.setPremultipliedAlpha(premultipliedAlpha);
    mState.setOpaque(opaque);
    mState.setColor(color);
    mState.isPremultipliedAlpha = premultipliedAlpha;
    mState.isOpaque = opaque;
    mState.color = color;

    if (disableTexture) {
        mState.disableTexture();
        mState.textureEnabled = false;
    }

    if (color.a < 1.0f || !opaque) {
@@ -697,7 +697,7 @@ void GLES20RenderEngine::setupLayerBlending(bool premultipliedAlpha, bool opaque
}

void GLES20RenderEngine::setSourceY410BT2020(bool enable) {
    mState.setY410BT2020(enable);
    mState.isY410BT2020 = enable;
}

void GLES20RenderEngine::setSourceDataSpace(Dataspace source) {
@@ -709,7 +709,7 @@ void GLES20RenderEngine::setOutputDataSpace(Dataspace dataspace) {
}

void GLES20RenderEngine::setDisplayMaxLuminance(const float maxLuminance) {
    mState.setDisplayMaxLuminance(maxLuminance);
    mState.displayMaxLuminance = maxLuminance;
}

void GLES20RenderEngine::setupLayerTexturing(const Texture& texture) {
@@ -724,22 +724,24 @@ void GLES20RenderEngine::setupLayerTexturing(const Texture& texture) {
    glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
    glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);

    mState.setTexture(texture);
    mState.texture = texture;
    mState.textureEnabled = true;
}

void GLES20RenderEngine::setupLayerBlackedOut() {
    glBindTexture(GL_TEXTURE_2D, mProtectedTexName);
    Texture texture(Texture::TEXTURE_2D, mProtectedTexName);
    texture.setDimensions(1, 1); // FIXME: we should get that from somewhere
    mState.setTexture(texture);
    mState.texture = texture;
    mState.textureEnabled = true;
}

void GLES20RenderEngine::setupColorTransform(const mat4& colorTransform) {
    mState.setColorMatrix(colorTransform);
    mState.colorMatrix = colorTransform;
}

void GLES20RenderEngine::disableTexturing() {
    mState.disableTexture();
    mState.textureEnabled = false;
}

void GLES20RenderEngine::disableBlending() {
@@ -747,10 +749,10 @@ void GLES20RenderEngine::disableBlending() {
}

void GLES20RenderEngine::setupFillWithColor(float r, float g, float b, float a) {
    mState.setPremultipliedAlpha(true);
    mState.setOpaque(false);
    mState.setColor(half4(r, g, b, a));
    mState.disableTexture();
    mState.isPremultipliedAlpha = true;
    mState.isOpaque = false;
    mState.color = half4(r, g, b, a);
    mState.textureEnabled = false;
    glDisable(GL_BLEND);
}

@@ -784,26 +786,26 @@ void GLES20RenderEngine::drawMesh(const Mesh& mesh) {
            // The supported input color spaces are standard RGB, Display P3 and BT2020.
            switch (inputStandard) {
                case Dataspace::STANDARD_DCI_P3:
                    managedState.setInputTransformMatrix(mDisplayP3ToXyz);
                    managedState.inputTransformMatrix = mDisplayP3ToXyz;
                    break;
                case Dataspace::STANDARD_BT2020:
                    managedState.setInputTransformMatrix(mBt2020ToXyz);
                    managedState.inputTransformMatrix = mBt2020ToXyz;
                    break;
                default:
                    managedState.setInputTransformMatrix(mSrgbToXyz);
                    managedState.inputTransformMatrix = mSrgbToXyz;
                    break;
            }

            // The supported output color spaces are BT2020, Display P3 and standard RGB.
            switch (outputStandard) {
                case Dataspace::STANDARD_BT2020:
                    managedState.setOutputTransformMatrix(mXyzToBt2020);
                    managedState.outputTransformMatrix = mXyzToBt2020;
                    break;
                case Dataspace::STANDARD_DCI_P3:
                    managedState.setOutputTransformMatrix(mXyzToDisplayP3);
                    managedState.outputTransformMatrix = mXyzToDisplayP3;
                    break;
                default:
                    managedState.setOutputTransformMatrix(mXyzToSrgb);
                    managedState.outputTransformMatrix = mXyzToSrgb;
                    break;
            }
        } else if (inputStandard != outputStandard) {
@@ -818,9 +820,9 @@ void GLES20RenderEngine::drawMesh(const Mesh& mesh) {
            // - sRGB
            // - Display P3
            if (outputStandard == Dataspace::STANDARD_BT709) {
                managedState.setOutputTransformMatrix(mDisplayP3ToSrgb);
                managedState.outputTransformMatrix = mDisplayP3ToSrgb;
            } else if (outputStandard == Dataspace::STANDARD_DCI_P3) {
                managedState.setOutputTransformMatrix(mSrgbToDisplayP3);
                managedState.outputTransformMatrix = mSrgbToDisplayP3;
            }
        }

@@ -830,32 +832,10 @@ void GLES20RenderEngine::drawMesh(const Mesh& mesh) {
        // - the input transfer function doesn't match the output transfer function.
        if (managedState.hasColorMatrix() || managedState.hasOutputTransformMatrix() ||
            inputTransfer != outputTransfer) {
            switch (inputTransfer) {
                case Dataspace::TRANSFER_ST2084:
                    managedState.setInputTransferFunction(Description::TransferFunction::ST2084);
                    break;
                case Dataspace::TRANSFER_HLG:
                    managedState.setInputTransferFunction(Description::TransferFunction::HLG);
                    break;
                case Dataspace::TRANSFER_LINEAR:
                    managedState.setInputTransferFunction(Description::TransferFunction::LINEAR);
                    break;
                default:
                    managedState.setInputTransferFunction(Description::TransferFunction::SRGB);
                    break;
            }

            switch (outputTransfer) {
                case Dataspace::TRANSFER_ST2084:
                    managedState.setOutputTransferFunction(Description::TransferFunction::ST2084);
                    break;
                case Dataspace::TRANSFER_HLG:
                    managedState.setOutputTransferFunction(Description::TransferFunction::HLG);
                    break;
                default:
                    managedState.setOutputTransferFunction(Description::TransferFunction::SRGB);
                    break;
            }
            managedState.inputTransferFunction =
                Description::dataSpaceToTransferFunction(inputTransfer);
            managedState.outputTransferFunction =
                Description::dataSpaceToTransferFunction(outputTransfer);
        }

        ProgramCache::getInstance().useProgram(managedState);
+3 −3
Original line number Diff line number Diff line
@@ -131,9 +131,9 @@ private:

    mat4 mSrgbToDisplayP3;
    mat4 mDisplayP3ToSrgb;
    mat3 mSrgbToXyz;
    mat3 mBt2020ToXyz;
    mat3 mDisplayP3ToXyz;
    mat4 mSrgbToXyz;
    mat4 mBt2020ToXyz;
    mat4 mDisplayP3ToXyz;
    mat4 mXyzToSrgb;
    mat4 mXyzToDisplayP3;
    mat4 mXyzToBt2020;
+6 −6
Original line number Diff line number Diff line
@@ -129,28 +129,28 @@ void Program::setUniforms(const Description& desc) {

    if (mSamplerLoc >= 0) {
        glUniform1i(mSamplerLoc, 0);
        glUniformMatrix4fv(mTextureMatrixLoc, 1, GL_FALSE, desc.mTexture.getMatrix().asArray());
        glUniformMatrix4fv(mTextureMatrixLoc, 1, GL_FALSE, desc.texture.getMatrix().asArray());
    }
    if (mColorLoc >= 0) {
        const float color[4] = {desc.mColor.r, desc.mColor.g, desc.mColor.b, desc.mColor.a};
        const float color[4] = {desc.color.r, desc.color.g, desc.color.b, desc.color.a};
        glUniform4fv(mColorLoc, 1, color);
    }
    if (mInputTransformMatrixLoc >= 0) {
        mat4 inputTransformMatrix = mat4(desc.mInputTransformMatrix);
        mat4 inputTransformMatrix = desc.inputTransformMatrix;
        glUniformMatrix4fv(mInputTransformMatrixLoc, 1, GL_FALSE, inputTransformMatrix.asArray());
    }
    if (mOutputTransformMatrixLoc >= 0) {
        // The output transform matrix and color matrix can be combined as one matrix
        // that is applied right before applying OETF.
        mat4 outputTransformMatrix = desc.mColorMatrix * desc.mOutputTransformMatrix;
        mat4 outputTransformMatrix = desc.colorMatrix * desc.outputTransformMatrix;
        glUniformMatrix4fv(mOutputTransformMatrixLoc, 1, GL_FALSE,
                           outputTransformMatrix.asArray());
    }
    if (mDisplayMaxLuminanceLoc >= 0) {
        glUniform1f(mDisplayMaxLuminanceLoc, desc.mDisplayMaxLuminance);
        glUniform1f(mDisplayMaxLuminanceLoc, desc.displayMaxLuminance) ;
    }
    // these uniforms are always present
    glUniformMatrix4fv(mProjectionMatrixLoc, 1, GL_FALSE, desc.mProjectionMatrix.asArray());
    glUniformMatrix4fv(mProjectionMatrixLoc, 1, GL_FALSE, desc.projectionMatrix.asArray());
}

}  // namespace gl
+9 −9
Original line number Diff line number Diff line
@@ -130,19 +130,19 @@ void ProgramCache::primeCache(bool useColorManagement) {
ProgramCache::Key ProgramCache::computeKey(const Description& description) {
    Key needs;
    needs.set(Key::TEXTURE_MASK,
              !description.mTextureEnabled
              !description.textureEnabled
                      ? Key::TEXTURE_OFF
                      : description.mTexture.getTextureTarget() == GL_TEXTURE_EXTERNAL_OES
                      : description.texture.getTextureTarget() == GL_TEXTURE_EXTERNAL_OES
                              ? Key::TEXTURE_EXT
                              : description.mTexture.getTextureTarget() == GL_TEXTURE_2D
                              : description.texture.getTextureTarget() == GL_TEXTURE_2D
                                      ? Key::TEXTURE_2D
                                      : Key::TEXTURE_OFF)
            .set(Key::ALPHA_MASK,
                 (description.mColor.a < 1) ? Key::ALPHA_LT_ONE : Key::ALPHA_EQ_ONE)
                 (description.color.a < 1) ? Key::ALPHA_LT_ONE : Key::ALPHA_EQ_ONE)
            .set(Key::BLEND_MASK,
                 description.mPremultipliedAlpha ? Key::BLEND_PREMULT : Key::BLEND_NORMAL)
                 description.isPremultipliedAlpha ? Key::BLEND_PREMULT : Key::BLEND_NORMAL)
            .set(Key::OPACITY_MASK,
                 description.mOpaque ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT)
                 description.isOpaque ? Key::OPACITY_OPAQUE : Key::OPACITY_TRANSLUCENT)
            .set(Key::Key::INPUT_TRANSFORM_MATRIX_MASK,
                 description.hasInputTransformMatrix() ?
                     Key::INPUT_TRANSFORM_MATRIX_ON : Key::INPUT_TRANSFORM_MATRIX_OFF)
@@ -151,10 +151,10 @@ ProgramCache::Key ProgramCache::computeKey(const Description& description) {
                     Key::OUTPUT_TRANSFORM_MATRIX_ON : Key::OUTPUT_TRANSFORM_MATRIX_OFF);

    needs.set(Key::Y410_BT2020_MASK,
              description.mY410BT2020 ? Key::Y410_BT2020_ON : Key::Y410_BT2020_OFF);
              description.isY410BT2020 ? Key::Y410_BT2020_ON : Key::Y410_BT2020_OFF);

    if (needs.hasTransformMatrix() || (needs.getInputTF() != needs.getOutputTF())) {
        switch (description.mInputTransferFunction) {
        switch (description.inputTransferFunction) {
            case Description::TransferFunction::LINEAR:
            default:
                needs.set(Key::INPUT_TF_MASK, Key::INPUT_TF_LINEAR);
@@ -170,7 +170,7 @@ ProgramCache::Key ProgramCache::computeKey(const Description& description) {
                break;
        }

        switch (description.mOutputTransferFunction) {
        switch (description.outputTransferFunction) {
            case Description::TransferFunction::LINEAR:
            default:
                needs.set(Key::OUTPUT_TF_MASK, Key::OUTPUT_TF_LINEAR);
Loading