OpenGLRenderer.h revision d44fbe55a9f434cb5bb0e34c143ba1445141990d
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
373b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h>
383b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
39c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
4051769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
41f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
425cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
43bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
44b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Renderer.h"
4514e513058ed4168c94e015638d16f5f87fd8063aChris Craik#include "StatefulBaseRenderer.h"
46db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy#include "SkiaColorFilter.h"
47b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Snapshot.h"
483b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h"
49b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Vertex.h"
50fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
51bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
52e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
539d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
54e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
55b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState;
56b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DisplayList;
57b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass TextSetupFunctor;
58b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer;
59b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass SkiaShader;
60b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik
61c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers {
629b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    DrawModifiers() {
639b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy        reset();
649b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    }
659b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy
669b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    void reset() {
679b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy        memset(this, 0, sizeof(DrawModifiers));
689b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    }
699b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy
70c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaShader* mShader;
71c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    SkiaColorFilter* mColorFilter;
7216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    float mOverrideLayerAlpha;
73c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
74c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Drop shadow
75c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasShadow;
76c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowRadius;
77c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDx;
78c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    float mShadowDy;
79c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mShadowColor;
80c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
81c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Draw filters
82c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasDrawFilter;
83c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterClearBits;
84c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterSetBits;
85c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
86c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
87ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags {
88ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Draw = 0x1,
89ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Clip = 0x2
90ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik};
91ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
9228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags {
93a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik    kClipSide_None = 0x0,
9428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Left = 0x1,
9528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Top = 0x2,
9628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Right = 0x4,
9728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Bottom = 0x8,
98d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_Full = 0xF,
99d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_ConservativeFull = 0x1F
10028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik};
10128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik
1024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik/**
1034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Defines additional transformation that should be applied by the model view matrix, beyond that of
1044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * the currentTransform()
1054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */
1064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craikenum ModelViewMode {
1074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
1084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used when the model view should simply translate geometry passed to the shader. The resulting
1094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * matrix will be a simple translation.
1104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
1114063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    kModelViewMode_Translate = 0,
1124063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
1134063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
1144063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used when the model view should translate and scale geometry. The resulting matrix will be a
1154063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect.
1164063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
1174063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    kModelViewMode_TranslateAndScale = 1,
1184063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik};
1194063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
120f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
121f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
122f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
1235cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
12414e513058ed4168c94e015638d16f5f87fd8063aChris Craik * OpenGL Renderer implementation.
1255cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
12614e513058ed4168c94e015638d16f5f87fd8063aChris Craikclass OpenGLRenderer : public StatefulBaseRenderer {
127e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
1287953745dd565167113f8cbfc461bc0521d32d870Romain Guy    ANDROID_API OpenGLRenderer();
129e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
130e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
13187e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    ANDROID_API void initProperties();
13287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
133b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    virtual void setViewport(int width, int height);
1347c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
13517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    virtual void finish();
136c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void interrupt();
137c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy    virtual void resume();
138c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
13978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    ANDROID_API void setCountOverdrawEnabled(bool enabled) {
14078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy        mCountOverdraw = enabled;
14178dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    }
14278dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
14378dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    ANDROID_API float getOverdraw() {
14478dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy        return mCountOverdraw ? mOverdraw : 0.0f;
14578dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    }
14678dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
1478f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    ANDROID_API status_t invokeFunctors(Rect& dirty);
148ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void detachFunctor(Functor* functor);
149ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    ANDROID_API void attachFunctor(Functor* functor);
1508f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
15108ae317c21ec3086b5017672bba87420cc38a407Romain Guy
15211cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void pushLayerUpdate(Layer* layer);
153e93482f5eac3df581d57e64c2a771a96aa868585Romain Guy    ANDROID_API void cancelLayerUpdate(Layer* layer);
15411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    ANDROID_API void clearLayerUpdates();
155405436021da156fbe3c5d4de48bdefa564cf7fc0Romain Guy    ANDROID_API void flushLayerUpdates();
15611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
157d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger    ANDROID_API virtual int saveLayer(float left, float top, float right, float bottom,
158d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger            const SkPaint* paint, int flags);
159bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
160d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    int saveLayerDeferred(float left, float top, float right, float bottom,
161d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger            const SkPaint* paint, int flags);
162d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
1634f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck    virtual status_t drawDisplayList(DisplayList* displayList, Rect& dirty, int32_t replayFlags = 1);
164a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    virtual status_t drawLayer(Layer* layer, float x, float y);
165d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmap(const SkBitmap* bitmap, float left, float top,
166d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
167d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
168d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
169d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmap(const SkBitmap* bitmap, const SkMatrix* matrix,
170d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
171d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
172e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
173d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float dstRight, float dstBottom, const SkPaint* paint);
174d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmapData(const SkBitmap* bitmap, float left, float top,
175d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
176d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
177d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* vertices, const int* colors, const SkPaint* paint);
178d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
179d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
180d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
181d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float left, float top, float right, float bottom, const SkPaint* paint);
182d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
183d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float left, float top, float right, float bottom, const SkPaint* paint);
184486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
185d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawRect(float left, float top, float right, float bottom,
186d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
187486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
188d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float rx, float ry, const SkPaint* paint);
189d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawCircle(float x, float y, float radius, const SkPaint* paint);
190d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawOval(float left, float top, float right, float bottom,
191d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
192486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
193d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
194d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPath(const SkPath* path, const SkPaint* paint);
195d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawLines(const float* points, int count, const SkPaint* paint);
196d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPoints(const float* points, int count, const SkPaint* paint);
197d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
198d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float hOffset, float vOffset, const SkPaint* paint);
199486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
200d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* positions, const SkPaint* paint);
201c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
202d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
203527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik            DrawOpMode drawOpMode = kDrawOpMode_Immediate);
204d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawRects(const float* rects, int count, const SkPaint* paint);
20585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
206f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik    status_t drawShadow(const mat4& casterTransform, float casterAlpha,
20715a07a21eb33e8ca1c7444944fe0541a53380c0cChris Craik            const SkPath* casterOutline);
208f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik
2094aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShader();
2104aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShader(SkiaShader* shader);
211d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy
2124aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetColorFilter();
2134aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupColorFilter(SkiaColorFilter* filter);
214db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
2154aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void resetShadow();
2164aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    virtual void setupShadow(float radius, float dx, float dy, int color);
2171e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
2185ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
2195ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
2205ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
22116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer)
22216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; }
22316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
224d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    const SkPaint* filterPaint(const SkPaint* paint);
2255ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
2265e49b307eb99269db2db257760508b8efd7bb97dChris Craik    /**
2275e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Store the current display state (most importantly, the current clip and transform), and
2285e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * additionally map the state's bounds from local to window coordinates.
2295e49b307eb99269db2db257760508b8efd7bb97dChris Craik     *
2305e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Returns true if quick-rejected
2315e49b307eb99269db2db257760508b8efd7bb97dChris Craik     */
232ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
233527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
23428ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    void setupMergedMultiDraw(const Rect* clipRect);
235c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
236d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    const DrawModifiers& getDrawModifiers() { return mDrawModifiers; }
237d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; }
238d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
239672433d90fab7383cd28beac9d4485b566a90940Romain Guy    ANDROID_API bool isCurrentTransformSimple() {
240d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        return currentTransform()->isSimple();
241672433d90fab7383cd28beac9d4485b566a90940Romain Guy    }
242672433d90fab7383cd28beac9d4485b566a90940Romain Guy
2430f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    Caches& getCaches() {
2440f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        return mCaches;
2450f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2460f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
247ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    // simple rect clip
248ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool isCurrentClipSimple() {
249ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return mSnapshot->clipRegion->isEmpty();
250ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
251ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
252d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    int getViewportWidth() { return currentSnapshot()->viewport.getWidth(); }
253d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    int getViewportHeight() { return currentSnapshot()->viewport.getHeight(); }
2540e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik
25517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
256a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik     * Scales the alpha on the current snapshot. This alpha value will be modulated
25717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
25817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
259a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    void scaleAlpha(float alpha) {
260a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik        mSnapshot->alpha *= alpha;
26117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    }
26217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
26317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
2640f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     * Inserts a named event marker in the stream of GL commands.
2650f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     */
2660f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    void eventMark(const char* name) const;
2670f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
2680f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    /**
26917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
27017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
27117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
27217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
27313631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
27417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
27517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
27617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
27717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
27813631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
27913631f3da855f200a151e7837ed9f6b079622b58Romain Guy
280d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    /**
281d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * Gets the alpha and xfermode out of a paint object. If the paint is null
282d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
28316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not multiply the paint's alpha by the current snapshot's alpha, and does
28416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not replace the alpha with the overrideLayerAlpha
285d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     *
286d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param paint The paint to extract values from
287d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param alpha Where to store the resulting alpha
288d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param mode Where to store the resulting xfermode
289d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     */
290d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
291527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *mode = getXfermodeDirect(paint);
292527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *alpha = getAlphaDirect(paint);
293527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
294527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
295d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) {
296527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return SkXfermode::kSrcOver_Mode;
297527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return getXfermode(paint->getXfermode());
298527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
299527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
300c1c5f0870282b56dafe5a4d756e4b9e6884655a7Chris Craik    static inline int getAlphaDirect(const SkPaint* paint) {
301527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return 255;
302527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return paint->getAlpha();
303d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    }
304d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
305624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    /**
306624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * Return the best transform to use to rasterize text given a full
307624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     * transform matrix.
308624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     */
309624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    mat4 findBestFontTransform(const mat4& transform) const;
310624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy
311527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR
312527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
313527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.setScissorEnabled(false);
314527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
315527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        // should only be called outside of other draw ops, so stencil can only be in test state
316527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
317527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.stencil.disable();
318527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
319527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
320527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
321527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (stencilWasEnabled) mCaches.stencil.enableTest();
322527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
323527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif
324527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
325e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
326e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
32735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Computes the projection matrix, initialize the first snapshot
32835643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * and stores the dimensions of the render target.
32935643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
33035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void initViewport(int width, int height);
33135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
33235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
33396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Perform the setup specific to a frame. This method does not
33496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * issue any OpenGL commands.
33596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
33696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void setupFrameState(float left, float top, float right, float bottom, bool opaque);
33796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
33896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
33996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Indicates the start of rendering. This method will setup the
34096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * initial OpenGL state (viewport, clearing the buffer, etc.)
34196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
34296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    status_t startFrame();
34396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
34496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
3457c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     * Clears the underlying surface if needed.
3467c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     */
3477c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
3487c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy
3497c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    /**
35035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Call this method after updating a layer during a drawing pass.
35135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
35235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void resumeAfterLayer();
35335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
35435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
3558ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * This method is called whenever a stencil buffer is required. Subclasses
3568ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * should override this method and call attachStencilBufferToLayer() on the
3578ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * appropriate layer(s).
3588ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3598ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    virtual void ensureStencilBuffer();
3608ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
3618ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
3628ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Obtains a stencil render buffer (allocating it if necessary) and
3638ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * attaches it to the specified layer.
3648ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3658ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void attachStencilBufferToLayer(Layer* layer);
3668ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
367f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    bool quickRejectSetupScissor(float left, float top, float right, float bottom,
368d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint = NULL);
369d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) {
370f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        return quickRejectSetupScissor(bounds.left, bounds.top,
371f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik                bounds.right, bounds.bottom, paint);
372f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    }
373f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik
3748ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
375e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
376e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
377e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
378e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
379e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
380e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
381e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
382e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
38314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    virtual void composeLayer(const Snapshot& current, const Snapshot& previous);
384694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
385ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
386f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
387ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
388f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
389ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
39042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
39142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
39242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
393624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual Region* getRegion() const {
394f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
395f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
396f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
39742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
39842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
39942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
400624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool hasLayer() const {
401f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
402f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
4031bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
40442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
40542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
40642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
40714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    virtual GLuint getTargetFbo() const {
40842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
40942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
41042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
41177a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
41277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
41377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
41477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
41577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
41677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
41777a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
41877a811610f99e21da7f88dafef60d09f345d0506Romain Guy
419be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
420be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
42116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both
42216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * snapshot alpha, and overrideLayerAlpha
423be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
424be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
425be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
426be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
427be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
428d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const;
42916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
43016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    /**
43116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha
43216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     *
43316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * @param layer The layer from which the alpha is extracted
43416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     */
43516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    inline float getLayerAlpha(Layer* layer) const;
436be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
437be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
438be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Safely retrieves the mode from the specified xfermode. If the specified
439be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * xfermode is null, the mode is assumed to be SkXfermode::kSrcOver_Mode.
440be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
441be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    static inline SkXfermode::Mode getXfermode(SkXfermode* mode) {
442be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        SkXfermode::Mode resultMode;
443be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        if (!SkXfermode::AsMode(mode, &resultMode)) {
444be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy            resultMode = SkXfermode::kSrcOver_Mode;
445be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        }
446be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy        return resultMode;
447be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
448be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
44911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    /**
45011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     * Set to true to suppress error checks at the end of a frame.
45111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     */
452624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool suppressErrorChecks() const {
45311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy        return false;
45411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    }
45511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
45608ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
4575cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
458dcfc836b457a87881da409e1acf251515f121446Romain Guy     * Discards the content of the framebuffer if supported by the driver.
459dcfc836b457a87881da409e1acf251515f121446Romain Guy     * This method should be called at the beginning of a frame to optimize
460dcfc836b457a87881da409e1acf251515f121446Romain Guy     * rendering on some tiler architectures.
461dcfc836b457a87881da409e1acf251515f121446Romain Guy     */
462dcfc836b457a87881da409e1acf251515f121446Romain Guy    void discardFramebuffer(float left, float top, float right, float bottom);
463dcfc836b457a87881da409e1acf251515f121446Romain Guy
464dcfc836b457a87881da409e1acf251515f121446Romain Guy    /**
465ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
466ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
467ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
468ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
469ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
470ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
4712b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
472d6b65f67717025b1162f86f04e2caa5723566cacChris Craik     * This method will use the current layer space clip rect.
4732b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * This method needs to be invoked every time getTargetFbo() is
4742b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * bound again.
4752b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
476d6b65f67717025b1162f86f04e2caa5723566cacChris Craik    void startTilingCurrentClip(bool opaque = false);
4772b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
4782b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
479c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
480c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method needs to be invoked every time getTargetFbo() is
481c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * bound again.
482c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     */
483c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    void startTiling(const Rect& clip, int windowHeight, bool opaque = false);
484c3fedafc5f50100219449125a000e3138f6fb987Romain Guy
485c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    /**
4862b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU that we are done drawing the frame or that we
4872b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * are switching to another render target.
4882b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
4892b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    void endTiling();
4902b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
49114e513058ed4168c94e015638d16f5f87fd8063aChris Craik    void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored);
492bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
4935cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
4945cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
4955cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
4965cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
497bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
498bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
4995cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Sets the clipping region using the stencil buffer. The clip region
5018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is defined by the current snapshot's clipRegion member.
5028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
5038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void setStencilFromClip();
5048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
5058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
506408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds of the layer, calculates ...
507d90144db52c7297879b950cbbc85137ed123ab5bChris Craik     */
508d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
509d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
510d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    /**
511408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
512408eb12631376cbdc96803e918decf6ea804d346Chris Craik     */
513408eb12631376cbdc96803e918decf6ea804d346Chris Craik    void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
514408eb12631376cbdc96803e918decf6ea804d346Chris Craik            bool fboLayer, int alpha);
515408eb12631376cbdc96803e918decf6ea804d346Chris Craik
516408eb12631376cbdc96803e918decf6ea804d346Chris Craik    /**
517d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
518d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
519d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
520d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
521d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
522d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
523d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
524d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
525d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
526d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
527d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
528d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
529d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
530d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createLayer(float left, float top, float right, float bottom,
531d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger            const SkPaint* paint, int flags);
532d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
533d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
5345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
5355b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5365b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
5375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
5385b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
5395b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
540e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip);
5415b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5425b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5435b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
5445b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5455b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5465b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5485b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
5495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5505b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5515b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
5525b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5535b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5545b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5555b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
5565b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5575b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
5585b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
55954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
56054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
56154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
56254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
56354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
56454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
56554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
566f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
567f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
568f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
569f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
570f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
571f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
572f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
573f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
574f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
575f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
576f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
577f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
578f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
5795cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
580735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * are transformed by the current snapshot's transform matrix unless specified
581735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * otherwise.
5825cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
5835cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
5845cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
5855cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
5865cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
5875cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param color The rectangle's ARGB color, defined as a packed 32 bits word
588026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param mode The Skia xfermode to use
5893d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
5905cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
591026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
5921c740bce8a762f02b5283045a0e2de7c8fb41277Romain Guy            int color, SkXfermode::Mode mode, bool ignoreTransform = false);
5935cbbce535744b89df5ecea95de21ee3733298260Romain Guy
59454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
595735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * Draws a series of colored rectangles with the specified color. The specified
596735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * coordinates are transformed by the current snapshot's transform matrix unless
597735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * specified otherwise.
598735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *
599735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
600735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *              per rectangle
601735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param color The rectangles' ARGB color, defined as a packed 32 bits word
602735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param mode The Skia xfermode to use
603735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param ignoreTransform True if the current transform should be ignored
6048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * @param dirty True if calling this method should dirty the current layer
6053bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy     * @param clip True if the rects should be clipped, false otherwise
606735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     */
607735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    status_t drawColorRects(const float* rects, int count, int color,
6083bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            SkXfermode::Mode mode, bool ignoreTransform = false,
6093bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy            bool dirty = true, bool clip = true);
610735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
611735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    /**
61254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
61354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
61454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
61554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
61654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
61754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
61854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
61954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
62054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
62154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
622d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
62354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
62454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
62554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
62654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
62754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
62854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
62954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
63054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
63154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
63254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
633d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint);
634a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
63554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
63665cd612face362d054a85d0f7e5881c59cd523beChris Craik     * Renders a strip of polygons with the specified paint, used for tessellated geometry.
63765cd612face362d054a85d0f7e5881c59cd523beChris Craik     *
63865cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param vertexBuffer The VertexBuffer to be drawn
63965cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param paint The paint to render with
64065cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param useOffset Offset the vertexBuffer (used in drawing non-AA lines)
64165cd612face362d054a85d0f7e5881c59cd523beChris Craik     */
642d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawVertexBuffer(const VertexBuffer& vertexBuffer, const SkPaint* paint,
64365cd612face362d054a85d0f7e5881c59cd523beChris Craik            bool useOffset = false);
64465cd612face362d054a85d0f7e5881c59cd523beChris Craik
64565cd612face362d054a85d0f7e5881c59cd523beChris Craik    /**
646710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * Renders the convex hull defined by the specified path as a strip of polygons.
64754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
648710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * @param path The hull of the path to draw
649cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * @param paint The paint to render with
65054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
651d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawConvexPath(const SkPath& path, const SkPaint* paint);
652858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
6535cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6545cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
6555cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
6565cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6575cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
6585cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
6595cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
6605cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
6615cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param texture The texture name to map onto the rectangle
6625cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
663d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode
664c1396e93b6a5286a5183c00c781b62e940a12c1fRomain Guy     * @param blend True if the texture contains an alpha channel
6655cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
666bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy    void drawTextureRect(float left, float top, float right, float bottom, GLuint texture,
667a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend);
668c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
669026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    /**
67082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
67182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * are transformed by the current snapshot's transform matrix.
67282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
67382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
67482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
67582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
67682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
67782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
67882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
67982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
680a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
681d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            Texture* texture, const SkPaint* paint);
68282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
68382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
68403750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
68503750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
68603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
68782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
68882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
68982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
69082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
69182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
69282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
69382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param alpha An additional translucency parameter, between 0.0f and 1.0f
69482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param mode The blending mode
69582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
69682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
69782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
69882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
699f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
700f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
70103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
7024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param modelViewMode Defines whether the model view matrix should be scaled
7035b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
704f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
705f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
706a979474f15b454c8e2963f239a3770e200bb227cRomain Guy            float alpha, SkXfermode::Mode mode, bool blend,
7076820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7085b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
7094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
710f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
7113b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture,
7123b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            float alpha, SkXfermode::Mode mode, bool blend,
7133b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7143b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
7154063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
7163b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
717886b275e529e44a59c54b933453d9bc902973178Romain Guy    void drawAlpha8TextureMesh(float left, float top, float right, float bottom,
718886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLuint texture, bool hasColor, int color, int alpha, SkXfermode::Mode mode,
719886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7204063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale,
7214063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            bool dirty = true);
722886b275e529e44a59c54b933453d9bc902973178Romain Guy
723f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
724448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * Draws the specified list of vertices as quads using indexed GL_TRIANGLES.
725448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * If the number of vertices to draw exceeds the number of indices we have
726448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * pre-allocated, this method will generate several glDrawElements() calls.
727448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     */
7284063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount);
729448455fe783b0a711340322dca272b8cc0ebe473Romain Guy
730448455fe783b0a711340322dca272b8cc0ebe473Romain Guy    /**
7310a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
7320a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
7330a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
7340a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
73541541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik     * @param totalAdvance The total advance in pixels, defines underline/strikethrough length
7360a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
7370a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
7380a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
7390a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
740d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint);
7411e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
742416a847633680d94efb926837efdc18726d54918Raph Levien   /**
743416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
744416a847633680d94efb926837efdc18726d54918Raph Levien     *
745416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
746416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
747416a847633680d94efb926837efdc18726d54918Raph Levien     * @param bytesCount The number of bytes in the text
748416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
749416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
750416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
751416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
752416a847633680d94efb926837efdc18726d54918Raph Levien     * @param mode The xfermode for drawing the shadow
753416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
754416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
755416a847633680d94efb926837efdc18726d54918Raph Levien     */
756d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count,
757416a847633680d94efb926837efdc18726d54918Raph Levien            const float* positions, FontRenderer& fontRenderer, int alpha, SkXfermode::Mode mode,
758416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
759416a847633680d94efb926837efdc18726d54918Raph Levien
76054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
76154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
76254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
76354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
76454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
76554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
76654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
76754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
76854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
769d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik     void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint);
77001d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
7711e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
772ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
773026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
774026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
7758ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
776026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
777026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
778026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
779026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
780026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
781026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
782026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
783026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
7848ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
785768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     * Returns true if the specified paint will draw invisible text.
786768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     */
787768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    bool canSkipText(const SkPaint* paint) const;
788768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy
789768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    /**
790746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
791746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
792a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
793746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
7948aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(texture);
795746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
796746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
797746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
798aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
799aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
800aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
801aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
8028aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
803aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
804aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
805aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
80682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
80782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
80882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
809f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
810f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
811a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
812f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
813d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
814d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
815d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
816d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
8176926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
818d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
819d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
820d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
821260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
822889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
823260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
824746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
825746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
826746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
82754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
82817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
82970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
83070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
83170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
83270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
833ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawWithTextureAndColor(bool isAlpha8 = false);
834aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
83515bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
836710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik    void setupDrawAA();
8378d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
83870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
83986568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
8404121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
84170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShader();
84270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilter();
84370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
84470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
84570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawBlending(bool blend = true, SkXfermode::Mode mode = SkXfermode::kSrcOver_Mode,
84670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy            bool swapSrcDst = false);
84770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
84870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
8494063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
8504063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
8514063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Setup the current program matrices based upon the nature of the geometry.
8524063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8534063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top
8544063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1)
8554063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * space must be scaled up and translated to fill the quad provided in (l,t,r,b). These
8564063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * transformations are stored in the modelView matrix and uploaded to the shader.
8574063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8584063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate
859564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik     * geometry pixel positioning. See Vertex::GeometryFudgeFactor().
8604063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8614063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space,
8624063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil,
8634063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * or when simple translation has been extracted)
8644063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
8654063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    void setupDrawModelView(ModelViewMode mode, bool offset,
8664063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            float left, float top, float right, float bottom, bool ignoreTransform = false);
86770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorUniforms();
86886568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
86970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawShaderUniforms(bool ignoreTransform = false);
87070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColorFilterUniforms();
87170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
87270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
873aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
8748f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
8758f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
8764121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
877564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0);
878564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors);
879564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0);
880448455fe783b0a711340322dca272b8cc0ebe473Romain Guy    void setupDrawIndexedVertices(GLvoid* vertices);
881f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
882746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
88311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    bool updateLayer(Layer* layer, bool inFrame);
88411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    void updateLayers();
88596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void flushLayers();
88611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
887e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS
88817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
88917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
89017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
89117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
892e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    void drawRegionRectsDebug(const Region& region);
893e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif
8943a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
8958ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
8968ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Renders the specified region as a series of rectangles. The region
8978ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * must be in screen-space coordinates.
8988ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
8998ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void drawRegionRects(const SkRegion& region, int color, SkXfermode::Mode mode,
9008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy            bool dirty = false);
9018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
9038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
9048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is turned on.
9058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
9068ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void debugClip();
9078ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9087c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void debugOverdraw(bool enable, bool clear);
9097c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void renderOverdraw();
91078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    void countOverdraw();
9117c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
912746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
913746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
914746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
915746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
916746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
917746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
918746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
9193b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    inline const UvMapper& getMapper(const Texture* texture) {
9203b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
9213b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    }
9223b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
9233b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    /**
9243b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * Returns a texture object for the specified bitmap. The texture can
9253b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * come from the texture cache or an atlas. If this method returns
9263b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * NULL, the texture could not be found and/or allocated.
9273b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     */
928d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    Texture* getTexture(const SkBitmap* bitmap);
9293b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
930f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik    // Matrix used for view/projection in shaders
931f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik    mat4 mViewProjMatrix;
932bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
9334063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
9344063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Model-view matrix used to position/size objects
9354063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
9364063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Stores operation-local modifications to the draw matrix that aren't incorporated into the
9374063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * currentTransform().
9384063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
9394063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * If generated with kModelViewMode_Translate, the mModelView will reflect an x/y offset,
9404063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale,
9414063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * mModelView will reflect a translation and scale, e.g. the translation and scale required to
9424063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height of a
9434063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * bitmap.
9444063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
9454063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used as input to SkiaShader transformation.
9464063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
947c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy    mat4 mModelView;
948c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
9492b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // State used to define the clipping region
9505f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    Rect mTilingClip;
95196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is the target render surface opaque
95296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mOpaque;
95396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is a frame currently being rendered
95496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mFrameStarted;
9559d5316e3f56d138504565ff311145ac01621dff4Romain Guy
956026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
957ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
958ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
9593b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    // Default UV mapper
9603b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    const UvMapper mUvMapper;
9613b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
962c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // shader, filters, and shadow
963c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
9645ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
9655ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
96682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
967fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
9683bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    Extensions& mExtensions;
9698694230ff25fa0a60e480d424843e56b718f0516Romain Guy
9708f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
97154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
9728f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of functors to invoke after a frame is drawn
973ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy    SortedVector<Functor*> mFunctors;
97411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    // List of layers to update at the beginning of a frame
97511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    Vector<Layer*> mLayerUpdates;
97654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
97770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
97870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
97970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
98070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
98170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
98270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
98370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
98470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
98570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
98670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
98770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
98870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
9892b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // Indicate whether we are drawing an opaque frame
9902b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    bool mOpaqueFrame;
99170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
99287e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
99387e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // Properties.h
99487e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    bool mScissorOptimizationDisabled;
99587e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
99654c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    // No-ops start/endTiling when set
99754c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    bool mSuppressTiling;
99854c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
99978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    // If true, this renderer will setup drawing to emulate
100078dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    // an increment stencil buffer in the color buffer
100178dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    bool mCountOverdraw;
100278dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    float mOverdraw;
100378dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy
1004b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy    friend class DisplayListRenderer;
100596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    friend class Layer;
1006257ae3502cfad43df681b1783528d645bdabc63fRomain Guy    friend class TextSetupFunctor;
100703c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy    friend class DrawBitmapOp;
100803c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy    friend class DrawPatchOp;
1009b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
1010bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
1011e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10129d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
1013e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
1014e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10155b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
1016