Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -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 | |
| 17 | #ifndef ANDROID_UI_SNAPSHOT_H |
| 18 | #define ANDROID_UI_SNAPSHOT_H |
| 19 | |
| 20 | #include <GLES2/gl2.h> |
| 21 | #include <GLES2/gl2ext.h> |
| 22 | |
| 23 | #include <utils/RefBase.h> |
| 24 | |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 25 | #include "Layer.h" |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 26 | #include "Matrix.h" |
| 27 | #include "Rect.h" |
| 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
| 32 | /** |
| 33 | * A snapshot holds information about the current state of the rendering |
| 34 | * surface. A snapshot is usually created whenever the user calls save() |
| 35 | * and discarded when the user calls restore(). Once a snapshot is created, |
| 36 | * it can hold information for deferred rendering. |
| 37 | * |
| 38 | * Each snapshot has a link to a previous snapshot, indicating the previous |
| 39 | * state of the renderer. |
| 40 | */ |
| 41 | class Snapshot: public LightRefBase<Snapshot> { |
| 42 | public: |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 43 | Snapshot(): layer(NULL), fbo(0) { } |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Copies the specified snapshot. Only the transform and clip rectangle |
| 47 | * are copied. The layer information is set to 0 and the transform is |
| 48 | * assumed to be dirty. The specified snapshot is stored as the previous |
| 49 | * snapshot. |
| 50 | */ |
| 51 | Snapshot(const sp<Snapshot> s): |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 52 | height(s->height), |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 53 | transform(s->transform), |
| 54 | clipRect(s->clipRect), |
| 55 | flags(kFlagDirtyTransform), |
| 56 | previous(s), |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 57 | layer(NULL), |
| 58 | fbo(s->fbo) { |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Various flags set on #flags. |
| 63 | */ |
| 64 | enum Flags { |
| 65 | /** |
| 66 | * Indicates that the clip region was modified. When this |
| 67 | * snapshot is restored so must the clip. |
| 68 | */ |
| 69 | kFlagClipSet = 0x1, |
| 70 | /** |
| 71 | * Indicates that the snapshot holds new transform |
| 72 | * information. |
| 73 | */ |
| 74 | kFlagDirtyTransform = 0x2, |
| 75 | /** |
| 76 | * Indicates that this snapshot was created when saving |
| 77 | * a new layer. |
| 78 | */ |
| 79 | kFlagIsLayer = 0x4, |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 80 | /** |
| 81 | * Indicates that this snapshot has changed the ortho matrix. |
| 82 | */ |
| 83 | kFlagDirtyOrtho = 0x8, |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * Returns the current clip region mapped by the current transform. |
| 88 | */ |
| 89 | const Rect& getMappedClip() { |
| 90 | if (flags & kFlagDirtyTransform) { |
| 91 | flags &= ~kFlagDirtyTransform; |
| 92 | mappedClip.set(clipRect); |
| 93 | transform.mapRect(mappedClip); |
| 94 | } |
| 95 | return mappedClip; |
| 96 | } |
| 97 | |
| 98 | /** |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 99 | * Height of the framebuffer the snapshot is rendering into. |
| 100 | */ |
| 101 | int height; |
| 102 | |
| 103 | /** |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 104 | * Local transformation. Holds the current translation, scale and |
| 105 | * rotation values. |
| 106 | */ |
| 107 | mat4 transform; |
| 108 | |
| 109 | /** |
| 110 | * Current clip region. |
| 111 | */ |
| 112 | Rect clipRect; |
| 113 | |
| 114 | /** |
| 115 | * Dirty flags. |
| 116 | */ |
| 117 | int flags; |
| 118 | |
| 119 | /** |
| 120 | * Previous snapshot. |
| 121 | */ |
| 122 | sp<Snapshot> previous; |
| 123 | |
| 124 | /** |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 125 | * Only set when the flag kFlagIsLayer is set. |
| 126 | */ |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 127 | Layer* layer; |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 128 | GLuint fbo; |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 129 | |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 130 | /** |
| 131 | * Contains the previous ortho matrix. |
| 132 | */ |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame^] | 133 | mat4 orthoMatrix; |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 134 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 135 | private: |
| 136 | // Clipping rectangle mapped with the transform |
| 137 | Rect mappedClip; |
| 138 | }; // class Snapshot |
| 139 | |
| 140 | }; // namespace uirenderer |
| 141 | }; // namespace android |
| 142 | |
| 143 | #endif // ANDROID_UI_SNAPSHOT_H |