OpenGLRenderer.h revision 33f6beb10f98e8ba96250e284876d607055d278d
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/*
2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2010 The Android Open Source Project
3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License.
6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at
7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy *
10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software
11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and
14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License.
15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */
16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_OPENGL_RENDERER_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_OPENGL_RENDERER_H
199d5316e3f56d138504565ff311145ac01621dff4Romain Guy
209d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2.h>
219d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2ext.h>
2285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
23ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkBitmap.h>
24f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h>
25ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h>
26079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h>
27d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy#include <SkShader.h>
2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
29e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
30daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h>
31bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
328694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
347953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
357953745dd565167113f8cbfc461bc0521d32d870Romain Guy
36c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
3751769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
38f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
395cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
40bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
415cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Snapshot.h"
42f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy#include "Vertex.h"
4306f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include "SkiaShader.h"
44db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
45fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
46bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
47e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
489d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
49e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
50f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
51f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
52f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
53f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
540fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guyclass DisplayList;
55b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
565cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
575cbbce535744b89df5ecea95de21ee3733298260Romain Guy * OpenGL renderer used to draw accelerated 2D graphics. The API is a
585cbbce535744b89df5ecea95de21ee3733298260Romain Guy * simplified version of Skia's Canvas API.
595cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
6085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass OpenGLRenderer {
61e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
627953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API OpenGLRenderer();
63e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
64e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
65b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
66e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
677953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void prepare(bool opaque);
687d7b5490a0b0763e831b31bc11f17d8159b5914aRomain Guy    virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
69e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void finish();
70e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
716c319ca1275c8db892c39b48fc54864c949f9171Romain Guy    // These two calls must not be recorded in display lists
72daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void interrupt();
73daf98e941e140e8739458126640183b9f296a2abChet Haase    virtual void resume();
746c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
75cabfcc1364eb7e4de0b15b3574fba45027b45cfcRomain Guy    virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
7608ae317c21ec3086b5017672bba87420cc38a407Romain Guy
777953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API int getSaveCount() const;
784aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
794aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
804aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
81bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
82e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
835c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            SkPaint* p, int flags);
84e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
85e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            int alpha, int flags);
86bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
874aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
884aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
894aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
90807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
91f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
927953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void getMatrix(SkMatrix* matrix);
934aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
944aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
95f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
967953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API const Rect& getClipBounds();
977953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API bool quickReject(float left, float top, float right, float bottom);
984aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
99bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1007b5b6abf852c039983eded25ebe43a70fef5a4abRomain Guy    virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
10133f6beb10f98e8ba96250e284876d607055d278dRomain Guy            Rect& dirty, int32_t flags, uint32_t level = 0);
102ed30fd8e9a2d65ee5c8520de55b0089c219f390cChet Haase    virtual void outputDisplayList(DisplayList* displayList, uint32_t level = 0);
103ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
1045c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
1055c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
106e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
107e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
1085c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
1095a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy    virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1105a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
1114aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
1124bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
1135c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
114e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawColor(int color, SkXfermode::Mode mode);
1155c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
11601d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    virtual void drawRoundRect(float left, float top, float right, float bottom,
11701d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
11801d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
119c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
1208b2f5267f16c295f12faab810527cd6311997e34Romain Guy    virtual void drawArc(float left, float top, float right, float bottom,
1218b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
122e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawPath(SkPath* path, SkPaint* paint);
1235c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    virtual void drawLines(float* points, int count, SkPaint* paint);
124ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    virtual void drawPoints(float* points, int count, SkPaint* paint);
125e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
126cac5fd3e09e9dc918753d4aff624bf29a367ade3Romain Guy            SkPaint* paint, float length = -1.0f);
127eb9a5367e8f0e970db8509ffb2584f5376bc62edRomain Guy    virtual void drawPosText(const char* text, int bytesCount, int count, const float* positions,
128eb9a5367e8f0e970db8509ffb2584f5376bc62edRomain Guy            SkPaint* paint);
12985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
1304aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
1314aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
132d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
1334aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
1344aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
135db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1364aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
1374aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
1381e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
1395ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
1405ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
1415ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
1425ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint* filterPaint(SkPaint* paint);
1435ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
144530041d3191ce817832a0108514617768e43cda6Romain Guy    ANDROID_API static uint32_t getStencilSize();
145530041d3191ce817832a0108514617768e43cda6Romain Guy
14613631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
14713631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
14813631f3da855f200a151e7837ed9f6b079622b58Romain Guy
149e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
150e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
151e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
152e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
153e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
154e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
155e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
156e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
157e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
158e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
159e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
160694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
161ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
162f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
163ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
164f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
165ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
166ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
167f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
168ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
169f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    sp<Snapshot> getSnapshot() {
170f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
171f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
172ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
17342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
17442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
17542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
176f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual Region* getRegion() {
177f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
178f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
179f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
18042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
18142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
18242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
183f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual bool hasLayer() {
184f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
185f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
1861bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
18742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
18842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
18942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
19042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    virtual GLint getTargetFbo() {
19142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
19242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
19342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
19477a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
19577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
19677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
19777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
19877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
19977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
20077a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
20177a811610f99e21da7f88dafef60d09f345d0506Romain Guy
20208ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
2035cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
2055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
2065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
2075cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2088aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
2098aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
2105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
2115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
2128aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
2135cbbce535744b89df5ecea95de21ee3733298260Romain Guy
2145cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2155cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
2165cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2172542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
2185cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
219bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
220bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2215cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
2225cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
2235cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
2245cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
225bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
226bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
2275cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
228d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
229d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
230d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
231d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
232d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
233d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
234d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
235d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
236d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
237d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
238eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
239d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
240d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
241d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
242d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
243eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
244d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
245d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
2465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
2475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
2495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
2505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
2515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
2525b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
2545b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            GLuint previousFbo);
2555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
2575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
2585b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2595b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
2605b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
2615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
2635b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
2645b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
2655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
2665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
2675b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
2685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
2695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
2705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
2715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
2725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
27354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
27454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
27554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
27654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
27754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
27854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
27954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
280f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
281f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
282f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
283f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
284f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
285f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
286f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
287f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
288f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
289f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
290f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
291f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
292f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
2935cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
2945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
2955cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
2965cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
2975cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
2985cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
2995cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
3005cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
301026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
3023d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
3035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreBlending True if the blending is set by the caller
3045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
305026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
3061c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
3075cbbce535744b89df5ecea95de21ee3733298260Romain Guy
30854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
30954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
31054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
31154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
31254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
31354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
31454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
31554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
31654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
31754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
31854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
319c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    void drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
32054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
32154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
32254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as a shape.
32354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This will render the rect using a path texture, which is used to render
32454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * rects with stroke effects.
32554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
32654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
32754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
32854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
32954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
33054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param p The paint to draw the rect with
33154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
332c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy    void drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
333c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy
33454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
33554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
33654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
33754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
33854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
33954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
34054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
34154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
34254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
343a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
344a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
34554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
34654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as an anti-aliased rect.
34754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
34854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
34954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
35054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
35154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
35254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param color The color of the rect
35354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param mode The blending mode to draw the rect
35454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
355858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase    void drawAARect(float left, float top, float right, float bottom,
356858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase            int color, SkXfermode::Mode mode);
357858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
3585cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
3595cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
3605cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
3615cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
3625cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
3635cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
3645cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
3655cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
3665cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
3675cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
368d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
369c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
3705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
371bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
372a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
373c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
374026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
37582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
37682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
37782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
37882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
37982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
38082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
38182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
38282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
38382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
38482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
385a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
3868164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
38782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
38882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
38903750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
39003750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
39103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
39282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
39382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
39482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
39582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
39682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
39782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
39882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
39982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
40082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
40182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
40282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
40382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
404f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
405f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
40603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
4075b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
4085b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
409f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
410f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
411a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
4126820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
4135b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
4145b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
415f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
416f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
4170a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
4180a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
4190a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
4200a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
4210a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
4220a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
4230a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
4240a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
4250a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
4260a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
4270a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
4281e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
42954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
43054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
43154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
43254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
43354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
43454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
43554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
43654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
43754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
43801d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy    void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
43901d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
4401e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
441ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
442026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
443026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
4448ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
445026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
446026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
447026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
448026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
449026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
450026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
451026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
452026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
4538ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
4548ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
4558ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
4568ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     *
4578ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param paint The paint to extract values from
4588ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param alpha Where to store the resulting alpha
4598ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * @param mode Where to store the resulting xfermode
4608ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     */
4615c13d89c1332fcc499379b9064b891187b75ca32Chet Haase    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
4628ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy
463f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
464746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
465746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
466a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
467746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
468746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
469746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
470746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
471746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
472aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
473aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
474aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
475aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
476aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
477aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
478aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
479aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
48082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
48182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
48282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
483f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
484f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
485a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
486f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
487f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
488f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
489f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     */
490a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy    inline SkXfermode::Mode getXfermode(SkXfermode* mode);
49182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
492260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    /**
493d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
494d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
495d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
496d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
4976926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
498d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
499d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
500d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
501260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
502889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
503260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
504746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
505746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
506746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
50754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
50870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
50970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
51070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
51170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
512aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
51315bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
5145b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawAALine();
515ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPoint(float pointSize);
51670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(int color);
5178d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
51870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
51986568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
52086568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(float r, float g, float b, float a);
52170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
52270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
52370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
52470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
52570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
52670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
52770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
52870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
5298a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase    void setupDrawModelViewIdentity(bool offset = false);
53070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
53170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
53270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
53370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
534ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPointUniforms();
53570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
53686568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
5378d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
53870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
53970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
54070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
54170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
542aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
5438f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
5448f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
5458d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
54615bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
5475b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawVertices(GLvoid* vertices);
54899585adeb4167ca357a72eb866f34c1af944f4b9Chet Haase    void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, GLvoid* lengthCoords,
54999585adeb4167ca357a72eb866f34c1af944f4b9Chet Haase            float strokeWidth);
55070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
551f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
552746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
5533a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
5543a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
555746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
556746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
557746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
558746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
559746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
560746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
561746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
562bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
563bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
564bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
56585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
566260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
567bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
568c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
569c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
570c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
571bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
572bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
573f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
574ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
575bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
576bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
5779d5316e3f56d138504565ff311145ac01621dff4Romain Guy
5789d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
57906f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
580026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
581db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
582db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
583db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
584026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
585ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
586ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
5871e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
5881e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
5891e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
5901e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
5911e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
5921e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
5931e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
5945ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    // Draw filters
5955ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    bool mHasDrawFilter;
5965ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterClearBits;
5975ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterSetBits;
5985ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
5995ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
60082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
601fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
6028694230ff25fa0a60e480d424843e56b718f0516Romain Guy
60354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    // List of rectagnles to clear after saveLayer() is invoked
60454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
60554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
60699bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    // Indentity matrix
60799bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    const mat4 mIdentity;
60899bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy
609746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
610746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
611746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
61270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
61370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
61470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
61570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
61670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
61770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
61870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
61970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
62070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
62170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
62270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
62370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
62470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
625b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
626b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
627bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
628e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6299d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
630e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
631e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
633