OpenGLRenderer.h revision e93482f5eac3df581d57e64c2a771a96aa868585
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/*
2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2010 The Android Open Source Project
3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License.
6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at
7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software
11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and
14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License.
15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */
16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_OPENGL_RENDERER_H
199d5316e3f56d138504565ff311145ac01621dff4Romain Guy
209d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2.h>
219d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2ext.h>
2285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
23ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkBitmap.h>
24f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h>
25ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h>
26079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h>
27d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy#include <SkShader.h>
2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
29e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
30daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h>
31bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
32ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h>
338694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
34bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
357953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
367953745dd565167113f8cbfc461bc0521d32d870Romain Guy
373b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h>
383b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
39c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
4051769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
41f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
425cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
43bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
445cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
45f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4606f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
47db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
483b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h"
49fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
50bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
51e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
529d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
53e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
54c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers {
55c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaShader* mShader;
56c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaColorFilter* mColorFilter;
5716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    float mOverrideLayerAlpha;
58c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
59c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Drop shadow
60c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasShadow;
61c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowRadius;
62c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDx;
63c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDy;
64c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mShadowColor;
65c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
66c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Draw filters
67c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasDrawFilter;
68c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterClearBits;
69c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterSetBits;
70c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
71c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
72ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags {
73ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Draw = 0x1,
74ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Clip = 0x2
75ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik};
76ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
77527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craikenum DrawOpMode {
78527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    kDrawOpMode_Immediate,
79527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    kDrawOpMode_Defer,
80527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    kDrawOpMode_Flush
81527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik};
82527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
8328ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags {
8428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Unclipped = 0x0,
8528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Left = 0x1,
8628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Top = 0x2,
8728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Right = 0x4,
8828ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Bottom = 0x8,
8928ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Full = 0xF
9028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik};
9128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik
92c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DeferredDisplayState {
933b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    // global op bounds, mapped by mMatrix to be in screen space coordinates, clipped
943b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    Rect mBounds;
95c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
96c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // the below are set and used by the OpenGLRenderer at record and deferred playback
97527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    bool mClipValid;
98c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    Rect mClip;
9928ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    int mClipSideFlags; // specifies which sides of the bounds are clipped, unclipped if cleared
1002db5e993b626794eb07a0ff354269f9a77da81b3Romain Guy    bool mClipped;
101c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    mat4 mMatrix;
102c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
103ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    float mAlpha;
104c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
105c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
106f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
107f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
108f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
109f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
1100fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
111257ae3502cfad43df681b1783528d645bdabc63fRomain Guyclass TextSetupFunctor;
11265cd612face362d054a85d0f7e5881c59cd523beChris Craikclass VertexBuffer;
113b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
1145cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
1155cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
1165cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
1175cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
11885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
119e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
1207953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API OpenGLRenderer();
121e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
122e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
12317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
124ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * Sets the name of this renderer. The name is optional and
125ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * empty by default. If the pointer is null the name is set
126ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * to the empty string.
127ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     */
128ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    ANDROID_API void setName(const char* name);
129ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
130ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    /**
131ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * Returns the name of this renderer as UTF8 string.
132ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * The returned pointer is never null.
133ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     */
134ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    ANDROID_API const char* getName() const;
135ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
136ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    /**
13787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     * Read externally defined properties to control the behavior
13887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     * of the renderer.
13987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     */
14087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    ANDROID_API void initProperties();
14187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
14287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    /**
14317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates whether this renderer executes drawing commands immediately.
14417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * If this method returns true, the drawing commands will be executed
14517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * later.
14617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
14749c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy    virtual bool isDeferred();
14849c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy
14917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
15017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Sets the dimension of the underlying drawing surface. This method must
15117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * be called at least once every time the drawing surface changes size.
15217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
15317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param width The width in pixels of the underlysing surface
15417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param height The height in pixels of the underlysing surface
15517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
156b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
157e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
15817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
15917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
16017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. When this method is invoked, the
16117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * entire drawing surface is assumed to be redrawn.
16217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
16317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
16417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
16517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared
16617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
1677c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    ANDROID_API status_t prepare(bool opaque);
16817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
16917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
17017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
17117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. Only the specified rectangle of the
17217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * frame is assumed to be dirty. A clip will automatically be set to
17317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the specified rectangle.
17417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
17517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param left The left coordinate of the dirty rectangle
17617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param top The top coordinate of the dirty rectangle
17717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param right The right coordinate of the dirty rectangle
17817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param bottom The bottom coordinate of the dirty rectangle
17917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
18017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
18117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared in the specified dirty rectangle
18217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
1837c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
184e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
18517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
18617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates the end of a frame. This method must be invoked whenever
18717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the caller is done rendering a frame.
18817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
18917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    virtual void finish();
1906c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
191c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    /**
192c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This method must be invoked before handing control over to a draw functor.
193c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * See callDrawGLFunction() for instance.
194c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     *
195c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This command must not be recorded inside display lists.
196c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     */
197c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void interrupt();
198c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
199c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    /**
200c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This method must be invoked after getting control back from a draw functor.
201c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     *
202c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This command must not be recorded inside display lists.
203c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     */
204c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void resume();
205c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
20678dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    ANDROID_API void setCountOverdrawEnabled(bool enabled) {
20778dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy        mCountOverdraw = enabled;
20878dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    }
20978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
21078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    ANDROID_API float getOverdraw() {
21178dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy        return mCountOverdraw ? mOverdraw : 0.0f;
21278dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    }
21378dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
2148f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    ANDROID_API status_t invokeFunctors(Rect& dirty);
215ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void detachFunctor(Functor* functor);
216ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void attachFunctor(Functor* functor);
2178f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
21808ae317c21ec3086b5017672bba87420cc38a407Romain Guy
21911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void pushLayerUpdate(Layer* layer);
220e93482f5eac3df581d57e64c2a771a96aa868585Romain Guy    ANDROID_API void cancelLayerUpdate(Layer* layer);
22111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void clearLayerUpdates();
222405436021da156fbe3c5d4de48bdefa564cf7fc0Romain Guy    ANDROID_API void flushLayerUpdates();
22311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
2247953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API int getSaveCount() const;
2254aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
2264aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
2274aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
228bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
229ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    ANDROID_API int saveLayer(float left, float top, float right, float bottom,
230ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            SkPaint* paint, int flags) {
231ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
232ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        if (paint) mode = getXfermode(paint->getXfermode());
233ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return saveLayer(left, top, right, bottom, paint ? paint->getAlpha() : 255, mode, flags);
234ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
235ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    ANDROID_API int saveLayerAlpha(float left, float top, float right, float bottom,
236ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            int alpha, int flags) {
237ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return saveLayer(left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
238ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
239e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
240ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            int alpha, SkXfermode::Mode mode, int flags);
241bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
242d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    int saveLayerDeferred(float left, float top, float right, float bottom,
243d90144db52c7297879b950cbbc85137ed123ab5bChris Craik            int alpha, SkXfermode::Mode mode, int flags);
244d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
2454aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
2464aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
2474aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
248807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
249f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
250b98a016c6769b9e80d392df22fe77a2fca048d9fChris Craik    bool hasRectToRectTransform();
2517953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void getMatrix(SkMatrix* matrix);
2524aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
2534aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
254f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
2557953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API const Rect& getClipBounds();
25639a908c1df89e1073627b0dcbce922d826b67055Chris Craik
25739a908c1df89e1073627b0dcbce922d826b67055Chris Craik    /**
25839a908c1df89e1073627b0dcbce922d826b67055Chris Craik     * Performs a quick reject but adjust the bounds to account for stroke width if necessary
25939a908c1df89e1073627b0dcbce922d826b67055Chris Craik     */
26039a908c1df89e1073627b0dcbce922d826b67055Chris Craik    bool quickRejectPreStroke(float left, float top, float right, float bottom, SkPaint* paint);
26139a908c1df89e1073627b0dcbce922d826b67055Chris Craik
26239a908c1df89e1073627b0dcbce922d826b67055Chris Craik    /**
26339a908c1df89e1073627b0dcbce922d826b67055Chris Craik     * Returns false and sets scissor based upon bounds if drawing won't be clipped out
26439a908c1df89e1073627b0dcbce922d826b67055Chris Craik     */
26539a908c1df89e1073627b0dcbce922d826b67055Chris Craik    bool quickReject(float left, float top, float right, float bottom);
26641541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik    bool quickReject(const Rect& bounds) {
26741541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik        return quickReject(bounds.left, bounds.top, bounds.right, bounds.bottom);
26841541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik    }
26939a908c1df89e1073627b0dcbce922d826b67055Chris Craik
27039a908c1df89e1073627b0dcbce922d826b67055Chris Craik    /**
27139a908c1df89e1073627b0dcbce922d826b67055Chris Craik     * Same as quickReject, without the scissor, instead returning clipRequired through pointer.
27239a908c1df89e1073627b0dcbce922d826b67055Chris Craik     * clipRequired will be only set if not rejected
27339a908c1df89e1073627b0dcbce922d826b67055Chris Craik     */
27439a908c1df89e1073627b0dcbce922d826b67055Chris Craik    ANDROID_API bool quickRejectNoScissor(float left, float top, float right, float bottom,
27539a908c1df89e1073627b0dcbce922d826b67055Chris Craik            bool* clipRequired = NULL);
27639a908c1df89e1073627b0dcbce922d826b67055Chris Craik    bool quickRejectNoScissor(const Rect& bounds, bool* clipRequired = NULL) {
27739a908c1df89e1073627b0dcbce922d826b67055Chris Craik        return quickRejectNoScissor(bounds.left, bounds.top, bounds.right, bounds.bottom,
27839a908c1df89e1073627b0dcbce922d826b67055Chris Craik                clipRequired);
27939a908c1df89e1073627b0dcbce922d826b67055Chris Craik    }
28039a908c1df89e1073627b0dcbce922d826b67055Chris Craik
2814aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
282735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    virtual bool clipPath(SkPath* path, SkRegion::Op op);
283735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    virtual bool clipRegion(SkRegion* region, SkRegion::Op op);
284a23eed808a1ae4ec0d818c0a9238385e797fd056Chet Haase    virtual Rect* getClipRect();
285bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
286ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t replayFlags);
287c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    virtual void outputDisplayList(DisplayList* displayList);
288a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    virtual status_t drawLayer(Layer* layer, float x, float y);
289486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
290527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    status_t drawBitmaps(SkBitmap* bitmap, int bitmapCount, TextureVertex* vertices,
2912db5e993b626794eb07a0ff354269f9a77da81b3Romain Guy            bool transformed, const Rect& bounds, SkPaint* paint);
292486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
293486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
294e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
2955c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
296486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
297486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
2985a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
2993b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    virtual status_t drawPatch(SkBitmap* bitmap, Res_png_9patch* patch,
3005c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
3014c2547fa9244e78115cde0a259291053108c3dc7Romain Guy    status_t drawPatch(SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
302be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode);
303486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
304486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
305486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
30601d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
307486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint);
308486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint);
309486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
3108b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
311486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPath(SkPath* path, SkPaint* paint);
312486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLines(float* points, int count, SkPaint* paint);
313486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPoints(float* points, int count, SkPaint* paint);
314486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
315325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            float hOffset, float vOffset, SkPaint* paint);
316486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
317325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            const float* positions, SkPaint* paint);
318c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
31941541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik            const float* positions, SkPaint* paint, float totalAdvance, const Rect& bounds,
320527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik            DrawOpMode drawOpMode = kDrawOpMode_Immediate);
321672433d90fab7383cd28beac9d4485b566a90940Romain Guy    virtual status_t drawRects(const float* rects, int count, SkPaint* paint);
32285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
3234aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
3244aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
325d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
3264aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
3274aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
328db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
3294aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
3304aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
3311e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
3325ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
3335ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
3345ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
33516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer)
33616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; }
33716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
338a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    SkPaint* filterPaint(SkPaint* paint);
3395ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
340ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
341527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
34228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    void setupMergedMultiDraw(const Rect* clipRect);
343c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
344d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    const DrawModifiers& getDrawModifiers() { return mDrawModifiers; }
345d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; }
346d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
347672433d90fab7383cd28beac9d4485b566a90940Romain Guy    ANDROID_API bool isCurrentTransformSimple() {
348672433d90fab7383cd28beac9d4485b566a90940Romain Guy        return mSnapshot->transform->isSimple();
349672433d90fab7383cd28beac9d4485b566a90940Romain Guy    }
350672433d90fab7383cd28beac9d4485b566a90940Romain Guy
3510f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    Caches& getCaches() {
3520f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        return mCaches;
3530f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
3540f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
355ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    // simple rect clip
356ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool isCurrentClipSimple() {
357ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return mSnapshot->clipRegion->isEmpty();
358ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
359ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
36017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
361a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik     * Scales the alpha on the current snapshot. This alpha value will be modulated
36217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
36317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
364a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    void scaleAlpha(float alpha) {
365a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik        mSnapshot->alpha *= alpha;
36617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    }
36717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
36817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
3690f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     * Inserts a named event marker in the stream of GL commands.
3700f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     */
3710f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    void eventMark(const char* name) const;
3720f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
3730f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    /**
37417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
37517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
37617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
37717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
37813631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
37917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
38017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
38117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
38217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
38313631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
38413631f3da855f200a151e7837ed9f6b079622b58Romain Guy
385d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    /**
386d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * Gets the alpha and xfermode out of a paint object. If the paint is null
387d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
38816ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not multiply the paint's alpha by the current snapshot's alpha, and does
38916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not replace the alpha with the overrideLayerAlpha
390d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     *
391d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param paint The paint to extract values from
392d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param alpha Where to store the resulting alpha
393d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param mode Where to store the resulting xfermode
394d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     */
395d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
396527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *mode = getXfermodeDirect(paint);
397527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *alpha = getAlphaDirect(paint);
398527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
399527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
400527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    static inline SkXfermode::Mode getXfermodeDirect(SkPaint* paint) {
401527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return SkXfermode::kSrcOver_Mode;
402527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return getXfermode(paint->getXfermode());
403527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
404527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
405527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    static inline int getAlphaDirect(SkPaint* paint) {
406527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return 255;
407527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return paint->getAlpha();
408d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    }
409d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
410624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    /**
411624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * Return the best transform to use to rasterize text given a full
412624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * transform matrix.
413624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     */
414624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    mat4 findBestFontTransform(const mat4& transform) const;
415624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy
416527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR
417527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
418527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.setScissorEnabled(false);
419527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
420527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        // should only be called outside of other draw ops, so stencil can only be in test state
421527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
422527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.stencil.disable();
423527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
424527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
425527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
426527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (stencilWasEnabled) mCaches.stencil.enableTest();
427527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
428527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif
429527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
430e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
431e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
43235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Computes the projection matrix, initialize the first snapshot
43335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * and stores the dimensions of the render target.
43435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
43535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void initViewport(int width, int height);
43635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
43735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
43896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Perform the setup specific to a frame. This method does not
43996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * issue any OpenGL commands.
44096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
44196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void setupFrameState(float left, float top, float right, float bottom, bool opaque);
44296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
44396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
44496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Indicates the start of rendering. This method will setup the
44596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * initial OpenGL state (viewport, clearing the buffer, etc.)
44696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
44796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    status_t startFrame();
44896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
44996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
4507c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     * Clears the underlying surface if needed.
4517c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     */
4527c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
4537c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy
4547c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    /**
45535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Call this method after updating a layer during a drawing pass.
45635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
45735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void resumeAfterLayer();
45835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
45935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
4608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * This method is called whenever a stencil buffer is required. Subclasses
4618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * should override this method and call attachStencilBufferToLayer() on the
4628ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * appropriate layer(s).
4638ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
4648ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    virtual void ensureStencilBuffer();
4658ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
4668ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
4678ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Obtains a stencil render buffer (allocating it if necessary) and
4688ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * attaches it to the specified layer.
4698ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
4708ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void attachStencilBufferToLayer(Layer* layer);
4718ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
4728ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
473e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
474e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
475e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
476e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
477e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
478e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
479e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
480e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
481e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
482694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
483ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
484f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
485ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
486f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
487ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
488ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
489f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
490ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
491624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    sp<Snapshot> getSnapshot() const {
492f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
493f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
494ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
49542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
49642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
49742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
498624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual Region* getRegion() const {
499f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
500f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
501f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
50242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
50342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
50442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
505624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool hasLayer() const {
506f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
507f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
5081bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
50942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
51042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
51142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
512624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual GLint getTargetFbo() const {
51342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
51442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
51542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
51677a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
51777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
51877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
51977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
52077a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
52177a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
52277a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
52377a811610f99e21da7f88dafef60d09f345d0506Romain Guy
524be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
525be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
52616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both
52716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * snapshot alpha, and overrideLayerAlpha
528be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
529be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
530be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
531be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
532be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
53316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const;
53416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
53516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    /**
53616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha
53716ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     *
53816ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * @param layer The layer from which the alpha is extracted
53916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     */
54016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    inline float getLayerAlpha(Layer* layer) const;
541be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
542be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
543be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
544be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
545be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
546be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
547be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        SkXfermode::Mode resultMode;
548be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (!SkXfermode::AsMode(mode, &resultMode)) {
549be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            resultMode = SkXfermode::kSrcOver_Mode;
550be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
551be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        return resultMode;
552be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
553be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
55411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    /**
55511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     * Set to true to suppress error checks at the end of a frame.
55611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     */
557624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool suppressErrorChecks() const {
55811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy        return false;
55911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    }
56011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
56108ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
5625cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
563dcfc836b457a87881da409e1acf251515f121446Romain Guy     * Discards the content of the framebuffer if supported by the driver.
564dcfc836b457a87881da409e1acf251515f121446Romain Guy     * This method should be called at the beginning of a frame to optimize
565dcfc836b457a87881da409e1acf251515f121446Romain Guy     * rendering on some tiler architectures.
566dcfc836b457a87881da409e1acf251515f121446Romain Guy     */
567dcfc836b457a87881da409e1acf251515f121446Romain Guy    void discardFramebuffer(float left, float top, float right, float bottom);
568dcfc836b457a87881da409e1acf251515f121446Romain Guy
569dcfc836b457a87881da409e1acf251515f121446Romain Guy    /**
570ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
571ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
572ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
573ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
574ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
575ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
5762b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
577c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method will use the clip rect that we started drawing the
578c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * frame with.
5792b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * This method needs to be invoked every time getTargetFbo() is
5802b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * bound again.
5812b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
58257b5268708c3b974296c7d4e58a02a957979224aRomain Guy    void startTiling(const sp<Snapshot>& snapshot, bool opaque = false);
5832b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
5842b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
585c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
586c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method needs to be invoked every time getTargetFbo() is
587c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * bound again.
588c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     */
589c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    void startTiling(const Rect& clip, int windowHeight, bool opaque = false);
590c3fedafc5f50100219449125a000e3138f6fb987Romain Guy
591c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    /**
5922b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU that we are done drawing the frame or that we
5932b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * are switching to another render target.
5942b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
5952b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    void endTiling();
5962b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
5972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
5985cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
5995cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
6005cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
6015cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6028aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
6038aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
6045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
6055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
6068aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
6075cbbce535744b89df5ecea95de21ee3733298260Romain Guy
6085cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
6105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6112542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
6125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
613bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
614bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
6155cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6165cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
6175cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
6185cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
619bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
620bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
6215cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6228ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Sets the clipping region using the stencil buffer. The clip region
6238ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is defined by the current snapshot's clipRegion member.
6248ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
6258ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void setStencilFromClip();
6268ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
6278ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
628408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds of the layer, calculates ...
629d90144db52c7297879b950cbbc85137ed123ab5bChris Craik     */
630d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
631d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
632d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    /**
633408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
634408eb12631376cbdc96803e918decf6ea804d346Chris Craik     */
635408eb12631376cbdc96803e918decf6ea804d346Chris Craik    void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
636408eb12631376cbdc96803e918decf6ea804d346Chris Craik            bool fboLayer, int alpha);
637408eb12631376cbdc96803e918decf6ea804d346Chris Craik
638408eb12631376cbdc96803e918decf6ea804d346Chris Craik    /**
639d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
640d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
641d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
642d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
643d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
644d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
645d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
646d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
647d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
648d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
649eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
650d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
651d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
652d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
653d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createLayer(float left, float top, float right, float bottom,
654eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
655d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
656d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
6575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
6585b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
6595b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
6605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
6615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
6625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
6635b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
664d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip, GLuint previousFbo);
6655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
6665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
6675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
6685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
6695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
6705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
6715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
6725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
6735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
6745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
6755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
6765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
6775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
6785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
6795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
6805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
6815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
6825b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
68354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
68454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
68554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
68654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
68754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
68854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
68954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
690f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
691f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
692f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
693f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
694f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
695f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
696f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
697f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
698f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
699f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
700f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
701f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
702f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
7035cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
704735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * are transformed by the current snapshot's transform matrix unless specified
705735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * otherwise.
7065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
7075cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
7085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
7095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
7105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
7115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
712026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
7133d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
7145cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
715026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
7161c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
7175cbbce535744b89df5ecea95de21ee3733298260Romain Guy
71854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
719735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * Draws a series of colored rectangles with the specified color. The specified
720735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * coordinates are transformed by the current snapshot's transform matrix unless
721735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * specified otherwise.
722735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *
723735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
724735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *              per rectangle
725735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param color The rectangles' ARGB color, defined as a packed 32 bits word
726735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param mode The Skia xfermode to use
727735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param ignoreTransform True if the current transform should be ignored
7288ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * @param dirty True if calling this method should dirty the current layer
7293bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy     * @param clip True if the rects should be clipped, false otherwise
730735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     */
731735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    status_t drawColorRects(const float* rects, int count, int color,
7323bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            SkXfermode::Mode mode, bool ignoreTransform = false,
7333bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            bool dirty = true, bool clip = true);
734735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
735735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    /**
73654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
73754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
73854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
73954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
74054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
74154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
74254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
74354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
74454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
74554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
746486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
74754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
74854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
74954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
75054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
75154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
75254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
75354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
75454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
75554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
75654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
757a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
758a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
75954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
76065cd612face362d054a85d0f7e5881c59cd523beChris Craik     * Renders a strip of polygons with the specified paint, used for tessellated geometry.
76165cd612face362d054a85d0f7e5881c59cd523beChris Craik     *
76265cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param vertexBuffer The VertexBuffer to be drawn
76365cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param paint The paint to render with
76465cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param useOffset Offset the vertexBuffer (used in drawing non-AA lines)
76565cd612face362d054a85d0f7e5881c59cd523beChris Craik     */
76665cd612face362d054a85d0f7e5881c59cd523beChris Craik    status_t drawVertexBuffer(const VertexBuffer& vertexBuffer, SkPaint* paint,
76765cd612face362d054a85d0f7e5881c59cd523beChris Craik            bool useOffset = false);
76865cd612face362d054a85d0f7e5881c59cd523beChris Craik
76965cd612face362d054a85d0f7e5881c59cd523beChris Craik    /**
770710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * Renders the convex hull defined by the specified path as a strip of polygons.
77154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
772710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * @param path The hull of the path to draw
773cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * @param paint The paint to render with
77454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
77565cd612face362d054a85d0f7e5881c59cd523beChris Craik    status_t drawConvexPath(const SkPath& path, SkPaint* paint);
776858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
7775cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
7785cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
7795cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
7805cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
7815cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
7825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
7835cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
7845cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
7855cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
7865cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
787d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
788c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
7895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
790bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
791a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
792c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
793026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
79482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
79582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
79682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
79782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
79882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
79982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
80082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
80182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
80282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
80382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
804a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
8058164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
80682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
80782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
80803750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
80903750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
81003750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
81182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
81282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
81382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
81482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
81582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
81682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
81782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
81882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
81982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
82082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
82182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
82282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
823f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
824f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
82503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
8265b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
8275b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
828f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
829f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
830a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
8316820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
8325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
8335b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
834f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
8353b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture,
8363b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            float alpha, SkXfermode::Mode mode, bool blend,
8373b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
8383b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
8393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            bool ignoreScale = false, bool dirty = true);
8403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
841886b275e529e44a59c54b933453d9bc902973178Romain Guy    void drawAlpha8TextureMesh(float left, float top, float right, float bottom,
842886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLuint texture, bool hasColor, int color, int alpha, SkXfermode::Mode mode,
843886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
844527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik            bool ignoreTransform, bool ignoreScale = false, bool dirty = true);
845886b275e529e44a59c54b933453d9bc902973178Romain Guy
846f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
8470a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
8480a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
8490a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
8500a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
85141541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik     * @param totalAdvance The total advance in pixels, defines underline/strikethrough length
8520a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
8530a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
8540a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
8550a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
85641541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik    void drawTextDecorations(const char* text, int bytesCount, float totalAdvance,
8570a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
8581e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
859416a847633680d94efb926837efdc18726d54918Raph Levien   /**
860416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
861416a847633680d94efb926837efdc18726d54918Raph Levien     *
862416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
863416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
864416a847633680d94efb926837efdc18726d54918Raph Levien     * @param bytesCount The number of bytes in the text
865416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
866416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
867416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
868416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
869416a847633680d94efb926837efdc18726d54918Raph Levien     * @param mode The xfermode for drawing the shadow
870416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
871416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
872416a847633680d94efb926837efdc18726d54918Raph Levien     */
873416a847633680d94efb926837efdc18726d54918Raph Levien    void drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count,
874416a847633680d94efb926837efdc18726d54918Raph Levien            const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode,
875416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
876416a847633680d94efb926837efdc18726d54918Raph Levien
87754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
87854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
87954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
88054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
88154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
88254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
88354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
88454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
88554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
886416a847633680d94efb926837efdc18726d54918Raph Levien     void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
88701d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
8881e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
889ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
890026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
891026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
8928ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
893026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
894026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
895026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
896026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
897026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
898026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
899026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
900026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
9018ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
902768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     * Returns true if the specified paint will draw invisible text.
903768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     */
904768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    bool canSkipText(const SkPaint* paint) const;
905768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy
906768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    /**
907746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
908746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
909a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
910746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
9118aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(texture);
912746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
913746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
914746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
915aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
916aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
917aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
918aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
9198aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
920aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
921aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
922aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
92382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
92482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
92582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
926f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
927f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
928a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
929f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
930d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
931d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
932d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
933d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
9346926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
935d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
936d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
937d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
938260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
939889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
940260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
941746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
942746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
943746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
94454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
94517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
94670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
94770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
94870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
94970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
950ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawWithTextureAndColor(bool isAlpha8 = false);
951aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
95215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
953710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik    void setupDrawAA();
9548d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
95570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
95686568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
9574121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
95870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
95970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
96070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
96170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
96270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
96370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
96470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
96570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
9668a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase    void setupDrawModelViewIdentity(bool offset = false);
96770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
96870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
96970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
97070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
97170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
97286568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
9738d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
97470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
97570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
97670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
97770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
978aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
9798f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
9808f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
9814121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
9828d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
983ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLvoid* colors);
9843b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords, GLuint vbo = 0);
9855b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawVertices(GLvoid* vertices);
98670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
987f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
988746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
98911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    bool updateLayer(Layer* layer, bool inFrame);
99011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    void updateLayers();
99196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void flushLayers();
99211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
99317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
99417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
99517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
99617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
9973a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
9983a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
9998ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
10008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Renders the specified region as a series of rectangles. The region
10018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * must be in screen-space coordinates.
10028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
10038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void drawRegionRects(const SkRegion& region, int color, SkXfermode::Mode mode,
10048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy            bool dirty = false);
10058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
10068ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
10078ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
10088ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is turned on.
10098ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
10108ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void debugClip();
10118ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
10127c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void debugOverdraw(bool enable, bool clear);
10137c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void renderOverdraw();
101478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    void countOverdraw();
10157c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
1016746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
1017746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
1018746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
1019746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
1020746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
1021746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
1022746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
10233b753829ae858d424fe109f714745379a6daf455Romain Guy    inline mat4& currentTransform() const {
10243b753829ae858d424fe109f714745379a6daf455Romain Guy        return *mSnapshot->transform;
10253b753829ae858d424fe109f714745379a6daf455Romain Guy    }
10263b753829ae858d424fe109f714745379a6daf455Romain Guy
10273b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    inline const UvMapper& getMapper(const Texture* texture) {
10283b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
10293b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    }
10303b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
10313b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    /**
10323b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * Returns a texture object for the specified bitmap. The texture can
10333b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * come from the texture cache or an atlas. If this method returns
10343b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * NULL, the texture could not be found and/or allocated.
10353b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     */
10363b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    Texture* getTexture(SkBitmap* bitmap);
10373b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
1038bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
1039bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
1040bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
104185bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
1042260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
1043bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1044c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
1045c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
1046c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
1047bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
1048bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
1049f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
1050ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
1051bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
1052bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
10532b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // State used to define the clipping region
10545f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    Rect mTilingClip;
105596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is the target render surface opaque
105696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mOpaque;
105796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is a frame currently being rendered
105896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mFrameStarted;
10599d5316e3f56d138504565ff311145ac01621dff4Romain Guy
1060026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
1061ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
1062ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
10633b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    // Default UV mapper
10643b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    const UvMapper mUvMapper;
10653b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
1066c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // shader, filters, and shadow
1067c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
10685ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
10695ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
107082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
1071fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
10723bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    Extensions& mExtensions;
10738694230ff25fa0a60e480d424843e56b718f0516Romain Guy
10748f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
107554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
10768f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of functors to invoke after a frame is drawn
1077ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    SortedVector<Functor*> mFunctors;
107811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    // List of layers to update at the beginning of a frame
107911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    Vector<Layer*> mLayerUpdates;
108054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
1081746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
1082746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
1083746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
108470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
108570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
108670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
108770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
108870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
108970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
109070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
109170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
109270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
109370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
109470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
109570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
10962b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // Indicate whether we are drawing an opaque frame
10972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    bool mOpaqueFrame;
109870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
109987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
110087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // Properties.h
110187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    bool mScissorOptimizationDisabled;
110287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
110354c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    // No-ops start/endTiling when set
110454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    bool mSuppressTiling;
110554c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
110678dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    // If true, this renderer will setup drawing to emulate
110778dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    // an increment stencil buffer in the color buffer
110878dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    bool mCountOverdraw;
110978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    float mOverdraw;
111078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
1111ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    // Optional name of the renderer
1112ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    String8 mName;
1113ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
1114b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
111596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    friend class Layer;
1116257ae3502cfad43df681b1783528d645bdabc63fRomain Guy    friend class TextSetupFunctor;
1117b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
1118bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
1119e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
11209d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
1121e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
1122e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
11235b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
1124