blob: 5854289f49a7fe642041a0fcf5bd4e295ff12334 [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>
25#include <SkXfermode.h>
Romain Guy79537452011-10-12 13:48:51 -070026#include <cutils/compiler.h>
27
Romain Guy06f96e22010-07-30 19:18:16 -070028namespace android {
29namespace uirenderer {
30
Romain Guy8aa195d2013-06-04 18:00:09 -070031class Caches;
Tom Hudson2dc236b2014-10-15 15:46:42 -040032class Extensions;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040033class Layer;
Chris Craik922d3a72015-02-13 17:47:21 -080034class Texture;
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.
Chris Craik922d3a72015-02-13 17:47:21 -080039 *
40 * Note that kBitmap | kGradient = kCompose, since Compose implies
41 * both its component types are in use simultaneously. No other
42 * composition of multiple types is supported.
Romain Guy06f96e22010-07-30 19:18:16 -070043 */
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040044enum SkiaShaderType {
Chris Craik922d3a72015-02-13 17:47:21 -080045 kNone_SkiaShaderType = 0,
46 kBitmap_SkiaShaderType = 1,
47 kGradient_SkiaShaderType = 2,
48 kCompose_SkiaShaderType = kBitmap_SkiaShaderType | kGradient_SkiaShaderType,
49 kLayer_SkiaShaderType = 4,
50};
51
52struct SkiaShaderData {
53 SkiaShaderType skiaShaderType;
54 struct BitmapShaderData {
55 Texture* bitmapTexture;
56 GLuint bitmapSampler;
57 GLenum wrapS;
58 GLenum wrapT;
59
60 Matrix4 textureTransform;
61 float textureDimension[2];
62 } bitmapData;
63 struct GradientShaderData {
64 Matrix4 screenSpace;
Chris Craik922d3a72015-02-13 17:47:21 -080065
66 // simple gradient
67 FloatColor startColor;
68 FloatColor endColor;
69
70 // complex gradient
71 Texture* gradientTexture;
72 GLuint gradientSampler;
73 GLenum wrapST;
Chris Craik922d3a72015-02-13 17:47:21 -080074 } gradientData;
75 struct LayerShaderData {
76 Layer* layer;
77 GLuint bitmapSampler;
78 GLenum wrapS;
79 GLenum wrapT;
80
81 Matrix4 textureTransform;
82 float textureDimension[2];
83 } layerData;
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040084};
85
Chris Craik564acf72014-01-02 16:46:18 -080086class SkiaShader {
87public:
Chris Craik53e51e42015-06-01 10:35:35 -070088 static void store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
Chris Craik922d3a72015-02-13 17:47:21 -080089 GLuint* textureUnit, ProgramDescription* description,
90 SkiaShaderData* outData);
Romain Guy253f2c22016-09-28 17:34:42 -070091 static void apply(Caches& caches, const SkiaShaderData& data,
92 const GLsizei width, const GLsizei height);
Leon Scroggins IIId1ad5e62014-05-05 12:50:38 -040093};
Romain Guy06f96e22010-07-30 19:18:16 -070094
Romain Guy06f96e22010-07-30 19:18:16 -070095}; // namespace uirenderer
96}; // namespace android
97
Romain Guy5b3b3522010-10-27 18:57:51 -070098#endif // ANDROID_HWUI_SKIA_SHADER_H