2010-06-27 22:59:20 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#ifndef ANDROID_HWUI_PROGRAM_H
|
|
|
|
#define ANDROID_HWUI_PROGRAM_H
|
2010-06-27 22:59:20 -07:00
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
#include <utils/KeyedVector.h>
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
|
2016-10-28 17:21:45 -04:00
|
|
|
#include <SkBlendMode.h>
|
2010-06-27 22:59:20 -07:00
|
|
|
|
2013-03-01 11:08:11 -08:00
|
|
|
#include "Debug.h"
|
2015-02-11 13:17:06 -08:00
|
|
|
#include "FloatColor.h"
|
2010-07-09 18:53:25 -07:00
|
|
|
#include "Matrix.h"
|
2011-12-12 20:35:21 -08:00
|
|
|
#include "Properties.h"
|
2017-03-27 00:40:21 -07:00
|
|
|
#include "utils/Color.h"
|
2010-07-09 18:53:25 -07:00
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Defines
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Debug
|
|
|
|
#if DEBUG_PROGRAMS
|
2011-12-20 16:23:08 +00:00
|
|
|
#define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__)
|
2011-12-12 20:35:21 -08:00
|
|
|
#else
|
|
|
|
#define PROGRAM_LOGD(...)
|
|
|
|
#endif
|
|
|
|
|
2012-07-12 18:01:00 -07:00
|
|
|
#define COLOR_COMPONENT_THRESHOLD 1.0f
|
|
|
|
#define COLOR_COMPONENT_INV_THRESHOLD 0.0f
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2014-05-05 19:09:33 -07:00
|
|
|
#define PROGRAM_KEY_TEXTURE 0x01
|
|
|
|
#define PROGRAM_KEY_A8_TEXTURE 0x02
|
|
|
|
#define PROGRAM_KEY_BITMAP 0x04
|
|
|
|
#define PROGRAM_KEY_GRADIENT 0x08
|
|
|
|
#define PROGRAM_KEY_BITMAP_FIRST 0x10
|
|
|
|
#define PROGRAM_KEY_COLOR_MATRIX 0x20
|
|
|
|
#define PROGRAM_KEY_COLOR_BLEND 0x40
|
|
|
|
#define PROGRAM_KEY_BITMAP_NPOT 0x80
|
2016-12-12 16:14:11 -08:00
|
|
|
#define PROGRAM_KEY_BITMAP_EXTERNAL 0x100
|
2014-05-05 19:09:33 -07:00
|
|
|
|
|
|
|
#define PROGRAM_KEY_BITMAP_WRAPS_MASK 0x600
|
2011-12-12 20:35:21 -08:00
|
|
|
#define PROGRAM_KEY_BITMAP_WRAPT_MASK 0x1800
|
|
|
|
|
2017-03-27 00:40:21 -07:00
|
|
|
#define PROGRAM_KEY_SWAP_SRC_DST_SHIFT 13
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
// Encode the xfermodes on 6 bits
|
|
|
|
#define PROGRAM_MAX_XFERMODE 0x1f
|
|
|
|
#define PROGRAM_XFERMODE_SHADER_SHIFT 26
|
|
|
|
#define PROGRAM_XFERMODE_COLOR_OP_SHIFT 20
|
|
|
|
#define PROGRAM_XFERMODE_FRAMEBUFFER_SHIFT 14
|
|
|
|
|
|
|
|
#define PROGRAM_BITMAP_WRAPS_SHIFT 9
|
|
|
|
#define PROGRAM_BITMAP_WRAPT_SHIFT 11
|
|
|
|
|
2013-05-08 18:35:44 -07:00
|
|
|
#define PROGRAM_GRADIENT_TYPE_SHIFT 33 // 2 bits for gradient type
|
2011-12-12 20:35:21 -08:00
|
|
|
#define PROGRAM_MODULATE_SHIFT 35
|
|
|
|
|
2014-08-12 14:31:35 -07:00
|
|
|
#define PROGRAM_HAS_VERTEX_ALPHA_SHIFT 36
|
|
|
|
#define PROGRAM_USE_SHADOW_ALPHA_INTERP_SHIFT 37
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2014-08-11 16:00:44 -07:00
|
|
|
#define PROGRAM_HAS_EXTERNAL_TEXTURE_SHIFT 38
|
|
|
|
#define PROGRAM_HAS_TEXTURE_TRANSFORM_SHIFT 39
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2015-09-22 11:50:13 -07:00
|
|
|
#define PROGRAM_IS_SIMPLE_GRADIENT 40
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2015-09-22 11:50:13 -07:00
|
|
|
#define PROGRAM_HAS_COLORS 41
|
2012-07-16 17:04:24 -07:00
|
|
|
|
2015-09-22 11:50:13 -07:00
|
|
|
#define PROGRAM_HAS_DEBUG_HIGHLIGHT 42
|
|
|
|
#define PROGRAM_HAS_ROUND_RECT_CLIP 43
|
2013-02-25 14:15:37 -08:00
|
|
|
|
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,
etc.
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
follows:
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
extension
- 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
2016-09-28 17:34:42 -07:00
|
|
|
#define PROGRAM_HAS_GAMMA_CORRECTION 44
|
2017-02-07 11:21:05 -08:00
|
|
|
#define PROGRAM_HAS_LINEAR_TEXTURE 45
|
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,
etc.
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
follows:
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
extension
- 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
2016-09-28 17:34:42 -07:00
|
|
|
|
2017-03-27 00:40:21 -07:00
|
|
|
#define PROGRAM_HAS_COLOR_SPACE_CONVERSION 46
|
|
|
|
#define PROGRAM_TRANSFER_FUNCTION 47 // 2 bits for transfer function
|
|
|
|
#define PROGRAM_HAS_TRANSLUCENT_CONVERSION 49
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Types
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
typedef uint64_t programid;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Program description
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describe the features required for a given program. The features
|
|
|
|
* determine the generation of both the vertex and fragment shaders.
|
|
|
|
* A ProgramDescription must be used in conjunction with a ProgramCache.
|
|
|
|
*/
|
|
|
|
struct ProgramDescription {
|
2017-03-27 00:40:21 -07:00
|
|
|
enum class ColorFilterMode : int8_t {
|
2015-08-20 15:14:06 -07:00
|
|
|
None = 0,
|
|
|
|
Matrix,
|
|
|
|
Blend
|
2011-12-12 20:35:21 -08:00
|
|
|
};
|
|
|
|
|
2017-03-27 00:40:21 -07:00
|
|
|
enum Gradient : int8_t {
|
2012-07-30 14:47:51 -07:00
|
|
|
kGradientLinear = 0,
|
2011-12-12 20:35:21 -08:00
|
|
|
kGradientCircular,
|
|
|
|
kGradientSweep
|
|
|
|
};
|
|
|
|
|
|
|
|
ProgramDescription() {
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Texturing
|
|
|
|
bool hasTexture;
|
|
|
|
bool hasAlpha8Texture;
|
|
|
|
bool hasExternalTexture;
|
|
|
|
bool hasTextureTransform;
|
|
|
|
|
2013-02-13 18:39:43 -08:00
|
|
|
// Color attribute
|
|
|
|
bool hasColors;
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
// Modulate, this should only be set when setColor() return true
|
|
|
|
bool modulate;
|
|
|
|
|
|
|
|
// Shaders
|
|
|
|
bool hasBitmap;
|
2016-12-12 16:14:11 -08:00
|
|
|
bool isShaderBitmapExternal;
|
2016-11-15 18:01:21 -08:00
|
|
|
bool useShaderBasedWrap;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2014-08-12 14:31:35 -07:00
|
|
|
bool hasVertexAlpha;
|
|
|
|
bool useShadowAlphaInterp;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
bool hasGradient;
|
|
|
|
Gradient gradientType;
|
2012-07-30 14:47:51 -07:00
|
|
|
bool isSimpleGradient;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2016-10-28 17:21:45 -04:00
|
|
|
SkBlendMode shadersMode;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
bool isBitmapFirst;
|
|
|
|
GLenum bitmapWrapS;
|
|
|
|
GLenum bitmapWrapT;
|
|
|
|
|
|
|
|
// Color operations
|
2015-02-05 10:12:38 -08:00
|
|
|
ColorFilterMode colorOp;
|
2016-10-28 17:21:45 -04:00
|
|
|
SkBlendMode colorMode;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
// Framebuffer blending (requires Extensions.hasFramebufferFetch())
|
2016-10-28 17:21:45 -04:00
|
|
|
// Ignored for all values < SkBlendMode::kPlus
|
|
|
|
SkBlendMode framebufferMode;
|
2011-12-12 20:35:21 -08:00
|
|
|
bool swapSrcDst;
|
|
|
|
|
2013-02-25 14:15:37 -08:00
|
|
|
bool hasDebugHighlight;
|
2014-05-05 19:09:33 -07:00
|
|
|
bool hasRoundRectClip;
|
2013-02-25 14:15:37 -08:00
|
|
|
|
2017-02-07 11:21:05 -08:00
|
|
|
// Extra gamma correction used for text
|
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,
etc.
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
follows:
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
extension
- 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
2016-09-28 17:34:42 -07:00
|
|
|
bool hasGammaCorrection;
|
2017-02-07 11:21:05 -08:00
|
|
|
// Set when sampling an image in linear space
|
|
|
|
bool hasLinearTexture;
|
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,
etc.
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
follows:
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
extension
- 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
2016-09-28 17:34:42 -07:00
|
|
|
|
2017-03-27 00:40:21 -07:00
|
|
|
bool hasColorSpaceConversion;
|
|
|
|
TransferFunctionType transferFunction;
|
|
|
|
// Indicates whether the bitmap to convert between color spaces is translucent
|
|
|
|
bool hasTranslucentConversion;
|
|
|
|
|
2011-12-12 20:35:21 -08:00
|
|
|
/**
|
|
|
|
* Resets this description. All fields are reset back to the default
|
|
|
|
* values they hold after building a new instance.
|
|
|
|
*/
|
|
|
|
void reset() {
|
|
|
|
hasTexture = false;
|
|
|
|
hasAlpha8Texture = false;
|
|
|
|
hasExternalTexture = false;
|
|
|
|
hasTextureTransform = false;
|
|
|
|
|
2013-02-13 18:39:43 -08:00
|
|
|
hasColors = false;
|
|
|
|
|
2014-08-12 14:31:35 -07:00
|
|
|
hasVertexAlpha = false;
|
|
|
|
useShadowAlphaInterp = false;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
modulate = false;
|
|
|
|
|
|
|
|
hasBitmap = false;
|
2016-12-12 16:14:11 -08:00
|
|
|
isShaderBitmapExternal = false;
|
2016-11-15 18:01:21 -08:00
|
|
|
useShaderBasedWrap = false;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
hasGradient = false;
|
|
|
|
gradientType = kGradientLinear;
|
2012-07-30 14:47:51 -07:00
|
|
|
isSimpleGradient = false;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2016-10-28 17:21:45 -04:00
|
|
|
shadersMode = SkBlendMode::kClear;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
|
|
|
isBitmapFirst = false;
|
|
|
|
bitmapWrapS = GL_CLAMP_TO_EDGE;
|
|
|
|
bitmapWrapT = GL_CLAMP_TO_EDGE;
|
|
|
|
|
2015-08-20 15:14:06 -07:00
|
|
|
colorOp = ColorFilterMode::None;
|
2016-10-28 17:21:45 -04:00
|
|
|
colorMode = SkBlendMode::kClear;
|
2011-12-12 20:35:21 -08:00
|
|
|
|
2016-10-28 17:21:45 -04:00
|
|
|
framebufferMode = SkBlendMode::kClear;
|
2011-12-12 20:35:21 -08:00
|
|
|
swapSrcDst = false;
|
|
|
|
|
2013-02-25 14:15:37 -08:00
|
|
|
hasDebugHighlight = false;
|
2014-05-05 19:09:33 -07:00
|
|
|
hasRoundRectClip = false;
|
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,
etc.
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
follows:
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
extension
- 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
2016-09-28 17:34:42 -07:00
|
|
|
|
|
|
|
hasGammaCorrection = false;
|
2017-02-07 11:21:05 -08:00
|
|
|
hasLinearTexture = false;
|
2017-03-27 00:40:21 -07:00
|
|
|
|
|
|
|
hasColorSpaceConversion = false;
|
|
|
|
transferFunction = TransferFunctionType::None;
|
|
|
|
hasTranslucentConversion = false;
|
2011-12-12 20:35:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates, for a given color, whether color modulation is required in
|
|
|
|
* the fragment shader. When this method returns true, the program should
|
|
|
|
* be provided with a modulation color.
|
|
|
|
*/
|
2013-10-17 10:30:55 -07:00
|
|
|
bool setColorModulate(const float a) {
|
2012-09-13 20:31:08 -07:00
|
|
|
modulate = a < COLOR_COMPONENT_THRESHOLD;
|
2011-12-12 20:35:21 -08:00
|
|
|
return modulate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates, for a given color, whether color modulation is required in
|
|
|
|
* the fragment shader. When this method returns true, the program should
|
|
|
|
* be provided with a modulation color.
|
|
|
|
*/
|
2013-10-17 10:30:55 -07:00
|
|
|
bool setAlpha8ColorModulate(const float r, const float g, const float b, const float a) {
|
2011-12-12 20:35:21 -08:00
|
|
|
modulate = a < COLOR_COMPONENT_THRESHOLD || r > COLOR_COMPONENT_INV_THRESHOLD ||
|
|
|
|
g > COLOR_COMPONENT_INV_THRESHOLD || b > COLOR_COMPONENT_INV_THRESHOLD;
|
|
|
|
return modulate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the unique key identifying this program.
|
|
|
|
*/
|
|
|
|
programid key() const {
|
|
|
|
programid key = 0;
|
|
|
|
if (hasTexture) key |= PROGRAM_KEY_TEXTURE;
|
|
|
|
if (hasAlpha8Texture) key |= PROGRAM_KEY_A8_TEXTURE;
|
|
|
|
if (hasBitmap) {
|
|
|
|
key |= PROGRAM_KEY_BITMAP;
|
2016-11-15 18:01:21 -08:00
|
|
|
if (useShaderBasedWrap) {
|
2011-12-12 20:35:21 -08:00
|
|
|
key |= PROGRAM_KEY_BITMAP_NPOT;
|
|
|
|
key |= getEnumForWrap(bitmapWrapS) << PROGRAM_BITMAP_WRAPS_SHIFT;
|
|
|
|
key |= getEnumForWrap(bitmapWrapT) << PROGRAM_BITMAP_WRAPT_SHIFT;
|
|
|
|
}
|
2016-12-12 16:14:11 -08:00
|
|
|
if (isShaderBitmapExternal) {
|
|
|
|
key |= PROGRAM_KEY_BITMAP_EXTERNAL;
|
|
|
|
}
|
2011-12-12 20:35:21 -08:00
|
|
|
}
|
|
|
|
if (hasGradient) key |= PROGRAM_KEY_GRADIENT;
|
|
|
|
key |= programid(gradientType) << PROGRAM_GRADIENT_TYPE_SHIFT;
|
|
|
|
if (isBitmapFirst) key |= PROGRAM_KEY_BITMAP_FIRST;
|
|
|
|
if (hasBitmap && hasGradient) {
|
2016-10-28 17:21:45 -04:00
|
|
|
key |= ((int)shadersMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_SHADER_SHIFT;
|
2011-12-12 20:35:21 -08:00
|
|
|
}
|
|
|
|
switch (colorOp) {
|
2015-08-20 15:14:06 -07:00
|
|
|
case ColorFilterMode::Matrix:
|
2011-12-12 20:35:21 -08:00
|
|
|
key |= PROGRAM_KEY_COLOR_MATRIX;
|
|
|
|
break;
|
2015-08-20 15:14:06 -07:00
|
|
|
case ColorFilterMode::Blend:
|
2011-12-12 20:35:21 -08:00
|
|
|
key |= PROGRAM_KEY_COLOR_BLEND;
|
2017-03-27 00:40:21 -07:00
|
|
|
key |= ((int) colorMode & PROGRAM_MAX_XFERMODE) << PROGRAM_XFERMODE_COLOR_OP_SHIFT;
|
2011-12-12 20:35:21 -08:00
|
|
|
break;
|
2015-08-20 15:14:06 -07:00
|
|
|
case ColorFilterMode::None:
|
2011-12-12 20:35:21 -08:00
|
|
|
break;
|
|
|
|
}
|
2017-03-27 00:40:21 -07:00
|
|
|
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;
|
2011-12-12 20:35:21 -08:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logs the specified message followed by the key identifying this program.
|
|
|
|
*/
|
|
|
|
void log(const char* message) const {
|
|
|
|
#if DEBUG_PROGRAMS
|
|
|
|
programid k = key();
|
|
|
|
PROGRAM_LOGD("%s (key = 0x%.8x%.8x)", message, uint32_t(k >> 32),
|
|
|
|
uint32_t(k & 0xffffffff));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-07-16 17:04:24 -07:00
|
|
|
static inline uint32_t getEnumForWrap(GLenum wrap) {
|
2011-12-12 20:35:21 -08:00
|
|
|
switch (wrap) {
|
|
|
|
case GL_CLAMP_TO_EDGE:
|
|
|
|
return 0;
|
|
|
|
case GL_REPEAT:
|
|
|
|
return 1;
|
|
|
|
case GL_MIRRORED_REPEAT:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // struct ProgramDescription
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
|
|
|
* A program holds a vertex and a fragment shader. It offers several utility
|
|
|
|
* methods to query attributes and uniforms.
|
|
|
|
*/
|
2010-07-29 14:37:42 -07:00
|
|
|
class Program {
|
2010-06-27 22:59:20 -07:00
|
|
|
public:
|
2011-12-12 16:47:48 -08:00
|
|
|
enum ShaderBindings {
|
|
|
|
kBindingPosition,
|
|
|
|
kBindingTexCoords
|
|
|
|
};
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
|
|
|
* Creates a new program with the specified vertex and fragment
|
|
|
|
* shaders sources.
|
|
|
|
*/
|
2011-12-12 20:35:21 -08:00
|
|
|
Program(const ProgramDescription& description, const char* vertex, const char* fragment);
|
2010-07-12 20:20:03 -07:00
|
|
|
virtual ~Program();
|
2010-06-27 22:59:20 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds this program to the GL context.
|
|
|
|
*/
|
2010-07-12 20:20:03 -07:00
|
|
|
virtual void use();
|
2010-06-27 22:59:20 -07:00
|
|
|
|
2010-07-12 14:41:06 -07:00
|
|
|
/**
|
|
|
|
* Marks this program as unused. This will not unbind
|
|
|
|
* the program from the GL context.
|
|
|
|
*/
|
2010-07-12 20:20:03 -07:00
|
|
|
virtual void remove();
|
2010-07-12 14:41:06 -07:00
|
|
|
|
2010-07-27 17:39:27 -07:00
|
|
|
/**
|
|
|
|
* Returns the OpenGL name of the specified attribute.
|
|
|
|
*/
|
|
|
|
int getAttrib(const char* name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the OpenGL name of the specified uniform.
|
|
|
|
*/
|
|
|
|
int getUniform(const char* name);
|
|
|
|
|
2010-07-12 14:41:06 -07:00
|
|
|
/**
|
|
|
|
* Indicates whether this program is currently in use with
|
|
|
|
* the GL context.
|
|
|
|
*/
|
|
|
|
inline bool isInUse() const {
|
|
|
|
return mUse;
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:23 -08:00
|
|
|
/**
|
|
|
|
* Indicates whether this program was correctly compiled and linked.
|
|
|
|
*/
|
|
|
|
inline bool isInitialized() const {
|
|
|
|
return mInitialized;
|
|
|
|
}
|
|
|
|
|
2010-07-29 14:37:42 -07:00
|
|
|
/**
|
|
|
|
* Binds the program with the specified projection, modelView and
|
|
|
|
* transform matrices.
|
|
|
|
*/
|
|
|
|
void set(const mat4& projectionMatrix, const mat4& modelViewMatrix,
|
2011-04-26 07:28:09 -07:00
|
|
|
const mat4& transformMatrix, bool offset = false);
|
2010-07-29 14:37:42 -07:00
|
|
|
|
|
|
|
/**
|
2010-10-11 16:34:59 -07:00
|
|
|
* Sets the color associated with this shader.
|
2010-07-29 14:37:42 -07:00
|
|
|
*/
|
2015-02-11 13:17:06 -08:00
|
|
|
void setColor(FloatColor color);
|
2010-07-29 14:37:42 -07:00
|
|
|
|
|
|
|
/**
|
2015-02-02 13:50:55 -08:00
|
|
|
* Name of the texCoords attribute if it exists (kBindingTexCoords), -1 otherwise.
|
2011-12-12 20:35:21 -08:00
|
|
|
*/
|
|
|
|
int texCoords;
|
|
|
|
|
2010-07-29 14:37:42 -07:00
|
|
|
/**
|
|
|
|
* Name of the transform uniform.
|
|
|
|
*/
|
|
|
|
int transform;
|
|
|
|
|
2012-09-26 16:39:40 -07:00
|
|
|
/**
|
|
|
|
* Name of the projection uniform.
|
|
|
|
*/
|
|
|
|
int projection;
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Adds an attribute with the specified name.
|
|
|
|
*
|
|
|
|
* @return The OpenGL name of the attribute.
|
|
|
|
*/
|
|
|
|
int addAttrib(const char* name);
|
|
|
|
|
2011-12-12 16:47:48 -08:00
|
|
|
/**
|
|
|
|
* Binds the specified attribute name to the specified slot.
|
|
|
|
*/
|
|
|
|
int bindAttrib(const char* name, ShaderBindings bindingSlot);
|
|
|
|
|
2010-06-27 22:59:20 -07:00
|
|
|
/**
|
|
|
|
* Adds a uniform with the specified name.
|
|
|
|
*
|
|
|
|
* @return The OpenGL name of the uniform.
|
|
|
|
*/
|
|
|
|
int addUniform(const char* name);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Compiles the specified shader of the specified type.
|
|
|
|
*
|
|
|
|
* @return The name of the compiled shader.
|
|
|
|
*/
|
|
|
|
GLuint buildShader(const char* source, GLenum type);
|
|
|
|
|
2011-12-12 16:47:48 -08:00
|
|
|
// Name of the OpenGL program and shaders
|
2011-12-09 12:55:37 -08:00
|
|
|
GLuint mProgramId;
|
2011-12-12 16:47:48 -08:00
|
|
|
GLuint mVertexShader;
|
|
|
|
GLuint mFragmentShader;
|
2010-06-27 22:59:20 -07:00
|
|
|
|
|
|
|
// Keeps track of attributes and uniforms slots
|
2011-12-09 12:55:37 -08:00
|
|
|
KeyedVector<const char*, int> mAttributes;
|
|
|
|
KeyedVector<const char*, int> mUniforms;
|
2010-07-12 14:41:06 -07:00
|
|
|
|
|
|
|
bool mUse;
|
2010-12-07 20:09:23 -08:00
|
|
|
bool mInitialized;
|
2011-12-09 12:55:37 -08:00
|
|
|
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
// Uniforms caching
|
2011-12-09 12:55:37 -08:00
|
|
|
bool mHasColorUniform;
|
|
|
|
int mColorUniform;
|
2011-12-13 22:00:19 -08:00
|
|
|
|
|
|
|
bool mHasSampler;
|
Pack preloaded framework assets in a texture atlas
When the Android runtime starts, the system preloads a series of assets
in the Zygote process. These assets are shared across all processes.
Unfortunately, each one of these assets is later uploaded in its own
OpenGL texture, once per process. This wastes memory and generates
unnecessary OpenGL state changes.
This CL introduces an asset server that provides an atlas to all processes.
Note: bitmaps used by skia shaders are *not* sampled from the atlas.
It's an uncommon use case and would require extra texture transforms
in the GL shaders.
WHAT IS THE ASSETS ATLAS
The "assets atlas" is a single, shareable graphic buffer that contains
all the system's preloaded bitmap drawables (this includes 9-patches.)
The atlas is made of two distinct objects: the graphic buffer that
contains the actual pixels and the map which indicates where each
preloaded bitmap can be found in the atlas (essentially a pair of
x and y coordinates.)
HOW IS THE ASSETS ATLAS GENERATED
Because we need to support a wide variety of devices and because it
is easy to change the list of preloaded drawables, the atlas is
generated at runtime, during the startup phase of the system process.
There are several steps that lead to the atlas generation:
1. If the device is booting for the first time, or if the device was
updated, we need to find the best atlas configuration. To do so,
the atlas service tries a number of width, height and algorithm
variations that allows us to pack as many assets as possible while
using as little memory as possible. Once a best configuration is found,
it gets written to disk in /data/system/framework_atlas
2. Given a best configuration (algorithm variant, dimensions and
number of bitmaps that can be packed in the atlas), the atlas service
packs all the preloaded bitmaps into a single graphic buffer object.
3. The packing is done using Skia in a temporary native bitmap. The
Skia bitmap is then copied into the graphic buffer using OpenGL ES
to benefit from texture swizzling.
HOW PROCESSES USE THE ATLAS
Whenever a process' hardware renderer initializes its EGL context,
it queries the atlas service for the graphic buffer and the map.
It is important to remember that both the context and the map will
be valid for the lifetime of the hardware renderer (if the system
process goes down, all apps get killed as well.)
Every time the hardware renderer needs to render a bitmap, it first
checks whether the bitmap can be found in the assets atlas. When
the bitmap is part of the atlas, texture coordinates are remapped
appropriately before rendering.
Change-Id: I8eaecf53e7f6a33d90da3d0047c5ceec89ea3af0
2013-04-17 18:54:38 -07:00
|
|
|
|
|
|
|
mat4 mProjection;
|
2014-01-29 13:00:33 -08:00
|
|
|
bool mOffset;
|
2010-06-27 22:59:20 -07:00
|
|
|
}; // class Program
|
|
|
|
|
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-10-27 18:57:51 -07:00
|
|
|
#endif // ANDROID_HWUI_PROGRAM_H
|