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