OpenGLRenderer.h revision 408eb12631376cbdc96803e918decf6ea804d346
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
37c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
3851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
39f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
405cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
41bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
425cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
43f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4406f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
45db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
46fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
47bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
48e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
499d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
50e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
51c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers {
52c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaShader* mShader;
53c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaColorFilter* mColorFilter;
54c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
55c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Drop shadow
56c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasShadow;
57c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowRadius;
58c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDx;
59c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDy;
60c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mShadowColor;
61c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
62c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Draw filters
63c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasDrawFilter;
64c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterClearBits;
65c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterSetBits;
66c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
67c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
68ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags {
69ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Draw = 0x1,
70ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Clip = 0x2
71ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik};
72ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
73c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DeferredDisplayState {
74c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    Rect mBounds; // local bounds, mapped with matrix to be in screen space coordinates, clipped.
75c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
76c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // the below are set and used by the OpenGLRenderer at record and deferred playback
77c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    Rect mClip;
78c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    mat4 mMatrix;
79c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
80ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    float mAlpha;
81c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
82c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
83f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
84f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
85f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
86f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
870fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
88257ae3502cfad43df681b1783528d645bdabc63fRomain Guyclass TextSetupFunctor;
8965cd612face362d054a85d0f7e5881c59cd523beChris Craikclass VertexBuffer;
90b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
915cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
925cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
935cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
945cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
9585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
96e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
977953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API OpenGLRenderer();
98e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
99e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
101ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * Sets the name of this renderer. The name is optional and
102ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * empty by default. If the pointer is null the name is set
103ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * to the empty string.
104ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     */
105ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    ANDROID_API void setName(const char* name);
106ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
107ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    /**
108ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * Returns the name of this renderer as UTF8 string.
109ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     * The returned pointer is never null.
110ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy     */
111ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    ANDROID_API const char* getName() const;
112ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
113ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    /**
11487e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     * Read externally defined properties to control the behavior
11587e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     * of the renderer.
11687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy     */
11787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    ANDROID_API void initProperties();
11887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
11987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    /**
12017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates whether this renderer executes drawing commands immediately.
12117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * If this method returns true, the drawing commands will be executed
12217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * later.
12317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
12449c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy    virtual bool isDeferred();
12549c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy
12617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
12717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Sets the dimension of the underlying drawing surface. This method must
12817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * be called at least once every time the drawing surface changes size.
12917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
13017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param width The width in pixels of the underlysing surface
13117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param height The height in pixels of the underlysing surface
13217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
133b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
134e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
13517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
13617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
13717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. When this method is invoked, the
13817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * entire drawing surface is assumed to be redrawn.
13917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
14017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
14117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
14217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared
14317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
1447c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    ANDROID_API status_t prepare(bool opaque);
14517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
14617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
14717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
14817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. Only the specified rectangle of the
14917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * frame is assumed to be dirty. A clip will automatically be set to
15017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the specified rectangle.
15117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
15217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param left The left coordinate of the dirty rectangle
15317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param top The top coordinate of the dirty rectangle
15417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param right The right coordinate of the dirty rectangle
15517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param bottom The bottom coordinate of the dirty rectangle
15617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
15717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
15817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared in the specified dirty rectangle
15917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
1607c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
161e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
16217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
16317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates the end of a frame. This method must be invoked whenever
16417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the caller is done rendering a frame.
16517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
16617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    virtual void finish();
1676c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
168c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    /**
169c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This method must be invoked before handing control over to a draw functor.
170c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * See callDrawGLFunction() for instance.
171c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     *
172c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This command must not be recorded inside display lists.
173c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     */
174c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void interrupt();
175c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
176c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    /**
177c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This method must be invoked after getting control back from a draw functor.
178c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     *
179c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     * This command must not be recorded inside display lists.
180c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy     */
181c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void resume();
182c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
1838f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    ANDROID_API status_t invokeFunctors(Rect& dirty);
184ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void detachFunctor(Functor* functor);
185ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void attachFunctor(Functor* functor);
1868f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
18708ae317c21ec3086b5017672bba87420cc38a407Romain Guy
18811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void pushLayerUpdate(Layer* layer);
18911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void clearLayerUpdates();
19011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
1917953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API int getSaveCount() const;
1924aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
1934aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
1944aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
195bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
196ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    ANDROID_API int saveLayer(float left, float top, float right, float bottom,
197ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            SkPaint* paint, int flags) {
198ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode;
199ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        if (paint) mode = getXfermode(paint->getXfermode());
200ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return saveLayer(left, top, right, bottom, paint ? paint->getAlpha() : 255, mode, flags);
201ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
202ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    ANDROID_API int saveLayerAlpha(float left, float top, float right, float bottom,
203ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            int alpha, int flags) {
204ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return saveLayer(left, top, right, bottom, alpha, SkXfermode::kSrcOver_Mode, flags);
205ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
206e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
207ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik            int alpha, SkXfermode::Mode mode, int flags);
208bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
209d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    int saveLayerDeferred(float left, float top, float right, float bottom,
210d90144db52c7297879b950cbbc85137ed123ab5bChris Craik            int alpha, SkXfermode::Mode mode, int flags);
211d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
2124aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
2134aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
2144aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
215807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
216f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
217b98a016c6769b9e80d392df22fe77a2fca048d9fChris Craik    bool hasRectToRectTransform();
2187953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void getMatrix(SkMatrix* matrix);
2194aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
2204aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
221f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
2227953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API const Rect& getClipBounds();
2237953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API bool quickReject(float left, float top, float right, float bottom);
2248a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    bool quickRejectNoScissor(float left, float top, float right, float bottom);
2254aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
226735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    virtual bool clipPath(SkPath* path, SkRegion::Op op);
227735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    virtual bool clipRegion(SkRegion* region, SkRegion::Op op);
228a23eed808a1ae4ec0d818c0a9238385e797fd056Chet Haase    virtual Rect* getClipRect();
229bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
230ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t replayFlags);
231c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    virtual void outputDisplayList(DisplayList* displayList);
232a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    virtual status_t drawLayer(Layer* layer, float x, float y);
233486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
234486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
235486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
236e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
2375c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
238486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
239486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
2405a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
241486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
2424bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
2435c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
244be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
245be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
246be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode);
247486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
248486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
249486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
25001d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
251486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint);
252486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint);
253486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
2548b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
255486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPath(SkPath* path, SkPaint* paint);
256486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLines(float* points, int count, SkPaint* paint);
257486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPoints(float* points, int count, SkPaint* paint);
258486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
259325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            float hOffset, float vOffset, SkPaint* paint);
260486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
261325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            const float* positions, SkPaint* paint);
262c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
263996e57c84368058be793897ebc355b917a59abc2Raph Levien            const float* positions, SkPaint* paint, float length = -1.0f);
264672433d90fab7383cd28beac9d4485b566a90940Romain Guy    virtual status_t drawRects(const float* rects, int count, SkPaint* paint);
26585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
2664aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
2674aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
268d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
2694aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
2704aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
271db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
2724aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
2734aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
2741e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
2755ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
2765ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
2775ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
278a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    SkPaint* filterPaint(SkPaint* paint);
2795ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
280ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
281ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    void restoreDisplayState(const DeferredDisplayState& state, int stateDeferFlags);
282c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
283d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    const DrawModifiers& getDrawModifiers() { return mDrawModifiers; }
284d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; }
285d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
286ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    // TODO: what does this mean? no perspective? no rotate?
287672433d90fab7383cd28beac9d4485b566a90940Romain Guy    ANDROID_API bool isCurrentTransformSimple() {
288672433d90fab7383cd28beac9d4485b566a90940Romain Guy        return mSnapshot->transform->isSimple();
289672433d90fab7383cd28beac9d4485b566a90940Romain Guy    }
290672433d90fab7383cd28beac9d4485b566a90940Romain Guy
2910f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    Caches& getCaches() {
2920f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        return mCaches;
2930f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2940f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
295ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    // simple rect clip
296ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool isCurrentClipSimple() {
297ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return mSnapshot->clipRegion->isEmpty();
298ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
299ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
30017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
301a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik     * Scales the alpha on the current snapshot. This alpha value will be modulated
30217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
30317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
304a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    void scaleAlpha(float alpha) {
305a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik        mSnapshot->alpha *= alpha;
30617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    }
30717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
30817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
3090f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     * Inserts a named event marker in the stream of GL commands.
3100f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     */
3110f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    void eventMark(const char* name) const;
3120f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
3130f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    /**
31417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
31517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
31617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
31717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
31813631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
31917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
32017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
32117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
32217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
32313631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
32413631f3da855f200a151e7837ed9f6b079622b58Romain Guy
325d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    /**
326d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * Gets the alpha and xfermode out of a paint object. If the paint is null
327d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
328d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * not multiply the paint's alpha by the current snapshot's alpha.
329d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     *
330d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param paint The paint to extract values from
331d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param alpha Where to store the resulting alpha
332d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param mode Where to store the resulting xfermode
333d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     */
334d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
335d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase        if (paint) {
336d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            *mode = getXfermode(paint->getXfermode());
337d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
338d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            // Skia draws using the color's alpha channel if < 255
339d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            // Otherwise, it uses the paint's alpha
340d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            int color = paint->getColor();
341d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            *alpha = (color >> 24) & 0xFF;
342d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            if (*alpha == 255) {
343d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase                *alpha = paint->getAlpha();
344d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            }
345d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase        } else {
346d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            *mode = SkXfermode::kSrcOver_Mode;
347d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase            *alpha = 255;
348d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase        }
349d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    }
350d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
351624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    /**
352624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * Return the best transform to use to rasterize text given a full
353624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * transform matrix.
354624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     */
355624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    mat4 findBestFontTransform(const mat4& transform) const;
356624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy
357e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
358e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
35935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Computes the projection matrix, initialize the first snapshot
36035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * and stores the dimensions of the render target.
36135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
36235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void initViewport(int width, int height);
36335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
36435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
3657c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     * Clears the underlying surface if needed.
3667c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     */
3677c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
3687c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy
3697c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    /**
37035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Call this method after updating a layer during a drawing pass.
37135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
37235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void resumeAfterLayer();
37335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
37435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
3758ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * This method is called whenever a stencil buffer is required. Subclasses
3768ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * should override this method and call attachStencilBufferToLayer() on the
3778ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * appropriate layer(s).
3788ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3798ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    virtual void ensureStencilBuffer();
3808ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
3818ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
3828ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Obtains a stencil render buffer (allocating it if necessary) and
3838ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * attaches it to the specified layer.
3848ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3858ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void attachStencilBufferToLayer(Layer* layer);
3868ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
3878ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
388e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
389e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
390e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
391e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
392e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
393e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
394e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
395e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
396e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
397694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
398ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
399f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
400ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
401f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
402ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
403ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
404f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
405ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
406624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    sp<Snapshot> getSnapshot() const {
407f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
408f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
409ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
41042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
41142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
41242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
413624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual Region* getRegion() const {
414f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
415f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
416f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
41742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
41842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
41942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
420624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool hasLayer() const {
421f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
422f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
4231bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
42442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
42542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
42642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
427624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual GLint getTargetFbo() const {
42842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
42942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
43042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
43177a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
43277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
43377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
43477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
43577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
43677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
43777a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
43877a811610f99e21da7f88dafef60d09f345d0506Romain Guy
439be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
440be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
441be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
442be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
443be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
444be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
445be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
446be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
447be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
448be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
449be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
450be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
451be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
452be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
453be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
454be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        SkXfermode::Mode resultMode;
455be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (!SkXfermode::AsMode(mode, &resultMode)) {
456be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            resultMode = SkXfermode::kSrcOver_Mode;
457be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
458be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        return resultMode;
459be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
460be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
46111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    /**
46211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     * Set to true to suppress error checks at the end of a frame.
46311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     */
464624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool suppressErrorChecks() const {
46511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy        return false;
46611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    }
46711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
46808ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
4695cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
470dcfc836b457a87881da409e1acf251515f121446Romain Guy     * Discards the content of the framebuffer if supported by the driver.
471dcfc836b457a87881da409e1acf251515f121446Romain Guy     * This method should be called at the beginning of a frame to optimize
472dcfc836b457a87881da409e1acf251515f121446Romain Guy     * rendering on some tiler architectures.
473dcfc836b457a87881da409e1acf251515f121446Romain Guy     */
474dcfc836b457a87881da409e1acf251515f121446Romain Guy    void discardFramebuffer(float left, float top, float right, float bottom);
475dcfc836b457a87881da409e1acf251515f121446Romain Guy
476dcfc836b457a87881da409e1acf251515f121446Romain Guy    /**
477ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
478ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
479ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
480ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
481ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
482ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
4832b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
484c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method will use the clip rect that we started drawing the
485c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * frame with.
4862b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * This method needs to be invoked every time getTargetFbo() is
4872b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * bound again.
4882b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
48957b5268708c3b974296c7d4e58a02a957979224aRomain Guy    void startTiling(const sp<Snapshot>& snapshot, bool opaque = false);
4902b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
4912b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
492c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
493c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method needs to be invoked every time getTargetFbo() is
494c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * bound again.
495c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     */
496c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    void startTiling(const Rect& clip, int windowHeight, bool opaque = false);
497c3fedafc5f50100219449125a000e3138f6fb987Romain Guy
498c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    /**
4992b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU that we are done drawing the frame or that we
5002b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * are switching to another render target.
5012b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
5022b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    void endTiling();
5032b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
5042b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
5055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
5065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
5075cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
5085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
5098aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
5108aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
5115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
5125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
5138aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
5145cbbce535744b89df5ecea95de21ee3733298260Romain Guy
5155cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5165cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
5175cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
5182542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
5195cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
520bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
521bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
5225cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5235cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
5245cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
5255cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
526bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
527bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
5285cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5298ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Sets the clipping region using the stencil buffer. The clip region
5308ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is defined by the current snapshot's clipRegion member.
5318ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
5328ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void setStencilFromClip();
5338ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
5348ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
53535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Performs a quick reject but does not affect the scissor. Returns
53635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * the transformed rect to test and the current clip.
53735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
53835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    bool quickRejectNoScissor(float left, float top, float right, float bottom,
53935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy            Rect& transformed, Rect& clip);
54035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
54135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
542cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * Performs a quick reject but adjust the bounds to account for stroke width if necessary
543cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     */
544cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik    bool quickRejectPreStroke(float left, float top, float right, float bottom, SkPaint* paint);
545cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik
546cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik    /**
547408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds of the layer, calculates ...
548d90144db52c7297879b950cbbc85137ed123ab5bChris Craik     */
549d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
550d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
551d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    /**
552408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
553408eb12631376cbdc96803e918decf6ea804d346Chris Craik     */
554408eb12631376cbdc96803e918decf6ea804d346Chris Craik    void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
555408eb12631376cbdc96803e918decf6ea804d346Chris Craik            bool fboLayer, int alpha);
556408eb12631376cbdc96803e918decf6ea804d346Chris Craik
557408eb12631376cbdc96803e918decf6ea804d346Chris Craik    /**
558d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
559d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
560d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
561d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
562d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
563d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
564d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
565d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
566d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
567d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
568eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
569d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
570d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
571d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
572d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createLayer(float left, float top, float right, float bottom,
573eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
574d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
575d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
5765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
5775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
5795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
5805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
5815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
5825b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
583d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip, GLuint previousFbo);
5845b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5855b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5865b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
5875b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5885b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5895b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5905b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5915b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
5925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5935b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5945b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
5955b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5965b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5975b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5985b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
5995b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
6005b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
6015b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
60254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
60354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
60454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
60554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
60654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
60754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
60854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
609f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
610f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
611f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
612f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
613f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
614f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
615f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
616f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
617f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
618f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
619f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
620f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
621f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
6225cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
623735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * are transformed by the current snapshot's transform matrix unless specified
624735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * otherwise.
6255cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6265cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
6275cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
6285cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
6295cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
6305cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
631026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
6323d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
6335cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
634026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
6351c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
6365cbbce535744b89df5ecea95de21ee3733298260Romain Guy
63754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
638735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * Draws a series of colored rectangles with the specified color. The specified
639735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * coordinates are transformed by the current snapshot's transform matrix unless
640735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * specified otherwise.
641735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *
642735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
643735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *              per rectangle
644735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param color The rectangles' ARGB color, defined as a packed 32 bits word
645735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param mode The Skia xfermode to use
646735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param ignoreTransform True if the current transform should be ignored
6478ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * @param dirty True if calling this method should dirty the current layer
6483bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy     * @param clip True if the rects should be clipped, false otherwise
649735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     */
650735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    status_t drawColorRects(const float* rects, int count, int color,
6513bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            SkXfermode::Mode mode, bool ignoreTransform = false,
6523bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            bool dirty = true, bool clip = true);
653735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
654735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    /**
65554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
65654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
65754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
65854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
65954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
66054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
66154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
66254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
66354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
66454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
665486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
66654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
66754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
66854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
66954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
67054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
67154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
67254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
67354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
67454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
67554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
676a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
677a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
67854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
67965cd612face362d054a85d0f7e5881c59cd523beChris Craik     * Renders a strip of polygons with the specified paint, used for tessellated geometry.
68065cd612face362d054a85d0f7e5881c59cd523beChris Craik     *
68165cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param vertexBuffer The VertexBuffer to be drawn
68265cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param paint The paint to render with
68365cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param useOffset Offset the vertexBuffer (used in drawing non-AA lines)
68465cd612face362d054a85d0f7e5881c59cd523beChris Craik     */
68565cd612face362d054a85d0f7e5881c59cd523beChris Craik    status_t drawVertexBuffer(const VertexBuffer& vertexBuffer, SkPaint* paint,
68665cd612face362d054a85d0f7e5881c59cd523beChris Craik            bool useOffset = false);
68765cd612face362d054a85d0f7e5881c59cd523beChris Craik
68865cd612face362d054a85d0f7e5881c59cd523beChris Craik    /**
689710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * Renders the convex hull defined by the specified path as a strip of polygons.
69054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
691710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * @param path The hull of the path to draw
692cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * @param paint The paint to render with
69354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
69465cd612face362d054a85d0f7e5881c59cd523beChris Craik    status_t drawConvexPath(const SkPath& path, SkPaint* paint);
695858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
6965cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6975cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
6985cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
6995cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
7005cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
7015cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
7025cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
7035cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
7045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
7055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
706d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
707c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
7085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
709bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
710a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
711c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
712026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
71382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
71482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
71582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
71682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
71782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
71882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
71982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
72082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
72182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
72282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
723a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
7248164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
72582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
72682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
72703750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
72803750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
72903750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
73082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
73182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
73282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
73382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
73482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
73582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
73682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
73782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
73882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
73982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
74082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
74182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
742f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
743f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
74403750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
7455b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
7465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
747f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
748f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
749a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
7506820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
7525b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
753f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
754886b275e529e44a59c54b933453d9bc902973178Romain Guy    void drawAlpha8TextureMesh(float left, float top, float right, float bottom,
755886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLuint texture, bool hasColor, int color, int alpha, SkXfermode::Mode mode,
756886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
757886b275e529e44a59c54b933453d9bc902973178Romain Guy            bool ignoreTransform, bool dirty = true);
758886b275e529e44a59c54b933453d9bc902973178Romain Guy
759f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
7600a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
7610a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
7620a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
7630a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
7640a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
7650a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
7660a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
7670a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
7680a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
7690a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
7700a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
7711e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
772416a847633680d94efb926837efdc18726d54918Raph Levien   /**
773416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
774416a847633680d94efb926837efdc18726d54918Raph Levien     *
775416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
776416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
777416a847633680d94efb926837efdc18726d54918Raph Levien     * @param bytesCount The number of bytes in the text
778416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
779416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
780416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
781416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
782416a847633680d94efb926837efdc18726d54918Raph Levien     * @param mode The xfermode for drawing the shadow
783416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
784416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
785416a847633680d94efb926837efdc18726d54918Raph Levien     */
786416a847633680d94efb926837efdc18726d54918Raph Levien    void drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count,
787416a847633680d94efb926837efdc18726d54918Raph Levien            const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode,
788416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
789416a847633680d94efb926837efdc18726d54918Raph Levien
79054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
79154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
79254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
79354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
79454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
79554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
79654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
79754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
79854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
799416a847633680d94efb926837efdc18726d54918Raph Levien     void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
80001d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
8011e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
802ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
803026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
804026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
8058ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
806026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
807026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
808026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
809026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
810026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
811026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
812026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
813026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
8148ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
815768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     * Returns true if the specified paint will draw invisible text.
816768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     */
817768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    bool canSkipText(const SkPaint* paint) const;
818768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy
819768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    /**
820746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
821746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
822a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
823746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
824746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
825746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
826746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
827746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
828aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
829aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
830aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
831aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
832aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
833aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
834aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
835aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
83682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
83782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
83882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
839f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
840f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
841a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
842f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
843d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
844d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
845d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
846d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
8476926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
848d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
849d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
850d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
851260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
852889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
853260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
854746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
855746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
856746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
85754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
85817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
85970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
86070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
86170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
86270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
863ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawWithTextureAndColor(bool isAlpha8 = false);
864aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
86515bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
866710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik    void setupDrawAA();
867ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPoint(float pointSize);
8688d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
86970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
87086568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
8714121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
87270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
87370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
87470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
87570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
87670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
87770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
87870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
87970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
8808a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase    void setupDrawModelViewIdentity(bool offset = false);
88170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
88270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
88370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
88470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
885ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPointUniforms();
88670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
88786568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
8888d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
88970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
89070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
89170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
89270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
893aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
8948f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
8958f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
8964121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
8978d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
898ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLvoid* colors);
89915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
9005b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawVertices(GLvoid* vertices);
90170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
902f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
903746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
90411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    bool updateLayer(Layer* layer, bool inFrame);
90511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    void updateLayers();
90611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
90717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
90817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
90917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
91017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
9113a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
9123a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
9138ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
9148ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Renders the specified region as a series of rectangles. The region
9158ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * must be in screen-space coordinates.
9168ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
9178ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void drawRegionRects(const SkRegion& region, int color, SkXfermode::Mode mode,
9188ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy            bool dirty = false);
9198ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9208ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
9218ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
9228ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is turned on.
9238ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
9248ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void debugClip();
9258ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9267c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void debugOverdraw(bool enable, bool clear);
9277c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void renderOverdraw();
9287c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
929746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
930746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
931746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
932746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
933746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
934746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
935746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
9363b753829ae858d424fe109f714745379a6daf455Romain Guy    inline mat4& currentTransform() const {
9373b753829ae858d424fe109f714745379a6daf455Romain Guy        return *mSnapshot->transform;
9383b753829ae858d424fe109f714745379a6daf455Romain Guy    }
9393b753829ae858d424fe109f714745379a6daf455Romain Guy
940bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
941bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
942bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
94385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
944260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
945bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
946c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
947c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
948c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
949bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
950bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
951f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
952ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
953bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
954bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
9552b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // State used to define the clipping region
9565f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    Rect mTilingClip;
9579d5316e3f56d138504565ff311145ac01621dff4Romain Guy
958026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
959ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
960ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
961c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // shader, filters, and shadow
962c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
9635ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
9645ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
96582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
966fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
9673bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    Extensions& mExtensions;
9688694230ff25fa0a60e480d424843e56b718f0516Romain Guy
9698f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
97054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
9718f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of functors to invoke after a frame is drawn
972ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    SortedVector<Functor*> mFunctors;
97311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    // List of layers to update at the beginning of a frame
97411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    Vector<Layer*> mLayerUpdates;
97554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
976746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
977746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
978746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
97970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
98070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
98170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
98270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
98370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
98470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
98570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
98670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
98770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
98870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
98970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
99070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
9912b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // Indicate whether we are drawing an opaque frame
9922b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    bool mOpaqueFrame;
99370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
99487e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
99587e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // Properties.h
99687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    bool mScissorOptimizationDisabled;
99787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
99854c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    // No-ops start/endTiling when set
99954c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    bool mSuppressTiling;
100054c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
1001ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    // Optional name of the renderer
1002ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy    String8 mName;
1003ef35927abcd089652f87a985dd6dde7afde58b92Romain Guy
1004b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
1005257ae3502cfad43df681b1783528d645bdabc63fRomain Guy    friend class TextSetupFunctor;
1006b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
1007bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
1008e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10099d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
1010e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
1011e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10125b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
1013