2015-02-02 18:39:33 -08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
*/
|
2016-07-06 16:10:09 -07:00
|
|
|
|
|
|
|
#pragma once
|
2015-02-02 18:39:33 -08:00
|
|
|
|
2015-06-01 10:35:35 -07:00
|
|
|
#include "Glop.h"
|
2015-02-02 18:39:33 -08:00
|
|
|
#include "Program.h"
|
2015-03-09 14:17:29 -07:00
|
|
|
#include "renderstate/Blend.h"
|
2015-02-02 18:39:33 -08:00
|
|
|
#include "utils/Macros.h"
|
|
|
|
|
|
|
|
class SkPaint;
|
2015-02-13 17:47:21 -08:00
|
|
|
class SkShader;
|
2015-02-02 18:39:33 -08:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
class Caches;
|
2017-01-09 14:15:41 -05:00
|
|
|
class GlLayer;
|
2015-02-05 10:12:38 -08:00
|
|
|
class Matrix4;
|
2016-07-06 16:10:09 -07:00
|
|
|
class Patch;
|
2015-02-02 18:39:33 -08:00
|
|
|
class RenderState;
|
|
|
|
class Texture;
|
2016-07-06 16:10:09 -07:00
|
|
|
class UvMapper;
|
2015-02-05 10:12:38 -08:00
|
|
|
class VertexBuffer;
|
2016-07-06 16:10:09 -07:00
|
|
|
struct PathTexture;
|
|
|
|
struct ShadowTexture;
|
2015-02-02 18:39:33 -08:00
|
|
|
|
2015-06-01 10:35:35 -07:00
|
|
|
namespace TextureFillFlags {
|
2017-11-03 10:12:19 -07:00
|
|
|
enum {
|
|
|
|
None = 0,
|
|
|
|
IsAlphaMaskTexture = 1 << 0,
|
|
|
|
ForceFilter = 1 << 1,
|
|
|
|
};
|
2015-06-01 10:35:35 -07:00
|
|
|
}
|
2015-02-27 17:43:02 -08:00
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
class GlopBuilder {
|
|
|
|
PREVENT_COPY_AND_ASSIGN(GlopBuilder);
|
2017-11-03 10:12:19 -07:00
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
public:
|
|
|
|
GlopBuilder(RenderState& renderState, Caches& caches, Glop* outGlop);
|
2015-02-06 15:25:51 -08:00
|
|
|
|
2015-11-02 14:52:21 -08:00
|
|
|
GlopBuilder& setMeshTexturedIndexedVbo(GLuint vbo, GLsizei elementCount);
|
2015-02-02 18:39:33 -08:00
|
|
|
GlopBuilder& setMeshUnitQuad();
|
2015-02-19 09:51:53 -08:00
|
|
|
GlopBuilder& setMeshTexturedUnitQuad(const UvMapper* uvMapper);
|
2015-02-24 13:46:29 -08:00
|
|
|
GlopBuilder& setMeshTexturedUvQuad(const UvMapper* uvMapper, const Rect uvs);
|
2016-04-28 16:59:42 -07:00
|
|
|
GlopBuilder& setMeshVertexBuffer(const VertexBuffer& vertexBuffer);
|
2015-02-25 17:16:16 -08:00
|
|
|
GlopBuilder& setMeshIndexedQuads(Vertex* vertexData, int quadCount);
|
2017-11-03 10:12:19 -07:00
|
|
|
GlopBuilder& setMeshColoredTexturedMesh(ColorTextureVertex* vertexData,
|
|
|
|
int elementCount); // TODO: use indexed quads
|
|
|
|
GlopBuilder& setMeshTexturedIndexedQuads(TextureVertex* vertexData,
|
|
|
|
int elementCount); // TODO: take quadCount
|
2015-03-03 09:54:14 -08:00
|
|
|
GlopBuilder& setMeshPatchQuads(const Patch& patch);
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2017-11-03 10:12:19 -07:00
|
|
|
GlopBuilder& setFillPaint(const SkPaint& paint, float alphaScale,
|
|
|
|
bool shadowInterp = false); // TODO: avoid boolean with default
|
2015-06-01 10:35:35 -07:00
|
|
|
GlopBuilder& setFillTexturePaint(Texture& texture, const int textureFillFlags,
|
2017-11-03 10:12:19 -07:00
|
|
|
const SkPaint* paint, float alphaScale);
|
|
|
|
GlopBuilder& setFillPathTexturePaint(PathTexture& texture, const SkPaint& paint,
|
|
|
|
float alphaScale);
|
2015-02-17 16:42:02 -08:00
|
|
|
GlopBuilder& setFillShadowTexturePaint(ShadowTexture& texture, int shadowColor,
|
2017-11-03 10:12:19 -07:00
|
|
|
const SkPaint& paint, float alphaScale);
|
2015-02-17 16:42:02 -08:00
|
|
|
GlopBuilder& setFillBlack();
|
|
|
|
GlopBuilder& setFillClear();
|
2017-11-03 10:12:19 -07:00
|
|
|
GlopBuilder& setFillLayer(Texture& texture, const SkColorFilter* colorFilter, float alpha,
|
|
|
|
SkBlendMode mode, Blend::ModeOrderSwap modeUsage);
|
2017-01-09 14:15:41 -05:00
|
|
|
GlopBuilder& setFillTextureLayer(GlLayer& layer, float alpha);
|
2016-10-25 15:21:50 -07:00
|
|
|
// TODO: setFillLayer normally forces its own wrap & filter mode,
|
|
|
|
// which isn't always correct.
|
2017-06-28 11:08:07 -07:00
|
|
|
GlopBuilder& setFillExternalTexture(Texture& texture, Matrix4& textureTransform,
|
2017-11-03 10:12:19 -07:00
|
|
|
bool requiresFilter);
|
2015-02-11 13:17:06 -08:00
|
|
|
|
2015-10-05 13:00:52 -07:00
|
|
|
GlopBuilder& setTransform(const Matrix4& canvas, const int transformFlags);
|
2015-02-05 10:12:38 -08:00
|
|
|
|
|
|
|
GlopBuilder& setModelViewMapUnitToRect(const Rect destination);
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& setModelViewMapUnitToRectSnap(const Rect destination);
|
2015-02-27 17:43:02 -08:00
|
|
|
GlopBuilder& setModelViewMapUnitToRectOptionalSnap(bool snap, const Rect& destination) {
|
2015-02-26 16:28:17 -08:00
|
|
|
if (snap) {
|
|
|
|
return setModelViewMapUnitToRectSnap(destination);
|
|
|
|
} else {
|
|
|
|
return setModelViewMapUnitToRect(destination);
|
|
|
|
}
|
|
|
|
}
|
2015-02-05 10:12:38 -08:00
|
|
|
GlopBuilder& setModelViewOffsetRect(float offsetX, float offsetY, const Rect source);
|
2015-02-19 09:51:53 -08:00
|
|
|
GlopBuilder& setModelViewOffsetRectSnap(float offsetX, float offsetY, const Rect source);
|
2017-11-03 10:12:19 -07:00
|
|
|
GlopBuilder& setModelViewOffsetRectOptionalSnap(bool snap, float offsetX, float offsetY,
|
|
|
|
const Rect& source) {
|
2015-02-27 17:43:02 -08:00
|
|
|
if (snap) {
|
|
|
|
return setModelViewOffsetRectSnap(offsetX, offsetY, source);
|
|
|
|
} else {
|
|
|
|
return setModelViewOffsetRect(offsetX, offsetY, source);
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 17:21:58 -08:00
|
|
|
GlopBuilder& setModelViewIdentityEmptyBounds() {
|
|
|
|
// pass empty rect since not needed for damage / snap
|
|
|
|
return setModelViewOffsetRect(0, 0, Rect());
|
|
|
|
}
|
2015-02-05 10:12:38 -08:00
|
|
|
|
2015-02-11 13:17:06 -08:00
|
|
|
GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
|
|
|
|
|
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
|
|
|
GlopBuilder& setGammaCorrection(bool enabled);
|
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
void build();
|
2015-10-05 13:00:52 -07:00
|
|
|
|
|
|
|
static void dump(const Glop& glop);
|
2017-11-03 10:12:19 -07:00
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
private:
|
2017-11-03 10:12:19 -07:00
|
|
|
void setFill(int color, float alphaScale, SkBlendMode mode, Blend::ModeOrderSwap modeUsage,
|
|
|
|
const SkShader* shader, const SkColorFilter* colorFilter);
|
2015-02-11 13:17:06 -08:00
|
|
|
|
2015-02-05 10:12:38 -08:00
|
|
|
enum StageFlags {
|
|
|
|
kInitialStage = 0,
|
|
|
|
kMeshStage = 1 << 0,
|
|
|
|
kTransformStage = 1 << 1,
|
|
|
|
kModelViewStage = 1 << 2,
|
|
|
|
kFillStage = 1 << 3,
|
2015-02-11 13:17:06 -08:00
|
|
|
kRoundRectClipStage = 1 << 4,
|
2017-11-03 10:12:19 -07:00
|
|
|
kAllStages =
|
|
|
|
kMeshStage | kFillStage | kTransformStage | kModelViewStage | kRoundRectClipStage,
|
2015-02-05 10:12:38 -08:00
|
|
|
} mStageFlags;
|
|
|
|
|
2015-02-02 18:39:33 -08:00
|
|
|
ProgramDescription mDescription;
|
|
|
|
RenderState& mRenderState;
|
|
|
|
Caches& mCaches;
|
2015-02-13 17:47:21 -08:00
|
|
|
const SkShader* mShader;
|
2015-02-02 18:39:33 -08:00
|
|
|
Glop* mOutGlop;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace uirenderer */
|
|
|
|
} /* namespace android */
|