blob: 72fc100ebd1d3d4012e5abe8e1d1f1f6b722691e [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
Chris Craik9fded232015-11-11 16:42:34 -080020#include "Canvas.h"
21#include "CanvasState.h"
22#include "DisplayList.h"
23#include "RenderNode.h"
24#include "ResourceCache.h"
25#include "SkiaCanvasProxy.h"
26#include "utils/Macros.h"
27
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -040028#include <SkDrawFilter.h>
Romain Guy4aa90572010-09-26 18:40:37 -070029#include <SkMatrix.h>
30#include <SkPaint.h>
31#include <SkPath.h>
Tom Hudson2dc236b2014-10-15 15:46:42 -040032#include <SkRegion.h>
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -040033#include <SkTLazy.h>
Romain Guy79537452011-10-12 13:48:51 -070034#include <cutils/compiler.h>
35
Romain Guy4aa90572010-09-26 18:40:37 -070036namespace android {
37namespace uirenderer {
38
39///////////////////////////////////////////////////////////////////////////////
40// Defines
41///////////////////////////////////////////////////////////////////////////////
42
Romain Guyffac7fc2011-01-13 17:21:49 -080043// Debug
44#if DEBUG_DISPLAY_LIST
Steve Block5baa3a62011-12-20 16:23:08 +000045 #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyffac7fc2011-01-13 17:21:49 -080046#else
47 #define DISPLAY_LIST_LOGD(...)
48#endif
49
Romain Guy4aa90572010-09-26 18:40:37 -070050///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070051// Display list
Romain Guy4aa90572010-09-26 18:40:37 -070052///////////////////////////////////////////////////////////////////////////////
53
Chris Craikc3566d02013-02-04 16:16:33 -080054class DeferredDisplayList;
John Reck12f5e342014-11-07 07:53:43 -080055class DeferredLayerUpdater;
Chris Craik2af46352012-11-26 18:30:17 -080056class DisplayListOp;
57class DrawOp;
Chris Craik8d1f2122015-11-24 16:40:09 -080058class DrawRenderNodeOp;
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 */
Chris Craikdb663fe2015-04-20 13:34:45 -070065class ANDROID_API DisplayListCanvas: public Canvas, public CanvasStateClient {
Romain Guyb051e892010-09-28 19:09:36 -070066public:
Derek Sollenbergercc882b62015-07-09 15:51:20 -040067 DisplayListCanvas(int width, int height);
Chris Craikdb663fe2015-04-20 13:34:45 -070068 virtual ~DisplayListCanvas();
Romain Guyb051e892010-09-28 19:09:36 -070069
Derek Sollenbergercc882b62015-07-09 15:51:20 -040070 void reset(int width, int height);
Chris Craik9fded232015-11-11 16:42:34 -080071 WARN_UNUSED_RESULT DisplayList* finishRecording();
Chet Haase5977baa2011-01-05 18:01:22 -080072
Chris Craik14e51302013-12-30 15:32:54 -080073// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050074// HWUI Canvas state operations
Chris Craik14e51302013-12-30 15:32:54 -080075// ----------------------------------------------------------------------------
Tom Hudson984162f2014-10-10 13:38:16 -040076
Derek Sollenbergercc882b62015-07-09 15:51:20 -040077 void insertReorderBarrier(bool enableReorder);
Romain Guy4aa90572010-09-26 18:40:37 -070078
Chris Craik14e51302013-12-30 15:32:54 -080079// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050080// HWUI Canvas draw operations
Chris Craik14e51302013-12-30 15:32:54 -080081// ----------------------------------------------------------------------------
Chris Craik14e51302013-12-30 15:32:54 -080082
Chris Craik14e51302013-12-30 15:32:54 -080083 // Shapes
Tom Hudson8dfaa492014-12-09 15:03:44 -050084 void drawRoundRect(CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top,
Jorim Jaggi072707d2014-09-15 17:20:08 +020085 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom,
86 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry,
87 CanvasPropertyPaint* paint);
Tom Hudson8dfaa492014-12-09 15:03:44 -050088 void drawCircle(CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y,
John Reck52244ff2014-05-01 21:27:37 -070089 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint);
Chris Craik14e51302013-12-30 15:32:54 -080090
Chris Craik14e51302013-12-30 15:32:54 -080091
92// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -050093// HWUI Canvas draw operations - special
Chris Craik14e51302013-12-30 15:32:54 -080094// ----------------------------------------------------------------------------
Chris Craik3aadd602015-08-20 12:41:40 -070095 void drawLayer(DeferredLayerUpdater* layerHandle);
Chris Craik956f3402015-04-27 16:41:00 -070096 void drawRenderNode(RenderNode* renderNode);
Chris Craik14e51302013-12-30 15:32:54 -080097
98 // TODO: rename for consistency
Chris Craik956f3402015-04-27 16:41:00 -070099 void callDrawGLFunction(Functor* functor);
Chris Craik14e51302013-12-30 15:32:54 -0800100
Tom Hudson984162f2014-10-10 13:38:16 -0400101// ----------------------------------------------------------------------------
Tom Hudson8dfaa492014-12-09 15:03:44 -0500102// CanvasStateClient interface
Tom Hudson984162f2014-10-10 13:38:16 -0400103// ----------------------------------------------------------------------------
Chris Craike84a2082014-12-22 14:28:49 -0800104 virtual void onViewportInitialized() override { }
105 virtual void onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) override { }
Chris Craik6b109c72015-02-27 10:55:28 -0800106 virtual GLuint getTargetFbo() const override { return -1; }
Tom Hudson984162f2014-10-10 13:38:16 -0400107
Tom Hudson8dfaa492014-12-09 15:03:44 -0500108// ----------------------------------------------------------------------------
109// android/graphics/Canvas interface
110// ----------------------------------------------------------------------------
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500111 virtual SkCanvas* asSkCanvas() override;
112
John Reckc1b33d62015-04-22 09:04:45 -0700113 virtual void setBitmap(const SkBitmap& bitmap) override {
Chris Craikdb663fe2015-04-20 13:34:45 -0700114 LOG_ALWAYS_FATAL("DisplayListCanvas is not backed by a bitmap.");
Tom Hudson8dfaa492014-12-09 15:03:44 -0500115 }
116
Chris Craikd41c4d82015-01-05 15:51:13 -0800117 virtual bool isOpaque() override { return false; }
118 virtual int width() override { return mState.getWidth(); }
119 virtual int height() override { return mState.getHeight(); }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500120
Derek Sollenberger6578a982015-07-13 13:24:29 -0400121 virtual void setHighContrastText(bool highContrastText) override {
122 mHighContrastText = highContrastText;
123 }
124 virtual bool isHighContrastText() override { return mHighContrastText; }
125
Tom Hudson8dfaa492014-12-09 15:03:44 -0500126// ----------------------------------------------------------------------------
127// android/graphics/Canvas state operations
128// ----------------------------------------------------------------------------
129 // Save (layer)
Chris Craikd41c4d82015-01-05 15:51:13 -0800130 virtual int getSaveCount() const override { return mState.getSaveCount(); }
131 virtual int save(SkCanvas::SaveFlags flags) override;
132 virtual void restore() override;
133 virtual void restoreToCount(int saveCount) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500134
135 virtual int saveLayer(float left, float top, float right, float bottom, const SkPaint* paint,
Chris Craikd41c4d82015-01-05 15:51:13 -0800136 SkCanvas::SaveFlags flags) override;
Tom Hudson8dfaa492014-12-09 15:03:44 -0500137 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Chris Craikd41c4d82015-01-05 15:51:13 -0800138 int alpha, SkCanvas::SaveFlags flags) override {
Tom Hudson8dfaa492014-12-09 15:03:44 -0500139 SkPaint paint;
140 paint.setAlpha(alpha);
141 return saveLayer(left, top, right, bottom, &paint, flags);
142 }
143
144 // Matrix
Chris Craikd41c4d82015-01-05 15:51:13 -0800145 virtual void getMatrix(SkMatrix* outMatrix) const override { mState.getMatrix(outMatrix); }
146 virtual void setMatrix(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 drawTextOnPath(const uint16_t* glyphs, int count, const SkPath& path,
Chris Craikd41c4d82015-01-05 15:51:13 -0800217 float hOffset, float vOffset, const SkPaint& paint) override;
218 virtual bool drawTextAbsolutePos() const override { return false; }
Tom Hudson8dfaa492014-12-09 15:03:44 -0500219
220
Romain Guy4aa90572010-09-26 18:40:37 -0700221private:
Tom Hudson984162f2014-10-10 13:38:16 -0400222
223 CanvasState mState;
Derek Sollenberger1db141f2014-12-16 08:37:20 -0500224 std::unique_ptr<SkiaCanvasProxy> mSkiaCanvasProxy;
Tom Hudson984162f2014-10-10 13:38:16 -0400225
Chris Craik8afd0f22014-08-21 17:41:57 -0700226 enum DeferredBarrierType {
227 kBarrier_None,
228 kBarrier_InOrder,
229 kBarrier_OutOfOrder,
230 };
231
Derek Sollenberger94394b32015-07-10 09:58:41 -0400232 void drawBitmap(const SkBitmap* bitmap, const SkPaint* paint);
233 void drawRects(const float* rects, int count, const SkPaint* paint);
234
Chris Craik8afd0f22014-08-21 17:41:57 -0700235 void flushRestoreToCount();
236 void flushTranslate();
237 void flushReorderBarrier();
Romain Guy27454a42011-01-23 12:01:41 -0800238
Chris Craik003cc3d2015-10-16 10:24:55 -0700239 LinearAllocator& alloc() { return mDisplayList->allocator; }
Chris Craikb3cca872014-08-08 18:42:51 -0700240
241 // Each method returns final index of op
Chris Craik8afd0f22014-08-21 17:41:57 -0700242 size_t addOpAndUpdateChunk(DisplayListOp* op);
243 // flushes any deferred operations, and appends the op
244 size_t flushAndAddOp(DisplayListOp* op);
245
246 size_t addStateOp(StateOp* op);
247 size_t addDrawOp(DrawOp* op);
248 size_t addRenderNodeOp(DrawRenderNodeOp* op);
249
John Reck37b08242015-06-09 13:12:40 -0700250 void refBitmapsInShader(const SkShader* shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700251
Chris Craik2af46352012-11-26 18:30:17 -0800252 template<class T>
Chris Craikd218a922014-01-02 17:13:34 -0800253 inline const T* refBuffer(const T* srcBuffer, int32_t count) {
Chris Craike84a2082014-12-22 14:28:49 -0800254 if (!srcBuffer) return nullptr;
Chris Craikd218a922014-01-02 17:13:34 -0800255
Chris Craik003cc3d2015-10-16 10:24:55 -0700256 T* dstBuffer = (T*) mDisplayList->allocator.alloc(count * sizeof(T));
Chris Craik2af46352012-11-26 18:30:17 -0800257 memcpy(dstBuffer, srcBuffer, count * sizeof(T));
258 return dstBuffer;
Romain Guy33f6beb2012-02-16 19:24:51 -0800259 }
260
Chris Craik2af46352012-11-26 18:30:17 -0800261 inline char* refText(const char* text, size_t byteLength) {
262 return (char*) refBuffer<uint8_t>((uint8_t*)text, byteLength);
Romain Guy33f6beb2012-02-16 19:24:51 -0800263 }
264
Chris Craikd218a922014-01-02 17:13:34 -0800265 inline const SkPath* refPath(const SkPath* path) {
Chris Craike84a2082014-12-22 14:28:49 -0800266 if (!path) return nullptr;
Romain Guy2fc941e2011-02-03 15:06:05 -0800267
Derek Sollenbergeree248592015-02-12 14:10:21 -0500268 // The points/verbs within the path are refcounted so this copy operation
269 // is inexpensive and maintains the generationID of the original path.
270 const SkPath* cachedPath = new SkPath(*path);
Chris Craik003cc3d2015-10-16 10:24:55 -0700271 mDisplayList->pathResources.push_back(cachedPath);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800272 return cachedPath;
Romain Guy4aa90572010-09-26 18:40:37 -0700273 }
274
Chris Craikd218a922014-01-02 17:13:34 -0800275 inline const SkPaint* refPaint(const SkPaint* paint) {
Chris Craike84a2082014-12-22 14:28:49 -0800276 if (!paint) return nullptr;
Romain Guy0fe478e2010-11-08 12:08:41 -0800277
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400278 // If there is a draw filter apply it here and store the modified paint
279 // so that we don't need to modify the paint every time we access it.
Chris Craikda3198a2014-11-21 22:05:46 +0000280 SkTLazy<SkPaint> filteredPaint;
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400281 if (mDrawFilter.get()) {
Derek Sollenberger0b860622015-03-25 10:08:30 -0400282 filteredPaint.set(*paint);
Chris Craik51d6a3d2014-12-22 17:16:56 -0800283 mDrawFilter->filter(filteredPaint.get(), SkDrawFilter::kPaint_Type);
Derek Sollenberger0b860622015-03-25 10:08:30 -0400284 paint = filteredPaint.get();
Chet Haased98aa2d2010-10-25 15:47:32 -0700285 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800286
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400287 // compute the hash key for the paint and check the cache.
288 const uint32_t key = paint->getHash();
289 const SkPaint* cachedPaint = mPaintMap.valueFor(key);
290 // In the unlikely event that 2 unique paints have the same hash we do a
291 // object equality check to ensure we don't erroneously dedup them.
Chris Craike84a2082014-12-22 14:28:49 -0800292 if (cachedPaint == nullptr || *cachedPaint != *paint) {
Chris Craik51d6a3d2014-12-22 17:16:56 -0800293 cachedPaint = new SkPaint(*paint);
294 std::unique_ptr<const SkPaint> copy(cachedPaint);
Chris Craik003cc3d2015-10-16 10:24:55 -0700295 mDisplayList->paints.push_back(std::move(copy));
Chris Craik51d6a3d2014-12-22 17:16:56 -0800296
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400297 // replaceValueFor() performs an add if the entry doesn't exist
298 mPaintMap.replaceValueFor(key, cachedPaint);
John Reck37b08242015-06-09 13:12:40 -0700299 refBitmapsInShader(cachedPaint->getShader());
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400300 }
301
302 return cachedPaint;
Romain Guy0fe478e2010-11-08 12:08:41 -0800303 }
304
Chris Craikd218a922014-01-02 17:13:34 -0800305 inline const SkRegion* refRegion(const SkRegion* region) {
Romain Guy735738c2012-12-03 12:34:51 -0800306 if (!region) {
Romain Guy735738c2012-12-03 12:34:51 -0800307 return region;
308 }
309
Chris Craik51d6a3d2014-12-22 17:16:56 -0800310 const SkRegion* cachedRegion = mRegionMap.valueFor(region);
Romain Guy735738c2012-12-03 12:34:51 -0800311 // TODO: Add generation ID to SkRegion
Chris Craik51d6a3d2014-12-22 17:16:56 -0800312 if (cachedRegion == nullptr) {
313 std::unique_ptr<const SkRegion> copy(new SkRegion(*region));
314 cachedRegion = copy.get();
Chris Craik003cc3d2015-10-16 10:24:55 -0700315 mDisplayList->regions.push_back(std::move(copy));
Chris Craik51d6a3d2014-12-22 17:16:56 -0800316
Romain Guy735738c2012-12-03 12:34:51 -0800317 // replaceValueFor() performs an add if the entry doesn't exist
Chris Craik51d6a3d2014-12-22 17:16:56 -0800318 mRegionMap.replaceValueFor(region, cachedRegion);
Romain Guy735738c2012-12-03 12:34:51 -0800319 }
320
Chris Craik51d6a3d2014-12-22 17:16:56 -0800321 return cachedRegion;
Romain Guy735738c2012-12-03 12:34:51 -0800322 }
323
John Reck7c103a32015-04-15 15:52:10 -0700324 inline const SkBitmap* refBitmap(const SkBitmap& bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700325 // Note that this assumes the bitmap is immutable. There are cases this won't handle
326 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
327 // contents, and drawing again. The only fix would be to always copy it the first time,
328 // which doesn't seem worth the extra cycles for this unlikely case.
John Reck98ae4df2015-05-07 13:50:55 -0700329 SkBitmap* localBitmap = new (alloc()) SkBitmap(bitmap);
John Recke75ab4c2015-05-07 13:14:15 -0700330 alloc().autoDestroy(localBitmap);
Chris Craik003cc3d2015-10-16 10:24:55 -0700331 mDisplayList->bitmapResources.push_back(localBitmap);
John Recke75ab4c2015-05-07 13:14:15 -0700332 return localBitmap;
Romain Guy49c5fc02012-05-15 11:10:01 -0700333 }
334
Chris Craikd218a922014-01-02 17:13:34 -0800335 inline const Res_png_9patch* refPatch(const Res_png_9patch* patch) {
Chris Craik003cc3d2015-10-16 10:24:55 -0700336 mDisplayList->patchResources.push_back(patch);
John Recka35778c72014-11-06 09:45:10 -0800337 mResourceCache.incrementRefcount(patch);
Romain Guye3b0a012013-06-26 15:45:41 -0700338 return patch;
339 }
340
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400341 DefaultKeyedVector<uint32_t, const SkPaint*> mPaintMap;
Chris Craikd218a922014-01-02 17:13:34 -0800342 DefaultKeyedVector<const SkPath*, const SkPath*> mPathMap;
Chris Craikd218a922014-01-02 17:13:34 -0800343 DefaultKeyedVector<const SkRegion*, const SkRegion*> mRegionMap;
Romain Guy24c00212011-01-14 15:31:00 -0800344
John Recka35778c72014-11-06 09:45:10 -0800345 ResourceCache& mResourceCache;
Chris Craik003cc3d2015-10-16 10:24:55 -0700346 DisplayList* mDisplayList;
Romain Guy58ecc202012-09-07 11:58:36 -0700347
Romain Guy33f6beb2012-02-16 19:24:51 -0800348 float mTranslateX;
349 float mTranslateY;
Chris Craik8afd0f22014-08-21 17:41:57 -0700350 bool mHasDeferredTranslate;
351 DeferredBarrierType mDeferredBarrierType;
Chris Craikcce47eb2014-07-16 15:12:15 -0700352 bool mHighContrastText;
Romain Guy54c1a642012-09-27 17:55:46 -0700353
Chris Craikeea6ef92014-03-05 16:37:35 -0800354 int mRestoreSaveCount;
355
Derek Sollenberger09c2d4f2014-10-15 09:21:10 -0400356 SkAutoTUnref<SkDrawFilter> mDrawFilter;
357
John Recke18264b2014-03-12 13:56:30 -0700358 friend class RenderNode;
Romain Guyb051e892010-09-28 19:09:36 -0700359
Chris Craikdb663fe2015-04-20 13:34:45 -0700360}; // class DisplayListCanvas
Romain Guy4aa90572010-09-26 18:40:37 -0700361
362}; // namespace uirenderer
363}; // namespace android
364
Romain Guy5b3b3522010-10-27 18:57:51 -0700365#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H