blob: aede0790b719c2ec268a81edb070562fc93b2a7a [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.
Chris Craik0c0ec262014-05-09 16:11:14 -070068 *
69 * Viewport has been modified to fit the new Fbo, and must be
70 * restored when this snapshot is restored.
Romain Guyeb993562010-10-05 18:14:38 -070071 */
72 kFlagIsFboLayer = 0x4,
73 /**
Romain Guy5b3b3522010-10-27 18:57:51 -070074 * Indicates that this snapshot or an ancestor snapshot is
75 * an FBO layer.
76 */
Chris Craik0c0ec262014-05-09 16:11:14 -070077 kFlagFboTarget = 0x8,
Romain Guy5cbbce52010-06-27 22:59:20 -070078 };
79
80 /**
Romain Guyf607bdc2010-09-10 19:20:06 -070081 * Modifies the current clip with the new clip rectangle and
82 * the specified operation. The specified rectangle is transformed
83 * by this snapshot's trasnformation.
Romain Guy3d58c032010-07-14 16:34:53 -070084 */
Romain Guyf607bdc2010-09-10 19:20:06 -070085 bool clip(float left, float top, float right, float bottom,
Romain Guyada4d532012-02-02 17:31:16 -080086 SkRegion::Op op = SkRegion::kIntersect_Op);
Romain Guyf607bdc2010-09-10 19:20:06 -070087
88 /**
89 * Modifies the current clip with the new clip rectangle and
90 * the specified operation. The specified rectangle is considered
91 * already transformed.
92 */
Romain Guyada4d532012-02-02 17:31:16 -080093 bool clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op);
Romain Guy5cbbce52010-06-27 22:59:20 -070094
95 /**
Romain Guy8ce00302013-01-15 18:51:42 -080096 * Modifies the current clip with the specified region and operation.
97 * The specified region is considered already transformed.
98 */
99 bool clipRegionTransformed(const SkRegion& region, SkRegion::Op op);
100
101 /**
Romain Guyd27977d2010-07-14 19:18:51 -0700102 * Sets the current clip.
103 */
Romain Guyada4d532012-02-02 17:31:16 -0800104 void setClip(float left, float top, float right, float bottom);
Romain Guy079ba2c2010-07-16 14:12:24 -0700105
Romain Guyada4d532012-02-02 17:31:16 -0800106 /**
107 * Returns the current clip in local coordinates. The clip rect is
108 * transformed by the inverse transform matrix.
109 */
Chris Craik3f0854292014-04-15 16:18:08 -0700110 const Rect& getLocalClip();
111
112 /**
113 * Returns the current clip in render target coordinates.
114 */
115 const Rect& getRenderTargetClip() { return *clipRect; }
Romain Guy959c91f2010-08-11 19:35:53 -0700116
Romain Guyada4d532012-02-02 17:31:16 -0800117 /**
118 * Resets the clip to the specified rect.
119 */
120 void resetClip(float left, float top, float right, float bottom);
Romain Guy959c91f2010-08-11 19:35:53 -0700121
Romain Guyada4d532012-02-02 17:31:16 -0800122 /**
123 * Resets the current transform to a pure 3D translation.
124 */
125 void resetTransform(float x, float y, float z);
Romain Guy8aef54f2010-09-01 15:13:49 -0700126
Romain Guyada4d532012-02-02 17:31:16 -0800127 /**
128 * Indicates whether this snapshot should be ignored. A snapshot
129 * is typicalled ignored if its layer is invisible or empty.
130 */
131 bool isIgnored() const;
Romain Guyaf636eb2010-12-09 17:47:21 -0800132
Romain Guy8b55f372010-08-18 17:10:07 -0700133 /**
Romain Guya3dc55f2012-09-28 13:55:44 -0700134 * Indicates whether the current transform has perspective components.
135 */
136 bool hasPerspectiveTransform() const;
137
138 /**
Romain Guy5cbbce52010-06-27 22:59:20 -0700139 * Dirty flags.
140 */
141 int flags;
142
143 /**
144 * Previous snapshot.
145 */
146 sp<Snapshot> previous;
147
148 /**
Romain Guy8ce00302013-01-15 18:51:42 -0800149 * A pointer to the currently active layer.
Romain Guyada4d532012-02-02 17:31:16 -0800150 *
151 * This snapshot does not own the layer, this pointer must not be freed.
Romain Guy5cbbce52010-06-27 22:59:20 -0700152 */
Romain Guydda570202010-07-06 11:39:32 -0700153 Layer* layer;
Romain Guyf86ef572010-07-01 11:05:42 -0700154
Romain Guy8aef54f2010-09-01 15:13:49 -0700155 /**
Romain Guy421458a2011-11-21 15:14:37 -0800156 * Target FBO used for rendering. Set to 0 when rendering directly
157 * into the framebuffer.
Romain Guyeb993562010-10-05 18:14:38 -0700158 */
159 GLuint fbo;
160
161 /**
Romain Guydbc26d22010-10-11 17:58:29 -0700162 * Indicates that this snapshot is invisible and nothing should be drawn
Romain Guyaf636eb2010-12-09 17:47:21 -0800163 * inside it. This flag is set only when the layer clips drawing to its
164 * bounds and is passed to subsequent snapshots.
Romain Guydbc26d22010-10-11 17:58:29 -0700165 */
166 bool invisible;
167
168 /**
Romain Guyaf636eb2010-12-09 17:47:21 -0800169 * If set to true, the layer will not be composited. This is similar to
170 * invisible but this flag is not passed to subsequent snapshots.
171 */
172 bool empty;
173
174 /**
Romain Guyeb993562010-10-05 18:14:38 -0700175 * Current viewport.
176 */
177 Rect viewport;
178
179 /**
180 * Height of the framebuffer the snapshot is rendering into.
181 */
182 int height;
183
184 /**
Chris Craik0c0ec262014-05-09 16:11:14 -0700185 * Contains the current orthographic, projection matrix.
Romain Guyeb993562010-10-05 18:14:38 -0700186 */
187 mat4 orthoMatrix;
188
189 /**
Romain Guy8aef54f2010-09-01 15:13:49 -0700190 * Local transformation. Holds the current translation, scale and
191 * rotation values.
Romain Guyada4d532012-02-02 17:31:16 -0800192 *
193 * This is a reference to a matrix owned by this snapshot or another
194 * snapshot. This pointer must not be freed. See ::mTransformRoot.
Romain Guy8aef54f2010-09-01 15:13:49 -0700195 */
196 mat4* transform;
197
198 /**
Romain Guy967e2bf2012-02-07 17:04:34 -0800199 * Current clip rect. The clip is stored in canvas-space coordinates,
Romain Guy8aef54f2010-09-01 15:13:49 -0700200 * (screen-space coordinates in the regular case.)
Romain Guyada4d532012-02-02 17:31:16 -0800201 *
202 * This is a reference to a rect owned by this snapshot or another
203 * snapshot. This pointer must not be freed. See ::mClipRectRoot.
Romain Guy8aef54f2010-09-01 15:13:49 -0700204 */
205 Rect* clipRect;
206
Romain Guy5b3b3522010-10-27 18:57:51 -0700207 /**
Romain Guy967e2bf2012-02-07 17:04:34 -0800208 * Current clip region. The clip is stored in canvas-space coordinates,
209 * (screen-space coordinates in the regular case.)
210 *
211 * This is a reference to a region owned by this snapshot or another
212 * snapshot. This pointer must not be freed. See ::mClipRegionRoot.
Romain Guy967e2bf2012-02-07 17:04:34 -0800213 */
Romain Guy0baaac52012-08-31 20:31:01 -0700214 SkRegion* clipRegion;
Romain Guy967e2bf2012-02-07 17:04:34 -0800215
216 /**
Romain Guyf219da52011-01-16 12:54:25 -0800217 * The ancestor layer's dirty region.
Romain Guyada4d532012-02-02 17:31:16 -0800218 *
219 * This is a reference to a region owned by a layer. This pointer must
220 * not be freed.
Romain Guy5b3b3522010-10-27 18:57:51 -0700221 */
222 Region* region;
223
Chet Haasedb8c9a62012-03-21 18:54:18 -0700224 /**
225 * Current alpha value. This value is 1 by default, but may be set by a DisplayList which
226 * has translucent rendering in a non-overlapping View. This value will be used by
227 * the renderer to set the alpha in the current color being used for ensuing drawing
228 * operations. The value is inherited by child snapshots because the same value should
229 * be applied to descendents of the current DisplayList (for example, a TextView contains
230 * the base alpha value which should be applied to the child DisplayLists used for drawing
231 * the actual text).
232 */
233 float alpha;
234
Chris Craik5f803622013-03-21 14:39:04 -0700235 void dump() const;
236
Romain Guy5cbbce52010-06-27 22:59:20 -0700237private:
Romain Guy967e2bf2012-02-07 17:04:34 -0800238 void ensureClipRegion();
239 void copyClipRectFromRegion();
240
Romain Guy0baaac52012-08-31 20:31:01 -0700241 bool clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op);
Romain Guy967e2bf2012-02-07 17:04:34 -0800242
Romain Guy8aef54f2010-09-01 15:13:49 -0700243 mat4 mTransformRoot;
244 Rect mClipRectRoot;
Chris Craik3f0854292014-04-15 16:18:08 -0700245 Rect mLocalClip; // don't use directly, call getLocalClip() which initializes this
Romain Guy079ba2c2010-07-16 14:12:24 -0700246
Romain Guy0baaac52012-08-31 20:31:01 -0700247 SkRegion mClipRegionRoot;
Romain Guy967e2bf2012-02-07 17:04:34 -0800248
Romain Guy5cbbce52010-06-27 22:59:20 -0700249}; // class Snapshot
250
251}; // namespace uirenderer
252}; // namespace android
253
Romain Guy5b3b3522010-10-27 18:57:51 -0700254#endif // ANDROID_HWUI_SNAPSHOT_H