blob: 44cf546244b3a77a1760cc77b5ae2136e76e26b4 [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;
Romain Guyb051e892010-09-28 19:09:36 -070055class DisplayListRenderer;
Chris Craik2af46352012-11-26 18:30:17 -080056class DisplayListOp;
Tom Hudson2dc236b2014-10-15 15:46:42 -040057class DisplayListRenderer;
Chris Craik2af46352012-11-26 18:30:17 -080058class DrawOp;
Tom Hudson2dc236b2014-10-15 15:46:42 -040059class RenderNode;
Chris Craik2af46352012-11-26 18:30:17 -080060class StateOp;
61
Romain Guyb051e892010-09-28 19:09:36 -070062/**
Chris Craikd6b65f62014-01-01 14:45:21 -080063 * Records drawing commands in a display list for later playback into an OpenGLRenderer.
Romain Guyb051e892010-09-28 19:09:36 -070064 */
Tom Hudson8dfaa492014-12-09 15:03:44 -050065class ANDROID_API DisplayListRenderer: public Canvas, public CanvasStateClient {
Romain Guyb051e892010-09-28 19:09:36 -070066public:
John Reck3b202512014-06-23 13:13:08 -070067 DisplayListRenderer();
Romain Guy79537452011-10-12 13:48:51 -070068 virtual ~DisplayListRenderer();
Romain Guyb051e892010-09-28 19:09:36 -070069
Chris Craik8afd0f22014-08-21 17:41:57 -070070 void insertReorderBarrier(bool enableReorder);
71
John Reck3b202512014-06-23 13:13:08 -070072 DisplayListData* finishRecording();
Chet Haase5977baa2011-01-05 18:01:22 -080073
Chris Craik14e51302013-12-30 15:32:54 -080074// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050075// HWUI Frame state operations
Chris Craik14e51302013-12-30 15:32:54 -080076// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050077
78 void prepareDirty(float left, float top, float right, float bottom);
79 void prepare() { prepareDirty(0.0f, 0.0f, width(), height()); }
80 bool finish();
81 void interrupt();
82 void resume();
Chet Haasedaf98e92011-01-10 14:10:36 -080083
Chris Craik14e51302013-12-30 15:32:54 -080084// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050085// HWUI Canvas state operations
Chris Craik14e51302013-12-30 15:32:54 -080086// ----------------------------------------------------------------------------
Tom Hudson984162f2014-10-10 13:38:16 -040087
Tom Hudson8dfaa492014-12-09 15:03:44 -050088 void setViewport(int width, int height) { mState.setViewport(width, height); }
Romain Guy4aa90572010-09-26 18:40:37 -070089
Tom Hudson984162f2014-10-10 13:38:16 -040090 const Rect& getRenderTargetClipBounds() const { return mState.getRenderTargetClipBounds(); }
Romain Guy5ff9df62012-01-23 17:09:05 -080091
John Reck3b202512014-06-23 13:13:08 -070092 bool isCurrentTransformSimple() {
Tom Hudson984162f2014-10-10 13:38:16 -040093 return mState.currentTransform()->isSimple();
John Reck3b202512014-06-23 13:13:08 -070094 }
95
Chris Craik14e51302013-12-30 15:32:54 -080096// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050097// HWUI Canvas draw operations
Chris Craik14e51302013-12-30 15:32:54 -080098// ----------------------------------------------------------------------------
Chris Craik14e51302013-12-30 15:32:54 -080099
100 // Bitmap-based
Tom Hudson8dfaa492014-12-09 15:03:44 -0500101 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -0500102 // TODO: move drawPatch() to Canvas.h
John Reck4bd981e2015-04-15 15:52:10 -0700103 void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
Tom Hudson8dfaa492014-12-09 15:03:44 -0500104 float left, float top, float right, float bottom, const SkPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -0800105
106 // Shapes
Tom Hudson8dfaa492014-12-09 15:03:44 -0500107 void drawRects(const float* rects, int count, const SkPaint* paint);
108 void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
Jorim Jaggi072707d2014-09-15 17:20:08 +0200109 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
110 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
111 CanvasPropertyPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -0500112 void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
John Reck52244ff2014-05-01 21:27:37 -0700113 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -0800114
Chris Craik14e51302013-12-30 15:32:54 -0800115
116// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500117// HWUI Canvas draw operations - special
Chris Craik14e51302013-12-30 15:32:54 -0800118// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500119 void drawLayer(DeferredLayerUpdater* layerHandle, float x, float y);
120 void drawRenderNode(RenderNode* renderNode, Rect& dirty, int32_t replayFlags);
Chris Craik14e51302013-12-30 15:32:54 -0800121
122 // TODO: rename for consistency
Tom Hudson8dfaa492014-12-09 15:03:44 -0500123 void callDrawGLFunction(Functor* functor, Rect& dirty);
Chris Craik14e51302013-12-30 15:32:54 -0800124
Chris Craikcce47eb2014-07-16 15:12:15 -0700125 void setHighContrastText(bool highContrastText) {
126 mHighContrastText = highContrastText;
127 }
Tom Hudson984162f2014-10-10 13:38:16 -0400128
129// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500130// CanvasStateClient interface
Tom Hudson984162f2014-10-10 13:38:16 -0400131// ----------------------------------------------------------------------------
Chris Craike84a2082014-12-22 14:28:49 -0800132 virtual void onViewportInitialized() override { }
133 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
Chris Craik6b109c72015-02-27 10:55:28 -0800134 virtual GLuint getTargetFbo() const override { return -1; }
Tom Hudson984162f2014-10-10 13:38:16 -0400135
Tom Hudson8dfaa492014-12-09 15:03:44 -0500136// ----------------------------------------------------------------------------
137// android/graphics/Canvas interface
138// ----------------------------------------------------------------------------
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500139 virtual SkCanvas* asSkCanvas() override;
140
John Reckc294d122015-04-13 15:20:29 -0700141 virtual void setBitmap(const SkBitmap& bitmap) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500142 LOG_ALWAYS_FATAL("DisplayListRenderer is not backed by a bitmap.");
143 }
144
Chris Craikd41c4d82015-01-05 15:51:13 -0800145 virtual bool isOpaque() override { return false; }
146 virtual int width() override { return mState.getWidth(); }
147 virtual int height() override { return mState.getHeight(); }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500148
149// ----------------------------------------------------------------------------
150// android/graphics/Canvas state operations
151// ----------------------------------------------------------------------------
152 // Save (layer)
Chris Craikd41c4d82015-01-05 15:51:13 -0800153 virtual int getSaveCount() const override { return mState.getSaveCount(); }
154 virtual int save(SkCanvas::SaveFlags flags) override;
155 virtual void restore() override;
156 virtual void restoreToCount(int saveCount) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500157
158 virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
Chris Craikd41c4d82015-01-05 15:51:13 -0800159 SkCanvas::SaveFlags flags) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500160 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800161 int alpha, SkCanvas::SaveFlags flags) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500162 SkPaint paint;
163 paint.setAlpha(alpha);
164 return saveLayer(left, top, right, bottom, &paint, flags);
165 }
166
167 // Matrix
Chris Craikd41c4d82015-01-05 15:51:13 -0800168 virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
169 virtual void setMatrix(const SkMatrix& matrix) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500170
Chris Craikd41c4d82015-01-05 15:51:13 -0800171 virtual void concat(const SkMatrix& matrix) override;
172 virtual void rotate(float degrees) override;
173 virtual void scale(float sx, float sy) override;
174 virtual void skew(float sx, float sy) override;
175 virtual void translate(float dx, float dy) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500176
177 // Clip
Chris Craikd41c4d82015-01-05 15:51:13 -0800178 virtual bool getClipBounds(SkRect* outRect) const override;
179 virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
180 virtual bool quickRejectPath(const SkPath& path) const override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500181
Chris Craikd41c4d82015-01-05 15:51:13 -0800182 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
183 virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
184 virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500185
186 // Misc
Chris Craikd41c4d82015-01-05 15:51:13 -0800187 virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
188 virtual void setDrawFilter(SkDrawFilter* filter) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500189
190// ----------------------------------------------------------------------------
191// android/graphics/Canvas draw operations
192// ----------------------------------------------------------------------------
Chris Craikd41c4d82015-01-05 15:51:13 -0800193 virtual void drawColor(int color, SkXfermode::Mode mode) override;
194 virtual void drawPaint(const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500195
196 // Geometry
Chris Craikd41c4d82015-01-05 15:51:13 -0800197 virtual void drawPoint(float x, float y, const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500198 float points[2] = { x, y };
199 drawPoints(points, 2, paint);
200 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800201 virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500202 virtual void drawLine(float startX, float startY, float stopX, float stopY,
Chris Craikd41c4d82015-01-05 15:51:13 -0800203 const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500204 float points[4] = { startX, startY, stopX, stopY };
205 drawLines(points, 4, paint);
206 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800207 virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
208 virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500209 virtual void drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800210 float rx, float ry, const SkPaint& paint) override;
211 virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
212 virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500213 virtual void drawArc(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800214 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
215 virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500216 virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
217 const float* verts, const float* tex, const int* colors,
Chris Craikd41c4d82015-01-05 15:51:13 -0800218 const uint16_t* indices, int indexCount, const SkPaint& paint) override
Tom Hudsonb1476ae2015-03-05 10:30:18 -0500219 { /* DisplayListRenderer does not support drawVertices(); ignore */ }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500220
221 // Bitmap-based
Chris Craikd41c4d82015-01-05 15:51:13 -0800222 virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500223 virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
Chris Craikd41c4d82015-01-05 15:51:13 -0800224 const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500225 virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
226 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800227 float dstRight, float dstBottom, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500228 virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
Chris Craikd41c4d82015-01-05 15:51:13 -0800229 const float* vertices, const int* colors, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500230
231 // Text
232 virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
233 const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800234 float boundsRight, float boundsBottom, float totalAdvance) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500235 virtual void drawPosText(const uint16_t* text, const float* positions, int count,
Chris Craikd41c4d82015-01-05 15:51:13 -0800236 int posCount, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500237 virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
Chris Craikd41c4d82015-01-05 15:51:13 -0800238 float hOffset, float vOffset, const SkPaint& paint) override;
239 virtual bool drawTextAbsolutePos() const override { return false; }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500240
241
Romain Guy4aa90572010-09-26 18:40:37 -0700242private:
Tom Hudson984162f2014-10-10 13:38:16 -0400243
244 CanvasState mState;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500245 std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
Tom Hudson984162f2014-10-10 13:38:16 -0400246
Chris Craik8afd0f22014-08-21 17:41:57 -0700247 enum DeferredBarrierType {
248 kBarrier_None,
249 kBarrier_InOrder,
250 kBarrier_OutOfOrder,
251 };
252
253 void flushRestoreToCount();
254 void flushTranslate();
255 void flushReorderBarrier();
Romain Guy27454a42011-01-23 12:01:41 -0800256
Chris Craik2af46352012-11-26 18:30:17 -0800257 LinearAllocator& alloc() { return mDisplayListData->allocator; }
Chris Craikb3cca872014-08-08 18:42:51 -0700258
259 // Each method returns final index of op
Chris Craik8afd0f22014-08-21 17:41:57 -0700260 size_t addOpAndUpdateChunk(DisplayListOp* op);
261 // flushes any deferred operations, and appends the op
262 size_t flushAndAddOp(DisplayListOp* op);
263
264 size_t addStateOp(StateOp* op);
265 size_t addDrawOp(DrawOp* op);
266 size_t addRenderNodeOp(DrawRenderNodeOp* op);
267
Romain Guy4aa90572010-09-26 18:40:37 -0700268
Chris Craik2af46352012-11-26 18:30:17 -0800269 template<class T>
Chris Craikd218a922014-01-02 17:13:34 -0800270 inline const T* refBuffer(const T* srcBuffer, int32_t count) {
Chris Craike84a2082014-12-22 14:28:49 -0800271 if (!srcBuffer) return nullptr;
Chris Craikd218a922014-01-02 17:13:34 -0800272
Chris Craik2af46352012-11-26 18:30:17 -0800273 T* dstBuffer = (T*) mDisplayListData->allocator.alloc(count * sizeof(T));
274 memcpy(dstBuffer, srcBuffer, count * sizeof(T));
275 return dstBuffer;
Romain Guy33f6beb2012-02-16 19:24:51 -0800276 }
277
Chris Craik2af46352012-11-26 18:30:17 -0800278 inline char* refText(const char* text, size_t byteLength) {
279 return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
Romain Guy33f6beb2012-02-16 19:24:51 -0800280 }
281
Chris Craikd218a922014-01-02 17:13:34 -0800282 inline const SkPath* refPath(const SkPath* path) {
Chris Craike84a2082014-12-22 14:28:49 -0800283 if (!path) return nullptr;
Romain Guy2fc941e2011-02-03 15:06:05 -0800284
Derek Sollenbergeree248592015-02-12 14:10:21 -0500285 // The points/verbs within the path are refcounted so this copy operation
286 // is inexpensive and maintains the generationID of the original path.
287 const SkPath* cachedPath = new SkPath(*path);
288 mDisplayListData->pathResources.add(cachedPath);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800289 return cachedPath;
Romain Guy4aa90572010-09-26 18:40:37 -0700290 }
291
Chris Craikd218a922014-01-02 17:13:34 -0800292 inline const SkPaint* refPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800293 if (!paint) return nullptr;
Romain Guy0fe478e2010-11-08 12:08:41 -0800294
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400295 // If there is a draw filter apply it here and store the modified paint
296 // so that we don't need to modify the paint every time we access it.
Chris Craikda3198a2014-11-21 22:05:46 +0000297 SkTLazy<SkPaint> filteredPaint;
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400298 if (mDrawFilter.get()) {
Derek Sollenberger0b860622015-03-25 10:08:30 -0400299 filteredPaint.set(*paint);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800300 mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
Derek Sollenberger0b860622015-03-25 10:08:30 -0400301 paint = filteredPaint.get();
Chet Haased98aa2d2010-10-25 15:47:32 -0700302 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800303
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400304 // compute the hash key for the paint and check the cache.
305 const uint32_t key = paint->getHash();
306 const SkPaint* cachedPaint = mPaintMap.valueFor(key);
307 // In the unlikely event that 2 unique paints have the same hash we do a
308 // object equality check to ensure we don't erroneously dedup them.
Chris Craike84a2082014-12-22 14:28:49 -0800309 if (cachedPaint == nullptr || *cachedPaint != *paint) {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800310 cachedPaint = new SkPaint(*paint);
311 std::unique_ptr<const SkPaint> copy(cachedPaint);
312 mDisplayListData->paints.push_back(std::move(copy));
313
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400314 // replaceValueFor() performs an add if the entry doesn't exist
315 mPaintMap.replaceValueFor(key, cachedPaint);
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400316 }
317
318 return cachedPaint;
Romain Guy0fe478e2010-11-08 12:08:41 -0800319 }
320
Chris Craikcce47eb2014-07-16 15:12:15 -0700321 inline SkPaint* copyPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800322 if (!paint) return nullptr;
Chris Craikcce47eb2014-07-16 15:12:15 -0700323
Chris Craik51d6a3d2014-12-22 17:16:56 -0800324 SkPaint* returnPaint = new SkPaint(*paint);
325 std::unique_ptr<const SkPaint> copy(returnPaint);
326 mDisplayListData->paints.push_back(std::move(copy));
327
328 return returnPaint;
Chris Craikcce47eb2014-07-16 15:12:15 -0700329 }
330
Chris Craikd218a922014-01-02 17:13:34 -0800331 inline const SkRegion* refRegion(const SkRegion* region) {
Romain Guy735738c2012-12-03 12:34:51 -0800332 if (!region) {
Romain Guy735738c2012-12-03 12:34:51 -0800333 return region;
334 }
335
Chris Craik51d6a3d2014-12-22 17:16:56 -0800336 const SkRegion* cachedRegion = mRegionMap.valueFor(region);
Romain Guy735738c2012-12-03 12:34:51 -0800337 // TODO: Add generation ID to SkRegion
Chris Craik51d6a3d2014-12-22 17:16:56 -0800338 if (cachedRegion == nullptr) {
339 std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
340 cachedRegion = copy.get();
341 mDisplayListData->regions.push_back(std::move(copy));
342
Romain Guy735738c2012-12-03 12:34:51 -0800343 // replaceValueFor() performs an add if the entry doesn't exist
Chris Craik51d6a3d2014-12-22 17:16:56 -0800344 mRegionMap.replaceValueFor(region, cachedRegion);
Romain Guy735738c2012-12-03 12:34:51 -0800345 }
346
Chris Craik51d6a3d2014-12-22 17:16:56 -0800347 return cachedRegion;
Romain Guy735738c2012-12-03 12:34:51 -0800348 }
349
John Reck4bd981e2015-04-15 15:52:10 -0700350 inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700351 // Note that this assumes the bitmap is immutable. There are cases this won't handle
352 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
353 // contents, and drawing again. The only fix would be to always copy it the first time,
354 // which doesn't seem worth the extra cycles for this unlikely case.
Derek Sollenberger3d4eed72014-12-04 15:20:29 -0500355 const SkBitmap* cachedBitmap = mResourceCache.insert(bitmap);
356 mDisplayListData->bitmapResources.add(cachedBitmap);
357 return cachedBitmap;
Romain Guy49c5fc02012-05-15 11:10:01 -0700358 }
359
Chris Craikd218a922014-01-02 17:13:34 -0800360 inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
John Reck44fd8d22014-02-26 11:00:11 -0800361 mDisplayListData->patchResources.add(patch);
John Recka35778c72014-11-06 09:45:10 -0800362 mResourceCache.incrementRefcount(patch);
Romain Guye3b0a012013-06-26 15:45:41 -0700363 return patch;
364 }
365
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400366 DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
Chris Craikd218a922014-01-02 17:13:34 -0800367 DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
Chris Craikd218a922014-01-02 17:13:34 -0800368 DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Romain Guy24c00212011-01-14 15:31:00 -0800369
John Recka35778c72014-11-06 09:45:10 -0800370 ResourceCache& mResourceCache;
John Reck44fd8d22014-02-26 11:00:11 -0800371 DisplayListData* mDisplayListData;
Romain Guy58ecc202012-09-07 11:58:36 -0700372
Romain Guy33f6beb2012-02-16 19:24:51 -0800373 float mTranslateX;
374 float mTranslateY;
Chris Craik8afd0f22014-08-21 17:41:57 -0700375 bool mHasDeferredTranslate;
376 DeferredBarrierType mDeferredBarrierType;
Chris Craikcce47eb2014-07-16 15:12:15 -0700377 bool mHighContrastText;
Romain Guy54c1a642012-09-27 17:55:46 -0700378
Chris Craikeea6ef92014-03-05 16:37:35 -0800379 int mRestoreSaveCount;
380
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400381 SkAutoTUnref<SkDrawFilter> mDrawFilter;
382
John Recke18264b2014-03-12 13:56:30 -0700383 friend class RenderNode;
Romain Guyb051e892010-09-28 19:09:36 -0700384
Romain Guy4aa90572010-09-26 18:40:37 -0700385}; // class DisplayListRenderer
386
387}; // namespace uirenderer
388}; // namespace android
389
Romain Guy5b3b3522010-10-27 18:57:51 -0700390#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H