DisplayListRenderer.cpp revision cabfcc1364eb7e4de0b15b3574fba45027b45cfc
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, Rect& dirty, 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, dirty); 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, dirty, 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, Rect& dirty) { 593 // Ignore dirty during recording, it matters only when we replay 594 addOp(DisplayList::DrawGLFunction); 595 addInt((int) functor); 596 return false; // No invalidate needed at record-time 597} 598 599int DisplayListRenderer::save(int flags) { 600 addOp(DisplayList::Save); 601 addInt(flags); 602 return OpenGLRenderer::save(flags); 603} 604 605void DisplayListRenderer::restore() { 606 addOp(DisplayList::Restore); 607 OpenGLRenderer::restore(); 608} 609 610void DisplayListRenderer::restoreToCount(int saveCount) { 611 mRestoreSaveCount = saveCount; 612 OpenGLRenderer::restoreToCount(saveCount); 613} 614 615int DisplayListRenderer::saveLayer(float left, float top, float right, float bottom, 616 SkPaint* p, int flags) { 617 addOp(DisplayList::SaveLayer); 618 addBounds(left, top, right, bottom); 619 addPaint(p); 620 addInt(flags); 621 return OpenGLRenderer::save(flags); 622} 623 624int DisplayListRenderer::saveLayerAlpha(float left, float top, float right, float bottom, 625 int alpha, int flags) { 626 addOp(DisplayList::SaveLayerAlpha); 627 addBounds(left, top, right, bottom); 628 addInt(alpha); 629 addInt(flags); 630 return OpenGLRenderer::save(flags); 631} 632 633void DisplayListRenderer::translate(float dx, float dy) { 634 addOp(DisplayList::Translate); 635 addPoint(dx, dy); 636 OpenGLRenderer::translate(dx, dy); 637} 638 639void DisplayListRenderer::rotate(float degrees) { 640 addOp(DisplayList::Rotate); 641 addFloat(degrees); 642 OpenGLRenderer::rotate(degrees); 643} 644 645void DisplayListRenderer::scale(float sx, float sy) { 646 addOp(DisplayList::Scale); 647 addPoint(sx, sy); 648 OpenGLRenderer::scale(sx, sy); 649} 650 651void DisplayListRenderer::skew(float sx, float sy) { 652 addOp(DisplayList::Skew); 653 addPoint(sx, sy); 654 OpenGLRenderer::skew(sx, sy); 655} 656 657void DisplayListRenderer::setMatrix(SkMatrix* matrix) { 658 addOp(DisplayList::SetMatrix); 659 addMatrix(matrix); 660 OpenGLRenderer::setMatrix(matrix); 661} 662 663void DisplayListRenderer::concatMatrix(SkMatrix* matrix) { 664 addOp(DisplayList::ConcatMatrix); 665 addMatrix(matrix); 666 OpenGLRenderer::concatMatrix(matrix); 667} 668 669bool DisplayListRenderer::clipRect(float left, float top, float right, float bottom, 670 SkRegion::Op op) { 671 addOp(DisplayList::ClipRect); 672 addBounds(left, top, right, bottom); 673 addInt(op); 674 return OpenGLRenderer::clipRect(left, top, right, bottom, op); 675} 676 677bool DisplayListRenderer::drawDisplayList(DisplayList* displayList, Rect& dirty, uint32_t level) { 678 // dirty is an out parameter and should not be recorded, 679 // it matters only when replaying the display list 680 addOp(DisplayList::DrawDisplayList); 681 addDisplayList(displayList); 682 return false; 683} 684 685void DisplayListRenderer::drawLayer(Layer* layer, float x, float y, SkPaint* paint) { 686 addOp(DisplayList::DrawLayer); 687 addInt((int) layer); 688 addPoint(x, y); 689 addPaint(paint); 690} 691 692void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float left, float top, 693 SkPaint* paint) { 694 addOp(DisplayList::DrawBitmap); 695 addBitmap(bitmap); 696 addPoint(left, top); 697 addPaint(paint); 698} 699 700void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, SkMatrix* matrix, 701 SkPaint* paint) { 702 addOp(DisplayList::DrawBitmapMatrix); 703 addBitmap(bitmap); 704 addMatrix(matrix); 705 addPaint(paint); 706} 707 708void DisplayListRenderer::drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, 709 float srcRight, float srcBottom, float dstLeft, float dstTop, 710 float dstRight, float dstBottom, SkPaint* paint) { 711 addOp(DisplayList::DrawBitmapRect); 712 addBitmap(bitmap); 713 addBounds(srcLeft, srcTop, srcRight, srcBottom); 714 addBounds(dstLeft, dstTop, dstRight, dstBottom); 715 addPaint(paint); 716} 717 718void DisplayListRenderer::drawBitmapMesh(SkBitmap* bitmap, int meshWidth, int meshHeight, 719 float* vertices, int* colors, SkPaint* paint) { 720 addOp(DisplayList::DrawBitmapMesh); 721 addBitmap(bitmap); 722 addInt(meshWidth); 723 addInt(meshHeight); 724 addFloats(vertices, (meshWidth + 1) * (meshHeight + 1) * 2); 725 if (colors) { 726 addInt(1); 727 addInts(colors, (meshWidth + 1) * (meshHeight + 1)); 728 } else { 729 addInt(0); 730 } 731 addPaint(paint); 732} 733 734void DisplayListRenderer::drawPatch(SkBitmap* bitmap, const int32_t* xDivs, const int32_t* yDivs, 735 const uint32_t* colors, uint32_t width, uint32_t height, int8_t numColors, 736 float left, float top, float right, float bottom, SkPaint* paint) { 737 addOp(DisplayList::DrawPatch); 738 addBitmap(bitmap); 739 addInts(xDivs, width); 740 addInts(yDivs, height); 741 addUInts(colors, numColors); 742 addBounds(left, top, right, bottom); 743 addPaint(paint); 744} 745 746void DisplayListRenderer::drawColor(int color, SkXfermode::Mode mode) { 747 addOp(DisplayList::DrawColor); 748 addInt(color); 749 addInt(mode); 750} 751 752void DisplayListRenderer::drawRect(float left, float top, float right, float bottom, 753 SkPaint* paint) { 754 addOp(DisplayList::DrawRect); 755 addBounds(left, top, right, bottom); 756 addPaint(paint); 757} 758 759void DisplayListRenderer::drawRoundRect(float left, float top, float right, float bottom, 760 float rx, float ry, SkPaint* paint) { 761 addOp(DisplayList::DrawRoundRect); 762 addBounds(left, top, right, bottom); 763 addPoint(rx, ry); 764 addPaint(paint); 765} 766 767void DisplayListRenderer::drawCircle(float x, float y, float radius, SkPaint* paint) { 768 addOp(DisplayList::DrawCircle); 769 addPoint(x, y); 770 addFloat(radius); 771 addPaint(paint); 772} 773 774void DisplayListRenderer::drawOval(float left, float top, float right, float bottom, 775 SkPaint* paint) { 776 addOp(DisplayList::DrawOval); 777 addBounds(left, top, right, bottom); 778 addPaint(paint); 779} 780 781void DisplayListRenderer::drawArc(float left, float top, float right, float bottom, 782 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) { 783 addOp(DisplayList::DrawArc); 784 addBounds(left, top, right, bottom); 785 addPoint(startAngle, sweepAngle); 786 addInt(useCenter ? 1 : 0); 787 addPaint(paint); 788} 789 790void DisplayListRenderer::drawPath(SkPath* path, SkPaint* paint) { 791 addOp(DisplayList::DrawPath); 792 addPath(path); 793 addPaint(paint); 794} 795 796void DisplayListRenderer::drawLines(float* points, int count, SkPaint* paint) { 797 addOp(DisplayList::DrawLines); 798 addFloats(points, count); 799 addPaint(paint); 800} 801 802void DisplayListRenderer::drawText(const char* text, int bytesCount, int count, 803 float x, float y, SkPaint* paint) { 804 addOp(DisplayList::DrawText); 805 addText(text, bytesCount); 806 addInt(count); 807 addPoint(x, y); 808 addPaint(paint); 809} 810 811void DisplayListRenderer::resetShader() { 812 addOp(DisplayList::ResetShader); 813} 814 815void DisplayListRenderer::setupShader(SkiaShader* shader) { 816 addOp(DisplayList::SetupShader); 817 addShader(shader); 818} 819 820void DisplayListRenderer::resetColorFilter() { 821 addOp(DisplayList::ResetColorFilter); 822} 823 824void DisplayListRenderer::setupColorFilter(SkiaColorFilter* filter) { 825 addOp(DisplayList::SetupColorFilter); 826 addColorFilter(filter); 827} 828 829void DisplayListRenderer::resetShadow() { 830 addOp(DisplayList::ResetShadow); 831} 832 833void DisplayListRenderer::setupShadow(float radius, float dx, float dy, int color) { 834 addOp(DisplayList::SetupShadow); 835 addFloat(radius); 836 addPoint(dx, dy); 837 addInt(color); 838} 839 840}; // namespace uirenderer 841}; // namespace android 842