blob: a9ac57dace30abf1645a075b510351c2478b088f [file] [log] [blame]
Romain Guy4aa90572010-09-26 18:40:37 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
18#define ANDROID_HWUI_DISPLAY_LIST_RENDERER_H
Romain Guy4aa90572010-09-26 18:40:37 -070019
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -040020#include <SkDrawFilter.h>
Romain Guy4aa90572010-09-26 18:40:37 -070021#include <SkMatrix.h>
22#include <SkPaint.h>
23#include <SkPath.h>
Tom Hudson2dc236b2014-10-15 15:46:42 -040024#include <SkRegion.h>
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -040025#include <SkTLazy.h>
Romain Guy79537452011-10-12 13:48:51 -070026#include <cutils/compiler.h>
27
John Reck849911a2015-01-20 07:51:14 -080028#include "Canvas.h"
Tom Hudson984162f2014-10-10 13:38:16 -040029#include "CanvasState.h"
Tom Hudson2dc236b2014-10-15 15:46:42 -040030#include "DisplayList.h"
Derek Sollenberger1db141f2014-12-16 08:37:20 -050031#include "SkiaCanvasProxy.h"
Tom Hudson984162f2014-10-10 13:38:16 -040032#include "RenderNode.h"
John Recka35778c72014-11-06 09:45:10 -080033#include "ResourceCache.h"
Romain Guy4aa90572010-09-26 18:40:37 -070034
35namespace android {
36namespace uirenderer {
37
38///////////////////////////////////////////////////////////////////////////////
39// Defines
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guyffac7fc2011-01-13 17:21:49 -080042// Debug
43#if DEBUG_DISPLAY_LIST
Steve Block5baa3a62011-12-20 16:23:08 +000044 #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyffac7fc2011-01-13 17:21:49 -080045#else
46 #define DISPLAY_LIST_LOGD(...)
47#endif
48
Romain Guy4aa90572010-09-26 18:40:37 -070049///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070050// Display list
Romain Guy4aa90572010-09-26 18:40:37 -070051///////////////////////////////////////////////////////////////////////////////
52
Chris Craikc3566d02013-02-04 16:16:33 -080053class DeferredDisplayList;
John Reck12f5e342014-11-07 07:53:43 -080054class DeferredLayerUpdater;
Chris Craik2af46352012-11-26 18:30:17 -080055class DisplayListOp;
56class DrawOp;
Tom Hudson2dc236b2014-10-15 15:46:42 -040057class RenderNode;
Chris Craik2af46352012-11-26 18:30:17 -080058class StateOp;
59
Romain Guyb051e892010-09-28 19:09:36 -070060/**
Chris Craikd6b65f62014-01-01 14:45:21 -080061 * Records drawing commands in a display list for later playback into an OpenGLRenderer.
Romain Guyb051e892010-09-28 19:09:36 -070062 */
Chris Craikdb663fe2015-04-20 13:34:45 -070063class ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient {
Romain Guyb051e892010-09-28 19:09:36 -070064public:
Chris Craikdb663fe2015-04-20 13:34:45 -070065 DisplayListCanvas();
66 virtual ~DisplayListCanvas();
Romain Guyb051e892010-09-28 19:09:36 -070067
Chris Craik8afd0f22014-08-21 17:41:57 -070068 void insertReorderBarrier(bool enableReorder);
69
John Reck3b202512014-06-23 13:13:08 -070070 DisplayListData* finishRecording();
Chet Haase5977baa2011-01-05 18:01:22 -080071
Chris Craik14e51302013-12-30 15:32:54 -080072// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050073// HWUI Frame state operations
Chris Craik14e51302013-12-30 15:32:54 -080074// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050075
76 void prepareDirty(float left, float top, float right, float bottom);
77 void prepare() { prepareDirty(0.0f, 0.0f, width(), height()); }
78 bool finish();
79 void interrupt();
80 void resume();
Chet Haasedaf98e92011-01-10 14:10:36 -080081
Chris Craik14e51302013-12-30 15:32:54 -080082// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050083// HWUI Canvas state operations
Chris Craik14e51302013-12-30 15:32:54 -080084// ----------------------------------------------------------------------------
Tom Hudson984162f2014-10-10 13:38:16 -040085
Tom Hudson8dfaa492014-12-09 15:03:44 -050086 void setViewport(int width, int height) { mState.setViewport(width, height); }
Romain Guy4aa90572010-09-26 18:40:37 -070087
Tom Hudson984162f2014-10-10 13:38:16 -040088 const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
Romain Guy5ff9df62012-01-23 17:09:05 -080089
John Reck3b202512014-06-23 13:13:08 -070090 bool isCurrentTransformSimple() {
Tom Hudson984162f2014-10-10 13:38:16 -040091 return mState.currentTransform()->isSimple();
John Reck3b202512014-06-23 13:13:08 -070092 }
93
Chris Craik14e51302013-12-30 15:32:54 -080094// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050095// HWUI Canvas draw operations
Chris Craik14e51302013-12-30 15:32:54 -080096// ----------------------------------------------------------------------------
Chris Craik14e51302013-12-30 15:32:54 -080097
98 // Bitmap-based
Tom Hudson8dfaa492014-12-09 15:03:44 -050099 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -0500100 // TODO: move drawPatch() to Canvas.h
John Reck1ff961d2015-04-17 20:45:15 +0000101 void drawPatch(const SkBitmap* bitmap, const Res_png_9patch* patch,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500102 float left, float top, float right, float bottom, const SkPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -0800103
104 // Shapes
Tom Hudson8dfaa492014-12-09 15:03:44 -0500105 void drawRects(const float* rects, int count, const SkPaint* paint);
106 void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
Jorim Jaggi072707d2014-09-15 17:20:08 +0200107 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
108 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
109 CanvasPropertyPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -0500110 void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
John Reck52244ff2014-05-01 21:27:37 -0700111 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -0800112
Chris Craik14e51302013-12-30 15:32:54 -0800113
114// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500115// HWUI Canvas draw operations - special
Chris Craik14e51302013-12-30 15:32:54 -0800116// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500117 void drawLayer(DeferredLayerUpdater* layerHandle, float x, float y);
118 void drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t replayFlags);
Chris Craik14e51302013-12-30 15:32:54 -0800119
120 // TODO: rename for consistency
Tom Hudson8dfaa492014-12-09 15:03:44 -0500121 void callDrawGLFunction(Functor* functor, Rect& dirty);
Chris Craik14e51302013-12-30 15:32:54 -0800122
Chris Craikcce47eb2014-07-16 15:12:15 -0700123 void setHighContrastText(bool highContrastText) {
124 mHighContrastText = highContrastText;
125 }
Tom Hudson984162f2014-10-10 13:38:16 -0400126
127// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500128// CanvasStateClient interface
Tom Hudson984162f2014-10-10 13:38:16 -0400129// ----------------------------------------------------------------------------
Chris Craike84a2082014-12-22 14:28:49 -0800130 virtual void onViewportInitialized() override { }
131 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
Chris Craik6b109c72015-02-27 10:55:28 -0800132 virtual GLuint getTargetFbo() const override { return -1; }
Tom Hudson984162f2014-10-10 13:38:16 -0400133
Tom Hudson8dfaa492014-12-09 15:03:44 -0500134// ----------------------------------------------------------------------------
135// android/graphics/Canvas interface
136// ----------------------------------------------------------------------------
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500137 virtual SkCanvas* asSkCanvas() override;
138
John Reck9d4efdf2015-04-17 20:45:40 +0000139 virtual void setBitmap(SkBitmap* bitmap, bool copyState) override {
Chris Craikdb663fe2015-04-20 13:34:45 -0700140 LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
Tom Hudson8dfaa492014-12-09 15:03:44 -0500141 }
142
Chris Craikd41c4d82015-01-05 15:51:13 -0800143 virtual bool isOpaque() override { return false; }
144 virtual int width() override { return mState.getWidth(); }
145 virtual int height() override { return mState.getHeight(); }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500146
147// ----------------------------------------------------------------------------
148// android/graphics/Canvas state operations
149// ----------------------------------------------------------------------------
150 // Save (layer)
Chris Craikd41c4d82015-01-05 15:51:13 -0800151 virtual int getSaveCount() const override { return mState.getSaveCount(); }
152 virtual int save(SkCanvas::SaveFlags flags) override;
153 virtual void restore() override;
154 virtual void restoreToCount(int saveCount) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500155
156 virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
Chris Craikd41c4d82015-01-05 15:51:13 -0800157 SkCanvas::SaveFlags flags) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500158 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800159 int alpha, SkCanvas::SaveFlags flags) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500160 SkPaint paint;
161 paint.setAlpha(alpha);
162 return saveLayer(left, top, right, bottom, &paint, flags);
163 }
164
165 // Matrix
Chris Craikd41c4d82015-01-05 15:51:13 -0800166 virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
167 virtual void setMatrix(const SkMatrix& matrix) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500168
Chris Craikd41c4d82015-01-05 15:51:13 -0800169 virtual void concat(const SkMatrix& matrix) override;
170 virtual void rotate(float degrees) override;
171 virtual void scale(float sx, float sy) override;
172 virtual void skew(float sx, float sy) override;
173 virtual void translate(float dx, float dy) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500174
175 // Clip
Chris Craikd41c4d82015-01-05 15:51:13 -0800176 virtual bool getClipBounds(SkRect* outRect) const override;
177 virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
178 virtual bool quickRejectPath(const SkPath& path) const override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500179
Chris Craikd41c4d82015-01-05 15:51:13 -0800180 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
181 virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
182 virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500183
184 // Misc
Chris Craikd41c4d82015-01-05 15:51:13 -0800185 virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
186 virtual void setDrawFilter(SkDrawFilter* filter) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500187
188// ----------------------------------------------------------------------------
189// android/graphics/Canvas draw operations
190// ----------------------------------------------------------------------------
Chris Craikd41c4d82015-01-05 15:51:13 -0800191 virtual void drawColor(int color, SkXfermode::Mode mode) override;
192 virtual void drawPaint(const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500193
194 // Geometry
Chris Craikd41c4d82015-01-05 15:51:13 -0800195 virtual void drawPoint(float x, float y, const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500196 float points[2] = { x, y };
197 drawPoints(points, 2, paint);
198 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800199 virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500200 virtual void drawLine(float startX, float startY, float stopX, float stopY,
Chris Craikd41c4d82015-01-05 15:51:13 -0800201 const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500202 float points[4] = { startX, startY, stopX, stopY };
203 drawLines(points, 4, paint);
204 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800205 virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
206 virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500207 virtual void drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800208 float rx, float ry, const SkPaint& paint) override;
209 virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
210 virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500211 virtual void drawArc(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800212 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
213 virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500214 virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
215 const float* verts, const float* tex, const int* colors,
Chris Craikd41c4d82015-01-05 15:51:13 -0800216 const uint16_t* indices, int indexCount, const SkPaint& paint) override
Chris Craikdb663fe2015-04-20 13:34:45 -0700217 { /* DisplayListCanvas does not support drawVertices(); ignore */ }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500218
219 // Bitmap-based
Chris Craikd41c4d82015-01-05 15:51:13 -0800220 virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500221 virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
Chris Craikd41c4d82015-01-05 15:51:13 -0800222 const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500223 virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
224 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800225 float dstRight, float dstBottom, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500226 virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
Chris Craikd41c4d82015-01-05 15:51:13 -0800227 const float* vertices, const int* colors, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500228
229 // Text
230 virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
231 const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800232 float boundsRight, float boundsBottom, float totalAdvance) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500233 virtual void drawPosText(const uint16_t* text, const float* positions, int count,
Chris Craikd41c4d82015-01-05 15:51:13 -0800234 int posCount, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500235 virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
Chris Craikd41c4d82015-01-05 15:51:13 -0800236 float hOffset, float vOffset, const SkPaint& paint) override;
237 virtual bool drawTextAbsolutePos() const override { return false; }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500238
239
Romain Guy4aa90572010-09-26 18:40:37 -0700240private:
Tom Hudson984162f2014-10-10 13:38:16 -0400241
242 CanvasState mState;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500243 std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
Tom Hudson984162f2014-10-10 13:38:16 -0400244
Chris Craik8afd0f22014-08-21 17:41:57 -0700245 enum DeferredBarrierType {
246 kBarrier_None,
247 kBarrier_InOrder,
248 kBarrier_OutOfOrder,
249 };
250
251 void flushRestoreToCount();
252 void flushTranslate();
253 void flushReorderBarrier();
Romain Guy27454a42011-01-23 12:01:41 -0800254
Chris Craik2af46352012-11-26 18:30:17 -0800255 LinearAllocator& alloc() { return mDisplayListData->allocator; }
Chris Craikb3cca872014-08-08 18:42:51 -0700256
257 // Each method returns final index of op
Chris Craik8afd0f22014-08-21 17:41:57 -0700258 size_t addOpAndUpdateChunk(DisplayListOp* op);
259 // flushes any deferred operations, and appends the op
260 size_t flushAndAddOp(DisplayListOp* op);
261
262 size_t addStateOp(StateOp* op);
263 size_t addDrawOp(DrawOp* op);
264 size_t addRenderNodeOp(DrawRenderNodeOp* op);
265
Romain Guy4aa90572010-09-26 18:40:37 -0700266
Chris Craik2af46352012-11-26 18:30:17 -0800267 template<class T>
Chris Craikd218a922014-01-02 17:13:34 -0800268 inline const T* refBuffer(const T* srcBuffer, int32_t count) {
Chris Craike84a2082014-12-22 14:28:49 -0800269 if (!srcBuffer) return nullptr;
Chris Craikd218a922014-01-02 17:13:34 -0800270
Chris Craik2af46352012-11-26 18:30:17 -0800271 T* dstBuffer = (T*) mDisplayListData->allocator.alloc(count * sizeof(T));
272 memcpy(dstBuffer, srcBuffer, count * sizeof(T));
273 return dstBuffer;
Romain Guy33f6beb2012-02-16 19:24:51 -0800274 }
275
Chris Craik2af46352012-11-26 18:30:17 -0800276 inline char* refText(const char* text, size_t byteLength) {
277 return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
Romain Guy33f6beb2012-02-16 19:24:51 -0800278 }
279
Chris Craikd218a922014-01-02 17:13:34 -0800280 inline const SkPath* refPath(const SkPath* path) {
Chris Craike84a2082014-12-22 14:28:49 -0800281 if (!path) return nullptr;
Romain Guy2fc941e2011-02-03 15:06:05 -0800282
Derek Sollenbergeree248592015-02-12 14:10:21 -0500283 // The points/verbs within the path are refcounted so this copy operation
284 // is inexpensive and maintains the generationID of the original path.
285 const SkPath* cachedPath = new SkPath(*path);
286 mDisplayListData->pathResources.add(cachedPath);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800287 return cachedPath;
Romain Guy4aa90572010-09-26 18:40:37 -0700288 }
289
Chris Craikd218a922014-01-02 17:13:34 -0800290 inline const SkPaint* refPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800291 if (!paint) return nullptr;
Romain Guy0fe478e2010-11-08 12:08:41 -0800292
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400293 // If there is a draw filter apply it here and store the modified paint
294 // so that we don't need to modify the paint every time we access it.
Chris Craikda3198a2014-11-21 22:05:46 +0000295 SkTLazy<SkPaint> filteredPaint;
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400296 if (mDrawFilter.get()) {
Derek Sollenberger0b860622015-03-25 10:08:30 -0400297 filteredPaint.set(*paint);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800298 mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
Derek Sollenberger0b860622015-03-25 10:08:30 -0400299 paint = filteredPaint.get();
Chet Haased98aa2d2010-10-25 15:47:32 -0700300 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800301
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400302 // compute the hash key for the paint and check the cache.
303 const uint32_t key = paint->getHash();
304 const SkPaint* cachedPaint = mPaintMap.valueFor(key);
305 // In the unlikely event that 2 unique paints have the same hash we do a
306 // object equality check to ensure we don't erroneously dedup them.
Chris Craike84a2082014-12-22 14:28:49 -0800307 if (cachedPaint == nullptr || *cachedPaint != *paint) {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800308 cachedPaint = new SkPaint(*paint);
309 std::unique_ptr<const SkPaint> copy(cachedPaint);
310 mDisplayListData->paints.push_back(std::move(copy));
311
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400312 // replaceValueFor() performs an add if the entry doesn't exist
313 mPaintMap.replaceValueFor(key, cachedPaint);
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400314 }
315
316 return cachedPaint;
Romain Guy0fe478e2010-11-08 12:08:41 -0800317 }
318
Chris Craikcce47eb2014-07-16 15:12:15 -0700319 inline SkPaint* copyPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800320 if (!paint) return nullptr;
Chris Craikcce47eb2014-07-16 15:12:15 -0700321
Chris Craik51d6a3d2014-12-22 17:16:56 -0800322 SkPaint* returnPaint = new SkPaint(*paint);
323 std::unique_ptr<const SkPaint> copy(returnPaint);
324 mDisplayListData->paints.push_back(std::move(copy));
325
326 return returnPaint;
Chris Craikcce47eb2014-07-16 15:12:15 -0700327 }
328
Chris Craikd218a922014-01-02 17:13:34 -0800329 inline const SkRegion* refRegion(const SkRegion* region) {
Romain Guy735738c2012-12-03 12:34:51 -0800330 if (!region) {
Romain Guy735738c2012-12-03 12:34:51 -0800331 return region;
332 }
333
Chris Craik51d6a3d2014-12-22 17:16:56 -0800334 const SkRegion* cachedRegion = mRegionMap.valueFor(region);
Romain Guy735738c2012-12-03 12:34:51 -0800335 // TODO: Add generation ID to SkRegion
Chris Craik51d6a3d2014-12-22 17:16:56 -0800336 if (cachedRegion == nullptr) {
337 std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
338 cachedRegion = copy.get();
339 mDisplayListData->regions.push_back(std::move(copy));
340
Romain Guy735738c2012-12-03 12:34:51 -0800341 // replaceValueFor() performs an add if the entry doesn't exist
Chris Craik51d6a3d2014-12-22 17:16:56 -0800342 mRegionMap.replaceValueFor(region, cachedRegion);
Romain Guy735738c2012-12-03 12:34:51 -0800343 }
344
Chris Craik51d6a3d2014-12-22 17:16:56 -0800345 return cachedRegion;
Romain Guy735738c2012-12-03 12:34:51 -0800346 }
347
John Reck1ff961d2015-04-17 20:45:15 +0000348 inline const SkBitmap* refBitmap(const SkBitmap* bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700349 // Note that this assumes the bitmap is immutable. There are cases this won't handle
350 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
351 // contents, and drawing again. The only fix would be to always copy it the first time,
352 // which doesn't seem worth the extra cycles for this unlikely case.
Derek Sollenberger3d4eed72014-12-04 15:20:29 -0500353 const SkBitmap* cachedBitmap = mResourceCache.insert(bitmap);
354 mDisplayListData->bitmapResources.add(cachedBitmap);
355 return cachedBitmap;
Romain Guy49c5fc02012-05-15 11:10:01 -0700356 }
357
Chris Craikd218a922014-01-02 17:13:34 -0800358 inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
John Reck44fd8d22014-02-26 11:00:11 -0800359 mDisplayListData->patchResources.add(patch);
John Recka35778c72014-11-06 09:45:10 -0800360 mResourceCache.incrementRefcount(patch);
Romain Guye3b0a012013-06-26 15:45:41 -0700361 return patch;
362 }
363
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400364 DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
Chris Craikd218a922014-01-02 17:13:34 -0800365 DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
Chris Craikd218a922014-01-02 17:13:34 -0800366 DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Romain Guy24c00212011-01-14 15:31:00 -0800367
John Recka35778c72014-11-06 09:45:10 -0800368 ResourceCache& mResourceCache;
John Reck44fd8d22014-02-26 11:00:11 -0800369 DisplayListData* mDisplayListData;
Romain Guy58ecc202012-09-07 11:58:36 -0700370
Romain Guy33f6beb2012-02-16 19:24:51 -0800371 float mTranslateX;
372 float mTranslateY;
Chris Craik8afd0f22014-08-21 17:41:57 -0700373 bool mHasDeferredTranslate;
374 DeferredBarrierType mDeferredBarrierType;
Chris Craikcce47eb2014-07-16 15:12:15 -0700375 bool mHighContrastText;
Romain Guy54c1a642012-09-27 17:55:46 -0700376
Chris Craikeea6ef92014-03-05 16:37:35 -0800377 int mRestoreSaveCount;
378
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400379 SkAutoTUnref<SkDrawFilter> mDrawFilter;
380
John Recke18264b2014-03-12 13:56:30 -0700381 friend class RenderNode;
Romain Guyb051e892010-09-28 19:09:36 -0700382
Chris Craikdb663fe2015-04-20 13:34:45 -0700383}; // class DisplayListCanvas
Romain Guy4aa90572010-09-26 18:40:37 -0700384
385}; // namespace uirenderer
386}; // namespace android
387
Romain Guy5b3b3522010-10-27 18:57:51 -0700388#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H