blob: d2f37cda9cb3c575820c4d224d6ff88b02ac76c3 [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
Chris Craik922d3a72015-02-13 17:47:21 -080020#include "FloatColor.h"
21#include "Matrix.h"
Romain Guy06f96e22010-07-30 19:18:16 -070022
23#include <GLES2/gl2.h>
Chris Craik922d3a72015-02-13 17:47:21 -080024#include <SkShader.h>
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;
Chris Craik922d3a72015-02-13 17:47:21 -080033class Texture;
Tom Hudson73edbfe2014-10-16 09:10:41 -040034struct ProgramDescription;
Romain Guy06f96e22010-07-30 19:18:16 -070035
36/**
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040037 * Type of Skia shader in use.
Chris Craik922d3a72015-02-13 17:47:21 -080038 *
39 * Note that kBitmap | kGradient = kCompose, since Compose implies
40 * both its component types are in use simultaneously. No other
41 * composition of multiple types is supported.
Romain Guy06f96e22010-07-30 19:18:16 -070042 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040043enum SkiaShaderType {
Chris Craik922d3a72015-02-13 17:47:21 -080044 kNone_SkiaShaderType = 0,
45 kBitmap_SkiaShaderType = 1,
46 kGradient_SkiaShaderType = 2,
47 kCompose_SkiaShaderType = kBitmap_SkiaShaderType | kGradient_SkiaShaderType,
48 kLayer_SkiaShaderType = 4,
49};
50
51struct SkiaShaderData {
52 SkiaShaderType skiaShaderType;
53 struct BitmapShaderData {
54 Texture* bitmapTexture;
55 GLuint bitmapSampler;
56 GLenum wrapS;
57 GLenum wrapT;
58
59 Matrix4 textureTransform;
60 float textureDimension[2];
61 } bitmapData;
62 struct GradientShaderData {
63 Matrix4 screenSpace;
Chris Craik922d3a72015-02-13 17:47:21 -080064
65 // simple gradient
66 FloatColor startColor;
67 FloatColor endColor;
68
69 // complex gradient
70 Texture* gradientTexture;
71 GLuint gradientSampler;
72 GLenum wrapST;
Chris Craik922d3a72015-02-13 17:47:21 -080073 } gradientData;
74 struct LayerShaderData {
75 Layer* layer;
76 GLuint bitmapSampler;
77 GLenum wrapS;
78 GLenum wrapT;
79
80 Matrix4 textureTransform;
81 float textureDimension[2];
82 } layerData;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040083};
84
Chris Craik564acf72014-01-02 16:46:18 -080085class SkiaShader {
86public:
Chris Craik53e51e42015-06-01 10:35:35 -070087 static void store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
Chris Craik922d3a72015-02-13 17:47:21 -080088 GLuint* textureUnit, ProgramDescription* description,
89 SkiaShaderData* outData);
Romain Guy253f2c22016-09-28 17:34:42 -070090 static void apply(Caches& caches, const SkiaShaderData& data,
91 const GLsizei width, const GLsizei height);
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040092};
Romain Guy06f96e22010-07-30 19:18:16 -070093
Romain Guy06f96e22010-07-30 19:18:16 -070094}; // namespace uirenderer
95}; // namespace android
96
Romain Guy5b3b3522010-10-27 18:57:51 -070097#endif // ANDROID_HWUI_SKIA_SHADER_H