blob: a375542554cd2e62773d302505cd35e185d69c35 [file] [log] [blame]
Romain Guy06f96e22010-07-30 19:18:16 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_SKIA_SHADER_H
18#define ANDROID_HWUI_SKIA_SHADER_H
Romain Guy06f96e22010-07-30 19:18:16 -070019
20#include <SkShader.h>
21#include <SkXfermode.h>
22
23#include <GLES2/gl2.h>
24
Romain Guy79537452011-10-12 13:48:51 -070025#include <cutils/compiler.h>
26
Romain Guy06f96e22010-07-30 19:18:16 -070027namespace android {
28namespace uirenderer {
29
Romain Guy8aa195d2013-06-04 18:00:09 -070030class Caches;
Tom Hudson2dc236b2014-10-15 15:46:42 -040031class Extensions;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040032class Layer;
Romain Guy06f96e22010-07-30 19:18:16 -070033
34/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040035 * Type of Skia shader in use.
Romain Guy06f96e22010-07-30 19:18:16 -070036 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040037enum SkiaShaderType {
38 kNone_SkiaShaderType,
39 kBitmap_SkiaShaderType,
40 kGradient_SkiaShaderType,
41 kCompose_SkiaShaderType,
42 kLayer_SkiaShaderType
43};
44
Chris Craik564acf72014-01-02 16:46:18 -080045class SkiaShader {
46public:
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040047 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};
Romain Guy06f96e22010-07-30 19:18:16 -070053
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040054class 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.
Chet Haase5c13d892010-10-08 08:37:55 -070063 }
64
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040065};
Romain Guy06f96e22010-07-30 19:18:16 -070066/**
Chris Craik3f0854292014-04-15 16:18:08 -070067 * A shader that draws a layer.
68 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040069class 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
Chris Craik3f0854292014-04-15 16:18:08 -070076
77/**
Romain Guy06f96e22010-07-30 19:18:16 -070078 * A shader that draws a bitmap.
79 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040080class 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);
Romain Guy06f96e22010-07-30 19:18:16 -070086
Romain Guy06f96e22010-07-30 19:18:16 -070087
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040088}; // class SkiaBitmapShader
Romain Guy06f96e22010-07-30 19:18:16 -070089
90/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040091 * A shader that draws one of three types of gradient, depending on shader param.
Romain Guy06f96e22010-07-30 19:18:16 -070092 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040093class 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};
Romain Guyddb80be2010-09-20 19:04:33 -0700100
101/**
Romain Guy06f96e22010-07-30 19:18:16 -0700102 * A shader that draws two shaders, composited with an xfermode.
103 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400104class 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
Romain Guy06f96e22010-07-30 19:18:16 -0700111
112}; // namespace uirenderer
113}; // namespace android
114
Romain Guy5b3b3522010-10-27 18:57:51 -0700115#endif // ANDROID_HWUI_SKIA_SHADER_H