OpenGLRenderer.h revision a979474f15b454c8e2963f239a3770e200bb227c
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>
2685bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
27e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
28bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
29deba785f122a47915756ffd991f5540d952cf937Romain Guy#include <utils/ResourceTypes.h>
30bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
31f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
325cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
345cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
35ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include "TextureCache.h"
36dda570201ac851dd85af3861f7e575721d3345daRomain Guy#include "LayerCache.h"
37f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "PatchCache.h"
38f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
39bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
40e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
419d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
42e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
43f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
44f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Support
45f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
46f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
475cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
48026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy * Structure mapping Skia xfermodes to OpenGL blending factors.
49026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy */
50026c5e16704e817cac7d9c382914c947e34f87e0Romain Guystruct Blender {
51026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    SkXfermode::Mode mode;
52026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    GLenum src;
53026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    GLenum dst;
54026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy}; // struct Blender
55026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
56f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
57f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
58f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
59f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
605cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
615cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
625cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
635cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
6485bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
65e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
6685bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    OpenGLRenderer();
6785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    ~OpenGLRenderer();
68e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
69e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy    void setViewport(int width, int height);
70e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy    void prepare();
7108ae317c21ec3086b5017672bba87420cc38a407Romain Guy
72bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int getSaveCount() const;
73bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int save(int flags);
74bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void restore();
75bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void restoreToCount(int saveCount);
76bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
77bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    int saveLayer(float left, float top, float right, float bottom, const SkPaint* p, int flags);
78bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags);
79bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
80f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void translate(float dx, float dy);
81f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void rotate(float degrees);
82f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void scale(float sx, float sy);
83f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
84f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void setMatrix(SkMatrix* matrix);
85f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void getMatrix(SkMatrix* matrix);
86f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    void concatMatrix(SkMatrix* matrix);
87f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
889d5316e3f56d138504565ff311145ac01621dff4Romain Guy    const Rect& getClipBounds();
89c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    bool quickReject(float left, float top, float right, float bottom);
90bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool clipRect(float left, float top, float right, float bottom);
91bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
92c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy    void drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint);
93f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy    void drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint);
948ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom,
95f86ef57f8bcd8ba43ce222ec6a8b4f67d3600640Romain Guy            float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint);
96deba785f122a47915756ffd991f5540d952cf937Romain Guy    void drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, float left, float top,
97deba785f122a47915756ffd991f5540d952cf937Romain Guy            float right, float bottom, const SkPaint* paint);
9885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    void drawColor(int color, SkXfermode::Mode mode);
99bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawRect(float left, float top, float right, float bottom, const SkPaint* paint);
10085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
10108ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
1025cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1035cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
1045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
1055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
1065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1075cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
1085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
109bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int saveSnapshot();
1105cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1115cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
1135cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1145cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return True if the clip should be also reapplied by calling
1155cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *         #setScissorFromClip().
1165cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
117bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
118bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1195cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1205cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
1215cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
1225cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
123bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
124bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1255cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
126d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Compose the layer defined in the current snapshot with the layer
127d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * defined by the previous snapshot.
128d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
129d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
130d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
131d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param curent The current snapshot containing the layer to compose
132d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param previous The previous snapshot to compose the current layer with
133d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
134d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
135d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
136d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
137d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
138d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
139d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
140d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
141d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
142d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
143d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
144d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
145d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
146d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
147d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
148d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
149d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
150d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
151d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy            int alpha, SkXfermode::Mode mode, int flags);
152d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
153d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
1545cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
1555cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
1565cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1575cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
1585cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
1595cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
1605cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
1615cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
162026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
1635cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
164026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
165026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    		int color, SkXfermode::Mode mode);
1665cbbce535744b89df5ecea95de21ee3733298260Romain Guy
1675cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
1685cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
1695cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
1705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
1715cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
1725cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
1735cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
1745cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
1755cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
1765cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
177d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
178c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
1795cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
180bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
181a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
182c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
183026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
18482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
18582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
18682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
18782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
18882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
18982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
19082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
19182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
19282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
19382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
194a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
195a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            const Texture* texture, const SkPaint* paint);
19682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
19782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
19882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted, the
19982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * mesh is drawn as a simple quad.
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 name to map onto the rectangle
20682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
20782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
20882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
20982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
21082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
21182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param indices The indices of the vertices, can be NULL
21282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
213f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
214f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
215a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
216f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy            GLvoid* vertices, GLvoid* texCoords, GLvoid* indices, GLsizei elementsCount = 0);
217f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
218f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
219026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * Resets the texture coordinates stored in mDrawTextureVertices. Setting the values
220026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
221026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
2228ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
223026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
224026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
225026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
226026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
227026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
228026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
229026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
230026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
2318ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
2328ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
2338ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
2348ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     *
2358ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param paint The paint to extract values from
2368ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param alpha Where to store the resulting alpha
2378ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param mode Where to store the resulting xfermode
2388ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     */
2398ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
2408ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy
241f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
24282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
24382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
24482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
245a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, bool isPremultiplied = true);
24682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
247260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    /**
248260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     * Use the specified shader with the current GL context. If the shader is already
249260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     * in use, it will not be bound again. If it is not in use, the current shader is
250260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     * marked unused and the specified shader becomes used and becomes the new
251260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     * current shader.
2526926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
2536926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     * @return true If the specified shader was already in use, false otherwise.
254260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
2556926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy    inline bool useShader(const sp<Program>& shader);
256260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
257bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
258bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
259bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
26085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
261260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
262bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
263c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
264c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
265c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
266bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
267bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
268f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
269f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    Snapshot mFirstSnapshot;
270bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
271bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
2729d5316e3f56d138504565ff311145ac01621dff4Romain Guy
2739d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
274260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    sp<Program> mCurrentShader;
2759d5316e3f56d138504565ff311145ac01621dff4Romain Guy    sp<DrawColorProgram> mDrawColorShader;
276bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    sp<DrawTextureProgram> mDrawTextureShader;
277026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
278026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
279026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    TextureVertex mDrawTextureVertices[4];
280ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
28182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Last known blend state
28282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    bool mBlend;
28382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    GLenum mLastSrcMode;
28482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    GLenum mLastDstMode;
28582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
28682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
287ce0537b80087a6225273040a987414b1dd081aa0Romain Guy    TextureCache mTextureCache;
288dda570201ac851dd85af3861f7e575721d3345daRomain Guy    LayerCache mLayerCache;
289f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    PatchCache mPatchCache;
290bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
291e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
2929d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
293e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
294e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
2959d5316e3f56d138504565ff311145ac01621dff4Romain Guy#endif // ANDROID_UI_OPENGL_RENDERER_H
296