Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_LAYER_H |
| 18 | #define ANDROID_HWUI_LAYER_H |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 19 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 22 | #include <GLES2/gl2.h> |
| 23 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 24 | #include <ui/Region.h> |
| 25 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 26 | #include <SkXfermode.h> |
| 27 | |
| 28 | #include "Rect.h" |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 29 | #include "SkiaColorFilter.h" |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 30 | #include "Vertex.h" |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 31 | |
| 32 | namespace android { |
| 33 | namespace uirenderer { |
| 34 | |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | // Layers |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 40 | * A layer has dimensions and is backed by an OpenGL texture or FBO. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 41 | */ |
| 42 | struct Layer { |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 43 | Layer(const uint32_t layerWidth, const uint32_t layerHeight): |
| 44 | width(layerWidth), height(layerHeight) { |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 45 | mesh = NULL; |
| 46 | meshIndices = NULL; |
| 47 | meshElementCount = 0; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 48 | isCacheable = true; |
| 49 | isTextureLayer = false; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 50 | renderTarget = GL_TEXTURE_2D; |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ~Layer() { |
| 54 | if (mesh) delete mesh; |
| 55 | if (meshIndices) delete meshIndices; |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 58 | /** |
Romain Guy | 9fc2781 | 2011-04-27 14:21:41 -0700 | [diff] [blame] | 59 | * Sets this layer's region to a rectangle. Computes the appropriate |
| 60 | * texture coordinates. |
| 61 | */ |
| 62 | void setRegionAsRect() { |
| 63 | const android::Rect& bounds = region.getBounds(); |
| 64 | regionRect.set(bounds.leftTop().x, bounds.leftTop().y, |
| 65 | bounds.rightBottom().x, bounds.rightBottom().y); |
| 66 | |
| 67 | const float texX = 1.0f / float(width); |
| 68 | const float texY = 1.0f / float(height); |
| 69 | const float height = layer.getHeight(); |
| 70 | texCoords.set( |
| 71 | regionRect.left * texX, (height - regionRect.top) * texY, |
| 72 | regionRect.right * texX, (height - regionRect.bottom) * texY); |
| 73 | } |
| 74 | |
| 75 | /** |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 76 | * Bounds of the layer. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 77 | */ |
| 78 | Rect layer; |
| 79 | /** |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 80 | * Texture coordinates of the layer. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 81 | */ |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 82 | Rect texCoords; |
| 83 | |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 84 | /** |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 85 | * Name of the FBO used to render the layer. If the name is 0 |
| 86 | * this layer is not backed by an FBO, but a simple texture. |
| 87 | */ |
| 88 | GLuint fbo; |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 89 | |
Romain Guy | eb99356 | 2010-10-05 18:14:38 -0700 | [diff] [blame] | 90 | /** |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 91 | * Opacity of the layer. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 92 | */ |
Romain Guy | f607bdc | 2010-09-10 19:20:06 -0700 | [diff] [blame] | 93 | int alpha; |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Blending mode of the layer. |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 96 | */ |
| 97 | SkXfermode::Mode mode; |
| 98 | /** |
| 99 | * Indicates whether this layer should be blended. |
| 100 | */ |
| 101 | bool blend; |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 102 | |
Romain Guy | 38c85b9 | 2010-09-22 22:48:20 -0700 | [diff] [blame] | 103 | /** |
Romain Guy | 0bb5667 | 2010-10-01 00:25:02 -0700 | [diff] [blame] | 104 | * Indicates whether this layer has been used already. |
Romain Guy | 38c85b9 | 2010-09-22 22:48:20 -0700 | [diff] [blame] | 105 | */ |
| 106 | bool empty; |
Romain Guy | 8550c4c | 2010-10-08 15:49:53 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Name of the texture used to render the layer. |
| 110 | */ |
| 111 | GLuint texture; |
| 112 | /** |
| 113 | * Width of the layer texture. |
| 114 | */ |
| 115 | uint32_t width; |
| 116 | /** |
| 117 | * Height of the layer texture. |
| 118 | */ |
| 119 | uint32_t height; |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Dirty region indicating what parts of the layer |
| 123 | * have been drawn. |
| 124 | */ |
| 125 | Region region; |
Romain Guy | 4066767 | 2011-03-18 14:34:03 -0700 | [diff] [blame] | 126 | /** |
| 127 | * If the region is a rectangle, coordinates of the |
| 128 | * region are stored here. |
| 129 | */ |
| 130 | Rect regionRect; |
Romain Guy | 171c592 | 2011-01-06 10:04:23 -0800 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Color filter used to draw this layer. Optional. |
| 134 | */ |
| 135 | SkiaColorFilter* colorFilter; |
Romain Guy | f219da5 | 2011-01-16 12:54:25 -0800 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * If the layer can be rendered as a mesh, this is non-null. |
| 139 | */ |
| 140 | TextureVertex* mesh; |
| 141 | uint16_t* meshIndices; |
| 142 | GLsizei meshElementCount; |
Romain Guy | aa6c24c | 2011-04-28 18:40:04 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * If set to true (by default), the layer can be reused. |
| 146 | */ |
| 147 | bool isCacheable; |
| 148 | |
| 149 | /** |
| 150 | * When set to true, this layer must be treated as a texture |
| 151 | * layer. |
| 152 | */ |
| 153 | bool isTextureLayer; |
| 154 | |
| 155 | /** |
| 156 | * Optional texture coordinates transform. |
| 157 | */ |
| 158 | mat4 texTransform; |
Romain Guy | 8f0095c | 2011-05-02 17:24:22 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Indicates the render target. |
| 162 | */ |
| 163 | GLenum renderTarget; |
Romain Guy | dda5702 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 164 | }; // struct Layer |
| 165 | |
| 166 | }; // namespace uirenderer |
| 167 | }; // namespace android |
| 168 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 169 | #endif // ANDROID_HWUI_LAYER_H |