SkiaShader.h revision 2dc236b2bae13b9a0ed9b3f7320502aecd7983b3
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 <SkShader.h>
21#include <SkXfermode.h>
22
23#include <GLES2/gl2.h>
24
25#include <cutils/compiler.h>
26
27namespace android {
28namespace uirenderer {
29
30class Caches;
31class Extensions;
32class Layer;
33
34/**
35 * Type of Skia shader in use.
36 */
37enum SkiaShaderType {
38    kNone_SkiaShaderType,
39    kBitmap_SkiaShaderType,
40    kGradient_SkiaShaderType,
41    kCompose_SkiaShaderType,
42    kLayer_SkiaShaderType
43};
44
45class SkiaShader {
46public:
47    static SkiaShaderType getType(const SkShader& shader);
48    static void describe(Caches* caches, ProgramDescription& description,
49            const Extensions& extensions, const SkShader& shader);
50    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
51            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
52};
53
54class InvalidSkiaShader {
55public:
56    static void describe(Caches* caches, ProgramDescription& description,
57            const Extensions& extensions, const SkShader& shader) {
58        // This shader is unsupported. Skip it.
59    }
60    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
61            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader) {
62        // This shader is unsupported. Skip it.
63    }
64
65};
66/**
67 * A shader that draws a layer.
68 */
69class SkiaLayerShader {
70public:
71    static void describe(Caches* caches, ProgramDescription& description,
72            const Extensions& extensions, const SkShader& shader);
73    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
74            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
75}; // class SkiaLayerShader
76
77/**
78 * A shader that draws a bitmap.
79 */
80class SkiaBitmapShader {
81public:
82    static void describe(Caches* caches, ProgramDescription& description,
83            const Extensions& extensions, const SkShader& shader);
84    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
85            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
86
87
88}; // class SkiaBitmapShader
89
90/**
91 * A shader that draws one of three types of gradient, depending on shader param.
92 */
93class SkiaGradientShader {
94public:
95    static void describe(Caches* caches, ProgramDescription& description,
96            const Extensions& extensions, const SkShader& shader);
97    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
98            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
99};
100
101/**
102 * A shader that draws two shaders, composited with an xfermode.
103 */
104class SkiaComposeShader {
105public:
106    static void describe(Caches* caches, ProgramDescription& description,
107            const Extensions& extensions, const SkShader& shader);
108    static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
109            GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
110}; // class SkiaComposeShader
111
112}; // namespace uirenderer
113}; // namespace android
114
115#endif // ANDROID_HWUI_SKIA_SHADER_H
116