blob: 87149970366726ab062e8848c14843e4be57f3d4 [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
17#define LOG_TAG "OpenGLRenderer"
18
19#include "DisplayListRenderer.h"
20
21namespace android {
22namespace uirenderer {
23
24///////////////////////////////////////////////////////////////////////////////
Romain Guy7975fb62010-10-01 16:36:14 -070025// Defines
26///////////////////////////////////////////////////////////////////////////////
27
28#define PATH_HEAP_SIZE 64
29
30///////////////////////////////////////////////////////////////////////////////
31// Helpers
32///////////////////////////////////////////////////////////////////////////////
33
34PathHeap::PathHeap(): mHeap(PATH_HEAP_SIZE * sizeof(SkPath)) {
35}
36
37PathHeap::PathHeap(SkFlattenableReadBuffer& buffer): mHeap(PATH_HEAP_SIZE * sizeof(SkPath)) {
38 int count = buffer.readS32();
39
40 mPaths.setCount(count);
41 SkPath** ptr = mPaths.begin();
42 SkPath* p = (SkPath*) mHeap.allocThrow(count * sizeof(SkPath));
43
44 for (int i = 0; i < count; i++) {
45 new (p) SkPath;
46 p->unflatten(buffer);
47 *ptr++ = p;
48 p++;
49 }
50}
51
52PathHeap::~PathHeap() {
53 SkPath** iter = mPaths.begin();
54 SkPath** stop = mPaths.end();
55 while (iter < stop) {
56 (*iter)->~SkPath();
57 iter++;
58 }
59}
60
61int PathHeap::append(const SkPath& path) {
62 SkPath* p = (SkPath*) mHeap.allocThrow(sizeof(SkPath));
63 new (p) SkPath(path);
64 *mPaths.append() = p;
65 return mPaths.count();
66}
67
68void PathHeap::flatten(SkFlattenableWriteBuffer& buffer) const {
69 int count = mPaths.count();
70
71 buffer.write32(count);
72 SkPath** iter = mPaths.begin();
73 SkPath** stop = mPaths.end();
74 while (iter < stop) {
75 (*iter)->flatten(buffer);
76 iter++;
77 }
78}
79
80///////////////////////////////////////////////////////////////////////////////
Romain Guyb051e892010-09-28 19:09:36 -070081// Display list
82///////////////////////////////////////////////////////////////////////////////
83
Romain Guyffac7fc2011-01-13 17:21:49 -080084const char* DisplayList::OP_NAMES[] = {
85 "AcquireContext",
86 "ReleaseContext",
87 "Save",
88 "Restore",
89 "RestoreToCount",
90 "SaveLayer",
91 "SaveLayerAlpha",
92 "Translate",
93 "Rotate",
94 "Scale",
Romain Guy4cf6e2f2011-01-23 11:35:13 -080095 "Skew",
Romain Guyffac7fc2011-01-13 17:21:49 -080096 "SetMatrix",
97 "ConcatMatrix",
98 "ClipRect",
99 "DrawDisplayList",
100 "DrawLayer",
101 "DrawBitmap",
102 "DrawBitmapMatrix",
103 "DrawBitmapRect",
Romain Guy5a7b4662011-01-20 19:09:30 -0800104 "DrawBitmapMesh",
Romain Guyffac7fc2011-01-13 17:21:49 -0800105 "DrawPatch",
106 "DrawColor",
107 "DrawRect",
Romain Guy01d58e42011-01-19 21:54:02 -0800108 "DrawRoundRect",
109 "DrawCircle",
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800110 "DrawOval",
Romain Guyffac7fc2011-01-13 17:21:49 -0800111 "DrawPath",
112 "DrawLines",
113 "DrawText",
114 "ResetShader",
115 "SetupShader",
116 "ResetColorFilter",
117 "SetupColorFilter",
118 "ResetShadow",
119 "SetupShadow"
120};
121
Romain Guyb051e892010-09-28 19:09:36 -0700122DisplayList::DisplayList(const DisplayListRenderer& recorder) {
Chet Haase5977baa2011-01-05 18:01:22 -0800123 initFromDisplayListRenderer(recorder);
124}
125
126DisplayList::~DisplayList() {
127 sk_free((void*) mReader.base());
128
129 Caches& caches = Caches::getInstance();
130
131 for (size_t i = 0; i < mBitmapResources.size(); i++) {
132 caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
133 }
134 mBitmapResources.clear();
135
Romain Guy24c00212011-01-14 15:31:00 -0800136 for (size_t i = 0; i < mShaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800137 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
Chet Haase5977baa2011-01-05 18:01:22 -0800138 }
Romain Guy24c00212011-01-14 15:31:00 -0800139 mShaders.clear();
Chet Haase5977baa2011-01-05 18:01:22 -0800140
141 for (size_t i = 0; i < mPaints.size(); i++) {
142 delete mPaints.itemAt(i);
143 }
144 mPaints.clear();
145
146 for (size_t i = 0; i < mMatrices.size(); i++) {
147 delete mMatrices.itemAt(i);
148 }
149 mMatrices.clear();
150
151 if (mPathHeap) {
152 for (int i = 0; i < mPathHeap->count(); i++) {
153 caches.pathCache.removeDeferred(&(*mPathHeap)[i]);
154 }
155 mPathHeap->safeUnref();
156 }
157}
158
159void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder) {
Romain Guyb051e892010-09-28 19:09:36 -0700160 const SkWriter32& writer = recorder.writeStream();
161 init();
162
163 if (writer.size() == 0) {
164 return;
165 }
166
167 size_t size = writer.size();
168 void* buffer = sk_malloc_throw(size);
169 writer.flatten(buffer);
170 mReader.setMemory(buffer, size);
171
172 mRCPlayback.reset(&recorder.mRCRecorder);
173 mRCPlayback.setupBuffer(mReader);
174
175 mTFPlayback.reset(&recorder.mTFRecorder);
176 mTFPlayback.setupBuffer(mReader);
177
Chet Haase5c13d892010-10-08 08:37:55 -0700178 Caches& caches = Caches::getInstance();
Romain Guyb051e892010-09-28 19:09:36 -0700179
Chet Haase5c13d892010-10-08 08:37:55 -0700180 const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
181 for (size_t i = 0; i < bitmapResources.size(); i++) {
182 SkBitmap* resource = bitmapResources.itemAt(i);
183 mBitmapResources.add(resource);
184 caches.resourceCache.incrementRefcount(resource);
Romain Guyb051e892010-09-28 19:09:36 -0700185 }
Chet Haased98aa2d2010-10-25 15:47:32 -0700186
Romain Guy24c00212011-01-14 15:31:00 -0800187 const Vector<SkiaShader*> &shaders = recorder.getShaders();
188 for (size_t i = 0; i < shaders.size(); i++) {
Romain Guy43ccf462011-01-14 18:51:01 -0800189 SkiaShader* shader = shaders.itemAt(i);
190 mShaders.add(shader);
191 caches.resourceCache.incrementRefcount(shader);
Romain Guyb051e892010-09-28 19:09:36 -0700192 }
193
Chet Haased98aa2d2010-10-25 15:47:32 -0700194 const Vector<SkPaint*> &paints = recorder.getPaints();
195 for (size_t i = 0; i < paints.size(); i++) {
196 mPaints.add(paints.itemAt(i));
197 }
198
199 const Vector<SkMatrix*> &matrices = recorder.getMatrices();
200 for (size_t i = 0; i < matrices.size(); i++) {
201 mMatrices.add(matrices.itemAt(i));
202 }
203
Romain Guyb051e892010-09-28 19:09:36 -0700204 mPathHeap = recorder.mPathHeap;
Romain Guy9e108412010-11-09 14:35:20 -0800205 if (mPathHeap) {
206 mPathHeap->safeRef();
207 }
Romain Guyb051e892010-09-28 19:09:36 -0700208}
209
Romain Guyb051e892010-09-28 19:09:36 -0700210void DisplayList::init() {
Romain Guyb051e892010-09-28 19:09:36 -0700211 mPathHeap = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700212}
213
Romain Guyffac7fc2011-01-13 17:21:49 -0800214void DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
Romain Guyb051e892010-09-28 19:09:36 -0700215 TextContainer text;
216 mReader.rewind();
217
Romain Guyffac7fc2011-01-13 17:21:49 -0800218#if DEBUG_DISPLAY_LIST
219 uint32_t count = (level + 1) * 2;
220 char indent[count + 1];
221 for (uint32_t i = 0; i < count; i++) {
222 indent[i] = ' ';
223 }
224 indent[count] = '\0';
225 DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
226#endif
Romain Guyb051e892010-09-28 19:09:36 -0700227
Romain Guyffac7fc2011-01-13 17:21:49 -0800228 int saveCount = renderer.getSaveCount() - 1;
Romain Guyb051e892010-09-28 19:09:36 -0700229 while (!mReader.eof()) {
Romain Guy5b3b3522010-10-27 18:57:51 -0700230 int op = mReader.readInt();
Romain Guyffac7fc2011-01-13 17:21:49 -0800231 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
232
Romain Guy5b3b3522010-10-27 18:57:51 -0700233 switch (op) {
Romain Guyb051e892010-09-28 19:09:36 -0700234 case AcquireContext: {
235 renderer.acquireContext();
236 }
237 break;
238 case ReleaseContext: {
239 renderer.releaseContext();
240 }
241 break;
242 case Save: {
243 renderer.save(getInt());
244 }
245 break;
246 case Restore: {
247 renderer.restore();
248 }
249 break;
250 case RestoreToCount: {
251 renderer.restoreToCount(saveCount + getInt());
252 }
253 break;
254 case SaveLayer: {
255 renderer.saveLayer(getFloat(), getFloat(), getFloat(), getFloat(),
256 getPaint(), getInt());
257 }
258 break;
Romain Guy5b3b3522010-10-27 18:57:51 -0700259 case SaveLayerAlpha: {
260 renderer.saveLayerAlpha(getFloat(), getFloat(), getFloat(), getFloat(),
261 getInt(), getInt());
262 }
263 break;
Romain Guyb051e892010-09-28 19:09:36 -0700264 case Translate: {
265 renderer.translate(getFloat(), getFloat());
266 }
267 break;
268 case Rotate: {
269 renderer.rotate(getFloat());
270 }
271 break;
272 case Scale: {
273 renderer.scale(getFloat(), getFloat());
274 }
275 break;
Romain Guy807daf72011-01-18 11:19:19 -0800276 case Skew: {
277 renderer.skew(getFloat(), getFloat());
278 }
279 break;
Romain Guyb051e892010-09-28 19:09:36 -0700280 case SetMatrix: {
281 renderer.setMatrix(getMatrix());
282 }
283 break;
284 case ConcatMatrix: {
285 renderer.concatMatrix(getMatrix());
286 }
287 break;
288 case ClipRect: {
289 renderer.clipRect(getFloat(), getFloat(), getFloat(), getFloat(),
290 (SkRegion::Op) getInt());
291 }
292 break;
Romain Guy0fe478e2010-11-08 12:08:41 -0800293 case DrawDisplayList: {
Romain Guyffac7fc2011-01-13 17:21:49 -0800294 renderer.drawDisplayList(getDisplayList(), level + 1);
Romain Guy0fe478e2010-11-08 12:08:41 -0800295 }
296 break;
Romain Guy6c319ca2011-01-11 14:29:25 -0800297 case DrawLayer: {
Romain Guyada830f2011-01-13 12:13:20 -0800298 renderer.drawLayer((Layer*) getInt(), getFloat(), getFloat(), getPaint());
Romain Guy6c319ca2011-01-11 14:29:25 -0800299 }
300 break;
Romain Guyb051e892010-09-28 19:09:36 -0700301 case DrawBitmap: {
302 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getPaint());
303 }
304 break;
305 case DrawBitmapMatrix: {
306 renderer.drawBitmap(getBitmap(), getMatrix(), getPaint());
307 }
308 break;
309 case DrawBitmapRect: {
310 renderer.drawBitmap(getBitmap(), getFloat(), getFloat(), getFloat(), getFloat(),
311 getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
312 }
313 break;
Romain Guy5a7b4662011-01-20 19:09:30 -0800314 case DrawBitmapMesh: {
315 int verticesCount = 0;
316 uint32_t colorsCount = 0;
317
318 SkBitmap* bitmap = getBitmap();
319 uint32_t meshWidth = getInt();
320 uint32_t meshHeight = getInt();
321 float* vertices = getFloats(verticesCount);
322 bool hasColors = getInt();
323 int* colors = hasColors ? getInts(colorsCount) : NULL;
324
325 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint());
326 }
Romain Guyb051e892010-09-28 19:09:36 -0700327 case DrawPatch: {
328 int32_t* xDivs = NULL;
329 int32_t* yDivs = NULL;
Romain Guy4bb94202010-10-12 15:59:26 -0700330 uint32_t* colors = NULL;
Romain Guyb051e892010-09-28 19:09:36 -0700331 uint32_t xDivsCount = 0;
332 uint32_t yDivsCount = 0;
Romain Guy4bb94202010-10-12 15:59:26 -0700333 int8_t numColors = 0;
Romain Guyb051e892010-09-28 19:09:36 -0700334
335 SkBitmap* bitmap = getBitmap();
336
337 xDivs = getInts(xDivsCount);
338 yDivs = getInts(yDivsCount);
Romain Guy4bb94202010-10-12 15:59:26 -0700339 colors = getUInts(numColors);
Romain Guyb051e892010-09-28 19:09:36 -0700340
Romain Guy4bb94202010-10-12 15:59:26 -0700341 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
342 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
Romain Guyb051e892010-09-28 19:09:36 -0700343 }
344 break;
345 case DrawColor: {
346 renderer.drawColor(getInt(), (SkXfermode::Mode) getInt());
347 }
348 break;
349 case DrawRect: {
350 renderer.drawRect(getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
351 }
352 break;
Romain Guy01d58e42011-01-19 21:54:02 -0800353 case DrawRoundRect: {
354 renderer.drawRoundRect(getFloat(), getFloat(), getFloat(), getFloat(),
355 getFloat(), getFloat(), getPaint());
356 }
357 break;
358 case DrawCircle: {
359 renderer.drawCircle(getFloat(), getFloat(), getFloat(), getPaint());
360 }
361 break;
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800362 case DrawOval: {
363 renderer.drawOval(getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
364 }
365 break;
Romain Guyb051e892010-09-28 19:09:36 -0700366 case DrawPath: {
367 renderer.drawPath(getPath(), getPaint());
368 }
369 break;
370 case DrawLines: {
371 int count = 0;
372 float* points = getFloats(count);
373 renderer.drawLines(points, count, getPaint());
374 }
375 break;
376 case DrawText: {
377 getText(&text);
378 renderer.drawText(text.text(), text.length(), getInt(),
379 getFloat(), getFloat(), getPaint());
380 }
381 break;
382 case ResetShader: {
383 renderer.resetShader();
384 }
385 break;
386 case SetupShader: {
Chet Haase5c13d892010-10-08 08:37:55 -0700387 renderer.setupShader(getShader());
Romain Guyb051e892010-09-28 19:09:36 -0700388 }
389 break;
390 case ResetColorFilter: {
391 renderer.resetColorFilter();
392 }
393 break;
394 case SetupColorFilter: {
Chet Haasead93c2b2010-10-22 16:17:12 -0700395 renderer.setupColorFilter(getColorFilter());
Romain Guyb051e892010-09-28 19:09:36 -0700396 }
397 break;
398 case ResetShadow: {
399 renderer.resetShadow();
400 }
401 break;
402 case SetupShadow: {
403 renderer.setupShadow(getFloat(), getFloat(), getFloat(), getInt());
404 }
405 break;
406 }
407 }
Romain Guyffac7fc2011-01-13 17:21:49 -0800408
409 DISPLAY_LIST_LOGD("%sDone", (char*) indent + 2);
Romain Guyb051e892010-09-28 19:09:36 -0700410}
411
412///////////////////////////////////////////////////////////////////////////////
Romain Guy4aa90572010-09-26 18:40:37 -0700413// Base structure
414///////////////////////////////////////////////////////////////////////////////
415
416DisplayListRenderer::DisplayListRenderer():
417 mHeap(HEAP_BLOCK_SIZE), mWriter(MIN_WRITER_SIZE) {
Romain Guy4aa90572010-09-26 18:40:37 -0700418 mPathHeap = NULL;
Chet Haase5977baa2011-01-05 18:01:22 -0800419 mDisplayList = NULL;
Romain Guy4aa90572010-09-26 18:40:37 -0700420}
421
422DisplayListRenderer::~DisplayListRenderer() {
423 reset();
424}
425
426void DisplayListRenderer::reset() {
427 if (mPathHeap) {
428 mPathHeap->unref();
429 mPathHeap = NULL;
430 }
431
Romain Guy4aa90572010-09-26 18:40:37 -0700432 mWriter.reset();
433 mHeap.reset();
434
435 mRCRecorder.reset();
436 mTFRecorder.reset();
Chet Haase5c13d892010-10-08 08:37:55 -0700437
438 Caches& caches = Caches::getInstance();
439 for (size_t i = 0; i < mBitmapResources.size(); i++) {
440 SkBitmap* resource = mBitmapResources.itemAt(i);
441 caches.resourceCache.decrementRefcount(resource);
442 }
443 mBitmapResources.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700444
Romain Guy43ccf462011-01-14 18:51:01 -0800445 for (size_t i = 0; i < mShaders.size(); i++) {
446 caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
447 }
Romain Guy24c00212011-01-14 15:31:00 -0800448 mShaders.clear();
449 mShaderMap.clear();
Romain Guy43ccf462011-01-14 18:51:01 -0800450
451 mPaints.clear();
452 mPaintMap.clear();
Chet Haased98aa2d2010-10-25 15:47:32 -0700453 mMatrices.clear();
Romain Guy4aa90572010-09-26 18:40:37 -0700454}
455
456///////////////////////////////////////////////////////////////////////////////
457// Operations
458///////////////////////////////////////////////////////////////////////////////
459
Chet Haase5977baa2011-01-05 18:01:22 -0800460DisplayList* DisplayListRenderer::getDisplayList() {
461 if (mDisplayList == NULL) {
462 mDisplayList = new DisplayList(*this);
463 } else {
464 mDisplayList->initFromDisplayListRenderer(*this);
465 }
466 return mDisplayList;
467}
468
Romain Guyb051e892010-09-28 19:09:36 -0700469void DisplayListRenderer::setViewport(int width, int height) {
470 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
471
472 mWidth = width;
473 mHeight = height;
474}
475
Romain Guy6b7bd242010-10-06 19:49:23 -0700476void DisplayListRenderer::prepare(bool opaque) {
Romain Guyb051e892010-09-28 19:09:36 -0700477 mSnapshot = new Snapshot(mFirstSnapshot,
478 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
479 mSaveCount = 1;
480 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
Romain Guy27454a42011-01-23 12:01:41 -0800481 mRestoreSaveCount = -1;
482}
483
484void DisplayListRenderer::finish() {
485 insertRestoreToCount();
486 OpenGLRenderer::finish();
Romain Guyb051e892010-09-28 19:09:36 -0700487}
488
Romain Guy4aa90572010-09-26 18:40:37 -0700489void DisplayListRenderer::acquireContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700490 addOp(DisplayList::AcquireContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700491 OpenGLRenderer::acquireContext();
492}
493
494void DisplayListRenderer::releaseContext() {
Romain Guyb051e892010-09-28 19:09:36 -0700495 addOp(DisplayList::ReleaseContext);
Romain Guy4aa90572010-09-26 18:40:37 -0700496 OpenGLRenderer::releaseContext();
497}
498
499int DisplayListRenderer::save(int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700500 addOp(DisplayList::Save);
Romain Guy4aa90572010-09-26 18:40:37 -0700501 addInt(flags);
502 return OpenGLRenderer::save(flags);
503}
504
505void DisplayListRenderer::restore() {
Romain Guyb051e892010-09-28 19:09:36 -0700506 addOp(DisplayList::Restore);
Romain Guy4aa90572010-09-26 18:40:37 -0700507 OpenGLRenderer::restore();
508}
509
510void DisplayListRenderer::restoreToCount(int saveCount) {
Romain Guy27454a42011-01-23 12:01:41 -0800511 mRestoreSaveCount = saveCount;
Romain Guy4aa90572010-09-26 18:40:37 -0700512 OpenGLRenderer::restoreToCount(saveCount);
513}
514
515int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700516 SkPaint* p, int flags) {
Romain Guyb051e892010-09-28 19:09:36 -0700517 addOp(DisplayList::SaveLayer);
Romain Guy4aa90572010-09-26 18:40:37 -0700518 addBounds(left, top, right, bottom);
519 addPaint(p);
520 addInt(flags);
Romain Guyb051e892010-09-28 19:09:36 -0700521 return OpenGLRenderer::save(flags);
Romain Guy4aa90572010-09-26 18:40:37 -0700522}
523
Romain Guy5b3b3522010-10-27 18:57:51 -0700524int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
525 int alpha, int flags) {
526 addOp(DisplayList::SaveLayerAlpha);
527 addBounds(left, top, right, bottom);
528 addInt(alpha);
529 addInt(flags);
530 return OpenGLRenderer::save(flags);
531}
532
Romain Guy4aa90572010-09-26 18:40:37 -0700533void DisplayListRenderer::translate(float dx, float dy) {
Romain Guyb051e892010-09-28 19:09:36 -0700534 addOp(DisplayList::Translate);
Romain Guy4aa90572010-09-26 18:40:37 -0700535 addPoint(dx, dy);
536 OpenGLRenderer::translate(dx, dy);
537}
538
539void DisplayListRenderer::rotate(float degrees) {
Romain Guyb051e892010-09-28 19:09:36 -0700540 addOp(DisplayList::Rotate);
Romain Guy4aa90572010-09-26 18:40:37 -0700541 addFloat(degrees);
542 OpenGLRenderer::rotate(degrees);
543}
544
545void DisplayListRenderer::scale(float sx, float sy) {
Romain Guyb051e892010-09-28 19:09:36 -0700546 addOp(DisplayList::Scale);
Romain Guy4aa90572010-09-26 18:40:37 -0700547 addPoint(sx, sy);
548 OpenGLRenderer::scale(sx, sy);
549}
550
Romain Guy807daf72011-01-18 11:19:19 -0800551void DisplayListRenderer::skew(float sx, float sy) {
552 addOp(DisplayList::Skew);
553 addPoint(sx, sy);
554 OpenGLRenderer::skew(sx, sy);
555}
556
Romain Guy4aa90572010-09-26 18:40:37 -0700557void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700558 addOp(DisplayList::SetMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700559 addMatrix(matrix);
560 OpenGLRenderer::setMatrix(matrix);
561}
562
563void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
Romain Guyb051e892010-09-28 19:09:36 -0700564 addOp(DisplayList::ConcatMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700565 addMatrix(matrix);
566 OpenGLRenderer::concatMatrix(matrix);
567}
568
569bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
570 SkRegion::Op op) {
Romain Guyb051e892010-09-28 19:09:36 -0700571 addOp(DisplayList::ClipRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700572 addBounds(left, top, right, bottom);
573 addInt(op);
574 return OpenGLRenderer::clipRect(left, top, right, bottom, op);
575}
576
Romain Guyffac7fc2011-01-13 17:21:49 -0800577void DisplayListRenderer::drawDisplayList(DisplayList* displayList, uint32_t level) {
Romain Guy0fe478e2010-11-08 12:08:41 -0800578 addOp(DisplayList::DrawDisplayList);
579 addDisplayList(displayList);
580}
581
Romain Guyada830f2011-01-13 12:13:20 -0800582void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
Romain Guy6c319ca2011-01-11 14:29:25 -0800583 addOp(DisplayList::DrawLayer);
Romain Guyada830f2011-01-13 12:13:20 -0800584 addInt((int) layer);
585 addPoint(x, y);
Romain Guy6c319ca2011-01-11 14:29:25 -0800586 addPaint(paint);
587}
588
Romain Guy4aa90572010-09-26 18:40:37 -0700589void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
Chet Haase5c13d892010-10-08 08:37:55 -0700590 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700591 addOp(DisplayList::DrawBitmap);
Romain Guy4aa90572010-09-26 18:40:37 -0700592 addBitmap(bitmap);
593 addPoint(left, top);
594 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700595}
596
Chet Haase5c13d892010-10-08 08:37:55 -0700597void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
598 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700599 addOp(DisplayList::DrawBitmapMatrix);
Romain Guy4aa90572010-09-26 18:40:37 -0700600 addBitmap(bitmap);
601 addMatrix(matrix);
602 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700603}
604
605void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
606 float srcRight, float srcBottom, float dstLeft, float dstTop,
Chet Haase5c13d892010-10-08 08:37:55 -0700607 float dstRight, float dstBottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700608 addOp(DisplayList::DrawBitmapRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700609 addBitmap(bitmap);
610 addBounds(srcLeft, srcTop, srcRight, srcBottom);
611 addBounds(dstLeft, dstTop, dstRight, dstBottom);
612 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700613}
614
Romain Guy5a7b4662011-01-20 19:09:30 -0800615void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
616 float* vertices, int* colors, SkPaint* paint) {
617 addOp(DisplayList::DrawBitmapMesh);
618 addBitmap(bitmap);
619 addInt(meshWidth);
620 addInt(meshHeight);
621 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
622 if (colors) {
623 addInt(1);
624 addInts(colors, (meshWidth + 1) * (meshHeight + 1));
625 } else {
626 addInt(0);
627 }
628 addPaint(paint);
629}
630
Romain Guy4aa90572010-09-26 18:40:37 -0700631void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
Romain Guy4bb94202010-10-12 15:59:26 -0700632 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
Chet Haase5c13d892010-10-08 08:37:55 -0700633 float left, float top, float right, float bottom, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700634 addOp(DisplayList::DrawPatch);
Romain Guy4aa90572010-09-26 18:40:37 -0700635 addBitmap(bitmap);
636 addInts(xDivs, width);
637 addInts(yDivs, height);
Romain Guy4bb94202010-10-12 15:59:26 -0700638 addUInts(colors, numColors);
Romain Guy4aa90572010-09-26 18:40:37 -0700639 addBounds(left, top, right, bottom);
640 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700641}
642
643void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
Romain Guyb051e892010-09-28 19:09:36 -0700644 addOp(DisplayList::DrawColor);
Romain Guy4aa90572010-09-26 18:40:37 -0700645 addInt(color);
646 addInt(mode);
Romain Guy4aa90572010-09-26 18:40:37 -0700647}
648
649void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
Chet Haase5c13d892010-10-08 08:37:55 -0700650 SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700651 addOp(DisplayList::DrawRect);
Romain Guy4aa90572010-09-26 18:40:37 -0700652 addBounds(left, top, right, bottom);
653 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700654}
655
Romain Guy01d58e42011-01-19 21:54:02 -0800656void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
657 float rx, float ry, SkPaint* paint) {
658 addOp(DisplayList::DrawRoundRect);
659 addBounds(left, top, right, bottom);
660 addPoint(rx, ry);
661 addPaint(paint);
662}
663
664void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
665 addOp(DisplayList::DrawCircle);
666 addPoint(x, y);
667 addFloat(radius);
668 addPaint(paint);
669}
670
Romain Guyc1cd9ba32011-01-23 14:18:41 -0800671void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
672 SkPaint* paint) {
673 addOp(DisplayList::DrawOval);
674 addBounds(left, top, right, bottom);
675 addPaint(paint);
676}
677
Romain Guy4aa90572010-09-26 18:40:37 -0700678void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700679 addOp(DisplayList::DrawPath);
Romain Guy4aa90572010-09-26 18:40:37 -0700680 addPath(path);
681 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700682}
683
Chet Haase5c13d892010-10-08 08:37:55 -0700684void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700685 addOp(DisplayList::DrawLines);
Romain Guy4aa90572010-09-26 18:40:37 -0700686 addFloats(points, count);
687 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700688}
689
690void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
691 float x, float y, SkPaint* paint) {
Romain Guyb051e892010-09-28 19:09:36 -0700692 addOp(DisplayList::DrawText);
Romain Guy4aa90572010-09-26 18:40:37 -0700693 addText(text, bytesCount);
694 addInt(count);
695 addPoint(x, y);
696 addPaint(paint);
Romain Guy4aa90572010-09-26 18:40:37 -0700697}
698
699void DisplayListRenderer::resetShader() {
Romain Guyb051e892010-09-28 19:09:36 -0700700 addOp(DisplayList::ResetShader);
Romain Guy4aa90572010-09-26 18:40:37 -0700701}
702
703void DisplayListRenderer::setupShader(SkiaShader* shader) {
Chet Haase5c13d892010-10-08 08:37:55 -0700704 addOp(DisplayList::SetupShader);
705 addShader(shader);
Romain Guy4aa90572010-09-26 18:40:37 -0700706}
707
708void DisplayListRenderer::resetColorFilter() {
Romain Guyb051e892010-09-28 19:09:36 -0700709 addOp(DisplayList::ResetColorFilter);
Romain Guy4aa90572010-09-26 18:40:37 -0700710}
711
712void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
Chet Haasead93c2b2010-10-22 16:17:12 -0700713 addOp(DisplayList::SetupColorFilter);
714 addColorFilter(filter);
Romain Guy4aa90572010-09-26 18:40:37 -0700715}
716
717void DisplayListRenderer::resetShadow() {
Romain Guyb051e892010-09-28 19:09:36 -0700718 addOp(DisplayList::ResetShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700719}
720
721void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
Romain Guyb051e892010-09-28 19:09:36 -0700722 addOp(DisplayList::SetupShadow);
Romain Guy4aa90572010-09-26 18:40:37 -0700723 addFloat(radius);
724 addPoint(dx, dy);
725 addInt(color);
Romain Guy4aa90572010-09-26 18:40:37 -0700726}
727
Romain Guy4aa90572010-09-26 18:40:37 -0700728}; // namespace uirenderer
729}; // namespace android