History log of /frameworks/base/libs/hwui/GradientCache.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
669b15a93548b82135c73196665bcb7f03d87795 31-Mar-2017 Derek Sollenberger <djsollen@google.com> Fix HWUI/Skia Gradients to premultiply the colors prior to interpolation

This is fixed in Skia by passing the appropriate flag when the shader is
generated. The fix in HWUI is to reverse the premultiplication and
interpolation steps.

Test: bit CtsUiRenderingTestCases:.testclasses.ShaderTests
Bug: 34323783
Change-Id: I3417141949f62fcc696b6d8213a4b446d7d0cbf8
6183c97e5f317ad52ad16fe50e40129e2c7b2150 16-Mar-2017 Romain Guy <romainguy@google.com> Bowing my head in shame, going back to gamma interpolated gradients

Frankengradients (linearly interpolated RGB, gamma interpolated alpha) look
fantastic but unfortunately create sligh compatibility issues. For instance,
a gradient from 0xffea1030 to 0x00ea1030 (opaque to alpha, with a single
color) blended on top of 0xff101010 would not look the same as a single
opaque gradient from 0xffea1030 to 0xff101010. The difference is hardly
noticeable on simple gradients but it could cause confusion amongst app
developers. Their life is hard enough as it is, let's be good to them.

My crusade against the gamma world is not over and one day I shall
be the victor. I am patience.

Bug: 35485208
Test: UiRendering.ShaderTests, UiRendering.GradientTests, manual testing
Change-Id: I8204e60cdf0a6b12dfe22638d30ca9622687000e
efb4b06493fe7b1604c762a448b13c7af2845a8d 27-Feb-2017 Romain Guy <romainguy@google.com> Add ColorSpace information on Bitmap

This is the first step toward interpreting color spaces at render time.

Bug: 32984164
Test: BitmapColorSpaceTest in CtsGraphicsTestCases

Change-Id: I0164a18f1ed74a745874fe5229168042afe27a04
9fe7e16399aa9739b63ce9add1d04fd8ef00678f 04-Feb-2017 Romain Guy <romainguy@google.com> Gradients are now an absurd Chimera

As of O, gradients are interpolated in linear space. This unfortunately
affects applications that were expecting a certain behavior for the
alpha ramp. This change attempts to get the best of both world: better
color interpolation (in linear space) and the old alpha interpolation
(in gamma space). This is achieved by applying the electro-optical
transfer function to the alpha channel; an idea so wrong it would
make any graphics programmer worth his salt weep in disgust.

As abhorrent this idea might be to me, it also acts as a faint
beacon of hope admist the unfathomable darkness that is Android's
color management.

And if you allow me another misguided metaphor, this change
represents the flotsam I can cling onto in the hope to one day
reach the bountiful shores of linear blending and accurate color
management. Would this change not fix the distress caused by its
predecessors, I will have no choice but bow my head in shame until
the day I can finally devise an infallible plan.

Bug: 33010587
Test: CtsUiRenderingTestCases
Change-Id: I5397fefd7944413f2c820e613a5cba50579d4dd5
a0ed6f03f6f06eb41cbcc15c0a99b4a78fd91bef 13-Dec-2016 Romain Guy <romainguy@google.com> Pre-multiply gradient colors the right way

Alpha pre-multiplication must be done after applying the
opto-electronic transfer function when linear blending is
disabled. The correct way would be to pre-multiply before
gamma encoding but this leads to improper blending which
cannot be corrected without using sRGB frame buffers and
texture sampling.

Bug: 33010587
Test: cts-tradefed run singleCommand cts-dev --module CtsUiRenderingTestCases --test android.uirendering.cts.testclasses.GradientTests
Change-Id: I5f04bda4cb9f63674537aef5931621c14d601884
f9037dabea3ccf80b05ec1d66aeac13bee38b239 13-Oct-2016 Romain Guy <romainguy@google.com> Don't apply the OECF twice to multi-stop gradients

Test: Manual

Change-Id: Icd65d906df2f0a059373edb8c6d55fe378c92f92
8762e332e3797fb41929a1c6069207f4906ca329 12-Oct-2016 Romain Guy <romainguy@google.com> Various fixes for linear blending and gradients

With linear blending turned off some textures were still
created as sRGB textures instead of linear textures.
Multi-stop gradients were not behaving properly on devices
with no support for float textures.
Gradients are now always interpolated in linear space
even if linear blending is off.
New functions to always force sRGB->linear->sRGB conversions.

