Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_SKIA_SHADER_H |
| 18 | #define ANDROID_HWUI_SKIA_SHADER_H |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 19 | |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 20 | #include "FloatColor.h" |
| 21 | #include "Matrix.h" |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 22 | |
| 23 | #include <GLES2/gl2.h> |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 24 | #include <SkShader.h> |
| 25 | #include <SkXfermode.h> |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 26 | #include <cutils/compiler.h> |
| 27 | |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 31 | class Caches; |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 32 | class Extensions; |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 33 | class Layer; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 34 | class Texture; |
Tom Hudson | 73edbfe | 2014-10-16 09:10:41 -0400 | [diff] [blame] | 35 | struct ProgramDescription; |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 36 | |
| 37 | /** |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 38 | * Type of Skia shader in use. |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 39 | * |
| 40 | * Note that kBitmap | kGradient = kCompose, since Compose implies |
| 41 | * both its component types are in use simultaneously. No other |
| 42 | * composition of multiple types is supported. |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 43 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 44 | enum SkiaShaderType { |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 45 | kNone_SkiaShaderType = 0, |
| 46 | kBitmap_SkiaShaderType = 1, |
| 47 | kGradient_SkiaShaderType = 2, |
| 48 | kCompose_SkiaShaderType = kBitmap_SkiaShaderType | kGradient_SkiaShaderType, |
| 49 | kLayer_SkiaShaderType = 4, |
| 50 | }; |
| 51 | |
| 52 | struct SkiaShaderData { |
| 53 | SkiaShaderType skiaShaderType; |
| 54 | struct BitmapShaderData { |
| 55 | Texture* bitmapTexture; |
| 56 | GLuint bitmapSampler; |
| 57 | GLenum wrapS; |
| 58 | GLenum wrapT; |
| 59 | |
| 60 | Matrix4 textureTransform; |
| 61 | float textureDimension[2]; |
| 62 | } bitmapData; |
| 63 | struct GradientShaderData { |
| 64 | Matrix4 screenSpace; |
| 65 | GLuint ditherSampler; |
| 66 | |
| 67 | // simple gradient |
| 68 | FloatColor startColor; |
| 69 | FloatColor endColor; |
| 70 | |
| 71 | // complex gradient |
| 72 | Texture* gradientTexture; |
| 73 | GLuint gradientSampler; |
| 74 | GLenum wrapST; |
| 75 | |
| 76 | } gradientData; |
| 77 | struct LayerShaderData { |
| 78 | Layer* layer; |
| 79 | GLuint bitmapSampler; |
| 80 | GLenum wrapS; |
| 81 | GLenum wrapT; |
| 82 | |
| 83 | Matrix4 textureTransform; |
| 84 | float textureDimension[2]; |
| 85 | } layerData; |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 86 | }; |
| 87 | |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 88 | class SkiaShader { |
| 89 | public: |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 90 | static SkiaShaderType getType(const SkShader& shader); |
| 91 | static void describe(Caches* caches, ProgramDescription& description, |
| 92 | const Extensions& extensions, const SkShader& shader); |
| 93 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 94 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame^] | 95 | |
| 96 | // new SkiaShader interaction model - store into ShaderData, and apply to Caches/Program/GL |
| 97 | static void store(Caches& caches, const SkShader* shader, const Matrix4& modelViewMatrix, |
| 98 | GLuint* textureUnit, ProgramDescription* description, |
| 99 | SkiaShaderData* outData); |
| 100 | static void apply(Caches& caches, const SkiaShaderData& data); |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 101 | }; |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 102 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 103 | class InvalidSkiaShader { |
| 104 | public: |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 105 | static void describe(Caches* caches, ProgramDescription& description, |
| 106 | const Extensions& extensions, const SkShader& shader) { |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 107 | // This shader is unsupported. Skip it. |
| 108 | } |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 109 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 110 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader) { |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 111 | // This shader is unsupported. Skip it. |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 114 | }; |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 115 | /** |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 116 | * A shader that draws a layer. |
| 117 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 118 | class SkiaLayerShader { |
| 119 | public: |
| 120 | static void describe(Caches* caches, ProgramDescription& description, |
| 121 | const Extensions& extensions, const SkShader& shader); |
| 122 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 123 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 124 | }; // class SkiaLayerShader |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 125 | |
| 126 | /** |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 127 | * A shader that draws a bitmap. |
| 128 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 129 | class SkiaBitmapShader { |
| 130 | public: |
| 131 | static void describe(Caches* caches, ProgramDescription& description, |
| 132 | const Extensions& extensions, const SkShader& shader); |
| 133 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 134 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 135 | |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 136 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 137 | }; // class SkiaBitmapShader |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 140 | * A shader that draws one of three types of gradient, depending on shader param. |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 141 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 142 | class SkiaGradientShader { |
| 143 | public: |
| 144 | static void describe(Caches* caches, ProgramDescription& description, |
| 145 | const Extensions& extensions, const SkShader& shader); |
| 146 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 147 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 148 | }; |
Romain Guy | ddb80be | 2010-09-20 19:04:33 -0700 | [diff] [blame] | 149 | |
| 150 | /** |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 151 | * A shader that draws two shaders, composited with an xfermode. |
| 152 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 153 | class SkiaComposeShader { |
| 154 | public: |
| 155 | static void describe(Caches* caches, ProgramDescription& description, |
| 156 | const Extensions& extensions, const SkShader& shader); |
| 157 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 158 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 159 | }; // class SkiaComposeShader |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 160 | |
| 161 | }; // namespace uirenderer |
| 162 | }; // namespace android |
| 163 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 164 | #endif // ANDROID_HWUI_SKIA_SHADER_H |