OpenGLRenderer.h revision 70ca14e08ae197547ac412e8a1210e1ebdfb2eb1
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
30bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
318694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
32bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
33c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
3451769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
35f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
365cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
37bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
385cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
39f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4006f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
41db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
42fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
43bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
44e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
459d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
46e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
47f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
48f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
49f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
50f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
510fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
52b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
535cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
545cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
555cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
565cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
5785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
58e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
5985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    OpenGLRenderer();
60e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
61e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
62b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
63e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
646b7bd24659fb175fe1f0e97c86c18969918b496aRomain Guy    virtual void prepare(bool opaque);
65e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void finish();
66e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
674aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void acquireContext();
684aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void releaseContext();
6908ae317c21ec3086b5017672bba87420cc38a407Romain Guy
70bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int getSaveCount() const;
714aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
724aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
734aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
74bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
75e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
765c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            SkPaint* p, int flags);
77e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
78e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            int alpha, int flags);
79bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
804aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
814aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
824aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
83f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
8441030da16856c8869e1e51d4a0405432fa96614eRomain Guy    const float* getMatrix() const;
85f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void getMatrix(SkMatrix* matrix);
864aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
874aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
88f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
899d5316e3f56d138504565ff311145ac01621dff4Romain Guy    const Rect& getClipBounds();
90c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    bool quickReject(float left, float top, float right, float bottom);
914aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
92bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
930fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guy    virtual void drawDisplayList(DisplayList* displayList);
945c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
955c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
96e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
97e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
985c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
994aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
1004bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
1015c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
102e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawColor(int color, SkXfermode::Mode mode);
1035c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
104e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawPath(SkPath* path, SkPaint* paint);
1055c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawLines(float* points, int count, SkPaint* paint);
106e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
107e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            SkPaint* paint);
10885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
1094aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
1104aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
111d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
1124aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
1134aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
114db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1154aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
1164aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
1171e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
118e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
119e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
120e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
121e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
122e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
123e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
124e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
125e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
126e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
127e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
128e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
129694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
13008ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
1315cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1325cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
1335cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
1345cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
1355cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1368aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
1378aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
1385cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
1395cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
1408aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
1415cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1425cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1435cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
1445cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1452542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
1465cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
147bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
148bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1495cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1505cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
1515cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
1525cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
153bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
154bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1555cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
156d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
157d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
158d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
159d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
160d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
161d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
162d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
163d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
164d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
165d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
166eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
167d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
168d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
169d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
170d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
171eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
172d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
173d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
1745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
1755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
1765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
1775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
1785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
1795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
1805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
1815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
1825b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            GLuint previousFbo);
1835b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
1845b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
1855b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
1865b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
1875b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
1885b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
1895b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
1905b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
1915b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
1925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
1935b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
1945b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
1955b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
1965b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
1975b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
1985b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
1995b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
2005b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2015b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
2028694230ff25fa0a60e480d424843e56b718f0516Romain Guy     * Clears all the regions corresponding to the current list of layers.
2038694230ff25fa0a60e480d424843e56b718f0516Romain Guy     * This method MUST be invoked before any drawing operation.
2048694230ff25fa0a60e480d424843e56b718f0516Romain Guy     */
2058694230ff25fa0a60e480d424843e56b718f0516Romain Guy    void clearLayerRegions();
2068694230ff25fa0a60e480d424843e56b718f0516Romain Guy
2078694230ff25fa0a60e480d424843e56b718f0516Romain Guy    /**
2085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
2095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
2105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
2125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
2135cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
2145cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
2155cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
216026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
2173d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
2185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreBlending True if the blending is set by the caller
2195cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
220026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
2211c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
2225cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2235cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2245cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
2255cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
2265cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2275cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
2285cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
2295cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
2305cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
2315cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
2325cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
233d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
234c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
2355cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
236bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
237a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
238c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
239026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
24082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
24182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
24282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
24382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
24482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
24582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
24682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
24782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
24882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
24982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
250a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
2518164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
25282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
25382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
25403750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
25503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
25603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
25782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
25882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
25982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
26082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
26182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
26282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
26382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
26482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
26582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
26682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
26782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
26882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
269f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
270f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
27103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
2725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
2735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
274f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
275f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
276a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
2776820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
2785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
2795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
280f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
281f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
282746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Prepares the renderer to draw the specified shadow. The active texture
283746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * unit must be 0 and the other units must be unbound.
2841e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *
2851e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param texture The shadow texture
2861e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param x The x coordinate of the shadow
2871e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param y The y coordinate of the shadow
2881e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param mode The blending mode
2892542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @param alpha The alpha value
2906620c6d413f972819fada92b574f0fa9e96d36c1Romain Guy     * @param ignoreTransforms True if the coordinates are already in screen space
2911e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     */
2922542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy    void setupShadow(const ShadowTexture* texture, float x, float y, SkXfermode::Mode mode,
2936620c6d413f972819fada92b574f0fa9e96d36c1Romain Guy            float alpha, bool ignoreTransforms = false);
2941e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
2951e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
2960a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
2971e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *
2981e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param texture The texture to render with
2991e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param textureUnit The texture unit to use, may be modified
3001e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param x The x coordinate of the rectangle to draw
3011e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param y The y coordinate of the rectangle to draw
3021e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param r The red component of the color
3031e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param g The green component of the color
3041e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param b The blue component of the color
3051e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param a The alpha component of the color
3061e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param mode The blending mode
3070a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param transforms True if the matrix passed to the shader should be multiplied
3080a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        by the model-view matrix
3091e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param applyFilters Whether or not to take color filters and
3101e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *        shaders into account
3111e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     */
3120a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void setupTextureAlpha8(const Texture* texture, GLuint& textureUnit, float x, float y,
3130a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float r, float g, float b, float a, SkXfermode::Mode mode, bool transforms,
3140a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            bool applyFilters);
3150a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy
3160a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    /**
3170a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
3180a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
3190a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param texture The texture to render with
3200a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param width The width of the texture
3210a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param height The height of the texture
3220a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param textureUnit The texture unit to use, may be modified
3230a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate of the rectangle to draw
3240a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate of the rectangle to draw
3250a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param r The red component of the color
3260a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param g The green component of the color
3270a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param b The blue component of the color
3280a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param a The alpha component of the color
3290a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param mode The blending mode
3300a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param transforms True if the matrix passed to the shader should be multiplied
3310a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        by the model-view matrix
3320a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param applyFilters Whether or not to take color filters and
3330a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        shaders into account
3340a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
3350a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
3360a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
3370a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            SkXfermode::Mode mode, bool transforms, bool applyFilters);
3380a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy
3390a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    /**
340759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy     * Same as above setupTextureAlpha8() but specifies the mesh's vertices
34103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * and texCoords pointers. The pointers become offsets when a VBO is bound.
342759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy     */
343759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy    void setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
344759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy            GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
345759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy            SkXfermode::Mode mode, bool transforms, bool applyFilters,
3466620c6d413f972819fada92b574f0fa9e96d36c1Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLuint vbo = 0, bool ignoreTransform = false);
347759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy
348759ea80dca64ad652110a129e0d8bf93fea79f61Romain Guy    /**
3490a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
3500a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
3510a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
3520a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
3530a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
3540a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
3550a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
3560a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
3570a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
3580a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
3590a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
3601e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
3611e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
362ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
363026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
364026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
3658ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
366026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
367026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
368026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
369026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
370026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
371026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
372026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
373026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
3748ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
3758ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
3768ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
3778ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     *
3788ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param paint The paint to extract values from
3798ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param alpha Where to store the resulting alpha
3808ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param mode Where to store the resulting xfermode
3818ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     */
3825c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
3838ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy
384f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
385746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
386746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
387a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
388746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
389746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
390746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
391746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
392746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
393746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Sets the wrap modes for the specified texture. The wrap modes are modified
394746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * only when needed.
395746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
396746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT);
397a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy
398a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy    /**
39982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
40082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
40182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
402f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
403f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
404a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
405f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
406f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
407f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
408f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
409a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy    inline SkXfermode::Mode getXfermode(SkXfermode* mode);
41082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
411260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    /**
412d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
413d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
414d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
415d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
4166926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
417d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
418d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
419d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
420260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
421889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
422260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
423746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
424746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
425746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
426746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    void setupDraw();
42770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
42870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
42970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
43070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
43170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(int color);
43270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
43370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
43470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
43570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
43670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
43770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
43870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
43970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
44070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
44170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
44270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
44370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
44470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
44570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
44670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
44770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
44870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
44970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
45070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords, GLuint vbo = 0);
45170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
452746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
453746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
454746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
455746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
456746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
457746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
458746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
459746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
4605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
4615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
4625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * are transformed with the supplied matrix.
4635b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
4645b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void dirtyLayer(const float left, const float top, const float right, const float bottom,
4655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            const mat4 transform);
4665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
4675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
4685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Mark the layer as dirty at the specified coordinates.
4695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
4705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void dirtyLayer(const float left, const float top, const float right, const float bottom);
4715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
472bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
473bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
474bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
47585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
476260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
477bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
478c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
479c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
480c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
481bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
482bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
483f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
484ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
485bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
486bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
4879d5316e3f56d138504565ff311145ac01621dff4Romain Guy
4889d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
48906f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
490026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
491db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
492db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
493db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
494026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
495ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
496ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
4971e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
4981e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
4991e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
5001e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
5011e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
5021e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
5031e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
50482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
505fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
5068694230ff25fa0a60e480d424843e56b718f0516Romain Guy
5078694230ff25fa0a60e480d424843e56b718f0516Romain Guy    // List of rectangles to clear due to calls to saveLayer()
5088694230ff25fa0a60e480d424843e56b718f0516Romain Guy    Vector<Rect*> mLayers;
5098694230ff25fa0a60e480d424843e56b718f0516Romain Guy
51099bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    // Indentity matrix
51199bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    const mat4 mIdentity;
51299bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy
513746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
514746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
515746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
51670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
51770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
51870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
51970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
52070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
52170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
52270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
52370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
52470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
52570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
52670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
52770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
52870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Texture coordinates slot
52970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    int mTexCoordsSlot;
53070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
531b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
532b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
533bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
534e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
5359d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
536e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
537e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
5385b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
539