Test: Manual testing
Bug: 29940137
Change-Id: Ie2f84ee2a65fd85570e88af813e841e0e625df6c
253f2c213f6ecda63b6872aee77bd30d5ec07c82 29-Sep-2016 Romain Guy <romainguy@google.com> Linear blending, step 1

NOTE: Linear blending is currently disabled in this CL as the
feature is still a work in progress

Android currently performs all blending (any kind of linear math
on colors really) on gamma-encoded colors. Since Android assumes
that the default color space is sRGB, all bitmaps and colors
are encoded with the sRGB Opto-Electronic Conversion Function
(OECF, which can be approximated with a power function). Since
the power curve is not linear, our linear math is incorrect.
The result is that we generate colors that tend to be too dark;
this affects blending but also anti-aliasing, gradients, blurs,

The solution is to convert gamma-encoded colors back to linear
space before doing any math on them, using the sRGB Electo-Optical
Conversion Function (EOCF). This is achieved in different
ways in different parts of the pipeline:

- Using hardware conversions when sampling from OpenGL textures
or writing into OpenGL frame buffers
- Using software conversion functions, to translate app-supplied
colors to and from sRGB
- Using Skia's color spaces

Any type of processing on colors must roughly ollow these steps:

[sRGB input]->EOCF->[linear data]->[processing]->OECF->[sRGB output]

For the sRGB color space, the conversion functions are defined as

OECF(linear) :=
linear <= 0.0031308 ? linear * 12.92 : (pow(linear, 1/2.4) * 1.055) - 0.055

EOCF(srgb) :=
srgb <= 0.04045 ? srgb / 12.92 : pow((srgb + 0.055) / 1.055, 2.4)

The EOCF is simply the reciprocal of the OECF.
While it is highly recommended to use the exact sRGB conversion
functions everywhere possible, it is sometimes useful or beneficial
to rely on approximations:

- pow(x,2.2) and pow(x,1/2.2)
- x^2 and sqrt(x)

The latter is particularly useful in fragment shaders (for instance
to apply dithering in sRGB space), especially if the sqrt() can be
replaced with an inversesqrt().

Here is a fairly exhaustive list of modifications implemented
in this CL:

- Set TARGET_ENABLE_LINEAR_BLENDING := false in BoardConfig.mk
to disable linear blending. This is only for GLES 2.0 GPUs
with no hardware sRGB support. This flag is currently assumed
to be false (see note above)
- sRGB writes are disabled when entering a functor (WebView).
This will need to be fixed at some point
- Skia bitmaps are created with the sRGB color space
- Bitmaps using a 565 config are expanded to 888
- Linear blending is disabled when entering a functor
- External textures are not properly sampled (see below)
- Gradients are interpolated in linear space
- Texture-based dithering was replaced with analytical dithering
- Dithering is done in the quantization color space, which is
why we must do EOCF(OECF(color)+dither)
- Text is now gamma corrected differently depending on the luminance
of the source pixel. The asumption is that a bright pixel will be
blended on a dark background and the other way around. The source
alpha is gamma corrected to thicken dark on bright and thin
bright on dark to match the intended design of fonts. This also
matches the behavior of popular design/drawing applications
- Removed the asset atlas. It did not contain anything useful and
could not be sampled in sRGB without a yet-to-be-defined GL
- The last column of color matrices is converted to linear space
because its value are added to linear colors

Missing features:
- Resource qualifier?
- Regeneration of goldeng images for automated tests
- Handle alpha8/grey8 properly
- Disable sRGB write for layers with external textures

Test: Manual testing while work in progress
Bug: 29940137

Change-Id: I6a07b15ab49b554377cd33a36b6d9971a15e9a0b
d61fd4ede537695d6f7c340aae365095e5bade4d 11-Feb-2016 John Reck <jreck@google.com> Fix build

Change-Id: Id793d3a824902ab794b5d5a4cdf4c77a72c52add
1d4e6a0901e5d26f4319ed173b4aa7b907350d93 11-Feb-2016 John Reck <jreck@google.com> Fix bpp mismatch

Bug: 26980851

GL_RGBA16F was being incorrectly calculated
as 4 bpp instead of 16 in Texture's objectSize(),
leading to a mismatch in cache size tracking
in GradientCache

Change-Id: I533c52fcdf9910d7a7d14bbd80965b8cbef8e147
807842acfacbc12a6ef0234e20ef3f91e669c06f 06-Feb-2016 Chris Craik <ccraik@google.com> Merge "Move several property queries to Properties class"
48a8f431fa52ae2ee25ffba9d20676f03bb710ff 06-Feb-2016 Chris Craik <ccraik@google.com> Move several property queries to Properties class


