blob: 5d922db3baccc13b2fc1ce74665bc3733f11fda1 [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
20#include <SkChunkAlloc.h>
21#include <SkFlattenable.h>
22#include <SkMatrix.h>
23#include <SkPaint.h>
24#include <SkPath.h>
Romain Guy4aa90572010-09-26 18:40:37 -070025#include <SkRefCnt.h>
26#include <SkTDArray.h>
27#include <SkTSearch.h>
28
Romain Guy79537452011-10-12 13:48:51 -070029#include <cutils/compiler.h>
30
Chet Haase9c1e23b2011-03-24 10:51:31 -070031#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070032#include "OpenGLRenderer.h"
Romain Guy7d7b5492011-01-24 16:33:45 -080033#include "utils/Functor.h"
Romain Guy4aa90572010-09-26 18:40:37 -070034
35namespace android {
36namespace uirenderer {
37
38///////////////////////////////////////////////////////////////////////////////
39// Defines
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guy6d7475d2011-07-27 16:28:21 -070042#define MIN_WRITER_SIZE 4096
Romain Guy4aa90572010-09-26 18:40:37 -070043
Romain Guyffac7fc2011-01-13 17:21:49 -080044// Debug
45#if DEBUG_DISPLAY_LIST
Steve Block5baa3a62011-12-20 16:23:08 +000046 #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyffac7fc2011-01-13 17:21:49 -080047#else
48 #define DISPLAY_LIST_LOGD(...)
49#endif
50
Romain Guy4aa90572010-09-26 18:40:37 -070051///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070052// Display list
Romain Guy4aa90572010-09-26 18:40:37 -070053///////////////////////////////////////////////////////////////////////////////
54
Romain Guyb051e892010-09-28 19:09:36 -070055class DisplayListRenderer;
56
Romain Guy4aa90572010-09-26 18:40:37 -070057/**
Romain Guyb051e892010-09-28 19:09:36 -070058 * Replays recorded drawing commands.
Romain Guy4aa90572010-09-26 18:40:37 -070059 */
Romain Guyb051e892010-09-28 19:09:36 -070060class DisplayList {
Romain Guy4aa90572010-09-26 18:40:37 -070061public:
Romain Guyb051e892010-09-28 19:09:36 -070062 DisplayList(const DisplayListRenderer& recorder);
Romain Guy79537452011-10-12 13:48:51 -070063 ANDROID_API ~DisplayList();
Romain Guy4aa90572010-09-26 18:40:37 -070064
Romain Guyffac7fc2011-01-13 17:21:49 -080065 // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
66 // when modifying this file
Romain Guy4aa90572010-09-26 18:40:37 -070067 enum Op {
Romain Guy04c9d8c2011-08-25 14:01:48 -070068 // Non-drawing operations
Romain Guy2b1847e2011-01-26 13:43:01 -080069 Save = 0,
Romain Guy4aa90572010-09-26 18:40:37 -070070 Restore,
71 RestoreToCount,
72 SaveLayer,
Romain Guy5b3b3522010-10-27 18:57:51 -070073 SaveLayerAlpha,
Romain Guy4aa90572010-09-26 18:40:37 -070074 Translate,
75 Rotate,
76 Scale,
Romain Guy807daf72011-01-18 11:19:19 -080077 Skew,
Romain Guy4aa90572010-09-26 18:40:37 -070078 SetMatrix,
79 ConcatMatrix,
80 ClipRect,
Romain Guy04c9d8c2011-08-25 14:01:48 -070081 // Drawing operations
Romain Guy0fe478e2010-11-08 12:08:41 -080082 DrawDisplayList,
Romain Guy6c319ca2011-01-11 14:29:25 -080083 DrawLayer,
Romain Guy4aa90572010-09-26 18:40:37 -070084 DrawBitmap,
85 DrawBitmapMatrix,
86 DrawBitmapRect,
Romain Guy5a7b4662011-01-20 19:09:30 -080087 DrawBitmapMesh,
Romain Guy4aa90572010-09-26 18:40:37 -070088 DrawPatch,
89 DrawColor,
90 DrawRect,
Romain Guy01d58e42011-01-19 21:54:02 -080091 DrawRoundRect,
92 DrawCircle,
Romain Guyc1cd9ba32011-01-23 14:18:41 -080093 DrawOval,
Romain Guy8b2f5262011-01-23 16:15:02 -080094 DrawArc,
Romain Guy4aa90572010-09-26 18:40:37 -070095 DrawPath,
96 DrawLines,
Romain Guyed6fcb02011-03-21 13:11:28 -070097 DrawPoints,
Romain Guy4aa90572010-09-26 18:40:37 -070098 DrawText,
99 ResetShader,
100 SetupShader,
101 ResetColorFilter,
102 SetupColorFilter,
103 ResetShadow,
Romain Guyffac7fc2011-01-13 17:21:49 -0800104 SetupShadow,
Chet Haasedaf98e92011-01-10 14:10:36 -0800105 DrawGLFunction,
Romain Guy4aa90572010-09-26 18:40:37 -0700106 };
107
Romain Guyffac7fc2011-01-13 17:21:49 -0800108 static const char* OP_NAMES[];
109
Chet Haased63cbd12011-02-03 16:32:46 -0800110 void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
Chet Haase5977baa2011-01-05 18:01:22 -0800111
Romain Guy79537452011-10-12 13:48:51 -0700112 ANDROID_API size_t getSize();
Romain Guy65b345f2011-07-27 18:51:50 -0700113
Romain Guycabfcc12011-03-07 18:06:46 -0800114 bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0);
Romain Guyb051e892010-09-28 19:09:36 -0700115
Chet Haaseed30fd82011-04-22 16:18:45 -0700116 void output(OpenGLRenderer& renderer, uint32_t level = 0);
117
Romain Guy79537452011-10-12 13:48:51 -0700118 ANDROID_API static void outputLogBuffer(int fd);
Chet Haase9c1e23b2011-03-24 10:51:31 -0700119
Romain Guy04c9d8c2011-08-25 14:01:48 -0700120 void setRenderable(bool renderable) {
121 mIsRenderable = renderable;
122 }
123
124 bool isRenderable() const {
125 return mIsRenderable;
126 }
127
Romain Guyb051e892010-09-28 19:09:36 -0700128private:
129 void init();
130
Chet Haased63cbd12011-02-03 16:32:46 -0800131 void clearResources();
132
Romain Guyb051e892010-09-28 19:09:36 -0700133 class TextContainer {
134 public:
135 size_t length() const {
136 return mByteLength;
137 }
138
139 const char* text() const {
140 return (const char*) mText;
141 }
142
143 size_t mByteLength;
144 const char* mText;
145 };
146
147 SkBitmap* getBitmap() {
Chet Haase5c13d892010-10-08 08:37:55 -0700148 return (SkBitmap*) getInt();
149 }
150
151 SkiaShader* getShader() {
152 return (SkiaShader*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700153 }
154
Chet Haasead93c2b2010-10-22 16:17:12 -0700155 SkiaColorFilter* getColorFilter() {
156 return (SkiaColorFilter*) getInt();
157 }
158
Romain Guyb051e892010-09-28 19:09:36 -0700159 inline int getIndex() {
160 return mReader.readInt();
161 }
162
163 inline int getInt() {
164 return mReader.readInt();
165 }
166
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700167 inline uint32_t getUInt() {
168 return mReader.readU32();
169 }
170
Romain Guyb051e892010-09-28 19:09:36 -0700171 SkMatrix* getMatrix() {
Chet Haase5c13d892010-10-08 08:37:55 -0700172 return (SkMatrix*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700173 }
174
175 SkPath* getPath() {
Romain Guy2fc941e2011-02-03 15:06:05 -0800176 return (SkPath*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700177 }
178
179 SkPaint* getPaint() {
Chet Haase5c13d892010-10-08 08:37:55 -0700180 return (SkPaint*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700181 }
182
Romain Guy0fe478e2010-11-08 12:08:41 -0800183 DisplayList* getDisplayList() {
184 return (DisplayList*) getInt();
185 }
186
Romain Guyb051e892010-09-28 19:09:36 -0700187 inline float getFloat() {
188 return mReader.readScalar();
189 }
190
191 int32_t* getInts(uint32_t& count) {
192 count = getInt();
193 return (int32_t*) mReader.skip(count * sizeof(int32_t));
194 }
195
Romain Guy4bb94202010-10-12 15:59:26 -0700196 uint32_t* getUInts(int8_t& count) {
197 count = getInt();
198 return (uint32_t*) mReader.skip(count * sizeof(uint32_t));
199 }
200
Romain Guyb051e892010-09-28 19:09:36 -0700201 float* getFloats(int& count) {
202 count = getInt();
203 return (float*) mReader.skip(count * sizeof(float));
204 }
205
206 void getText(TextContainer* text) {
207 size_t length = text->mByteLength = getInt();
208 text->mText = (const char*) mReader.skip(length);
209 }
210
Chet Haase5c13d892010-10-08 08:37:55 -0700211 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700212 Vector<SkiaColorFilter*> mFilterResources;
Romain Guyb051e892010-09-28 19:09:36 -0700213
Chet Haased98aa2d2010-10-25 15:47:32 -0700214 Vector<SkPaint*> mPaints;
Romain Guy2fc941e2011-02-03 15:06:05 -0800215 Vector<SkPath*> mPaths;
Chet Haased98aa2d2010-10-25 15:47:32 -0700216 Vector<SkMatrix*> mMatrices;
Romain Guy24c00212011-01-14 15:31:00 -0800217 Vector<SkiaShader*> mShaders;
Chet Haased98aa2d2010-10-25 15:47:32 -0700218
Romain Guyb051e892010-09-28 19:09:36 -0700219 mutable SkFlattenableReadBuffer mReader;
Romain Guy65b345f2011-07-27 18:51:50 -0700220
221 size_t mSize;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700222
223 bool mIsRenderable;
Romain Guyb051e892010-09-28 19:09:36 -0700224};
225
226///////////////////////////////////////////////////////////////////////////////
227// Renderer
228///////////////////////////////////////////////////////////////////////////////
229
230/**
231 * Records drawing commands in a display list for latter playback.
232 */
233class DisplayListRenderer: public OpenGLRenderer {
234public:
Romain Guy79537452011-10-12 13:48:51 -0700235 ANDROID_API DisplayListRenderer();
236 virtual ~DisplayListRenderer();
Romain Guyb051e892010-09-28 19:09:36 -0700237
Romain Guy79537452011-10-12 13:48:51 -0700238 ANDROID_API DisplayList* getDisplayList(DisplayList* displayList);
Chet Haase5977baa2011-01-05 18:01:22 -0800239
Romain Guy79537452011-10-12 13:48:51 -0700240 virtual void setViewport(int width, int height);
241 virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
242 virtual void finish();
Romain Guyb051e892010-09-28 19:09:36 -0700243
Romain Guy79537452011-10-12 13:48:51 -0700244 virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
Romain Guy4aa90572010-09-26 18:40:37 -0700245
Romain Guy79537452011-10-12 13:48:51 -0700246 virtual void interrupt();
247 virtual void resume();
Chet Haasedaf98e92011-01-10 14:10:36 -0800248
Romain Guy79537452011-10-12 13:48:51 -0700249 virtual int save(int flags);
250 virtual void restore();
251 virtual void restoreToCount(int saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700252
Romain Guy79537452011-10-12 13:48:51 -0700253 virtual int saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700254 SkPaint* p, int flags);
Romain Guy79537452011-10-12 13:48:51 -0700255 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Romain Guy5b3b3522010-10-27 18:57:51 -0700256 int alpha, int flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700257
Romain Guy79537452011-10-12 13:48:51 -0700258 virtual void translate(float dx, float dy);
259 virtual void rotate(float degrees);
260 virtual void scale(float sx, float sy);
261 virtual void skew(float sx, float sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700262
Romain Guy79537452011-10-12 13:48:51 -0700263 virtual void setMatrix(SkMatrix* matrix);
264 virtual void concatMatrix(SkMatrix* matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700265
Romain Guy79537452011-10-12 13:48:51 -0700266 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
Romain Guy4aa90572010-09-26 18:40:37 -0700267
Romain Guy79537452011-10-12 13:48:51 -0700268 virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700269 Rect& dirty, uint32_t level = 0);
Romain Guy79537452011-10-12 13:48:51 -0700270 virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
271 virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
272 virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
273 virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700274 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700275 float dstRight, float dstBottom, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700276 virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -0800277 float* vertices, int* colors, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700278 virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700279 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700280 float left, float top, float right, float bottom, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700281 virtual void drawColor(int color, SkXfermode::Mode mode);
282 virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
283 virtual void drawRoundRect(float left, float top, float right, float bottom,
Romain Guy01d58e42011-01-19 21:54:02 -0800284 float rx, float ry, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700285 virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
286 virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
287 virtual void drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -0800288 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700289 virtual void drawPath(SkPath* path, SkPaint* paint);
290 virtual void drawLines(float* points, int count, SkPaint* paint);
291 virtual void drawPoints(float* points, int count, SkPaint* paint);
292 virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
Romain Guy8f9a9f62011-12-05 11:53:26 -0800293 SkPaint* paint, float length = 1.0f);
Romain Guy4aa90572010-09-26 18:40:37 -0700294
Romain Guy79537452011-10-12 13:48:51 -0700295 virtual void resetShader();
296 virtual void setupShader(SkiaShader* shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700297
Romain Guy79537452011-10-12 13:48:51 -0700298 virtual void resetColorFilter();
299 virtual void setupColorFilter(SkiaColorFilter* filter);
Romain Guy4aa90572010-09-26 18:40:37 -0700300
Romain Guy79537452011-10-12 13:48:51 -0700301 virtual void resetShadow();
302 virtual void setupShadow(float radius, float dx, float dy, int color);
Romain Guy4aa90572010-09-26 18:40:37 -0700303
Romain Guy79537452011-10-12 13:48:51 -0700304 ANDROID_API void reset();
Romain Guy4aa90572010-09-26 18:40:37 -0700305
Romain Guyb051e892010-09-28 19:09:36 -0700306 const SkWriter32& writeStream() const {
307 return mWriter;
308 }
309
Chet Haase5c13d892010-10-08 08:37:55 -0700310 const Vector<SkBitmap*>& getBitmapResources() const {
311 return mBitmapResources;
Romain Guyb051e892010-09-28 19:09:36 -0700312 }
313
Romain Guyd586ad92011-06-22 16:14:36 -0700314 const Vector<SkiaColorFilter*>& getFilterResources() const {
315 return mFilterResources;
316 }
317
Romain Guy24c00212011-01-14 15:31:00 -0800318 const Vector<SkiaShader*>& getShaders() const {
319 return mShaders;
Romain Guyb051e892010-09-28 19:09:36 -0700320 }
321
Chet Haased98aa2d2010-10-25 15:47:32 -0700322 const Vector<SkPaint*>& getPaints() const {
323 return mPaints;
324 }
325
Romain Guy2fc941e2011-02-03 15:06:05 -0800326 const Vector<SkPath*>& getPaths() const {
327 return mPaths;
328 }
329
Chet Haased98aa2d2010-10-25 15:47:32 -0700330 const Vector<SkMatrix*>& getMatrices() const {
331 return mMatrices;
332 }
333
Romain Guy4aa90572010-09-26 18:40:37 -0700334private:
Romain Guy27454a42011-01-23 12:01:41 -0800335 void insertRestoreToCount() {
336 if (mRestoreSaveCount >= 0) {
337 mWriter.writeInt(DisplayList::RestoreToCount);
338 addInt(mRestoreSaveCount);
339 mRestoreSaveCount = -1;
340 }
341 }
342
Romain Guyb051e892010-09-28 19:09:36 -0700343 inline void addOp(DisplayList::Op drawOp) {
Romain Guy27454a42011-01-23 12:01:41 -0800344 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -0700345 mWriter.writeInt(drawOp);
Romain Guy04c9d8c2011-08-25 14:01:48 -0700346 mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList;
Romain Guy4aa90572010-09-26 18:40:37 -0700347 }
348
349 inline void addInt(int value) {
350 mWriter.writeInt(value);
351 }
352
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700353 inline void addSize(uint32_t w, uint32_t h) {
354 mWriter.writeInt(w);
355 mWriter.writeInt(h);
356 }
357
Romain Guy4aa90572010-09-26 18:40:37 -0700358 void addInts(const int32_t* values, uint32_t count) {
Romain Guyb051e892010-09-28 19:09:36 -0700359 mWriter.writeInt(count);
Romain Guy4aa90572010-09-26 18:40:37 -0700360 for (uint32_t i = 0; i < count; i++) {
361 mWriter.writeInt(values[i]);
362 }
363 }
364
Romain Guy4bb94202010-10-12 15:59:26 -0700365 void addUInts(const uint32_t* values, int8_t count) {
366 mWriter.writeInt(count);
367 for (int8_t i = 0; i < count; i++) {
368 mWriter.writeInt(values[i]);
369 }
370 }
371
Romain Guy4aa90572010-09-26 18:40:37 -0700372 inline void addFloat(float value) {
373 mWriter.writeScalar(value);
374 }
375
376 void addFloats(const float* values, int count) {
Romain Guyb051e892010-09-28 19:09:36 -0700377 mWriter.writeInt(count);
Romain Guy4aa90572010-09-26 18:40:37 -0700378 for (int i = 0; i < count; i++) {
379 mWriter.writeScalar(values[i]);
380 }
381 }
382
383 inline void addPoint(float x, float y) {
384 mWriter.writeScalar(x);
385 mWriter.writeScalar(y);
386 }
387
388 inline void addBounds(float left, float top, float right, float bottom) {
389 mWriter.writeScalar(left);
390 mWriter.writeScalar(top);
391 mWriter.writeScalar(right);
392 mWriter.writeScalar(bottom);
393 }
394
395 inline void addText(const void* text, size_t byteLength) {
396 mWriter.writeInt(byteLength);
397 mWriter.writePad(text, byteLength);
398 }
399
Romain Guy2fc941e2011-02-03 15:06:05 -0800400 inline void addPath(SkPath* path) {
401 if (!path) {
402 addInt((int) NULL);
403 return;
Romain Guy4aa90572010-09-26 18:40:37 -0700404 }
Romain Guy2fc941e2011-02-03 15:06:05 -0800405
406 SkPath* pathCopy = mPathMap.valueFor(path);
407 if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
Romain Guyb29cfbf2011-03-18 16:24:19 -0700408 pathCopy = new SkPath(*path);
Romain Guy2fc941e2011-02-03 15:06:05 -0800409 mPathMap.add(path, pathCopy);
Romain Guyb29cfbf2011-03-18 16:24:19 -0700410 mPaths.add(pathCopy);
Romain Guy2fc941e2011-02-03 15:06:05 -0800411 }
412
413 addInt((int) pathCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700414 }
415
Chet Haase5c13d892010-10-08 08:37:55 -0700416 inline void addPaint(SkPaint* paint) {
Romain Guy24c00212011-01-14 15:31:00 -0800417 if (!paint) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800418 addInt((int) NULL);
Chet Haased98aa2d2010-10-25 15:47:32 -0700419 return;
420 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800421
Romain Guy24c00212011-01-14 15:31:00 -0800422 SkPaint* paintCopy = mPaintMap.valueFor(paint);
Chet Haased98aa2d2010-10-25 15:47:32 -0700423 if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) {
424 paintCopy = new SkPaint(*paint);
425 mPaintMap.add(paint, paintCopy);
426 mPaints.add(paintCopy);
427 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800428
429 addInt((int) paintCopy);
430 }
431
432 inline void addDisplayList(DisplayList* displayList) {
433 // TODO: To be safe, the display list should be ref-counted in the
434 // resources cache, but we rely on the caller (UI toolkit) to
435 // do the right thing for now
436 addInt((int) displayList);
Romain Guy4aa90572010-09-26 18:40:37 -0700437 }
438
Chet Haase5c13d892010-10-08 08:37:55 -0700439 inline void addMatrix(SkMatrix* matrix) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700440 // Copying the matrix is cheap and prevents against the user changing the original
441 // matrix before the operation that uses it
Romain Guyf6a63ae2011-06-22 15:13:09 -0700442 SkMatrix* copy = new SkMatrix(*matrix);
443 addInt((int) copy);
444 mMatrices.add(copy);
Romain Guy4aa90572010-09-26 18:40:37 -0700445 }
446
Chet Haase5c13d892010-10-08 08:37:55 -0700447 inline void addBitmap(SkBitmap* bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700448 // Note that this assumes the bitmap is immutable. There are cases this won't handle
449 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
450 // contents, and drawing again. The only fix would be to always copy it the first time,
451 // which doesn't seem worth the extra cycles for this unlikely case.
Romain Guy0fe478e2010-11-08 12:08:41 -0800452 addInt((int) bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700453 mBitmapResources.add(bitmap);
Romain Guyd586ad92011-06-22 16:14:36 -0700454 Caches::getInstance().resourceCache.incrementRefcount(bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700455 }
Romain Guy4aa90572010-09-26 18:40:37 -0700456
Chet Haase5c13d892010-10-08 08:37:55 -0700457 inline void addShader(SkiaShader* shader) {
Romain Guy24c00212011-01-14 15:31:00 -0800458 if (!shader) {
459 addInt((int) NULL);
460 return;
461 }
462
463 SkiaShader* shaderCopy = mShaderMap.valueFor(shader);
464 // TODO: We also need to handle generation ID changes in compose shaders
Romain Guy1f1fcb72011-01-14 15:37:54 -0800465 if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) {
Romain Guy24c00212011-01-14 15:31:00 -0800466 shaderCopy = shader->copy();
467 mShaderMap.add(shader, shaderCopy);
Romain Guy1f1fcb72011-01-14 15:37:54 -0800468 mShaders.add(shaderCopy);
Romain Guy43ccf462011-01-14 18:51:01 -0800469 Caches::getInstance().resourceCache.incrementRefcount(shaderCopy);
Romain Guy24c00212011-01-14 15:31:00 -0800470 }
471
472 addInt((int) shaderCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700473 }
474
Chet Haasead93c2b2010-10-22 16:17:12 -0700475 inline void addColorFilter(SkiaColorFilter* colorFilter) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800476 addInt((int) colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700477 mFilterResources.add(colorFilter);
Romain Guyd586ad92011-06-22 16:14:36 -0700478 Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700479 }
480
Chet Haase5c13d892010-10-08 08:37:55 -0700481 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700482 Vector<SkiaColorFilter*> mFilterResources;
Romain Guy4aa90572010-09-26 18:40:37 -0700483
Chet Haased98aa2d2010-10-25 15:47:32 -0700484 Vector<SkPaint*> mPaints;
Romain Guy0fe478e2010-11-08 12:08:41 -0800485 DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap;
Romain Guy24c00212011-01-14 15:31:00 -0800486
Romain Guy2fc941e2011-02-03 15:06:05 -0800487 Vector<SkPath*> mPaths;
488 DefaultKeyedVector<SkPath*, SkPath*> mPathMap;
489
Romain Guy24c00212011-01-14 15:31:00 -0800490 Vector<SkiaShader*> mShaders;
491 DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap;
492
Chet Haased98aa2d2010-10-25 15:47:32 -0700493 Vector<SkMatrix*> mMatrices;
494
Romain Guy4aa90572010-09-26 18:40:37 -0700495 SkWriter32 mWriter;
496
Romain Guy27454a42011-01-23 12:01:41 -0800497 int mRestoreSaveCount;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700498 bool mHasDrawOps;
Romain Guy27454a42011-01-23 12:01:41 -0800499
Romain Guyb051e892010-09-28 19:09:36 -0700500 friend class DisplayList;
501
Romain Guy4aa90572010-09-26 18:40:37 -0700502}; // class DisplayListRenderer
503
504}; // namespace uirenderer
505}; // namespace android
506
Romain Guy5b3b3522010-10-27 18:57:51 -0700507#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H