SkiaShader.h revision 253f2c213f6ecda63b6872aee77bd30d5ec07c82
1/*
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
17#ifndef ANDROID_HWUI_SKIA_SHADER_H
18#define ANDROID_HWUI_SKIA_SHADER_H
19
20#include "FloatColor.h"
21#include "Matrix.h"
22
23#include <GLES2/gl2.h>
24#include <SkShader.h>
25#include <SkXfermode.h>
26#include <cutils/compiler.h>
27
28namespace android {
29namespace uirenderer {
30
31class Caches;
32class Extensions;
33class Layer;
34class Texture;
35struct ProgramDescription;
36
37/**
38 * Type of Skia shader in use.
39 *
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.
43 */
44enum SkiaShaderType {
45    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;
65
66        // simple gradient
67        FloatColor startColor;
68        FloatColor endColor;
69
70        // complex gradient
71        Texture* gradientTexture;
72        GLuint gradientSampler;
73        GLenum wrapST;
74    } 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;
84};
85
86class SkiaShader {
87public:
88    static void store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
89            GLuint* textureUnit, ProgramDescription* description,
90            SkiaShaderData* outData);
91    static void apply(Caches& caches, const SkiaShaderData& data,
92            const GLsizei width, const GLsizei height);
93};
94
95}; // namespace uirenderer
96}; // namespace android
97
98#endif // ANDROID_HWUI_SKIA_SHADER_H
99