blob: 6c4a2a9a972dd283add2fb12a5ee26beed863204 [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;
48 }
49
50 ~Layer() {
51 if (mesh) delete mesh;
52 if (meshIndices) delete meshIndices;
Romain Guy8550c4c2010-10-08 15:49:53 -070053 }
54
Romain Guydda57022010-07-06 11:39:32 -070055 /**
Romain Guy9fc27812011-04-27 14:21:41 -070056 * Sets this layer's region to a rectangle. Computes the appropriate
57 * texture coordinates.
58 */
59 void setRegionAsRect() {
60 const android::Rect& bounds = region.getBounds();
61 regionRect.set(bounds.leftTop().x, bounds.leftTop().y,
62 bounds.rightBottom().x, bounds.rightBottom().y);
63
64 const float texX = 1.0f / float(width);
65 const float texY = 1.0f / float(height);
66 const float height = layer.getHeight();
67 texCoords.set(
68 regionRect.left * texX, (height - regionRect.top) * texY,
69 regionRect.right * texX, (height - regionRect.bottom) * texY);
70 }
71
72 /**
Romain Guy8550c4c2010-10-08 15:49:53 -070073 * Bounds of the layer.
Romain Guydda57022010-07-06 11:39:32 -070074 */
75 Rect layer;
76 /**
Romain Guy8550c4c2010-10-08 15:49:53 -070077 * Texture coordinates of the layer.
Romain Guydda57022010-07-06 11:39:32 -070078 */
Romain Guy8550c4c2010-10-08 15:49:53 -070079 Rect texCoords;
80
Romain Guydda57022010-07-06 11:39:32 -070081 /**
Romain Guyeb993562010-10-05 18:14:38 -070082 * Name of the FBO used to render the layer. If the name is 0
83 * this layer is not backed by an FBO, but a simple texture.
84 */
85 GLuint fbo;
Romain Guy8550c4c2010-10-08 15:49:53 -070086
Romain Guyeb993562010-10-05 18:14:38 -070087 /**
Romain Guydda57022010-07-06 11:39:32 -070088 * Opacity of the layer.
Romain Guydda57022010-07-06 11:39:32 -070089 */
Romain Guyf607bdc2010-09-10 19:20:06 -070090 int alpha;
Romain Guydda57022010-07-06 11:39:32 -070091 /**
92 * Blending mode of the layer.
Romain Guydda57022010-07-06 11:39:32 -070093 */
94 SkXfermode::Mode mode;
95 /**
96 * Indicates whether this layer should be blended.
97 */
98 bool blend;
Romain Guy8550c4c2010-10-08 15:49:53 -070099
Romain Guy38c85b92010-09-22 22:48:20 -0700100 /**
Romain Guy0bb56672010-10-01 00:25:02 -0700101 * Indicates whether this layer has been used already.
Romain Guy38c85b92010-09-22 22:48:20 -0700102 */
103 bool empty;
Romain Guy8550c4c2010-10-08 15:49:53 -0700104
105 /**
106 * Name of the texture used to render the layer.
107 */
108 GLuint texture;
109 /**
110 * Width of the layer texture.
111 */
112 uint32_t width;
113 /**
114 * Height of the layer texture.
115 */
116 uint32_t height;
Romain Guy5b3b3522010-10-27 18:57:51 -0700117
118 /**
119 * Dirty region indicating what parts of the layer
120 * have been drawn.
121 */
122 Region region;
Romain Guy40667672011-03-18 14:34:03 -0700123 /**
124 * If the region is a rectangle, coordinates of the
125 * region are stored here.
126 */
127 Rect regionRect;
Romain Guy171c5922011-01-06 10:04:23 -0800128
129 /**
130 * Color filter used to draw this layer. Optional.
131 */
132 SkiaColorFilter* colorFilter;
Romain Guyf219da52011-01-16 12:54:25 -0800133
134 /**
135 * If the layer can be rendered as a mesh, this is non-null.
136 */
137 TextureVertex* mesh;
138 uint16_t* meshIndices;
139 GLsizei meshElementCount;
Romain Guydda57022010-07-06 11:39:32 -0700140}; // struct Layer
141
142}; // namespace uirenderer
143}; // namespace android
144
Romain Guy5b3b3522010-10-27 18:57:51 -0700145#endif // ANDROID_HWUI_LAYER_H