blob: 631305f77fe8f2c4ea7739a094d1e579ea930902 [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 -070027#include "Extensions.h"
28#include "ProgramCache.h"
29#include "TextureCache.h"
30#include "GradientCache.h"
Romain Guy06f96e22010-07-30 19:18:16 -070031
32namespace android {
33namespace uirenderer {
34
Romain Guy8aa195d2013-06-04 18:00:09 -070035class Caches;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040036class Layer;
Romain Guy06f96e22010-07-30 19:18:16 -070037
38/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040039 * Type of Skia shader in use.
Romain Guy06f96e22010-07-30 19:18:16 -070040 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040041enum SkiaShaderType {
42 kNone_SkiaShaderType,
43 kBitmap_SkiaShaderType,
44 kGradient_SkiaShaderType,
45 kCompose_SkiaShaderType,
46 kLayer_SkiaShaderType
47};
48
Chris Craik564acf72014-01-02 16:46:18 -080049class SkiaShader {
50public:
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040051 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};
Romain Guy06f96e22010-07-30 19:18:16 -070057
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040058class InvalidSkiaShader {
59public:
John Reckf088c342014-12-12 09:49:29 -080060 static void describe(Caches* caches, ProgramDescription& description,
61 const Extensions& extensions, const SkShader& shader) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040062 // This shader is unsupported. Skip it.
63 }
John Reckf088c342014-12-12 09:49:29 -080064 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
65 GLuint* textureUnit, const Extensions& extensions,
66 const SkShader& shader) {
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040067 // This shader is unsupported. Skip it.
Chet Haase5c13d892010-10-08 08:37:55 -070068 }
69
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040070};
Romain Guy06f96e22010-07-30 19:18:16 -070071/**
Chris Craik3f0854292014-04-15 16:18:08 -070072 * A shader that draws a layer.
73 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040074class SkiaLayerShader {
75public:
76 static void describe(Caches* caches, ProgramDescription& description,
77 const Extensions& extensions, const SkShader& shader);
78 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
79 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
80}; // class SkiaLayerShader
Chris Craik3f0854292014-04-15 16:18:08 -070081
82/**
Romain Guy06f96e22010-07-30 19:18:16 -070083 * A shader that draws a bitmap.
84 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040085class SkiaBitmapShader {
86public:
87 static void describe(Caches* caches, ProgramDescription& description,
88 const Extensions& extensions, const SkShader& shader);
89 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
90 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
Romain Guy06f96e22010-07-30 19:18:16 -070091
Romain Guy06f96e22010-07-30 19:18:16 -070092
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040093}; // class SkiaBitmapShader
Romain Guy06f96e22010-07-30 19:18:16 -070094
95/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040096 * A shader that draws one of three types of gradient, depending on shader param.
Romain Guy06f96e22010-07-30 19:18:16 -070097 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040098class SkiaGradientShader {
99public:
100 static void describe(Caches* caches, ProgramDescription& description,
101 const Extensions& extensions, const SkShader& shader);
102 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
103 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
104};
Romain Guyddb80be2010-09-20 19:04:33 -0700105
106/**
Romain Guy06f96e22010-07-30 19:18:16 -0700107 * A shader that draws two shaders, composited with an xfermode.
108 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400109class SkiaComposeShader {
110public:
111 static void describe(Caches* caches, ProgramDescription& description,
112 const Extensions& extensions, const SkShader& shader);
113 static void setupProgram(Caches* caches, const mat4& modelViewMatrix,
114 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader);
115}; // class SkiaComposeShader
Romain Guy06f96e22010-07-30 19:18:16 -0700116
117}; // namespace uirenderer
118}; // namespace android
119
Romain Guy5b3b3522010-10-27 18:57:51 -0700120#endif // ANDROID_HWUI_SKIA_SHADER_H