RecordingCanvas.cpp revision d2dfd8f128b632ed99418ab2b32949c939a9a369
1/* 2 * Copyright (C) 2015 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#include "RecordingCanvas.h" 18 19#include "DeferredLayerUpdater.h" 20#include "RecordedOp.h" 21#include "RenderNode.h" 22 23namespace android { 24namespace uirenderer { 25 26RecordingCanvas::RecordingCanvas(size_t width, size_t height) 27 : mState(*this) 28 , mResourceCache(ResourceCache::getInstance()) { 29 reset(width, height); 30} 31 32RecordingCanvas::~RecordingCanvas() { 33 LOG_ALWAYS_FATAL_IF(mDisplayList, 34 "Destroyed a RecordingCanvas during a record!"); 35} 36 37void RecordingCanvas::reset(int width, int height) { 38 LOG_ALWAYS_FATAL_IF(mDisplayList, 39 "prepareDirty called a second time during a recording!"); 40 mDisplayList = new DisplayList(); 41 42 mState.initializeSaveStack(width, height, 0, 0, width, height, Vector3()); 43 44 mDeferredBarrierType = DeferredBarrierType::InOrder; 45 mState.setDirtyClip(false); 46 mRestoreSaveCount = -1; 47} 48 49DisplayList* RecordingCanvas::finishRecording() { 50 mPaintMap.clear(); 51 mRegionMap.clear(); 52 mPathMap.clear(); 53 DisplayList* displayList = mDisplayList; 54 mDisplayList = nullptr; 55 mSkiaCanvasProxy.reset(nullptr); 56 return displayList; 57} 58 59SkCanvas* RecordingCanvas::asSkCanvas() { 60 LOG_ALWAYS_FATAL_IF(!mDisplayList, 61 "attempting to get an SkCanvas when we are not recording!"); 62 if (!mSkiaCanvasProxy) { 63 mSkiaCanvasProxy.reset(new SkiaCanvasProxy(this)); 64 } 65 66 // SkCanvas instances default to identity transform, but should inherit 67 // the state of this Canvas; if this code was in the SkiaCanvasProxy 68 // constructor, we couldn't cache mSkiaCanvasProxy. 69 SkMatrix parentTransform; 70 getMatrix(&parentTransform); 71 mSkiaCanvasProxy.get()->setMatrix(parentTransform); 72 73 return mSkiaCanvasProxy.get(); 74} 75 76// ---------------------------------------------------------------------------- 77// CanvasStateClient implementation 78// ---------------------------------------------------------------------------- 79 80void RecordingCanvas::onViewportInitialized() { 81} 82 83void RecordingCanvas::onSnapshotRestored(const Snapshot& removed, const Snapshot& restored) { 84 if (removed.flags & Snapshot::kFlagIsFboLayer) { 85 addOp(new (alloc()) EndLayerOp()); 86 } 87} 88 89// ---------------------------------------------------------------------------- 90// android/graphics/Canvas state operations 91// ---------------------------------------------------------------------------- 92// Save (layer) 93int RecordingCanvas::save(SkCanvas::SaveFlags flags) { 94 return mState.save((int) flags); 95} 96 97void RecordingCanvas::RecordingCanvas::restore() { 98 if (mRestoreSaveCount < 0) { 99 restoreToCount(getSaveCount() - 1); 100 return; 101 } 102 103 mRestoreSaveCount--; 104 mState.restore(); 105} 106 107void RecordingCanvas::restoreToCount(int saveCount) { 108 mRestoreSaveCount = saveCount; 109 mState.restoreToCount(saveCount); 110} 111 112int RecordingCanvas::saveLayer(float left, float top, float right, float bottom, const SkPaint* paint, 113 SkCanvas::SaveFlags flags) { 114 if (!(flags & SkCanvas::kClipToLayer_SaveFlag)) { 115 LOG_ALWAYS_FATAL("unclipped layers not supported"); 116 } 117 // force matrix/clip isolation for layer 118 flags |= SkCanvas::kClip_SaveFlag | SkCanvas::kMatrix_SaveFlag; 119 120 121 const Snapshot& previous = *mState.currentSnapshot(); 122 123 // initialize the snapshot as though it almost represents an FBO layer so deferred draw 124 // operations will be able to store and restore the current clip and transform info, and 125 // quick rejection will be correct (for display lists) 126 127 const Rect untransformedBounds(left, top, right, bottom); 128 129 // determine clipped bounds relative to previous viewport. 130 Rect visibleBounds = untransformedBounds; 131 previous.transform->mapRect(visibleBounds); 132 133 134 visibleBounds.doIntersect(previous.getRenderTargetClip()); 135 visibleBounds.snapToPixelBoundaries(); 136 137 Rect previousViewport(0, 0, previous.getViewportWidth(), previous.getViewportHeight()); 138 visibleBounds.doIntersect(previousViewport); 139 140 // Map visible bounds back to layer space, and intersect with parameter bounds 141 Rect layerBounds = visibleBounds; 142 Matrix4 inverse; 143 inverse.loadInverse(*previous.transform); 144 inverse.mapRect(layerBounds); 145 layerBounds.doIntersect(untransformedBounds); 146 147 int saveValue = mState.save((int) flags); 148 Snapshot& snapshot = *mState.writableSnapshot(); 149 150 // layerBounds is now original bounds, but with clipped to clip 151 // and viewport to ensure it's minimal size. 152 if (layerBounds.isEmpty() || untransformedBounds.isEmpty()) { 153 // Don't bother recording layer, since it's been rejected 154 snapshot.resetClip(0, 0, 0, 0); 155 return saveValue; 156 } 157 158 snapshot.flags |= Snapshot::kFlagFboTarget | Snapshot::kFlagIsFboLayer; 159 snapshot.initializeViewport(untransformedBounds.getWidth(), untransformedBounds.getHeight()); 160 snapshot.transform->loadTranslate(-untransformedBounds.left, -untransformedBounds.top, 0.0f); 161 162 Rect clip = layerBounds; 163 clip.translate(-untransformedBounds.left, -untransformedBounds.top); 164 snapshot.resetClip(clip.left, clip.top, clip.right, clip.bottom); 165 snapshot.roundRectClipState = nullptr; 166 167 addOp(new (alloc()) BeginLayerOp( 168 Rect(left, top, right, bottom), 169 *previous.transform, // transform to *draw* with 170 previous.getRenderTargetClip(), // clip to *draw* with 171 refPaint(paint))); 172 173 return saveValue; 174} 175 176// Matrix 177void RecordingCanvas::rotate(float degrees) { 178 if (degrees == 0) return; 179 180 mState.rotate(degrees); 181} 182 183void RecordingCanvas::scale(float sx, float sy) { 184 if (sx == 1 && sy == 1) return; 185 186 mState.scale(sx, sy); 187} 188 189void RecordingCanvas::skew(float sx, float sy) { 190 mState.skew(sx, sy); 191} 192 193void RecordingCanvas::translate(float dx, float dy) { 194 if (dx == 0 && dy == 0) return; 195 196 mState.translate(dx, dy, 0); 197} 198 199// Clip 200bool RecordingCanvas::getClipBounds(SkRect* outRect) const { 201 *outRect = mState.getLocalClipBounds().toSkRect(); 202 return !(outRect->isEmpty()); 203} 204bool RecordingCanvas::quickRejectRect(float left, float top, float right, float bottom) const { 205 return mState.quickRejectConservative(left, top, right, bottom); 206} 207bool RecordingCanvas::quickRejectPath(const SkPath& path) const { 208 SkRect bounds = path.getBounds(); 209 return mState.quickRejectConservative(bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); 210} 211bool RecordingCanvas::clipRect(float left, float top, float right, float bottom, SkRegion::Op op) { 212 return mState.clipRect(left, top, right, bottom, op); 213} 214bool RecordingCanvas::clipPath(const SkPath* path, SkRegion::Op op) { 215 return mState.clipPath(path, op); 216} 217bool RecordingCanvas::clipRegion(const SkRegion* region, SkRegion::Op op) { 218 return mState.clipRegion(region, op); 219} 220 221// ---------------------------------------------------------------------------- 222// android/graphics/Canvas draw operations 223// ---------------------------------------------------------------------------- 224void RecordingCanvas::drawColor(int color, SkXfermode::Mode mode) { 225 SkPaint paint; 226 paint.setColor(color); 227 paint.setXfermodeMode(mode); 228 drawPaint(paint); 229} 230 231void RecordingCanvas::drawPaint(const SkPaint& paint) { 232 // TODO: more efficient recording? 233 addOp(new (alloc()) RectOp( 234 mState.getRenderTargetClipBounds(), 235 Matrix4::identity(), 236 mState.getRenderTargetClipBounds(), 237 refPaint(&paint))); 238} 239 240static Rect calcBoundsOfPoints(const float* points, int floatCount) { 241 Rect unmappedBounds(points[0], points[1], points[0], points[1]); 242 for (int i = 2; i < floatCount; i += 2) { 243 unmappedBounds.expandToCover(points[i], points[i + 1]); 244 } 245 return unmappedBounds; 246} 247 248// Geometry 249void RecordingCanvas::drawPoints(const float* points, int floatCount, const SkPaint& paint) { 250 if (floatCount < 2) return; 251 floatCount &= ~0x1; // round down to nearest two 252 253 addOp(new (alloc()) PointsOp( 254 calcBoundsOfPoints(points, floatCount), 255 *mState.currentSnapshot()->transform, 256 mState.getRenderTargetClipBounds(), 257 refPaint(&paint), refBuffer<float>(points, floatCount), floatCount)); 258} 259 260void RecordingCanvas::drawLines(const float* points, int floatCount, const SkPaint& paint) { 261 if (floatCount < 4) return; 262 floatCount &= ~0x3; // round down to nearest four 263 264 addOp(new (alloc()) LinesOp( 265 calcBoundsOfPoints(points, floatCount), 266 *mState.currentSnapshot()->transform, 267 mState.getRenderTargetClipBounds(), 268 refPaint(&paint), refBuffer<float>(points, floatCount), floatCount)); 269} 270 271void RecordingCanvas::drawRect(float left, float top, float right, float bottom, const SkPaint& paint) { 272 addOp(new (alloc()) RectOp( 273 Rect(left, top, right, bottom), 274 *(mState.currentSnapshot()->transform), 275 mState.getRenderTargetClipBounds(), 276 refPaint(&paint))); 277} 278 279void RecordingCanvas::drawSimpleRects(const float* rects, int vertexCount, const SkPaint* paint) { 280 if (rects == nullptr) return; 281 282 Vertex* rectData = (Vertex*) mDisplayList->allocator.alloc(vertexCount * sizeof(Vertex)); 283 Vertex* vertex = rectData; 284 285 float left = FLT_MAX; 286 float top = FLT_MAX; 287 float right = FLT_MIN; 288 float bottom = FLT_MIN; 289 for (int index = 0; index < vertexCount; index += 4) { 290 float l = rects[index + 0]; 291 float t = rects[index + 1]; 292 float r = rects[index + 2]; 293 float b = rects[index + 3]; 294 295 Vertex::set(vertex++, l, t); 296 Vertex::set(vertex++, r, t); 297 Vertex::set(vertex++, l, b); 298 Vertex::set(vertex++, r, b); 299 300 left = std::min(left, l); 301 top = std::min(top, t); 302 right = std::max(right, r); 303 bottom = std::max(bottom, b); 304 } 305 addOp(new (alloc()) SimpleRectsOp( 306 Rect(left, top, right, bottom), 307 *(mState.currentSnapshot()->transform), 308 mState.getRenderTargetClipBounds(), 309 refPaint(paint), rectData, vertexCount)); 310} 311 312void RecordingCanvas::drawRegion(const SkRegion& region, const SkPaint& paint) { 313 if (paint.getStyle() == SkPaint::kFill_Style 314 && (!paint.isAntiAlias() || mState.currentTransform()->isSimple())) { 315 int count = 0; 316 Vector<float> rects; 317 SkRegion::Iterator it(region); 318 while (!it.done()) { 319 const SkIRect& r = it.rect(); 320 rects.push(r.fLeft); 321 rects.push(r.fTop); 322 rects.push(r.fRight); 323 rects.push(r.fBottom); 324 count += 4; 325 it.next(); 326 } 327 drawSimpleRects(rects.array(), count, &paint); 328 } else { 329 SkRegion::Iterator it(region); 330 while (!it.done()) { 331 const SkIRect& r = it.rect(); 332 drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); 333 it.next(); 334 } 335 } 336} 337void RecordingCanvas::drawRoundRect(float left, float top, float right, float bottom, 338 float rx, float ry, const SkPaint& paint) { 339 addOp(new (alloc()) RoundRectOp( 340 Rect(left, top, right, bottom), 341 *(mState.currentSnapshot()->transform), 342 mState.getRenderTargetClipBounds(), 343 refPaint(&paint), rx, ry)); 344} 345 346void RecordingCanvas::drawRoundRect( 347 CanvasPropertyPrimitive* left, CanvasPropertyPrimitive* top, 348 CanvasPropertyPrimitive* right, CanvasPropertyPrimitive* bottom, 349 CanvasPropertyPrimitive* rx, CanvasPropertyPrimitive* ry, 350 CanvasPropertyPaint* paint) { 351 mDisplayList->ref(left); 352 mDisplayList->ref(top); 353 mDisplayList->ref(right); 354 mDisplayList->ref(bottom); 355 mDisplayList->ref(rx); 356 mDisplayList->ref(ry); 357 mDisplayList->ref(paint); 358 refBitmapsInShader(paint->value.getShader()); 359 addOp(new (alloc()) RoundRectPropsOp( 360 *(mState.currentSnapshot()->transform), 361 mState.getRenderTargetClipBounds(), 362 &paint->value, 363 &left->value, &top->value, &right->value, &bottom->value, 364 &rx->value, &ry->value)); 365} 366 367void RecordingCanvas::drawCircle(float x, float y, float radius, const SkPaint& paint) { 368 // TODO: move to Canvas.h 369 if (radius <= 0) return; 370 drawOval(x - radius, y - radius, x + radius, y + radius, paint); 371} 372 373void RecordingCanvas::drawCircle( 374 CanvasPropertyPrimitive* x, CanvasPropertyPrimitive* y, 375 CanvasPropertyPrimitive* radius, CanvasPropertyPaint* paint) { 376 mDisplayList->ref(x); 377 mDisplayList->ref(y); 378 mDisplayList->ref(radius); 379 mDisplayList->ref(paint); 380 refBitmapsInShader(paint->value.getShader()); 381 addOp(new (alloc()) CirclePropsOp( 382 *(mState.currentSnapshot()->transform), 383 mState.getRenderTargetClipBounds(), 384 &paint->value, 385 &x->value, &y->value, &radius->value)); 386} 387 388 389void RecordingCanvas::drawOval(float left, float top, float right, float bottom, const SkPaint& paint) { 390 addOp(new (alloc()) OvalOp( 391 Rect(left, top, right, bottom), 392 *(mState.currentSnapshot()->transform), 393 mState.getRenderTargetClipBounds(), 394 refPaint(&paint))); 395} 396 397void RecordingCanvas::drawArc(float left, float top, float right, float bottom, 398 float startAngle, float sweepAngle, bool useCenter, const SkPaint& paint) { 399 addOp(new (alloc()) ArcOp( 400 Rect(left, top, right, bottom), 401 *(mState.currentSnapshot()->transform), 402 mState.getRenderTargetClipBounds(), 403 refPaint(&paint), 404 startAngle, sweepAngle, useCenter)); 405} 406 407void RecordingCanvas::drawPath(const SkPath& path, const SkPaint& paint) { 408 addOp(new (alloc()) PathOp( 409 Rect(path.getBounds()), 410 *(mState.currentSnapshot()->transform), 411 mState.getRenderTargetClipBounds(), 412 refPaint(&paint), refPath(&path))); 413} 414 415// Bitmap-based 416void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, float left, float top, const SkPaint* paint) { 417 save(SkCanvas::kMatrix_SaveFlag); 418 translate(left, top); 419 drawBitmap(&bitmap, paint); 420 restore(); 421} 422 423void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, const SkMatrix& matrix, 424 const SkPaint* paint) { 425 if (matrix.isIdentity()) { 426 drawBitmap(&bitmap, paint); 427 } else if (!(matrix.getType() & ~(SkMatrix::kScale_Mask | SkMatrix::kTranslate_Mask)) 428 && MathUtils::isPositive(matrix.getScaleX()) 429 && MathUtils::isPositive(matrix.getScaleY())) { 430 // SkMatrix::isScaleTranslate() not available in L 431 SkRect src; 432 SkRect dst; 433 bitmap.getBounds(&src); 434 matrix.mapRect(&dst, src); 435 drawBitmap(bitmap, src.fLeft, src.fTop, src.fRight, src.fBottom, 436 dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, paint); 437 } else { 438 save(SkCanvas::kMatrix_SaveFlag); 439 concat(matrix); 440 drawBitmap(&bitmap, paint); 441 restore(); 442 } 443} 444 445void RecordingCanvas::drawBitmap(const SkBitmap& bitmap, float srcLeft, float srcTop, 446 float srcRight, float srcBottom, float dstLeft, float dstTop, 447 float dstRight, float dstBottom, const SkPaint* paint) { 448 if (srcLeft == 0 && srcTop == 0 449 && srcRight == bitmap.width() 450 && srcBottom == bitmap.height() 451 && (srcBottom - srcTop == dstBottom - dstTop) 452 && (srcRight - srcLeft == dstRight - dstLeft)) { 453 // transform simple rect to rect drawing case into position bitmap ops, since they merge 454 save(SkCanvas::kMatrix_SaveFlag); 455 translate(dstLeft, dstTop); 456 drawBitmap(&bitmap, paint); 457 restore(); 458 } else { 459 addOp(new (alloc()) BitmapRectOp( 460 Rect(dstLeft, dstTop, dstRight, dstBottom), 461 *(mState.currentSnapshot()->transform), 462 mState.getRenderTargetClipBounds(), 463 refPaint(paint), refBitmap(bitmap), 464 Rect(srcLeft, srcTop, srcRight, srcBottom))); 465 } 466} 467 468void RecordingCanvas::drawBitmapMesh(const SkBitmap& bitmap, int meshWidth, int meshHeight, 469 const float* vertices, const int* colors, const SkPaint* paint) { 470 int vertexCount = (meshWidth + 1) * (meshHeight + 1); 471 addOp(new (alloc()) BitmapMeshOp( 472 calcBoundsOfPoints(vertices, vertexCount * 2), 473 *(mState.currentSnapshot()->transform), 474 mState.getRenderTargetClipBounds(), 475 refPaint(paint), refBitmap(bitmap), meshWidth, meshHeight, 476 refBuffer<float>(vertices, vertexCount * 2), // 2 floats per vertex 477 refBuffer<int>(colors, vertexCount))); // 1 color per vertex 478} 479 480void RecordingCanvas::drawNinePatch(const SkBitmap& bitmap, const android::Res_png_9patch& patch, 481 float dstLeft, float dstTop, float dstRight, float dstBottom, 482 const SkPaint* paint) { 483 addOp(new (alloc()) PatchOp( 484 Rect(dstLeft, dstTop, dstRight, dstBottom), 485 *(mState.currentSnapshot()->transform), 486 mState.getRenderTargetClipBounds(), 487 refPaint(paint), refBitmap(bitmap), refPatch(&patch))); 488} 489 490// Text 491void RecordingCanvas::drawText(const uint16_t* glyphs, const float* positions, int glyphCount, 492 const SkPaint& paint, float x, float y, float boundsLeft, float boundsTop, 493 float boundsRight, float boundsBottom, float totalAdvance) { 494 if (!glyphs || !positions || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return; 495 glyphs = refBuffer<glyph_t>(glyphs, glyphCount); 496 positions = refBuffer<float>(positions, glyphCount * 2); 497 498 // TODO: either must account for text shadow in bounds, or record separate ops for text shadows 499 addOp(new (alloc()) TextOp( 500 Rect(boundsLeft, boundsTop, boundsRight, boundsBottom), 501 *(mState.currentSnapshot()->transform), 502 mState.getRenderTargetClipBounds(), 503 refPaint(&paint), glyphs, positions, glyphCount, x, y)); 504 drawTextDecorations(x, y, totalAdvance, paint); 505} 506 507void RecordingCanvas::drawTextOnPath(const uint16_t* glyphs, int glyphCount, const SkPath& path, 508 float hOffset, float vOffset, const SkPaint& paint) { 509 if (!glyphs || glyphCount <= 0 || PaintUtils::paintWillNotDrawText(paint)) return; 510 glyphs = refBuffer<glyph_t>(glyphs, glyphCount); 511 addOp(new (alloc()) TextOnPathOp( 512 mState.getRenderTargetClipBounds(), // TODO: explicitly define bounds 513 *(mState.currentSnapshot()->transform), 514 mState.getRenderTargetClipBounds(), 515 refPaint(&paint), glyphs, glyphCount, refPath(&path), hOffset, vOffset)); 516} 517 518void RecordingCanvas::drawBitmap(const SkBitmap* bitmap, const SkPaint* paint) { 519 addOp(new (alloc()) BitmapOp( 520 Rect(bitmap->width(), bitmap->height()), 521 *(mState.currentSnapshot()->transform), 522 mState.getRenderTargetClipBounds(), 523 refPaint(paint), refBitmap(*bitmap))); 524} 525 526void RecordingCanvas::drawRenderNode(RenderNode* renderNode) { 527 auto&& stagingProps = renderNode->stagingProperties(); 528 RenderNodeOp* op = new (alloc()) RenderNodeOp( 529 Rect(stagingProps.getWidth(), stagingProps.getHeight()), 530 *(mState.currentSnapshot()->transform), 531 mState.getRenderTargetClipBounds(), 532 renderNode); 533 int opIndex = addOp(op); 534 int childIndex = mDisplayList->addChild(op); 535 536 // update the chunk's child indices 537 DisplayList::Chunk& chunk = mDisplayList->chunks.back(); 538 chunk.endChildIndex = childIndex + 1; 539 540 if (renderNode->stagingProperties().isProjectionReceiver()) { 541 // use staging property, since recording on UI thread 542 mDisplayList->projectionReceiveIndex = opIndex; 543 } 544} 545 546void RecordingCanvas::drawLayer(DeferredLayerUpdater* layerHandle) { 547 // We ref the DeferredLayerUpdater due to its thread-safe ref-counting semantics. 548 mDisplayList->ref(layerHandle); 549 550 Layer* layer = layerHandle->backingLayer(); 551 Matrix4 totalTransform(*(mState.currentSnapshot()->transform)); 552 totalTransform.multiply(layer->getTransform()); 553 554 addOp(new (alloc()) TextureLayerOp( 555 Rect(layer->getWidth(), layer->getHeight()), 556 totalTransform, 557 mState.getRenderTargetClipBounds(), 558 layer)); 559} 560 561void RecordingCanvas::callDrawGLFunction(Functor* functor) { 562 mDisplayList->functors.push_back(functor); 563 addOp(new (alloc()) FunctorOp( 564 mState.getRenderTargetClipBounds(), // TODO: explicitly define bounds 565 *(mState.currentSnapshot()->transform), 566 mState.getRenderTargetClipBounds(), 567 functor)); 568} 569 570size_t RecordingCanvas::addOp(RecordedOp* op) { 571 // TODO: validate if "addDrawOp" quickrejection logic is useful before adding 572 int insertIndex = mDisplayList->ops.size(); 573 mDisplayList->ops.push_back(op); 574 if (mDeferredBarrierType != DeferredBarrierType::None) { 575 // op is first in new chunk 576 mDisplayList->chunks.emplace_back(); 577 DisplayList::Chunk& newChunk = mDisplayList->chunks.back(); 578 newChunk.beginOpIndex = insertIndex; 579 newChunk.endOpIndex = insertIndex + 1; 580 newChunk.reorderChildren = (mDeferredBarrierType == DeferredBarrierType::OutOfOrder); 581 582 int nextChildIndex = mDisplayList->children.size(); 583 newChunk.beginChildIndex = newChunk.endChildIndex = nextChildIndex; 584 mDeferredBarrierType = DeferredBarrierType::None; 585 } else { 586 // standard case - append to existing chunk 587 mDisplayList->chunks.back().endOpIndex = insertIndex + 1; 588 } 589 return insertIndex; 590} 591 592void RecordingCanvas::refBitmapsInShader(const SkShader* shader) { 593 if (!shader) return; 594 595 // If this paint has an SkShader that has an SkBitmap add 596 // it to the bitmap pile 597 SkBitmap bitmap; 598 SkShader::TileMode xy[2]; 599 if (shader->isABitmap(&bitmap, nullptr, xy)) { 600 refBitmap(bitmap); 601 return; 602 } 603 SkShader::ComposeRec rec; 604 if (shader->asACompose(&rec)) { 605 refBitmapsInShader(rec.fShaderA); 606 refBitmapsInShader(rec.fShaderB); 607 return; 608 } 609} 610 611}; // namespace uirenderer 612}; // namespace android 613