blob: e110ca57d09b26331bfb00302f2a449e25a634c0 [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
Tom Hudson73edbfe2014-10-16 09:10:41 -040027#include "Matrix.h"
28
Romain Guy06f96e22010-07-30 19:18:16 -070029namespace android {
30namespace uirenderer {
31
Romain Guy8aa195d2013-06-04 18:00:09 -070032class Caches;
Tom Hudson2dc236b2014-10-15 15:46:42 -040033class Extensions;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040034class Layer;
Tom Hudson73edbfe2014-10-16 09:10:41 -040035struct ProgramDescription;
Romain Guy06f96e22010-07-30 19:18:16 -070036
37/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040038 * Type of Skia shader in use.
Romain Guy06f96e22010-07-30 19:18:16 -070039 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040040enum SkiaShaderType {
41 kNone_SkiaShaderType,
42 kBitmap_SkiaShaderType,
43 kGradient_SkiaShaderType,
44 kCompose_SkiaShaderType,
45 kLayer_SkiaShaderType
46};
47
Chris Craik564acf72014-01-02 16:46:18 -080048class SkiaShader {
49public:
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040050 static SkiaShaderType getType(const SkShader& shader);
51 static void describe(Caches* caches, ProgramDescription& description,
52 const Extensions& extensions, const SkShader& shader);
53 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
54 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
55};
Romain Guy06f96e22010-07-30 19:18:16 -070056
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040057class InvalidSkiaShader {
58public:
Andreas Gampe64bb4132014-11-22 00:35:09 +000059 static void describe(Caches* caches, ProgramDescription& description,
60 const Extensions& extensions, const SkShader& shader) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040061 // This shader is unsupported. Skip it.
62 }
Andreas Gampe64bb4132014-11-22 00:35:09 +000063 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
64 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040065 // This shader is unsupported. Skip it.
Chet Haase5c13d892010-10-08 08:37:55 -070066 }
67
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040068};
Romain Guy06f96e22010-07-30 19:18:16 -070069/**
Chris Craik3f0854292014-04-15 16:18:08 -070070 * A shader that draws a layer.
71 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040072class SkiaLayerShader {
73public:
74 static void describe(Caches* caches, ProgramDescription& description,
75 const Extensions& extensions, const SkShader& shader);
76 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
77 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
78}; // class SkiaLayerShader
Chris Craik3f0854292014-04-15 16:18:08 -070079
80/**
Romain Guy06f96e22010-07-30 19:18:16 -070081 * A shader that draws a bitmap.
82 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040083class SkiaBitmapShader {
84public:
85 static void describe(Caches* caches, ProgramDescription& description,
86 const Extensions& extensions, const SkShader& shader);
87 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
88 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
Romain Guy06f96e22010-07-30 19:18:16 -070089
Romain Guy06f96e22010-07-30 19:18:16 -070090
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040091}; // class SkiaBitmapShader
Romain Guy06f96e22010-07-30 19:18:16 -070092
93/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040094 * A shader that draws one of three types of gradient, depending on shader param.
Romain Guy06f96e22010-07-30 19:18:16 -070095 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040096class SkiaGradientShader {
97public:
98 static void describe(Caches* caches, ProgramDescription& description,
99 const Extensions& extensions, const SkShader& shader);
100 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
101 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
102};
Romain Guyddb80be2010-09-20 19:04:33 -0700103
104/**
Romain Guy06f96e22010-07-30 19:18:16 -0700105 * A shader that draws two shaders, composited with an xfermode.
106 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400107class SkiaComposeShader {
108public:
109 static void describe(Caches* caches, ProgramDescription& description,
110 const Extensions& extensions, const SkShader& shader);
111 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
112 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
113}; // class SkiaComposeShader
Romain Guy06f96e22010-07-30 19:18:16 -0700114
115}; // namespace uirenderer
116}; // namespace android
117
Romain Guy5b3b3522010-10-27 18:57:51 -0700118#endif // ANDROID_HWUI_SKIA_SHADER_H