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