Snapshot.h revision e4db79de127cfe961195f52907af8451026eaa20
15cbbce535744b89df5ecea95de21ee3733298260Romain Guy/*
25cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Copyright (C) 2010 The Android Open Source Project
35cbbce535744b89df5ecea95de21ee3733298260Romain Guy *
45cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
55cbbce535744b89df5ecea95de21ee3733298260Romain Guy * you may not use this file except in compliance with the License.
65cbbce535744b89df5ecea95de21ee3733298260Romain Guy * You may obtain a copy of the License at
75cbbce535744b89df5ecea95de21ee3733298260Romain Guy *
85cbbce535744b89df5ecea95de21ee3733298260Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
95cbbce535744b89df5ecea95de21ee3733298260Romain Guy *
105cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Unless required by applicable law or agreed to in writing, software
115cbbce535744b89df5ecea95de21ee3733298260Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
125cbbce535744b89df5ecea95de21ee3733298260Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135cbbce535744b89df5ecea95de21ee3733298260Romain Guy * See the License for the specific language governing permissions and
145cbbce535744b89df5ecea95de21ee3733298260Romain Guy * limitations under the License.
155cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
165cbbce535744b89df5ecea95de21ee3733298260Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_SNAPSHOT_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_SNAPSHOT_H
195cbbce535744b89df5ecea95de21ee3733298260Romain Guy
205cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include <GLES2/gl2.h>
215cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include <GLES2/gl2ext.h>
225cbbce535744b89df5ecea95de21ee3733298260Romain Guy
23deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#include <utils/LinearAllocator.h>
245cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include <utils/RefBase.h>
255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#include <ui/Region.h>
265cbbce535744b89df5ecea95de21ee3733298260Romain Guy
27ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy#include <SkRegion.h>
28079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy
29487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk#include "ClipArea.h"
30dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "Layer.h"
315cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Matrix.h"
32deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#include "Outline.h"
335cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Rect.h"
34deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#include "utils/Macros.h"
355cbbce535744b89df5ecea95de21ee3733298260Romain Guy
365cbbce535744b89df5ecea95de21ee3733298260Romain Guynamespace android {
375cbbce535744b89df5ecea95de21ee3733298260Romain Guynamespace uirenderer {
385cbbce535744b89df5ecea95de21ee3733298260Romain Guy
395cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
40deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * Temporary structure holding information for a single outline clip.
41deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik *
42deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * These structures are treated as immutable once created, and only exist for a single frame, which
43deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * is why they may only be allocated with a LinearAllocator.
44deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik */
45deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craikclass RoundRectClipState {
46deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craikpublic:
47deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /** static void* operator new(size_t size); PURPOSELY OMITTED, allocator only **/
48deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    static void* operator new(size_t size, LinearAllocator& allocator) {
49deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        return allocator.alloc(size);
50deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
51deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
52deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    bool areaRequiresRoundRectClip(const Rect& rect) const {
53deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        return rect.intersects(dangerRects[0])
54deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[1])
55deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[2])
56deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[3]);
57deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
58deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
59e83cbd451868a734bfac07ccd680d5617080b579Chris Craik    bool highPriority;
60deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    Matrix4 matrix;
61deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    Rect dangerRects[4];
62af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik    Rect innerRect;
63af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik    float radius;
64deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik};
65deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
66fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craikclass ProjectionPathMask {
67fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craikpublic:
68fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    /** static void* operator new(size_t size); PURPOSELY OMITTED, allocator only **/
69fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    static void* operator new(size_t size, LinearAllocator& allocator) {
70fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik        return allocator.alloc(size);
71fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    }
72fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik
73fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    const SkPath* projectionMask;
74fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    Matrix4 projectionMaskTransform;
75fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik};
76fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik
77deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik/**
785cbbce535744b89df5ecea95de21ee3733298260Romain Guy * A snapshot holds information about the current state of the rendering
795cbbce535744b89df5ecea95de21ee3733298260Romain Guy * surface. A snapshot is usually created whenever the user calls save()
805cbbce535744b89df5ecea95de21ee3733298260Romain Guy * and discarded when the user calls restore(). Once a snapshot is created,
815cbbce535744b89df5ecea95de21ee3733298260Romain Guy * it can hold information for deferred rendering.
825cbbce535744b89df5ecea95de21ee3733298260Romain Guy *
835cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Each snapshot has a link to a previous snapshot, indicating the previous
845cbbce535744b89df5ecea95de21ee3733298260Romain Guy * state of the renderer.
855cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
86d9ee550888011a64fa3f35e666360ec8278597d8John Reckclass Snapshot {
875cbbce535744b89df5ecea95de21ee3733298260Romain Guypublic:
885cbbce535744b89df5ecea95de21ee3733298260Romain Guy
89ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    Snapshot();
90d9ee550888011a64fa3f35e666360ec8278597d8John Reck    Snapshot(Snapshot* s, int saveFlags);
915cbbce535744b89df5ecea95de21ee3733298260Romain Guy
925cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
93ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Various flags set on ::flags.
945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
955cbbce535744b89df5ecea95de21ee3733298260Romain Guy    enum Flags {
965cbbce535744b89df5ecea95de21ee3733298260Romain Guy        /**
975cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * Indicates that the clip region was modified. When this
985cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * snapshot is restored so must the clip.
995cbbce535744b89df5ecea95de21ee3733298260Romain Guy         */
1005cbbce535744b89df5ecea95de21ee3733298260Romain Guy        kFlagClipSet = 0x1,
1015cbbce535744b89df5ecea95de21ee3733298260Romain Guy        /**
1025cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * Indicates that this snapshot was created when saving
1035cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * a new layer.
1045cbbce535744b89df5ecea95de21ee3733298260Romain Guy         */
105079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy        kFlagIsLayer = 0x2,
106f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy        /**
107eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * Indicates that this snapshot is a special type of layer
108eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * backed by an FBO. This flag only makes sense when the
109eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * flag kFlagIsLayer is also set.
110a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         *
111a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Viewport has been modified to fit the new Fbo, and must be
112a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * restored when this snapshot is restored.
113eb99356a0548684a501766e6a524529ab93304c8Romain Guy         */
114eb99356a0548684a501766e6a524529ab93304c8Romain Guy        kFlagIsFboLayer = 0x4,
115eb99356a0548684a501766e6a524529ab93304c8Romain Guy        /**
1165b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         * Indicates that this snapshot or an ancestor snapshot is
1175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         * an FBO layer.
1185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         */
119a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        kFlagFboTarget = 0x8,
1205cbbce535744b89df5ecea95de21ee3733298260Romain Guy    };
1215cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1225cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
123f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Modifies the current clip with the new clip rectangle and
124f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * the specified operation. The specified rectangle is transformed
125f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * by this snapshot's trasnformation.
1263d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     */
127a2a70723b8cbda4354d23f901f995623e819012cChris Craik    void clip(const Rect& localClip, SkRegion::Op op);
128f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy
129f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
130f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Modifies the current clip with the new clip rectangle and
131f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * the specified operation. The specified rectangle is considered
132f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * already transformed.
133f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
1344d3e704b04c6abd7995df640d12662b0271f6c7bChris Craik    void clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op);
1355cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1365cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1378ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Modifies the current clip with the specified region and operation.
1388ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * The specified region is considered already transformed.
1398ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
1404d3e704b04c6abd7995df640d12662b0271f6c7bChris Craik    void clipRegionTransformed(const SkRegion& region, SkRegion::Op op);
1418ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
1428ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
143487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * Modifies the current clip with the specified path and operation.
144487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     */
1454d3e704b04c6abd7995df640d12662b0271f6c7bChris Craik    void clipPath(const SkPath& path, SkRegion::Op op);
146487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk
147487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    /**
148d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Sets the current clip.
149d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     */
150ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void setClip(float left, float top, float right, float bottom);
151959c91f7f7b4f921d341264f5b4ef54e702a0df0Romain Guy
152ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
153ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Returns the current clip in local coordinates. The clip rect is
154ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * transformed by the inverse transform matrix.
155ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
1561a49868fd82f8975da5685fdb6ca3cc83a99bdf5Ben Cheng    ANDROID_API const Rect& getLocalClip();
1573f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik
1583f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    /**
1593f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     * Returns the current clip in render target coordinates.
1603f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     */
1616fe991e5e76f9af9dab960100d5768d96d5f4daaChris Craik    const Rect& getRenderTargetClip() const { return mClipArea->getClipRect(); }
162487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk
163487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    /*
164487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * Accessor functions so that the clip area can stay private
165487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     */
166487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    bool clipIsEmpty() const { return mClipArea->isEmpty(); }
167487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    const SkRegion& getClipRegion() const { return mClipArea->getClipRegion(); }
168487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    bool clipIsSimple() const { return mClipArea->isSimple(); }
169487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    const ClipArea& getClipArea() const { return *mClipArea; }
170e4db79de127cfe961195f52907af8451026eaa20Chris Craik    ClipArea& mutateClipArea() { return *mClipArea; }
171d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
172ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
173ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Resets the clip to the specified rect.
174ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
175ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void resetClip(float left, float top, float right, float bottom);
176eb99356a0548684a501766e6a524529ab93304c8Romain Guy
177ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
178ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Resets the current transform to a pure 3D translation.
179ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
180ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void resetTransform(float x, float y, float z);
181eb99356a0548684a501766e6a524529ab93304c8Romain Guy
182a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    void initializeViewport(int width, int height) {
183a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        mViewportData.initialize(width, height);
184487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk        mClipAreaRoot.setViewportDimensions(width, height);
185a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    }
186a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
187a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportWidth() const { return mViewportData.mWidth; }
188a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportHeight() const { return mViewportData.mHeight; }
189a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    const Matrix4& getOrthoMatrix() const { return mViewportData.mOrthoMatrix; }
190a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
19169e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    const Vector3& getRelativeLightCenter() const { return mRelativeLightCenter; }
19269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    void setRelativeLightCenter(const Vector3& lightCenter) { mRelativeLightCenter = lightCenter; }
19369e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik
194ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
195deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Sets (and replaces) the current clipping outline
196e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     *
197e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * If the current round rect clip is high priority, the incoming clip is ignored.
198deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     */
199e83cbd451868a734bfac07ccd680d5617080b579Chris Craik    void setClippingRoundRect(LinearAllocator& allocator, const Rect& bounds,
200e83cbd451868a734bfac07ccd680d5617080b579Chris Craik            float radius, bool highPriority);
201deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
202deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /**
203fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     * Sets (and replaces) the current projection mask
204fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     */
205fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    void setProjectionPathMask(LinearAllocator& allocator, const SkPath* path);
206fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik
207fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    /**
208ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Indicates whether this snapshot should be ignored. A snapshot
209487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * is typically ignored if its layer is invisible or empty.
210ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
211ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    bool isIgnored() const;
212af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy
2138b55f377655d13a445b08a0a8ed09b6e95c752b0Romain Guy    /**
214a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy     * Indicates whether the current transform has perspective components.
215a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy     */
216a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy    bool hasPerspectiveTransform() const;
217a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy
218a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy    /**
219fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     * Fills outTransform with the current, total transform to screen space,
220fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     * across layer boundaries.
221fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     */
222fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    void buildScreenSpaceTransform(Matrix4* outTransform) const;
223fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik
224fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    /**
2255cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Dirty flags.
2265cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
2275cbbce535744b89df5ecea95de21ee3733298260Romain Guy    int flags;
2285cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2295cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2305cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Previous snapshot.
2315cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
232d9ee550888011a64fa3f35e666360ec8278597d8John Reck    Snapshot* previous;
2335cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2345cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2358ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * A pointer to the currently active layer.
236ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
237ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This snapshot does not own the layer, this pointer must not be freed.
2385cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
239dda570201ac851dd85af3861f7e575721d3345daRomain Guy    Layer* layer;
240f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy
2418aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    /**
242421458aad764cd9d1403d2540ab979b336b02341Romain Guy     * Target FBO used for rendering. Set to 0 when rendering directly
243421458aad764cd9d1403d2540ab979b336b02341Romain Guy     * into the framebuffer.
244eb99356a0548684a501766e6a524529ab93304c8Romain Guy     */
245eb99356a0548684a501766e6a524529ab93304c8Romain Guy    GLuint fbo;
246eb99356a0548684a501766e6a524529ab93304c8Romain Guy
247eb99356a0548684a501766e6a524529ab93304c8Romain Guy    /**
248dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy     * Indicates that this snapshot is invisible and nothing should be drawn
249af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * inside it. This flag is set only when the layer clips drawing to its
250af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * bounds and is passed to subsequent snapshots.
251dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy     */
252dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy    bool invisible;
253dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy
254dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy    /**
255af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * If set to true, the layer will not be composited. This is similar to
256af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * invisible but this flag is not passed to subsequent snapshots.
257af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     */
258af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy    bool empty;
259af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy
260af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy    /**
2618aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * Local transformation. Holds the current translation, scale and
2628aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * rotation values.
263ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
264ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This is a reference to a matrix owned by this snapshot or another
265ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *  snapshot. This pointer must not be freed. See ::mTransformRoot.
2668aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     */
2678aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    mat4* transform;
2688aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy
2698aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    /**
270f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * The ancestor layer's dirty region.
271ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
272ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This is a reference to a region owned by a layer. This pointer must
273ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * not be freed.
2745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    Region* region;
2765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
277db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase    /**
278db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * Current alpha value. This value is 1 by default, but may be set by a DisplayList which
279db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * has translucent rendering in a non-overlapping View. This value will be used by
280db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the renderer to set the alpha in the current color being used for ensuing drawing
281db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * operations. The value is inherited by child snapshots because the same value should
282487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * be applied to descendants of the current DisplayList (for example, a TextView contains
283db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the base alpha value which should be applied to the child DisplayLists used for drawing
284db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the actual text).
285db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     */
286db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase    float alpha;
287db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase
288deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /**
289deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Current clipping round rect.
290deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     *
291deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Points to data not owned by the snapshot, and may only be replaced by subsequent RR clips,
292deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * never modified.
293deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     */
294deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    const RoundRectClipState* roundRectClipState;
295deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
296fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    /**
297fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     * Current projection masking path - used exclusively to mask tessellated circles.
298fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik     */
299fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    const ProjectionPathMask* projectionPathMask;
300fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik
3015f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    void dump() const;
3025f803623559aab395a29d575c37c4e39c23a4b4eChris Craik
3035cbbce535744b89df5ecea95de21ee3733298260Romain Guyprivate:
304a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    struct ViewportData {
305924197513aa2df4c1fb2977c1727f5d2c21f2689Chris Craik        ViewportData() : mWidth(0), mHeight(0) {}
306a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        void initialize(int width, int height) {
307a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mWidth = width;
308a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mHeight = height;
309a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
310a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        }
311a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
312a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        /*
313a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Width and height of current viewport.
314a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         *
315a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * The viewport is always defined to be (0, 0, width, height).
316a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         */
317a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        int mWidth;
318a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        int mHeight;
319a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        /**
320a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Contains the current orthographic, projection matrix.
321a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         */
322a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        mat4 mOrthoMatrix;
323a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    };
324a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
3258aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    mat4 mTransformRoot;
326079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy
327487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    ClipArea mClipAreaRoot;
328487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    ClipArea* mClipArea;
329487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    Rect mLocalClip;
330487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk
331a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    ViewportData mViewportData;
33269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    Vector3 mRelativeLightCenter;
333967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy
3345cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // class Snapshot
3355cbbce535744b89df5ecea95de21ee3733298260Romain Guy
3365cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // namespace uirenderer
3375cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // namespace android
3385cbbce535744b89df5ecea95de21ee3733298260Romain Guy
3395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_SNAPSHOT_H
340