blob: 9c612ffb86f1f27d16ebd6b73a1430b2bd82d5c6 [file] [log] [blame]
Romain Guy5cbbce52010-06-27 22:59:20 -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_SNAPSHOT_H
18#define ANDROID_HWUI_SNAPSHOT_H
Romain Guy5cbbce52010-06-27 22:59:20 -070019
20#include <GLES2/gl2.h>
21#include <GLES2/gl2ext.h>
22
23#include <utils/RefBase.h>
Romain Guy5b3b3522010-10-27 18:57:51 -070024#include <ui/Region.h>
Romain Guy5cbbce52010-06-27 22:59:20 -070025
Romain Guyada4d532012-02-02 17:31:16 -080026#include <SkRegion.h>
Romain Guy079ba2c2010-07-16 14:12:24 -070027
Romain Guydda570202010-07-06 11:39:32 -070028#include "Layer.h"
Romain Guy5cbbce52010-06-27 22:59:20 -070029#include "Matrix.h"
30#include "Rect.h"
31
32namespace android {
33namespace uirenderer {
34
35/**
36 * A snapshot holds information about the current state of the rendering
37 * surface. A snapshot is usually created whenever the user calls save()
38 * and discarded when the user calls restore(). Once a snapshot is created,
39 * it can hold information for deferred rendering.
40 *
41 * Each snapshot has a link to a previous snapshot, indicating the previous
42 * state of the renderer.
43 */
44class Snapshot: public LightRefBase<Snapshot> {
45public:
Romain Guyada4d532012-02-02 17:31:16 -080046
47 Snapshot();
48 Snapshot(const sp<Snapshot>& s, int saveFlags);
Romain Guy5cbbce52010-06-27 22:59:20 -070049
50 /**
Romain Guyada4d532012-02-02 17:31:16 -080051 * Various flags set on ::flags.
Romain Guy5cbbce52010-06-27 22:59:20 -070052 */
53 enum Flags {
54 /**
55 * Indicates that the clip region was modified. When this
56 * snapshot is restored so must the clip.
57 */
58 kFlagClipSet = 0x1,
59 /**
Romain Guy5cbbce52010-06-27 22:59:20 -070060 * Indicates that this snapshot was created when saving
61 * a new layer.
62 */
Romain Guy079ba2c2010-07-16 14:12:24 -070063 kFlagIsLayer = 0x2,
Romain Guyf86ef572010-07-01 11:05:42 -070064 /**
Romain Guyeb993562010-10-05 18:14:38 -070065 * Indicates that this snapshot is a special type of layer
66 * backed by an FBO. This flag only makes sense when the
67 * flag kFlagIsLayer is also set.
68 */
69 kFlagIsFboLayer = 0x4,
70 /**
Romain Guyeb993562010-10-05 18:14:38 -070071 * Indicates that this snapshot has changed the ortho matrix.
72 */
Romain Guyed7a8fc2011-10-04 19:21:27 -070073 kFlagDirtyOrtho = 0x8,
Romain Guy5b3b3522010-10-27 18:57:51 -070074 /**
75 * Indicates that this snapshot or an ancestor snapshot is
76 * an FBO layer.
77 */
Romain Guyed7a8fc2011-10-04 19:21:27 -070078 kFlagFboTarget = 0x10
Romain Guy5cbbce52010-06-27 22:59:20 -070079 };
80
81 /**
Romain Guyf607bdc2010-09-10 19:20:06 -070082 * Modifies the current clip with the new clip rectangle and
83 * the specified operation. The specified rectangle is transformed
84 * by this snapshot's trasnformation.
Romain Guy3d58c032010-07-14 16:34:53 -070085 */
Romain Guyf607bdc2010-09-10 19:20:06 -070086 bool clip(float left, float top, float right, float bottom,
Romain Guyada4d532012-02-02 17:31:16 -080087 SkRegion::Op op = SkRegion::kIntersect_Op);
Romain Guyf607bdc2010-09-10 19:20:06 -070088
89 /**
90 * Modifies the current clip with the new clip rectangle and
91 * the specified operation. The specified rectangle is considered
92 * already transformed.
93 */
Romain Guyada4d532012-02-02 17:31:16 -080094 bool clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op);
Romain Guy5cbbce52010-06-27 22:59:20 -070095
96 /**
Romain Guyd27977d2010-07-14 19:18:51 -070097 * Sets the current clip.
98 */
Romain Guyada4d532012-02-02 17:31:16 -080099 void setClip(float left, float top, float right, float bottom);
Romain Guy079ba2c2010-07-16 14:12:24 -0700100
Romain Guyada4d532012-02-02 17:31:16 -0800101 /**
102 * Returns the current clip in local coordinates. The clip rect is
103 * transformed by the inverse transform matrix.
104 */
105 const Rect& getLocalClip();
Romain Guy959c91f2010-08-11 19:35:53 -0700106
Romain Guyada4d532012-02-02 17:31:16 -0800107 /**
108 * Resets the clip to the specified rect.
109 */
110 void resetClip(float left, float top, float right, float bottom);
Romain Guy959c91f2010-08-11 19:35:53 -0700111
Romain Guyada4d532012-02-02 17:31:16 -0800112 /**
113 * Resets the current transform to a pure 3D translation.
114 */
115 void resetTransform(float x, float y, float z);
Romain Guy8aef54f2010-09-01 15:13:49 -0700116
Romain Guyada4d532012-02-02 17:31:16 -0800117 /**
118 * Indicates whether this snapshot should be ignored. A snapshot
119 * is typicalled ignored if its layer is invisible or empty.
120 */
121 bool isIgnored() const;
Romain Guyaf636eb2010-12-09 17:47:21 -0800122
Romain Guy8b55f372010-08-18 17:10:07 -0700123 /**
Romain Guya3dc55f2012-09-28 13:55:44 -0700124 * Indicates whether the current transform has perspective components.
125 */
126 bool hasPerspectiveTransform() const;
127
128 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700129 * Dirty flags.
130 */
131 int flags;
132
133 /**
134 * Previous snapshot.
135 */
136 sp<Snapshot> previous;
137
138 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700139 * Only set when the flag kFlagIsLayer is set.
Romain Guyada4d532012-02-02 17:31:16 -0800140 *
141 * This snapshot does not own the layer, this pointer must not be freed.
Romain Guy5cbbce52010-06-27 22:59:20 -0700142 */
Romain Guydda570202010-07-06 11:39:32 -0700143 Layer* layer;
Romain Guyf86ef572010-07-01 11:05:42 -0700144
Romain Guy8aef54f2010-09-01 15:13:49 -0700145 /**
Romain Guy421458a2011-11-21 15:14:37 -0800146 * Target FBO used for rendering. Set to 0 when rendering directly
147 * into the framebuffer.
Romain Guyeb993562010-10-05 18:14:38 -0700148 */
149 GLuint fbo;
150
151 /**
Romain Guydbc26d22010-10-11 17:58:29 -0700152 * Indicates that this snapshot is invisible and nothing should be drawn
Romain Guyaf636eb2010-12-09 17:47:21 -0800153 * inside it. This flag is set only when the layer clips drawing to its
154 * bounds and is passed to subsequent snapshots.
Romain Guydbc26d22010-10-11 17:58:29 -0700155 */
156 bool invisible;
157
158 /**
Romain Guyaf636eb2010-12-09 17:47:21 -0800159 * If set to true, the layer will not be composited. This is similar to
160 * invisible but this flag is not passed to subsequent snapshots.
161 */
162 bool empty;
163
164 /**
Romain Guyeb993562010-10-05 18:14:38 -0700165 * Current viewport.
166 */
167 Rect viewport;
168
169 /**
170 * Height of the framebuffer the snapshot is rendering into.
171 */
172 int height;
173
174 /**
175 * Contains the previous ortho matrix.
176 */
177 mat4 orthoMatrix;
178
179 /**
Romain Guy8aef54f2010-09-01 15:13:49 -0700180 * Local transformation. Holds the current translation, scale and
181 * rotation values.
Romain Guyada4d532012-02-02 17:31:16 -0800182 *
183 * This is a reference to a matrix owned by this snapshot or another
184 * snapshot. This pointer must not be freed. See ::mTransformRoot.
Romain Guy8aef54f2010-09-01 15:13:49 -0700185 */
186 mat4* transform;
187
188 /**
Romain Guy967e2bf2012-02-07 17:04:34 -0800189 * Current clip rect. The clip is stored in canvas-space coordinates,
Romain Guy8aef54f2010-09-01 15:13:49 -0700190 * (screen-space coordinates in the regular case.)
Romain Guyada4d532012-02-02 17:31:16 -0800191 *
192 * This is a reference to a rect owned by this snapshot or another
193 * snapshot. This pointer must not be freed. See ::mClipRectRoot.
Romain Guy8aef54f2010-09-01 15:13:49 -0700194 */
195 Rect* clipRect;
196
Romain Guy5b3b3522010-10-27 18:57:51 -0700197 /**
Romain Guy967e2bf2012-02-07 17:04:34 -0800198 * Current clip region. The clip is stored in canvas-space coordinates,
199 * (screen-space coordinates in the regular case.)
200 *
201 * This is a reference to a region owned by this snapshot or another
202 * snapshot. This pointer must not be freed. See ::mClipRegionRoot.
203 *
204 * This field is used only if STENCIL_BUFFER_SIZE is > 0.
205 */
Romain Guy0baaac52012-08-31 20:31:01 -0700206 SkRegion* clipRegion;
Romain Guy967e2bf2012-02-07 17:04:34 -0800207
208 /**
Romain Guyf219da52011-01-16 12:54:25 -0800209 * The ancestor layer's dirty region.
Romain Guyada4d532012-02-02 17:31:16 -0800210 *
211 * This is a reference to a region owned by a layer. This pointer must
212 * not be freed.
Romain Guy5b3b3522010-10-27 18:57:51 -0700213 */
214 Region* region;
215
Chet Haasedb8c9a62012-03-21 18:54:18 -0700216 /**
217 * Current alpha value. This value is 1 by default, but may be set by a DisplayList which
218 * has translucent rendering in a non-overlapping View. This value will be used by
219 * the renderer to set the alpha in the current color being used for ensuing drawing
220 * operations. The value is inherited by child snapshots because the same value should
221 * be applied to descendents of the current DisplayList (for example, a TextView contains
222 * the base alpha value which should be applied to the child DisplayLists used for drawing
223 * the actual text).
224 */
225 float alpha;
226
Romain Guy5cbbce52010-06-27 22:59:20 -0700227private:
Romain Guy967e2bf2012-02-07 17:04:34 -0800228 void ensureClipRegion();
229 void copyClipRectFromRegion();
230
Romain Guy0baaac52012-08-31 20:31:01 -0700231 bool clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op);
Romain Guy967e2bf2012-02-07 17:04:34 -0800232
Romain Guy8aef54f2010-09-01 15:13:49 -0700233 mat4 mTransformRoot;
234 Rect mClipRectRoot;
235 Rect mLocalClip;
Romain Guy079ba2c2010-07-16 14:12:24 -0700236
Romain Guy967e2bf2012-02-07 17:04:34 -0800237#if STENCIL_BUFFER_SIZE
Romain Guy0baaac52012-08-31 20:31:01 -0700238 SkRegion mClipRegionRoot;
Romain Guy967e2bf2012-02-07 17:04:34 -0800239#endif
240
Romain Guy5cbbce52010-06-27 22:59:20 -0700241}; // class Snapshot
242
243}; // namespace uirenderer
244}; // namespace android
245
Romain Guy5b3b3522010-10-27 18:57:51 -0700246#endif // ANDROID_HWUI_SNAPSHOT_H