14aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy/*
24aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * Copyright (C) 2010 The Android Open Source Project
34aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy *
44aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * Licensed under the Apache License, Version 2.0 (the "License");
54aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * you may not use this file except in compliance with the License.
64aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * You may obtain a copy of the License at
74aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy *
84aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy *      http://www.apache.org/licenses/LICENSE-2.0
94aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy *
104aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * Unless required by applicable law or agreed to in writing, software
114aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * distributed under the License is distributed on an "AS IS" BASIS,
124aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * See the License for the specific language governing permissions and
144aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * limitations under the License.
154aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy */
164aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
194aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
209fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "CanvasState.h"
219fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "DisplayList.h"
229fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "RenderNode.h"
239fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "ResourceCache.h"
249fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "SkiaCanvasProxy.h"
25dccca44ffda4836b56a21da95a046c9708ffd49csergeyv#include "hwui/Canvas.h"
269fded232a9548a304e0145011df8849fba0dcda7Chris Craik#include "utils/Macros.h"
279fded232a9548a304e0145011df8849fba0dcda7Chris Craik
2809c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger#include <SkDrawFilter.h>
294aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy#include <SkMatrix.h>
304aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy#include <SkPaint.h>
314aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy#include <SkPath.h>
322dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudson#include <SkRegion.h>
3309c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger#include <SkTLazy.h>
347953745dd565167113f8cbfc461bc0521d32d870Romain Guy#include <cutils/compiler.h>
357953745dd565167113f8cbfc461bc0521d32d870Romain Guy
364aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guynamespace android {
374aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guynamespace uirenderer {
384aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
394aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy///////////////////////////////////////////////////////////////////////////////
404aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy// Defines
414aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy///////////////////////////////////////////////////////////////////////////////
424aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
43ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy// Debug
44ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy#if DEBUG_DISPLAY_LIST
455baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
46ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy#else
47ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy    #define DISPLAY_LIST_LOGD(...)
48ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy#endif
49ffac7fc5042296a459d0f5a450dbfe20917093dcRomain Guy
504aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy///////////////////////////////////////////////////////////////////////////////
51b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy// Display list
524aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy///////////////////////////////////////////////////////////////////////////////
534aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
54c3566d06421c8acc0aafb18f7e307e5725ce87e1Chris Craikclass DeferredDisplayList;
5512f5e3433226f0a2886a98b0b8da8d5e947c5cdeJohn Reckclass DeferredLayerUpdater;
562af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craikclass DisplayListOp;
572af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craikclass DrawOp;
588d1f2120fe80b23ab03c7168e3b6b2d13bafe2e7Chris Craikclass DrawRenderNodeOp;
592dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudsonclass RenderNode;
602af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craikclass StateOp;
612af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik
62b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy/**
63d6b65f67717025b1162f86f04e2caa5723566cacChris Craik * Records drawing commands in a display list for later playback into an OpenGLRenderer.
64b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy */
65db663fe83f976107fd8fd9307d871b37d9e47370Chris Craikclass ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient {
66b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guypublic:
67cc882b6518129a11fa007f8c9343e972f03607b4Derek Sollenberger    DisplayListCanvas(int width, int height);
68db663fe83f976107fd8fd9307d871b37d9e47370Chris Craik    virtual ~DisplayListCanvas();
69b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
706f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void resetRecording(int width, int height) override;
716f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual WARN_UNUSED_RESULT DisplayList* finishRecording() override;
725977baa1fa24125c148a72699b53e62abaf08960Chet Haase
7314e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
748dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// HWUI Canvas state operations
7514e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
76984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
776f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void insertReorderBarrier(bool enableReorder) override;
784aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
7914e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
808dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// HWUI Canvas draw operations
8114e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
8214e513058ed4168c94e015638d16f5f87fd8063aChris Craik
8314e513058ed4168c94e015638d16f5f87fd8063aChris Craik    // Shapes
846f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
85072707dfad1da6f49f4d3ce58ca104f6c46a7266Jorim Jaggi                CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
86072707dfad1da6f49f4d3ce58ca104f6c46a7266Jorim Jaggi                CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
876f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger                CanvasPropertyPaint* paint) override;
886f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
896f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger                CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) override;
904aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
9114e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
928dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// HWUI Canvas draw operations - special
9314e513058ed4168c94e015638d16f5f87fd8063aChris Craik// ----------------------------------------------------------------------------
946f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawLayer(DeferredLayerUpdater* layerHandle) override;
956f485569fa3d6047dcffd068aebf361e3598783cDerek Sollenberger    virtual void drawRenderNode(RenderNode* renderNode) override;
96cd1c3eba69d044b551cededad75474038f919890John Reck    virtual void callDrawGLFunction(Functor* functor,
97cd1c3eba69d044b551cededad75474038f919890John Reck            GlFunctorLifecycleListener* listener) override;
985ff9df658230d49e42c43586997a02d8e4dd417eRomain Guy
99984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson// ----------------------------------------------------------------------------
1008dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// CanvasStateClient interface
101984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson// ----------------------------------------------------------------------------
102e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik    virtual void onViewportInitialized() override { }
103e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik    virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
1046b109c74982033d4a220cd10a0eab8b024b351c9Chris Craik    virtual GLuint getTargetFbo() const override { return -1; }
105984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
1068dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
1078dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// android/graphics/Canvas interface
1088dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
1091db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger    virtual SkCanvas* asSkCanvas() override;
1101db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger
111c1b33d665c8caf5760f68c45c6ca0baa649b832aJohn Reck    virtual void setBitmap(const SkBitmap& bitmap) override {
112db663fe83f976107fd8fd9307d871b37d9e47370Chris Craik        LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
1138dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    }
1148dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
115d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool isOpaque() override { return false; }
116d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual int width() override { return mState.getWidth(); }
117d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual int height() override { return mState.getHeight(); }
1188dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1196578a989566e585eee053095dc80e2552e125db2Derek Sollenberger    virtual void setHighContrastText(bool highContrastText) override {
1206578a989566e585eee053095dc80e2552e125db2Derek Sollenberger        mHighContrastText = highContrastText;
1216578a989566e585eee053095dc80e2552e125db2Derek Sollenberger    }
1226578a989566e585eee053095dc80e2552e125db2Derek Sollenberger    virtual bool isHighContrastText() override { return mHighContrastText; }
1236578a989566e585eee053095dc80e2552e125db2Derek Sollenberger
1248dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
1258dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// android/graphics/Canvas state operations
1268dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
1278dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Save (layer)
128d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual int getSaveCount() const override { return mState.getSaveCount(); }
129eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita    virtual int save(SaveFlags::Flags flags) override;
130d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void restore() override;
131d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void restoreToCount(int saveCount) override;
1328dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1338dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
134eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita        SaveFlags::Flags flags) override;
1358dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual int saveLayerAlpha(float left, float top, float right, float bottom,
136eecff56fed5dd5206acfbc5007b4912081b36d3bFlorin Malita            int alpha, SaveFlags::Flags flags) override {
1378dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        SkPaint paint;
1388dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        paint.setAlpha(alpha);
1398dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        return saveLayer(left, top, right, bottom, &paint, flags);
1408dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    }
1418dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1428dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Matrix
143d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
144d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void setMatrix(const SkMatrix& matrix) override;
1458dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
146d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void concat(const SkMatrix& matrix) override;
147d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void rotate(float degrees) override;
148d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void scale(float sx, float sy) override;
149d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void skew(float sx, float sy) override;
150d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void translate(float dx, float dy) override;
1518dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1528dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Clip
153d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool getClipBounds(SkRect* outRect) const override;
154d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
155d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool quickRejectPath(const SkPath& path) const override;
1568dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
157d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
158d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
159d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
1608dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1618dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Misc
162d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
163d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void setDrawFilter(SkDrawFilter* filter) override;
1648dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1658dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
1668dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// android/graphics/Canvas draw operations
1678dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson// ----------------------------------------------------------------------------
168d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawColor(int color, SkXfermode::Mode mode) override;
169d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawPaint(const SkPaint& paint) override;
1708dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1718dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Geometry
172d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawPoint(float x, float y, const SkPaint& paint) override {
1738dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        float points[2] = { x, y };
1748dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        drawPoints(points, 2, paint);
1758dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    }
176d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
1778dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawLine(float startX, float startY, float stopX, float stopY,
178d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            const SkPaint& paint) override {
1798dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        float points[4] = { startX, startY, stopX, stopY };
1808dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson        drawLines(points, 4, paint);
1818dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    }
182d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
183d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
18494394b3fb048d5349a77b57950ab7f6b6e92ce34Derek Sollenberger    virtual void drawRegion(const SkRegion& region, const SkPaint& paint) override;
1858dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawRoundRect(float left, float top, float right, float bottom,
186d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            float rx, float ry, const SkPaint& paint) override;
187d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
188d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
1898dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawArc(float left, float top, float right, float bottom,
190d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
191d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
1928dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
1938dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson            const float* verts, const float* tex, const int* colors,
194d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            const uint16_t* indices, int indexCount, const SkPaint& paint) override
195db663fe83f976107fd8fd9307d871b37d9e47370Chris Craik        { /* DisplayListCanvas does not support drawVertices(); ignore */ }
1968dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
1978dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Bitmap-based
198d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
1998dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
200d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik                            const SkPaint* paint) override;
2018dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
2028dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson            float srcRight, float srcBottom, float dstLeft, float dstTop,
203d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            float dstRight, float dstBottom, const SkPaint* paint) override;
2048dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
205d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            const float* vertices, const int* colors, const SkPaint* paint) override;
2064c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger    virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
2074c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger            float dstLeft, float dstTop, float dstRight, float dstBottom,
2084c5efe9290543b723b76a8bd48518da1ae1dcb26Derek Sollenberger            const SkPaint* paint) override;
2098dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
210766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu    virtual void drawVectorDrawable(VectorDrawableRoot* tree) override;
211766431aa57c16ece8842287a92b2e7208e3b8ac3Doris Liu
2128dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson    // Text
213dccca44ffda4836b56a21da95a046c9708ffd49csergeyv    virtual void drawGlyphs(const uint16_t* glyphs, const float* positions, int count,
2148dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson            const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
215d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            float boundsRight, float boundsBottom, float totalAdvance) override;
216dccca44ffda4836b56a21da95a046c9708ffd49csergeyv    virtual void drawGlyphsOnPath(const uint16_t* glyphs, int count, const SkPath& path,
217d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik            float hOffset, float vOffset, const SkPaint& paint) override;
218d41c4d8c732095ae99c955b6b82f7306633004b1Chris Craik    virtual bool drawTextAbsolutePos() const override { return false; }
2198dfaa4904205772cdceee63ef3989bcdedf1a914Tom Hudson
2204aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guyprivate:
221984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
222984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson    CanvasState mState;
2231db141f93c4fe79a4669440c3d14f63bc87b2e34Derek Sollenberger    std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
224984162fb7e4010b6e2908352dbff17ed47eecf06Tom Hudson
2258afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    enum DeferredBarrierType {
2268afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik        kBarrier_None,
2278afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik        kBarrier_InOrder,
2288afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik        kBarrier_OutOfOrder,
2298afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    };
2308afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik
23194394b3fb048d5349a77b57950ab7f6b6e92ce34Derek Sollenberger    void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
23294394b3fb048d5349a77b57950ab7f6b6e92ce34Derek Sollenberger    void drawRects(const float* rects, int count, const SkPaint* paint);
23394394b3fb048d5349a77b57950ab7f6b6e92ce34Derek Sollenberger
2348afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    void flushRestoreToCount();
2358afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    void flushTranslate();
2368afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    void flushReorderBarrier();
2374aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
238003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik    LinearAllocator& alloc() { return mDisplayList->allocator; }
239b3cca876c2e11b865cb4f83abe2c48a60b95af5bChris Craik
240b3cca876c2e11b865cb4f83abe2c48a60b95af5bChris Craik    // Each method returns final index of op
2418afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    size_t addOpAndUpdateChunk(DisplayListOp* op);
2428afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    // flushes any deferred operations, and appends the op
2438afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    size_t flushAndAddOp(DisplayListOp* op);
2448afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik
2458afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    size_t addStateOp(StateOp* op);
2468afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    size_t addDrawOp(DrawOp* op);
2478afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    size_t addRenderNodeOp(DrawRenderNodeOp* op);
2488afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik
24937b0824a46157b7e169ad7ec33a46e89c851884cJohn Reck    void refBitmapsInShader(const SkShader* shader);
2504aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
2512af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik    template<class T>
252d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline const T* refBuffer(const T* srcBuffer, int32_t count) {
253e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik        if (!srcBuffer) return nullptr;
254d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik
2557df9ff2a08fd4bbd9b2e734a357cffcf64675df9John Reck        T* dstBuffer = (T*) mDisplayList->allocator.alloc<T>(count * sizeof(T));
2562af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        memcpy(dstBuffer, srcBuffer, count * sizeof(T));
2572af4635e4a9e448a65ff541252f8f94bc6ac48e0Chris Craik        return dstBuffer;
2584aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    }
2594aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
260d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline const SkPath* refPath(const SkPath* path) {
261e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik        if (!path) return nullptr;
2622fc941e4650d618ff6e122f28b616d9032ffa134Romain Guy
263ee248599d49a15fc207c5aeb0b90ec263cc1d600Derek Sollenberger        // The points/verbs within the path are refcounted so this copy operation
264ee248599d49a15fc207c5aeb0b90ec263cc1d600Derek Sollenberger        // is inexpensive and maintains the generationID of the original path.
265ee248599d49a15fc207c5aeb0b90ec263cc1d600Derek Sollenberger        const SkPath* cachedPath = new SkPath(*path);
266003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik        mDisplayList->pathResources.push_back(cachedPath);
26751d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        return cachedPath;
2684aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy    }
2694aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
270d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline const SkPaint* refPaint(const SkPaint* paint) {
271e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik        if (!paint) return nullptr;
2720fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guy
27309c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        // If there is a draw filter apply it here and store the modified paint
27409c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        // so that we don't need to modify the paint every time we access it.
275da3198a550bdd91ccdc8a09c3a6e00d3b61c0c20Chris Craik        SkTLazy<SkPaint> filteredPaint;
27609c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        if (mDrawFilter.get()) {
2770b8606266c1afc69cbeb73acda67c85d87943318Derek Sollenberger            filteredPaint.set(*paint);
27851d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
2790b8606266c1afc69cbeb73acda67c85d87943318Derek Sollenberger            paint = filteredPaint.get();
28009c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        }
28109c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger
28209c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        // compute the hash key for the paint and check the cache.
28309c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        const uint32_t key = paint->getHash();
28409c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        const SkPaint* cachedPaint = mPaintMap.valueFor(key);
28509c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        // In the unlikely event that 2 unique paints have the same hash we do a
28609c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        // object equality check to ensure we don't erroneously dedup them.
287e84a208317e0ed388fcdad1e6743c7849acb51b0Chris Craik        if (cachedPaint == nullptr || *cachedPaint != *paint) {
28851d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            cachedPaint = new SkPaint(*paint);
28951d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            std::unique_ptr<const SkPaint> copy(cachedPaint);
290003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik            mDisplayList->paints.push_back(std::move(copy));
29151d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik
29296ebc6b5097ab73eef45e094241e444f4c21bfccRomain Guy            // replaceValueFor() performs an add if the entry doesn't exist
29309c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger            mPaintMap.replaceValueFor(key, cachedPaint);
29437b0824a46157b7e169ad7ec33a46e89c851884cJohn Reck            refBitmapsInShader(cachedPaint->getShader());
295d98aa2de9ab18e09c2be1997f41212740f51f6e6Chet Haase        }
2960fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guy
29709c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger        return cachedPaint;
2980fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guy    }
2990fe478ea04720a57ef3919dbc23711bc7eba517fRomain Guy
300d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline const SkRegion* refRegion(const SkRegion* region) {
301735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy        if (!region) {
302735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy            return region;
303735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy        }
304735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
30551d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        const SkRegion* cachedRegion = mRegionMap.valueFor(region);
306735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy        // TODO: Add generation ID to SkRegion
30751d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        if (cachedRegion == nullptr) {
30851d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
30951d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            cachedRegion = copy.get();
310003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik            mDisplayList->regions.push_back(std::move(copy));
31151d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik
312735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy            // replaceValueFor() performs an add if the entry doesn't exist
31351d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik            mRegionMap.replaceValueFor(region, cachedRegion);
314735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy        }
315735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
31651d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik        return cachedRegion;
317735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy    }
318735738c4ddf3229caa5f6e634bf591953ac29944Romain Guy
3197c103a36f60b690e3fe83c40210e1cb0c76bba43John Reck    inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
320d98aa2de9ab18e09c2be1997f41212740f51f6e6Chet Haase        // Note that this assumes the bitmap is immutable. There are cases this won't handle
321d98aa2de9ab18e09c2be1997f41212740f51f6e6Chet Haase        // correctly, such as creating the bitmap from scratch, drawing with it, changing its
322d98aa2de9ab18e09c2be1997f41212740f51f6e6Chet Haase        // contents, and drawing again. The only fix would be to always copy it the first time,
323d98aa2de9ab18e09c2be1997f41212740f51f6e6Chet Haase        // which doesn't seem worth the extra cycles for this unlikely case.
3247df9ff2a08fd4bbd9b2e734a357cffcf64675df9John Reck        SkBitmap* localBitmap = alloc().create<SkBitmap>(bitmap);
325003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik        mDisplayList->bitmapResources.push_back(localBitmap);
326e75ab4c26a4f661334845f7bc4132011694836a4John Reck        return localBitmap;
32749c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy    }
32849c5fc0b9e850497233e189ff9dcc71a78ebe6e7Romain Guy
329d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
330003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik        mDisplayList->patchResources.push_back(patch);
331a35778c799e8073a42b9e22191bde9d838327ab7John Reck        mResourceCache.incrementRefcount(patch);
332e3b0a0117a2ab4118f868a731b238fe8f2430276Romain Guy        return patch;
333e3b0a0117a2ab4118f868a731b238fe8f2430276Romain Guy    }
334e3b0a0117a2ab4118f868a731b238fe8f2430276Romain Guy
33509c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger    DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
336d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
337d218a92c0afb8c0d98135b20b52ac87236e1c935Chris Craik    DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
33824c00216687ac87fe531dc4d4168ac0c0ca04ea6Romain Guy
339a35778c799e8073a42b9e22191bde9d838327ab7John Reck    ResourceCache& mResourceCache;
340003cc3dec8e2a92e51086fbcd5ee1bb236efa701Chris Craik    DisplayList* mDisplayList;
34158ecc204fbcacef34806290492384677a330d4d4Romain Guy
34233f6beb10f98e8ba96250e284876d607055d278dRomain Guy    float mTranslateX;
34333f6beb10f98e8ba96250e284876d607055d278dRomain Guy    float mTranslateY;
3448afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    bool mHasDeferredTranslate;
3458afd0f245cc0c4a0366f39f41b5f78e47ee83be3Chris Craik    DeferredBarrierType mDeferredBarrierType;
346cce47eb580d666ead1f6095d1e3b65233592bbaaChris Craik    bool mHighContrastText;
34754c1a64d5441a964890b44280e4457e11f4f924aRomain Guy
348eea6ef9c767c734797912022113191dd255c4ae6Chris Craik    int mRestoreSaveCount;
349eea6ef9c767c734797912022113191dd255c4ae6Chris Craik
35009c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger    SkAutoTUnref<SkDrawFilter> mDrawFilter;
35109c2d4fe15fbac2faf8a97ba2cc59132ee12222aDerek Sollenberger
352e18264b079481a244b30e3f71012c53bbd861f92John Reck    friend class RenderNode;
353b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy
354db663fe83f976107fd8fd9307d871b37d9e47370Chris Craik}; // class DisplayListCanvas
3554aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
3564aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy}; // namespace uirenderer
3574aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy}; // namespace android
3584aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy
3595b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
360