blob: 0310bc344798e5660c1f5c1bb1b4a32b16301e6c [file] [log] [blame]
Romain Guydda57022010-07-06 11:39:32 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_LAYER_H
18#define ANDROID_HWUI_LAYER_H
Romain Guydda57022010-07-06 11:39:32 -070019
Romain Guyf7f93552010-07-08 19:17:03 -070020#include <sys/types.h>
21
Romain Guydda57022010-07-06 11:39:32 -070022#include <GLES2/gl2.h>
23
Romain Guy5b3b3522010-10-27 18:57:51 -070024#include <ui/Region.h>
25
Romain Guydda57022010-07-06 11:39:32 -070026#include <SkXfermode.h>
27
28#include "Rect.h"
Romain Guy171c5922011-01-06 10:04:23 -080029#include "SkiaColorFilter.h"
Romain Guyf219da52011-01-16 12:54:25 -080030#include "Vertex.h"
Romain Guydda57022010-07-06 11:39:32 -070031
32namespace android {
33namespace uirenderer {
34
Romain Guy8550c4c2010-10-08 15:49:53 -070035///////////////////////////////////////////////////////////////////////////////
36// Layers
37///////////////////////////////////////////////////////////////////////////////
Romain Guydda57022010-07-06 11:39:32 -070038
39/**
Romain Guyeb993562010-10-05 18:14:38 -070040 * A layer has dimensions and is backed by an OpenGL texture or FBO.
Romain Guydda57022010-07-06 11:39:32 -070041 */
42struct Layer {
Romain Guy8550c4c2010-10-08 15:49:53 -070043 Layer(const uint32_t layerWidth, const uint32_t layerHeight):
44 width(layerWidth), height(layerHeight) {
Romain Guyf219da52011-01-16 12:54:25 -080045 mesh = NULL;
46 meshIndices = NULL;
47 meshElementCount = 0;
Romain Guyaa6c24c2011-04-28 18:40:04 -070048 isCacheable = true;
49 isTextureLayer = false;
Romain Guy8f0095c2011-05-02 17:24:22 -070050 renderTarget = GL_TEXTURE_2D;
Romain Guyf219da52011-01-16 12:54:25 -080051 }
52
53 ~Layer() {
54 if (mesh) delete mesh;
55 if (meshIndices) delete meshIndices;
Romain Guy8550c4c2010-10-08 15:49:53 -070056 }
57
Romain Guydda57022010-07-06 11:39:32 -070058 /**
Romain Guy9fc27812011-04-27 14:21:41 -070059 * 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 Guy8550c4c2010-10-08 15:49:53 -070076 * Bounds of the layer.
Romain Guydda57022010-07-06 11:39:32 -070077 */
78 Rect layer;
79 /**
Romain Guy8550c4c2010-10-08 15:49:53 -070080 * Texture coordinates of the layer.
Romain Guydda57022010-07-06 11:39:32 -070081 */
Romain Guy8550c4c2010-10-08 15:49:53 -070082 Rect texCoords;
83
Romain Guydda57022010-07-06 11:39:32 -070084 /**
Romain Guyeb993562010-10-05 18:14:38 -070085 * 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 Guy8550c4c2010-10-08 15:49:53 -070089
Romain Guyeb993562010-10-05 18:14:38 -070090 /**
Romain Guydda57022010-07-06 11:39:32 -070091 * Opacity of the layer.
Romain Guydda57022010-07-06 11:39:32 -070092 */
Romain Guyf607bdc2010-09-10 19:20:06 -070093 int alpha;
Romain Guydda57022010-07-06 11:39:32 -070094 /**
95 * Blending mode of the layer.
Romain Guydda57022010-07-06 11:39:32 -070096 */
97 SkXfermode::Mode mode;
98 /**
99 * Indicates whether this layer should be blended.
100 */
101 bool blend;
Romain Guy8550c4c2010-10-08 15:49:53 -0700102
Romain Guy38c85b92010-09-22 22:48:20 -0700103 /**
Romain Guy0bb56672010-10-01 00:25:02 -0700104 * Indicates whether this layer has been used already.
Romain Guy38c85b92010-09-22 22:48:20 -0700105 */
106 bool empty;
Romain Guy8550c4c2010-10-08 15:49:53 -0700107
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 Guy5b3b3522010-10-27 18:57:51 -0700120
121 /**
122 * Dirty region indicating what parts of the layer
123 * have been drawn.
124 */
125 Region region;
Romain Guy40667672011-03-18 14:34:03 -0700126 /**
127 * If the region is a rectangle, coordinates of the
128 * region are stored here.
129 */
130 Rect regionRect;
Romain Guy171c5922011-01-06 10:04:23 -0800131
132 /**
133 * Color filter used to draw this layer. Optional.
134 */
135 SkiaColorFilter* colorFilter;
Romain Guyf219da52011-01-16 12:54:25 -0800136
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 Guyaa6c24c2011-04-28 18:40:04 -0700143
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 Guy8f0095c2011-05-02 17:24:22 -0700159
160 /**
161 * Indicates the render target.
162 */
163 GLenum renderTarget;
Romain Guydda57022010-07-06 11:39:32 -0700164}; // struct Layer
165
166}; // namespace uirenderer
167}; // namespace android
168
Romain Guy5b3b3522010-10-27 18:57:51 -0700169#endif // ANDROID_HWUI_LAYER_H