• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ANDROID_HWUI_SKIA_SHADER_H
18 #define ANDROID_HWUI_SKIA_SHADER_H
19 
20 #include "FloatColor.h"
21 #include "Matrix.h"
22 
23 #include <GLES2/gl2.h>
24 #include <SkShader.h>
25 #include <cutils/compiler.h>
26 
27 namespace android {
28 namespace uirenderer {
29 
30 class Caches;
31 class Extensions;
32 class Texture;
33 struct ProgramDescription;
34 
35 /**
36  * Type of Skia shader in use.
37  *
38  * Note that kBitmap | kGradient = kCompose, since Compose implies
39  * both its component types are in use simultaneously. No other
40  * composition of multiple types is supported.
41  */
42 enum SkiaShaderType {
43     kNone_SkiaShaderType = 0,
44     kBitmap_SkiaShaderType = 1,
45     kGradient_SkiaShaderType = 2,
46     kCompose_SkiaShaderType = kBitmap_SkiaShaderType | kGradient_SkiaShaderType,
47 };
48 
49 struct SkiaShaderData {
50     SkiaShaderType skiaShaderType;
51     struct BitmapShaderData {
52         Texture* bitmapTexture;
53         GLuint bitmapSampler;
54         GLenum wrapS;
55         GLenum wrapT;
56 
57         Matrix4 textureTransform;
58         float textureDimension[2];
59     } bitmapData;
60     struct GradientShaderData {
61         Matrix4 screenSpace;
62 
63         // simple gradient
64         FloatColor startColor;
65         FloatColor endColor;
66 
67         // complex gradient
68         Texture* gradientTexture;
69         GLuint gradientSampler;
70         GLenum wrapST;
71     } gradientData;
72 };
73 
74 class SkiaShader {
75 public:
76     static void store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
77             GLuint* textureUnit, ProgramDescription* description,
78             SkiaShaderData* outData);
79     static void apply(Caches& caches, const SkiaShaderData& data,
80             const GLsizei width, const GLsizei height);
81 };
82 
83 }; // namespace uirenderer
84 }; // namespace android
85 
86 #endif // ANDROID_HWUI_SKIA_SHADER_H
87