OpenGLRenderer.h revision 8a4ac610e1aaf04931ac1af54b146a7fc8e66114
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/*
2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2010 The Android Open Source Project
3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License.
6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at
7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software
11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and
14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License.
15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */
16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_OPENGL_RENDERER_H
199d5316e3f56d138504565ff311145ac01621dff4Romain Guy
209d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2.h>
219d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2ext.h>
2285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
23ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkBitmap.h>
24f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h>
25ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h>
26079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h>
27d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy#include <SkShader.h>
2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
29e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
30daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h>
31bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
32ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h>
338694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
34bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
357953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
367953745dd565167113f8cbfc461bc0521d32d870Romain Guy
37c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
3851769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
39f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
405cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
41bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
425cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
43f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4406f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
45db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
46fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
47bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
48e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
499d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
50e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
52f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
53f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
54f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
550fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
56b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
575cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
585cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
595cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
605cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
6185bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
62e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
637953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API OpenGLRenderer();
64e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
65e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6649c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy    virtual bool isDeferred();
6749c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy
68b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
69e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
7044b2fe3fc114ee5f7273c6b0fee2cc999bf244a2Chet Haase    ANDROID_API int prepare(bool opaque);
7144b2fe3fc114ee5f7273c6b0fee2cc999bf244a2Chet Haase    virtual int prepareDirty(float left, float top, float right, float bottom, bool opaque);
72e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void finish();
73e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
746c319ca1275c8db892c39b48fc54864c949f9171Romain Guy    // These two calls must not be recorded in display lists
75daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void interrupt();
76daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void resume();
776c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
788f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    ANDROID_API status_t invokeFunctors(Rect& dirty);
79ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void detachFunctor(Functor* functor);
80ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void attachFunctor(Functor* functor);
818f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
8208ae317c21ec3086b5017672bba87420cc38a407Romain Guy
837953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API int getSaveCount() const;
844aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
854aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
864aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
87bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
88e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
895c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            SkPaint* p, int flags);
90e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
91e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            int alpha, int flags);
92bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
93f26c8be01bb218619e073a209c9d57fe9d26c517Romain Guy    void setAlpha(float alpha) {
94db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase        mSnapshot->alpha = alpha;
95db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase    }
96db8c9a6a4d9bf8c39f834b25611926caf21380f6Chet Haase
974aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
984aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
994aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
100807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
101f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
1027953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void getMatrix(SkMatrix* matrix);
1034aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
1044aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
105f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
1067953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API const Rect& getClipBounds();
1077953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API bool quickReject(float left, float top, float right, float bottom);
1088a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    bool quickRejectNoScissor(float left, float top, float right, float bottom);
1094aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
110a23eed808a1ae4ec0d818c0a9238385e797fd056Chet Haase    virtual Rect* getClipRect();
111bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1121271e2cc80b01d577e9db339459ef0222bb9320dChet Haase    virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t flags,
1131271e2cc80b01d577e9db339459ef0222bb9320dChet Haase            uint32_t level = 0);
114ed30fd8e9a2d65ee5c8520de55b0089c219f390cChet Haase    virtual void outputDisplayList(DisplayList* displayList, uint32_t level = 0);
115486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLayer(Layer* layer, float x, float y, SkPaint* paint);
116486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
117486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
118486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
119e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
1205c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
121486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
122486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1235a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
124486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
1254bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
1265c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
127be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
128be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
129be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode);
130486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
131486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
132486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
13301d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
134486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint);
135486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint);
136486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
1378b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
138486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPath(SkPath* path, SkPaint* paint);
139486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLines(float* points, int count, SkPaint* paint);
140486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPoints(float* points, int count, SkPaint* paint);
141486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
142cac5fd3e09e9dc918753d4aff624bf29a367ade3Romain Guy            SkPaint* paint, float length = -1.0f);
143486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
144325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            float hOffset, float vOffset, SkPaint* paint);
145486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
146325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            const float* positions, SkPaint* paint);
14785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
1484aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
1494aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
150d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
1514aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
1524aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
153db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1544aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
1554aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
1561e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
1575ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
1585ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
1595ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
1605ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint* filterPaint(SkPaint* paint);
1615ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
162530041d3191ce817832a0108514617768e43cda6Romain Guy    ANDROID_API static uint32_t getStencilSize();
163530041d3191ce817832a0108514617768e43cda6Romain Guy
16413631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
16513631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
16613631f3da855f200a151e7837ed9f6b079622b58Romain Guy
167e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
168e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
169e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
170e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
171e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
172e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
173e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
174e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
175e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
176e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
177e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
178694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
179ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
180f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
181ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
182f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
183ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
184ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
185f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
186ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
187f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    sp<Snapshot> getSnapshot() {
188f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
189f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
190ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
19142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
19242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
19342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
194f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual Region* getRegion() {
195f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
196f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
197f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
19842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
19942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
20042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
201f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual bool hasLayer() {
202f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
203f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
2041bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
20542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
20642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
20742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
20842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    virtual GLint getTargetFbo() {
20942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
21042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
21142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
21277a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
21377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
21477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
21577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
21677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
21777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
21877a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
21977a811610f99e21da7f88dafef60d09f345d0506Romain Guy
220be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
221be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
222be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
223be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
224be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
225be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
226be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
227be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
228be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
229be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
230be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
231be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
232be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
233be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * not multiply the paint's alpha by the current snapshot's alpha.
234be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
235be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
236be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
237be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
238be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
239be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
240be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (paint) {
241be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *mode = getXfermode(paint->getXfermode());
242be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
243be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            // Skia draws using the color's alpha channel if < 255
244be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            // Otherwise, it uses the paint's alpha
245be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            int color = paint->getColor();
246be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *alpha = (color >> 24) & 0xFF;
247be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            if (*alpha == 255) {
248be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy                *alpha = paint->getAlpha();
249be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            }
250be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        } else {
251be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *mode = SkXfermode::kSrcOver_Mode;
252be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *alpha = 255;
253be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
254be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
255be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
256be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
257be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
258be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
259be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
260be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
261be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        SkXfermode::Mode resultMode;
262be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (!SkXfermode::AsMode(mode, &resultMode)) {
263be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            resultMode = SkXfermode::kSrcOver_Mode;
264be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
265be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        return resultMode;
266be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
267be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
26808ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
2695cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
270ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
271ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
272ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
273ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
274ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
275ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
2765cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
2775cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
2785cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
2795cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2808aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
2818aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
2825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
2835cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
2848aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
2855cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2865cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2875cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
2885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2892542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
2905cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
291bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
292bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2935cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
2955cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
2965cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
297bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
298bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2995cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
300d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
301d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
302d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
303d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
304d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
305d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
306d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
307d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
308d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
309d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
310eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
311d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
312d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
313d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
314d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
315eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
316d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
317d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
3185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
3195b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
3205b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
3215b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
3225b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
3235b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
3245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
3255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
3265b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            GLuint previousFbo);
3275b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
3285b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
3295b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
3305b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
3315b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
3325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
3335b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
3345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
3355b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
3365b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
3375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
3385b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
3395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
3405b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
3415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
3425b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
3435b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
3445b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
34554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
34654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
34754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
34854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
34954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
35054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
35154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
352f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
353f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
354f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
355f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
356f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
357f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
358f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
359f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
360f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
361f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
362f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
363f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
364f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
3655cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
3665cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
3675cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
3685cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
3695cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
3705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
3715cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
3725cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
373026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
3743d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
3755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreBlending True if the blending is set by the caller
3765cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
377026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
3781c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
3795cbbce535744b89df5ecea95de21ee3733298260Romain Guy
38054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
38154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
38254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
38354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
38454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
38554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
38654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
38754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
38854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
38954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
39054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
391486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
39254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
39354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
39454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as a shape.
39554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This will render the rect using a path texture, which is used to render
39654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * rects with stroke effects.
39754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
39854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
39954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
40054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
40154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
40254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param p The paint to draw the rect with
40354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
404486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
405c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy
40654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
40754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
40854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
40954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
41054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
41154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
41254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
41354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
41454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
415a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
416a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
41754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
41854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as an anti-aliased rect.
41954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
42054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
42154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
42254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
42354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
42454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param color The color of the rect
42554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param mode The blending mode to draw the rect
42654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
427858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase    void drawAARect(float left, float top, float right, float bottom,
428858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase            int color, SkXfermode::Mode mode);
429858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
4305cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
4315cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
4325cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
4335cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
4345cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
4355cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
4365cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
4375cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
4385cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
4395cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
440d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
441c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
4425cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
443bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
444a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
445c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
446026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
44782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
44882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
44982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
45082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
45182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
45282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
45382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
45482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
45582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
45682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
457a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
4588164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
45982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
46082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
46103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
46203750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
46303750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
46482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
46582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
46682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
46782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
46882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
46982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
47082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
47182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
47282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
47382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
47482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
47582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
476f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
477f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
47803750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
4795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
4805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
481f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
482f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
483a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
4846820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
4855b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
4865b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
487f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
488f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
4890a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
4900a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
4910a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
4920a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
4930a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
4940a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
4950a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
4960a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
4970a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
4980a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
4990a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
5001e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
50154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
50254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
50354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
50454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
50554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
50654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
50754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
50854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
50954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
51001d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
51101d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
5121e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
513ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
514026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
515026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
5168ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
517026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
518026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
519026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
520026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
521026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
522026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
523026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
524026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
5258ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
526746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
527746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
528a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
529746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
530746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
531746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
532746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
533746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
534aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
535aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
536aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
537aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
538aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
539aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
540aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
541aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
54282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
54382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
54482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
545f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
546f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
547a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
548f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
549d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
550d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
551d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
552d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
5536926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
554d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
555d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
556d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
557260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
558889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
559260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
560746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
561746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
562746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
56354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
56470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
56570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
56670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
56770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
568aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
56915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
5705b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawAALine();
571ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPoint(float pointSize);
57270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(int color);
5738d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
57470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
57586568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
5764121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
57770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
57870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
57970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
58070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
58170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
58270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
58370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
58470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
5858a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase    void setupDrawModelViewIdentity(bool offset = false);
58670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
58770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
58870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
58970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
590ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPointUniforms();
59170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
59286568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
5938d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
59470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
59570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
59670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
59770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
598aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
5998f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
6008f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
6014121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
6028d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
60315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
6045b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawVertices(GLvoid* vertices);
60599585adeb4167ca357a72eb866f34c1af944f4b9Chet Haase    void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, GLvoid* lengthCoords,
6067b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy            float strokeWidth, int& widthSlot, int& lengthSlot);
6077b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy    void finishDrawAALine(const int widthSlot, const int lengthSlot);
60870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
609f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
610746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
6113a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
6123a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
613746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
614746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
615746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
616746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
617746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
618746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
619746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
620bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
621bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
622bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
62385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
624260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
625bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
626c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
627c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
628c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
629bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
630bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
631f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
632ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
633bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
634bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
6359d5316e3f56d138504565ff311145ac01621dff4Romain Guy
6369d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
63706f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
638026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
639db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
640db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
641db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
642026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
643ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
644ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
6451e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
6461e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
6471e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
6481e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
6491e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
6501e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
6511e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
6525ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    // Draw filters
6535ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    bool mHasDrawFilter;
6545ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterClearBits;
6555ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterSetBits;
6565ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
6575ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
65882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
659fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
6608694230ff25fa0a60e480d424843e56b718f0516Romain Guy
6618f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
66254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
6638f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of functors to invoke after a frame is drawn
664ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    SortedVector<Functor*> mFunctors;
66554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
66699bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    // Indentity matrix
66799bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    const mat4 mIdentity;
66899bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy
669746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
670746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
671746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
67270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
67370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
67470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
67570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
67670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
67770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
67870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
67970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
68070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
68170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
68270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
68370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
68470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
685b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
686b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
687bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
688e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6899d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
690e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
691e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
693