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