summaryrefslogtreecommitdiff
path: root/libs/hwui/Program.h
diff options
context:
space:
mode:
author Romain Guy <romainguy@google.com> 2017-03-27 00:40:21 -0700
committer Romain Guy <romainguy@google.com> 2017-03-28 18:35:49 -0700
commitcaaaa66e57293e4a6f312649bf472eab84d5c7fe (patch)
tree66beeca493da1046b482736293441a70f29474b3 /libs/hwui/Program.h
parentb7980a3bbee067eae4665c8abbe8d39aefb2d36a (diff)
Convert bitmaps to sRGB/scRGB when they have a color profile
This change also fixes an issue with RGBA16F bitmaps when modulated with a color (for instance by setting an alpha on the Paint object). The color space conversion is currently done entirely in the shader, by doing these operations in order: 1. Sample the texture 2. Un-premultiply alpha 3. Apply the EOTF 4. Multiply by the 3x3 color space matrix 5. Apply the OETF 6. Premultiply alpha Optimizations: - Steps 2 & 6 are skipped for opaque (common) bitmaps - Step 3 is skipped when the color space's EOTF is close to sRGB (Display P3 for instance). Instead, we use a hardware sRGB fetch (when the GPU supports it) - When step 3 is necessary, we use one of four standard EOTF implementations, to save cycles when possible: + Linear (doesn't do anything) + Full parametric (ICC parametric curve type 4 as defined in ICC.1:2004-10, section 10.15) + Limited parametric (ICC parametric curve type 3) + Gamma (ICC parametric curve type 0) Color space conversion could be done using texture samplers instead, for instance 3D LUTs, with or without transfer functions baked in, or 1D LUTs for transfer functions. This would result in dependent texture fetches which may or may not be an advantage over an ALU based implementation. The current solution favor the use of ALUs to save precious bandwidth. Test: CtsUiRenderingTests, CtsGraphicsTests Bug: 32984164 Change-Id: I10bc3db515e13973b45220f129c66b23f0f7f8fe
Diffstat (limited to 'libs/hwui/Program.h')
-rw-r--r--libs/hwui/Program.h53
1 files changed, 35 insertions, 18 deletions
diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h
index 5c8f8e93fa3d..2becfcb709c3 100644
--- a/libs/hwui/Program.h
+++ b/libs/hwui/Program.h
@@ -28,6 +28,7 @@
#include "FloatColor.h"
#include "Matrix.h"
#include "Properties.h"
+#include "utils/Color.h"
namespace android {
namespace uirenderer {
@@ -56,11 +57,11 @@ namespace uirenderer {
#define PROGRAM_KEY_BITMAP_NPOT 0x80
#define PROGRAM_KEY_BITMAP_EXTERNAL 0x100
-#define PROGRAM_KEY_SWAP_SRC_DST 0x2000
-
#define PROGRAM_KEY_BITMAP_WRAPS_MASK 0x600
#define PROGRAM_KEY_BITMAP_WRAPT_MASK 0x1800
+#define PROGRAM_KEY_SWAP_SRC_DST_SHIFT 13
+
// Encode the xfermodes on 6 bits
#define PROGRAM_MAX_XFERMODE 0x1f
#define PROGRAM_XFERMODE_SHADER_SHIFT 26
@@ -89,6 +90,10 @@ namespace uirenderer {
#define PROGRAM_HAS_GAMMA_CORRECTION 44
#define PROGRAM_HAS_LINEAR_TEXTURE 45
+#define PROGRAM_HAS_COLOR_SPACE_CONVERSION 46
+#define PROGRAM_TRANSFER_FUNCTION 47 // 2 bits for transfer function
+#define PROGRAM_HAS_TRANSLUCENT_CONVERSION 49
+
///////////////////////////////////////////////////////////////////////////////
// Types
///////////////////////////////////////////////////////////////////////////////
@@ -105,13 +110,13 @@ typedef uint64_t programid;
* A ProgramDescription must be used in conjunction with a ProgramCache.
*/
struct ProgramDescription {
- enum class ColorFilterMode {
+ enum class ColorFilterMode : int8_t {
None = 0,
Matrix,
Blend
};
- enum Gradient {
+ enum Gradient : int8_t {
kGradientLinear = 0,
kGradientCircular,
kGradientSweep
@@ -168,6 +173,11 @@ struct ProgramDescription {
// Set when sampling an image in linear space
bool hasLinearTexture;
+ bool hasColorSpaceConversion;
+ TransferFunctionType transferFunction;
+ // Indicates whether the bitmap to convert between color spaces is translucent
+ bool hasTranslucentConversion;
+
/**
* Resets this description. All fields are reset back to the default
* values they hold after building a new instance.
@@ -210,6 +220,10 @@ struct ProgramDescription {
hasGammaCorrection = false;
hasLinearTexture = false;
+
+ hasColorSpaceConversion = false;
+ transferFunction = TransferFunctionType::None;
+ hasTranslucentConversion = false;
}
/**
@@ -263,24 +277,27 @@ struct ProgramDescription {
break;
case ColorFilterMode::Blend:
key |= PROGRAM_KEY_COLOR_BLEND;
- key |= ((int)colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT;
+ key |= ((int) colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT;
break;
case ColorFilterMode::None:
break;
}
- key |= ((int)framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT;
- if (swapSrcDst) key |= PROGRAM_KEY_SWAP_SRC_DST;
- if (modulate) key |= programid(0x1) << PROGRAM_MODULATE_SHIFT;
- if (hasVertexAlpha) key |= programid(0x1) << PROGRAM_HAS_VERTEX_ALPHA_SHIFT;
- if (useShadowAlphaInterp) key |= programid(0x1) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT;
- if (hasExternalTexture) key |= programid(0x1) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
- if (hasTextureTransform) key |= programid(0x1) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
- if (isSimpleGradient) key |= programid(0x1) << PROGRAM_IS_SIMPLE_GRADIENT;
- if (hasColors) key |= programid(0x1) << PROGRAM_HAS_COLORS;
- if (hasDebugHighlight) key |= programid(0x1) << PROGRAM_HAS_DEBUG_HIGHLIGHT;
- if (hasRoundRectClip) key |= programid(0x1) << PROGRAM_HAS_ROUND_RECT_CLIP;
- if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION;
- if (hasLinearTexture) key |= programid(0x1) << PROGRAM_HAS_LINEAR_TEXTURE;
+ key |= ((int) framebufferMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT;
+ key |= programid(swapSrcDst) << PROGRAM_KEY_SWAP_SRC_DST_SHIFT;
+ key |= programid(modulate) << PROGRAM_MODULATE_SHIFT;
+ key |= programid(hasVertexAlpha) << PROGRAM_HAS_VERTEX_ALPHA_SHIFT;
+ key |= programid(useShadowAlphaInterp) << PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT;
+ key |= programid(hasExternalTexture) << PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT;
+ key |= programid(hasTextureTransform) << PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT;
+ key |= programid(isSimpleGradient) << PROGRAM_IS_SIMPLE_GRADIENT;
+ key |= programid(hasColors) << PROGRAM_HAS_COLORS;
+ key |= programid(hasDebugHighlight) << PROGRAM_HAS_DEBUG_HIGHLIGHT;
+ key |= programid(hasRoundRectClip) << PROGRAM_HAS_ROUND_RECT_CLIP;
+ key |= programid(hasGammaCorrection) << PROGRAM_HAS_GAMMA_CORRECTION;
+ key |= programid(hasLinearTexture) << PROGRAM_HAS_LINEAR_TEXTURE;
+ key |= programid(hasColorSpaceConversion) << PROGRAM_HAS_COLOR_SPACE_CONVERSION;
+ key |= programid(transferFunction) << PROGRAM_TRANSFER_FUNCTION;
+ key |= programid(hasTranslucentConversion) << PROGRAM_HAS_TRANSLUCENT_CONVERSION;
return key;
}