DisplayListRenderer.cpp revision b29cfbf768eab959b31410aafc0a99e20249e9d7
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, Rect& dirty, 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, dirty); 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 uint32_t width = getUInt(); 278 uint32_t height = getUInt(); 279 DISPLAY_LIST_LOGD("%s%s %p, %dx%d, %d", (char*) indent, OP_NAMES[op], 280 displayList, width, height, level + 1); 281 needsInvalidate |= renderer.drawDisplayList(displayList, width, height, 282 dirty, level + 1); 283 } 284 break; 285 case DrawLayer: { 286 Layer* layer = (Layer*) getInt(); 287 float x = getFloat(); 288 float y = getFloat(); 289 SkPaint* paint = getPaint(); 290 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], 291 layer, x, y, paint); 292 renderer.drawLayer(layer, x, y, paint); 293 } 294 break; 295 case DrawBitmap: { 296 SkBitmap* bitmap = getBitmap(); 297 float x = getFloat(); 298 float y = getFloat(); 299 SkPaint* paint = getPaint(); 300 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], 301 bitmap, x, y, paint); 302 renderer.drawBitmap(bitmap, x, y, paint); 303 } 304 break; 305 case DrawBitmapMatrix: { 306 SkBitmap* bitmap = getBitmap(); 307 SkMatrix* matrix = getMatrix(); 308 SkPaint* paint = getPaint(); 309 DISPLAY_LIST_LOGD("%s%s %p, %p, %p", (char*) indent, OP_NAMES[op], 310 bitmap, matrix, paint); 311 renderer.drawBitmap(bitmap, matrix, paint); 312 } 313 break; 314 case DrawBitmapRect: { 315 SkBitmap* bitmap = getBitmap(); 316 float f1 = getFloat(); 317 float f2 = getFloat(); 318 float f3 = getFloat(); 319 float f4 = getFloat(); 320 float f5 = getFloat(); 321 float f6 = getFloat(); 322 float f7 = getFloat(); 323 float f8 = getFloat(); 324 SkPaint* paint = getPaint(); 325 DISPLAY_LIST_LOGD("%s%s %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", 326 (char*) indent, OP_NAMES[op], bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint); 327 renderer.drawBitmap(bitmap, f1, f2, f3, f4, f5, f6, f7, f8, paint); 328 } 329 break; 330 case DrawBitmapMesh: { 331 int verticesCount = 0; 332 uint32_t colorsCount = 0; 333 334 SkBitmap* bitmap = getBitmap(); 335 uint32_t meshWidth = getInt(); 336 uint32_t meshHeight = getInt(); 337 float* vertices = getFloats(verticesCount); 338 bool hasColors = getInt(); 339 int* colors = hasColors ? getInts(colorsCount) : NULL; 340 341 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 342 renderer.drawBitmapMesh(bitmap, meshWidth, meshHeight, vertices, colors, getPaint()); 343 } 344 break; 345 case DrawPatch: { 346 int32_t* xDivs = NULL; 347 int32_t* yDivs = NULL; 348 uint32_t* colors = NULL; 349 uint32_t xDivsCount = 0; 350 uint32_t yDivsCount = 0; 351 int8_t numColors = 0; 352 353 SkBitmap* bitmap = getBitmap(); 354 355 xDivs = getInts(xDivsCount); 356 yDivs = getInts(yDivsCount); 357 colors = getUInts(numColors); 358 359 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 360 renderer.drawPatch(bitmap, xDivs, yDivs, colors, xDivsCount, yDivsCount, 361 numColors, getFloat(), getFloat(), getFloat(), getFloat(), getPaint()); 362 } 363 break; 364 case DrawColor: { 365 int color = getInt(); 366 int xferMode = getInt(); 367 DISPLAY_LIST_LOGD("%s%s 0x%x %d", (char*) indent, OP_NAMES[op], color, xferMode); 368 renderer.drawColor(color, (SkXfermode::Mode) xferMode); 369 } 370 break; 371 case DrawRect: { 372 float f1 = getFloat(); 373 float f2 = getFloat(); 374 float f3 = getFloat(); 375 float f4 = getFloat(); 376 SkPaint* paint = getPaint(); 377 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], 378 f1, f2, f3, f4, paint); 379 renderer.drawRect(f1, f2, f3, f4, paint); 380 } 381 break; 382 case DrawRoundRect: { 383 float f1 = getFloat(); 384 float f2 = getFloat(); 385 float f3 = getFloat(); 386 float f4 = getFloat(); 387 float f5 = getFloat(); 388 float f6 = getFloat(); 389 SkPaint* paint = getPaint(); 390 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %p", 391 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, paint); 392 renderer.drawRoundRect(f1, f2, f3, f4, f5, f6, paint); 393 } 394 break; 395 case DrawCircle: { 396 float f1 = getFloat(); 397 float f2 = getFloat(); 398 float f3 = getFloat(); 399 SkPaint* paint = getPaint(); 400 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %p", 401 (char*) indent, OP_NAMES[op], f1, f2, f3, paint); 402 renderer.drawCircle(f1, f2, f3, paint); 403 } 404 break; 405 case DrawOval: { 406 float f1 = getFloat(); 407 float f2 = getFloat(); 408 float f3 = getFloat(); 409 float f4 = getFloat(); 410 SkPaint* paint = getPaint(); 411 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %p", 412 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, paint); 413 renderer.drawOval(f1, f2, f3, f4, paint); 414 } 415 break; 416 case DrawArc: { 417 float f1 = getFloat(); 418 float f2 = getFloat(); 419 float f3 = getFloat(); 420 float f4 = getFloat(); 421 float f5 = getFloat(); 422 float f6 = getFloat(); 423 int i1 = getInt(); 424 SkPaint* paint = getPaint(); 425 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p", 426 (char*) indent, OP_NAMES[op], f1, f2, f3, f4, f5, f6, i1, paint); 427 renderer.drawArc(f1, f2, f3, f4, f5, f6, i1 == 1, paint); 428 } 429 break; 430 case DrawPath: { 431 SkPath* path = getPath(); 432 SkPaint* paint = getPaint(); 433 DISPLAY_LIST_LOGD("%s%s %p, %p", (char*) indent, OP_NAMES[op], path, paint); 434 renderer.drawPath(path, paint); 435 } 436 break; 437 case DrawLines: { 438 int count = 0; 439 float* points = getFloats(count); 440 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 441 renderer.drawLines(points, count, getPaint()); 442 } 443 break; 444 case DrawText: { 445 getText(&text); 446 int count = getInt(); 447 float x = getFloat(); 448 float y = getFloat(); 449 SkPaint* paint = getPaint(); 450 DISPLAY_LIST_LOGD("%s%s %s, %d, %d, %.2f, %.2f, %p", (char*) indent, OP_NAMES[op], 451 text.text(), text.length(), count, x, y, paint); 452 renderer.drawText(text.text(), text.length(), count, x, y, paint); 453 } 454 break; 455 case ResetShader: { 456 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 457 renderer.resetShader(); 458 } 459 break; 460 case SetupShader: { 461 SkiaShader* shader = getShader(); 462 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], shader); 463 renderer.setupShader(shader); 464 } 465 break; 466 case ResetColorFilter: { 467 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 468 renderer.resetColorFilter(); 469 } 470 break; 471 case SetupColorFilter: { 472 SkiaColorFilter *colorFilter = getColorFilter(); 473 DISPLAY_LIST_LOGD("%s%s %p", (char*) indent, OP_NAMES[op], colorFilter); 474 renderer.setupColorFilter(colorFilter); 475 } 476 break; 477 case ResetShadow: { 478 DISPLAY_LIST_LOGD("%s%s", (char*) indent, OP_NAMES[op]); 479 renderer.resetShadow(); 480 } 481 break; 482 case SetupShadow: { 483 float radius = getFloat(); 484 float dx = getFloat(); 485 float dy = getFloat(); 486 int color = getInt(); 487 DISPLAY_LIST_LOGD("%s%s %.2f, %.2f, %.2f, 0x%x", (char*) indent, OP_NAMES[op], 488 radius, dx, dy, color); 489 renderer.setupShadow(radius, dx, dy, color); 490 } 491 break; 492 default: 493 DISPLAY_LIST_LOGD("Display List error: op not handled: %s%s", 494 (char*) indent, OP_NAMES[op]); 495 break; 496 } 497 } 498 499 DISPLAY_LIST_LOGD("%sDone, returning %d", (char*) indent + 2, needsInvalidate); 500 return needsInvalidate; 501} 502 503/////////////////////////////////////////////////////////////////////////////// 504// Base structure 505/////////////////////////////////////////////////////////////////////////////// 506 507DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) { 508 mDisplayList = NULL; 509} 510 511DisplayListRenderer::~DisplayListRenderer() { 512 reset(); 513} 514 515void DisplayListRenderer::reset() { 516 mWriter.reset(); 517 518 Caches& caches = Caches::getInstance(); 519 for (size_t i = 0; i < mBitmapResources.size(); i++) { 520 SkBitmap* resource = mBitmapResources.itemAt(i); 521 caches.resourceCache.decrementRefcount(resource); 522 } 523 mBitmapResources.clear(); 524 525 for (size_t i = 0; i < mShaders.size(); i++) { 526 caches.resourceCache.decrementRefcount(mShaders.itemAt(i)); 527 } 528 mShaders.clear(); 529 mShaderMap.clear(); 530 531 mPaints.clear(); 532 mPaintMap.clear(); 533 mPaths.clear(); 534 mPathMap.clear(); 535 mMatrices.clear(); 536} 537 538/////////////////////////////////////////////////////////////////////////////// 539// Operations 540/////////////////////////////////////////////////////////////////////////////// 541 542DisplayList* DisplayListRenderer::getDisplayList() { 543 if (mDisplayList == NULL) { 544 mDisplayList = new DisplayList(*this); 545 } else { 546 mDisplayList->initFromDisplayListRenderer(*this, true); 547 } 548 return mDisplayList; 549} 550 551void DisplayListRenderer::setViewport(int width, int height) { 552 mOrthoMatrix.loadOrtho(0, width, height, 0, -1, 1); 553 554 mWidth = width; 555 mHeight = height; 556} 557 558void DisplayListRenderer::prepareDirty(float left, float top, 559 float right, float bottom, bool opaque) { 560 mSnapshot = new Snapshot(mFirstSnapshot, 561 SkCanvas::kMatrix_SaveFlag | SkCanvas::kClip_SaveFlag); 562 mSaveCount = 1; 563 mSnapshot->setClip(0.0f, 0.0f, mWidth, mHeight); 564 mRestoreSaveCount = -1; 565} 566 567void DisplayListRenderer::finish() { 568 insertRestoreToCount(); 569 OpenGLRenderer::finish(); 570} 571 572void DisplayListRenderer::interrupt() { 573} 574 575void DisplayListRenderer::resume() { 576} 577 578bool DisplayListRenderer::callDrawGLFunction(Functor *functor, Rect& dirty) { 579 // Ignore dirty during recording, it matters only when we replay 580 addOp(DisplayList::DrawGLFunction); 581 addInt((int) functor); 582 return false; // No invalidate needed at record-time 583} 584 585int DisplayListRenderer::save(int flags) { 586 addOp(DisplayList::Save); 587 addInt(flags); 588 return OpenGLRenderer::save(flags); 589} 590 591void DisplayListRenderer::restore() { 592 addOp(DisplayList::Restore); 593 OpenGLRenderer::restore(); 594} 595 596void DisplayListRenderer::restoreToCount(int saveCount) { 597 mRestoreSaveCount = saveCount; 598 OpenGLRenderer::restoreToCount(saveCount); 599} 600 601int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom, 602 SkPaint* p, int flags) { 603 addOp(DisplayList::SaveLayer); 604 addBounds(left, top, right, bottom); 605 addPaint(p); 606 addInt(flags); 607 return OpenGLRenderer::save(flags); 608} 609 610int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom, 611 int alpha, int flags) { 612 addOp(DisplayList::SaveLayerAlpha); 613 addBounds(left, top, right, bottom); 614 addInt(alpha); 615 addInt(flags); 616 return OpenGLRenderer::save(flags); 617} 618 619void DisplayListRenderer::translate(float dx, float dy) { 620 addOp(DisplayList::Translate); 621 addPoint(dx, dy); 622 OpenGLRenderer::translate(dx, dy); 623} 624 625void DisplayListRenderer::rotate(float degrees) { 626 addOp(DisplayList::Rotate); 627 addFloat(degrees); 628 OpenGLRenderer::rotate(degrees); 629} 630 631void DisplayListRenderer::scale(float sx, float sy) { 632 addOp(DisplayList::Scale); 633 addPoint(sx, sy); 634 OpenGLRenderer::scale(sx, sy); 635} 636 637void DisplayListRenderer::skew(float sx, float sy) { 638 addOp(DisplayList::Skew); 639 addPoint(sx, sy); 640 OpenGLRenderer::skew(sx, sy); 641} 642 643void DisplayListRenderer::setMatrix(SkMatrix* matrix) { 644 addOp(DisplayList::SetMatrix); 645 addMatrix(matrix); 646 OpenGLRenderer::setMatrix(matrix); 647} 648 649void DisplayListRenderer::concatMatrix(SkMatrix* matrix) { 650 addOp(DisplayList::ConcatMatrix); 651 addMatrix(matrix); 652 OpenGLRenderer::concatMatrix(matrix); 653} 654 655bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom, 656 SkRegion::Op op) { 657 addOp(DisplayList::ClipRect); 658 addBounds(left, top, right, bottom); 659 addInt(op); 660 return OpenGLRenderer::clipRect(left, top, right, bottom, op); 661} 662 663bool DisplayListRenderer::drawDisplayList(DisplayList* displayList, 664 uint32_t width, uint32_t height, Rect& dirty, uint32_t level) { 665 // dirty is an out parameter and should not be recorded, 666 // it matters only when replaying the display list 667 addOp(DisplayList::DrawDisplayList); 668 addDisplayList(displayList); 669 addSize(width, height); 670 return false; 671} 672 673void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) { 674 addOp(DisplayList::DrawLayer); 675 addInt((int) layer); 676 addPoint(x, y); 677 addPaint(paint); 678} 679 680void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, 681 SkPaint* paint) { 682 addOp(DisplayList::DrawBitmap); 683 addBitmap(bitmap); 684 addPoint(left, top); 685 addPaint(paint); 686} 687 688void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, 689 SkPaint* paint) { 690 addOp(DisplayList::DrawBitmapMatrix); 691 addBitmap(bitmap); 692 addMatrix(matrix); 693 addPaint(paint); 694} 695 696void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, 697 float srcRight, float srcBottom, float dstLeft, float dstTop, 698 float dstRight, float dstBottom, SkPaint* paint) { 699 addOp(DisplayList::DrawBitmapRect); 700 addBitmap(bitmap); 701 addBounds(srcLeft, srcTop, srcRight, srcBottom); 702 addBounds(dstLeft, dstTop, dstRight, dstBottom); 703 addPaint(paint); 704} 705 706void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, 707 float* vertices, int* colors, SkPaint* paint) { 708 addOp(DisplayList::DrawBitmapMesh); 709 addBitmap(bitmap); 710 addInt(meshWidth); 711 addInt(meshHeight); 712 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2); 713 if (colors) { 714 addInt(1); 715 addInts(colors, (meshWidth + 1) * (meshHeight + 1)); 716 } else { 717 addInt(0); 718 } 719 addPaint(paint); 720} 721 722void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, 723 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, 724 float left, float top, float right, float bottom, SkPaint* paint) { 725 addOp(DisplayList::DrawPatch); 726 addBitmap(bitmap); 727 addInts(xDivs, width); 728 addInts(yDivs, height); 729 addUInts(colors, numColors); 730 addBounds(left, top, right, bottom); 731 addPaint(paint); 732} 733 734void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) { 735 addOp(DisplayList::DrawColor); 736 addInt(color); 737 addInt(mode); 738} 739 740void DisplayListRenderer::drawRect(float left, float top, float right, float bottom, 741 SkPaint* paint) { 742 addOp(DisplayList::DrawRect); 743 addBounds(left, top, right, bottom); 744 addPaint(paint); 745} 746 747void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom, 748 float rx, float ry, SkPaint* paint) { 749 addOp(DisplayList::DrawRoundRect); 750 addBounds(left, top, right, bottom); 751 addPoint(rx, ry); 752 addPaint(paint); 753} 754 755void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) { 756 addOp(DisplayList::DrawCircle); 757 addPoint(x, y); 758 addFloat(radius); 759 addPaint(paint); 760} 761 762void DisplayListRenderer::drawOval(float left, float top, float right, float bottom, 763 SkPaint* paint) { 764 addOp(DisplayList::DrawOval); 765 addBounds(left, top, right, bottom); 766 addPaint(paint); 767} 768 769void DisplayListRenderer::drawArc(float left, float top, float right, float bottom, 770 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) { 771 addOp(DisplayList::DrawArc); 772 addBounds(left, top, right, bottom); 773 addPoint(startAngle, sweepAngle); 774 addInt(useCenter ? 1 : 0); 775 addPaint(paint); 776} 777 778void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) { 779 addOp(DisplayList::DrawPath); 780 addPath(path); 781 addPaint(paint); 782} 783 784void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) { 785 addOp(DisplayList::DrawLines); 786 addFloats(points, count); 787 addPaint(paint); 788} 789 790void DisplayListRenderer::drawText(const char* text, int bytesCount, int count, 791 float x, float y, SkPaint* paint) { 792 addOp(DisplayList::DrawText); 793 addText(text, bytesCount); 794 addInt(count); 795 addPoint(x, y); 796 addPaint(paint); 797} 798 799void DisplayListRenderer::resetShader() { 800 addOp(DisplayList::ResetShader); 801} 802 803void DisplayListRenderer::setupShader(SkiaShader* shader) { 804 addOp(DisplayList::SetupShader); 805 addShader(shader); 806} 807 808void DisplayListRenderer::resetColorFilter() { 809 addOp(DisplayList::ResetColorFilter); 810} 811 812void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) { 813 addOp(DisplayList::SetupColorFilter); 814 addColorFilter(filter); 815} 816 817void DisplayListRenderer::resetShadow() { 818 addOp(DisplayList::ResetShadow); 819} 820 821void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) { 822 addOp(DisplayList::SetupShadow); 823 addFloat(radius); 824 addPoint(dx, dy); 825 addInt(color); 826} 827 828}; // namespace uirenderer 829}; // namespace android 830