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