OpenGLRenderer.h revision 6820ac8b14b4558f5d8b833dde80895306a3e137
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
179d5316e3f56d138504565ff311145ac01621dff4Romain Guy#ifndef ANDROID_UI_OPENGL_RENDERER_H
189d5316e3f56d138504565ff311145ac01621dff4Romain Guy#define ANDROID_UI_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>
31deba785f122a47915756ffd991f5540d952cf937Romain Guy#include <utils/ResourceTypes.h>
328694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
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
515cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
525cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
535cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
545cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
5585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
56e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
5785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    OpenGLRenderer();
5885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    ~OpenGLRenderer();
59e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
60e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy    void setViewport(int width, int height);
61e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy    void prepare();
62da8532c6f48b4c10b5e2ccb9e08690341efa1616Romain Guy    void acquireContext();
63da8532c6f48b4c10b5e2ccb9e08690341efa1616Romain Guy    void releaseContext();
6408ae317c21ec3086b5017672bba87420cc38a407Romain Guy
65bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int getSaveCount() const;
66bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int save(int flags);
67bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void restore();
68bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void restoreToCount(int saveCount);
69bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
70bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    int saveLayer(float left, float top, float right, float bottom, const SkPaint* p, int flags);
71bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags);
72bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
73f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void translate(float dx, float dy);
74f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void rotate(float degrees);
75f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void scale(float sx, float sy);
76f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
77f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void setMatrix(SkMatrix* matrix);
78f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void getMatrix(SkMatrix* matrix);
79f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void concatMatrix(SkMatrix* matrix);
80f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
819d5316e3f56d138504565ff311145ac01621dff4Romain Guy    const Rect& getClipBounds();
82c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    bool quickReject(float left, float top, float right, float bottom);
83079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy    bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
84bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
85c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy    void drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint);
86f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy    void drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint);
878ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom,
88f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy            float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint);
89deba785f122a47915756ffd991f5540d952cf937Romain Guy    void drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, float left, float top,
90deba785f122a47915756ffd991f5540d952cf937Romain Guy            float right, float bottom, const SkPaint* paint);
9185bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    void drawColor(int color, SkXfermode::Mode mode);
92bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawRect(float left, float top, float right, float bottom, const SkPaint* paint);
937fbcc0492fca03857e3c45064f4aa040af817d55Romain Guy    void drawPath(SkPath* path, SkPaint* paint);
9485bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
95d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy    void resetShader();
9606f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    void setupShader(SkiaShader* shader);
97d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
98db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    void resetColorFilter();
99db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    void setupColorFilter(SkiaColorFilter* filter);
100db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1011e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    void resetShadow();
1021e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    void setupShadow(float radius, float dx, float dy, int color);
1031e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
104e8e62a4a032a80409114a37908b5f18ab0080848Romain Guy    void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint);
105694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
10608ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
1075cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
1095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
1105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
1115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1128aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
1138aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
1145cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
1155cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
1168aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
1175cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1185cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1195cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
1205cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1212542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
1225cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
123bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
124bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1255cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1265cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
1275cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
1285cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
129bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
130bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1315cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
132d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Compose the layer defined in the current snapshot with the layer
133d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * defined by the previous snapshot.
134d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
135d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
136d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
137d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param curent The current snapshot containing the layer to compose
138d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param previous The previous snapshot to compose the current layer with
139d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
140d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
141d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
142d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
143d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
144d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
145d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
146d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
147d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
148d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
149d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
150d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
151d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
152d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
153d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
154d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
155d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
156d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
157d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy            int alpha, SkXfermode::Mode mode, int flags);
158d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
159d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
1608694230ff25fa0a60e480d424843e56b718f0516Romain Guy     * Clears all the regions corresponding to the current list of layers.
1618694230ff25fa0a60e480d424843e56b718f0516Romain Guy     * This method MUST be invoked before any drawing operation.
1628694230ff25fa0a60e480d424843e56b718f0516Romain Guy     */
1638694230ff25fa0a60e480d424843e56b718f0516Romain Guy    void clearLayerRegions();
1648694230ff25fa0a60e480d424843e56b718f0516Romain Guy
1658694230ff25fa0a60e480d424843e56b718f0516Romain Guy    /**
1665cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
1675cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
1685cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1695cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
1705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
1715cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
1725cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
1735cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
174026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
1753d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
176f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @paran ignoreBlending True if the blending is set by the caller
1775cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
178026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
1791c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
1805cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1815cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
1835cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
1845cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1855cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
1865cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
1875cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
1885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
1895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
1905cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
191d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
192c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
1935cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
194bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
195a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
196c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
197026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
19882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
19982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
20082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
20182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
20282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
20382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
20482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
20582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
20682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
20782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
208a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
209a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            const Texture* texture, const SkPaint* paint);
21082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
21182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
21282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted, the
21382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * mesh is drawn as a simple quad.
21482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
21582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
21682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
21782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
21882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
21982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
22082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
22182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
22282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
22382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
22482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
22582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param indices The indices of the vertices, can be NULL
22682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
227f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
228f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
229f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
230f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
231a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
2326820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
233f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false, bool ignoreTransform = false);
234f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
235f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
2360a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Prepares the renderer to draw the specified shadow.
2371e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *
2381e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param texture The shadow texture
2391e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param x The x coordinate of the shadow
2401e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param y The y coordinate of the shadow
2411e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param mode The blending mode
2422542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @param alpha The alpha value
2431e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     */
2442542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy    void setupShadow(const ShadowTexture* texture, float x, float y, SkXfermode::Mode mode,
2452542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy            float alpha);
2461e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
2471e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
2480a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
2491e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *
2501e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param texture The texture to render with
2511e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param textureUnit The texture unit to use, may be modified
2521e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param x The x coordinate of the rectangle to draw
2531e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param y The y coordinate of the rectangle to draw
2541e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param r The red component of the color
2551e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param g The green component of the color
2561e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param b The blue component of the color
2571e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param a The alpha component of the color
2581e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param mode The blending mode
2590a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param transforms True if the matrix passed to the shader should be multiplied
2600a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        by the model-view matrix
2611e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     * @param applyFilters Whether or not to take color filters and
2621e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     *        shaders into account
2631e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy     */
2640a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void setupTextureAlpha8(const Texture* texture, GLuint& textureUnit, float x, float y,
2650a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float r, float g, float b, float a, SkXfermode::Mode mode, bool transforms,
2660a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            bool applyFilters);
2670a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy
2680a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    /**
2690a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Prepares the renderer to draw the specified Alpha8 texture as a rectangle.
2700a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
2710a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param texture The texture to render with
2720a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param width The width of the texture
2730a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param height The height of the texture
2740a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param textureUnit The texture unit to use, may be modified
2750a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate of the rectangle to draw
2760a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate of the rectangle to draw
2770a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param r The red component of the color
2780a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param g The green component of the color
2790a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param b The blue component of the color
2800a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param a The alpha component of the color
2810a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param mode The blending mode
2820a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param transforms True if the matrix passed to the shader should be multiplied
2830a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        by the model-view matrix
2840a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param applyFilters Whether or not to take color filters and
2850a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *        shaders into account
2860a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
2870a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void setupTextureAlpha8(GLuint texture, uint32_t width, uint32_t height,
2880a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            GLuint& textureUnit, float x, float y, float r, float g, float b, float a,
2890a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            SkXfermode::Mode mode, bool transforms, bool applyFilters);
2900a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy
2910a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    /**
2920a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
2930a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
2940a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
2950a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
2960a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
2970a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
2980a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
2990a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
3000a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
3010a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
3020a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
3031e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
3041e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
305ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
306026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
307026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
3088ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
309026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
310026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
311026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
312026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
313026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
314026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
315026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
316026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
3178ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
3188ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
3198ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
3208ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     *
3218ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param paint The paint to extract values from
3228ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param alpha Where to store the resulting alpha
3238ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param mode Where to store the resulting xfermode
3248ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     */
3258ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
3268ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy
327f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
328a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     * Binds the specified texture with the specified wrap modes.
329a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
330889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline void bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT, GLuint textureUnit = 0);
331a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy
332a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy    /**
33382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
33482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
33582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
336f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
337f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
338a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
339f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
340f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
341f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
342f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
343a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy    inline SkXfermode::Mode getXfermode(SkXfermode* mode);
34482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
345260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    /**
346d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
347d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
348d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
349d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
3506926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
351d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
352d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
353d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
354260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
355889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
356260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
357bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
358bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
359bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
36085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
361260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
362bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
363c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
364c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
365c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
366bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
367bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
368f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
369ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
370bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
371bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
3729d5316e3f56d138504565ff311145ac01621dff4Romain Guy
3739d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
37406f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
375026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
376db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
377db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
378db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
379026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
380ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
381ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
38251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy    // GL extensions
38351769a68a5cb34e9564740c6a854fcb93018789dRomain Guy    Extensions mExtensions;
38451769a68a5cb34e9564740c6a854fcb93018789dRomain Guy
3851e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
3861e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
3871e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
3881e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
3891e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
3901e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
3911e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
39282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
393fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
3948694230ff25fa0a60e480d424843e56b718f0516Romain Guy
3958694230ff25fa0a60e480d424843e56b718f0516Romain Guy    // List of rectangles to clear due to calls to saveLayer()
3968694230ff25fa0a60e480d424843e56b718f0516Romain Guy    Vector<Rect*> mLayers;
3978694230ff25fa0a60e480d424843e56b718f0516Romain Guy
398bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
399e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
4009d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
401e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
402e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
4039d5316e3f56d138504565ff311145ac01621dff4Romain Guy#endif // ANDROID_UI_OPENGL_RENDERER_H
404