2010-07-30 19:18:16 -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.
|
|
|
|
*/
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
#include "SkiaShader.h"
|
2010-07-30 19:18:16 -07:00
|
|
|
|
2011-12-13 14:55:06 -08:00
|
|
|
#include "Caches.h"
|
2014-10-15 15:46:42 -04:00
|
|
|
#include "Extensions.h"
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
#include "Matrix.h"
|
2010-07-30 19:18:16 -07:00
|
|
|
#include "Texture.h"
|
2016-10-20 18:39:04 -07:00
|
|
|
#include "hwui/Bitmap.h"
|
2010-07-30 19:18:16 -07:00
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
#include <SkMatrix.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
|
2010-07-30 19:18:16 -07:00
|
|
|
namespace android {
|
|
|
|
namespace uirenderer {
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Support
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-21 15:31:20 -07:00
|
|
|
static constexpr GLenum gTileModes[] = {
|
2010-07-30 19:18:16 -07:00
|
|
|
GL_CLAMP_TO_EDGE, // == SkShader::kClamp_TileMode
|
|
|
|
GL_REPEAT, // == SkShader::kRepeat_Mode
|
|
|
|
GL_MIRRORED_REPEAT // == SkShader::kMirror_TileMode
|
|
|
|
};
|
|
|
|
|
2015-08-21 15:31:20 -07:00
|
|
|
static_assert(gTileModes[SkShader::kClamp_TileMode] == GL_CLAMP_TO_EDGE,
|
|
|
|
"SkShader TileModes have changed");
|
|
|
|
static_assert(gTileModes[SkShader::kRepeat_TileMode] == GL_REPEAT,
|
|
|
|
"SkShader TileModes have changed");
|
|
|
|
static_assert(gTileModes[SkShader::kMirror_TileMode] == GL_MIRRORED_REPEAT,
|
|
|
|
"SkShader TileModes have changed");
|
|
|
|
|
2012-07-30 14:47:51 -07:00
|
|
|
/**
|
|
|
|
* This function does not work for n == 0.
|
|
|
|
*/
|
|
|
|
static inline bool isPowerOfTwo(unsigned int n) {
|
|
|
|
return !(n & (n - 1));
|
|
|
|
}
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
static inline void bindUniformColor(int slot, FloatColor color) {
|
|
|
|
glUniform4fv(slot, 1, reinterpret_cast<const float*>(&color));
|
|
|
|
}
|
|
|
|
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
static inline void bindTexture(Caches* caches, Texture* texture, GLenum wrapS, GLenum wrapT) {
|
2016-11-15 18:01:21 -08:00
|
|
|
caches->textureState().bindTexture(texture->target(), texture->id());
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
texture->setWrapST(wrapS, wrapT);
|
2011-01-14 15:31:00 -08:00
|
|
|
}
|
|
|
|
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
/**
|
|
|
|
* Compute the matrix to transform to screen space.
|
|
|
|
* @param screenSpace Output param for the computed matrix.
|
|
|
|
* @param unitMatrix The unit matrix for gradient shaders, as returned by SkShader::asAGradient,
|
|
|
|
* or identity.
|
|
|
|
* @param localMatrix Local matrix, as returned by SkShader::getLocalMatrix().
|
|
|
|
* @param modelViewMatrix Model view matrix, as supplied by the OpenGLRenderer.
|
|
|
|
*/
|
|
|
|
static void computeScreenSpaceMatrix(mat4& screenSpace, const SkMatrix& unitMatrix,
|
|
|
|
const SkMatrix& localMatrix, const mat4& modelViewMatrix) {
|
|
|
|
mat4 shaderMatrix;
|
|
|
|
// uses implicit construction
|
|
|
|
shaderMatrix.loadInverse(localMatrix);
|
|
|
|
// again, uses implicit construction
|
|
|
|
screenSpace.loadMultiply(unitMatrix, shaderMatrix);
|
|
|
|
screenSpace.multiply(modelViewMatrix);
|
|
|
|
}
|
|
|
|
|
2010-07-30 19:18:16 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2016-12-12 18:21:32 -08:00
|
|
|
// Gradient shader matrix helpers
|
2010-07-30 19:18:16 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-04-03 09:37:49 -07:00
|
|
|
static void toLinearUnitMatrix(const SkPoint pts[2], SkMatrix* matrix) {
|
2010-10-06 16:57:29 -07:00
|
|
|
SkVector vec = pts[1] - pts[0];
|
|
|
|
const float mag = vec.length();
|
|
|
|
const float inv = mag ? 1.0f / mag : 0;
|
|
|
|
|
|
|
|
vec.scale(inv);
|
|
|
|
matrix->setSinCos(-vec.fY, vec.fX, pts[0].fX, pts[0].fY);
|
|
|
|
matrix->postTranslate(-pts[0].fX, -pts[0].fY);
|
|
|
|
matrix->postScale(inv, inv);
|
|
|
|
}
|
|
|
|
|
2010-10-07 15:07:45 -07:00
|
|
|
static void toCircularUnitMatrix(const float x, const float y, const float radius,
|
|
|
|
SkMatrix* matrix) {
|
|
|
|
const float inv = 1.0f / radius;
|
|
|
|
matrix->setTranslate(-x, -y);
|
|
|
|
matrix->postScale(inv, inv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void toSweepUnitMatrix(const float x, const float y, SkMatrix* matrix) {
|
|
|
|
matrix->setTranslate(-x, -y);
|
|
|
|
}
|
|
|
|
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Common gradient code
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-01-14 15:31:00 -08:00
|
|
|
|
Inspect SkShader to determine hw shader.
Instead of duplicating internal info about SkShader, inspect the
SkShader installed on the SkPaint.
core/java/android/view/GLES20Canvas.java:
Remove setupModifiers, nResetModifiers, and nSetupShader.
core/jni/android/graphics/Shader.cpp:
Remove calls to create/destroy the (previously) attached SkiaShader.
core/jni/android_view_GLES20Canvas.cpp:
Remove native code for setupShader and resetModifiers.
graphics/java/android/graphics/BitmapShader.java:
graphics/java/android/graphics/ComposeShader.java:
graphics/java/android/graphics/LinearGradient.java:
graphics/java/android/graphics/RadialGradient.java:
graphics/java/android/graphics/Shader.java:
graphics/java/android/graphics/SweepGradient.java:
Remove code keeping track of native SkiaShader.
libs/hwui/Caches.h:
Include Extensions.h.
libs/hwui/DeferredDisplayList.cpp:
Compare shaders on the paint, instead of on DrawModifiers.
libs/hwui/DisplayList.cpp:
libs/hwui/DisplayList.h:
Remove vector of SkiaShaders.
libs/hwui/DisplayListOp.h:
Access the SkShader on mPaint.
Remove SetupShaderOp and ResetShaderOp.
libs/hwui/DisplayListRenderer.cpp:
libs/hwui/DisplayListRenderer.h:
Remove resetShader, setupShader, refShader, and mShaderMap.
libs/hwui/FontRenderer.cpp:
Pass SkShader to setupDrawShader and setupDrawShaderUniforms.
libs/hwui/OpenGLRenderer.cpp:
libs/hwui/OpenGLRenderer.h:
Add LayerShader, a class inheriting from SkShader, to mimic the
behavior of SkiaLayerShader. Unlike SkiaLayerShader, it can be set on
the SkPaint so it can be inspected later.
Set a LayerShader instead of a SkiaLayerShader.
setupDrawShader and setupDrawShaderUniforms now inspect an SkShader
passed in.
Inspect SkShader instead of mDrawModifiers.mShader.
Remove resetShader and setupShader.
setupDrawColorUniforms now takes a boolean indicating whether there is
a shader.
Add an inline function for accessing the SkShader on an SkPaint.
In setupDrawBlending(Layer*, bool), do not check the shader (which will
never be set), but do check whether the color filter may change the
alpha (newly fixed behavior).
In setupDrawBlending(SkPaint, ...), check the SkShader and whether the
color filter affects alpha (the latter is new behavior).
libs/hwui/Renderer.h:
Remove pure virtual functions setupShader and resetShader.
libs/hwui/ResourceCache.cpp:
libs/hwui/ResourceCache.h:
Remove functions for refing/unrefing shaders.
libs/hwui/SkiaShader.cpp:
libs/hwui/SkiaShader.h:
Much of this code was redundant and has been removed.
Convert structs into class with nothing but static functions for
calling describe/setupProgram.
libs/hwui/TextureCache.cpp:
libs/hwui/TextureCache.h:
Use the SkPixelRef as the key to the bitmap Lru cache, since shader
inspection will provide a different SkBitmap pointer (though it will
hold the correct SkPixelRef with the correct generation ID).
tests/CanvasCompare/src/com/android/test/hwuicompare/DisplayModifier.java:
tests/CanvasCompare/src/com/android/test/hwuicompare/ResourceModifiers.java:
Update manual test to have more shaders: radial, sweep, compose,
invalid compose.
BUG:10650594
Change-Id: Iaa7189178bda1c55f96da044d2a9fa602ba36034
2014-05-05 12:50:38 -04:00
|
|
|
static bool isSimpleGradient(const SkShader::GradientInfo& gradInfo) {
|
|
|
|
return gradInfo.fColorCount == 2 && gradInfo.fTileMode == SkShader::kClamp_TileMode;
|
|
|
|
}
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Store / apply
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool tryStoreGradient(Caches& caches, const SkShader& shader, const Matrix4 modelViewMatrix,
|
|
|
|
GLuint* textureUnit, ProgramDescription* description,
|
|
|
|
SkiaShaderData::GradientShaderData* outData) {
|
|
|
|
SkShader::GradientInfo gradInfo;
|
|
|
|
gradInfo.fColorCount = 0;
|
|
|
|
gradInfo.fColors = nullptr;
|
|
|
|
gradInfo.fColorOffsets = nullptr;
|
|
|
|
|
|
|
|
SkMatrix unitMatrix;
|
|
|
|
switch (shader.asAGradient(&gradInfo)) {
|
|
|
|
case SkShader::kLinear_GradientType:
|
|
|
|
description->gradientType = ProgramDescription::kGradientLinear;
|
|
|
|
|
2015-04-03 09:37:49 -07:00
|
|
|
toLinearUnitMatrix(gradInfo.fPoint, &unitMatrix);
|
2015-02-13 17:47:21 -08:00
|
|
|
break;
|
|
|
|
case SkShader::kRadial_GradientType:
|
|
|
|
description->gradientType = ProgramDescription::kGradientCircular;
|
|
|
|
|
|
|
|
toCircularUnitMatrix(gradInfo.fPoint[0].fX, gradInfo.fPoint[0].fY,
|
|
|
|
gradInfo.fRadius[0], &unitMatrix);
|
|
|
|
break;
|
|
|
|
case SkShader::kSweep_GradientType:
|
|
|
|
description->gradientType = ProgramDescription::kGradientSweep;
|
|
|
|
|
|
|
|
toSweepUnitMatrix(gradInfo.fPoint[0].fX, gradInfo.fPoint[0].fY, &unitMatrix);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Do nothing. This shader is unsupported.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
description->hasGradient = true;
|
|
|
|
description->isSimpleGradient = isSimpleGradient(gradInfo);
|
|
|
|
|
|
|
|
computeScreenSpaceMatrix(outData->screenSpace, unitMatrix,
|
|
|
|
shader.getLocalMatrix(), modelViewMatrix);
|
|
|
|
|
|
|
|
// re-query shader to get full color / offset data
|
|
|
|
std::unique_ptr<SkColor[]> colorStorage(new SkColor[gradInfo.fColorCount]);
|
|
|
|
std::unique_ptr<SkScalar[]> colorOffsets(new SkScalar[gradInfo.fColorCount]);
|
|
|
|
gradInfo.fColors = &colorStorage[0];
|
|
|
|
gradInfo.fColorOffsets = &colorOffsets[0];
|
|
|
|
shader.asAGradient(&gradInfo);
|
|
|
|
|
2016-12-12 18:21:32 -08:00
|
|
|
if (CC_UNLIKELY(!description->isSimpleGradient)) {
|
2015-02-13 17:47:21 -08:00
|
|
|
outData->gradientSampler = (*textureUnit)++;
|
|
|
|
|
|
|
|
#ifndef SK_SCALAR_IS_FLOAT
|
|
|
|
#error Need to convert gradInfo.fColorOffsets to float!
|
|
|
|
#endif
|
|
|
|
outData->gradientTexture = caches.gradientCache.get(
|
|
|
|
gradInfo.fColors, gradInfo.fColorOffsets, gradInfo.fColorCount);
|
|
|
|
outData->wrapST = gTileModes[gradInfo.fTileMode];
|
|
|
|
} else {
|
|
|
|
outData->gradientSampler = 0;
|
|
|
|
outData->gradientTexture = nullptr;
|
|
|
|
|
2017-03-31 12:09:24 -04:00
|
|
|
outData->startColor.set(gradInfo.fColors[0]);
|
|
|
|
outData->endColor.set(gradInfo.fColors[1]);
|
2015-02-13 17:47:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void applyGradient(Caches& caches, const SkiaShaderData::GradientShaderData& data,
|
|
|
|
const GLsizei width, const GLsizei height) {
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
if (CC_UNLIKELY(data.gradientTexture)) {
|
|
|
|
caches.textureState().activateTexture(data.gradientSampler);
|
|
|
|
bindTexture(&caches, data.gradientTexture, data.wrapST, data.wrapST);
|
|
|
|
glUniform1i(caches.program().getUniform("gradientSampler"), data.gradientSampler);
|
|
|
|
} else {
|
|
|
|
bindUniformColor(caches.program().getUniform("startColor"), data.startColor);
|
|
|
|
bindUniformColor(caches.program().getUniform("endColor"), data.endColor);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
glUniform2f(caches.program().getUniform("screenSize"), 1.0f / width, 1.0f / height);
|
2015-02-13 17:47:21 -08:00
|
|
|
glUniformMatrix4fv(caches.program().getUniform("screenSpace"), 1,
|
|
|
|
GL_FALSE, &data.screenSpace.data[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tryStoreBitmap(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
|
|
|
|
GLuint* textureUnit, ProgramDescription* description,
|
|
|
|
SkiaShaderData::BitmapShaderData* outData) {
|
|
|
|
SkBitmap bitmap;
|
|
|
|
SkShader::TileMode xy[2];
|
2015-07-31 10:38:40 -04:00
|
|
|
if (!shader.isABitmap(&bitmap, nullptr, xy)) {
|
2015-02-13 17:47:21 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-20 18:39:04 -07:00
|
|
|
// TODO: create hwui-owned BitmapShader.
|
|
|
|
Bitmap* hwuiBitmap = static_cast<Bitmap*>(bitmap.pixelRef());
|
|
|
|
outData->bitmapTexture = caches.textureCache.get(hwuiBitmap);
|
2015-02-13 17:47:21 -08:00
|
|
|
if (!outData->bitmapTexture) return false;
|
|
|
|
|
|
|
|
outData->bitmapSampler = (*textureUnit)++;
|
|
|
|
|
2015-11-10 12:19:17 -08:00
|
|
|
const float width = outData->bitmapTexture->width();
|
|
|
|
const float height = outData->bitmapTexture->height();
|
2015-02-13 17:47:21 -08:00
|
|
|
|
2017-03-27 00:40:21 -07:00
|
|
|
Texture* texture = outData->bitmapTexture;
|
|
|
|
|
2015-02-13 17:47:21 -08:00
|
|
|
description->hasBitmap = true;
|
2017-03-27 00:40:21 -07:00
|
|
|
description->hasLinearTexture = texture->isLinear();
|
|
|
|
description->hasColorSpaceConversion = texture->hasColorSpaceConversion();
|
|
|
|
description->transferFunction = texture->getTransferFunctionType();
|
|
|
|
description->hasTranslucentConversion = texture->blend;
|
2016-12-12 16:14:11 -08:00
|
|
|
description->isShaderBitmapExternal = hwuiBitmap->isHardware();
|
2016-11-15 18:01:21 -08:00
|
|
|
// gralloc doesn't support non-clamp modes
|
|
|
|
if (hwuiBitmap->isHardware() || (!caches.extensions().hasNPot()
|
2015-02-13 17:47:21 -08:00
|
|
|
&& (!isPowerOfTwo(width) || !isPowerOfTwo(height))
|
2016-11-15 18:01:21 -08:00
|
|
|
&& (xy[0] != SkShader::kClamp_TileMode || xy[1] != SkShader::kClamp_TileMode))) {
|
|
|
|
// need non-clamp mode, but it's not supported for this draw,
|
|
|
|
// so enable custom shader logic to mimic
|
|
|
|
description->useShaderBasedWrap = true;
|
2015-02-13 17:47:21 -08:00
|
|
|
description->bitmapWrapS = gTileModes[xy[0]];
|
|
|
|
description->bitmapWrapT = gTileModes[xy[1]];
|
|
|
|
|
|
|
|
outData->wrapS = GL_CLAMP_TO_EDGE;
|
|
|
|
outData->wrapT = GL_CLAMP_TO_EDGE;
|
|
|
|
} else {
|
|
|
|
outData->wrapS = gTileModes[xy[0]];
|
|
|
|
outData->wrapT = gTileModes[xy[1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
computeScreenSpaceMatrix(outData->textureTransform, SkMatrix::I(), shader.getLocalMatrix(),
|
|
|
|
modelViewMatrix);
|
|
|
|
outData->textureDimension[0] = 1.0f / width;
|
|
|
|
outData->textureDimension[1] = 1.0f / height;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void applyBitmap(Caches& caches, const SkiaShaderData::BitmapShaderData& data) {
|
|
|
|
caches.textureState().activateTexture(data.bitmapSampler);
|
|
|
|
bindTexture(&caches, data.bitmapTexture, data.wrapS, data.wrapT);
|
|
|
|
data.bitmapTexture->setFilter(GL_LINEAR);
|
|
|
|
|
|
|
|
glUniform1i(caches.program().getUniform("bitmapSampler"), data.bitmapSampler);
|
|
|
|
glUniformMatrix4fv(caches.program().getUniform("textureTransform"), 1, GL_FALSE,
|
|
|
|
&data.textureTransform.data[0]);
|
|
|
|
glUniform2fv(caches.program().getUniform("textureDimension"), 1, &data.textureDimension[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkiaShaderType getComposeSubType(const SkShader& shader) {
|
|
|
|
// First check for a gradient shader.
|
|
|
|
switch (shader.asAGradient(nullptr)) {
|
|
|
|
case SkShader::kNone_GradientType:
|
|
|
|
// Not a gradient shader. Fall through to check for other types.
|
|
|
|
break;
|
|
|
|
case SkShader::kLinear_GradientType:
|
|
|
|
case SkShader::kRadial_GradientType:
|
|
|
|
case SkShader::kSweep_GradientType:
|
|
|
|
return kGradient_SkiaShaderType;
|
|
|
|
default:
|
|
|
|
// This is a Skia gradient that has no SkiaShader equivalent. Return None to skip.
|
|
|
|
return kNone_SkiaShaderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The shader is not a gradient. Check for a bitmap shader.
|
2015-07-31 10:38:40 -04:00
|
|
|
if (shader.isABitmap()) {
|
2015-02-13 17:47:21 -08:00
|
|
|
return kBitmap_SkiaShaderType;
|
|
|
|
}
|
|
|
|
return kNone_SkiaShaderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void storeCompose(Caches& caches, const SkShader& bitmapShader, const SkShader& gradientShader,
|
|
|
|
const Matrix4& modelViewMatrix, GLuint* textureUnit,
|
|
|
|
ProgramDescription* description, SkiaShaderData* outData) {
|
|
|
|
LOG_ALWAYS_FATAL_IF(!tryStoreBitmap(caches, bitmapShader, modelViewMatrix,
|
|
|
|
textureUnit, description, &outData->bitmapData),
|
|
|
|
"failed storing bitmap shader data");
|
|
|
|
LOG_ALWAYS_FATAL_IF(!tryStoreGradient(caches, gradientShader, modelViewMatrix,
|
|
|
|
textureUnit, description, &outData->gradientData),
|
|
|
|
"failing storing gradient shader data");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tryStoreCompose(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
|
|
|
|
GLuint* textureUnit, ProgramDescription* description,
|
|
|
|
SkiaShaderData* outData) {
|
|
|
|
|
|
|
|
SkShader::ComposeRec rec;
|
|
|
|
if (!shader.asACompose(&rec)) return false;
|
|
|
|
|
|
|
|
const SkiaShaderType shaderAType = getComposeSubType(*rec.fShaderA);
|
|
|
|
const SkiaShaderType shaderBType = getComposeSubType(*rec.fShaderB);
|
|
|
|
|
|
|
|
// check that type enum values are the 2 flags that compose the kCompose value
|
|
|
|
if ((shaderAType & shaderBType) != 0) return false;
|
|
|
|
if ((shaderAType | shaderBType) != kCompose_SkiaShaderType) return false;
|
|
|
|
|
|
|
|
mat4 transform;
|
|
|
|
computeScreenSpaceMatrix(transform, SkMatrix::I(), shader.getLocalMatrix(), modelViewMatrix);
|
|
|
|
if (shaderAType == kBitmap_SkiaShaderType) {
|
|
|
|
description->isBitmapFirst = true;
|
|
|
|
storeCompose(caches, *rec.fShaderA, *rec.fShaderB,
|
|
|
|
transform, textureUnit, description, outData);
|
|
|
|
} else {
|
|
|
|
description->isBitmapFirst = false;
|
|
|
|
storeCompose(caches, *rec.fShaderB, *rec.fShaderA,
|
|
|
|
transform, textureUnit, description, outData);
|
|
|
|
}
|
2016-10-28 17:21:45 -04:00
|
|
|
description->shadersMode = rec.fBlendMode;
|
2015-02-13 17:47:21 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-01 10:35:35 -07:00
|
|
|
void SkiaShader::store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
|
2015-02-13 17:47:21 -08:00
|
|
|
GLuint* textureUnit, ProgramDescription* description,
|
|
|
|
SkiaShaderData* outData) {
|
2015-06-01 10:35:35 -07:00
|
|
|
if (tryStoreGradient(caches, shader, modelViewMatrix,
|
2015-02-13 17:47:21 -08:00
|
|
|
textureUnit, description, &outData->gradientData)) {
|
|
|
|
outData->skiaShaderType = kGradient_SkiaShaderType;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-01 10:35:35 -07:00
|
|
|
if (tryStoreBitmap(caches, shader, modelViewMatrix,
|
2015-02-13 17:47:21 -08:00
|
|
|
textureUnit, description, &outData->bitmapData)) {
|
|
|
|
outData->skiaShaderType = kBitmap_SkiaShaderType;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-01 10:35:35 -07:00
|
|
|
if (tryStoreCompose(caches, shader, modelViewMatrix,
|
2015-02-13 17:47:21 -08:00
|
|
|
textureUnit, description, outData)) {
|
|
|
|
outData->skiaShaderType = kCompose_SkiaShaderType;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-13 13:34:07 -07:00
|
|
|
// Unknown/unsupported type, so explicitly ignore shader
|
|
|
|
outData->skiaShaderType = kNone_SkiaShaderType;
|
2015-02-13 17:47:21 -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
|
|
|
void SkiaShader::apply(Caches& caches, const SkiaShaderData& data,
|
|
|
|
const GLsizei width, const GLsizei height) {
|
2015-02-13 17:47:21 -08:00
|
|
|
if (!data.skiaShaderType) return;
|
|
|
|
|
|
|
|
if (data.skiaShaderType & kGradient_SkiaShaderType) {
|
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
|
|
|
applyGradient(caches, data.gradientData, width, height);
|
2015-02-13 17:47:21 -08:00
|
|
|
}
|
|
|
|
if (data.skiaShaderType & kBitmap_SkiaShaderType) {
|
|
|
|
applyBitmap(caches, data.bitmapData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-30 19:18:16 -07:00
|
|
|
}; // namespace uirenderer
|
|
|
|
}; // namespace android
|