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>
2476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkCanvas.h>
2576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkColorFilter.h>
26f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h>
27ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h>
28079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h>
2985bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
30e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
31c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger#include <utils/Blur.h>
32daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h>
33bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
34ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h>
358694230ff25fa0a60e480d424843e56b718f0516Romain Guy#include <utils/Vector.h>
36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
377953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
387953745dd565167113f8cbfc461bc0521d32d870Romain Guy
393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h>
403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
41c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
4251769a68a5cb34e9564740c6a854fcb93018789dRomain Guy#include "Extensions.h"
43f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include "Matrix.h"
445cbbce535744b89df5ecea95de21ee3733298260Romain Guy#include "Program.h"
45bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include "Rect.h"
46b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Renderer.h"
47b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Snapshot.h"
48d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III#include "StatefulBaseRenderer.h"
493b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include "UvMapper.h"
50b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik#include "Vertex.h"
51fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy#include "Caches.h"
5252244fff29042926e21fa897ef5ab11148e35299John Reck#include "CanvasProperty.h"
53bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
54d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins IIIclass SkShader;
55d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III
56e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
579d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
58e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
59b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState;
603b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState;
61e18264b079481a244b30e3f71012c53bbd861f92John Reckclass RenderNode;
62b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass TextSetupFunctor;
63b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer;
64b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik
65c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikstruct DrawModifiers {
669b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    DrawModifiers() {
679b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy        reset();
689b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    }
699b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy
709b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    void reset() {
719b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy        memset(this, 0, sizeof(DrawModifiers));
729b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy    }
739b5a1a28c327e6113d68302b1f0eed1d1c6f6183Romain Guy
7416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    float mOverrideLayerAlpha;
75c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
76c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // Draw filters
77c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    bool mHasDrawFilter;
78c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterClearBits;
79c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    int mPaintFilterSetBits;
80c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik};
81c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
82ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags {
83ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Draw = 0x1,
84ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Clip = 0x2
85ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik};
86ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
8728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags {
88a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik    kClipSide_None = 0x0,
8928ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Left = 0x1,
9028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Top = 0x2,
9128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Right = 0x4,
9228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Bottom = 0x8,
93d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_Full = 0xF,
94d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_ConservativeFull = 0x1F
9528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik};
9628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik
97bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craikenum VertexBufferDisplayFlags {
98bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik    kVertexBuffer_Offset = 0x1,
9991a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik    kVertexBuffer_ShadowInterp = 0x2,
100bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik};
101bf75945e7a1ae7c1000682716643c942c1e19ba6Chris 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:
1283b20251a355c88193c439f928a84ae69483fb488John Reck    OpenGLRenderer(RenderState& renderState);
129e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
130e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
1313b20251a355c88193c439f928a84ae69483fb488John Reck    void initProperties();
132058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    void initLight(const Vector3& lightCenter, float lightRadius,
133058fc640017c90120c599d378a4cbc55668b05b7Chris Craik            uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
13487e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
135797b95b26bbb7557678af78b9a2a61830158920fChris Craik    virtual void onViewportInitialized();
1367c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t prepareDirty(float left, float top, float right, float bottom, bool opaque);
13717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    virtual void finish();
138c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
1398f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    virtual status_t callDrawGLFunction(Functor* functor, Rect& dirty);
14008ae317c21ec3086b5017672bba87420cc38a407Romain Guy
1413b20251a355c88193c439f928a84ae69483fb488John Reck    void pushLayerUpdate(Layer* layer);
1423b20251a355c88193c439f928a84ae69483fb488John Reck    void cancelLayerUpdate(Layer* layer);
1433b20251a355c88193c439f928a84ae69483fb488John Reck    void flushLayerUpdates();
144443a714fa7c0dd07fee3527cc5bc3d3ca1fb7d44John Reck    void markLayersAsBuildLayers();
14511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
1463b20251a355c88193c439f928a84ae69483fb488John Reck    virtual int saveLayer(float left, float top, float right, float bottom,
1473f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik            const SkPaint* paint, int flags) {
1483f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik        return saveLayer(left, top, right, bottom, paint, flags, NULL);
1493f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    }
1503f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik
1513f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if
1523f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    // created, which will in turn clip to that mask when drawn back/restored.
1533f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    int saveLayer(float left, float top, float right, float bottom,
1543f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik            const SkPaint* paint, int flags, const SkPath* convexMask);
155bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
156d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    int saveLayerDeferred(float left, float top, float right, float bottom,
157d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger            const SkPaint* paint, int flags);
158d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
159a7090e0cfd7c719a6d4c03aae34f5db98754cbddChris Craik    virtual status_t drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
160a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    virtual status_t drawLayer(Layer* layer, float x, float y);
161796475006f5d670e8383a2050f11719522437a43Chris Craik    virtual status_t drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
162d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
163d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
164d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmap(const SkBitmap* bitmap, float srcLeft, float srcTop,
165e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy            float srcRight, float srcBottom, float dstLeft, float dstTop,
166d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float dstRight, float dstBottom, const SkPaint* paint);
167796475006f5d670e8383a2050f11719522437a43Chris Craik    virtual status_t drawBitmapData(const SkBitmap* bitmap, const SkPaint* paint);
168d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
169d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* vertices, const int* colors, const SkPaint* paint);
170d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
171d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
172d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
173d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float left, float top, float right, float bottom, const SkPaint* paint);
174d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
175d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float left, float top, float right, float bottom, const SkPaint* paint);
176486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawColor(int color, SkXfermode::Mode mode);
177d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawRect(float left, float top, float right, float bottom,
178d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
179486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawRoundRect(float left, float top, float right, float bottom,
180d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float rx, float ry, const SkPaint* paint);
181d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawCircle(float x, float y, float radius, const SkPaint* paint);
182d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawOval(float left, float top, float right, float bottom,
183d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint);
184486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawArc(float left, float top, float right, float bottom,
185d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
186d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPath(const SkPath* path, const SkPaint* paint);
187d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawLines(const float* points, int count, const SkPaint* paint);
188d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawPoints(const float* points, int count, const SkPaint* paint);
189d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawTextOnPath(const char* text, int bytesCount, int count, const SkPath* path,
190d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float hOffset, float vOffset, const SkPaint* paint);
191486590963e2207d68eebd6944fec70d50d41116aChet Haase    virtual status_t drawPosText(const char* text, int bytesCount, int count,
192d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* positions, const SkPaint* paint);
193c25259519f1b74bb62a2b051b74537f073436b5cRomain Guy    virtual status_t drawText(const char* text, int bytesCount, int count, float x, float y,
194d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
195527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik            DrawOpMode drawOpMode = kDrawOpMode_Immediate);
196d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    virtual status_t drawRects(const float* rects, int count, const SkPaint* paint);
19785bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
19805f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    status_t drawShadow(float casterAlpha,
19905f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik            const VertexBuffer* ambientShadowVertexBuffer, const VertexBuffer* spotShadowVertexBuffer);
200f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik
2015ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void resetPaintFilter();
2025ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    virtual void setupPaintFilter(int clearBits, int setBits);
2035ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
20416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    // If this value is set to < 1.0, it overrides alpha set on layer (see drawBitmap, drawLayer)
20516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    void setOverrideLayerAlpha(float alpha) { mDrawModifiers.mOverrideLayerAlpha = alpha; }
20616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
207d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    const SkPaint* filterPaint(const SkPaint* paint);
2085ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
2095e49b307eb99269db2db257760508b8efd7bb97dChris Craik    /**
2105e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Store the current display state (most importantly, the current clip and transform), and
2115e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * additionally map the state's bounds from local to window coordinates.
2125e49b307eb99269db2db257760508b8efd7bb97dChris Craik     *
2135e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Returns true if quick-rejected
2145e49b307eb99269db2db257760508b8efd7bb97dChris Craik     */
215ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
216527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
21728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    void setupMergedMultiDraw(const Rect* clipRect);
218c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
219d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    const DrawModifiers& getDrawModifiers() { return mDrawModifiers; }
220d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void setDrawModifiers(const DrawModifiers& drawModifiers) { mDrawModifiers = drawModifiers; }
221d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
2223b20251a355c88193c439f928a84ae69483fb488John Reck    bool isCurrentTransformSimple() {
223d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        return currentTransform()->isSimple();
224672433d90fab7383cd28beac9d4485b566a90940Romain Guy    }
225672433d90fab7383cd28beac9d4485b566a90940Romain Guy
2260f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    Caches& getCaches() {
2270f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        return mCaches;
2280f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2290f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
230ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    // simple rect clip
231ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool isCurrentClipSimple() {
232ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik        return mSnapshot->clipRegion->isEmpty();
233ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    }
234ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
235a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportWidth() { return currentSnapshot()->getViewportWidth(); }
236a64a2bef1048db5a742843f1e3bea9e80d0defc5Chris Craik    int getViewportHeight() { return currentSnapshot()->getViewportHeight(); }
2370e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik
23817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
239a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik     * Scales the alpha on the current snapshot. This alpha value will be modulated
24017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
24117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
242a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik    void scaleAlpha(float alpha) {
243a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik        mSnapshot->alpha *= alpha;
24417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    }
24517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
24617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
2470f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     * Inserts a named event marker in the stream of GL commands.
2480f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     */
2490f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    void eventMark(const char* name) const;
2500f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
2510f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    /**
25262d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik     * Inserts a formatted event marker in the stream of GL commands.
25362d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik     */
25462d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik    void eventMarkDEBUG(const char *fmt, ...) const;
25562d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik
25662d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik    /**
25717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
25817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
25917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
26017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
26113631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
26217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
26317112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
26417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
26517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
26613631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
26713631f3da855f200a151e7837ed9f6b079622b58Romain Guy
268d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    /**
269d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * Gets the alpha and xfermode out of a paint object. If the paint is null
270d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * alpha will be 255 and the xfermode will be SRC_OVER. This method does
27116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not multiply the paint's alpha by the current snapshot's alpha, and does
27216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * not replace the alpha with the overrideLayerAlpha
273d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     *
274d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param paint The paint to extract values from
275d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param alpha Where to store the resulting alpha
276d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     * @param mode Where to store the resulting xfermode
277d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase     */
278d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    static inline void getAlphaAndModeDirect(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) {
279527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *mode = getXfermodeDirect(paint);
280527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        *alpha = getAlphaDirect(paint);
281527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
282527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
283d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    static inline SkXfermode::Mode getXfermodeDirect(const SkPaint* paint) {
284527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return SkXfermode::kSrcOver_Mode;
285527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return getXfermode(paint->getXfermode());
286527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
287527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
288c1c5f0870282b56dafe5a4d756e4b9e6884655a7Chris Craik    static inline int getAlphaDirect(const SkPaint* paint) {
289527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (!paint) return 255;
290527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        return paint->getAlpha();
291d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    }
292d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase
293c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    struct TextShadow {
294c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        SkScalar radius;
295c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        float dx;
296c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        float dy;
297c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        SkColor color;
298c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    };
299c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger
300c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    static inline bool getTextShadow(const SkPaint* paint, TextShadow* textShadow) {
301c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        SkDrawLooper::BlurShadowRec blur;
302c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        if (paint && paint->getLooper() && paint->getLooper()->asABlurShadow(&blur)) {
303c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger            if (textShadow) {
304c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger                textShadow->radius = Blur::convertSigmaToRadius(blur.fSigma);
305c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger                textShadow->dx = blur.fOffset.fX;
306c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger                textShadow->dy = blur.fOffset.fY;
307c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger                textShadow->color = blur.fColor;
308c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger            }
309c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger            return true;
310c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        }
311c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        return false;
312c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    }
313c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger
314c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    static inline bool hasTextShadow(const SkPaint* paint) {
315c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger        return getTextShadow(paint, NULL);
316c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger    }
317c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger
318624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    /**
31959744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * Build the best transform to use to rasterize text given a full
32059744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * transform matrix, and whether filteration is needed.
32159744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     *
32259744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * Returns whether filtration is needed
323624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     */
32459744b79ec302000802cd56d30a1bf70f0183c80Chris Craik    bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const;
325624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy
326527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR
327527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
328527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.setScissorEnabled(false);
329527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
330527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        // should only be called outside of other draw ops, so stencil can only be in test state
331527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
332527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.stencil.disable();
333527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
334527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
335527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
336527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (stencilWasEnabled) mCaches.stencil.enableTest();
337527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
338527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif
339527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
34069e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    const Vector3& getLightCenter() const { return currentSnapshot()->getRelativeLightCenter(); }
34105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    float getLightRadius() const { return mLightRadius; }
34269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; }
34369e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; }
34405f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik
3454ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    SkPath* allocPathForFrame() {
3464ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik        SkPath* path = new SkPath();
3474ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik        mTempPaths.push_back(path);
3484ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik        return path;
3494ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    }
3504ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik
351e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
352e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
35396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Perform the setup specific to a frame. This method does not
35496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * issue any OpenGL commands.
35596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
35696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void setupFrameState(float left, float top, float right, float bottom, bool opaque);
35796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
35896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
35996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Indicates the start of rendering. This method will setup the
36096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * initial OpenGL state (viewport, clearing the buffer, etc.)
36196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
36296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    status_t startFrame();
36396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
36496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
3657c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     * Clears the underlying surface if needed.
3667c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     */
3677c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    virtual status_t clear(float left, float top, float right, float bottom, bool opaque);
3687c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy
3697c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    /**
37035643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Call this method after updating a layer during a drawing pass.
37135643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
37235643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void resumeAfterLayer();
37335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
37435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
3758ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * This method is called whenever a stencil buffer is required. Subclasses
3768ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * should override this method and call attachStencilBufferToLayer() on the
3778ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * appropriate layer(s).
3788ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3798ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    virtual void ensureStencilBuffer();
3808ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
3818ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
3828ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Obtains a stencil render buffer (allocating it if necessary) and
3838ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * attaches it to the specified layer.
3848ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3858ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void attachStencilBufferToLayer(Layer* layer);
3868ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
387f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    bool quickRejectSetupScissor(float left, float top, float right, float bottom,
388d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const SkPaint* paint = NULL);
389d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = NULL) {
390f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        return quickRejectSetupScissor(bounds.left, bounds.top,
391f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik                bounds.right, bounds.bottom, paint);
392f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    }
393f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik
3948ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
395e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
396e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
397e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
398e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
399e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
400e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
401e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
402e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
40314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    virtual void composeLayer(const Snapshot& current, const Snapshot& previous);
404694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
405ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
406f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
407ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
408f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
409ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
41042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
41142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
41242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
413624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual Region* getRegion() const {
414f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return mSnapshot->region;
415f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
416f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
41742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
41842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
41942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
420624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool hasLayer() const {
421f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy        return (mSnapshot->flags & Snapshot::kFlagFboTarget) && mSnapshot->region;
422f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
4231bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
42442f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
42542f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the name of the FBO this renderer is rendering into.
42642f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
42714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    virtual GLuint getTargetFbo() const {
42842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy        return 0;
42942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    }
43042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy
43177a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
43277a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
43377a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
43477a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
43577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
43677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
43777a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
43877a811610f99e21da7f88dafef60d09f345d0506Romain Guy
439be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
440be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * Gets the alpha and xfermode out of a paint object. If the paint is null
44116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * alpha will be 255 and the xfermode will be SRC_OVER. Accounts for both
44216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * snapshot alpha, and overrideLayerAlpha
443be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     *
444be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param paint The paint to extract values from
445be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param alpha Where to store the resulting alpha
446be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     * @param mode Where to store the resulting xfermode
447be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
448d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode) const;
44916ecda5317c40fc3da284952d9b3add34d6763aeChris Craik
45016ecda5317c40fc3da284952d9b3add34d6763aeChris Craik    /**
45116ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * Gets the alpha from a layer, accounting for snapshot alpha and overrideLayerAlpha
45216ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     *
45316ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * @param layer The layer from which the alpha is extracted
45416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     */
45576d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    inline float getLayerAlpha(const Layer* layer) const;
456be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
457be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
45876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * Safely retrieves the ColorFilter from the given Paint. If the paint is
45976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * null then null is returned.
460be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy     */
46176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    static inline SkColorFilter* getColorFilter(const SkPaint* paint) {
46276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger        return paint ? paint->getColorFilter() : NULL;
463be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    }
464be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
46511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    /**
466d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     * Safely retrieves the Shader from the given Paint. If the paint is
467d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     * null then null is returned.
468d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     */
469d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    static inline const SkShader* getShader(const SkPaint* paint) {
470d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III        return paint ? paint->getShader() : NULL;
471d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    }
472d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III
473d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    /**
47411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     * Set to true to suppress error checks at the end of a frame.
47511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     */
476624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool suppressErrorChecks() const {
47711cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy        return false;
47811cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    }
47911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
4803b20251a355c88193c439f928a84ae69483fb488John Reck    inline RenderState& renderState() { return mRenderState; }
4813b20251a355c88193c439f928a84ae69483fb488John Reck
48208ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
4835cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
484dcfc836b457a87881da409e1acf251515f121446Romain Guy     * Discards the content of the framebuffer if supported by the driver.
485dcfc836b457a87881da409e1acf251515f121446Romain Guy     * This method should be called at the beginning of a frame to optimize
486dcfc836b457a87881da409e1acf251515f121446Romain Guy     * rendering on some tiler architectures.
487dcfc836b457a87881da409e1acf251515f121446Romain Guy     */
488dcfc836b457a87881da409e1acf251515f121446Romain Guy    void discardFramebuffer(float left, float top, float right, float bottom);
489dcfc836b457a87881da409e1acf251515f121446Romain Guy
490dcfc836b457a87881da409e1acf251515f121446Romain Guy    /**
491ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * Ensures the state of the renderer is the same as the state of
492ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     * the GL context.
493ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy     */
494ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    void syncState();
495ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy
496ddf74373616c89e0880a28a2185fd7ce3db91de6Romain Guy    /**
4972b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
498d6b65f67717025b1162f86f04e2caa5723566cacChris Craik     * This method will use the current layer space clip rect.
4992b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * This method needs to be invoked every time getTargetFbo() is
5002b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * bound again.
5012b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
50233f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen    void startTilingCurrentClip(bool opaque = false, bool expand = false);
5032b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
5042b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    /**
505c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * Tells the GPU what part of the screen is about to be redrawn.
506c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * This method needs to be invoked every time getTargetFbo() is
507c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     * bound again.
508c3fedafc5f50100219449125a000e3138f6fb987Romain Guy     */
50933f5a59ac3e304970920dda824958870f85f76efhenry.uh_chen    void startTiling(const Rect& clip, int windowHeight, bool opaque = false, bool expand = false);
510c3fedafc5f50100219449125a000e3138f6fb987Romain Guy
511c3fedafc5f50100219449125a000e3138f6fb987Romain Guy    /**
5122b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * Tells the GPU that we are done drawing the frame or that we
5132b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     * are switching to another render target.
5142b7028eabac80cec170572bc0e945a1d4224e595Romain Guy     */
5152b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    void endTiling();
5162b7028eabac80cec170572bc0e945a1d4224e595Romain Guy
51714e513058ed4168c94e015638d16f5f87fd8063aChris Craik    void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored);
518bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
5195cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5205cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
5215cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
5225cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
523bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
524bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
5255cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
5268ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Sets the clipping region using the stencil buffer. The clip region
5278ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is defined by the current snapshot's clipRegion member.
5288ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
5298ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void setStencilFromClip();
5308ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
5318ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
532408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds of the layer, calculates ...
533d90144db52c7297879b950cbbc85137ed123ab5bChris Craik     */
534d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
535d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
536d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    /**
537408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
538408eb12631376cbdc96803e918decf6ea804d346Chris Craik     */
539408eb12631376cbdc96803e918decf6ea804d346Chris Craik    void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
540408eb12631376cbdc96803e918decf6ea804d346Chris Craik            bool fboLayer, int alpha);
541408eb12631376cbdc96803e918decf6ea804d346Chris Craik
542408eb12631376cbdc96803e918decf6ea804d346Chris Craik    /**
543d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
544d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
545d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
546d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
547d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
548d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
549d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
550d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
551d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
552d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
5533f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     * @param mask A mask to use when drawing the layer back, may be empty
554d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
555d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
556d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
557d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createLayer(float left, float top, float right, float bottom,
5583f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik            const SkPaint* paint, int flags, const SkPath* convexMask);
559d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
560d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
5615b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
5625b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5635b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
5645b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
5655b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
5665b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
567e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip);
5685b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5695b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5705b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
5715b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5725b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5735b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5745b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5755b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
5765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5775b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5785b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a simple rectangle.
5795b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5805b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5815b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5825b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param swap If true, the source and destination are swapped
5835b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5845b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRect(Layer* layer, const Rect& rect, bool swap = false);
5855b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
58654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
58754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
58854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
58954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
59054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
59154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
59254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
593f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
594f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
595f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
596f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
597f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom, const mat4 transform);
598f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
599f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
600f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
601f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
602f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
603f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
604f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
605f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
6065cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
607735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * are transformed by the current snapshot's transform matrix unless specified
608735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * otherwise.
6095cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6105cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
6115cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
6125cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
6135cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
61476d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * @param paint The paint containing the color, blending mode, etc.
6153d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
6165cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
617026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
61876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const SkPaint* paint, bool ignoreTransform = false);
6195cbbce535744b89df5ecea95de21ee3733298260Romain Guy
62054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
621735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * Draws a series of colored rectangles with the specified color. The specified
622735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * coordinates are transformed by the current snapshot's transform matrix unless
623735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * specified otherwise.
624735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *
625735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
626735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *              per rectangle
62776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * @param paint The paint containing the color, blending mode, etc.
628735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param ignoreTransform True if the current transform should be ignored
6298ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * @param dirty True if calling this method should dirty the current layer
6303bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy     * @param clip True if the rects should be clipped, false otherwise
631735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     */
63276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    status_t drawColorRects(const float* rects, int count, const SkPaint* paint,
63376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            bool ignoreTransform = false, bool dirty = true, bool clip = true);
634735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
635735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    /**
63654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
63754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
63854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
63954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
64054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
64154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
64254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
64354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
64454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
64554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
646d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawShape(float left, float top, const PathTexture* texture, const SkPaint* paint);
64754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
64854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
64954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the specified texture as an alpha bitmap. Alpha bitmaps obey
65054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * different compositing rules.
65154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
65254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to draw with
65354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The x coordinate of the bitmap
65454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The y coordinate of the bitmap
65554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to render with
65654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
657d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawAlphaBitmap(Texture* texture, float left, float top, const SkPaint* paint);
658a168d7372132d6c87835878794b6ed43d0d282fdRomain Guy
65954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
66065cd612face362d054a85d0f7e5881c59cd523beChris Craik     * Renders a strip of polygons with the specified paint, used for tessellated geometry.
66165cd612face362d054a85d0f7e5881c59cd523beChris Craik     *
66265cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param vertexBuffer The VertexBuffer to be drawn
66365cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param paint The paint to render with
664bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik     * @param flags flags with which to draw
66565cd612face362d054a85d0f7e5881c59cd523beChris Craik     */
66605f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    status_t drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
667bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik            const SkPaint* paint, int flags = 0);
66865cd612face362d054a85d0f7e5881c59cd523beChris Craik
66965cd612face362d054a85d0f7e5881c59cd523beChris Craik    /**
67005f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik     * Convenience for translating method
67105f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik     */
67205f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    status_t drawVertexBuffer(const VertexBuffer& vertexBuffer,
673bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik            const SkPaint* paint, int flags = 0) {
674bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik        return drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
67505f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    }
67605f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik
67705f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    /**
678710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * Renders the convex hull defined by the specified path as a strip of polygons.
67954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
680710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * @param path The hull of the path to draw
681cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * @param paint The paint to render with
68254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
683d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    status_t drawConvexPath(const SkPath& path, const SkPaint* paint);
684858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
6855cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
6865cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a textured rectangle with the specified texture. The specified coordinates
6875cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * are transformed by the current snapshot's transform matrix.
6885cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
6895cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
6905cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
6915cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
6925cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
69382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture to use
69482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param paint The paint containing the alpha, blending mode, etc.
69582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
696a979474f15b454c8e2963f239a3770e200bb227cRomain Guy    void drawTextureRect(float left, float top, float right, float bottom,
697d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            Texture* texture, const SkPaint* paint);
69882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy
69982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    /**
70003750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * Draws a textured mesh with the specified texture. If the indices are omitted,
70103750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * the mesh is drawn as a simple quad. The mesh pointers become offsets when a
70203750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * VBO is bound.
70382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     *
70482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param left The left coordinate of the rectangle
70582ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param top The top coordinate of the rectangle
70682ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param right The right coordinate of the rectangle
70782ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param bottom The bottom coordinate of the rectangle
70882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texture The texture name to map onto the rectangle
70976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * @param paint The paint containing the alpha, blending mode, colorFilter, etc.
71082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param blend True if the texture contains an alpha channel
71182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param vertices The vertices that define the mesh
71282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param texCoords The texture coordinates of each vertex
71382ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * @param elementsCount The number of elements in the mesh, required by indices
714f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param swapSrcDst Whether or not the src and dst blending operations should be swapped
715f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy     * @param ignoreTransform True if the current transform should be ignored
71603750a067e818ca7fbd0f590e2ff6a8fded21e6cRomain Guy     * @param vbo The VBO used to draw the mesh
7174063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param modelViewMode Defines whether the model view matrix should be scaled
7185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param dirty True if calling this method should dirty the current layer
719f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy     */
720f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture,
72176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const SkPaint* paint, bool blend,
7226820ac8b14b4558f5d8b833dde80895306a3e137Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7235b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
7244063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
725f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy
7263b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    void drawIndexedTextureMesh(float left, float top, float right, float bottom, GLuint texture,
72776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const SkPaint* paint, bool blend,
7283b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7293b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy            bool swapSrcDst = false, bool ignoreTransform = false, GLuint vbo = 0,
7304063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale, bool dirty = true);
7313b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
732886b275e529e44a59c54b933453d9bc902973178Romain Guy    void drawAlpha8TextureMesh(float left, float top, float right, float bottom,
73376d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            GLuint texture, const SkPaint* paint,
734886b275e529e44a59c54b933453d9bc902973178Romain Guy            GLvoid* vertices, GLvoid* texCoords, GLenum drawMode, GLsizei elementsCount,
7354063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            bool ignoreTransform, ModelViewMode modelViewMode = kModelViewMode_TranslateAndScale,
7364063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            bool dirty = true);
737886b275e529e44a59c54b933453d9bc902973178Romain Guy
738f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy    /**
739448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * Draws the specified list of vertices as quads using indexed GL_TRIANGLES.
740448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * If the number of vertices to draw exceeds the number of indices we have
741448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     * pre-allocated, this method will generate several glDrawElements() calls.
742448455fe783b0a711340322dca272b8cc0ebe473Romain Guy     */
7434063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    void issueIndexedQuadDraw(Vertex* mesh, GLsizei quadsCount);
744448455fe783b0a711340322dca272b8cc0ebe473Romain Guy
745448455fe783b0a711340322dca272b8cc0ebe473Romain Guy    /**
7460a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * Draws text underline and strike-through if needed.
7470a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     *
7480a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param text The text to decor
7490a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param bytesCount The number of bytes in the text
75041541825bc90dac740e424cdd41a8c997e15cdb7Chris Craik     * @param totalAdvance The total advance in pixels, defines underline/strikethrough length
7510a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param x The x coordinate where the text will be drawn
7520a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param y The y coordinate where the text will be drawn
7530a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     * @param paint The paint to draw the text with
7540a41749953f35d33f61b3119e3161a82bb5fa59eRomain Guy     */
755d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawTextDecorations(float totalAdvance, float x, float y, const SkPaint* paint);
7561e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy
757416a847633680d94efb926837efdc18726d54918Raph Levien   /**
758416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
759416a847633680d94efb926837efdc18726d54918Raph Levien     *
760416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
761416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
762416a847633680d94efb926837efdc18726d54918Raph Levien     * @param bytesCount The number of bytes in the text
763416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
764416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
765416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
766416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
767416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
768416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
769416a847633680d94efb926837efdc18726d54918Raph Levien     */
770d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    void drawTextShadow(const SkPaint* paint, const char* text, int bytesCount, int count,
77176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const float* positions, FontRenderer& fontRenderer, int alpha,
772416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
773416a847633680d94efb926837efdc18726d54918Raph Levien
77454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
77554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
77654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
77754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
77854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
77954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
78054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
78154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
78254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
783d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik     void drawPathTexture(const PathTexture* texture, float x, float y, const SkPaint* paint);
78401d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
7851e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
786ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
787026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
788026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
7898ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
790026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
791026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
792026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
793026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
794026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
795026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
796026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
797026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
7988ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
799768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     * Returns true if the specified paint will draw invisible text.
800768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     */
801768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    bool canSkipText(const SkPaint* paint) const;
802768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy
803768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    /**
804746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Binds the specified texture. The texture unit must have been selected
805746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * prior to calling this method.
806a1db574036c9bc2d397b69f8200594027e1fff16Romain Guy     */
807746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void bindTexture(GLuint texture) {
8088aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(texture);
809746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
810746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
811746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
812aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * Binds the specified EGLImage texture. The texture unit must have been selected
813aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     * prior to calling this method.
814aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy     */
815aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    inline void bindExternalTexture(GLuint texture) {
8168aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy        mCaches.bindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
817aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    }
818aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy
819aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    /**
82082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * Enable or disable blending as necessary. This function sets the appropriate
82182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     * blend function based on the specified xfermode.
82282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy     */
823f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    inline void chooseBlending(bool blend, SkXfermode::Mode mode, ProgramDescription& description,
824f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy            bool swapSrcDst = false);
825a5aed0d58962a24c44728ffc46dc9e1ba2f9fda5Romain Guy
826f607bdc167f66b3e7003acaa4736ae46d78c1492Romain Guy    /**
827d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * Use the specified program with the current GL context. If the program is already
828d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * in use, it will not be bound again. If it is not in use, the current program is
829d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * marked unused and the specified program becomes used and becomes the new
830d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * current program.
8316926c72e25b8dec3dd4b84af0819fa1937ae7296Romain Guy     *
832d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @param program The program to use
833d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     *
834d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy     * @return true If the specified program was already in use, false otherwise.
835260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy     */
836889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    inline bool useProgram(Program* program);
837260e102162322958cf17dbd895cd6bd30dc87e32Romain Guy
838746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
839746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Invoked before any drawing operation. This sets required state.
840746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
84154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void setupDraw(bool clear = true);
84217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
84370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    /**
84470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     * Various methods to setup OpenGL rendering.
84570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy     */
84670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawWithTexture(bool isAlpha8 = false);
847ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy    void setupDrawWithTextureAndColor(bool isAlpha8 = false);
848aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawWithExternalTexture();
84915bc6437f8b4cf10dba55c7638d349e7b9563f4fRomain Guy    void setupDrawNoTexture();
85091a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik    void setupDrawVertexAlpha(bool useShadowAlphaInterp);
8518d0d4783a0206c5884bf0b958d181f450ba5207dRomain Guy    void setupDrawColor(int color, int alpha);
85270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawColor(float r, float g, float b, float a);
85386568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawAlpha8Color(int color, int alpha);
8544121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGamma(const SkPaint* paint);
855d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    void setupDrawShader(const SkShader* shader);
85676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void setupDrawColorFilter(const SkColorFilter* filter);
85776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void setupDrawBlending(const Layer* layer, bool swapSrcDst = false);
85876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void setupDrawBlending(const SkPaint* paint, bool blend = true, bool swapSrcDst = false);
85970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawProgram();
86070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawDirtyRegionsDisabled();
8614063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
8624063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
8634063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Setup the current program matrices based upon the nature of the geometry.
8644063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8654063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param mode If kModelViewMode_Translate, the geometry must be translated by the left and top
8664063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * parameters. If kModelViewMode_TranslateAndScale, the geometry that exists in the (0,0, 1,1)
8674063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * space must be scaled up and translated to fill the quad provided in (l,t,r,b). These
8684063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * transformations are stored in the modelView matrix and uploaded to the shader.
8694063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8704063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param offset Set to true if the the matrix should be fudged (translated) slightly to disambiguate
871564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik     * geometry pixel positioning. See Vertex::GeometryFudgeFactor().
8724063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
8734063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * @param ignoreTransform Set to true if l,t,r,b coordinates already in layer space,
8744063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * currentTransform() will be ignored. (e.g. when drawing clip in layer coordinates to stencil,
8754063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * or when simple translation has been extracted)
8764063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
8774063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    void setupDrawModelView(ModelViewMode mode, bool offset,
8784063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik            float left, float top, float right, float bottom, bool ignoreTransform = false);
879d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    void setupDrawColorUniforms(bool hasShader);
88086568198f2c83d4ce5c4cd692eda074ba9de9ed2Romain Guy    void setupDrawPureColorUniforms();
881d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III
882d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    /**
883d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     * Setup uniforms for the current shader.
884d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     *
885d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     * @param shader SkShader on the current paint.
886d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     *
887d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     * @param ignoreTransform Set to true to ignore the transform in shader.
888d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III     */
889d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III    void setupDrawShaderUniforms(const SkShader* shader, bool ignoreTransform = false);
89076d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void setupDrawColorFilterUniforms(const SkColorFilter* paint);
89170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawSimpleMesh();
89270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    void setupDrawTexture(GLuint texture);
893aa6c24c21c727a196451332448d4e3b11a80be69Romain Guy    void setupDrawExternalTexture(GLuint texture);
8948f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransform();
8958f0095cd33558e9cc8a440047908e53b68906f5fRomain Guy    void setupDrawTextureTransformUniforms(mat4& transform);
8964121063313ac0d6f69f6253cac821d0c1c122086Romain Guy    void setupDrawTextGammaUniforms();
897564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords = NULL, GLuint vbo = 0);
898564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMesh(const GLvoid* vertices, const GLvoid* texCoords, const GLvoid* colors);
899564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik    void setupDrawMeshIndices(const GLvoid* vertices, const GLvoid* texCoords, GLuint vbo = 0);
900448455fe783b0a711340322dca272b8cc0ebe473Romain Guy    void setupDrawIndexedVertices(GLvoid* vertices);
901f09ef51889f75289b041f9e9f949b7b82ed5b686Romain Guy    void accountForClear(SkXfermode::Mode mode);
902746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
90311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    bool updateLayer(Layer* layer, bool inFrame);
90411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    void updateLayers();
90596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void flushLayers();
90611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
907e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS
90817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
90917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
91017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
91117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
912e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    void drawRegionRectsDebug(const Region& region);
913e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif
9143a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
9158ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
9168ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Renders the specified region as a series of rectangles. The region
9178ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * must be in screen-space coordinates.
9188ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
91976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false);
9208ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9218ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
9228ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
9238ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is turned on.
9248ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
9258ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void debugClip();
9268ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
9277c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void debugOverdraw(bool enable, bool clear);
9287c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void renderOverdraw();
92978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    void countOverdraw();
9307c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
931746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
932746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
933746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
934746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    inline void dirtyClip() {
935746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy        mDirtyClip = true;
936746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    }
937746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
9383b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    inline const UvMapper& getMapper(const Texture* texture) {
9393b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
9403b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    }
9413b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
9423b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    /**
9433b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * Returns a texture object for the specified bitmap. The texture can
9443b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * come from the texture cache or an atlas. If this method returns
9453b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * NULL, the texture could not be found and/or allocated.
9463b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     */
947d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    Texture* getTexture(const SkBitmap* bitmap);
9483b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
9494063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
9504063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Model-view matrix used to position/size objects
9514063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
9524063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Stores operation-local modifications to the draw matrix that aren't incorporated into the
9534063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * currentTransform().
9544063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
955e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik     * If generated with kModelViewMode_Translate, mModelViewMatrix will reflect an x/y offset,
9564063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * e.g. the offset in drawLayer(). If generated with kModelViewMode_TranslateAndScale,
957e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik     * mModelViewMatrix will reflect a translation and scale, e.g. the translation and scale
958e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik     * required to make VBO 0 (a rect of (0,0,1,1)) scaled to match the x,y offset, and width/height
959e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik     * of a bitmap.
9604063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     *
9614063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used as input to SkiaShader transformation.
9624063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
963e10e827ed68b0a9487cf8dd1fc545f9a09517ae9Chris Craik    mat4 mModelViewMatrix;
964c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy
9652b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // State used to define the clipping region
9665f803623559aab395a29d575c37c4e39c23a4b4eChris Craik    Rect mTilingClip;
96796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is the target render surface opaque
96896885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mOpaque;
96996885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    // Is a frame currently being rendered
97096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    bool mFrameStarted;
9719d5316e3f56d138504565ff311145ac01621dff4Romain Guy
972026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    // Used to draw textured quads
973ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    TextureVertex mMeshVertices[4];
974ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
9753b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    // Default UV mapper
9763b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    const UvMapper mUvMapper;
9773b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
978c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    // shader, filters, and shadow
979c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik    DrawModifiers mDrawModifiers;
9805ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy    SkPaint mFilteredPaint;
9815ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
98282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy    // Various caches
983fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy    Caches& mCaches;
9843bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy    Extensions& mExtensions;
9853b20251a355c88193c439f928a84ae69483fb488John Reck    RenderState& mRenderState;
9868694230ff25fa0a60e480d424843e56b718f0516Romain Guy
9878f3b8e32993d190a26c70c839a63d8ce4c3b16d9Romain Guy    // List of rectangles to clear after saveLayer() is invoked
98854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    Vector<Rect*> mLayers;
98911cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    // List of layers to update at the beginning of a frame
9900e89e2b7bcb2c035e8cee77f93120e7c5617f8d2John Reck    Vector< sp<Layer> > mLayerUpdates;
99154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
99270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // The following fields are used to setup drawing
99370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Used to describe the shaders to generate
99470ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    ProgramDescription mDescription;
99570ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Color description
99670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mColorSet;
99770ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    float mColorA, mColorR, mColorG, mColorB;
99870ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Indicates that the shader should get a color
99970ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mSetShaderColor;
100070ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Current texture unit
100170ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    GLuint mTextureUnit;
100270ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    // Track dirty regions, true by default
100370ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy    bool mTrackDirtyRegions;
10042b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    // Indicate whether we are drawing an opaque frame
10052b7028eabac80cec170572bc0e945a1d4224e595Romain Guy    bool mOpaqueFrame;
100670ca14e08ae197547ac412e8a1210e1ebdfb2eb1Romain Guy
100787e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // See PROPERTY_DISABLE_SCISSOR_OPTIMIZATION in
100887e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    // Properties.h
100987e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy    bool mScissorOptimizationDisabled;
101087e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
101154c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    // No-ops start/endTiling when set
101254c1a64d5441a964890b44280e4457e11f4f924aRomain Guy    bool mSuppressTiling;
1013284b24358410cb0200e525a5ba36994090c83f20Chris Craik    bool mFirstFrameAfterResize;
101454c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
1015deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik    bool mSkipOutlineClip;
1016deeda3d337aed1eee218b89a7aba5992ced371f0Chris Craik
1017058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    // Lighting + shadows
1018058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    Vector3 mLightCenter;
1019058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    float mLightRadius;
1020058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    uint8_t mAmbientShadowAlpha;
1021058fc640017c90120c599d378a4cbc55668b05b7Chris Craik    uint8_t mSpotShadowAlpha;
1022058fc640017c90120c599d378a4cbc55668b05b7Chris Craik
10234ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    // Paths kept alive for the duration of the frame
10244ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    std::vector<SkPath*> mTempPaths;
10254ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik
102696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    friend class Layer;
1027257ae3502cfad43df681b1783528d645bdabc63fRomain Guy    friend class TextSetupFunctor;
102803c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy    friend class DrawBitmapOp;
102903c00b5a135e68d22ca5bb829b899ebda6ed7e9dRomain Guy    friend class DrawPatchOp;
1030b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
1031bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy}; // class OpenGLRenderer
1032e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10339d5316e3f56d138504565ff311145ac01621dff4Romain Guy}; // namespace uirenderer
1034e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy}; // namespace android
1035e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
10365b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_OPENGL_RENDERER_H
1037