blob: 43617e7b8b02dfdce787609c3df17c7e023e603e [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>
Chet Haasea1cff502012-02-21 13:43:44 -080023#include <SkCamera.h>
Romain Guy4aa90572010-09-26 18:40:37 -070024#include <SkPaint.h>
25#include <SkPath.h>
Romain Guy4aa90572010-09-26 18:40:37 -070026#include <SkRefCnt.h>
27#include <SkTDArray.h>
28#include <SkTSearch.h>
29
Romain Guy79537452011-10-12 13:48:51 -070030#include <cutils/compiler.h>
31
Chet Haase9c1e23b2011-03-24 10:51:31 -070032#include "DisplayListLogBuffer.h"
Romain Guy4aa90572010-09-26 18:40:37 -070033#include "OpenGLRenderer.h"
34
35namespace android {
36namespace uirenderer {
37
38///////////////////////////////////////////////////////////////////////////////
39// Defines
40///////////////////////////////////////////////////////////////////////////////
41
Romain Guy6d7475d2011-07-27 16:28:21 -070042#define MIN_WRITER_SIZE 4096
Romain Guy33f6beb2012-02-16 19:24:51 -080043#define OP_MAY_BE_SKIPPED_MASK 0xff000000
Romain Guy4aa90572010-09-26 18:40:37 -070044
Romain Guyffac7fc2011-01-13 17:21:49 -080045// Debug
46#if DEBUG_DISPLAY_LIST
Steve Block5baa3a62011-12-20 16:23:08 +000047 #define DISPLAY_LIST_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyffac7fc2011-01-13 17:21:49 -080048#else
49 #define DISPLAY_LIST_LOGD(...)
50#endif
51
Chet Haasea1cff502012-02-21 13:43:44 -080052// Set to 1 to enable native processing of View properties. 0 by default. Eventually this
53// will go away and we will always use this approach for accelerated apps.
54#define USE_DISPLAY_LIST_PROPERTIES 0
55
56#define TRANSLATION 0x0001
57#define ROTATION 0x0002
58#define ROTATION_3D 0x0004
59#define SCALE 0x0008
60#define PIVOT 0x0010
61
Romain Guy4aa90572010-09-26 18:40:37 -070062///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070063// Display list
Romain Guy4aa90572010-09-26 18:40:37 -070064///////////////////////////////////////////////////////////////////////////////
65
Romain Guyb051e892010-09-28 19:09:36 -070066class DisplayListRenderer;
67
Romain Guy4aa90572010-09-26 18:40:37 -070068/**
Romain Guyb051e892010-09-28 19:09:36 -070069 * Replays recorded drawing commands.
Romain Guy4aa90572010-09-26 18:40:37 -070070 */
Romain Guyb051e892010-09-28 19:09:36 -070071class DisplayList {
Romain Guy4aa90572010-09-26 18:40:37 -070072public:
Romain Guyb051e892010-09-28 19:09:36 -070073 DisplayList(const DisplayListRenderer& recorder);
Romain Guy79537452011-10-12 13:48:51 -070074 ANDROID_API ~DisplayList();
Romain Guy4aa90572010-09-26 18:40:37 -070075
Romain Guyffac7fc2011-01-13 17:21:49 -080076 // IMPORTANT: Update the intialization of OP_NAMES in the .cpp file
77 // when modifying this file
Romain Guy4aa90572010-09-26 18:40:37 -070078 enum Op {
Romain Guy04c9d8c2011-08-25 14:01:48 -070079 // Non-drawing operations
Romain Guy2b1847e2011-01-26 13:43:01 -080080 Save = 0,
Romain Guy4aa90572010-09-26 18:40:37 -070081 Restore,
82 RestoreToCount,
83 SaveLayer,
Romain Guy5b3b3522010-10-27 18:57:51 -070084 SaveLayerAlpha,
Romain Guy4aa90572010-09-26 18:40:37 -070085 Translate,
86 Rotate,
87 Scale,
Romain Guy807daf72011-01-18 11:19:19 -080088 Skew,
Romain Guy4aa90572010-09-26 18:40:37 -070089 SetMatrix,
90 ConcatMatrix,
91 ClipRect,
Romain Guy04c9d8c2011-08-25 14:01:48 -070092 // Drawing operations
Romain Guy0fe478e2010-11-08 12:08:41 -080093 DrawDisplayList,
Romain Guy6c319ca2011-01-11 14:29:25 -080094 DrawLayer,
Romain Guy4aa90572010-09-26 18:40:37 -070095 DrawBitmap,
96 DrawBitmapMatrix,
97 DrawBitmapRect,
Romain Guy5a7b4662011-01-20 19:09:30 -080098 DrawBitmapMesh,
Romain Guy4aa90572010-09-26 18:40:37 -070099 DrawPatch,
100 DrawColor,
101 DrawRect,
Romain Guy01d58e42011-01-19 21:54:02 -0800102 DrawRoundRect,
103 DrawCircle,
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800104 DrawOval,
Romain Guy8b2f5262011-01-23 16:15:02 -0800105 DrawArc,
Romain Guy4aa90572010-09-26 18:40:37 -0700106 DrawPath,
107 DrawLines,
Romain Guyed6fcb02011-03-21 13:11:28 -0700108 DrawPoints,
Romain Guy4aa90572010-09-26 18:40:37 -0700109 DrawText,
Romain Guy325740f2012-02-24 16:48:34 -0800110 DrawTextOnPath,
Romain Guyeb9a5362012-01-17 17:39:26 -0800111 DrawPosText,
Romain Guy4aa90572010-09-26 18:40:37 -0700112 ResetShader,
113 SetupShader,
114 ResetColorFilter,
115 SetupColorFilter,
116 ResetShadow,
Romain Guyffac7fc2011-01-13 17:21:49 -0800117 SetupShadow,
Romain Guy5ff9df62012-01-23 17:09:05 -0800118 ResetPaintFilter,
119 SetupPaintFilter,
Chet Haasedaf98e92011-01-10 14:10:36 -0800120 DrawGLFunction,
Romain Guy4aa90572010-09-26 18:40:37 -0700121 };
122
Romain Guy33f6beb2012-02-16 19:24:51 -0800123 // See flags defined in DisplayList.java
124 enum ReplayFlag {
125 kReplayFlag_ClipChildren = 0x1
126 };
127
Romain Guyffac7fc2011-01-13 17:21:49 -0800128 static const char* OP_NAMES[];
129
Chet Haasea1cff502012-02-21 13:43:44 -0800130 void setViewProperties(OpenGLRenderer& renderer, uint32_t width, uint32_t height,
131 uint32_t level);
132 void outputViewProperties(OpenGLRenderer& renderer, char* indent);
133
Romain Guy79537452011-10-12 13:48:51 -0700134 ANDROID_API size_t getSize();
Romain Guybb0acdf2012-03-05 13:44:35 -0800135 ANDROID_API static void destroyDisplayListDeferred(DisplayList* displayList);
136 ANDROID_API static void outputLogBuffer(int fd);
137
138 void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
Romain Guy65b345f2011-07-27 18:51:50 -0700139
Chet Haasea1cff502012-02-21 13:43:44 -0800140 bool replay(OpenGLRenderer& renderer, uint32_t width, uint32_t height,
141 Rect& dirty, int32_t flags, uint32_t level = 0);
Romain Guyb051e892010-09-28 19:09:36 -0700142
Chet Haaseed30fd82011-04-22 16:18:45 -0700143 void output(OpenGLRenderer& renderer, uint32_t level = 0);
144
Romain Guy04c9d8c2011-08-25 14:01:48 -0700145 void setRenderable(bool renderable) {
146 mIsRenderable = renderable;
147 }
148
149 bool isRenderable() const {
150 return mIsRenderable;
151 }
152
Romain Guy13631f32012-01-30 17:41:55 -0800153 void setName(const char* name) {
154 if (name) {
155 mName.setTo(name);
156 }
157 }
158
Chet Haasea1cff502012-02-21 13:43:44 -0800159 void setApplicationScale(float scale) {
160 mApplicationScale = scale;
161 }
162
163 void setClipChildren(bool clipChildren) {
164 mClipChildren = clipChildren;
165 }
166
167 void setAlpha(float alpha) {
168 if (alpha != mAlpha) {
169 mAlpha = alpha;
170 mMultipliedAlpha = (int)(255 * alpha);
171 }
172 }
173
174 void setTranslationX(float translationX) {
175 if (translationX != mTranslationX) {
176 mTranslationX = translationX;
177 mMatrixDirty = true;
178 if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) {
179 mMatrixFlags &= ~TRANSLATION;
180 } else {
181 mMatrixFlags |= TRANSLATION;
182 }
183 }
184 }
185
186 void setTranslationY(float translationY) {
187 if (translationY != mTranslationY) {
188 mTranslationY = translationY;
189 mMatrixDirty = true;
190 if (ALMOST_EQUAL(mTranslationX, 0) && ALMOST_EQUAL(mTranslationY, 0)) {
191 mMatrixFlags &= ~TRANSLATION;
192 } else {
193 mMatrixFlags |= TRANSLATION;
194 }
195 }
196 }
197
198 void setRotation(float rotation) {
199 if (rotation != mRotation) {
200 mRotation = rotation;
201 mMatrixDirty = true;
202 if (ALMOST_EQUAL(mRotation, 0)) {
203 mMatrixFlags &= ~ROTATION;
204 } else {
205 mMatrixFlags |= ROTATION;
206 }
207 }
208 }
209
210 void setRotationX(float rotationX) {
211 if (rotationX != mRotationX) {
212 mRotationX = rotationX;
213 mMatrixDirty = true;
214 if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) {
215 mMatrixFlags &= ~ROTATION_3D;
216 } else {
217 mMatrixFlags |= ROTATION_3D;
218 }
219 }
220 }
221
222 void setRotationY(float rotationY) {
223 if (rotationY != mRotationY) {
224 mRotationY = rotationY;
225 mMatrixDirty = true;
226 if (ALMOST_EQUAL(mRotationX, 0) && ALMOST_EQUAL(mRotationY, 0)) {
227 mMatrixFlags &= ~ROTATION_3D;
228 } else {
229 mMatrixFlags |= ROTATION_3D;
230 }
231 }
232 }
233
234 void setScaleX(float scaleX) {
235 if (scaleX != mScaleX) {
236 mScaleX = scaleX;
237 mMatrixDirty = true;
238 if (ALMOST_EQUAL(mScaleX, 1) && ALMOST_EQUAL(mScaleY, 1)) {
239 mMatrixFlags &= ~SCALE;
240 } else {
241 mMatrixFlags |= SCALE;
242 }
243 }
244 }
245
246 void setScaleY(float scaleY) {
247 if (scaleY != mScaleY) {
248 mScaleY = scaleY;
249 mMatrixDirty = true;
250 if (ALMOST_EQUAL(mScaleX, 1) && ALMOST_EQUAL(mScaleY, 1)) {
251 mMatrixFlags &= ~SCALE;
252 } else {
253 mMatrixFlags |= SCALE;
254 }
255 }
256 }
257
258 void setPivotX(float pivotX) {
259 mPivotX = pivotX;
260 mMatrixDirty = true;
261 if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) {
262 mMatrixFlags &= ~PIVOT;
263 } else {
264 mMatrixFlags |= PIVOT;
265 }
266 mPivotExplicitlySet = true;
267 }
268
269 void setPivotY(float pivotY) {
270 mPivotY = pivotY;
271 mMatrixDirty = true;
272 if (ALMOST_EQUAL(mPivotX, 0) && ALMOST_EQUAL(mPivotY, 0)) {
273 mMatrixFlags &= ~PIVOT;
274 } else {
275 mMatrixFlags |= PIVOT;
276 }
277 mPivotExplicitlySet = true;
278 }
279
280 void setCameraDistance(float distance) {
281 if (distance != mCameraDistance) {
282 mCameraDistance = distance;
283 mMatrixDirty = true;
284 if (!mTransformCamera) {
285 mTransformCamera = new Sk3DView();
286 mTransformMatrix3D = new SkMatrix();
287 }
288 mTransformCamera->setCameraLocation(0, 0, distance);
289 }
290 }
291
292 void setLeft(int left) {
293 if (left != mLeft) {
294 mLeft = left;
295 mWidth = mRight - mLeft;
296 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
297 mMatrixDirty = true;
298 }
299 }
300 }
301
302 void setTop(int top) {
303 if (top != mTop) {
304 mTop = top;
305 mHeight = mBottom - mTop;
306 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
307 mMatrixDirty = true;
308 }
309 }
310 }
311
312 void setRight(int right) {
313 if (right != mRight) {
314 mRight = right;
315 mWidth = mRight - mLeft;
316 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
317 mMatrixDirty = true;
318 }
319 }
320 }
321
322 void setBottom(int bottom) {
323 if (bottom != mBottom) {
324 mBottom = bottom;
325 mHeight = mBottom - mTop;
326 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
327 mMatrixDirty = true;
328 }
329 }
330 }
331
332 void setLeftTop(int left, int top) {
333 if (left != mLeft || top != mTop) {
334 mLeft = left;
335 mTop = top;
336 mWidth = mRight - mLeft;
337 mHeight = mBottom - mTop;
338 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
339 mMatrixDirty = true;
340 }
341 }
342 }
343
344 void setLeftTopRightBottom(int left, int top, int right, int bottom) {
345 if (left != mLeft || top != mTop || right != mRight || bottom != mBottom) {
346 mLeft = left;
347 mTop = top;
348 mRight = right;
349 mBottom = bottom;
350 mWidth = mRight - mLeft;
351 mHeight = mBottom - mTop;
352 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
353 mMatrixDirty = true;
354 }
355 }
356 }
357
358 void offsetLeftRight(int offset) {
359 if (offset != 0) {
360 mLeft += offset;
361 mRight += offset;
362 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
363 mMatrixDirty = true;
364 }
365 }
366 }
367
368 void offsetTopBottom(int offset) {
369 if (offset != 0) {
370 mTop += offset;
371 mBottom += offset;
372 if (mMatrixFlags > TRANSLATION && !mPivotExplicitlySet) {
373 mMatrixDirty = true;
374 }
375 }
376 }
377
378 void setCaching(bool caching) {
379 mCaching = caching;
380 }
381
382 void transformRect(float left, float top, float right, float bottom, Rect& result);
383
Romain Guyb051e892010-09-28 19:09:36 -0700384private:
385 void init();
386
Chet Haasea1cff502012-02-21 13:43:44 -0800387 void initProperties();
388
Chet Haased63cbd12011-02-03 16:32:46 -0800389 void clearResources();
390
Chet Haasea1cff502012-02-21 13:43:44 -0800391 void updateMatrix();
392
Romain Guyb051e892010-09-28 19:09:36 -0700393 class TextContainer {
394 public:
395 size_t length() const {
396 return mByteLength;
397 }
398
399 const char* text() const {
400 return (const char*) mText;
401 }
402
403 size_t mByteLength;
404 const char* mText;
405 };
406
407 SkBitmap* getBitmap() {
Chet Haase5c13d892010-10-08 08:37:55 -0700408 return (SkBitmap*) getInt();
409 }
410
411 SkiaShader* getShader() {
412 return (SkiaShader*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700413 }
414
Chet Haasead93c2b2010-10-22 16:17:12 -0700415 SkiaColorFilter* getColorFilter() {
416 return (SkiaColorFilter*) getInt();
417 }
418
Romain Guy33f6beb2012-02-16 19:24:51 -0800419 inline int32_t getIndex() {
Romain Guyb051e892010-09-28 19:09:36 -0700420 return mReader.readInt();
421 }
422
Romain Guy33f6beb2012-02-16 19:24:51 -0800423 inline int32_t getInt() {
Romain Guyb051e892010-09-28 19:09:36 -0700424 return mReader.readInt();
425 }
426
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700427 inline uint32_t getUInt() {
428 return mReader.readU32();
429 }
430
Romain Guyb051e892010-09-28 19:09:36 -0700431 SkMatrix* getMatrix() {
Chet Haase5c13d892010-10-08 08:37:55 -0700432 return (SkMatrix*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700433 }
434
435 SkPath* getPath() {
Romain Guy2fc941e2011-02-03 15:06:05 -0800436 return (SkPath*) getInt();
Romain Guyb051e892010-09-28 19:09:36 -0700437 }
438
Romain Guy5ff9df62012-01-23 17:09:05 -0800439 SkPaint* getPaint(OpenGLRenderer& renderer) {
440 return renderer.filterPaint((SkPaint*) getInt());
Romain Guyb051e892010-09-28 19:09:36 -0700441 }
442
Romain Guy0fe478e2010-11-08 12:08:41 -0800443 DisplayList* getDisplayList() {
444 return (DisplayList*) getInt();
445 }
446
Romain Guyb051e892010-09-28 19:09:36 -0700447 inline float getFloat() {
448 return mReader.readScalar();
449 }
450
451 int32_t* getInts(uint32_t& count) {
452 count = getInt();
453 return (int32_t*) mReader.skip(count * sizeof(int32_t));
454 }
455
Romain Guy4bb94202010-10-12 15:59:26 -0700456 uint32_t* getUInts(int8_t& count) {
457 count = getInt();
458 return (uint32_t*) mReader.skip(count * sizeof(uint32_t));
459 }
460
Romain Guy33f6beb2012-02-16 19:24:51 -0800461 float* getFloats(int32_t& count) {
Romain Guyb051e892010-09-28 19:09:36 -0700462 count = getInt();
463 return (float*) mReader.skip(count * sizeof(float));
464 }
465
466 void getText(TextContainer* text) {
467 size_t length = text->mByteLength = getInt();
468 text->mText = (const char*) mReader.skip(length);
469 }
470
Chet Haase5c13d892010-10-08 08:37:55 -0700471 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700472 Vector<SkiaColorFilter*> mFilterResources;
Romain Guyb051e892010-09-28 19:09:36 -0700473
Chet Haased98aa2d2010-10-25 15:47:32 -0700474 Vector<SkPaint*> mPaints;
Romain Guy2fc941e2011-02-03 15:06:05 -0800475 Vector<SkPath*> mPaths;
Chet Haased98aa2d2010-10-25 15:47:32 -0700476 Vector<SkMatrix*> mMatrices;
Romain Guy24c00212011-01-14 15:31:00 -0800477 Vector<SkiaShader*> mShaders;
Chet Haased98aa2d2010-10-25 15:47:32 -0700478
Romain Guyb051e892010-09-28 19:09:36 -0700479 mutable SkFlattenableReadBuffer mReader;
Romain Guy65b345f2011-07-27 18:51:50 -0700480
481 size_t mSize;
Romain Guy04c9d8c2011-08-25 14:01:48 -0700482
483 bool mIsRenderable;
Romain Guy13631f32012-01-30 17:41:55 -0800484
485 String8 mName;
Chet Haasea1cff502012-02-21 13:43:44 -0800486
487 // View properties
488 float mApplicationScale;
489 bool mClipChildren;
490 float mAlpha;
491 int mMultipliedAlpha;
492 float mTranslationX, mTranslationY;
493 float mRotation, mRotationX, mRotationY;
494 float mScaleX, mScaleY;
495 float mPivotX, mPivotY;
496 float mCameraDistance;
497 int mLeft, mTop, mRight, mBottom;
498 int mWidth, mHeight;
499 int mPrevWidth, mPrevHeight;
500 bool mPivotExplicitlySet;
501 bool mMatrixDirty;
502 bool mMatrixIsIdentity;
503 uint32_t mMatrixFlags;
504 SkMatrix* mTransformMatrix;
505 Sk3DView* mTransformCamera;
506 SkMatrix* mTransformMatrix3D;
507 bool mCaching;
Romain Guyb051e892010-09-28 19:09:36 -0700508};
509
510///////////////////////////////////////////////////////////////////////////////
511// Renderer
512///////////////////////////////////////////////////////////////////////////////
513
514/**
515 * Records drawing commands in a display list for latter playback.
516 */
517class DisplayListRenderer: public OpenGLRenderer {
518public:
Romain Guy79537452011-10-12 13:48:51 -0700519 ANDROID_API DisplayListRenderer();
520 virtual ~DisplayListRenderer();
Romain Guyb051e892010-09-28 19:09:36 -0700521
Romain Guy79537452011-10-12 13:48:51 -0700522 ANDROID_API DisplayList* getDisplayList(DisplayList* displayList);
Chet Haase5977baa2011-01-05 18:01:22 -0800523
Romain Guy79537452011-10-12 13:48:51 -0700524 virtual void setViewport(int width, int height);
525 virtual void prepareDirty(float left, float top, float right, float bottom, bool opaque);
526 virtual void finish();
Romain Guyb051e892010-09-28 19:09:36 -0700527
Romain Guy79537452011-10-12 13:48:51 -0700528 virtual bool callDrawGLFunction(Functor *functor, Rect& dirty);
Romain Guy4aa90572010-09-26 18:40:37 -0700529
Romain Guy79537452011-10-12 13:48:51 -0700530 virtual void interrupt();
531 virtual void resume();
Chet Haasedaf98e92011-01-10 14:10:36 -0800532
Romain Guy79537452011-10-12 13:48:51 -0700533 virtual int save(int flags);
534 virtual void restore();
535 virtual void restoreToCount(int saveCount);
Romain Guy4aa90572010-09-26 18:40:37 -0700536
Romain Guy79537452011-10-12 13:48:51 -0700537 virtual int saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700538 SkPaint* p, int flags);
Romain Guy79537452011-10-12 13:48:51 -0700539 virtual int saveLayerAlpha(float left, float top, float right, float bottom,
Romain Guy5b3b3522010-10-27 18:57:51 -0700540 int alpha, int flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700541
Romain Guy79537452011-10-12 13:48:51 -0700542 virtual void translate(float dx, float dy);
543 virtual void rotate(float degrees);
544 virtual void scale(float sx, float sy);
545 virtual void skew(float sx, float sy);
Romain Guy4aa90572010-09-26 18:40:37 -0700546
Romain Guy79537452011-10-12 13:48:51 -0700547 virtual void setMatrix(SkMatrix* matrix);
548 virtual void concatMatrix(SkMatrix* matrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700549
Romain Guy79537452011-10-12 13:48:51 -0700550 virtual bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op);
Romain Guy4aa90572010-09-26 18:40:37 -0700551
Romain Guy79537452011-10-12 13:48:51 -0700552 virtual bool drawDisplayList(DisplayList* displayList, uint32_t width, uint32_t height,
Romain Guy33f6beb2012-02-16 19:24:51 -0800553 Rect& dirty, int32_t flags, uint32_t level = 0);
Romain Guy79537452011-10-12 13:48:51 -0700554 virtual void drawLayer(Layer* layer, float x, float y, SkPaint* paint);
555 virtual void drawBitmap(SkBitmap* bitmap, float left, float top, SkPaint* paint);
556 virtual void drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, SkPaint* paint);
557 virtual void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
Romain Guy4aa90572010-09-26 18:40:37 -0700558 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700559 float dstRight, float dstBottom, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700560 virtual void drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
Romain Guy5a7b4662011-01-20 19:09:30 -0800561 float* vertices, int* colors, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700562 virtual void drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700563 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700564 float left, float top, float right, float bottom, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700565 virtual void drawColor(int color, SkXfermode::Mode mode);
566 virtual void drawRect(float left, float top, float right, float bottom, SkPaint* paint);
567 virtual void drawRoundRect(float left, float top, float right, float bottom,
Romain Guy01d58e42011-01-19 21:54:02 -0800568 float rx, float ry, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700569 virtual void drawCircle(float x, float y, float radius, SkPaint* paint);
570 virtual void drawOval(float left, float top, float right, float bottom, SkPaint* paint);
571 virtual void drawArc(float left, float top, float right, float bottom,
Romain Guy8b2f5262011-01-23 16:15:02 -0800572 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint);
Romain Guy79537452011-10-12 13:48:51 -0700573 virtual void drawPath(SkPath* path, SkPaint* paint);
574 virtual void drawLines(float* points, int count, SkPaint* paint);
575 virtual void drawPoints(float* points, int count, SkPaint* paint);
576 virtual void drawText(const char* text, int bytesCount, int count, float x, float y,
Romain Guy8f9a9f62011-12-05 11:53:26 -0800577 SkPaint* paint, float length = 1.0f);
Romain Guy325740f2012-02-24 16:48:34 -0800578 virtual void drawTextOnPath(const char* text, int bytesCount, int count, SkPath* path,
579 float hOffset, float vOffset, SkPaint* paint);
Romain Guyeb9a5362012-01-17 17:39:26 -0800580 virtual void drawPosText(const char* text, int bytesCount, int count, const float* positions,
581 SkPaint* paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700582
Romain Guy79537452011-10-12 13:48:51 -0700583 virtual void resetShader();
584 virtual void setupShader(SkiaShader* shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700585
Romain Guy79537452011-10-12 13:48:51 -0700586 virtual void resetColorFilter();
587 virtual void setupColorFilter(SkiaColorFilter* filter);
Romain Guy4aa90572010-09-26 18:40:37 -0700588
Romain Guy79537452011-10-12 13:48:51 -0700589 virtual void resetShadow();
590 virtual void setupShadow(float radius, float dx, float dy, int color);
Romain Guy4aa90572010-09-26 18:40:37 -0700591
Romain Guy5ff9df62012-01-23 17:09:05 -0800592 virtual void resetPaintFilter();
593 virtual void setupPaintFilter(int clearBits, int setBits);
594
Romain Guy79537452011-10-12 13:48:51 -0700595 ANDROID_API void reset();
Romain Guy4aa90572010-09-26 18:40:37 -0700596
Romain Guyb051e892010-09-28 19:09:36 -0700597 const SkWriter32& writeStream() const {
598 return mWriter;
599 }
600
Chet Haase5c13d892010-10-08 08:37:55 -0700601 const Vector<SkBitmap*>& getBitmapResources() const {
602 return mBitmapResources;
Romain Guyb051e892010-09-28 19:09:36 -0700603 }
604
Romain Guyd586ad92011-06-22 16:14:36 -0700605 const Vector<SkiaColorFilter*>& getFilterResources() const {
606 return mFilterResources;
607 }
608
Romain Guy24c00212011-01-14 15:31:00 -0800609 const Vector<SkiaShader*>& getShaders() const {
610 return mShaders;
Romain Guyb051e892010-09-28 19:09:36 -0700611 }
612
Chet Haased98aa2d2010-10-25 15:47:32 -0700613 const Vector<SkPaint*>& getPaints() const {
614 return mPaints;
615 }
616
Romain Guy2fc941e2011-02-03 15:06:05 -0800617 const Vector<SkPath*>& getPaths() const {
618 return mPaths;
619 }
620
Chet Haased98aa2d2010-10-25 15:47:32 -0700621 const Vector<SkMatrix*>& getMatrices() const {
622 return mMatrices;
623 }
624
Romain Guy4aa90572010-09-26 18:40:37 -0700625private:
Romain Guy27454a42011-01-23 12:01:41 -0800626 void insertRestoreToCount() {
627 if (mRestoreSaveCount >= 0) {
628 mWriter.writeInt(DisplayList::RestoreToCount);
629 addInt(mRestoreSaveCount);
630 mRestoreSaveCount = -1;
631 }
632 }
633
Romain Guy33f6beb2012-02-16 19:24:51 -0800634 void insertTranlate() {
635 if (mHasTranslate) {
636 if (mTranslateX != 0.0f || mTranslateY != 0.0f) {
637 mWriter.writeInt(DisplayList::Translate);
638 addPoint(mTranslateX, mTranslateY);
639 mTranslateX = mTranslateY = 0.0f;
640 }
641 mHasTranslate = false;
642 }
643 }
644
645 inline void addOp(const DisplayList::Op drawOp) {
Romain Guy27454a42011-01-23 12:01:41 -0800646 insertRestoreToCount();
Romain Guy33f6beb2012-02-16 19:24:51 -0800647 insertTranlate();
Romain Guy4aa90572010-09-26 18:40:37 -0700648 mWriter.writeInt(drawOp);
Romain Guy04c9d8c2011-08-25 14:01:48 -0700649 mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList;
Romain Guy4aa90572010-09-26 18:40:37 -0700650 }
651
Romain Guy33f6beb2012-02-16 19:24:51 -0800652 uint32_t* addOp(const DisplayList::Op drawOp, const bool reject) {
653 insertRestoreToCount();
654 insertTranlate();
655 mHasDrawOps = mHasDrawOps || drawOp >= DisplayList::DrawDisplayList;
656 if (reject) {
657 mWriter.writeInt(OP_MAY_BE_SKIPPED_MASK | drawOp);
Romain Guyad1daaa2012-03-01 17:33:42 -0800658 mWriter.writeInt(0xdeaddead);
Romain Guy390f8822012-03-13 18:00:10 -0700659 mBufferSize = mWriter.size();
660 return mWriter.peek32(mBufferSize - sizeof(int32_t));
Romain Guy33f6beb2012-02-16 19:24:51 -0800661 }
662 mWriter.writeInt(drawOp);
663 return NULL;
664 }
665
666 inline void addSkip(uint32_t* location) {
667 if (location) {
Romain Guy390f8822012-03-13 18:00:10 -0700668 *location = (int32_t) (mWriter.size() - mBufferSize);
Romain Guy33f6beb2012-02-16 19:24:51 -0800669 }
670 }
671
672 inline void addInt(int32_t value) {
Romain Guy4aa90572010-09-26 18:40:37 -0700673 mWriter.writeInt(value);
674 }
675
Romain Guy7b5b6ab2011-03-14 18:05:08 -0700676 inline void addSize(uint32_t w, uint32_t h) {
677 mWriter.writeInt(w);
678 mWriter.writeInt(h);
679 }
680
Romain Guy4aa90572010-09-26 18:40:37 -0700681 void addInts(const int32_t* values, uint32_t count) {
Romain Guyb051e892010-09-28 19:09:36 -0700682 mWriter.writeInt(count);
Romain Guy4aa90572010-09-26 18:40:37 -0700683 for (uint32_t i = 0; i < count; i++) {
684 mWriter.writeInt(values[i]);
685 }
686 }
687
Romain Guy4bb94202010-10-12 15:59:26 -0700688 void addUInts(const uint32_t* values, int8_t count) {
689 mWriter.writeInt(count);
690 for (int8_t i = 0; i < count; i++) {
691 mWriter.writeInt(values[i]);
692 }
693 }
694
Romain Guy4aa90572010-09-26 18:40:37 -0700695 inline void addFloat(float value) {
696 mWriter.writeScalar(value);
697 }
698
Romain Guy33f6beb2012-02-16 19:24:51 -0800699 void addFloats(const float* values, int32_t count) {
Romain Guyb051e892010-09-28 19:09:36 -0700700 mWriter.writeInt(count);
Romain Guy33f6beb2012-02-16 19:24:51 -0800701 for (int32_t i = 0; i < count; i++) {
Romain Guy4aa90572010-09-26 18:40:37 -0700702 mWriter.writeScalar(values[i]);
703 }
704 }
705
706 inline void addPoint(float x, float y) {
707 mWriter.writeScalar(x);
708 mWriter.writeScalar(y);
709 }
710
711 inline void addBounds(float left, float top, float right, float bottom) {
712 mWriter.writeScalar(left);
713 mWriter.writeScalar(top);
714 mWriter.writeScalar(right);
715 mWriter.writeScalar(bottom);
716 }
717
718 inline void addText(const void* text, size_t byteLength) {
719 mWriter.writeInt(byteLength);
720 mWriter.writePad(text, byteLength);
721 }
722
Romain Guy2fc941e2011-02-03 15:06:05 -0800723 inline void addPath(SkPath* path) {
724 if (!path) {
725 addInt((int) NULL);
726 return;
Romain Guy4aa90572010-09-26 18:40:37 -0700727 }
Romain Guy2fc941e2011-02-03 15:06:05 -0800728
729 SkPath* pathCopy = mPathMap.valueFor(path);
730 if (pathCopy == NULL || pathCopy->getGenerationID() != path->getGenerationID()) {
Romain Guyb29cfbf2011-03-18 16:24:19 -0700731 pathCopy = new SkPath(*path);
Romain Guy4bcb7462012-02-23 17:08:38 -0800732 pathCopy->setSourcePath(path);
Romain Guy96ebc6b2012-02-21 18:32:32 -0800733 // replaceValueFor() performs an add if the entry doesn't exist
734 mPathMap.replaceValueFor(path, pathCopy);
Romain Guyb29cfbf2011-03-18 16:24:19 -0700735 mPaths.add(pathCopy);
Romain Guy2fc941e2011-02-03 15:06:05 -0800736 }
737
738 addInt((int) pathCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700739 }
740
Chet Haase5c13d892010-10-08 08:37:55 -0700741 inline void addPaint(SkPaint* paint) {
Romain Guy24c00212011-01-14 15:31:00 -0800742 if (!paint) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800743 addInt((int) NULL);
Chet Haased98aa2d2010-10-25 15:47:32 -0700744 return;
745 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800746
Romain Guy22d41842012-01-19 18:33:25 -0800747 SkPaint* paintCopy = mPaintMap.valueFor(paint);
Chet Haased98aa2d2010-10-25 15:47:32 -0700748 if (paintCopy == NULL || paintCopy->getGenerationID() != paint->getGenerationID()) {
749 paintCopy = new SkPaint(*paint);
Romain Guy96ebc6b2012-02-21 18:32:32 -0800750 // replaceValueFor() performs an add if the entry doesn't exist
751 mPaintMap.replaceValueFor(paint, paintCopy);
Chet Haased98aa2d2010-10-25 15:47:32 -0700752 mPaints.add(paintCopy);
753 }
Romain Guy0fe478e2010-11-08 12:08:41 -0800754
755 addInt((int) paintCopy);
756 }
757
758 inline void addDisplayList(DisplayList* displayList) {
759 // TODO: To be safe, the display list should be ref-counted in the
760 // resources cache, but we rely on the caller (UI toolkit) to
761 // do the right thing for now
762 addInt((int) displayList);
Romain Guy4aa90572010-09-26 18:40:37 -0700763 }
764
Chet Haase5c13d892010-10-08 08:37:55 -0700765 inline void addMatrix(SkMatrix* matrix) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700766 // Copying the matrix is cheap and prevents against the user changing the original
767 // matrix before the operation that uses it
Romain Guyf6a63ae2011-06-22 15:13:09 -0700768 SkMatrix* copy = new SkMatrix(*matrix);
769 addInt((int) copy);
770 mMatrices.add(copy);
Romain Guy4aa90572010-09-26 18:40:37 -0700771 }
772
Chet Haase5c13d892010-10-08 08:37:55 -0700773 inline void addBitmap(SkBitmap* bitmap) {
Chet Haased98aa2d2010-10-25 15:47:32 -0700774 // Note that this assumes the bitmap is immutable. There are cases this won't handle
775 // correctly, such as creating the bitmap from scratch, drawing with it, changing its
776 // contents, and drawing again. The only fix would be to always copy it the first time,
777 // which doesn't seem worth the extra cycles for this unlikely case.
Romain Guy0fe478e2010-11-08 12:08:41 -0800778 addInt((int) bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700779 mBitmapResources.add(bitmap);
Romain Guyd586ad92011-06-22 16:14:36 -0700780 Caches::getInstance().resourceCache.incrementRefcount(bitmap);
Chet Haase5c13d892010-10-08 08:37:55 -0700781 }
Romain Guy4aa90572010-09-26 18:40:37 -0700782
Chet Haase5c13d892010-10-08 08:37:55 -0700783 inline void addShader(SkiaShader* shader) {
Romain Guy24c00212011-01-14 15:31:00 -0800784 if (!shader) {
785 addInt((int) NULL);
786 return;
787 }
788
789 SkiaShader* shaderCopy = mShaderMap.valueFor(shader);
790 // TODO: We also need to handle generation ID changes in compose shaders
Romain Guy1f1fcb72011-01-14 15:37:54 -0800791 if (shaderCopy == NULL || shaderCopy->getGenerationId() != shader->getGenerationId()) {
Romain Guy24c00212011-01-14 15:31:00 -0800792 shaderCopy = shader->copy();
Romain Guy96ebc6b2012-02-21 18:32:32 -0800793 // replaceValueFor() performs an add if the entry doesn't exist
794 mShaderMap.replaceValueFor(shader, shaderCopy);
Romain Guy1f1fcb72011-01-14 15:37:54 -0800795 mShaders.add(shaderCopy);
Romain Guy43ccf462011-01-14 18:51:01 -0800796 Caches::getInstance().resourceCache.incrementRefcount(shaderCopy);
Romain Guy24c00212011-01-14 15:31:00 -0800797 }
798
799 addInt((int) shaderCopy);
Romain Guy4aa90572010-09-26 18:40:37 -0700800 }
801
Chet Haasead93c2b2010-10-22 16:17:12 -0700802 inline void addColorFilter(SkiaColorFilter* colorFilter) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800803 addInt((int) colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700804 mFilterResources.add(colorFilter);
Romain Guyd586ad92011-06-22 16:14:36 -0700805 Caches::getInstance().resourceCache.incrementRefcount(colorFilter);
Chet Haasead93c2b2010-10-22 16:17:12 -0700806 }
807
Chet Haase5c13d892010-10-08 08:37:55 -0700808 Vector<SkBitmap*> mBitmapResources;
Chet Haasead93c2b2010-10-22 16:17:12 -0700809 Vector<SkiaColorFilter*> mFilterResources;
Romain Guy4aa90572010-09-26 18:40:37 -0700810
Chet Haased98aa2d2010-10-25 15:47:32 -0700811 Vector<SkPaint*> mPaints;
Romain Guy0fe478e2010-11-08 12:08:41 -0800812 DefaultKeyedVector<SkPaint*, SkPaint*> mPaintMap;
Romain Guy24c00212011-01-14 15:31:00 -0800813
Romain Guy2fc941e2011-02-03 15:06:05 -0800814 Vector<SkPath*> mPaths;
815 DefaultKeyedVector<SkPath*, SkPath*> mPathMap;
816
Romain Guy24c00212011-01-14 15:31:00 -0800817 Vector<SkiaShader*> mShaders;
818 DefaultKeyedVector<SkiaShader*, SkiaShader*> mShaderMap;
819
Chet Haased98aa2d2010-10-25 15:47:32 -0700820 Vector<SkMatrix*> mMatrices;
821
Romain Guy4aa90572010-09-26 18:40:37 -0700822 SkWriter32 mWriter;
Romain Guy390f8822012-03-13 18:00:10 -0700823 uint32_t mBufferSize;
Romain Guy4aa90572010-09-26 18:40:37 -0700824
Romain Guy27454a42011-01-23 12:01:41 -0800825 int mRestoreSaveCount;
Romain Guy33f6beb2012-02-16 19:24:51 -0800826
827 float mTranslateX;
828 float mTranslateY;
829 bool mHasTranslate;
830
Romain Guy04c9d8c2011-08-25 14:01:48 -0700831 bool mHasDrawOps;
Romain Guy27454a42011-01-23 12:01:41 -0800832
Romain Guyb051e892010-09-28 19:09:36 -0700833 friend class DisplayList;
834
Romain Guy4aa90572010-09-26 18:40:37 -0700835}; // class DisplayListRenderer
836
837}; // namespace uirenderer
838}; // namespace android
839
Romain Guy5b3b3522010-10-27 18:57:51 -0700840#endif // ANDROID_HWUI_DISPLAY_LIST_RENDERER_H