This removes a lot of redundant property query code, and puts the
queries all in one place, so defining them automatically will be simpler
in the future.

Change-Id: I0428550e6081f07bc6554ffdf73b22284325abb8
83c9b5bf638d75a3395f57c2c57c31c959632f9d 05-Feb-2016 John Reck <jreck@google.com> Add a debug assert to track down infinite loop

Bug: 26980851
Change-Id: I326983ab367782048311b6cf06d800f72837e38e
2de7771740ee08fcaff638ec6b2e460bb72fff04 20-Jan-2016 John Reck <jreck@google.com> Normalize GL_UNPACK_ALIGNMENT

Several places were setting GL_UNPACK_ALIGNMENT
unneccessarily, whereas other places were assuming an
unpack alignment of 1. Since we never actually
do explicit row-alignment, set GL_UNPACK_ALIGNMENT
to 1 at context creation time and never change it

Bug: 26584230

Also turns on aggressive glGetError checking to
better catch potential problem zones

Change-Id: I190c8f0f0494a7f046d5ed769405c75d363be59a
9372ac3621848085e77b867f220c0b5ffce4010d 19-Jan-2016 John Reck <jreck@google.com> Fix ordering of texture->upload arguments

Caught by scatter-shotting GL_CHECKPOINTS which
seem generally useful to have

Bug: 26609444

Change-Id: Ie31d9297d8dae56405126720f338b4256c8bae77
38e0c32852e3b9d8ca4a9d3791577f52536419cb 10-Nov-2015 John Reck <jreck@google.com> Track texture memory globally

Also mostly consolidates texture creation

Change-Id: Ifea01303afda531dcec99b8fe2a0f64cf2f24420
6b50780363d3bb8db600c770183fa07677509ae8 03-Nov-2015 John Reck <jreck@google.com> Remove almost-all android::Singleton users

Bug: 25426213
Change-Id: I88e6206e8915cce95c3a8a8a82a4bb8fbf668141
5a4690bf26932c0d6940e4af8516d920e09ae81a 14-Jul-2015 Chris Craik <ccraik@google.com> Clean up unncessary defines

LOG_TAG and TRACE_TAG are already defined in the makefile

Change-Id: I9e53e3dacbe018441edd74cb7c8c90846defee74
8e93a7c9377b4ae43ecfb408f4906a09f6c83c03 23-Feb-2015 Chris Craik <ccraik@google.com> Simplify Texture member initialization

Change-Id: Iaaa6dd20e64a0a075d732b101e3c4278cad44047
117bdbcfa3e8306dad21e7e01fa71b00cdfa7265 05-Feb-2015 Chris Craik <ccraik@google.com> Glop ColorFilter & VertexBuffer support, initial enable

Enables Glop rendering for supported Rects and VertexBuffers
Also removes unused Query object

Change-Id: Ibe227bc362685a153159f75077664f0947764e06
44eb2c00861098dd3e2950d923646814b4cc57c2 29-Jan-2015 Chris Craik <ccraik@google.com> Refactor blending and texture gl state

Change-Id: Ia6b3c8b2afd3dfcee7f3ce401d846b789612054a
d41c4d8c732095ae99c955b6b82f7306633004b1 06-Jan-2015 Chris Craik <ccraik@google.com> Add overrides and switch to nullptr keyword for all files

Adds remaining missing overrides and nullptr usages, missed due to
an extreme failure in tool usage.

Change-Id: I56abd72975a3999ad13330003c348db40f59aebf
51d6a3db97bdd5315f1a17a4b447d10a92217b98 23-Dec-2014 Chris Craik <ccraik@google.com> Cleanup various clang warnings, use unique_ptrs in several places

Change-Id: I347904b25e51fcc7de14b1e72f1acd0f6ba26f3f
e63f7c622a2086aefa80983c6f41b74fb166bb42 17-Oct-2013 Chris Craik <ccraik@google.com> Clean unused parameters, disable warnings

Change-Id: Iddb872f53075dd022eeef45265594d1c6a9e2bc0
7f4307668b10467ee39d41c7ea29cf1ff238a835 13-Jun-2013 Romain Guy <romainguy@google.com> Add new Query class for debugging

This class can be used to perform occlusion queries. An occlusion query
can be used to test whether an object is entirely hidden or not.

Change-Id: Ida456df81dbe008a64d3ff4cb7879340785c6abf
be1b127c7bec252e0c6ab0e06ed6babed07d496f 06-Jun-2013 Romain Guy <romainguy@google.com> Assume a texture is unbound after deleting it
Bug #9316260

