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