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 | |
| 20 | #include <SkShader.h> |
| 21 | #include <SkXfermode.h> |
| 22 | |
| 23 | #include <GLES2/gl2.h> |
| 24 | |
Romain Guy | 7953745 | 2011-10-12 13:48:51 -0700 | [diff] [blame] | 25 | #include <cutils/compiler.h> |
| 26 | |
Tom Hudson | 73edbfe | 2014-10-16 09:10:41 -0400 | [diff] [blame] | 27 | #include "Matrix.h" |
| 28 | |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 32 | class Caches; |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 33 | class Extensions; |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 34 | class Layer; |
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. |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 39 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 40 | enum SkiaShaderType { |
| 41 | kNone_SkiaShaderType, |
| 42 | kBitmap_SkiaShaderType, |
| 43 | kGradient_SkiaShaderType, |
| 44 | kCompose_SkiaShaderType, |
| 45 | kLayer_SkiaShaderType |
| 46 | }; |
| 47 | |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 48 | class SkiaShader { |
| 49 | public: |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 50 | static SkiaShaderType getType(const SkShader& shader); |
| 51 | static void describe(Caches* caches, ProgramDescription& description, |
| 52 | const Extensions& extensions, const SkShader& shader); |
| 53 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 54 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 55 | }; |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 56 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 57 | class InvalidSkiaShader { |
| 58 | public: |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 59 | static void describe(Caches* caches, ProgramDescription& description, |
| 60 | const Extensions& extensions, const SkShader& shader) { |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 61 | // This shader is unsupported. Skip it. |
| 62 | } |
Andreas Gampe | 64bb413 | 2014-11-22 00:35:09 +0000 | [diff] [blame] | 63 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 64 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader) { |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 65 | // This shader is unsupported. Skip it. |
Chet Haase | 5c13d89 | 2010-10-08 08:37:55 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 68 | }; |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 69 | /** |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 70 | * A shader that draws a layer. |
| 71 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 72 | class SkiaLayerShader { |
| 73 | public: |
| 74 | static void describe(Caches* caches, ProgramDescription& description, |
| 75 | const Extensions& extensions, const SkShader& shader); |
| 76 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 77 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 78 | }; // class SkiaLayerShader |
Chris Craik | 3f085429 | 2014-04-15 16:18:08 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 81 | * A shader that draws a bitmap. |
| 82 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 83 | class SkiaBitmapShader { |
| 84 | public: |
| 85 | static void describe(Caches* caches, ProgramDescription& description, |
| 86 | const Extensions& extensions, const SkShader& shader); |
| 87 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 88 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 89 | |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 90 | |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 91 | }; // class SkiaBitmapShader |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 94 | * 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] | 95 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 96 | class SkiaGradientShader { |
| 97 | public: |
| 98 | static void describe(Caches* caches, ProgramDescription& description, |
| 99 | const Extensions& extensions, const SkShader& shader); |
| 100 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 101 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 102 | }; |
Romain Guy | ddb80be | 2010-09-20 19:04:33 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 105 | * A shader that draws two shaders, composited with an xfermode. |
| 106 | */ |
Leon Scroggins III | d1ad5e6 | 2014-05-05 12:50:38 -0400 | [diff] [blame] | 107 | class SkiaComposeShader { |
| 108 | public: |
| 109 | static void describe(Caches* caches, ProgramDescription& description, |
| 110 | const Extensions& extensions, const SkShader& shader); |
| 111 | static void setupProgram(Caches* caches, const mat4& modelViewMatrix, |
| 112 | GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); |
| 113 | }; // class SkiaComposeShader |
Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 114 | |
| 115 | }; // namespace uirenderer |
| 116 | }; // namespace android |
| 117 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 118 | #endif // ANDROID_HWUI_SKIA_SHADER_H |