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