The GL specification indicates that deleting a bound texture has
the side effect of binding the default texture (name=0). This change
replaces all calls to glDeleteTextures() by Caches::deleteTexture()
to properly keep track of texture bindings.

Change-Id: Ifbc60ef433e0f9776a668dd5bd5f0adbc65a77a0
8aa195d7081b889f3a7b1f426cbd8556377aae5e 05-Jun-2013 Romain Guy <romainguy@google.com> Introduce Caches::bindTexture() to reduce glBindTexture calls

Change-Id: Ic345422567c020c0a9035ff51dcf2ae2a1fc59f4
95aeff8f11968c8b29ae114bb5e1172c70cf7634 13-Apr-2013 Romain Guy <romainguy@google.com> Properly computer gradient textures width

Only on devices that do not have the npot extension

Change-Id: I472a13dc707d2abaf5fcc06f99c9da343b333558
b48800428906ae455c2b63acacd44e390e1fee49 05-Apr-2013 Romain Guy <romainguy@google.com> Use float textures to render gradients when possible

Float textures offer better precision for dithering.

In addition this change removes two uniforms from gradient shaders.
These uniforms were used to dither gradients but their value is
a build time constant. Instead we hardcode the value directly in
the shader source at compile time.

Change-Id: I05e9fd3eef93771843bbd91b453274452dfaefee
ca89e2a68703bd428e8b66547d033a6ed35b3595 09-Mar-2013 Romain Guy <romainguy@google.com> Precache paths from a worker thread

Change-Id: I3e7b53d67e0e03e403beaf55c39350ead7f1e309
3bbacf27c0be1bae4e4483577fc89ae3113abe5d 07-Feb-2013 Romain Guy <romainguy@google.com> Add a RenderBuffer object to store stencil buffers.
Bug #7146141

This change is needed to add a render buffer cache to avoid
creating and destroying stencil buffers on every frame.

This change also allows the renderer to use a 1 bit or 4 bit
stencil buffer whenever possible.

Finally this change fixes a bug introduced by a previous CL
which causes the stencil buffer to not be updated in certain
conditions. The fix relies on a new optional parameter in
drawColorRects() that can be used to avoid performing a
quickReject on rectangles generated by the clip region.

Change-Id: I2f55a8e807009887b276a83cde9f53fd5c01199f
15a65bfee5b0a98664eb5ebadad63c73e2c471f8 03-Jan-2013 Romain Guy <romainguy@google.com> Remove unnecessary & uninitialized variable
Bug #7728929

