SkiaShader.h revision d1ad5e62fda248c6d185cde3cb6d9f01a223066c
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
27#include "Extensions.h"
28#include "ProgramCache.h"
29#include "TextureCache.h"
30#include "GradientCache.h"
31
32namespace android {
33namespace uirenderer {
34
35class Caches;
36class Layer;
37
38/**
39 * Type of Skia shader in use.
40 */
41enum SkiaShaderType {
42    kNone_SkiaShaderType,
43    kBitmap_SkiaShaderType,
44    kGradient_SkiaShaderType,
45    kCompose_SkiaShaderType,
46    kLayer_SkiaShaderType
47};
48
49class SkiaShader {
50public:
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};
57
58class InvalidSkiaShader {
59public:
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.
67    }
68
69};
70/**
71 * A shader that draws a layer.
72 */
73class SkiaLayerShader {
74public:
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
80
81/**
82 * A shader that draws a bitmap.
83 */
84class SkiaBitmapShader {
85public:
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);
90
91
92}; // class SkiaBitmapShader
93
94/**
95 * A shader that draws one of three types of gradient, depending on shader param.
96 */
97class SkiaGradientShader {
98public:
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};
104
105/**
106 * A shader that draws two shaders, composited with an xfermode.
107 */
108class SkiaComposeShader {
109public:
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
115
116}; // namespace uirenderer
117}; // namespace android
118
119#endif // ANDROID_HWUI_SKIA_SHADER_H
120