[RenderEngine] Cleanup Description.
Make Description a struct.
Minor: Use mat4 instead of mat3.
BUG: 112585051
Test: Build, flash and boot
Change-Id: I8f4b8ac1fd847239b42af9685ba0cddb15f0fac7
diff --git a/services/surfaceflinger/RenderEngine/Description.cpp b/services/surfaceflinger/RenderEngine/Description.cpp
index b7522da..9696d28 100644
--- a/services/surfaceflinger/RenderEngine/Description.cpp
+++ b/services/surfaceflinger/RenderEngine/Description.cpp
@@ -23,76 +23,33 @@
namespace android {
namespace renderengine {
-void Description::setPremultipliedAlpha(bool premultipliedAlpha) {
- mPremultipliedAlpha = premultipliedAlpha;
-}
-
-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;
+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;
+ }
}
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
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
index 0f0ff62..a7b9ddb 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.cpp
@@ -398,9 +398,9 @@
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 @@
}
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::setSourceY410BT2020(bool enable) {
- mState.setY410BT2020(enable);
+ mState.isY410BT2020 = enable;
}
void GLES20RenderEngine::setSourceDataSpace(Dataspace source) {
@@ -709,7 +709,7 @@
}
void GLES20RenderEngine::setDisplayMaxLuminance(const float maxLuminance) {
- mState.setDisplayMaxLuminance(maxLuminance);
+ mState.displayMaxLuminance = maxLuminance;
}
void GLES20RenderEngine::setupLayerTexturing(const Texture& texture) {
@@ -724,22 +724,24 @@
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::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 @@
// 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 @@
// - 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 @@
// - 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);
diff --git a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
index 1abc5ba..94a4bba 100644
--- a/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
+++ b/services/surfaceflinger/RenderEngine/gl/GLES20RenderEngine.h
@@ -131,9 +131,9 @@
mat4 mSrgbToDisplayP3;
mat4 mDisplayP3ToSrgb;
- mat3 mSrgbToXyz;
- mat3 mBt2020ToXyz;
- mat3 mDisplayP3ToXyz;
+ mat4 mSrgbToXyz;
+ mat4 mBt2020ToXyz;
+ mat4 mDisplayP3ToXyz;
mat4 mXyzToSrgb;
mat4 mXyzToDisplayP3;
mat4 mXyzToBt2020;
diff --git a/services/surfaceflinger/RenderEngine/gl/Program.cpp b/services/surfaceflinger/RenderEngine/gl/Program.cpp
index c8d6cf9..da67f92 100644
--- a/services/surfaceflinger/RenderEngine/gl/Program.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/Program.cpp
@@ -129,28 +129,28 @@
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
diff --git a/services/surfaceflinger/RenderEngine/gl/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/gl/ProgramCache.cpp
index a19c1f1..9254aa0 100644
--- a/services/surfaceflinger/RenderEngine/gl/ProgramCache.cpp
+++ b/services/surfaceflinger/RenderEngine/gl/ProgramCache.cpp
@@ -130,19 +130,19 @@
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 @@
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 @@
break;
}
- switch (description.mOutputTransferFunction) {
+ switch (description.outputTransferFunction) {
case Description::TransferFunction::LINEAR:
default:
needs.set(Key::OUTPUT_TF_MASK, Key::OUTPUT_TF_LINEAR);
diff --git a/services/surfaceflinger/RenderEngine/gl/ProgramCache.h b/services/surfaceflinger/RenderEngine/gl/ProgramCache.h
index ea77a2d..47963eb 100644
--- a/services/surfaceflinger/RenderEngine/gl/ProgramCache.h
+++ b/services/surfaceflinger/RenderEngine/gl/ProgramCache.h
@@ -29,7 +29,7 @@
namespace renderengine {
-class Description;
+struct Description;
namespace gl {
diff --git a/services/surfaceflinger/RenderEngine/include/renderengine/private/Description.h b/services/surfaceflinger/RenderEngine/include/renderengine/private/Description.h
index a6301ae..efab8ff 100644
--- a/services/surfaceflinger/RenderEngine/include/renderengine/private/Description.h
+++ b/services/surfaceflinger/RenderEngine/include/renderengine/private/Description.h
@@ -17,84 +17,60 @@
#ifndef SF_RENDER_ENGINE_DESCRIPTION_H_
#define SF_RENDER_ENGINE_DESCRIPTION_H_
+#include <ui/GraphicTypes.h>
#include <renderengine/Texture.h>
namespace android {
namespace renderengine {
-namespace gl {
-class Program;
-class ProgramCache;
-}
-
/*
- * This holds the state of the rendering engine. This class is used
- * to generate a corresponding GLSL program and set the appropriate
- * uniform.
- *
- * Program and ProgramCache are friends and access the state directly
+ * This is the structure that holds the state of the rendering engine.
+ * This class is used to generate a corresponding GLSL program and set the
+ * appropriate uniform.
*/
-class Description {
-public:
- Description() = default;
- ~Description() = default;
-
- void setPremultipliedAlpha(bool premultipliedAlpha);
- void setOpaque(bool opaque);
- void setTexture(const Texture& texture);
- void disableTexture();
- void setColor(const half4& color);
- void setProjectionMatrix(const mat4& mtx);
- void setColorMatrix(const mat4& mtx);
- void setInputTransformMatrix(const mat3& matrix);
- void setOutputTransformMatrix(const mat4& matrix);
- bool hasInputTransformMatrix() const;
- bool hasOutputTransformMatrix() const;
- bool hasColorMatrix() const;
- const mat4& getColorMatrix() const;
-
- void setY410BT2020(bool enable);
-
+struct Description {
enum class TransferFunction : int {
LINEAR,
SRGB,
ST2084,
HLG, // Hybrid Log-Gamma for HDR.
};
- void setInputTransferFunction(TransferFunction transferFunction);
- void setOutputTransferFunction(TransferFunction transferFunction);
- void setDisplayMaxLuminance(const float maxLuminance);
-private:
- friend class gl::Program;
- friend class gl::ProgramCache;
+ static TransferFunction dataSpaceToTransferFunction(ui::Dataspace dataSpace);
+
+ Description() = default;
+ ~Description() = default;
+
+ bool hasInputTransformMatrix() const;
+ bool hasOutputTransformMatrix() const;
+ bool hasColorMatrix() const;
// whether textures are premultiplied
- bool mPremultipliedAlpha = false;
+ bool isPremultipliedAlpha = false;
// whether this layer is marked as opaque
- bool mOpaque = true;
+ bool isOpaque = true;
// Texture this layer uses
- Texture mTexture;
- bool mTextureEnabled = false;
+ Texture texture;
+ bool textureEnabled = false;
// color used when texturing is disabled or when setting alpha.
- half4 mColor;
+ half4 color;
// true if the sampled pixel values are in Y410/BT2020 rather than RGBA
- bool mY410BT2020 = false;
+ bool isY410BT2020 = false;
// transfer functions for the input/output
- TransferFunction mInputTransferFunction = TransferFunction::LINEAR;
- TransferFunction mOutputTransferFunction = TransferFunction::LINEAR;
+ TransferFunction inputTransferFunction = TransferFunction::LINEAR;
+ TransferFunction outputTransferFunction = TransferFunction::LINEAR;
- float mDisplayMaxLuminance;
+ float displayMaxLuminance;
// projection matrix
- mat4 mProjectionMatrix;
- mat4 mColorMatrix;
- mat3 mInputTransformMatrix;
- mat4 mOutputTransformMatrix;
+ mat4 projectionMatrix;
+ mat4 colorMatrix;
+ mat4 inputTransformMatrix;
+ mat4 outputTransformMatrix;
};
} // namespace renderengine