OSDN Git Service

Convert bitmaps to sRGB/scRGB when they have a color profile
authorRomain Guy <romainguy@google.com>
Mon, 27 Mar 2017 07:40:21 +0000 (00:40 -0700)
committerRomain Guy <romainguy@google.com>
Wed, 29 Mar 2017 01:35:49 +0000 (18:35 -0700)
commitcaaaa66e57293e4a6f312649bf472eab84d5c7fe
tree66beeca493da1046b482736293441a70f29474b3
parentb7980a3bbee067eae4665c8abbe8d39aefb2d36a
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
12 files changed:
libs/hwui/Android.mk
libs/hwui/GlLayer.h
libs/hwui/GlopBuilder.cpp
libs/hwui/Program.h
libs/hwui/ProgramCache.cpp
libs/hwui/SkiaShader.cpp
libs/hwui/Texture.cpp
libs/hwui/Texture.h
libs/hwui/hwui/Bitmap.cpp
libs/hwui/renderstate/RenderState.cpp
libs/hwui/utils/Color.cpp [new file with mode: 0644]
libs/hwui/utils/Color.h