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
2003ae272459869b854e5db252fc81a64a516e111fChris Craik#include "CanvasState.h"
2103ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Debug.h"
2203ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Extensions.h"
2303ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Matrix.h"
2403ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Program.h"
2503ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Rect.h"
2603ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Snapshot.h"
2703ae272459869b854e5db252fc81a64a516e111fChris Craik#include "UvMapper.h"
2803ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Vertex.h"
2903ae272459869b854e5db252fc81a64a516e111fChris Craik#include "Caches.h"
3003ae272459869b854e5db252fc81a64a516e111fChris Craik#include "utils/PaintUtils.h"
3103ae272459869b854e5db252fc81a64a516e111fChris Craik
329d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2.h>
339d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <GLES2/gl2ext.h>
3485bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
35ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkBitmap.h>
3676d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkCanvas.h>
3776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger#include <SkColorFilter.h>
386e03543f6335a03f9c3dc7d9afa9752f67a2e14cDerek Sollenberger#include <SkDrawLooper.h>
39f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <SkMatrix.h>
40ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <SkPaint.h>
41079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guy#include <SkRegion.h>
4285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <SkXfermode.h>
43e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
44c29a0a4664a4b9871fadd668b632469a0db240b9Derek Sollenberger#include <utils/Blur.h>
45daf98e941e140e8739458126640183b9f296a2abChet Haase#include <utils/Functor.h>
46bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy#include <utils/RefBase.h>
47ba6be8a62dcdb3ffd210cd36b9af4e3a658eac47Romain Guy#include <utils/SortedVector.h>
48bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
497953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
507953745dd565167113f8cbfc461bc0521d32d870Romain Guy
513b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy#include <androidfw/ResourceTypes.h>
523b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
53272a685f17cc4828257e521a6f62b7b17870f75eJohn Reck#include <vector>
54272a685f17cc4828257e521a6f62b7b17870f75eJohn Reck
55d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins IIIclass SkShader;
56d1ad5e62fda248c6d185cde3cb6d9f01a223066cLeon Scroggins III
57e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guynamespace android {
589d5316e3f56d138504565ff311145ac01621dff4Romain Guynamespace uirenderer {
59e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
6003ae272459869b854e5db252fc81a64a516e111fChris Craikenum class DrawOpMode {
6103ae272459869b854e5db252fc81a64a516e111fChris Craik    kImmediate,
6203ae272459869b854e5db252fc81a64a516e111fChris Craik    kDefer,
6303ae272459869b854e5db252fc81a64a516e111fChris Craik    kFlush
6403ae272459869b854e5db252fc81a64a516e111fChris Craik};
6503ae272459869b854e5db252fc81a64a516e111fChris Craik
66b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass DeferredDisplayState;
67117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craikstruct Glop;
683b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState;
69e18264b079481a244b30e3f71012c53bbd861f92John Reckclass RenderNode;
70828407356dd5c34a3e441604aaf895cbec7c7e66Chris Craikclass TextDrawFunctor;
71b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craikclass VertexBuffer;
72b458942bb6e6cf13c68341dda35ef5cee060f5aeChris Craik
73ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craikenum StateDeferFlags {
74ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Draw = 0x1,
75ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    kStateDeferFlag_Clip = 0x2
76ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik};
77ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik
7828ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craikenum ClipSideFlags {
79a02c4ed885d97e516f844ddb0a96083f1b45b4cbChris Craik    kClipSide_None = 0x0,
8028ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Left = 0x1,
8128ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Top = 0x2,
8228ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Right = 0x4,
8328ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    kClipSide_Bottom = 0x8,
84d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_Full = 0xF,
85d72b73cea49f29c41661e55eb6bfdbc04f09d809Chris Craik    kClipSide_ConservativeFull = 0x1F
8628ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik};
8728ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik
88bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craikenum VertexBufferDisplayFlags {
89bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik    kVertexBuffer_Offset = 0x1,
9091a8c7c62913c2597e3bf5a6d59d2ed5fc7ba4e0Chris Craik    kVertexBuffer_ShadowInterp = 0x2,
91bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik};
92bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik
934063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik/**
944063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * Defines additional transformation that should be applied by the model view matrix, beyond that of
954063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik * the currentTransform()
964063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik */
974063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craikenum ModelViewMode {
984063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
994063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used when the model view should simply translate geometry passed to the shader. The resulting
1004063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * matrix will be a simple translation.
1014063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
1024063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    kModelViewMode_Translate = 0,
1034063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
1044063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    /**
1054063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * Used when the model view should translate and scale geometry. The resulting matrix will be a
1064063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     * translation + scale. This is frequently used together with VBO 0, the (0,0,1,1) rect.
1074063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik     */
1084063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik    kModelViewMode_TranslateAndScale = 1,
1094063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik};
1104063a0e03ba2e354cc6d19c0ffc073fd5b8aa2caChris Craik
111f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
112f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy// Renderer
113f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy///////////////////////////////////////////////////////////////////////////////
1145cbbce535744b89df5ecea95de21ee3733298260Romain Guy/**
11514e513058ed4168c94e015638d16f5f87fd8063aChris Craik * OpenGL Renderer implementation.
1165cbbce535744b89df5ecea95de21ee3733298260Romain Guy */
11703ae272459869b854e5db252fc81a64a516e111fChris Craikclass OpenGLRenderer : public CanvasStateClient {
118e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guypublic:
1193b20251a355c88193c439f928a84ae69483fb488John Reck    OpenGLRenderer(RenderState& renderState);
120e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    virtual ~OpenGLRenderer();
121e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy
1223b20251a355c88193c439f928a84ae69483fb488John Reck    void initProperties();
12350210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette    void initLight(float lightRadius, uint8_t ambientShadowAlpha,
12450210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette            uint8_t spotShadowAlpha);
12550210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette    void setLightCenter(const Vector3& lightCenter);
12687e2f757be9b24d369bab354e37c276e851b1fc7Romain Guy
12703ae272459869b854e5db252fc81a64a516e111fChris Craik    /*
12803ae272459869b854e5db252fc81a64a516e111fChris Craik     * Prepares the renderer to draw a frame. This method must be invoked
12903ae272459869b854e5db252fc81a64a516e111fChris Craik     * at the beginning of each frame. Only the specified rectangle of the
13003ae272459869b854e5db252fc81a64a516e111fChris Craik     * frame is assumed to be dirty. A clip will automatically be set to
13103ae272459869b854e5db252fc81a64a516e111fChris Craik     * the specified rectangle.
13203ae272459869b854e5db252fc81a64a516e111fChris Craik     *
13303ae272459869b854e5db252fc81a64a516e111fChris Craik     * @param opaque If true, the target surface is considered opaque
13403ae272459869b854e5db252fc81a64a516e111fChris Craik     *               and will not be cleared. If false, the target surface
13503ae272459869b854e5db252fc81a64a516e111fChris Craik     *               will be cleared
13603ae272459869b854e5db252fc81a64a516e111fChris Craik     */
13764e445bf74bee2098781d608cedfd723d8cc88d3Chris Craik    virtual void prepareDirty(int viewportWidth, int viewportHeight,
13864e445bf74bee2098781d608cedfd723d8cc88d3Chris Craik            float left, float top, float right, float bottom, bool opaque);
139c89b14bba0f6cc2c91629080617f7ed215f697f3Romain Guy
14003ae272459869b854e5db252fc81a64a516e111fChris Craik    /**
14103ae272459869b854e5db252fc81a64a516e111fChris Craik     * Indicates the end of a frame. This method must be invoked whenever
14203ae272459869b854e5db252fc81a64a516e111fChris Craik     * the caller is done rendering a frame.
14303ae272459869b854e5db252fc81a64a516e111fChris Craik     * Returns true if any drawing was done during the frame (the output
14403ae272459869b854e5db252fc81a64a516e111fChris Craik     * has changed / is "dirty" and should be displayed to the user).
14503ae272459869b854e5db252fc81a64a516e111fChris Craik     */
14603ae272459869b854e5db252fc81a64a516e111fChris Craik    virtual bool finish();
14703ae272459869b854e5db252fc81a64a516e111fChris Craik
14803ae272459869b854e5db252fc81a64a516e111fChris Craik    void callDrawGLFunction(Functor* functor, Rect& dirty);
14908ae317c21ec3086b5017672bba87420cc38a407Romain Guy
1503b20251a355c88193c439f928a84ae69483fb488John Reck    void pushLayerUpdate(Layer* layer);
1513b20251a355c88193c439f928a84ae69483fb488John Reck    void cancelLayerUpdate(Layer* layer);
1523b20251a355c88193c439f928a84ae69483fb488John Reck    void flushLayerUpdates();
153443a714fa7c0dd07fee3527cc5bc3d3ca1fb7d44John Reck    void markLayersAsBuildLayers();
15411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
1553b20251a355c88193c439f928a84ae69483fb488John Reck    virtual int saveLayer(float left, float top, float right, float bottom,
15603ae272459869b854e5db252fc81a64a516e111fChris Craik            const SkPaint* paint, int flags) {
157e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik        return saveLayer(left, top, right, bottom, paint, flags, nullptr);
1583f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    }
1593f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik
1603f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    // Specialized saveLayer implementation, which will pass the convexMask to an FBO layer, if
1613f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    // created, which will in turn clip to that mask when drawn back/restored.
1623f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik    int saveLayer(float left, float top, float right, float bottom,
1633f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik            const SkPaint* paint, int flags, const SkPath* convexMask);
164bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy
165d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    int saveLayerDeferred(float left, float top, float right, float bottom,
166d44fbe55a9f434cb5bb0e34c143ba1445141990dDerek Sollenberger            const SkPaint* paint, int flags);
167d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
16803ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawRenderNode(RenderNode* displayList, Rect& dirty, int32_t replayFlags = 1);
1693aadd60521960be063ee06208562ccb63dc414e3Chris Craik    void drawLayer(Layer* layer);
17003ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
171107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawBitmaps(const SkBitmap* bitmap, AssetAtlas::Entry* entry, int bitmapCount,
172d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, bool pureTranslate, const Rect& bounds, const SkPaint* paint);
17303ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawBitmap(const SkBitmap* bitmap, Rect src, Rect dst,
17403ae272459869b854e5db252fc81a64a516e111fChris Craik            const SkPaint* paint);
17503ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawBitmapMesh(const SkBitmap* bitmap, int meshWidth, int meshHeight,
17603ae272459869b854e5db252fc81a64a516e111fChris Craik            const float* vertices, const int* colors, const SkPaint* paint);
177107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawPatches(const SkBitmap* bitmap, AssetAtlas::Entry* entry,
178d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            TextureVertex* vertices, uint32_t indexCount, const SkPaint* paint);
179107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawPatch(const SkBitmap* bitmap, const Patch* mesh, AssetAtlas::Entry* entry,
180d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            float left, float top, float right, float bottom, const SkPaint* paint);
18103ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawColor(int color, SkXfermode::Mode mode);
18203ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawRect(float left, float top, float right, float bottom,
18303ae272459869b854e5db252fc81a64a516e111fChris Craik            const SkPaint* paint);
18403ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawRoundRect(float left, float top, float right, float bottom,
18503ae272459869b854e5db252fc81a64a516e111fChris Craik            float rx, float ry, const SkPaint* paint);
18603ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawCircle(float x, float y, float radius, const SkPaint* paint);
18703ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawOval(float left, float top, float right, float bottom,
18803ae272459869b854e5db252fc81a64a516e111fChris Craik            const SkPaint* paint);
18903ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawArc(float left, float top, float right, float bottom,
19003ae272459869b854e5db252fc81a64a516e111fChris Craik            float startAngle, float sweepAngle, bool useCenter, const SkPaint* paint);
19103ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawPath(const SkPath* path, const SkPaint* paint);
19203ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawLines(const float* points, int count, const SkPaint* paint);
19303ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawPoints(const float* points, int count, const SkPaint* paint);
194e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    void drawTextOnPath(const glyph_t* glyphs, int bytesCount, int count, const SkPath* path,
19503ae272459869b854e5db252fc81a64a516e111fChris Craik            float hOffset, float vOffset, const SkPaint* paint);
196e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    void drawText(const glyph_t* glyphs, int bytesCount, int count, float x, float y,
197d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik            const float* positions, const SkPaint* paint, float totalAdvance, const Rect& bounds,
19803ae272459869b854e5db252fc81a64a516e111fChris Craik            DrawOpMode drawOpMode = DrawOpMode::kImmediate);
19903ae272459869b854e5db252fc81a64a516e111fChris Craik    void drawRects(const float* rects, int count, const SkPaint* paint);
20085bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy
201107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawShadow(float casterAlpha,
202e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik            const VertexBuffer* ambientShadowVertexBuffer,
203e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik            const VertexBuffer* spotShadowVertexBuffer);
204f57776b2d195f0937906eb88b777bb55ccc36967Chris Craik
20503ae272459869b854e5db252fc81a64a516e111fChris Craik    void setDrawFilter(SkDrawFilter* filter);
2065ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
2075e49b307eb99269db2db257760508b8efd7bb97dChris Craik    /**
2085e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Store the current display state (most importantly, the current clip and transform), and
2095e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * additionally map the state's bounds from local to window coordinates.
2105e49b307eb99269db2db257760508b8efd7bb97dChris Craik     *
2115e49b307eb99269db2db257760508b8efd7bb97dChris Craik     * Returns true if quick-rejected
2125e49b307eb99269db2db257760508b8efd7bb97dChris Craik     */
213ff78583d8a73ca35ce65b5d2592570ff6fb9901bChris Craik    bool storeDisplayState(DeferredDisplayState& state, int stateDeferFlags);
214527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void restoreDisplayState(const DeferredDisplayState& state, bool skipClipRestore = false);
21528ce94a4ffc7576f40776d212f1ada79fafaa061Chris Craik    void setupMergedMultiDraw(const Rect* clipRect);
216c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craik
2173b20251a355c88193c439f928a84ae69483fb488John Reck    bool isCurrentTransformSimple() {
218d6b65f67717025b1162f86f04e2caa5723566cacChris Craik        return currentTransform()->isSimple();
219672433d90fab7383cd28beac9d4485b566a90940Romain Guy    }
220672433d90fab7383cd28beac9d4485b566a90940Romain Guy
2210f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    Caches& getCaches() {
2220f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy        return mCaches;
2230f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    }
2240f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
22565fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik    RenderState& renderState() {
22665fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik        return mRenderState;
22765fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik    }
22865fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik
229984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    int getViewportWidth() { return mState.getViewportWidth(); }
230984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    int getViewportHeight() { return mState.getViewportHeight(); }
2310e87f00f8cb79635aa70b9a2dfa02bf19dc7473dChris Craik
23217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
233a08f95cfeca7217f9c533b03663bf0dceedd259aChris Craik     * Scales the alpha on the current snapshot. This alpha value will be modulated
23417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * with other alpha values when drawing primitives.
23517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
236984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    void scaleAlpha(float alpha) { mState.scaleAlpha(alpha); }
23717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
23817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
2390f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     * Inserts a named event marker in the stream of GL commands.
2400f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy     */
2410f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    void eventMark(const char* name) const;
2420f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy
2430f6675332c04c74909425d1d328f02b32c0ff40eRomain Guy    /**
24462d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik     * Inserts a formatted event marker in the stream of GL commands.
24562d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik     */
24662d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik    void eventMarkDEBUG(const char *fmt, ...) const;
24762d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik
24862d307c2402777d5e53b4590af5f32f8c55afd81Chris Craik    /**
24917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Inserts a named group marker in the stream of GL commands. This marker
25017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * can be used by tools to group commands into logical groups. A call to
25117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * this method must always be followed later on by a call to endMark().
25217112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
25313631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void startMark(const char* name) const;
25417112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy
25517112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
25617112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Closes the last group marker opened by startMark().
25717112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
25813631f3da855f200a151e7837ed9f6b079622b58Romain Guy    void endMark() const;
25913631f3da855f200a151e7837ed9f6b079622b58Romain Guy
260d15ebf25c595b855f6978d0600218e3ea5f31e92Chet Haase    /**
26159744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * Build the best transform to use to rasterize text given a full
26259744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * transform matrix, and whether filteration is needed.
26359744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     *
26459744b79ec302000802cd56d30a1bf70f0183c80Chris Craik     * Returns whether filtration is needed
265624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy     */
26659744b79ec302000802cd56d30a1bf70f0183c80Chris Craik    bool findBestFontTransform(const mat4& transform, SkMatrix* outMatrix) const;
267624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy
268527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#if DEBUG_MERGE_BEHAVIOR
269527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    void drawScreenSpaceColorRect(float left, float top, float right, float bottom, int color) {
270527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.setScissorEnabled(false);
271527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
272527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        // should only be called outside of other draw ops, so stencil can only be in test state
273527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        bool stencilWasEnabled = mCaches.stencil.isTestEnabled();
274527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        mCaches.stencil.disable();
275527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
276527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        drawColorRect(left, top, right, bottom, color, SkXfermode::kSrcOver_Mode, true);
277527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
278527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik        if (stencilWasEnabled) mCaches.stencil.enableTest();
279107843de4507b3511006cb9c77b8d0364374385aTom Hudson        mDirty = true;
280527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik    }
281527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik#endif
282527a3aace1dd72432c2e0472a570e030ad04bf16Chris Craik
283984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    const Vector3& getLightCenter() const { return mState.currentLightCenter(); }
28405f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    float getLightRadius() const { return mLightRadius; }
28569e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    uint8_t getAmbientShadowAlpha() const { return mAmbientShadowAlpha; }
28669e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    uint8_t getSpotShadowAlpha() const { return mSpotShadowAlpha; }
28705f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik
288984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    ///////////////////////////////////////////////////////////////////
289984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    /// State manipulation
290984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
29103ae272459869b854e5db252fc81a64a516e111fChris Craik    int getSaveCount() const;
29203ae272459869b854e5db252fc81a64a516e111fChris Craik    int save(int flags);
29303ae272459869b854e5db252fc81a64a516e111fChris Craik    void restore();
29403ae272459869b854e5db252fc81a64a516e111fChris Craik    void restoreToCount(int saveCount);
295984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
2966daa13c5fa7577fa1d8371deca446f6ca911f38fChris Craik    void setGlobalMatrix(const Matrix4& matrix) {
2976daa13c5fa7577fa1d8371deca446f6ca911f38fChris Craik        mState.setMatrix(matrix);
2986daa13c5fa7577fa1d8371deca446f6ca911f38fChris Craik    }
2996daa13c5fa7577fa1d8371deca446f6ca911f38fChris Craik    void setLocalMatrix(const Matrix4& matrix);
300ac7b6d33d23cb0baaf61c723346198d41f012035Tom Hudson    void setLocalMatrix(const SkMatrix& matrix);
30103ae272459869b854e5db252fc81a64a516e111fChris Craik    void concatMatrix(const SkMatrix& matrix) { mState.concatMatrix(matrix); }
302984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
30303ae272459869b854e5db252fc81a64a516e111fChris Craik    void translate(float dx, float dy, float dz = 0.0f);
30403ae272459869b854e5db252fc81a64a516e111fChris Craik    void rotate(float degrees);
30503ae272459869b854e5db252fc81a64a516e111fChris Craik    void scale(float sx, float sy);
30603ae272459869b854e5db252fc81a64a516e111fChris Craik    void skew(float sx, float sy);
307984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
308984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    void setMatrix(const Matrix4& matrix); // internal only convenience method
309984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    void concatMatrix(const Matrix4& matrix); // internal only convenience method
310984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
31103ae272459869b854e5db252fc81a64a516e111fChris Craik    const Rect& getLocalClipBounds() const { return mState.getLocalClipBounds(); }
312984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
31303ae272459869b854e5db252fc81a64a516e111fChris Craik    bool quickRejectConservative(float left, float top,
31403ae272459869b854e5db252fc81a64a516e111fChris Craik            float right, float bottom) const {
315984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson        return mState.quickRejectConservative(left, top, right, bottom);
316984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    }
317984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
31803ae272459869b854e5db252fc81a64a516e111fChris Craik    bool clipRect(float left, float top,
31903ae272459869b854e5db252fc81a64a516e111fChris Craik            float right, float bottom, SkRegion::Op op);
32003ae272459869b854e5db252fc81a64a516e111fChris Craik    bool clipPath(const SkPath* path, SkRegion::Op op);
32103ae272459869b854e5db252fc81a64a516e111fChris Craik    bool clipRegion(const SkRegion* region, SkRegion::Op op);
322984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
323984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    /**
324984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson     * Does not support different clipping Ops (that is, every call to setClippingOutline is
325984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson     * effectively using SkRegion::kReplaceOp)
326984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson     *
327984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson     * The clipping outline is independent from the regular clip.
328984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson     */
329984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    void setClippingOutline(LinearAllocator& allocator, const Outline* outline);
330984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    void setClippingRoundRect(LinearAllocator& allocator,
331984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson            const Rect& rect, float radius, bool highPriority = true);
332fca52b7583d1e5f5ff8ed06554875d2a30ef56faChris Craik    void setProjectionPathMask(LinearAllocator& allocator, const SkPath* path);
333984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
334984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    inline bool hasRectToRectTransform() const { return mState.hasRectToRectTransform(); }
335984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    inline const mat4* currentTransform() const { return mState.currentTransform(); }
336984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
337984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    ///////////////////////////////////////////////////////////////////
338984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    /// CanvasStateClient interface
339984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
340e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik    virtual void onViewportInitialized() override;
341e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik    virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override;
3426b109c74982033d4a220cd10a0eab8b024b351c9Chris Craik    virtual GLuint getTargetFbo() const override { return 0; }
343984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
3444ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    SkPath* allocPathForFrame() {
34551d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        std::unique_ptr<SkPath> path(new SkPath());
34651d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        SkPath* returnPath = path.get();
34751d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        mTempPaths.push_back(std::move(path));
34851d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        return returnPath;
3494ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik    }
3504ac36f80beb958c77a92a3e1a235f6ed9daaa510Chris Craik
351ac7b6d33d23cb0baaf61c723346198d41f012035Tom Hudson    void setBaseTransform(const Matrix4& matrix) { mBaseTransform = matrix; }
352ac7b6d33d23cb0baaf61c723346198d41f012035Tom Hudson
353e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyprotected:
354e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy    /**
35596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Perform the setup specific to a frame. This method does not
35696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * issue any OpenGL commands.
35796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
35864e445bf74bee2098781d608cedfd723d8cc88d3Chris Craik    void setupFrameState(int viewportWidth, int viewportHeight,
35964e445bf74bee2098781d608cedfd723d8cc88d3Chris Craik            float left, float top, float right, float bottom, bool opaque);
36096885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
36196885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
36296885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * Indicates the start of rendering. This method will setup the
36396885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     * initial OpenGL state (viewport, clearing the buffer, etc.)
36496885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy     */
365107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void startFrame();
36696885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy
36796885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    /**
3687c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     * Clears the underlying surface if needed.
3697c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy     */
370107843de4507b3511006cb9c77b8d0364374385aTom Hudson    virtual void clear(float left, float top, float right, float bottom, bool opaque);
3717c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy
3727c25aab491707f7324f9941b8cfa9bd2b4b97e76Romain Guy    /**
37335643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     * Call this method after updating a layer during a drawing pass.
37435643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy     */
37535643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    void resumeAfterLayer();
37635643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy
37735643ddc689913f5b5f80ceed864470d987bd6cdRomain Guy    /**
3788ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * This method is called whenever a stencil buffer is required. Subclasses
3798ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * should override this method and call attachStencilBufferToLayer() on the
3808ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * appropriate layer(s).
3818ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3828ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    virtual void ensureStencilBuffer();
3838ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
3848ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
3858ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Obtains a stencil render buffer (allocating it if necessary) and
3868ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * attaches it to the specified layer.
3878ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
3888ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void attachStencilBufferToLayer(Layer* layer);
3898ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
390487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    /**
391487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * Draw a rectangle list. Currently only used for the the stencil buffer so that the stencil
392487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * will have a value of 'n' in every unclipped pixel, where 'n' is the number of rectangles
393487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     * in the list.
394487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk     */
395487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk    void drawRectangleList(const RectangleList& rectangleList);
396487a92caef2eb90a62e8f8d7a6fe6315f1c1d8d8Rob Tsuk
397f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    bool quickRejectSetupScissor(float left, float top, float right, float bottom,
398e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik            const SkPaint* paint = nullptr);
399e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik    bool quickRejectSetupScissor(const Rect& bounds, const SkPaint* paint = nullptr) {
400f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik        return quickRejectSetupScissor(bounds.left, bounds.top,
401f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik                bounds.right, bounds.bottom, paint);
402f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik    }
403f0a590781b2c3e34132b2011d3956135add73ae0Chris Craik
4048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
405e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * Compose the layer defined in the current snapshot with the layer
406e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * defined by the previous snapshot.
407e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
408e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * The current snapshot *must* be a layer (flag kFlagIsLayer set.)
409e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     *
410e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param curent The current snapshot containing the layer to compose
411e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     * @param previous The previous snapshot to compose the current layer with
412e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy     */
41314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    virtual void composeLayer(const Snapshot& current, const Snapshot& previous);
414694b519ac647fe998fd396fe0784cc8e179aadc4Romain Guy
415ada830f639591b99c3e40de22b07296c7932a33fRomain Guy    /**
416f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Marks the specified region as dirty at the specified bounds.
417ada830f639591b99c3e40de22b07296c7932a33fRomain Guy     */
418f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayerUnchecked(Rect& bounds, Region* region);
419ada830f639591b99c3e40de22b07296c7932a33fRomain Guy
42042f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
42142f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Returns the region of the current layer.
42242f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
423624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual Region* getRegion() const {
424984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson        return mState.currentRegion();
425f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
426f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
42742f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy    /**
42842f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     * Indicates whether rendering is currently targeted at a layer.
42942f3a4b7c35dd1ea1922356eb3611af8cde05179Romain Guy     */
430624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool hasLayer() const {
431984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson        return (mState.currentFlags() & Snapshot::kFlagFboTarget) && mState.currentRegion();
432f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    }
4331bd1bad0b4a75e633c5edbe802bf6fb4dd765161Romain Guy
43477a811610f99e21da7f88dafef60d09f345d0506Romain Guy    /**
43577a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * Renders the specified layer as a textured quad.
43677a811610f99e21da7f88dafef60d09f345d0506Romain Guy     *
43777a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param layer The layer to render
43877a811610f99e21da7f88dafef60d09f345d0506Romain Guy     * @param rect The bounds of the layer
43977a811610f99e21da7f88dafef60d09f345d0506Romain Guy     */
44077a811610f99e21da7f88dafef60d09f345d0506Romain Guy    void drawTextureLayer(Layer* layer, const Rect& rect);
44177a811610f99e21da7f88dafef60d09f345d0506Romain Guy
442be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
4438df5ffa9ae0667d9e0241adf4675753156fcef84Chris Craik     * Gets the alpha from a layer, accounting for snapshot alpha
44416ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     *
44516ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     * @param layer The layer from which the alpha is extracted
44616ecda5317c40fc3da284952d9b3add34d6763aeChris Craik     */
44776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    inline float getLayerAlpha(const Layer* layer) const;
448be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy
449be6f9dc1e71b425b7ac1c40c0a2c72d03eb9fbeeRomain Guy    /**
45011cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     * Set to true to suppress error checks at the end of a frame.
45111cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy     */
452624234f69b2a4781d24f3e4c6ae6450729e38397Romain Guy    virtual bool suppressErrorChecks() const {
45311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy        return false;
45411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    }
45511cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
456984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    CanvasState mState;
45765fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik    Caches& mCaches;
45865fe5eeb19e2e15c8b1ee91e8a2dcf0c25e48ca6Chris Craik    RenderState& mRenderState;
459984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
46008ae317c21ec3086b5017672bba87420cc38a407Romain Guyprivate:
4613375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik    enum class GlopRenderType {
4623375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik        Standard,
4633375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik        Multi,
4643375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik        LayerClear
4653375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik    };
4663375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik
4673375f8ad30997482317b5ade5618cc8a01b96d7dChris Craik    void renderGlop(const Glop& glop, GlopRenderType type = GlopRenderType::Standard);
468117bdbcfa3e8306dad21e7e01fa71b00cdfa7265Chris Craik
4695cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
470dcfc836b457a87881da409e1acf251515f121446Romain Guy     * Discards the content of the framebuffer if supported by the driver.
471dcfc836b457a87881da409e1acf251515f121446Romain Guy     * This method should be called at the beginning of a frame to optimize
472dcfc836b457a87881da409e1acf251515f121446Romain Guy     * rendering on some tiler architectures.
473dcfc836b457a87881da409e1acf251515f121446Romain Guy     */
474dcfc836b457a87881da409e1acf251515f121446Romain Guy    void discardFramebuffer(float left, float top, float right, float bottom);
475dcfc836b457a87881da409e1acf251515f121446Romain Guy
476dcfc836b457a87881da409e1acf251515f121446Romain Guy    /**
4775cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Sets the clipping rectangle using glScissor. The clip is defined by
4785cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * the current snapshot's clipRect member.
4795cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
480bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy    void setScissorFromClip();
481bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy
4825cbbce535744b89df5ecea95de21ee3733298260Romain Guy    /**
4838ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Sets the clipping region using the stencil buffer. The clip region
4848ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is defined by the current snapshot's clipRegion member.
4858ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
4868ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void setStencilFromClip();
4878ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
4888ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
489408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds of the layer, calculates ...
490d90144db52c7297879b950cbbc85137ed123ab5bChris Craik     */
491d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    void calculateLayerBoundsAndClip(Rect& bounds, Rect& clip, bool fboLayer);
492d90144db52c7297879b950cbbc85137ed123ab5bChris Craik
493d90144db52c7297879b950cbbc85137ed123ab5bChris Craik    /**
494408eb12631376cbdc96803e918decf6ea804d346Chris Craik     * Given the local bounds + clip of the layer, updates current snapshot's empty/invisible
495408eb12631376cbdc96803e918decf6ea804d346Chris Craik     */
496408eb12631376cbdc96803e918decf6ea804d346Chris Craik    void updateSnapshotIgnoreForLayer(const Rect& bounds, const Rect& clip,
497408eb12631376cbdc96803e918decf6ea804d346Chris Craik            bool fboLayer, int alpha);
498408eb12631376cbdc96803e918decf6ea804d346Chris Craik
499408eb12631376cbdc96803e918decf6ea804d346Chris Craik    /**
500d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * Creates a new layer stored in the specified snapshot.
501d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
502d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param snapshot The snapshot associated with the new layer
503d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param left The left coordinate of the layer
504d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param top The top coordinate of the layer
505d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param right The right coordinate of the layer
506d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param bottom The bottom coordinate of the layer
507d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param alpha The translucency of the layer
508d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param mode The blending mode of the layer
509d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @param flags The layer save flags
5103f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik     * @param mask A mask to use when drawing the layer back, may be empty
511d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     *
512d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     * @return True if the layer was successfully created, false otherwise
513d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy     */
514d48885a6c8cd27a8a62552c33b5282e9882e19f6Chet Haase    bool createLayer(float left, float top, float right, float bottom,
5153f085429fd47ebd32ac2463b3eae2a5a6c17be25Chris Craik            const SkPaint* paint, int flags, const SkPath* convexMask);
516d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy
517d55a86120dd1e8ebcc6906c9ffd463f7460348daRomain Guy    /**
5185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Creates a new layer stored in the specified snapshot as an FBO.
5195b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5205b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to store as an FBO
5215b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param snapshot The snapshot associated with the new layer
5225b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param bounds The bounds of the layer
5235b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
524e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    bool createFboLayer(Layer* layer, Rect& bounds, Rect& clip);
5255b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5265b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
5275b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * Compose the specified layer as a region.
5285b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
5295b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param layer The layer to compose
5305b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     * @param rect The layer's bounds
5315b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
5325b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    void composeLayerRegion(Layer* layer, const Rect& rect);
5335b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
5345b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy    /**
53553e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * Restores the content in layer to the screen, swapping the blend mode,
53653e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * specifically used in the restore() of a saveLayerAlpha().
5375b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     *
53853e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * This allows e.g. a layer that would have been drawn on top of existing content (with SrcOver)
53953e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * to be drawn underneath.
54053e51e4aa933f9603587e1780f446c18816bf9beChris Craik     *
54153e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * This will always ignore the canvas transform.
54253e51e4aa933f9603587e1780f446c18816bf9beChris Craik     */
54353e51e4aa933f9603587e1780f446c18816bf9beChris Craik    void composeLayerRectSwapped(Layer* layer, const Rect& rect);
54453e51e4aa933f9603587e1780f446c18816bf9beChris Craik
54553e51e4aa933f9603587e1780f446c18816bf9beChris Craik    /**
54653e51e4aa933f9603587e1780f446c18816bf9beChris Craik     * Draws the content in layer to the screen.
5475b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy     */
54853e51e4aa933f9603587e1780f446c18816bf9beChris Craik    void composeLayerRect(Layer* layer, const Rect& rect);
5495b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy
55054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
55154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Clears all the regions corresponding to the current list of layers.
55254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method MUST be invoked before any drawing operation.
55354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
55454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    void clearLayerRegions();
55554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
55654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
557f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates. The coordinates
558f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * are transformed with the supplied matrix.
559f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
560f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
561083e733e8223a7d416d6c139f318e61864b28ad6Chris Craik            const float right, const float bottom, const Matrix4& transform);
562f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
563f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
564f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     * Mark the layer as dirty at the specified coordinates.
565f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy     */
566f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    void dirtyLayer(const float left, const float top,
567f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy            const float right, const float bottom);
568f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy
569f219da5e32e85deb442468ee9a63bb28eb198557Romain Guy    /**
5705cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * Draws a colored rectangle with the specified color. The specified coordinates
571735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * are transformed by the current snapshot's transform matrix unless specified
572735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * otherwise.
5735cbbce535744b89df5ecea95de21ee3733298260Romain Guy     *
5745cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param left The left coordinate of the rectangle
5755cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param top The top coordinate of the rectangle
5765cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param right The right coordinate of the rectangle
5775cbbce535744b89df5ecea95de21ee3733298260Romain Guy     * @param bottom The bottom coordinate of the rectangle
57876d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * @param paint The paint containing the color, blending mode, etc.
5793d58c03de0d8877b36cdb78b0ca8b5cac7f600e2Romain Guy     * @param ignoreTransform True if the current transform should be ignored
5805cbbce535744b89df5ecea95de21ee3733298260Romain Guy     */
581026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void drawColorRect(float left, float top, float right, float bottom,
58276d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const SkPaint* paint, bool ignoreTransform = false);
5835cbbce535744b89df5ecea95de21ee3733298260Romain Guy
58454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
585735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * Draws a series of colored rectangles with the specified color. The specified
586735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * coordinates are transformed by the current snapshot's transform matrix unless
587735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * specified otherwise.
588735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *
589735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param rects A list of rectangles, 4 floats (left, top, right, bottom)
590735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     *              per rectangle
59176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger     * @param paint The paint containing the color, blending mode, etc.
592735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     * @param ignoreTransform True if the current transform should be ignored
5938ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * @param dirty True if calling this method should dirty the current layer
5943bbacf27c0be1bae4e4483577fc89ae3113abe5dRomain Guy     * @param clip True if the rects should be clipped, false otherwise
595735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy     */
596107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawColorRects(const float* rects, int count, const SkPaint* paint,
59776d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            bool ignoreTransform = false, bool dirty = true, bool clip = true);
598735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
599735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    /**
60054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws the shape represented by the specified path texture.
60154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * This method invokes drawPathTexture() but takes into account
60254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * the extra left/top offset and the texture offset to correctly
60354be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * position the final shape.
60454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
60554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param left The left coordinate of the shape to render
60654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param top The top coordinate of the shape to render
60754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture reprsenting the shape
60854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the shape with
60954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
61030036092b40badecbe64d9c2bff4850132147f78Chris Craik    void drawShape(float left, float top, PathTexture* texture, const SkPaint* paint);
61154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy
61254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
61365cd612face362d054a85d0f7e5881c59cd523beChris Craik     * Renders a strip of polygons with the specified paint, used for tessellated geometry.
61465cd612face362d054a85d0f7e5881c59cd523beChris Craik     *
61565cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param vertexBuffer The VertexBuffer to be drawn
61665cd612face362d054a85d0f7e5881c59cd523beChris Craik     * @param paint The paint to render with
617bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik     * @param flags flags with which to draw
61865cd612face362d054a85d0f7e5881c59cd523beChris Craik     */
619107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawVertexBuffer(float translateX, float translateY, const VertexBuffer& vertexBuffer,
620bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik            const SkPaint* paint, int flags = 0);
62165cd612face362d054a85d0f7e5881c59cd523beChris Craik
62265cd612face362d054a85d0f7e5881c59cd523beChris Craik    /**
62305f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik     * Convenience for translating method
62405f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik     */
625107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawVertexBuffer(const VertexBuffer& vertexBuffer,
626bf75945e7a1ae7c1000682716643c942c1e19ba6Chris Craik            const SkPaint* paint, int flags = 0) {
627107843de4507b3511006cb9c77b8d0364374385aTom Hudson        drawVertexBuffer(0.0f, 0.0f, vertexBuffer, paint, flags);
62805f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    }
62905f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik
63005f3d6e5111fd08df5cd9aae2c3d28399dc0e7f5Chris Craik    /**
631710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * Renders the convex hull defined by the specified path as a strip of polygons.
63254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
633710f46d9d6a5bf9ea1c1833384caf61e1934124fChris Craik     * @param path The hull of the path to draw
634cb4d6009576cf08195dc23f341a3f4939c0878bbChris Craik     * @param paint The paint to render with
63554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
636107843de4507b3511006cb9c77b8d0364374385aTom Hudson    void drawConvexPath(const SkPath& path, const SkPaint* paint);
637858aa93ddb6e69e0503382af63bb681b6728aef1Chet Haase
638416a847633680d94efb926837efdc18726d54918Raph Levien   /**
639416a847633680d94efb926837efdc18726d54918Raph Levien     * Draws shadow layer on text (with optional positions).
640416a847633680d94efb926837efdc18726d54918Raph Levien     *
641416a847633680d94efb926837efdc18726d54918Raph Levien     * @param paint The paint to draw the shadow with
642416a847633680d94efb926837efdc18726d54918Raph Levien     * @param text The text to draw
643416a847633680d94efb926837efdc18726d54918Raph Levien     * @param count The number of glyphs in the text
644416a847633680d94efb926837efdc18726d54918Raph Levien     * @param positions The x, y positions of individual glyphs (or NULL)
645416a847633680d94efb926837efdc18726d54918Raph Levien     * @param fontRenderer The font renderer object
646416a847633680d94efb926837efdc18726d54918Raph Levien     * @param alpha The alpha value for drawing the shadow
647416a847633680d94efb926837efdc18726d54918Raph Levien     * @param x The x coordinate where the shadow will be drawn
648416a847633680d94efb926837efdc18726d54918Raph Levien     * @param y The y coordinate where the shadow will be drawn
649416a847633680d94efb926837efdc18726d54918Raph Levien     */
650e8c3c813b0e3ac98304b17a751ce6e436e252bd9Chris Craik    void drawTextShadow(const SkPaint* paint, const glyph_t* glyphs, int count,
65176d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger            const float* positions, FontRenderer& fontRenderer, int alpha,
652416a847633680d94efb926837efdc18726d54918Raph Levien            float x, float y);
653416a847633680d94efb926837efdc18726d54918Raph Levien
65454be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy    /**
65554be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * Draws a path texture. Path textures are alpha8 bitmaps that need special
65654be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * compositing to apply colors/filters/etc.
65754be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     *
65854be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param texture The texture to render
65954be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param x The x coordinate where the texture will be drawn
66054be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param y The y coordinate where the texture will be drawn
66154be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     * @param paint The paint to draw the texture with
66254be1cdf3d63095512120fa7ced5c16e462abffaRomain Guy     */
66330036092b40badecbe64d9c2bff4850132147f78Chris Craik     void drawPathTexture(PathTexture* texture, float x, float y, const SkPaint* paint);
66401d58e43ede5ca98cbebdd166f9b0c545032c01bRomain Guy
6651e45aae5de003657e5d18f74d34998f5de5db5b7Romain Guy    /**
666ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy     * Resets the texture coordinates stored in mMeshVertices. Setting the values
667026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * back to default is achieved by calling:
668026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
6698ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy     * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f);
670026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     *
671026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u1 The left coordinate of the texture
672026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v1 The bottom coordinate of the texture
673026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param u2 The right coordinate of the texture
674026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     * @param v2 The top coordinate of the texture
675026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy     */
676026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy    void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2);
677026c5e16704e817cac7d9c382914c947e34f87e0Romain Guy
6788ba548f81d1ab5f1750cbf86098c4a14e0b8beadRomain Guy    /**
679768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     * Returns true if the specified paint will draw invisible text.
680768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy     */
681768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy    bool canSkipText(const SkPaint* paint) const;
682768bffc9b814f6a1f7d9ff59d91285895c23bbe9Romain Guy
68311cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    bool updateLayer(Layer* layer, bool inFrame);
68411cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy    void updateLayers();
68596885eb480c5e0526fe2f77d30f6e551f3f3ceabRomain Guy    void flushLayers();
68611cb642756093a4af901b1525375b1eb2b5c3e2bRomain Guy
687e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#if DEBUG_LAYERS_AS_REGIONS
68817112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy    /**
68917112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * Renders the specified region as a series of rectangles. This method
69017112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     * is used for debugging only.
69117112ad8a21a77620eb1ff14dcf8bdd6b7859712Romain Guy     */
692e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik    void drawRegionRectsDebug(const Region& region);
693e63f7c622a2086aefa80983c6f41b74fb166bb42Chris Craik#endif
6943a3133d876caf60ebff2176ad75c3dcf0259148dRomain Guy
6958ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
6968ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Renders the specified region as a series of rectangles. The region
6978ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * must be in screen-space coordinates.
6988ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
69976d3a1b8d035d27bc80b0f2fc480a903bd001514Derek Sollenberger    void drawRegionRects(const SkRegion& region, const SkPaint& paint, bool dirty = false);
7008ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
7018ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    /**
7028ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * Draws the current clip region if any. Only when DEBUG_CLIP_REGIONS
7038ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     * is turned on.
7048ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy     */
7058ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy    void debugClip();
7068ce00301a023eecaeb8891ce906f67b513ebb42aRomain Guy
7077c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void debugOverdraw(bool enable, bool clear);
7087c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy    void renderOverdraw();
70978dd96d5af20f489f0e8b288617d57774ec284f7Romain Guy    void countOverdraw();
7107c450aaa3caac2a05fcb20a177483d0e92378426Romain Guy
711746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy    /**
712746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     * Should be invoked every time the glScissor is modified.
713746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy     */
714984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    inline void dirtyClip() { mState.setDirtyClip(true); }
715746b7401ceb86b5f2805f8c0d3b39ac739152015Romain Guy
7163b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    inline const UvMapper& getMapper(const Texture* texture) {
7173b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy        return texture && texture->uvMapper ? *texture->uvMapper : mUvMapper;
7183b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    }
7193b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
7203b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    /**
7213b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * Returns a texture object for the specified bitmap. The texture can
722