The uninitialized variable was taken into account to compute
the hash of gradient cache entries, thus causing cache corruptions
and sometimes infinite loops (it would also cause the cache to fill

Change-Id: Ic807a9bf901888b121a6a781a81dafc33075ed2a
059e12ccd20f5c249724a8362d6bac325334ea76 29-Nov-2012 Romain Guy <romainguy@google.com> Use LruCache instead of GenerationCache in libhwui

Change-Id: Ic26ddc7151eb5462bcd243b21daf7187ed6d3bec
a8557d2169e14997637f57bc897640c8882d4a46 01-Sep-2012 Mathias Agopian <mathias@google.com> Revert "Add more support for transformed clip rects and paths"

this introduced a dead lock in GradientCache's ctor.

This reverts commit dfe082f63e94cde9aee271c94d13de5e7217e036.

Bug: 7096001
Change-Id: I57b8bbab11fb7cb502fa58e3bbf5d19864db874f
dfe082f63e94cde9aee271c94d13de5e7217e036 01-Sep-2012 Romain Guy <romainguy@google.com> Add more support for transformed clip rects and paths

Change-Id: I41791b1e1bffef77d503dc9e52428395d2309688
d679b57ef279239cf11bb6c9bd14fb99b07971c9 30-Aug-2012 Romain Guy <romainguy@google.com> Pre-multiply color components for 2-stop gradients
Bug #7033344

Change-Id: Ia168501f1dc56ba7a1bb0c55078320432309a66a
320d46bf844b84351cb80c5d4a4768d86447ac81 09-Aug-2012 Romain Guy <romainguy@google.com> Reduce gradients textures size whenever possible

Change-Id: Ifd58625ee62edac3b5d20b77553cb98b6fa2b46e
42e1e0d482d774cf18a55773e434f02edb9e4462 30-Jul-2012 Romain Guy <romainguy@google.com> Improve gradients

Avoid using textures for common gradients (two stops from 0.0 to 1.0)

Change-Id: Iff55d21b126c8cfc4cfb701669f2339c8f6b131a
98ba89492a477114148fcb1f89675e41679ca7cc 21-Jul-2012 Romain Guy <romainguy@google.com> Make gradients look slightly better

Change-Id: Ib12c628a88b9ec6af1214ce6e5cb14cfde40485e
8dcfd5e836341b4a803b04d104a930bb312182d3 20-Jul-2012 Romain Guy <romainguy@google.com> Clamp gradient textures to max GL texture size

Change-Id: I8ce4e50988f5194fe5ce4bde7945ec01673af3cd
eb61cd8296ed7e3f3aef5bd430d846aa54d5d7e2 19-Jul-2012 Romain Guy <romainguy@google.com> Optimize gradient textures

Compute the size of the backing textures based on the maximum possible
number of shades in the gradient.

Change-Id: I2d7f20477d31b81e9735f2c1d83ebdd0dbcbe340
3762c311729fe9f3af085c14c5c1fb471d994c03 06-Jan-2012 Steve Block <steveblock@google.com> Rename (IF_)LOGE(_IF) to (IF_)ALOGE(_IF) DO NOT MERGE

See https://android-git.corp.google.com/g/#/c/157220

Bug: 5449033
Change-Id: Ic9c19d30693bd56755f55906127cd6bd7126096c
39d252a6632d057d5077f7eaf1b8ed7a142f3397 13-Dec-2011 Romain Guy <romainguy@google.com> Various OpenGL optimizations

Change-Id: Ib0742c96f10f5f50e7e5148b742c31b6c232d127
6203f6c8147069976342be8f42add797a50f9557 02-Aug-2011 Romain Guy <romainguy@google.com> Reduce the amount of data cached by the gradients cache.

Change-Id: I8546f5a5ecf38031c9a40bdcc434d4c7f22da63d
e3c26851dc315b730ea0fe5ef35bb1db81f6d675 26-Jul-2011 Romain Guy <romainguy@google.com> Improve rendering performance on some GPUs

This change sets textures filtering to GL_NEAREST by default. GL_LINEAR
filtering is only used when textures are transformed with a scale or
a rotation. This helps save a couple of fps on some GPUs.

Change-Id: I1efaa452c2c79905f00238e54d886a37203a2ac1
c9855a53edfac818dc68714557185977556f849d 22-Jan-2011 Romain Guy <romainguy@google.com> Log only 1 line per process when using OpenGLRenderer.

Change-Id: Idbdd6b84f31301e58ed53e0d50fd61fece192dfa
fe48f65922d4a3cc4aefe058cee5acec51504a20 12-Nov-2010 Romain Guy <romainguy@google.com> Free resources only from the GL context thread.
Bug #3179882

Resources were freed following garbage collections on a worker thread.
This worker thread had no EGL context, which would cause the renderer
to incorrectly assume that the memory was liberated.

Change-Id: Ifdb51f94ddf42641e8654522787bfac532976c7c
ee916f14cbd1fe1422c063ce2ef7b185e2bc5c6f 21-Sep-2010 Romain Guy <romainguy@google.com> Add support for SweepGradient in the GL renderer.

Change-Id: I7aa397ed4e34655ead9ba1f5b4ce087665e0f022
a2341a9f6addcd79723965ec5b1a1c5ae0f8bd65 09-Sep-2010 Romain Guy <romainguy@google.com> Purge Skia objects from GL caches as needed.

Change-Id: I754c671cf790ad5ae8bf047ad328034217da4ecc
fb8b763f762ae21923c58d64caa729b012f40e05 24-Aug-2010 Romain Guy <romainguy@google.com> Use only one GL context per process, share chaches.

Change-Id: Ieabaa25338d2f4b8d4fd90e7401ad6e7452eae11
9cccc2b9bdd4850a3f9679569aaec3ab98477a5d 08-Aug-2010 Romain Guy <romainguy@android.com> Enforce maximum texture size.

When an app tries to render a bitmap or path larger than the GPU's maximum
texture size, the drawing command is ignored and a warning is logged. This
change also makes texture drawing more robust by catching potential errors
during texture creation.

This change also fixes a crash in the FontRenderer. The destructor would
sometimes try to free an uninitialized array.

Change-Id: I95ae0939c52192d97b340aa02417bf6d0c962c57
c0ac193b9415680f0a69e20a3f5f22d16f8053be 20-Jul-2010 Romain Guy <romainguy@google.com> Add support for linear gradients.

Change-Id: Id15329da065045b3f06fdaed615f33cd57608496