SkiaShader.h revision 64bb413a664001c95c8439cf097dc3033f4ed733
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 <SkShader.h> 21#include <SkXfermode.h> 22 23#include <GLES2/gl2.h> 24 25#include <cutils/compiler.h> 26 27#include "Matrix.h" 28 29namespace android { 30namespace uirenderer { 31 32class Caches; 33class Extensions; 34class Layer; 35struct ProgramDescription; 36 37/** 38 * Type of Skia shader in use. 39 */ 40enum SkiaShaderType { 41 kNone_SkiaShaderType, 42 kBitmap_SkiaShaderType, 43 kGradient_SkiaShaderType, 44 kCompose_SkiaShaderType, 45 kLayer_SkiaShaderType 46}; 47 48class SkiaShader { 49public: 50 static SkiaShaderType getType(const SkShader& shader); 51 static void describe(Caches* caches, ProgramDescription& description, 52 const Extensions& extensions, const SkShader& shader); 53 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 54 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); 55}; 56 57class InvalidSkiaShader { 58public: 59 static void describe(Caches* caches, ProgramDescription& description, 60 const Extensions& extensions, const SkShader& shader) { 61 // This shader is unsupported. Skip it. 62 } 63 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 64 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader) { 65 // This shader is unsupported. Skip it. 66 } 67 68}; 69/** 70 * A shader that draws a layer. 71 */ 72class SkiaLayerShader { 73public: 74 static void describe(Caches* caches, ProgramDescription& description, 75 const Extensions& extensions, const SkShader& shader); 76 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 77 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); 78}; // class SkiaLayerShader 79 80/** 81 * A shader that draws a bitmap. 82 */ 83class SkiaBitmapShader { 84public: 85 static void describe(Caches* caches, ProgramDescription& description, 86 const Extensions& extensions, const SkShader& shader); 87 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 88 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); 89 90 91}; // class SkiaBitmapShader 92 93/** 94 * A shader that draws one of three types of gradient, depending on shader param. 95 */ 96class SkiaGradientShader { 97public: 98 static void describe(Caches* caches, ProgramDescription& description, 99 const Extensions& extensions, const SkShader& shader); 100 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 101 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); 102}; 103 104/** 105 * A shader that draws two shaders, composited with an xfermode. 106 */ 107class SkiaComposeShader { 108public: 109 static void describe(Caches* caches, ProgramDescription& description, 110 const Extensions& extensions, const SkShader& shader); 111 static void setupProgram(Caches* caches, const mat4& modelViewMatrix, 112 GLuint* textureUnit, const Extensions& extensions, const SkShader& shader); 113}; // class SkiaComposeShader 114 115}; // namespace uirenderer 116}; // namespace android 117 118#endif // ANDROID_HWUI_SKIA_SHADER_H 119