OpenGLRenderer.h revision 17112ad8a21a77620eb1ff14dcf8bdd6b7859712
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
6617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
6717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates whether this renderer executes drawing commands immediately.
6817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * If this method returns true, the drawing commands will be executed
6917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * later.
7017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
7149c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy    virtual bool isDeferred();
7249c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy
7317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
7417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Sets the dimension of the underlying drawing surface. This method must
7517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * be called at least once every time the drawing surface changes size.
7617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
7717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param width The width in pixels of the underlysing surface
7817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param height The height in pixels of the underlysing surface
7917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
80b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
81e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
8217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
8317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
8417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. When this method is invoked, the
8517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * entire drawing surface is assumed to be redrawn.
8617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
8717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
8817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
8917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared
9017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
9144b2fe3fc114ee5f7273c6b0fee2cc999bf244a2Chet Haase    ANDROID_API int prepare(bool opaque);
9217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
9317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
9417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Prepares the renderer to draw a frame. This method must be invoked
9517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * at the beginning of each frame. Only the specified rectangle of the
9617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * frame is assumed to be dirty. A clip will automatically be set to
9717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the specified rectangle.
9817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
9917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param left The left coordinate of the dirty rectangle
10017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param top The top coordinate of the dirty rectangle
10117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param right The right coordinate of the dirty rectangle
10217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param bottom The bottom coordinate of the dirty rectangle
10317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * @param opaque If true, the target surface is considered opaque
10417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               and will not be cleared. If false, the target surface
10517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *               will be cleared in the specified dirty rectangle
10617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
10744b2fe3fc114ee5f7273c6b0fee2cc999bf244a2Chet Haase    virtual int prepareDirty(float left, float top, float right, float bottom, bool opaque);
108e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy
10917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
11017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Indicates the end of a frame. This method must be invoked whenever
11117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * the caller is done rendering a frame.
11217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
11317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    virtual void finish();
1146c319ca1275c8db892c39b48fc54864c949f9171Romain Guy
1158f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    ANDROID_API status_t invokeFunctors(Rect& dirty);
116ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void detachFunctor(Functor* functor);
117ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void attachFunctor(Functor* functor);
1188f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
11908ae317c21ec3086b5017672bba87420cc38a407Romain Guy
1207953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API int getSaveCount() const;
1214aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual int save(int flags);
1224aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restore();
1234aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void restoreToCount(int saveCount);
124bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
125e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayer(float left, float top, float right, float bottom,
1265c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            SkPaint* p, int flags);
127e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
128e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            int alpha, int flags);
129bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
1304aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void translate(float dx, float dy);
1314aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void rotate(float degrees);
1324aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void scale(float sx, float sy);
133807daf7df615b60ce6fc41355aabe3aa353cebabRomain Guy    virtual void skew(float sx, float sy);
134f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
1357953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API void getMatrix(SkMatrix* matrix);
1364aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setMatrix(SkMatrix* matrix);
1374aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void concatMatrix(SkMatrix* matrix);
138f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy
1397953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API const Rect& getClipBounds();
1407953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API bool quickReject(float left, float top, float right, float bottom);
1418a4ac610e1aaf04931ac1af54b146a7fc8e66114Romain Guy    bool quickRejectNoScissor(float left, float top, float right, float bottom);
1424aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
143a23eed808a1ae4ec0d818c0a9238385e797fd056Chet Haase    virtual Rect* getClipRect();
144bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
1451271e2cc80b01d577e9db339459ef0222bb9320dChet Haase    virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t flags,
1461271e2cc80b01d577e9db339459ef0222bb9320dChet Haase            uint32_t level = 0);
147ed30fd8e9a2d65ee5c8520de55b0089c219f390cChet Haase    virtual void outputDisplayList(DisplayList* displayList, uint32_t level = 0);
148486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLayer(Layer* layer, float x, float y, SkPaint* paint);
149486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
150486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
151486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
152e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
1535c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float dstRight, float dstBottom, SkPaint* paint);
154486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapData(SkBitmap* bitmap, float left, float top, SkPaint* paint);
155486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
1565a7b466a2b4b7ced739bd5c31e022de61650545aRomain Guy            float* vertices, int* colors, SkPaint* paint);
157486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
1584bb942083a0d4db746adf95349108dd8ef842e32Romain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
1595c13d89c1332fcc499379b9064b891187b75ca32Chet Haase            float left, float top, float right, float bottom, SkPaint* paint);
160be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    status_t drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
161be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
162be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            float left, float top, float right, float bottom, int alpha, SkXfermode::Mode mode);
163486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
164486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRect(float left, float top, float right, float bottom, SkPaint* paint);
165486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
16601d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy            float rx, float ry, SkPaint* paint);
167486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawCircle(float x, float y, float radius, SkPaint* paint);
168486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawOval(float left, float top, float right, float bottom, SkPaint* paint);
169486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
1708b2f5267f16c295f12faab810527cd6311997e34Romain Guy            float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
171486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPath(SkPath* path, SkPaint* paint);
172486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawLines(float* points, int count, SkPaint* paint);
173486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPoints(float* points, int count, SkPaint* paint);
174486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
175325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            float hOffset, float vOffset, SkPaint* paint);
176486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
177325740fb444af8fc7fb0119b2e30ce322c2ae134Romain Guy            const float* positions, SkPaint* paint);
178c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
179996e57c84368058be793897ebc355b917a59abc2Raph Levien            const float* positions, SkPaint* paint, float length = -1.0f);
18085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
1814aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
1824aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
183d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
1844aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
1854aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
186db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
1874aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
1884aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
1891e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
1905ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
1915ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
1925ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
1935ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint* filterPaint(SkPaint* paint);
1945ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
19517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
19617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Returns the desired size for the stencil buffer. If the returned value
19717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is 0, then no stencil buffer is required.
19817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
199530041d3191ce817832a0108514617768e43cda6Romain Guy    ANDROID_API static uint32_t getStencilSize();
200530041d3191ce817832a0108514617768e43cda6Romain Guy
20117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
20217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Sets the alpha on the current snapshot. This alpha value will be modulated
20317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
20417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
20517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    void setAlpha(float alpha) {
20617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy        mSnapshot->alpha = alpha;
20717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    }
20817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
20917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
21017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
21117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
21217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
21317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
21413631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
21517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
21617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
21717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
21817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
21913631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
22013631f3da855f200a151e7837ed9f6b079622b58Romain Guy
221e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
22217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
22317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
22417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * This method must be invoked before handing control over to a draw functor.
22517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * See callDrawGLFunction() for instance.
22617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
22717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * This command must not be recorded inside display lists.
22817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
22917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    void interrupt();
23017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
23117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
23217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * This method must be invoked after getting control back from a draw functor.
23317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     *
23417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * This command must not be recorded inside display lists.
23517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
23617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    void resume();
23717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
238e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
239e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
240e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
241e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
242e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
243e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
244e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
245e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
246e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
247e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual void composeLayer(sp<Snapshot> current, sp<Snapshot> previous);
248694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
249ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
250f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
251ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
252f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
253ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
254ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
255f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Returns the current snapshot.
256ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
257f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    sp<Snapshot> getSnapshot() {
258f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot;
259f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
260ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
26142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
26242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
26342f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
264f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual Region* getRegion() {
265f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
266f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
267f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
26842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
26942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
27042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
271f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    virtual bool hasLayer() {
272f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
273f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
2741bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
27542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
27642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
27742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
27842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    virtual GLint getTargetFbo() {
27942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
28042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
28142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
28277a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
28377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
28477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
28577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
28677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
28777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
28877a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
28977a811610f99e21da7f88dafef60d09f345d0506Romain Guy
290be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
291be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
292be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER.
293be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
294be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
295be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
296be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
297be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
298be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    inline void getAlphaAndMode(SkPaint* paint, int* alpha, SkXfermode::Mode* mode);
299be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
300be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
301be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
302be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
303be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * not multiply the paint's alpha by the current snapshot's alpha.
304be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
305be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
306be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
307be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
308be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
309be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline void getAlphaAndModeDirect(SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
310be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (paint) {
311be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *mode = getXfermode(paint->getXfermode());
312be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
313be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            // Skia draws using the color's alpha channel if < 255
314be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            // Otherwise, it uses the paint's alpha
315be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            int color = paint->getColor();
316be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *alpha = (color >> 24) & 0xFF;
317be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            if (*alpha == 255) {
318be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy                *alpha = paint->getAlpha();
319be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            }
320be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        } else {
321be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *mode = SkXfermode::kSrcOver_Mode;
322be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            *alpha = 255;
323be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
324be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
325be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
326be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
327be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
328be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
329be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
330be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
331be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        SkXfermode::Mode resultMode;
332be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (!SkXfermode::AsMode(mode, &resultMode)) {
333be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            resultMode = SkXfermode::kSrcOver_Mode;
334be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
335be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        return resultMode;
336be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
337be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
33808ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
3395cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
340ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
341ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
342ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
343ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
344ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
345ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
3465cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Saves the current state of the renderer as a new snapshot.
3475cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * The new snapshot is saved in mSnapshot and the previous snapshot
3485cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * is linked from mSnapshot->previous.
3495cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
3508aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     * @param flags The save flags; see SkCanvas for more information
3518aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy     *
3525cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @return The new save count. This value can be passed to #restoreToCount()
3535cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
3548aef54fa17f2a3753d9a8f2027629bc480088f69Romain Guy    int saveSnapshot(int flags);
3555cbbce535744b89df5ecea95de21ee3733298260Romain Guy
3565cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
3575cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Restores the current snapshot; mSnapshot becomes mSnapshot->previous.
3585cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
3592542d199745cdf3ec910b8e3e4cff5851ed24e9bRomain Guy     * @return True if the clip was modified.
3605cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
361bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    bool restoreSnapshot();
362bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
3635cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
3645cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
3655cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
3665cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
367bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
368bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
3695cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
370d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
371d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
372d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
373d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
374d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
375d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
376d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
377d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
378d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
379d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
380eb99356a0548684a501766e6a524529ab93304c8Romain Guy     * @param previousFbo The name of the current framebuffer
381d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
382d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
383d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
384d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom,
385eb99356a0548684a501766e6a524529ab93304c8Romain Guy            int alpha, SkXfermode::Mode mode, int flags, GLuint previousFbo);
386d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
387d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
3885b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
3895b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
3905b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
3915b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
3925b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
3935b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param previousFbo The name of the current framebuffer
3945b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
3955b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    bool createFboLayer(Layer* layer, Rect& bounds, sp<Snapshot> snapshot,
3965b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            GLuint previousFbo);
3975b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
3985b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
3995b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
4005b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
4015b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
4025b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
4035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
4045b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
4055b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
4065b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
4075b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
4085b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
4095b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
4105b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
4115b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
4125b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
4135b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
4145b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
41554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
41654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
41754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
41854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
41954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
42054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
42154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
422f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
423f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
424f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
425f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
426f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
427f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
428f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
429f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
430f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
431f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
432f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
433f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
434f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
4355cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
4365cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
4375cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
4385cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
4395cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
4405cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
4415cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
4425cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
443026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
4443d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
4455b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreBlending True if the blending is set by the caller
4465cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
447026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
4481c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
4495cbbce535744b89df5ecea95de21ee3733298260Romain Guy
45054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
45154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
45254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
45354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
45454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
45554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
45654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
45754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
45854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
45954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
46054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
461486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawShape(float left, float top, const PathTexture* texture, SkPaint* paint);
46254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
46354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
46454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as a shape.
46554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This will render the rect using a path texture, which is used to render
46654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * rects with stroke effects.
46754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
46854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
46954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
47054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
47154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
47254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param p The paint to draw the rect with
47354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
474486590963e2207d68eebd6944fec70d50d41116aChet Haase    status_t drawRectAsShape(float left, float top, float right, float bottom, SkPaint* p);
475c1cd9ba335b293f11e1082447ef08e474710a05fRomain Guy
47654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
47754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
47854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
47954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
48054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
48154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
48254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
48354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
48454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
485a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy    void drawAlphaBitmap(Texture* texture, float left, float top, SkPaint* paint);
486a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
48754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
48854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Renders the rect defined by the specified bounds as an anti-aliased rect.
48954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
49054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the rect to draw
49154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the rect to draw
49254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param right The right coordinate of the rect to draw
49354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param bottom The bottom coordinate of the rect to draw
49454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param color The color of the rect
49554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param mode The blending mode to draw the rect
49654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
497858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase    void drawAARect(float left, float top, float right, float bottom,
498858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase            int color, SkXfermode::Mode mode);
499858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
5005cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5015cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
5025cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
5035cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
5045cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
5055cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
5065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
5075cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
5085cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
5095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
510d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
511c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
5125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
513bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
514a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
515c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
516026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
51782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
51882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
51982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
52082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
52182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
52282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
52382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
52482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
52582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
52682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
527a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
5288164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy            Texture* texture, SkPaint* paint);
52982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
53082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
53103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
53203750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
53303750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
53482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
53582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
53682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
53782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
53882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
53982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
54082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
54182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
54282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
54382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
54482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
54582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
546f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
547f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
54803750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
5495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param ignoreScale True if the model view matrix should not be scaled
5505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
551f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
552f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
553a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
5546820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
5555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
5565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool ignoreScale = false, bool dirty = true);
557f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
558f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
5590a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
5600a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
5610a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
5620a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
5630a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param length The length in pixels of the text, can be <= 0.0f to force a measurement
5640a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
5650a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
5660a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
5670a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
5680a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy    void drawTextDecorations(const char* text, int bytesCount, float length,
5690a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy            float x, float y, SkPaint* paint);
5701e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
571416a847633680d94efb926837efdc18726d54918Raph Levien   /**
572416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
573416a847633680d94efb926837efdc18726d54918Raph Levien     *
574416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
575416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
576416a847633680d94efb926837efdc18726d54918Raph Levien     * @param bytesCount The number of bytes in the text
577416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
578416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
579416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
580416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
581416a847633680d94efb926837efdc18726d54918Raph Levien     * @param mode The xfermode for drawing the shadow
582416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
583416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
584416a847633680d94efb926837efdc18726d54918Raph Levien     */
585416a847633680d94efb926837efdc18726d54918Raph Levien    void drawTextShadow(SkPaint* paint, const char* text, int bytesCount, int count,
586416a847633680d94efb926837efdc18726d54918Raph Levien            const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode,
587416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
588416a847633680d94efb926837efdc18726d54918Raph Levien
58954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
59054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
59154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
59254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
59354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
59454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
59554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
59654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
59754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
598416a847633680d94efb926837efdc18726d54918Raph Levien     void drawPathTexture(const PathTexture* texture, float x, float y, SkPaint* paint);
59901d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
6001e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
601ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
602026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
603026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
6048ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
605026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
606026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
607026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
608026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
609026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
610026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
611026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
612026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
6138ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
614746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
615746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
616a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
617746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
618746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        glBindTexture(GL_TEXTURE_2D, texture);
619746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
620746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
621746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
622aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
623aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
624aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
625aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
626aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy        glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
627aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
628aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
629aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
63082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
63182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
63282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
633f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
634f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
635a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
636f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
637d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
638d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
639d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
640d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
6416926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
642d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
643d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
644d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
645260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
646889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
647260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
648746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
649746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
650746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
65154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
65217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
65370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
65470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
65570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
65670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
657aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
65815bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
6595b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawAALine();
660ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPoint(float pointSize);
66170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(int color);
6628d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
66370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
66486568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
6654121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
66670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
66770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
66870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
66970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
67070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
67170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
67270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
67370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
6748a5cc92a150bae38ec43732d941b38bb381fe153Chet Haase    void setupDrawModelViewIdentity(bool offset = false);
67570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelView(float left, float top, float right, float bottom,
67670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false, bool ignoreModelView = false);
67770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawModelViewTranslate(float left, float top, float right, float bottom,
67870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool ignoreTransform = false);
679ed6fcb034b44d9a6ac2fc72fee6030417811f234Romain Guy    void setupDrawPointUniforms();
68070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
68186568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
6828d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawShaderIdentityUniforms();
68370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
68470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
68570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
68670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
687aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
6888f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
6898f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
6904121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
6918d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawMesh(GLvoid* vertices, GLvoid* texCoords = NULL, GLuint vbo = 0);
69215bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawMeshIndices(GLvoid* vertices, GLvoid* texCoords);
6935b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase    void setupDrawVertices(GLvoid* vertices);
69499585adeb4167ca357a72eb866f34c1af944f4b9Chet Haase    void setupDrawAALine(GLvoid* vertices, GLvoid* distanceCoords, GLvoid* lengthCoords,
6957b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy            float strokeWidth, int& widthSlot, int& lengthSlot);
6967b63142d2f4bc32beacedcc761453b8aea1f3a86Romain Guy    void finishDrawAALine(const int widthSlot, const int lengthSlot);
69770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void finishDrawTexture();
698f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
699746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
70017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
70117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
70217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
70317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
7043a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy    void drawRegionRects(const Region& region);
7053a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
706746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
707746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
708746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
709746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
710746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
711746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
712746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
713bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Dimensions of the drawing surface
714bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mWidth, mHeight;
715bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
71685bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy    // Matrix used for ortho projection in shaders
717260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy    mat4 mOrthoMatrix;
718bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
719c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    // Model-view matrix used to position/size objects
720c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
721c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
722bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Number of saved states
723bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    int mSaveCount;
724f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy    // Base state
725ae5575b3421c8fbe590ab046d7d5f2b36ecfd821Romain Guy    sp<Snapshot> mFirstSnapshot;
726bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    // Current state
727bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    sp<Snapshot> mSnapshot;
7289d5316e3f56d138504565ff311145ac01621dff4Romain Guy
7299d5316e3f56d138504565ff311145ac01621dff4Romain Guy    // Shaders
73006f96e2652e4855b6520ad9dd70583677605b79aRomain Guy    SkiaShader* mShader;
731026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
732db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    // Color filters
733db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    SkiaColorFilter* mColorFilter;
734db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
735026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
736ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
737ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
7381e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    // Drop shadow
7391e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    bool mHasShadow;
7401e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowRadius;
7411e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDx;
7421e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    float mShadowDy;
7431e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    int mShadowColor;
7441e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
7455ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    // Draw filters
7465ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    bool mHasDrawFilter;
7475ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterClearBits;
7485ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    int mPaintFilterSetBits;
7495ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
7505ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
75182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
752fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
7538694230ff25fa0a60e480d424843e56b718f0516Romain Guy
7548f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
75554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
7568f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of functors to invoke after a frame is drawn
757ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    SortedVector<Functor*> mFunctors;
75854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
75999bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    // Indentity matrix
76099bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy    const mat4 mIdentity;
76199bcdc52dcb365ed7d8cfa13540fb33fbcbbac9dRomain Guy
762746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    // Indicates whether the clip must be restored
763746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    bool mDirtyClip;
764746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
76570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
76670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
76770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
76870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
76970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
77070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
77170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
77270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
77370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
77470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
77570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
77670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
77770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
778b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
779b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
780bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
781e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
7829d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
783e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
784e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
7855b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
786