blob: 8cd7fea07d0173cd6536e24c22afe483acac984d [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
Chet Haase9c1e23b2011-03-24 10:51:31 -070029#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070030#include "OpenGLRenderer.h"
Romain Guy7d7b5492011-01-24 16:33:45 -080031#include "utils/Functor.h"
Romain Guy4aa90572010-09-26 18:40:37 -070032
33namespace android {
34namespace uirenderer {
35
36///////////////////////////////////////////////////////////////////////////////
37// Defines
38///////////////////////////////////////////////////////////////////////////////
39
Romain Guy6d7475d2011-07-27 16:28:21 -070040#define MIN_WRITER_SIZE 4096
Romain Guy4aa90572010-09-26 18:40:37 -070041
Romain Guyffac7fc2011-01-13 17:21:49 -080042// Debug
43#if DEBUG_DISPLAY_LIST
44 #define DISPLAY_LIST_LOGD(...) LOGD(__VA_ARGS__)
45#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
Romain Guyb051e892010-09-28 19:09:36 -070053class DisplayListRenderer;
54
Romain Guy4aa90572010-09-26 18:40:37 -070055/**
Romain Guyb051e892010-09-28 19:09:36 -070056 * Replays recorded drawing commands.
Romain Guy4aa90572010-09-26 18:40:37 -070057 */
Romain Guyb051e892010-09-28 19:09:36 -070058class DisplayList {
Romain Guy4aa90572010-09-26 18:40:37 -070059public:
Romain Guyb051e892010-09-28 19:09:36 -070060 DisplayList(const DisplayListRenderer& recorder);
61 ~DisplayList();
Romain Guy4aa90572010-09-26 18:40:37 -070062
Romain Guyffac7fc2011-01-13 17:21:49 -080063 // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
64 // when modifying this file
Romain Guy4aa90572010-09-26 18:40:37 -070065 enum Op {
Romain Guy04c9d8c2011-08-25 14:01:48 -070066 // Non-drawing operations
Romain Guy2b1847e2011-01-26 13:43:01 -080067 Save = 0,
Romain Guy4aa90572010-09-26 18:40:37 -070068 Restore,
69 RestoreToCount,
70 SaveLayer,
Romain Guy5b3b3522010-10-27 18:57:51 -070071 SaveLayerAlpha,
Romain Guy4aa90572010-09-26 18:40:37 -070072 Translate,
73 Rotate,
74 Scale,
Romain Guy807daf72011-01-18 11:19:19 -080075 Skew,
Romain Guy4aa90572010-09-26 18:40:37 -070076 SetMatrix,
77 ConcatMatrix,
78 ClipRect,
Romain Guy04c9d8c2011-08-25 14:01:48 -070079 // Drawing operations
Romain Guy0fe478e2010-11-08 12:08:41 -080080 DrawDisplayList,
Romain Guy6c319ca2011-01-11 14:29:25 -080081 DrawLayer,
Romain Guy4aa90572010-09-26 18:40:37 -070082 DrawBitmap,
83 DrawBitmapMatrix,
84 DrawBitmapRect,
Romain Guy5a7b4662011-01-20 19:09:30 -080085 DrawBitmapMesh,
Romain Guy4aa90572010-09-26 18:40:37 -070086 DrawPatch,
87 DrawColor,
88 DrawRect,
Romain Guy01d58e42011-01-19 21:54:02 -080089 DrawRoundRect,
90 DrawCircle,
Romain Guyc1cd9ba32011-01-23 14:18:41 -080091 DrawOval,
Romain Guy8b2f5262011-01-23 16:15:02 -080092 DrawArc,
Romain Guy4aa90572010-09-26 18:40:37 -070093 DrawPath,
94 DrawLines,
Romain Guyed6fcb02011-03-21 13:11:28 -070095 DrawPoints,
Romain Guy4aa90572010-09-26 18:40:37 -070096 DrawText,
97 ResetShader,
98 SetupShader,
99 ResetColorFilter,
100 SetupColorFilter,
101 ResetShadow,
Romain Guyffac7fc2011-01-13 17:21:49 -0800102 SetupShadow,
Chet Haasedaf98e92011-01-10 14:10:36 -0800103 DrawGLFunction,
Romain Guy4aa90572010-09-26 18:40:37 -0700104 };
105
Romain Guyffac7fc2011-01-13 17:21:49 -0800106 static const char* OP_NAMES[];
107
Chet Haased63cbd12011-02-03 16:32:46 -0800108 void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
Chet Haase5977baa2011-01-05 18:01:22 -0800109
Romain Guy65b345f2011-07-27 18:51:50 -0700110 size_t getSize();
111
Romain Guycabfcc12011-03-07 18:06:46 -0800112 bool replay(OpenGLRenderer& renderer, Rect& dirty, uint32_t level = 0);
Romain Guyb051e892010-09-28 19:09:36 -0700113
Chet Haaseed30fd82011-04-22 16:18:45 -0700114 void output(OpenGLRenderer& renderer, uint32_t level = 0);
115
Chet Haase9c1e23b2011-03-24 10:51:31 -0700116 static void outputLogBuffer(int fd);
117
Romain Guy04c9d8c2011-08-25 14:01:48 -0700118 void setRenderable(bool renderable) {
119 mIsRenderable = renderable;
120 }
121
122 bool isRenderable() const {
123 return mIsRenderable;
124 }
125
Romain Guyb051e892010-09-28 19:09:36 -0700126private:
127 void init();
128
Chet Haased63cbd12011-02-03 16:32:46 -0800129 void clearResources();
130
Romain Guyb051e892010-09-28 19:09:36 -0700131 class TextContainer {
132 public:
133 size_t length() const {
134 return mByteLength;
135 }
136
137 const char* text() const {
138 return (const char*) mText;
139 }
140
141 size_t mByteLength;
142 const char* mText;
143 };
144
145 SkBitmap* getBitmap() {
Chet Haase5c13d892010-10-08 08:37:55 -0700146 return (SkBitmap*) getInt();
147 }
148
149 SkiaShader* getShader() {
150 return (SkiaShader*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700151 }
152
Chet Haasead93c2b2010-10-22 16:17:12 -0700153 SkiaColorFilter* getColorFilter() {
154 return (SkiaColorFilter*) getInt();
155 }
156
Romain Guyb051e892010-09-28 19:09:36 -0700157 inline int getIndex() {
158 return mReader.readInt();
159 }
160
161 inline int getInt() {
162 return mReader.readInt();
163 }
164
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700165 inline uint32_t getUInt() {
166 return mReader.readU32();
167 }
168
Romain Guyb051e892010-09-28 19:09:36 -0700169 SkMatrix* getMatrix() {
Chet Haase5c13d892010-10-08 08:37:55 -0700170 return (SkMatrix*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700171 }
172
173 SkPath* getPath() {
Romain Guy2fc941e2011-02-03 15:06:05 -0800174 return (SkPath*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700175 }
176
177 SkPaint* getPaint() {
Chet Haase5c13d892010-10-08 08:37:55 -0700178 return (SkPaint*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700179 }
180
Romain Guy0fe478e2010-11-08 12:08:41 -0800181 DisplayList* getDisplayList() {
182 return (DisplayList*) getInt();
183 }
184
Romain Guyb051e892010-09-28 19:09:36 -0700185 inline float getFloat() {
186 return mReader.readScalar();
187 }
188
189 int32_t* getInts(uint32_t& count) {
190 count = getInt();
191 return (int32_t*) mReader.skip(count * sizeof(int32_t));
192 }
193
Romain Guy4bb94202010-10-12 15:59:26 -0700194 uint32_t* getUInts(int8_t& count) {
195 count = getInt();
196 return (uint32_t*) mReader.skip(count * sizeof(uint32_t));
197 }
198
Romain Guyb051e892010-09-28 19:09:36 -0700199 float* getFloats(int& count) {
200 count = getInt();
201 return (float*) mReader.skip(count * sizeof(float));
202 }
203
204 void getText(TextContainer* text) {
205 size_t length = text->mByteLength = getInt();
206 text->mText = (const char*) mReader.skip(length);
207 }
208
Chet Haase5c13d892010-10-08 08:37:55 -0700209 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700210 Vector<SkiaColorFilter*> mFilterResources;
Romain Guyb051e892010-09-28 19:09:36 -0700211
Chet Haased98aa2d2010-10-25 15:47:32 -0700212 Vector<SkPaint*> mPaints;
Romain Guy2fc941e2011-02-03 15:06:05 -0800213 Vector<SkPath*> mPaths;
Chet Haased98aa2d2010-10-25 15:47:32 -0700214 Vector<SkMatrix*> mMatrices;
Romain Guy24c00212011-01-14 15:31:00 -0800215 Vector<SkiaShader*> mShaders;
Chet Haased98aa2d2010-10-25 15:47:32 -0700216
Romain Guyb051e892010-09-28 19:09:36 -0700217 mutable SkFlattenableReadBuffer mReader;
Romain Guy65b345f2011-07-27 18:51:50 -0700218
219 size_t mSize;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700220
221 bool mIsRenderable;
Romain Guyb051e892010-09-28 19:09:36 -0700222};
223
224///////////////////////////////////////////////////////////////////////////////
225// Renderer
226///////////////////////////////////////////////////////////////////////////////
227
228/**
229 * Records drawing commands in a display list for latter playback.
230 */
231class DisplayListRenderer: public OpenGLRenderer {
232public:
233 DisplayListRenderer();
234 ~DisplayListRenderer();
235
Jeff Brown162a0212011-07-21 17:02:54 -0700236 DisplayList* getDisplayList(DisplayList* displayList);
Chet Haase5977baa2011-01-05 18:01:22 -0800237
Romain Guyb051e892010-09-28 19:09:36 -0700238 void setViewport(int width, int height);
Romain Guy7d7b5492011-01-24 16:33:45 -0800239 void prepareDirty(float left, float top, float right, float bottom, bool opaque);
Romain Guy27454a42011-01-23 12:01:41 -0800240 void finish();
Romain Guyb051e892010-09-28 19:09:36 -0700241
Romain Guycabfcc12011-03-07 18:06:46 -0800242 bool callDrawGLFunction(Functor *functor, Rect& dirty);
Romain Guy4aa90572010-09-26 18:40:37 -0700243
Chet Haasedaf98e92011-01-10 14:10:36 -0800244 void interrupt();
245 void resume();
246
Romain Guy4aa90572010-09-26 18:40:37 -0700247 int save(int flags);
248 void restore();
249 void restoreToCount(int saveCount);
250
251 int saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700252 SkPaint* p, int flags);
Romain Guy5b3b3522010-10-27 18:57:51 -0700253 int saveLayerAlpha(float left, float top, float right, float bottom,
254 int alpha, int flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700255
256 void translate(float dx, float dy);
257 void rotate(float degrees);
258 void scale(float sx, float sy);
Romain Guy807daf72011-01-18 11:19:19 -0800259 void skew(float sx, float sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700260
261 void setMatrix(SkMatrix* matrix);
262 void concatMatrix(SkMatrix* matrix);
263
264 bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
265
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700266 bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
267 Rect& dirty, uint32_t level = 0);
Romain Guyada830f2011-01-13 12:13:20 -0800268 void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
Chet Haase5c13d892010-10-08 08:37:55 -0700269 void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
270 void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700271 void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
272 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700273 float dstRight, float dstBottom, SkPaint* paint);
Romain Guy5a7b4662011-01-20 19:09:30 -0800274 void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
275 float* vertices, int* colors, SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700276 void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700277 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700278 float left, float top, float right, float bottom, SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700279 void drawColor(int color, SkXfermode::Mode mode);
Chet Haase5c13d892010-10-08 08:37:55 -0700280 void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
Romain Guy01d58e42011-01-19 21:54:02 -0800281 void drawRoundRect(float left, float top, float right, float bottom,
282 float rx, float ry, SkPaint* paint);
283 void drawCircle(float x, float y, float radius, SkPaint* paint);
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800284 void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
Romain Guy8b2f5262011-01-23 16:15:02 -0800285 void drawArc(float left, float top, float right, float bottom,
286 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700287 void drawPath(SkPath* path, SkPaint* paint);
Chet Haase5c13d892010-10-08 08:37:55 -0700288 void drawLines(float* points, int count, SkPaint* paint);
Romain Guyed6fcb02011-03-21 13:11:28 -0700289 void drawPoints(float* points, int count, SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700290 void drawText(const char* text, int bytesCount, int count, float x, float y, SkPaint* paint);
291
292 void resetShader();
293 void setupShader(SkiaShader* shader);
294
295 void resetColorFilter();
296 void setupColorFilter(SkiaColorFilter* filter);
297
298 void resetShadow();
299 void setupShadow(float radius, float dx, float dy, int color);
300
301 void reset();
302
Romain Guyb051e892010-09-28 19:09:36 -0700303 const SkWriter32& writeStream() const {
304 return mWriter;
305 }
306
Chet Haase5c13d892010-10-08 08:37:55 -0700307 const Vector<SkBitmap*>& getBitmapResources() const {
308 return mBitmapResources;
Romain Guyb051e892010-09-28 19:09:36 -0700309 }
310
Romain Guyd586ad92011-06-22 16:14:36 -0700311 const Vector<SkiaColorFilter*>& getFilterResources() const {
312 return mFilterResources;
313 }
314
Romain Guy24c00212011-01-14 15:31:00 -0800315 const Vector<SkiaShader*>& getShaders() const {
316 return mShaders;
Romain Guyb051e892010-09-28 19:09:36 -0700317 }
318
Chet Haased98aa2d2010-10-25 15:47:32 -0700319 const Vector<SkPaint*>& getPaints() const {
320 return mPaints;
321 }
322
Romain Guy2fc941e2011-02-03 15:06:05 -0800323 const Vector<SkPath*>& getPaths() const {
324 return mPaths;
325 }
326
Chet Haased98aa2d2010-10-25 15:47:32 -0700327 const Vector<SkMatrix*>& getMatrices() const {
328 return mMatrices;
329 }
330
Romain Guy4aa90572010-09-26 18:40:37 -0700331private:
Romain Guy27454a42011-01-23 12:01:41 -0800332 void insertRestoreToCount() {
333 if (mRestoreSaveCount >= 0) {
334 mWriter.writeInt(DisplayList::RestoreToCount);
335 addInt(mRestoreSaveCount);
336 mRestoreSaveCount = -1;
337 }
338 }
339
Romain Guyb051e892010-09-28 19:09:36 -0700340 inline void addOp(DisplayList::Op drawOp) {
Romain Guy27454a42011-01-23 12:01:41 -0800341 insertRestoreToCount();
Romain Guy4aa90572010-09-26 18:40:37 -0700342 mWriter.writeInt(drawOp);
Romain Guy04c9d8c2011-08-25 14:01:48 -0700343 mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList;
Romain Guy4aa90572010-09-26 18:40:37 -0700344 }
345
346 inline void addInt(int value) {
347 mWriter.writeInt(value);
348 }
349
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700350 inline void addSize(uint32_t w, uint32_t h) {
351 mWriter.writeInt(w);
352 mWriter.writeInt(h);
353 }
354
Romain Guy4aa90572010-09-26 18:40:37 -0700355 void addInts(const int32_t* values, uint32_t count) {
Romain Guyb051e892010-09-28 19:09:36 -0700356 mWriter.writeInt(count);
Romain Guy4aa90572010-09-26 18:40:37 -0700357 for (uint32_t i = 0; i < count; i++) {
358 mWriter.writeInt(values[i]);
359 }
360 }
361
Romain Guy4bb94202010-10-12 15:59:26 -0700362 void addUInts(const uint32_t* values, int8_t count) {
363 mWriter.writeInt(count);
364 for (int8_t i = 0; i < count; i++) {
365 mWriter.writeInt(values[i]);
366 }
367 }
368
Romain Guy4aa90572010-09-26 18:40:37 -0700369 inline void addFloat(float value) {
370 mWriter.writeScalar(value);
371 }
372
373 void addFloats(const float* values, int count) {
Romain Guyb051e892010-09-28 19:09:36 -0700374 mWriter.writeInt(count);
Romain Guy4aa90572010-09-26 18:40:37 -0700375 for (int i = 0; i < count; i++) {
376 mWriter.writeScalar(values[i]);
377 }
378 }
379
380 inline void addPoint(float x, float y) {
381 mWriter.writeScalar(x);
382 mWriter.writeScalar(y);
383 }
384
385 inline void addBounds(float left, float top, float right, float bottom) {
386 mWriter.writeScalar(left);
387 mWriter.writeScalar(top);
388 mWriter.writeScalar(right);
389 mWriter.writeScalar(bottom);
390 }
391
392 inline void addText(const void* text, size_t byteLength) {
393 mWriter.writeInt(byteLength);
394 mWriter.writePad(text, byteLength);
395 }
396
Romain Guy2fc941e2011-02-03 15:06:05 -0800397 inline void addPath(SkPath* path) {
398 if (!path) {
399 addInt((int) NULL);
400 return;
Romain Guy4aa90572010-09-26 18:40:37 -0700401 }
Romain Guy2fc941e2011-02-03 15:06:05 -0800402
403 SkPath* pathCopy = mPathMap.valueFor(path);
404 if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
Romain Guyb29cfbf2011-03-18 16:24:19 -0700405 pathCopy = new SkPath(*path);
Romain Guy2fc941e2011-02-03 15:06:05 -0800406 mPathMap.add(path, pathCopy);
Romain Guyb29cfbf2011-03-18 16:24:19 -0700407 mPaths.add(pathCopy);
Romain Guy2fc941e2011-02-03 15:06:05 -0800408 }
409
410 addInt((int) pathCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700411 }
412
Chet Haase5c13d892010-10-08 08:37:55 -0700413 inline void addPaint(SkPaint* paint) {
Romain Guy24c00212011-01-14 15:31:00 -0800414 if (!paint) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800415 addInt((int) NULL);
Chet Haased98aa2d2010-10-25 15:47:32 -0700416 return;
417 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800418
Romain Guy24c00212011-01-14 15:31:00 -0800419 SkPaint* paintCopy = mPaintMap.valueFor(paint);
Chet Haased98aa2d2010-10-25 15:47:32 -0700420 if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) {
421 paintCopy = new SkPaint(*paint);
422 mPaintMap.add(paint, paintCopy);
423 mPaints.add(paintCopy);
424 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800425
426 addInt((int) paintCopy);
427 }
428
429 inline void addDisplayList(DisplayList* displayList) {
430 // TODO: To be safe, the display list should be ref-counted in the
431 // resources cache, but we rely on the caller (UI toolkit) to
432 // do the right thing for now
433 addInt((int) displayList);
Romain Guy4aa90572010-09-26 18:40:37 -0700434 }
435
Chet Haase5c13d892010-10-08 08:37:55 -0700436 inline void addMatrix(SkMatrix* matrix) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700437 // Copying the matrix is cheap and prevents against the user changing the original
438 // matrix before the operation that uses it
Romain Guyf6a63ae2011-06-22 15:13:09 -0700439 SkMatrix* copy = new SkMatrix(*matrix);
440 addInt((int) copy);
441 mMatrices.add(copy);
Romain Guy4aa90572010-09-26 18:40:37 -0700442 }
443
Chet Haase5c13d892010-10-08 08:37:55 -0700444 inline void addBitmap(SkBitmap* bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700445 // Note that this assumes the bitmap is immutable. There are cases this won't handle
446 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
447 // contents, and drawing again. The only fix would be to always copy it the first time,
448 // which doesn't seem worth the extra cycles for this unlikely case.
Romain Guy0fe478e2010-11-08 12:08:41 -0800449 addInt((int) bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700450 mBitmapResources.add(bitmap);
Romain Guyd586ad92011-06-22 16:14:36 -0700451 Caches::getInstance().resourceCache.incrementRefcount(bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700452 }
Romain Guy4aa90572010-09-26 18:40:37 -0700453
Chet Haase5c13d892010-10-08 08:37:55 -0700454 inline void addShader(SkiaShader* shader) {
Romain Guy24c00212011-01-14 15:31:00 -0800455 if (!shader) {
456 addInt((int) NULL);
457 return;
458 }
459
460 SkiaShader* shaderCopy = mShaderMap.valueFor(shader);
461 // TODO: We also need to handle generation ID changes in compose shaders
Romain Guy1f1fcb72011-01-14 15:37:54 -0800462 if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) {
Romain Guy24c00212011-01-14 15:31:00 -0800463 shaderCopy = shader->copy();
464 mShaderMap.add(shader, shaderCopy);
Romain Guy1f1fcb72011-01-14 15:37:54 -0800465 mShaders.add(shaderCopy);
Romain Guy43ccf462011-01-14 18:51:01 -0800466 Caches::getInstance().resourceCache.incrementRefcount(shaderCopy);
Romain Guy24c00212011-01-14 15:31:00 -0800467 }
468
469 addInt((int) shaderCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700470 }
471
Chet Haasead93c2b2010-10-22 16:17:12 -0700472 inline void addColorFilter(SkiaColorFilter* colorFilter) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800473 addInt((int) colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700474 mFilterResources.add(colorFilter);
Romain Guyd586ad92011-06-22 16:14:36 -0700475 Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700476 }
477
Chet Haase5c13d892010-10-08 08:37:55 -0700478 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700479 Vector<SkiaColorFilter*> mFilterResources;
Romain Guy4aa90572010-09-26 18:40:37 -0700480
Chet Haased98aa2d2010-10-25 15:47:32 -0700481 Vector<SkPaint*> mPaints;
Romain Guy0fe478e2010-11-08 12:08:41 -0800482 DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap;
Romain Guy24c00212011-01-14 15:31:00 -0800483
Romain Guy2fc941e2011-02-03 15:06:05 -0800484 Vector<SkPath*> mPaths;
485 DefaultKeyedVector<SkPath*, SkPath*> mPathMap;
486
Romain Guy24c00212011-01-14 15:31:00 -0800487 Vector<SkiaShader*> mShaders;
488 DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap;
489
Chet Haased98aa2d2010-10-25 15:47:32 -0700490 Vector<SkMatrix*> mMatrices;
491
Romain Guy4aa90572010-09-26 18:40:37 -0700492 SkWriter32 mWriter;
493
Romain Guy27454a42011-01-23 12:01:41 -0800494 int mRestoreSaveCount;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700495 bool mHasDrawOps;
Romain Guy27454a42011-01-23 12:01:41 -0800496
Romain Guyb051e892010-09-28 19:09:36 -0700497 friend class DisplayList;
498
Romain Guy4aa90572010-09-26 18:40:37 -0700499}; // class DisplayListRenderer
500
501}; // namespace uirenderer
502}; // namespace android
503
Romain Guy5b3b3522010-10-27 18:57:51 -0700504#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H