blob: 034c3f652e164820e5bf20b6cdf29b87c61f1d4f [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:
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.
Chet Haase5c13d892010-10-08 08:37:55 -070067 }
68
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040069};
Romain Guy06f96e22010-07-30 19:18:16 -070070/**
Chris Craik3f0854292014-04-15 16:18:08 -070071 * A shader that draws a layer.
72 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040073class 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
Chris Craik3f0854292014-04-15 16:18:08 -070080
81/**
Romain Guy06f96e22010-07-30 19:18:16 -070082 * A shader that draws a bitmap.
83 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040084class 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);
Romain Guy06f96e22010-07-30 19:18:16 -070090
Romain Guy06f96e22010-07-30 19:18:16 -070091
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040092}; // class SkiaBitmapShader
Romain Guy06f96e22010-07-30 19:18:16 -070093
94/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040095 * A shader that draws one of three types of gradient, depending on shader param.
Romain Guy06f96e22010-07-30 19:18:16 -070096 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040097class 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};
Romain Guyddb80be2010-09-20 19:04:33 -0700104
105/**
Romain Guy06f96e22010-07-30 19:18:16 -0700106 * A shader that draws two shaders, composited with an xfermode.
107 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -0400108class 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
Romain Guy06f96e22010-07-30 19:18:16 -0700115
116}; // namespace uirenderer
117}; // namespace android
118
Romain Guy5b3b3522010-10-27 18:57:51 -0700119#endif // ANDROID_HWUI_SKIA_SHADER_H