DisplayListRenderer.cpp revision d63cbd10765e8f48e39b07b15f0a4b70bf853ec8
1/*
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///////////////////////////////////////////////////////////////////////////////
25// Display list
26///////////////////////////////////////////////////////////////////////////////
27
28const char* DisplayList::OP_NAMES[] = {
29    "Save",
30    "Restore",
31    "RestoreToCount",
32    "SaveLayer",
33    "SaveLayerAlpha",
34    "Translate",
35    "Rotate",
36    "Scale",
37    "Skew",
38    "SetMatrix",
39    "ConcatMatrix",
40    "ClipRect",
41    "DrawDisplayList",
42    "DrawLayer",
43    "DrawBitmap",
44    "DrawBitmapMatrix",
45    "DrawBitmapRect",
46    "DrawBitmapMesh",
47    "DrawPatch",
48    "DrawColor",
49    "DrawRect",
50    "DrawRoundRect",
51    "DrawCircle",
52    "DrawOval",
53    "DrawArc",
54    "DrawPath",
55    "DrawLines",
56    "DrawText",
57    "ResetShader",
58    "SetupShader",
59    "ResetColorFilter",
60    "SetupColorFilter",
61    "ResetShadow",
62    "SetupShadow",
63    "DrawGLFunction"
64};
65
66DisplayList::DisplayList(const DisplayListRenderer& recorder) {
67    initFromDisplayListRenderer(recorder);
68}
69
70DisplayList::~DisplayList() {
71    clearResources();
72}
73
74void DisplayList::clearResources() {
75    sk_free((void*) mReader.base());
76
77    Caches& caches = Caches::getInstance();
78
79    for (size_t i = 0; i < mBitmapResources.size(); i++) {
80        caches.resourceCache.decrementRefcount(mBitmapResources.itemAt(i));
81    }
82    mBitmapResources.clear();
83
84    for (size_t i = 0; i < mShaders.size(); i++) {
85        caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
86    }
87    mShaders.clear();
88
89    for (size_t i = 0; i < mPaints.size(); i++) {
90        delete mPaints.itemAt(i);
91    }
92    mPaints.clear();
93
94    for (size_t i = 0; i < mPaths.size(); i++) {
95        delete mPaths.itemAt(i);
96    }
97    mPaths.clear();
98
99    for (size_t i = 0; i < mMatrices.size(); i++) {
100        delete mMatrices.itemAt(i);
101    }
102    mMatrices.clear();
103}
104
105void DisplayList::initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing) {
106    const SkWriter32& writer = recorder.writeStream();
107    init();
108
109    if (writer.size() == 0) {
110        return;
111    }
112
113    if (reusing) {
114        // re-using display list - clear out previous allocations
115        clearResources();
116    }
117
118    size_t size = writer.size();
119    void* buffer = sk_malloc_throw(size);
120    writer.flatten(buffer);
121    mReader.setMemory(buffer, size);
122
123    Caches& caches = Caches::getInstance();
124
125    const Vector<SkBitmap*> &bitmapResources = recorder.getBitmapResources();
126    for (size_t i = 0; i < bitmapResources.size(); i++) {
127        SkBitmap* resource = bitmapResources.itemAt(i);
128        mBitmapResources.add(resource);
129        caches.resourceCache.incrementRefcount(resource);
130    }
131
132    const Vector<SkiaShader*> &shaders = recorder.getShaders();
133    for (size_t i = 0; i < shaders.size(); i++) {
134        SkiaShader* shader = shaders.itemAt(i);
135        mShaders.add(shader);
136        caches.resourceCache.incrementRefcount(shader);
137    }
138
139    const Vector<SkPaint*> &paints = recorder.getPaints();
140    for (size_t i = 0; i < paints.size(); i++) {
141        mPaints.add(paints.itemAt(i));
142    }
143
144    const Vector<SkPath*> &paths = recorder.getPaths();
145    for (size_t i = 0; i < paths.size(); i++) {
146        mPaths.add(paths.itemAt(i));
147    }
148
149    const Vector<SkMatrix*> &matrices = recorder.getMatrices();
150    for (size_t i = 0; i < matrices.size(); i++) {
151        mMatrices.add(matrices.itemAt(i));
152    }
153}
154
155void DisplayList::init() {
156}
157
158bool DisplayList::replay(OpenGLRenderer& renderer, uint32_t level) {
159    bool needsInvalidate = false;
160    TextContainer text;
161    mReader.rewind();
162
163#if DEBUG_DISPLAY_LIST
164    uint32_t count = (level + 1) * 2;
165    char indent[count + 1];
166    for (uint32_t i = 0; i < count; i++) {
167        indent[i] = ' ';
168    }
169    indent[count] = '\0';
170    DISPLAY_LIST_LOGD("%sStart display list (%p)", (char*) indent + 2, this);
171#endif
172
173    int saveCount = renderer.getSaveCount() - 1;
174    while (!mReader.eof()) {
175        int op = mReader.readInt();
176
177        switch (op) {
178            case DrawGLFunction: {
179                Functor *functor = (Functor *) getInt();
180                DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], functor);
181                needsInvalidate |= renderer.callDrawGLFunction(functor);
182            }
183            break;
184            case Save: {
185                int rendererNum = getInt();
186                DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], rendererNum);
187                renderer.save(rendererNum);
188            }
189            break;
190            case Restore: {
191                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
192                renderer.restore();
193            }
194            break;
195            case RestoreToCount: {
196                int restoreCount = saveCount + getInt();
197                DISPLAY_LIST_LOGD("%s%s %d", (char*) indent, OP_NAMES[op], restoreCount);
198                renderer.restoreToCount(restoreCount);
199            }
200            break;
201            case SaveLayer: {
202                float f1 = getFloat();
203                float f2 = getFloat();
204                float f3 = getFloat();
205                float f4 = getFloat();
206                SkPaint* paint = getPaint();
207                int flags = getInt();
208                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p, 0x%x", (char*) indent,
209                    OP_NAMES[op], f1, f2, f3, f4, paint, flags);
210                renderer.saveLayer(f1, f2, f3, f4, paint, flags);
211            }
212            break;
213            case SaveLayerAlpha: {
214                float f1 = getFloat();
215                float f2 = getFloat();
216                float f3 = getFloat();
217                float f4 = getFloat();
218                int alpha = getInt();
219                int flags = getInt();
220                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d, 0x%x", (char*) indent,
221                    OP_NAMES[op], f1, f2, f3, f4, alpha, flags);
222                renderer.saveLayerAlpha(f1, f2, f3, f4, alpha, flags);
223            }
224            break;
225            case Translate: {
226                float f1 = getFloat();
227                float f2 = getFloat();
228                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], f1, f2);
229                renderer.translate(f1, f2);
230            }
231            break;
232            case Rotate: {
233                float rotation = getFloat();
234                DISPLAY_LIST_LOGD("%s%s %.2f", (char*) indent, OP_NAMES[op], rotation);
235                renderer.rotate(rotation);
236            }
237            break;
238            case Scale: {
239                float sx = getFloat();
240                float sy = getFloat();
241                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
242                renderer.scale(sx, sy);
243            }
244            break;
245            case Skew: {
246                float sx = getFloat();
247                float sy = getFloat();
248                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f", (char*) indent, OP_NAMES[op], sx, sy);
249                renderer.skew(sx, sy);
250            }
251            break;
252            case SetMatrix: {
253                SkMatrix* matrix = getMatrix();
254                DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
255                renderer.setMatrix(matrix);
256            }
257            break;
258            case ConcatMatrix: {
259                SkMatrix* matrix = getMatrix();
260                DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], matrix);
261                renderer.concatMatrix(matrix);
262            }
263            break;
264            case ClipRect: {
265                float f1 = getFloat();
266                float f2 = getFloat();
267                float f3 = getFloat();
268                float f4 = getFloat();
269                int regionOp = getInt();
270                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %d", (char*) indent, OP_NAMES[op],
271                    f1, f2, f3, f4, regionOp);
272                renderer.clipRect(f1, f2, f3, f4, (SkRegion::Op) regionOp);
273            }
274            break;
275            case DrawDisplayList: {
276                DisplayList* displayList = getDisplayList();
277                DISPLAY_LIST_LOGD("%s%s %p, %d", (char*) indent, OP_NAMES[op],
278                    displayList, level + 1);
279                needsInvalidate |= renderer.drawDisplayList(displayList, level + 1);
280            }
281            break;
282            case DrawLayer: {
283                Layer* layer = (Layer*) getInt();
284                float x = getFloat();
285                float y = getFloat();
286                SkPaint* paint = getPaint();
287                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
288                    layer, x, y, paint);
289                renderer.drawLayer(layer, x, y, paint);
290            }
291            break;
292            case DrawBitmap: {
293                SkBitmap* bitmap = getBitmap();
294                float x = getFloat();
295                float y = getFloat();
296                SkPaint* paint = getPaint();
297                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
298                    bitmap, x, y, paint);
299                renderer.drawBitmap(bitmap, x, y, paint);
300            }
301            break;
302            case DrawBitmapMatrix: {
303                SkBitmap* bitmap = getBitmap();
304                SkMatrix* matrix = getMatrix();
305                SkPaint* paint = getPaint();
306                DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op],
307                    bitmap, matrix, paint);
308                renderer.drawBitmap(bitmap, matrix, paint);
309            }
310            break;
311            case DrawBitmapRect: {
312                SkBitmap* bitmap = getBitmap();
313                float f1 = getFloat();
314                float f2 = getFloat();
315                float f3 = getFloat();
316                float f4 = getFloat();
317                float f5 = getFloat();
318                float f6 = getFloat();
319                float f7 = getFloat();
320                float f8 = getFloat();
321                SkPaint* paint = getPaint();
322                DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
323                    (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
324                renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint);
325            }
326            break;
327            case DrawBitmapMesh: {
328                int verticesCount = 0;
329                uint32_t colorsCount = 0;
330
331                SkBitmap* bitmap = getBitmap();
332                uint32_t meshWidth = getInt();
333                uint32_t meshHeight = getInt();
334                float* vertices = getFloats(verticesCount);
335                bool hasColors = getInt();
336                int* colors = hasColors ? getInts(colorsCount) : NULL;
337
338                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
339                renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint());
340            }
341            break;
342            case DrawPatch: {
343                int32_t* xDivs = NULL;
344                int32_t* yDivs = NULL;
345                uint32_t* colors = NULL;
346                uint32_t xDivsCount = 0;
347                uint32_t yDivsCount = 0;
348                int8_t numColors = 0;
349
350                SkBitmap* bitmap = getBitmap();
351
352                xDivs = getInts(xDivsCount);
353                yDivs = getInts(yDivsCount);
354                colors = getUInts(numColors);
355
356                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
357                renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount,
358                        numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint());
359            }
360            break;
361            case DrawColor: {
362                int color = getInt();
363                int xferMode = getInt();
364                DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode);
365                renderer.drawColor(color, (SkXfermode::Mode) xferMode);
366            }
367            break;
368            case DrawRect: {
369                float f1 = getFloat();
370                float f2 = getFloat();
371                float f3 = getFloat();
372                float f4 = getFloat();
373                SkPaint* paint = getPaint();
374                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
375                    f1, f2, f3, f4, paint);
376                renderer.drawRect(f1, f2, f3, f4, paint);
377            }
378            break;
379            case DrawRoundRect: {
380                float f1 = getFloat();
381                float f2 = getFloat();
382                float f3 = getFloat();
383                float f4 = getFloat();
384                float f5 = getFloat();
385                float f6 = getFloat();
386                SkPaint* paint = getPaint();
387                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p",
388                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint);
389                renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint);
390            }
391            break;
392            case DrawCircle: {
393                float f1 = getFloat();
394                float f2 = getFloat();
395                float f3 = getFloat();
396                SkPaint* paint = getPaint();
397                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p",
398                    (char*) indent, OP_NAMES[op], f1, f2, f3, paint);
399                renderer.drawCircle(f1, f2, f3, paint);
400            }
401            break;
402            case DrawOval: {
403                float f1 = getFloat();
404                float f2 = getFloat();
405                float f3 = getFloat();
406                float f4 = getFloat();
407                SkPaint* paint = getPaint();
408                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p",
409                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint);
410                renderer.drawOval(f1, f2, f3, f4, paint);
411            }
412            break;
413            case DrawArc: {
414                float f1 = getFloat();
415                float f2 = getFloat();
416                float f3 = getFloat();
417                float f4 = getFloat();
418                float f5 = getFloat();
419                float f6 = getFloat();
420                int i1 = getInt();
421                SkPaint* paint = getPaint();
422                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p",
423                    (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint);
424                renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint);
425            }
426            break;
427            case DrawPath: {
428                SkPath* path = getPath();
429                SkPaint* paint = getPaint();
430                DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint);
431                renderer.drawPath(path, paint);
432            }
433            break;
434            case DrawLines: {
435                int count = 0;
436                float* points = getFloats(count);
437                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
438                renderer.drawLines(points, count, getPaint());
439            }
440            break;
441            case DrawText: {
442                getText(&text);
443                int count = getInt();
444                float x = getFloat();
445                float y = getFloat();
446                SkPaint* paint = getPaint();
447                DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op],
448                    text.text(), text.length(), count, x, y, paint);
449                renderer.drawText(text.text(), text.length(), count, x, y, paint);
450            }
451            break;
452            case ResetShader: {
453                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
454                renderer.resetShader();
455            }
456            break;
457            case SetupShader: {
458                SkiaShader* shader = getShader();
459                DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader);
460                renderer.setupShader(shader);
461            }
462            break;
463            case ResetColorFilter: {
464                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
465                renderer.resetColorFilter();
466            }
467            break;
468            case SetupColorFilter: {
469                SkiaColorFilter *colorFilter = getColorFilter();
470                DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter);
471                renderer.setupColorFilter(colorFilter);
472            }
473            break;
474            case ResetShadow: {
475                DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]);
476                renderer.resetShadow();
477            }
478            break;
479            case SetupShadow: {
480                float radius = getFloat();
481                float dx = getFloat();
482                float dy = getFloat();
483                int color = getInt();
484                DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op],
485                    radius, dx, dy, color);
486                renderer.setupShadow(radius, dx, dy, color);
487            }
488            break;
489            default:
490                DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s",
491                    (char*) indent, OP_NAMES[op]);
492                break;
493        }
494    }
495
496    DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate);
497    return needsInvalidate;
498}
499
500///////////////////////////////////////////////////////////////////////////////
501// Base structure
502///////////////////////////////////////////////////////////////////////////////
503
504DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) {
505    mDisplayList = NULL;
506}
507
508DisplayListRenderer::~DisplayListRenderer() {
509    reset();
510}
511
512void DisplayListRenderer::reset() {
513    mWriter.reset();
514
515    Caches& caches = Caches::getInstance();
516    for (size_t i = 0; i < mBitmapResources.size(); i++) {
517        SkBitmap* resource = mBitmapResources.itemAt(i);
518        caches.resourceCache.decrementRefcount(resource);
519    }
520    mBitmapResources.clear();
521
522    for (size_t i = 0; i < mShaders.size(); i++) {
523       caches.resourceCache.decrementRefcount(mShaders.itemAt(i));
524    }
525    mShaders.clear();
526    mShaderMap.clear();
527
528    mPaints.clear();
529    mPaintMap.clear();
530    mPaths.clear();
531    mPathMap.clear();
532    mMatrices.clear();
533}
534
535///////////////////////////////////////////////////////////////////////////////
536// Operations
537///////////////////////////////////////////////////////////////////////////////
538
539DisplayList* DisplayListRenderer::getDisplayList() {
540    if (mDisplayList == NULL) {
541        mDisplayList = new DisplayList(*this);
542    } else {
543        mDisplayList->initFromDisplayListRenderer(*this, true);
544    }
545    return mDisplayList;
546}
547
548void DisplayListRenderer::setViewport(int width, int height) {
549    mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1);
550
551    mWidth = width;
552    mHeight = height;
553}
554
555void DisplayListRenderer::prepareDirty(float left, float top,
556        float right, float bottom, bool opaque) {
557    mSnapshot = new Snapshot(mFirstSnapshot,
558            SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag);
559    mSaveCount = 1;
560    mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight);
561    mRestoreSaveCount = -1;
562}
563
564void DisplayListRenderer::finish() {
565    insertRestoreToCount();
566    OpenGLRenderer::finish();
567}
568
569void DisplayListRenderer::interrupt() {
570}
571
572void DisplayListRenderer::resume() {
573}
574
575bool DisplayListRenderer::callDrawGLFunction(Functor *functor) {
576    addOp(DisplayList::DrawGLFunction);
577    addInt((int) functor);
578    return false; // No invalidate needed at record-time
579}
580
581int DisplayListRenderer::save(int flags) {
582    addOp(DisplayList::Save);
583    addInt(flags);
584    return OpenGLRenderer::save(flags);
585}
586
587void DisplayListRenderer::restore() {
588    addOp(DisplayList::Restore);
589    OpenGLRenderer::restore();
590}
591
592void DisplayListRenderer::restoreToCount(int saveCount) {
593    mRestoreSaveCount = saveCount;
594    OpenGLRenderer::restoreToCount(saveCount);
595}
596
597int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom,
598        SkPaint* p, int flags) {
599    addOp(DisplayList::SaveLayer);
600    addBounds(left, top, right, bottom);
601    addPaint(p);
602    addInt(flags);
603    return OpenGLRenderer::save(flags);
604}
605
606int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom,
607        int alpha, int flags) {
608    addOp(DisplayList::SaveLayerAlpha);
609    addBounds(left, top, right, bottom);
610    addInt(alpha);
611    addInt(flags);
612    return OpenGLRenderer::save(flags);
613}
614
615void DisplayListRenderer::translate(float dx, float dy) {
616    addOp(DisplayList::Translate);
617    addPoint(dx, dy);
618    OpenGLRenderer::translate(dx, dy);
619}
620
621void DisplayListRenderer::rotate(float degrees) {
622    addOp(DisplayList::Rotate);
623    addFloat(degrees);
624    OpenGLRenderer::rotate(degrees);
625}
626
627void DisplayListRenderer::scale(float sx, float sy) {
628    addOp(DisplayList::Scale);
629    addPoint(sx, sy);
630    OpenGLRenderer::scale(sx, sy);
631}
632
633void DisplayListRenderer::skew(float sx, float sy) {
634    addOp(DisplayList::Skew);
635    addPoint(sx, sy);
636    OpenGLRenderer::skew(sx, sy);
637}
638
639void DisplayListRenderer::setMatrix(SkMatrix* matrix) {
640    addOp(DisplayList::SetMatrix);
641    addMatrix(matrix);
642    OpenGLRenderer::setMatrix(matrix);
643}
644
645void DisplayListRenderer::concatMatrix(SkMatrix* matrix) {
646    addOp(DisplayList::ConcatMatrix);
647    addMatrix(matrix);
648    OpenGLRenderer::concatMatrix(matrix);
649}
650
651bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom,
652        SkRegion::Op op) {
653    addOp(DisplayList::ClipRect);
654    addBounds(left, top, right, bottom);
655    addInt(op);
656    return OpenGLRenderer::clipRect(left, top, right, bottom, op);
657}
658
659bool DisplayListRenderer::drawDisplayList(DisplayList* displayList, uint32_t level) {
660    addOp(DisplayList::DrawDisplayList);
661    addDisplayList(displayList);
662    return false;
663}
664
665void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) {
666    addOp(DisplayList::DrawLayer);
667    addInt((int) layer);
668    addPoint(x, y);
669    addPaint(paint);
670}
671
672void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top,
673        SkPaint* paint) {
674    addOp(DisplayList::DrawBitmap);
675    addBitmap(bitmap);
676    addPoint(left, top);
677    addPaint(paint);
678}
679
680void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix,
681        SkPaint* paint) {
682    addOp(DisplayList::DrawBitmapMatrix);
683    addBitmap(bitmap);
684    addMatrix(matrix);
685    addPaint(paint);
686}
687
688void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop,
689        float srcRight, float srcBottom, float dstLeft, float dstTop,
690        float dstRight, float dstBottom, SkPaint* paint) {
691    addOp(DisplayList::DrawBitmapRect);
692    addBitmap(bitmap);
693    addBounds(srcLeft, srcTop, srcRight, srcBottom);
694    addBounds(dstLeft, dstTop, dstRight, dstBottom);
695    addPaint(paint);
696}
697
698void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight,
699        float* vertices, int* colors, SkPaint* paint) {
700    addOp(DisplayList::DrawBitmapMesh);
701    addBitmap(bitmap);
702    addInt(meshWidth);
703    addInt(meshHeight);
704    addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2);
705    if (colors) {
706        addInt(1);
707        addInts(colors, (meshWidth + 1) * (meshHeight + 1));
708    } else {
709        addInt(0);
710    }
711    addPaint(paint);
712}
713
714void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs,
715        const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors,
716        float left, float top, float right, float bottom, SkPaint* paint) {
717    addOp(DisplayList::DrawPatch);
718    addBitmap(bitmap);
719    addInts(xDivs, width);
720    addInts(yDivs, height);
721    addUInts(colors, numColors);
722    addBounds(left, top, right, bottom);
723    addPaint(paint);
724}
725
726void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) {
727    addOp(DisplayList::DrawColor);
728    addInt(color);
729    addInt(mode);
730}
731
732void DisplayListRenderer::drawRect(float left, float top, float right, float bottom,
733        SkPaint* paint) {
734    addOp(DisplayList::DrawRect);
735    addBounds(left, top, right, bottom);
736    addPaint(paint);
737}
738
739void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom,
740            float rx, float ry, SkPaint* paint) {
741    addOp(DisplayList::DrawRoundRect);
742    addBounds(left, top, right, bottom);
743    addPoint(rx, ry);
744    addPaint(paint);
745}
746
747void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) {
748    addOp(DisplayList::DrawCircle);
749    addPoint(x, y);
750    addFloat(radius);
751    addPaint(paint);
752}
753
754void DisplayListRenderer::drawOval(float left, float top, float right, float bottom,
755        SkPaint* paint) {
756    addOp(DisplayList::DrawOval);
757    addBounds(left, top, right, bottom);
758    addPaint(paint);
759}
760
761void DisplayListRenderer::drawArc(float left, float top, float right, float bottom,
762        float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
763    addOp(DisplayList::DrawArc);
764    addBounds(left, top, right, bottom);
765    addPoint(startAngle, sweepAngle);
766    addInt(useCenter ? 1 : 0);
767    addPaint(paint);
768}
769
770void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) {
771    addOp(DisplayList::DrawPath);
772    addPath(path);
773    addPaint(paint);
774}
775
776void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) {
777    addOp(DisplayList::DrawLines);
778    addFloats(points, count);
779    addPaint(paint);
780}
781
782void DisplayListRenderer::drawText(const char* text, int bytesCount, int count,
783        float x, float y, SkPaint* paint) {
784    addOp(DisplayList::DrawText);
785    addText(text, bytesCount);
786    addInt(count);
787    addPoint(x, y);
788    addPaint(paint);
789}
790
791void DisplayListRenderer::resetShader() {
792    addOp(DisplayList::ResetShader);
793}
794
795void DisplayListRenderer::setupShader(SkiaShader* shader) {
796    addOp(DisplayList::SetupShader);
797    addShader(shader);
798}
799
800void DisplayListRenderer::resetColorFilter() {
801    addOp(DisplayList::ResetColorFilter);
802}
803
804void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) {
805    addOp(DisplayList::SetupColorFilter);
806    addColorFilter(filter);
807}
808
809void DisplayListRenderer::resetShadow() {
810    addOp(DisplayList::ResetShadow);
811}
812
813void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) {
814    addOp(DisplayList::SetupShadow);
815    addFloat(radius);
816    addPoint(dx, dy);
817    addInt(color);
818}
819
820}; // namespace uirenderer
821}; // namespace android
822