OpenGLRenderer.h revision ed6fcb034b44d9a6ac2fc72fee6030417811f234
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>
328694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
34c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
3551769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
36f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
375cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
38bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
395cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
40f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4106f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
42db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
43fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
44bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
45e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
469d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
47e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
48f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
49f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
50f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
520fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
53b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
545cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
555cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
565cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
575cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
5885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
59e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
6085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    OpenGLRenderer();
61e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
62e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
63b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
64e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
657d7b5490a0b0763e831b31bc11f17d8159b5914aRomain Guy    void prepare(bool opaque);
667d7b5490a0b0763e831b31bc11f17d8159b5914aRomain Guy    virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
67e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void finish();
68e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
696c319ca1275c8db892c39b48fc54864c949f9171Romain Guy    // These two calls must not be recorded in display lists
70daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void interrupt();
71daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void resume();
726c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
73cabfcc1364eb7e4de0b15b3574fba45027b45cfcRomain Guy    virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
7408ae317c21ec3086b5017672bba87420cc38a407Romain Guy
75bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int getSaveCount() const;
764aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
774aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
784aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
79bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
80e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
815c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            SkPaint* p, int flags);
82e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
83e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            int alpha, int flags);
84bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
854aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
864aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
874aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
88807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
89f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
9041030da16856c8869e1e51d4a0405432fa96614eRomain Guy    const float* getMatrix() const;
91f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void getMatrix(SkMatrix* matrix);
924aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
934aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
94f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
959d5316e3f56d138504565ff311145ac01621dff4Romain Guy    const Rect& getClipBounds();
96c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    bool quickReject(float left, float top, float right, float bottom);
974aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
98bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
997b5b6abf852c039983eded25ebe43a70fef5a4abRomain Guy    virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
1007b5b6abf852c039983eded25ebe43a70fef5a4abRomain Guy            Rect& dirty, uint32_t level = 0);
101ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
1025c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
1035c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
104e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
105e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
1065c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
1075a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy    virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1085a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
1094aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
1104bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
1115c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
112e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawColor(int color, SkXfermode::Mode mode);
1135c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
11401d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    virtual void drawRoundRect(float left, float top, float right, float bottom,
11501d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
11601d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
117c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
1188b2f5267f16c295f12faab810527cd6311997e34Romain Guy    virtual void drawArc(float left, float top, float right, float bottom,
1198b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
120e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawPath(SkPath* path, SkPaint* paint);
1215c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawLines(float* points, int count, SkPaint* paint);
122ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    virtual void drawPoints(float* points, int count, SkPaint* paint);
123e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
124e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            SkPaint* paint);
12585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
1264aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
1274aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
128d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
1294aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
1304aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
131db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1324aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
1334aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
1341e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
135e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
136e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
137e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
138e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
139e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
140e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
141e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
142e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
143e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
144e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
145e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
146694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
147ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
148f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
149ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
150f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
151ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
152ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
153f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
154ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
155f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    sp<Snapshot> getSnapshot() {
156f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
157f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
158ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
15942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
16042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
16142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
162f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual Region* getRegion() {
163f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
164f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
165f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
16642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
16742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
16842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
169f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual bool hasLayer() {
170f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
171f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
1721bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
17342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
17442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
17542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
17642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    virtual GLint getTargetFbo() {
17742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
17842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
17942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
18008ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
1815cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
1835cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
1845cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
1855cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1868aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
1878aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
1885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
1895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
1908aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
1915cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1925cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1935cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
1945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1952542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
1965cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
197bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
198bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1995cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2005cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
2015cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
2025cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
203bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
204bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2055cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
206d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
207d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
208d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
209d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
210d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
211d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
212d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
213d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
214d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
215d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
216eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
217d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
218d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
219d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
220d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
221eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
222d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
223d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
2245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
2255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2265b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
2275b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
2285b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
2295b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
2305b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2315b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
2325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            GLuint previousFbo);
2335b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
2355b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
2365b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
2385b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
2395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2405b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
2415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2425b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
2435b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
2445b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2455b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
2465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
2475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
2485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
2505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
252f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
253f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
254f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
255f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
256f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
257f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
258f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
259f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
260f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
261f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
262f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
263f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
264f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
2655cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
2665cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
2675cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2685cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
2695cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
2705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
2715cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
2725cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
273026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
2743d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
2755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreBlending True if the blending is set by the caller
2765cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
277026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
2781c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
2795cbbce535744b89df5ecea95de21ee3733298260Romain Guy
280c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    void drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
281c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    void drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
282c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy
283a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
284a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
2855cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2865cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
2875cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
2885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
2905cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
2915cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
2925cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
2935cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
2945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
295d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
296c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
2975cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
298bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
299a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
300c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
301026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
30282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
30382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
30482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
30582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
30682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
30782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
30882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
30982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
31082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
31182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
312a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
3138164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
31482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
31582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
31603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
31703750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
31803750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
31982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
32082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
32182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
32282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
32382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
32482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
32582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
32682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
32782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
32882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
32982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
33082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
331f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
332f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
33303750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
3345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
3355b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
336f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
337f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
338a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
3396820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
3405b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
3415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
342f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
343f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
3440a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
3450a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
3460a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
3470a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
3480a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
3490a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
3500a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
3510a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
3520a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
3530a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
3540a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
3551e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
35601d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
35701d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
3581e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
359ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
360026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
361026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
3628ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
363026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
364026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
365026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
366026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
367026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
368026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
369026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
370026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
3718ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
3728ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
3738ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
3748ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     *
3758ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param paint The paint to extract values from
3768ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param alpha Where to store the resulting alpha
3778ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param mode Where to store the resulting xfermode
3788ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     */
3795c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
3808ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy
381f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
382746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
383746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
384a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
385746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
386746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
387746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
388746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
389746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
390746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Sets the wrap modes for the specified texture. The wrap modes are modified
391746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * only when needed.
392746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
393746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT);
394a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy
395a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy    /**
39682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
39782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
39882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
399f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
400f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
401a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
402f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
403f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
404f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
405f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
406a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy    inline SkXfermode::Mode getXfermode(SkXfermode* mode);
40782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
408260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    /**
409d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
410d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
411d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
412d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
4136926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
414d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
415d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
416d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
417260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
418889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
419260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
420746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
421746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
422746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
423746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    void setupDraw();
42470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
42570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
42670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
42770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
428ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPoint(float pointSize);
42970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(int color);
4308d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
43170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
43286568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
43386568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(float r, float g, float b, float a);
43470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
43570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
43670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
43770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
43870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
43970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
44070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
44170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
4428d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawModelViewIdentity();
44370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
44470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
44570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
44670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
447ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPointUniforms();
44870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
44986568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
4508d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
45170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
45270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
45370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
45470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
4558d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
45670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
457746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
4583a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
4593a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
460746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
461746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
462746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
463746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
464746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
465746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
466746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
467bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
468bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
469bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
47085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
471260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
472bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
473c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
474c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
475c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
476bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
477bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
478f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
479ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
480bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
481bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
4829d5316e3f56d138504565ff311145ac01621dff4Romain Guy
4839d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
48406f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
485026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
486db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
487db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
488db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
489026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
490ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
491ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
4921e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
4931e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
4941e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
4951e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
4961e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
4971e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
4981e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
49982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
500fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
5018694230ff25fa0a60e480d424843e56b718f0516Romain Guy
50299bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    // Indentity matrix
50399bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    const mat4 mIdentity;
50499bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy
505746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
506746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
507746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
50870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
50970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
51070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
51170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
51270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
51370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
51470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
51570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
51670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
51770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
51870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
51970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
52070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Texture coordinates slot
52170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    int mTexCoordsSlot;
52270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
523b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
524b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
525bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
526e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
5279d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
528e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
529e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
5305b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
531