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