blob: 3b619046612f1269b4cea7488ed11c4b9c757086 [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
Chris Craik14e51302013-12-30 15:32:54 -080082 // Shapes
Tom Hudson8dfaa492014-12-09 15:03:44 -050083 void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
Jorim Jaggi072707d2014-09-15 17:20:08 +020084 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
85 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
86 CanvasPropertyPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -050087 void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
John Reck52244ff2014-05-01 21:27:37 -070088 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -080089
Chris Craik14e51302013-12-30 15:32:54 -080090
91// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050092// HWUI Canvas draw operations - special
Chris Craik14e51302013-12-30 15:32:54 -080093// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050094 void drawLayer(DeferredLayerUpdater* layerHandle, float x, float y);
Chris Craik956f3402015-04-27 16:41:00 -070095 void drawRenderNode(RenderNode* renderNode);
Chris Craik14e51302013-12-30 15:32:54 -080096
97 // TODO: rename for consistency
Chris Craik956f3402015-04-27 16:41:00 -070098 void callDrawGLFunction(Functor* functor);
Chris Craik14e51302013-12-30 15:32:54 -080099
Tom Hudson984162f2014-10-10 13:38:16 -0400100// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500101// CanvasStateClient interface
Tom Hudson984162f2014-10-10 13:38:16 -0400102// ----------------------------------------------------------------------------
Chris Craike84a2082014-12-22 14:28:49 -0800103 virtual void onViewportInitialized() override { }
104 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
Chris Craik6b109c72015-02-27 10:55:28 -0800105 virtual GLuint getTargetFbo() const override { return -1; }
Tom Hudson984162f2014-10-10 13:38:16 -0400106
Tom Hudson8dfaa492014-12-09 15:03:44 -0500107// ----------------------------------------------------------------------------
108// android/graphics/Canvas interface
109// ----------------------------------------------------------------------------
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500110 virtual SkCanvas* asSkCanvas() override;
111
John Reckc1b33d62015-04-22 09:04:45 -0700112 virtual void setBitmap(const SkBitmap& bitmap) override {
Chris Craikdb663fe2015-04-20 13:34:45 -0700113 LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
Tom Hudson8dfaa492014-12-09 15:03:44 -0500114 }
115
Chris Craikd41c4d82015-01-05 15:51:13 -0800116 virtual bool isOpaque() override { return false; }
117 virtual int width() override { return mState.getWidth(); }
118 virtual int height() override { return mState.getHeight(); }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500119
Derek Sollenberger6578a982015-07-13 13:24:29 -0400120 virtual void setHighContrastText(bool highContrastText) override {
121 mHighContrastText = highContrastText;
122 }
123 virtual bool isHighContrastText() override { return mHighContrastText; }
124
Tom Hudson8dfaa492014-12-09 15:03:44 -0500125// ----------------------------------------------------------------------------
126// android/graphics/Canvas state operations
127// ----------------------------------------------------------------------------
128 // Save (layer)
Chris Craikd41c4d82015-01-05 15:51:13 -0800129 virtual int getSaveCount() const override { return mState.getSaveCount(); }
130 virtual int save(SkCanvas::SaveFlags flags) override;
131 virtual void restore() override;
132 virtual void restoreToCount(int saveCount) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500133
134 virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
Chris Craikd41c4d82015-01-05 15:51:13 -0800135 SkCanvas::SaveFlags flags) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500136 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800137 int alpha, SkCanvas::SaveFlags flags) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500138 SkPaint paint;
139 paint.setAlpha(alpha);
140 return saveLayer(left, top, right, bottom, &paint, flags);
141 }
142
143 // Matrix
Chris Craikd41c4d82015-01-05 15:51:13 -0800144 virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
145 virtual void setMatrix(const SkMatrix& matrix) override;
Tom Hudsonac7b6d32015-06-30 11:26:13 -0400146 virtual void setLocalMatrix(const SkMatrix& matrix) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500147
Chris Craikd41c4d82015-01-05 15:51:13 -0800148 virtual void concat(const SkMatrix& matrix) override;
149 virtual void rotate(float degrees) override;
150 virtual void scale(float sx, float sy) override;
151 virtual void skew(float sx, float sy) override;
152 virtual void translate(float dx, float dy) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500153
154 // Clip
Chris Craikd41c4d82015-01-05 15:51:13 -0800155 virtual bool getClipBounds(SkRect* outRect) const override;
156 virtual bool quickRejectRect(float left, float top, float right, float bottom) const override;
157 virtual bool quickRejectPath(const SkPath& path) const override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500158
Chris Craikd41c4d82015-01-05 15:51:13 -0800159 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op) override;
160 virtual bool clipPath(const SkPath* path, SkRegion::Op op) override;
161 virtual bool clipRegion(const SkRegion* region, SkRegion::Op op) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500162
163 // Misc
Chris Craikd41c4d82015-01-05 15:51:13 -0800164 virtual SkDrawFilter* getDrawFilter() override { return mDrawFilter.get(); }
165 virtual void setDrawFilter(SkDrawFilter* filter) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500166
167// ----------------------------------------------------------------------------
168// android/graphics/Canvas draw operations
169// ----------------------------------------------------------------------------
Chris Craikd41c4d82015-01-05 15:51:13 -0800170 virtual void drawColor(int color, SkXfermode::Mode mode) override;
171 virtual void drawPaint(const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500172
173 // Geometry
Chris Craikd41c4d82015-01-05 15:51:13 -0800174 virtual void drawPoint(float x, float y, const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500175 float points[2] = { x, y };
176 drawPoints(points, 2, paint);
177 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800178 virtual void drawPoints(const float* points, int count, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500179 virtual void drawLine(float startX, float startY, float stopX, float stopY,
Chris Craikd41c4d82015-01-05 15:51:13 -0800180 const SkPaint& paint) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500181 float points[4] = { startX, startY, stopX, stopY };
182 drawLines(points, 4, paint);
183 }
Chris Craikd41c4d82015-01-05 15:51:13 -0800184 virtual void drawLines(const float* points, int count, const SkPaint& paint) override;
185 virtual void drawRect(float left, float top, float right, float bottom, const SkPaint& paint) override;
Derek Sollenberger94394b32015-07-10 09:58:41 -0400186 virtual void drawRegion(const SkRegion& region, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500187 virtual void drawRoundRect(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800188 float rx, float ry, const SkPaint& paint) override;
189 virtual void drawCircle(float x, float y, float radius, const SkPaint& paint) override;
190 virtual void drawOval(float left, float top, float right, float bottom, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500191 virtual void drawArc(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800192 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) override;
193 virtual void drawPath(const SkPath& path, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500194 virtual void drawVertices(SkCanvas::VertexMode vertexMode, int vertexCount,
195 const float* verts, const float* tex, const int* colors,
Chris Craikd41c4d82015-01-05 15:51:13 -0800196 const uint16_t* indices, int indexCount, const SkPaint& paint) override
Chris Craikdb663fe2015-04-20 13:34:45 -0700197 { /* DisplayListCanvas does not support drawVertices(); ignore */ }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500198
199 // Bitmap-based
Chris Craikd41c4d82015-01-05 15:51:13 -0800200 virtual void drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500201 virtual void drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix,
Chris Craikd41c4d82015-01-05 15:51:13 -0800202 const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500203 virtual void drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop,
204 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800205 float dstRight, float dstBottom, const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500206 virtual void drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight,
Chris Craikd41c4d82015-01-05 15:51:13 -0800207 const float* vertices, const int* colors, const SkPaint* paint) override;
Derek Sollenberger4c5efe92015-07-10 13:56:39 -0400208 virtual void drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& chunk,
209 float dstLeft, float dstTop, float dstRight, float dstBottom,
210 const SkPaint* paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500211
212 // Text
213 virtual void drawText(const uint16_t* glyphs, const float* positions, int count,
214 const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop,
Chris Craikd41c4d82015-01-05 15:51:13 -0800215 float boundsRight, float boundsBottom, float totalAdvance) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500216 virtual void drawPosText(const uint16_t* text, const float* positions, int count,
Chris Craikd41c4d82015-01-05 15:51:13 -0800217 int posCount, const SkPaint& paint) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500218 virtual void drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
Chris Craikd41c4d82015-01-05 15:51:13 -0800219 float hOffset, float vOffset, const SkPaint& paint) override;
220 virtual bool drawTextAbsolutePos() const override { return false; }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500221
222
Romain Guy4aa90572010-09-26 18:40:37 -0700223private:
Tom Hudson984162f2014-10-10 13:38:16 -0400224
225 CanvasState mState;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500226 std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
Tom Hudson984162f2014-10-10 13:38:16 -0400227
Chris Craik8afd0f22014-08-21 17:41:57 -0700228 enum DeferredBarrierType {
229 kBarrier_None,
230 kBarrier_InOrder,
231 kBarrier_OutOfOrder,
232 };
233
Derek Sollenberger94394b32015-07-10 09:58:41 -0400234 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
235 void drawRects(const float* rects, int count, const SkPaint* paint);
236
Chris Craik8afd0f22014-08-21 17:41:57 -0700237 void flushRestoreToCount();
238 void flushTranslate();
239 void flushReorderBarrier();
Romain Guy27454a42011-01-23 12:01:41 -0800240
Chris Craik2af46352012-11-26 18:30:17 -0800241 LinearAllocator& alloc() { return mDisplayListData->allocator; }
Chris Craikb3cca872014-08-08 18:42:51 -0700242
243 // Each method returns final index of op
Chris Craik8afd0f22014-08-21 17:41:57 -0700244 size_t addOpAndUpdateChunk(DisplayListOp* op);
245 // flushes any deferred operations, and appends the op
246 size_t flushAndAddOp(DisplayListOp* op);
247
248 size_t addStateOp(StateOp* op);
249 size_t addDrawOp(DrawOp* op);
250 size_t addRenderNodeOp(DrawRenderNodeOp* op);
251
John Reck37b08242015-06-09 13:12:40 -0700252 void refBitmapsInShader(const SkShader* shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700253
Chris Craik2af46352012-11-26 18:30:17 -0800254 template<class T>
Chris Craikd218a922014-01-02 17:13:34 -0800255 inline const T* refBuffer(const T* srcBuffer, int32_t count) {
Chris Craike84a2082014-12-22 14:28:49 -0800256 if (!srcBuffer) return nullptr;
Chris Craikd218a922014-01-02 17:13:34 -0800257
Chris Craik2af46352012-11-26 18:30:17 -0800258 T* dstBuffer = (T*) mDisplayListData->allocator.alloc(count * sizeof(T));
259 memcpy(dstBuffer, srcBuffer, count * sizeof(T));
260 return dstBuffer;
Romain Guy33f6beb2012-02-16 19:24:51 -0800261 }
262
Chris Craik2af46352012-11-26 18:30:17 -0800263 inline char* refText(const char* text, size_t byteLength) {
264 return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
Romain Guy33f6beb2012-02-16 19:24:51 -0800265 }
266
Chris Craikd218a922014-01-02 17:13:34 -0800267 inline const SkPath* refPath(const SkPath* path) {
Chris Craike84a2082014-12-22 14:28:49 -0800268 if (!path) return nullptr;
Romain Guy2fc941e2011-02-03 15:06:05 -0800269
Derek Sollenbergeree248592015-02-12 14:10:21 -0500270 // The points/verbs within the path are refcounted so this copy operation
271 // is inexpensive and maintains the generationID of the original path.
272 const SkPath* cachedPath = new SkPath(*path);
John Reck272a6852015-07-29 16:48:58 -0700273 mDisplayListData->pathResources.push_back(cachedPath);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800274 return cachedPath;
Romain Guy4aa90572010-09-26 18:40:37 -0700275 }
276
Chris Craikd218a922014-01-02 17:13:34 -0800277 inline const SkPaint* refPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800278 if (!paint) return nullptr;
Romain Guy0fe478e2010-11-08 12:08:41 -0800279
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400280 // If there is a draw filter apply it here and store the modified paint
281 // so that we don't need to modify the paint every time we access it.
Chris Craikda3198a2014-11-21 22:05:46 +0000282 SkTLazy<SkPaint> filteredPaint;
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400283 if (mDrawFilter.get()) {
Derek Sollenberger0b860622015-03-25 10:08:30 -0400284 filteredPaint.set(*paint);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800285 mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
Derek Sollenberger0b860622015-03-25 10:08:30 -0400286 paint = filteredPaint.get();
Chet Haased98aa2d2010-10-25 15:47:32 -0700287 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800288
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400289 // compute the hash key for the paint and check the cache.
290 const uint32_t key = paint->getHash();
291 const SkPaint* cachedPaint = mPaintMap.valueFor(key);
292 // In the unlikely event that 2 unique paints have the same hash we do a
293 // object equality check to ensure we don't erroneously dedup them.
Chris Craike84a2082014-12-22 14:28:49 -0800294 if (cachedPaint == nullptr || *cachedPaint != *paint) {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800295 cachedPaint = new SkPaint(*paint);
296 std::unique_ptr<const SkPaint> copy(cachedPaint);
297 mDisplayListData->paints.push_back(std::move(copy));
298
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400299 // replaceValueFor() performs an add if the entry doesn't exist
300 mPaintMap.replaceValueFor(key, cachedPaint);
John Reck37b08242015-06-09 13:12:40 -0700301 refBitmapsInShader(cachedPaint->getShader());
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400302 }
303
304 return cachedPaint;
Romain Guy0fe478e2010-11-08 12:08:41 -0800305 }
306
Chris Craikd218a922014-01-02 17:13:34 -0800307 inline const SkRegion* refRegion(const SkRegion* region) {
Romain Guy735738c2012-12-03 12:34:51 -0800308 if (!region) {
Romain Guy735738c2012-12-03 12:34:51 -0800309 return region;
310 }
311
Chris Craik51d6a3d2014-12-22 17:16:56 -0800312 const SkRegion* cachedRegion = mRegionMap.valueFor(region);
Romain Guy735738c2012-12-03 12:34:51 -0800313 // TODO: Add generation ID to SkRegion
Chris Craik51d6a3d2014-12-22 17:16:56 -0800314 if (cachedRegion == nullptr) {
315 std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
316 cachedRegion = copy.get();
317 mDisplayListData->regions.push_back(std::move(copy));
318
Romain Guy735738c2012-12-03 12:34:51 -0800319 // replaceValueFor() performs an add if the entry doesn't exist
Chris Craik51d6a3d2014-12-22 17:16:56 -0800320 mRegionMap.replaceValueFor(region, cachedRegion);
Romain Guy735738c2012-12-03 12:34:51 -0800321 }
322
Chris Craik51d6a3d2014-12-22 17:16:56 -0800323 return cachedRegion;
Romain Guy735738c2012-12-03 12:34:51 -0800324 }
325
John Reck7c103a32015-04-15 15:52:10 -0700326 inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700327 // Note that this assumes the bitmap is immutable. There are cases this won't handle
328 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
329 // contents, and drawing again. The only fix would be to always copy it the first time,
330 // which doesn't seem worth the extra cycles for this unlikely case.
John Reck98ae4df2015-05-07 13:50:55 -0700331 SkBitmap* localBitmap = new (alloc()) SkBitmap(bitmap);
John Recke75ab4c2015-05-07 13:14:15 -0700332 alloc().autoDestroy(localBitmap);
333 mDisplayListData->bitmapResources.push_back(localBitmap);
334 return localBitmap;
Romain Guy49c5fc02012-05-15 11:10:01 -0700335 }
336
Chris Craikd218a922014-01-02 17:13:34 -0800337 inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
John Reck272a6852015-07-29 16:48:58 -0700338 mDisplayListData->patchResources.push_back(patch);
John Recka35778c72014-11-06 09:45:10 -0800339 mResourceCache.incrementRefcount(patch);
Romain Guye3b0a012013-06-26 15:45:41 -0700340 return patch;
341 }
342
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400343 DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
Chris Craikd218a922014-01-02 17:13:34 -0800344 DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
Chris Craikd218a922014-01-02 17:13:34 -0800345 DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Romain Guy24c00212011-01-14 15:31:00 -0800346
John Recka35778c72014-11-06 09:45:10 -0800347 ResourceCache& mResourceCache;
John Reck44fd8d22014-02-26 11:00:11 -0800348 DisplayListData* mDisplayListData;
Romain Guy58ecc202012-09-07 11:58:36 -0700349
Romain Guy33f6beb2012-02-16 19:24:51 -0800350 float mTranslateX;
351 float mTranslateY;
Chris Craik8afd0f22014-08-21 17:41:57 -0700352 bool mHasDeferredTranslate;
353 DeferredBarrierType mDeferredBarrierType;
Chris Craikcce47eb2014-07-16 15:12:15 -0700354 bool mHighContrastText;
Romain Guy54c1a642012-09-27 17:55:46 -0700355
Chris Craikeea6ef92014-03-05 16:37:35 -0800356 int mRestoreSaveCount;
357
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400358 SkAutoTUnref<SkDrawFilter> mDrawFilter;
359
John Recke18264b2014-03-12 13:56:30 -0700360 friend class RenderNode;
Romain Guyb051e892010-09-28 19:09:36 -0700361
Chris Craikdb663fe2015-04-20 13:34:45 -0700362}; // class DisplayListCanvas
Romain Guy4aa90572010-09-26 18:40:37 -0700363
364}; // namespace uirenderer
365}; // namespace android
366
Romain Guy5b3b3522010-10-27 18:57:51 -0700367#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H