Layer.h revision 8f0095cd33558e9cc8a440047908e53b68906f5f
1dda570201ac851dd85af3861f7e575721d3345daRomain Guy/* 2dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Copyright (C) 2010 The Android Open Source Project 3dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 4dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5dda570201ac851dd85af3861f7e575721d3345daRomain Guy * you may not use this file except in compliance with the License. 6dda570201ac851dd85af3861f7e575721d3345daRomain Guy * You may obtain a copy of the License at 7dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 8dda570201ac851dd85af3861f7e575721d3345daRomain Guy * http://www.apache.org/licenses/LICENSE-2.0 9dda570201ac851dd85af3861f7e575721d3345daRomain Guy * 10dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Unless required by applicable law or agreed to in writing, software 11dda570201ac851dd85af3861f7e575721d3345daRomain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12dda570201ac851dd85af3861f7e575721d3345daRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13dda570201ac851dd85af3861f7e575721d3345daRomain Guy * See the License for the specific language governing permissions and 14dda570201ac851dd85af3861f7e575721d3345daRomain Guy * limitations under the License. 15dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 16dda570201ac851dd85af3861f7e575721d3345daRomain Guy 175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_LAYER_H 185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_LAYER_H 19dda570201ac851dd85af3861f7e575721d3345daRomain Guy 20f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include <sys/types.h> 21f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 22dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include <GLES2/gl2.h> 23dda570201ac851dd85af3861f7e575721d3345daRomain Guy 245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#include <ui/Region.h> 255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 26dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include <SkXfermode.h> 27dda570201ac851dd85af3861f7e575721d3345daRomain Guy 28dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "Rect.h" 29171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy#include "SkiaColorFilter.h" 30f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy#include "Vertex.h" 31dda570201ac851dd85af3861f7e575721d3345daRomain Guy 32dda570201ac851dd85af3861f7e575721d3345daRomain Guynamespace android { 33dda570201ac851dd85af3861f7e575721d3345daRomain Guynamespace uirenderer { 34dda570201ac851dd85af3861f7e575721d3345daRomain Guy 358550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy/////////////////////////////////////////////////////////////////////////////// 368550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy// Layers 378550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy/////////////////////////////////////////////////////////////////////////////// 38dda570201ac851dd85af3861f7e575721d3345daRomain Guy 39dda570201ac851dd85af3861f7e575721d3345daRomain Guy/** 40eb99356a0548684a501766e6a524529ab93304c8Romain Guy * A layer has dimensions and is backed by an OpenGL texture or FBO. 41dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 42dda570201ac851dd85af3861f7e575721d3345daRomain Guystruct Layer { 438550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy Layer(const uint32_t layerWidth, const uint32_t layerHeight): 448550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy width(layerWidth), height(layerHeight) { 45f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy mesh = NULL; 46f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy meshIndices = NULL; 47f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy meshElementCount = 0; 48aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy isCacheable = true; 49aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy isTextureLayer = false; 508f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy renderTarget = GL_TEXTURE_2D; 51f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy } 52f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 53f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy ~Layer() { 54f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy if (mesh) delete mesh; 55f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy if (meshIndices) delete meshIndices; 568550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy } 578550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 58dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 599fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy * Sets this layer's region to a rectangle. Computes the appropriate 609fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy * texture coordinates. 619fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy */ 629fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy void setRegionAsRect() { 639fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const android::Rect& bounds = region.getBounds(); 649fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.set(bounds.leftTop().x, bounds.leftTop().y, 659fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy bounds.rightBottom().x, bounds.rightBottom().y); 669fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy 679fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const float texX = 1.0f / float(width); 689fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const float texY = 1.0f / float(height); 699fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy const float height = layer.getHeight(); 709fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy texCoords.set( 719fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.left * texX, (height - regionRect.top) * texY, 729fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy regionRect.right * texX, (height - regionRect.bottom) * texY); 739fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy } 749fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy 759fc27819d75e24ad63d7b383d80f5cb66a577a0dRomain Guy /** 768550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Bounds of the layer. 77dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 78dda570201ac851dd85af3861f7e575721d3345daRomain Guy Rect layer; 79dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 808550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Texture coordinates of the layer. 81dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 828550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy Rect texCoords; 838550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 84dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 85eb99356a0548684a501766e6a524529ab93304c8Romain Guy * Name of the FBO used to render the layer. If the name is 0 86eb99356a0548684a501766e6a524529ab93304c8Romain Guy * this layer is not backed by an FBO, but a simple texture. 87eb99356a0548684a501766e6a524529ab93304c8Romain Guy */ 88eb99356a0548684a501766e6a524529ab93304c8Romain Guy GLuint fbo; 898550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 90eb99356a0548684a501766e6a524529ab93304c8Romain Guy /** 91dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Opacity of the layer. 92dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 93f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy int alpha; 94dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 95dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Blending mode of the layer. 96dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 97dda570201ac851dd85af3861f7e575721d3345daRomain Guy SkXfermode::Mode mode; 98dda570201ac851dd85af3861f7e575721d3345daRomain Guy /** 99dda570201ac851dd85af3861f7e575721d3345daRomain Guy * Indicates whether this layer should be blended. 100dda570201ac851dd85af3861f7e575721d3345daRomain Guy */ 101dda570201ac851dd85af3861f7e575721d3345daRomain Guy bool blend; 1028550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 10338c85b907a478af96d71b9a5df5a2066b8475311Romain Guy /** 1040bb5667b4ef91fefd0500fae0186789d15d54e0eRomain Guy * Indicates whether this layer has been used already. 10538c85b907a478af96d71b9a5df5a2066b8475311Romain Guy */ 10638c85b907a478af96d71b9a5df5a2066b8475311Romain Guy bool empty; 1078550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy 1088550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy /** 1098550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Name of the texture used to render the layer. 1108550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy */ 1118550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy GLuint texture; 1128550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy /** 1138550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Width of the layer texture. 1148550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy */ 1158550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy uint32_t width; 1168550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy /** 1178550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy * Height of the layer texture. 1188550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy */ 1198550c4c7b5952b7a4e1e0ede95c9492d03099a13Romain Guy uint32_t height; 1205b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy 1215b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy /** 1225b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * Dirty region indicating what parts of the layer 1235b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy * have been drawn. 1245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy */ 1255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy Region region; 12640667676e542a9daeafeac9904c30004e8706fd3Romain Guy /** 12740667676e542a9daeafeac9904c30004e8706fd3Romain Guy * If the region is a rectangle, coordinates of the 12840667676e542a9daeafeac9904c30004e8706fd3Romain Guy * region are stored here. 12940667676e542a9daeafeac9904c30004e8706fd3Romain Guy */ 13040667676e542a9daeafeac9904c30004e8706fd3Romain Guy Rect regionRect; 131171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy 132171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy /** 133171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy * Color filter used to draw this layer. Optional. 134171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy */ 135171c592f0b7066acf279863c8a52ddabea49d3dbRomain Guy SkiaColorFilter* colorFilter; 136f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy 137f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy /** 138f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy * If the layer can be rendered as a mesh, this is non-null. 139f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy */ 140f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy TextureVertex* mesh; 141f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy uint16_t* meshIndices; 142f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy GLsizei meshElementCount; 143aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 144aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 145aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * If set to true (by default), the layer can be reused. 146aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 147aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy bool isCacheable; 148aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 149aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 150aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * When set to true, this layer must be treated as a texture 151aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * layer. 152aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 153aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy bool isTextureLayer; 154aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy 155aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy /** 156aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy * Optional texture coordinates transform. 157aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy */ 158aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy mat4 texTransform; 1598f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy 1608f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy /** 1618f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy * Indicates the render target. 1628f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy */ 1638f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy GLenum renderTarget; 164dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // struct Layer 165dda570201ac851dd85af3861f7e575721d3345daRomain Guy 166dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // namespace uirenderer 167dda570201ac851dd85af3861f7e575721d3345daRomain Guy}; // namespace android 168dda570201ac851dd85af3861f7e575721d3345daRomain Guy 1695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_LAYER_H 170