blob: f3f5713bbc3fdec9f341cc72497a77d5cedf7e39 [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:
Derek Sollenbergercc882b62015-07-09 15:51:20 -040065 DisplayListCanvas(int width, int height);
Chris Craikdb663fe2015-04-20 13:34:45 -070066 virtual ~DisplayListCanvas();
Romain Guyb051e892010-09-28 19:09:36 -070067
Derek Sollenbergercc882b62015-07-09 15:51:20 -040068 void reset(int width, int height);
Chris Craik8afd0f22014-08-21 17:41:57 -070069
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 Canvas state operations
Chris Craik14e51302013-12-30 15:32:54 -080074// ----------------------------------------------------------------------------
Tom Hudson984162f2014-10-10 13:38:16 -040075
Derek Sollenbergercc882b62015-07-09 15:51:20 -040076 void insertReorderBarrier(bool enableReorder);
Romain Guy4aa90572010-09-26 18:40:37 -070077
Chris Craik14e51302013-12-30 15:32:54 -080078// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050079// HWUI Canvas draw operations
Chris Craik14e51302013-12-30 15:32:54 -080080// ----------------------------------------------------------------------------
Chris Craik14e51302013-12-30 15:32:54 -080081
John Reck773bbe02015-08-17 15:18:29 -070082 // TODO: move drawPatch() to Canvas.h
83 void drawPatch(const SkBitmap& bitmap, const Res_png_9patch* patch,
84 float left, float top, float right, float bottom, const SkPaint* paint);
85
Chris Craik14e51302013-12-30 15:32:54 -080086 // Shapes
Tom Hudson8dfaa492014-12-09 15:03:44 -050087 void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
Jorim Jaggi072707d2014-09-15 17:20:08 +020088 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
89 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
90 CanvasPropertyPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -050091 void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
John Reck52244ff2014-05-01 21:27:37 -070092 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -080093
Chris Craik14e51302013-12-30 15:32:54 -080094
95// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050096// HWUI Canvas draw operations - special
Chris Craik14e51302013-12-30 15:32:54 -080097// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050098 void drawLayer(DeferredLayerUpdater* layerHandle, float x, float y);
Chris Craik956f3402015-04-27 16:41:00 -070099 void drawRenderNode(RenderNode* renderNode);
Chris Craik14e51302013-12-30 15:32:54 -0800100
101 // TODO: rename for consistency
Chris Craik956f3402015-04-27 16:41:00 -0700102 void callDrawGLFunction(Functor* functor);
Chris Craik14e51302013-12-30 15:32:54 -0800103
Tom Hudson984162f2014-10-10 13:38:16 -0400104// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500105// CanvasStateClient interface
Tom Hudson984162f2014-10-10 13:38:16 -0400106// ----------------------------------------------------------------------------
Chris Craike84a2082014-12-22 14:28:49 -0800107 virtual void onViewportInitialized() override { }
108 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
Chris Craik6b109c72015-02-27 10:55:28 -0800109 virtual GLuint getTargetFbo() const override { return -1; }
Tom Hudson984162f2014-10-10 13:38:16 -0400110
Tom Hudson8dfaa492014-12-09 15:03:44 -0500111// ----------------------------------------------------------------------------
112// android/graphics/Canvas interface
113// ----------------------------------------------------------------------------
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500114 virtual SkCanvas* asSkCanvas() override;
115
John Reckc1b33d62015-04-22 09:04:45 -0700116 virtual void setBitmap(const SkBitmap& bitmap) override {
Chris Craikdb663fe2015-04-20 13:34:45 -0700117 LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
Tom Hudson8dfaa492014-12-09 15:03:44 -0500118 }
119
Chris Craikd41c4d82015-01-05 15:51:13 -0800120 virtual bool isOpaque() override { return false; }
121 virtual int width() override { return mState.getWidth(); }
122 virtual int height() override { return mState.getHeight(); }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500123
Derek Sollenberger6578a982015-07-13 13:24:29 -0400124 virtual void setHighContrastText(bool highContrastText) override {
125 mHighContrastText = highContrastText;
126 }
127 virtual bool isHighContrastText() override { return mHighContrastText; }
128
Tom Hudson8dfaa492014-12-09 15:03:44 -0500129// ----------------------------------------------------------------------------
130// android/graphics/Canvas state operations
131// ----------------------------------------------------------------------------
132 // Save (layer)
Chris Craikd41c4d82015-01-05 15:51:13 -0800133 virtual int getSaveCount() const override { return mState.getSaveCount(); }
134 virtual int save(SkCanvas::SaveFlags flags) override;
135 virtual void restore() override;
136 virtual void restoreToCount(int saveCount) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500137
138 virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
Chris Craikd41c4d82015-01-05 15:51:13 -0800139 SkCanvas::SaveFlags flags) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500140 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800141 int alpha, SkCanvas::SaveFlags flags) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500142 SkPaint paint;
143 paint.setAlpha(alpha);
144 return saveLayer(left, top, right, bottom, &paint, flags);
145 }
146
147 // Matrix
Chris Craikd41c4d82015-01-05 15:51:13 -0800148 virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
149 virtual void setMatrix(const SkMatrix& matrix) override;
Tom Hudsonac7b6d32015-06-30 11:26:13 -0400150 virtual void setLocalMatrix(const SkMatrix& matrix) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500151
Chris Craikd41c4d82015-01-05 15:51:13 -0800152 virtual void concat(const SkMatrix& matrix) override;
153 virtual void rotate(float degrees) override;
154 virtual void scale(float sx, float sy) override;
155 virtual void skew(float sx, float sy) override;
156 virtual void translate(float dx, float dy) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500157
158 // Clip
Chris Craikd41c4d82015-01-05 15:51:13 -0800159 virtual bool getClipBounds(SkRect* outRect) const override;
160 virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
161 virtual bool quickRejectPath(const SkPath& path) const override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500162
Chris Craikd41c4d82015-01-05 15:51:13 -0800163 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
164 virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
165 virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500166
167 // Misc
Chris Craikd41c4d82015-01-05 15:51:13 -0800168 virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
169 virtual void setDrawFilter(SkDrawFilter* filter) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500170
171// ----------------------------------------------------------------------------
172// android/graphics/Canvas draw operations
173// ----------------------------------------------------------------------------
Chris Craikd41c4d82015-01-05 15:51:13 -0800174 virtual void drawColor(int color, SkXfermode::Mode mode) override;
175 virtual void drawPaint(const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500176
177 // Geometry
Chris Craikd41c4d82015-01-05 15:51:13 -0800178 virtual void drawPoint(float x, float y, const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500179 float points[2] = { x, y };
180 drawPoints(points, 2, paint);
181 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800182 virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500183 virtual void drawLine(float startX, float startY, float stopX, float stopY,
Chris Craikd41c4d82015-01-05 15:51:13 -0800184 const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500185 float points[4] = { startX, startY, stopX, stopY };
186 drawLines(points, 4, paint);
187 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800188 virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
189 virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
Derek Sollenberger94394b32015-07-10 09:58:41 -0400190 virtual void drawRegion(const SkRegion& region, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500191 virtual void drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800192 float rx, float ry, const SkPaint& paint) override;
193 virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
194 virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500195 virtual void drawArc(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800196 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
197 virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500198 virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
199 const float* verts, const float* tex, const int* colors,
Chris Craikd41c4d82015-01-05 15:51:13 -0800200 const uint16_t* indices, int indexCount, const SkPaint& paint) override
Chris Craikdb663fe2015-04-20 13:34:45 -0700201 { /* DisplayListCanvas does not support drawVertices(); ignore */ }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500202
203 // Bitmap-based
Chris Craikd41c4d82015-01-05 15:51:13 -0800204 virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500205 virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
Chris Craikd41c4d82015-01-05 15:51:13 -0800206 const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500207 virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
208 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800209 float dstRight, float dstBottom, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500210 virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
Chris Craikd41c4d82015-01-05 15:51:13 -0800211 const float* vertices, const int* colors, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500212
213 // Text
214 virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
215 const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800216 float boundsRight, float boundsBottom, float totalAdvance) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500217 virtual void drawPosText(const uint16_t* text, const float* positions, int count,
Chris Craikd41c4d82015-01-05 15:51:13 -0800218 int posCount, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500219 virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
Chris Craikd41c4d82015-01-05 15:51:13 -0800220 float hOffset, float vOffset, const SkPaint& paint) override;
221 virtual bool drawTextAbsolutePos() const override { return false; }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500222
223
Romain Guy4aa90572010-09-26 18:40:37 -0700224private:
Tom Hudson984162f2014-10-10 13:38:16 -0400225
226 CanvasState mState;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500227 std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
Tom Hudson984162f2014-10-10 13:38:16 -0400228
Chris Craik8afd0f22014-08-21 17:41:57 -0700229 enum DeferredBarrierType {
230 kBarrier_None,
231 kBarrier_InOrder,
232 kBarrier_OutOfOrder,
233 };
234
Derek Sollenberger94394b32015-07-10 09:58:41 -0400235 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
236 void drawRects(const float* rects, int count, const SkPaint* paint);
237
Chris Craik8afd0f22014-08-21 17:41:57 -0700238 void flushRestoreToCount();
239 void flushTranslate();
240 void flushReorderBarrier();
Romain Guy27454a42011-01-23 12:01:41 -0800241
Chris Craik2af46352012-11-26 18:30:17 -0800242 LinearAllocator& alloc() { return mDisplayListData->allocator; }
Chris Craikb3cca872014-08-08 18:42:51 -0700243
244 // Each method returns final index of op
Chris Craik8afd0f22014-08-21 17:41:57 -0700245 size_t addOpAndUpdateChunk(DisplayListOp* op);
246 // flushes any deferred operations, and appends the op
247 size_t flushAndAddOp(DisplayListOp* op);
248
249 size_t addStateOp(StateOp* op);
250 size_t addDrawOp(DrawOp* op);
251 size_t addRenderNodeOp(DrawRenderNodeOp* op);
252
John Reck37b08242015-06-09 13:12:40 -0700253 void refBitmapsInShader(const SkShader* shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700254
Chris Craik2af46352012-11-26 18:30:17 -0800255 template<class T>
Chris Craikd218a922014-01-02 17:13:34 -0800256 inline const T* refBuffer(const T* srcBuffer, int32_t count) {
Chris Craike84a2082014-12-22 14:28:49 -0800257 if (!srcBuffer) return nullptr;
Chris Craikd218a922014-01-02 17:13:34 -0800258
Chris Craik2af46352012-11-26 18:30:17 -0800259 T* dstBuffer = (T*) mDisplayListData->allocator.alloc(count * sizeof(T));
260 memcpy(dstBuffer, srcBuffer, count * sizeof(T));
261 return dstBuffer;
Romain Guy33f6beb2012-02-16 19:24:51 -0800262 }
263
Chris Craik2af46352012-11-26 18:30:17 -0800264 inline char* refText(const char* text, size_t byteLength) {
265 return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
Romain Guy33f6beb2012-02-16 19:24:51 -0800266 }
267
Chris Craikd218a922014-01-02 17:13:34 -0800268 inline const SkPath* refPath(const SkPath* path) {
Chris Craike84a2082014-12-22 14:28:49 -0800269 if (!path) return nullptr;
Romain Guy2fc941e2011-02-03 15:06:05 -0800270
Derek Sollenbergeree248592015-02-12 14:10:21 -0500271 // The points/verbs within the path are refcounted so this copy operation
272 // is inexpensive and maintains the generationID of the original path.
273 const SkPath* cachedPath = new SkPath(*path);
John Reck272a6852015-07-29 16:48:58 -0700274 mDisplayListData->pathResources.push_back(cachedPath);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800275 return cachedPath;
Romain Guy4aa90572010-09-26 18:40:37 -0700276 }
277
Chris Craikd218a922014-01-02 17:13:34 -0800278 inline const SkPaint* refPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800279 if (!paint) return nullptr;
Romain Guy0fe478e2010-11-08 12:08:41 -0800280
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400281 // If there is a draw filter apply it here and store the modified paint
282 // so that we don't need to modify the paint every time we access it.
Chris Craikda3198a2014-11-21 22:05:46 +0000283 SkTLazy<SkPaint> filteredPaint;
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400284 if (mDrawFilter.get()) {
Derek Sollenberger0b860622015-03-25 10:08:30 -0400285 filteredPaint.set(*paint);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800286 mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
Derek Sollenberger0b860622015-03-25 10:08:30 -0400287 paint = filteredPaint.get();
Chet Haased98aa2d2010-10-25 15:47:32 -0700288 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800289
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400290 // compute the hash key for the paint and check the cache.
291 const uint32_t key = paint->getHash();
292 const SkPaint* cachedPaint = mPaintMap.valueFor(key);
293 // In the unlikely event that 2 unique paints have the same hash we do a
294 // object equality check to ensure we don't erroneously dedup them.
Chris Craike84a2082014-12-22 14:28:49 -0800295 if (cachedPaint == nullptr || *cachedPaint != *paint) {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800296 cachedPaint = new SkPaint(*paint);
297 std::unique_ptr<const SkPaint> copy(cachedPaint);
298 mDisplayListData->paints.push_back(std::move(copy));
299
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400300 // replaceValueFor() performs an add if the entry doesn't exist
301 mPaintMap.replaceValueFor(key, cachedPaint);
John Reck37b08242015-06-09 13:12:40 -0700302 refBitmapsInShader(cachedPaint->getShader());
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400303 }
304
305 return cachedPaint;
Romain Guy0fe478e2010-11-08 12:08:41 -0800306 }
307
Chris Craikd218a922014-01-02 17:13:34 -0800308 inline const SkRegion* refRegion(const SkRegion* region) {
Romain Guy735738c2012-12-03 12:34:51 -0800309 if (!region) {
Romain Guy735738c2012-12-03 12:34:51 -0800310 return region;
311 }
312
Chris Craik51d6a3d2014-12-22 17:16:56 -0800313 const SkRegion* cachedRegion = mRegionMap.valueFor(region);
Romain Guy735738c2012-12-03 12:34:51 -0800314 // TODO: Add generation ID to SkRegion
Chris Craik51d6a3d2014-12-22 17:16:56 -0800315 if (cachedRegion == nullptr) {
316 std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
317 cachedRegion = copy.get();
318 mDisplayListData->regions.push_back(std::move(copy));
319
Romain Guy735738c2012-12-03 12:34:51 -0800320 // replaceValueFor() performs an add if the entry doesn't exist
Chris Craik51d6a3d2014-12-22 17:16:56 -0800321 mRegionMap.replaceValueFor(region, cachedRegion);
Romain Guy735738c2012-12-03 12:34:51 -0800322 }
323
Chris Craik51d6a3d2014-12-22 17:16:56 -0800324 return cachedRegion;
Romain Guy735738c2012-12-03 12:34:51 -0800325 }
326
John Reck7c103a32015-04-15 15:52:10 -0700327 inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700328 // Note that this assumes the bitmap is immutable. There are cases this won't handle
329 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
330 // contents, and drawing again. The only fix would be to always copy it the first time,
331 // which doesn't seem worth the extra cycles for this unlikely case.
John Reck98ae4df2015-05-07 13:50:55 -0700332 SkBitmap* localBitmap = new (alloc()) SkBitmap(bitmap);
John Recke75ab4c2015-05-07 13:14:15 -0700333 alloc().autoDestroy(localBitmap);
334 mDisplayListData->bitmapResources.push_back(localBitmap);
335 return localBitmap;
Romain Guy49c5fc02012-05-15 11:10:01 -0700336 }
337
Chris Craikd218a922014-01-02 17:13:34 -0800338 inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
John Reck272a6852015-07-29 16:48:58 -0700339 mDisplayListData->patchResources.push_back(patch);
John Recka35778c72014-11-06 09:45:10 -0800340 mResourceCache.incrementRefcount(patch);
Romain Guye3b0a012013-06-26 15:45:41 -0700341 return patch;
342 }
343
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400344 DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
Chris Craikd218a922014-01-02 17:13:34 -0800345 DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
Chris Craikd218a922014-01-02 17:13:34 -0800346 DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Romain Guy24c00212011-01-14 15:31:00 -0800347
John Recka35778c72014-11-06 09:45:10 -0800348 ResourceCache& mResourceCache;
John Reck44fd8d22014-02-26 11:00:11 -0800349 DisplayListData* mDisplayListData;
Romain Guy58ecc202012-09-07 11:58:36 -0700350
Romain Guy33f6beb2012-02-16 19:24:51 -0800351 float mTranslateX;
352 float mTranslateY;
Chris Craik8afd0f22014-08-21 17:41:57 -0700353 bool mHasDeferredTranslate;
354 DeferredBarrierType mDeferredBarrierType;
Chris Craikcce47eb2014-07-16 15:12:15 -0700355 bool mHighContrastText;
Romain Guy54c1a642012-09-27 17:55:46 -0700356
Chris Craikeea6ef92014-03-05 16:37:35 -0800357 int mRestoreSaveCount;
358
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400359 SkAutoTUnref<SkDrawFilter> mDrawFilter;
360
John Recke18264b2014-03-12 13:56:30 -0700361 friend class RenderNode;
Romain Guyb051e892010-09-28 19:09:36 -0700362
Chris Craikdb663fe2015-04-20 13:34:45 -0700363}; // class DisplayListCanvas
Romain Guy4aa90572010-09-26 18:40:37 -0700364
365}; // namespace uirenderer
366}; // namespace android
367
Romain Guy5b3b3522010-10-27 18:57:51 -0700368#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H