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