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
29dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "Layer.h"
305cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Matrix.h"
31deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#include "Outline.h"
325cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Rect.h"
33deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik#include "utils/Macros.h"
345cbbce535744b89df5ecea95de21ee3733298260Romain Guy
355cbbce535744b89df5ecea95de21ee3733298260Romain Guynamespace android {
365cbbce535744b89df5ecea95de21ee3733298260Romain Guynamespace uirenderer {
375cbbce535744b89df5ecea95de21ee3733298260Romain Guy
385cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
39deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * Temporary structure holding information for a single outline clip.
40deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik *
41deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * These structures are treated as immutable once created, and only exist for a single frame, which
42deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik * is why they may only be allocated with a LinearAllocator.
43deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik */
44deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craikclass RoundRectClipState {
45deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craikpublic:
46deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /** static void* operator new(size_t size); PURPOSELY OMITTED, allocator only **/
47deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    static void* operator new(size_t size, LinearAllocator& allocator) {
48deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        return allocator.alloc(size);
49deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
50deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
51deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    bool areaRequiresRoundRectClip(const Rect& rect) const {
52deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik        return rect.intersects(dangerRects[0])
53deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[1])
54deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[2])
55deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik                || rect.intersects(dangerRects[3]);
56deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    }
57deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
58e83cbd451868a734bfac07ccd680d5617080b579Chris Craik    bool highPriority;
59deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    Matrix4 matrix;
60deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    Rect dangerRects[4];
61af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik    Rect innerRect;
62af4d04cab6d48ae0d6a5e79bd30f679af87abaadChris Craik    float radius;
63deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik};
64deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
65deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik/**
665cbbce535744b89df5ecea95de21ee3733298260Romain Guy * A snapshot holds information about the current state of the rendering
675cbbce535744b89df5ecea95de21ee3733298260Romain Guy * surface. A snapshot is usually created whenever the user calls save()
685cbbce535744b89df5ecea95de21ee3733298260Romain Guy * and discarded when the user calls restore(). Once a snapshot is created,
695cbbce535744b89df5ecea95de21ee3733298260Romain Guy * it can hold information for deferred rendering.
705cbbce535744b89df5ecea95de21ee3733298260Romain Guy *
715cbbce535744b89df5ecea95de21ee3733298260Romain Guy * Each snapshot has a link to a previous snapshot, indicating the previous
725cbbce535744b89df5ecea95de21ee3733298260Romain Guy * state of the renderer.
735cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
745cbbce535744b89df5ecea95de21ee3733298260Romain Guyclass Snapshot: public LightRefBase<Snapshot> {
755cbbce535744b89df5ecea95de21ee3733298260Romain Guypublic:
765cbbce535744b89df5ecea95de21ee3733298260Romain Guy
77ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    Snapshot();
78ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    Snapshot(const sp<Snapshot>& s, int saveFlags);
795cbbce535744b89df5ecea95de21ee3733298260Romain Guy
805cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
81ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Various flags set on ::flags.
825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
835cbbce535744b89df5ecea95de21ee3733298260Romain Guy    enum Flags {
845cbbce535744b89df5ecea95de21ee3733298260Romain Guy        /**
855cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * Indicates that the clip region was modified. When this
865cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * snapshot is restored so must the clip.
875cbbce535744b89df5ecea95de21ee3733298260Romain Guy         */
885cbbce535744b89df5ecea95de21ee3733298260Romain Guy        kFlagClipSet = 0x1,
895cbbce535744b89df5ecea95de21ee3733298260Romain Guy        /**
905cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * Indicates that this snapshot was created when saving
915cbbce535744b89df5ecea95de21ee3733298260Romain Guy         * a new layer.
925cbbce535744b89df5ecea95de21ee3733298260Romain Guy         */
93079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy        kFlagIsLayer = 0x2,
94f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy        /**
95eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * Indicates that this snapshot is a special type of layer
96eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * backed by an FBO. This flag only makes sense when the
97eb99356a0548684a501766e6a524529ab93304c8Romain Guy         * flag kFlagIsLayer is also set.
98a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         *
99a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Viewport has been modified to fit the new Fbo, and must be
100a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * restored when this snapshot is restored.
101eb99356a0548684a501766e6a524529ab93304c8Romain Guy         */
102eb99356a0548684a501766e6a524529ab93304c8Romain Guy        kFlagIsFboLayer = 0x4,
103eb99356a0548684a501766e6a524529ab93304c8Romain Guy        /**
1045b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         * Indicates that this snapshot or an ancestor snapshot is
1055b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         * an FBO layer.
1065b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy         */
107a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        kFlagFboTarget = 0x8,
1085cbbce535744b89df5ecea95de21ee3733298260Romain Guy    };
1095cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1105cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
111f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Modifies the current clip with the new clip rectangle and
112f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * the specified operation. The specified rectangle is transformed
113f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * by this snapshot's trasnformation.
1143d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     */
115f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    bool clip(float left, float top, float right, float bottom,
116ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy            SkRegion::Op op = SkRegion::kIntersect_Op);
117f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy
118f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
119f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Modifies the current clip with the new clip rectangle and
120f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * the specified operation. The specified rectangle is considered
121f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * already transformed.
122f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
123ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    bool clipTransformed(const Rect& r, SkRegion::Op op = SkRegion::kIntersect_Op);
1245cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1255cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1268ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Modifies the current clip with the specified region and operation.
1278ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * The specified region is considered already transformed.
1288ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
1298ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    bool clipRegionTransformed(const SkRegion& region, SkRegion::Op op);
1308ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
1318ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
132d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Sets the current clip.
133d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     */
134ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void setClip(float left, float top, float right, float bottom);
135959c91f7f7b4f921d341264f5b4ef54e702a0df0Romain Guy
136ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
137ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Returns the current clip in local coordinates. The clip rect is
138ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * transformed by the inverse transform matrix.
139ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
1401a49868fd82f8975da5685fdb6ca3cc83a99bdf5Ben Cheng    ANDROID_API const Rect& getLocalClip();
1413f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik
1423f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    /**
1433f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     * Returns the current clip in render target coordinates.
1443f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     */
1453f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    const Rect& getRenderTargetClip() { return *clipRect; }
146d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
147ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
148ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Resets the clip to the specified rect.
149ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
150ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void resetClip(float left, float top, float right, float bottom);
151eb99356a0548684a501766e6a524529ab93304c8Romain Guy
152ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
153ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Resets the current transform to a pure 3D translation.
154ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
155ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    void resetTransform(float x, float y, float z);
156eb99356a0548684a501766e6a524529ab93304c8Romain Guy
157a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    void initializeViewport(int width, int height) {
158a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        mViewportData.initialize(width, height);
159a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    }
160a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
161a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportWidth() const { return mViewportData.mWidth; }
162a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportHeight() const { return mViewportData.mHeight; }
163a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    const Matrix4& getOrthoMatrix() const { return mViewportData.mOrthoMatrix; }
164a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
16569e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    const Vector3& getRelativeLightCenter() const { return mRelativeLightCenter; }
16669e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    void setRelativeLightCenter(const Vector3& lightCenter) { mRelativeLightCenter = lightCenter; }
16769e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik
168ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    /**
169deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Sets (and replaces) the current clipping outline
170e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     *
171e83cbd451868a734bfac07ccd680d5617080b579Chris Craik     * If the current round rect clip is high priority, the incoming clip is ignored.
172deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     */
173e83cbd451868a734bfac07ccd680d5617080b579Chris Craik    void setClippingRoundRect(LinearAllocator& allocator, const Rect& bounds,
174e83cbd451868a734bfac07ccd680d5617080b579Chris Craik            float radius, bool highPriority);
175deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
176deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /**
177ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * Indicates whether this snapshot should be ignored. A snapshot
178ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * is typicalled ignored if its layer is invisible or empty.
179ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     */
180ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy    bool isIgnored() const;
181af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy
1828b55f377655d13a445b08a0a8ed09b6e95c752b0Romain Guy    /**
183a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy     * Indicates whether the current transform has perspective components.
184a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy     */
185a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy    bool hasPerspectiveTransform() const;
186a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy
187a3dc55f83ab583e0a66b893c71b849afa046770aRomain Guy    /**
1885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Dirty flags.
1895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
1905cbbce535744b89df5ecea95de21ee3733298260Romain Guy    int flags;
1915cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1925cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1935cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Previous snapshot.
1945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
1955cbbce535744b89df5ecea95de21ee3733298260Romain Guy    sp<Snapshot> previous;
1965cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1975cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1988ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * A pointer to the currently active layer.
199ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
200ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This snapshot does not own the layer, this pointer must not be freed.
2015cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
202dda570201ac851dd85af3861f7e575721d3345daRomain Guy    Layer* layer;
203f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy
2048aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    /**
205421458aad764cd9d1403d2540ab979b336b02341Romain Guy     * Target FBO used for rendering. Set to 0 when rendering directly
206421458aad764cd9d1403d2540ab979b336b02341Romain Guy     * into the framebuffer.
207eb99356a0548684a501766e6a524529ab93304c8Romain Guy     */
208eb99356a0548684a501766e6a524529ab93304c8Romain Guy    GLuint fbo;
209eb99356a0548684a501766e6a524529ab93304c8Romain Guy
210eb99356a0548684a501766e6a524529ab93304c8Romain Guy    /**
211dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy     * Indicates that this snapshot is invisible and nothing should be drawn
212af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * inside it. This flag is set only when the layer clips drawing to its
213af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * bounds and is passed to subsequent snapshots.
214dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy     */
215dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy    bool invisible;
216dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy
217dbc26d2ba13f80a7590c57de2d80530d96832969Romain Guy    /**
218af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * If set to true, the layer will not be composited. This is similar to
219af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     * invisible but this flag is not passed to subsequent snapshots.
220af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy     */
221af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy    bool empty;
222af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy
223af636ebf5feb2837683fbfe965040cb706b32ec1Romain Guy    /**
2248aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * Local transformation. Holds the current translation, scale and
2258aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * rotation values.
226ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
227ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This is a reference to a matrix owned by this snapshot or another
228ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *  snapshot. This pointer must not be freed. See ::mTransformRoot.
2298aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     */
2308aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    mat4* transform;
2318aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy
2328aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    /**
233967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     * Current clip rect. The clip is stored in canvas-space coordinates,
2348aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * (screen-space coordinates in the regular case.)
235ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
236ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This is a reference to a rect owned by this snapshot or another
237ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * snapshot. This pointer must not be freed. See ::mClipRectRoot.
2388aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     */
2398aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    Rect* clipRect;
2408aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy
2415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
242967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     * Current clip region. The clip is stored in canvas-space coordinates,
243967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     * (screen-space coordinates in the regular case.)
244967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     *
245967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     * This is a reference to a region owned by this snapshot or another
246967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     * snapshot. This pointer must not be freed. See ::mClipRegionRoot.
247967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy     */
2480baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    SkRegion* clipRegion;
249967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy
250967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy    /**
251f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * The ancestor layer's dirty region.
252ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     *
253ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * This is a reference to a region owned by a layer. This pointer must
254ada4d53d50dc869b8278573ad640dc44118d3bcfRomain Guy     * not be freed.
2555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    Region* region;
2575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
258db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase    /**
259db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * Current alpha value. This value is 1 by default, but may be set by a DisplayList which
260db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * has translucent rendering in a non-overlapping View. This value will be used by
261db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the renderer to set the alpha in the current color being used for ensuing drawing
262db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * operations. The value is inherited by child snapshots because the same value should
263db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * be applied to descendents of the current DisplayList (for example, a TextView contains
264db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the base alpha value which should be applied to the child DisplayLists used for drawing
265db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     * the actual text).
266db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase     */
267db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase    float alpha;
268db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase
269deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    /**
270deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Current clipping round rect.
271deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     *
272deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * Points to data not owned by the snapshot, and may only be replaced by subsequent RR clips,
273deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     * never modified.
274deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik     */
275deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    const RoundRectClipState* roundRectClipState;
276deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
2775f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    void dump() const;
2785f803623559aab395a29d575c37c4e39c23a4b4eChris Craik
2795cbbce535744b89df5ecea95de21ee3733298260Romain Guyprivate:
280a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    struct ViewportData {
281924197513aa2df4c1fb2977c1727f5d2c21f2689Chris Craik        ViewportData() : mWidth(0), mHeight(0) {}
282a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        void initialize(int width, int height) {
283a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mWidth = width;
284a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mHeight = height;
285a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik            mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
286a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        }
287a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
288a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        /*
289a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Width and height of current viewport.
290a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         *
291a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * The viewport is always defined to be (0, 0, width, height).
292a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         */
293a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        int mWidth;
294a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        int mHeight;
295a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        /**
296a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         * Contains the current orthographic, projection matrix.
297a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik         */
298a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik        mat4 mOrthoMatrix;
299a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    };
300a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik
301967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy    void ensureClipRegion();
302967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy    void copyClipRectFromRegion();
303967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy
3040baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    bool clipRegionOp(float left, float top, float right, float bottom, SkRegion::Op op);
305967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy
3068aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    mat4 mTransformRoot;
3078aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    Rect mClipRectRoot;
3083f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    Rect mLocalClip; // don't use directly, call getLocalClip() which initializes this
309079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy
3100baaac5e9adf3ee280ae1239e2e58754a9d2b099Romain Guy    SkRegion mClipRegionRoot;
311a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    ViewportData mViewportData;
31269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    Vector3 mRelativeLightCenter;
313967e2bf3ac8943a8e8a374bf86021915445cda67Romain Guy
3145cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // class Snapshot
3155cbbce535744b89df5ecea95de21ee3733298260Romain Guy
3165cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // namespace uirenderer
3175cbbce535744b89df5ecea95de21ee3733298260Romain Guy}; // namespace android
3185cbbce535744b89df5ecea95de21ee3733298260Romain Guy
3195b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_SNAPSHOT_H
320