Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/core/SkLiteDL.cpp

Issue 2231553002: allocate memory manually in SkLiteDL (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: O(1) Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkLiteDL.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkImageFilter.h" 10 #include "SkImageFilter.h"
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 ? pod<SkColor>(this, count*(sizeof(SkRSXform) + sizeof(SkRect))) 461 ? pod<SkColor>(this, count*(sizeof(SkRSXform) + sizeof(SkRect)))
462 : nullptr; 462 : nullptr;
463 c->drawAtlas(atlas.get(), xforms, texs, colors, count, xfermode, 463 c->drawAtlas(atlas.get(), xforms, texs, colors, count, xfermode,
464 maybe_unset(cull), &paint); 464 maybe_unset(cull), &paint);
465 } 465 }
466 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &a tlas); } 466 void optimizeFor(GrContext* ctx) override { optimize_for(ctx, &paint, &a tlas); }
467 }; 467 };
468 } 468 }
469 469
470 template <typename T, typename... Args> 470 template <typename T, typename... Args>
471 static void* push(SkTDArray<uint8_t>* bytes, size_t pod, Args&&... args) { 471 void* SkLiteDL::push(size_t pod, Args&&... args) {
472 size_t skip = SkAlignPtr(sizeof(T) + pod); 472 size_t skip = SkAlignPtr(sizeof(T) + pod);
473 auto op = (T*)bytes->append(skip); 473 if (fUsed + skip > fReserved) {
474 fReserved = (fUsed + skip + 4096) & ~4095; // Next greater multiple of 4096.
475 fBytes.realloc(fReserved);
476 }
477 SkASSERT(fUsed + skip <= fReserved);
478 auto op = (T*)(fBytes.get() + fUsed);
479 fUsed += skip;
474 new (op) T{ std::forward<Args>(args)... }; 480 new (op) T{ std::forward<Args>(args)... };
475 op->skip = skip; 481 op->skip = skip;
476 return op+1; 482 return op+1;
477 } 483 }
478 484
479 template <typename Fn> 485 template <typename Fn>
480 static void map(SkTDArray<uint8_t>* bytes, Fn&& fn) { 486 void SkLiteDL::map(Fn&& fn) {
481 auto end = bytes->end(); 487 auto end = fBytes.get() + fUsed;
482 for (uint8_t* ptr = bytes->begin(); ptr < end; ) { 488 for (uint8_t* ptr = fBytes.get(); ptr < end; ) {
483 auto op = (Op*)ptr; 489 auto op = (Op*)ptr;
484 fn(op); 490 fn(op);
485 ptr += op->skip; 491 ptr += op->skip;
486 } 492 }
487 } 493 }
488 494
489 void SkLiteDL:: save() { push <Save>(&fBytes, 0); } 495 void SkLiteDL:: save() { this->push <Save>(0); }
490 void SkLiteDL::restore() { push<Restore>(&fBytes, 0); } 496 void SkLiteDL::restore() { this->push<Restore>(0); }
491 void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint, 497 void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
492 const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags) { 498 const SkImageFilter* backdrop, SkCanvas::SaveLayerFlags flags) {
493 push<SaveLayer>(&fBytes, 0, bounds, paint, backdrop, flags); 499 this->push<SaveLayer>(0, bounds, paint, backdrop, flags);
494 } 500 }
495 501
496 void SkLiteDL:: concat(const SkMatrix& matrix) { push <Concat>(&fBytes, 0, m atrix); } 502 void SkLiteDL:: concat(const SkMatrix& matrix) { this->push <Concat>(0, matr ix); }
497 void SkLiteDL::setMatrix(const SkMatrix& matrix) { push<SetMatrix>(&fBytes, 0, m atrix); } 503 void SkLiteDL::setMatrix(const SkMatrix& matrix) { this->push<SetMatrix>(0, matr ix); }
498 void SkLiteDL::translateZ(SkScalar dz) { push<TranslateZ>(&fBytes, 0, dz); } 504 void SkLiteDL::translateZ(SkScalar dz) { this->push<TranslateZ>(0, dz); }
499 505
500 void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) { 506 void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) {
501 push<ClipPath>(&fBytes, 0, path, op, aa); 507 this->push<ClipPath>(0, path, op, aa);
502 } 508 }
503 void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) { 509 void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) {
504 push<ClipRect>(&fBytes, 0, rect, op, aa); 510 this->push<ClipRect>(0, rect, op, aa);
505 } 511 }
506 void SkLiteDL::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) { 512 void SkLiteDL::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) {
507 push<ClipRRect>(&fBytes, 0, rrect, op, aa); 513 this->push<ClipRRect>(0, rrect, op, aa);
508 } 514 }
509 void SkLiteDL::clipRegion(const SkRegion& region, SkRegion::Op op) { 515 void SkLiteDL::clipRegion(const SkRegion& region, SkRegion::Op op) {
510 push<ClipRegion>(&fBytes, 0, region, op); 516 this->push<ClipRegion>(0, region, op);
511 } 517 }
512 518
513 void SkLiteDL::drawPaint(const SkPaint& paint) { 519 void SkLiteDL::drawPaint(const SkPaint& paint) {
514 push<DrawPaint>(&fBytes, 0, paint); 520 this->push<DrawPaint>(0, paint);
515 } 521 }
516 void SkLiteDL::drawPath(const SkPath& path, const SkPaint& paint) { 522 void SkLiteDL::drawPath(const SkPath& path, const SkPaint& paint) {
517 push<DrawPath>(&fBytes, 0, path, paint); 523 this->push<DrawPath>(0, path, paint);
518 } 524 }
519 void SkLiteDL::drawRect(const SkRect& rect, const SkPaint& paint) { 525 void SkLiteDL::drawRect(const SkRect& rect, const SkPaint& paint) {
520 push<DrawRect>(&fBytes, 0, rect, paint); 526 this->push<DrawRect>(0, rect, paint);
521 } 527 }
522 void SkLiteDL::drawOval(const SkRect& oval, const SkPaint& paint) { 528 void SkLiteDL::drawOval(const SkRect& oval, const SkPaint& paint) {
523 push<DrawOval>(&fBytes, 0, oval, paint); 529 this->push<DrawOval>(0, oval, paint);
524 } 530 }
525 void SkLiteDL::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 531 void SkLiteDL::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
526 push<DrawRRect>(&fBytes, 0, rrect, paint); 532 this->push<DrawRRect>(0, rrect, paint);
527 } 533 }
528 void SkLiteDL::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPa int& paint) { 534 void SkLiteDL::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPa int& paint) {
529 push<DrawDRRect>(&fBytes, 0, outer, inner, paint); 535 this->push<DrawDRRect>(0, outer, inner, paint);
530 } 536 }
531 537
532 void SkLiteDL::drawAnnotation(const SkRect& rect, const char* key, SkData* value ) { 538 void SkLiteDL::drawAnnotation(const SkRect& rect, const char* key, SkData* value ) {
533 size_t bytes = strlen(key)+1; 539 size_t bytes = strlen(key)+1;
534 void* pod = push<DrawAnnotation>(&fBytes, bytes, rect, value); 540 void* pod = this->push<DrawAnnotation>(bytes, rect, value);
535 copy_v(pod, key,bytes); 541 copy_v(pod, key,bytes);
536 } 542 }
537 void SkLiteDL::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { 543 void SkLiteDL::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
538 push<DrawDrawable>(&fBytes, 0, drawable, matrix); 544 this->push<DrawDrawable>(0, drawable, matrix);
539 } 545 }
540 void SkLiteDL::drawPicture(const SkPicture* picture, 546 void SkLiteDL::drawPicture(const SkPicture* picture,
541 const SkMatrix* matrix, const SkPaint* paint) { 547 const SkMatrix* matrix, const SkPaint* paint) {
542 push<DrawPicture>(&fBytes, 0, picture, matrix, paint); 548 this->push<DrawPicture>(0, picture, matrix, paint);
543 } 549 }
544 void SkLiteDL::drawShadowedPicture(const SkPicture* picture, 550 void SkLiteDL::drawShadowedPicture(const SkPicture* picture,
545 const SkMatrix* matrix, const SkPaint* paint) { 551 const SkMatrix* matrix, const SkPaint* paint) {
546 push<DrawShadowedPicture>(&fBytes, 0, picture, matrix, paint); 552 this->push<DrawShadowedPicture>(0, picture, matrix, paint);
547 } 553 }
548 554
549 void SkLiteDL::drawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPa int* paint) { 555 void SkLiteDL::drawBitmap(const SkBitmap& bm, SkScalar x, SkScalar y, const SkPa int* paint) {
550 push<DrawImage>(&fBytes, 0, SkImage::MakeFromBitmap(bm), x,y, paint); 556 this->push<DrawImage>(0, SkImage::MakeFromBitmap(bm), x,y, paint);
551 } 557 }
552 void SkLiteDL::drawBitmapNine(const SkBitmap& bm, const SkIRect& center, 558 void SkLiteDL::drawBitmapNine(const SkBitmap& bm, const SkIRect& center,
553 const SkRect& dst, const SkPaint* paint) { 559 const SkRect& dst, const SkPaint* paint) {
554 push<DrawImageNine>(&fBytes, 0, SkImage::MakeFromBitmap(bm), center, dst, pa int); 560 this->push<DrawImageNine>(0, SkImage::MakeFromBitmap(bm), center, dst, paint );
555 } 561 }
556 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec t& dst, 562 void SkLiteDL::drawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRec t& dst,
557 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) { 563 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) {
558 push<DrawImageRect>(&fBytes, 0, SkImage::MakeFromBitmap(bm), src, dst, paint , constraint); 564 this->push<DrawImageRect>(0, SkImage::MakeFromBitmap(bm), src, dst, paint, c onstraint);
559 } 565 }
560 566
561 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP aint* paint) { 567 void SkLiteDL::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP aint* paint) {
562 push<DrawImage>(&fBytes, 0, sk_ref_sp(image), x,y, paint); 568 this->push<DrawImage>(0, sk_ref_sp(image), x,y, paint);
563 } 569 }
564 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center, 570 void SkLiteDL::drawImageNine(const SkImage* image, const SkIRect& center,
565 const SkRect& dst, const SkPaint* paint) { 571 const SkRect& dst, const SkPaint* paint) {
566 push<DrawImageNine>(&fBytes, 0, sk_ref_sp(image), center, dst, paint); 572 this->push<DrawImageNine>(0, sk_ref_sp(image), center, dst, paint);
567 } 573 }
568 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe ct& dst, 574 void SkLiteDL::drawImageRect(const SkImage* image, const SkRect* src, const SkRe ct& dst,
569 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) { 575 const SkPaint* paint, SkCanvas::SrcRectConstraint c onstraint) {
570 push<DrawImageRect>(&fBytes, 0, sk_ref_sp(image), src, dst, paint, constrain t); 576 this->push<DrawImageRect>(0, sk_ref_sp(image), src, dst, paint, constraint);
571 } 577 }
572 void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l attice, 578 void SkLiteDL::drawImageLattice(const SkImage* image, const SkCanvas::Lattice& l attice,
573 const SkRect& dst, const SkPaint* paint) { 579 const SkRect& dst, const SkPaint* paint) {
574 int xs = lattice.fXCount, ys = lattice.fYCount; 580 int xs = lattice.fXCount, ys = lattice.fYCount;
575 size_t bytes = (xs + ys) * sizeof(int); 581 size_t bytes = (xs + ys) * sizeof(int);
576 void* pod = push<DrawImageLattice>(&fBytes, bytes, sk_ref_sp(image), xs, ys, dst, paint); 582 void* pod = this->push<DrawImageLattice>(bytes, sk_ref_sp(image), xs, ys, ds t, paint);
577 copy_v(pod, lattice.fXDivs, xs, 583 copy_v(pod, lattice.fXDivs, xs,
578 lattice.fYDivs, ys); 584 lattice.fYDivs, ys);
579 } 585 }
580 586
581 void SkLiteDL::drawText(const void* text, size_t bytes, 587 void SkLiteDL::drawText(const void* text, size_t bytes,
582 SkScalar x, SkScalar y, const SkPaint& paint) { 588 SkScalar x, SkScalar y, const SkPaint& paint) {
583 void* pod = push<DrawText>(&fBytes, bytes, bytes, x, y, paint); 589 void* pod = this->push<DrawText>(bytes, bytes, x, y, paint);
584 copy_v(pod, (const char*)text,bytes); 590 copy_v(pod, (const char*)text,bytes);
585 } 591 }
586 void SkLiteDL::drawPosText(const void* text, size_t bytes, 592 void SkLiteDL::drawPosText(const void* text, size_t bytes,
587 const SkPoint pos[], const SkPaint& paint) { 593 const SkPoint pos[], const SkPaint& paint) {
588 int n = paint.countText(text, bytes); 594 int n = paint.countText(text, bytes);
589 void* pod = push<DrawPosText>(&fBytes, n*sizeof(SkPoint)+bytes, bytes, paint , n); 595 void* pod = this->push<DrawPosText>(n*sizeof(SkPoint)+bytes, bytes, paint, n );
590 copy_v(pod, pos,n, (const char*)text,bytes); 596 copy_v(pod, pos,n, (const char*)text,bytes);
591 } 597 }
592 void SkLiteDL::drawPosTextH(const void* text, size_t bytes, 598 void SkLiteDL::drawPosTextH(const void* text, size_t bytes,
593 const SkScalar xs[], SkScalar y, const SkPaint& paint ) { 599 const SkScalar xs[], SkScalar y, const SkPaint& paint ) {
594 int n = paint.countText(text, bytes); 600 int n = paint.countText(text, bytes);
595 void* pod = push<DrawPosTextH>(&fBytes, n*sizeof(SkScalar)+bytes, bytes, y, paint, n); 601 void* pod = this->push<DrawPosTextH>(n*sizeof(SkScalar)+bytes, bytes, y, pai nt, n);
596 copy_v(pod, xs,n, (const char*)text,bytes); 602 copy_v(pod, xs,n, (const char*)text,bytes);
597 } 603 }
598 void SkLiteDL::drawTextOnPath(const void* text, size_t bytes, 604 void SkLiteDL::drawTextOnPath(const void* text, size_t bytes,
599 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) { 605 const SkPath& path, const SkMatrix* matrix, const SkPaint& paint) {
600 void* pod = push<DrawTextOnPath>(&fBytes, bytes, bytes, path, matrix, paint) ; 606 void* pod = this->push<DrawTextOnPath>(bytes, bytes, path, matrix, paint);
601 copy_v(pod, (const char*)text,bytes); 607 copy_v(pod, (const char*)text,bytes);
602 } 608 }
603 void SkLiteDL::drawTextRSXform(const void* text, size_t bytes, 609 void SkLiteDL::drawTextRSXform(const void* text, size_t bytes,
604 const SkRSXform xforms[], const SkRect* cull, con st SkPaint& paint) { 610 const SkRSXform xforms[], const SkRect* cull, con st SkPaint& paint) {
605 int n = paint.countText(text, bytes); 611 int n = paint.countText(text, bytes);
606 void* pod = push<DrawTextRSXform>(&fBytes, bytes+n*sizeof(SkRSXform), bytes, cull, paint); 612 void* pod = this->push<DrawTextRSXform>(bytes+n*sizeof(SkRSXform), bytes, cu ll, paint);
607 copy_v(pod, (const char*)text,bytes, xforms,n); 613 copy_v(pod, (const char*)text,bytes, xforms,n);
608 } 614 }
609 void SkLiteDL::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, cons t SkPaint& paint) { 615 void SkLiteDL::drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, cons t SkPaint& paint) {
610 push<DrawTextBlob>(&fBytes, 0, blob, x,y, paint); 616 this->push<DrawTextBlob>(0, blob, x,y, paint);
611 } 617 }
612 618
613 void SkLiteDL::drawPatch(const SkPoint points[12], const SkColor colors[4], cons t SkPoint texs[4], 619 void SkLiteDL::drawPatch(const SkPoint points[12], const SkColor colors[4], cons t SkPoint texs[4],
614 SkXfermode* xfermode, const SkPaint& paint) { 620 SkXfermode* xfermode, const SkPaint& paint) {
615 push<DrawPatch>(&fBytes, 0, points, colors, texs, xfermode, paint); 621 this->push<DrawPatch>(0, points, colors, texs, xfermode, paint);
616 } 622 }
617 void SkLiteDL::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint points[], 623 void SkLiteDL::drawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint points[],
618 const SkPaint& paint) { 624 const SkPaint& paint) {
619 void* pod = push<DrawPoints>(&fBytes, count*sizeof(SkPoint), mode, count, pa int); 625 void* pod = this->push<DrawPoints>(count*sizeof(SkPoint), mode, count, paint );
620 copy_v(pod, points,count); 626 copy_v(pod, points,count);
621 } 627 }
622 void SkLiteDL::drawVertices(SkCanvas::VertexMode mode, int count, const SkPoint vertices[], 628 void SkLiteDL::drawVertices(SkCanvas::VertexMode mode, int count, const SkPoint vertices[],
623 const SkPoint texs[], const SkColor colors[], SkXfer mode* xfermode, 629 const SkPoint texs[], const SkColor colors[], SkXfer mode* xfermode,
624 const uint16_t indices[], int nindices, const SkPain t& paint) { 630 const uint16_t indices[], int nindices, const SkPain t& paint) {
625 size_t bytes = count * sizeof(SkPoint); 631 size_t bytes = count * sizeof(SkPoint);
626 if (texs ) { bytes += count * sizeof(SkPoint); } 632 if (texs ) { bytes += count * sizeof(SkPoint); }
627 if (colors) { bytes += count * sizeof(SkColor); } 633 if (colors) { bytes += count * sizeof(SkColor); }
628 if (indices) { bytes += nindices * sizeof(uint16_t); } 634 if (indices) { bytes += nindices * sizeof(uint16_t); }
629 void* pod = push<DrawVertices>(&fBytes, bytes, mode, count, xfermode, nindic es, paint, 635 void* pod = this->push<DrawVertices>(bytes, mode, count, xfermode, nindices, paint,
630 texs != nullptr, colors != nullptr, indices ! = nullptr); 636 texs != nullptr, colors != nullptr, ind ices != nullptr);
631 copy_v(pod, vertices, count, 637 copy_v(pod, vertices, count,
632 texs, texs ? count : 0, 638 texs, texs ? count : 0,
633 colors, colors ? count : 0, 639 colors, colors ? count : 0,
634 indices, indices ? nindices : 0); 640 indices, indices ? nindices : 0);
635 } 641 }
636 void SkLiteDL::drawAtlas(const SkImage* atlas, const SkRSXform xforms[], const S kRect texs[], 642 void SkLiteDL::drawAtlas(const SkImage* atlas, const SkRSXform xforms[], const S kRect texs[],
637 const SkColor colors[], int count, SkXfermode::Mode xfe rmode, 643 const SkColor colors[], int count, SkXfermode::Mode xfe rmode,
638 const SkRect* cull, const SkPaint* paint) { 644 const SkRect* cull, const SkPaint* paint) {
639 size_t bytes = count*(sizeof(SkRSXform) + sizeof(SkRect)); 645 size_t bytes = count*(sizeof(SkRSXform) + sizeof(SkRect));
640 if (colors) { 646 if (colors) {
641 bytes += count*sizeof(SkColor); 647 bytes += count*sizeof(SkColor);
642 } 648 }
643 void* pod = push<DrawAtlas>(&fBytes, bytes, 649 void* pod = this->push<DrawAtlas>(bytes,
644 atlas, count, xfermode, cull, paint, colors != n ullptr); 650 atlas, count, xfermode, cull, paint, color s != nullptr);
645 copy_v(pod, xforms, count, 651 copy_v(pod, xforms, count,
646 texs, count, 652 texs, count,
647 colors, colors ? count : 0); 653 colors, colors ? count : 0);
648 } 654 }
649 655
650 656
651 void SkLiteDL::onDraw(SkCanvas* canvas) { 657 void SkLiteDL::onDraw(SkCanvas* canvas) {
652 map(&fBytes, [canvas](Op* op) { op->draw(canvas); }); 658 this->map([canvas](Op* op) { op->draw(canvas); });
653 } 659 }
654 660
655 void SkLiteDL::optimizeFor(GrContext* ctx) { 661 void SkLiteDL::optimizeFor(GrContext* ctx) {
656 map(&fBytes, [ctx](Op* op) { op->optimizeFor(ctx); }); 662 this->map([ctx](Op* op) { op->optimizeFor(ctx); });
657 } 663 }
658 664
659 void SkLiteDL::makeThreadsafe() { 665 void SkLiteDL::makeThreadsafe() {
660 map(&fBytes, [](Op* op) { op->makeThreadsafe(); }); 666 this->map([](Op* op) { op->makeThreadsafe(); });
661 } 667 }
662 668
663 SkRect SkLiteDL::onGetBounds() { 669 SkRect SkLiteDL::onGetBounds() {
664 return fBounds; 670 return fBounds;
665 } 671 }
666 672
667 #if !defined(SK_LITEDL_USES) 673 #if !defined(SK_LITEDL_USES)
668 #define SK_LITEDL_USES 16 674 #define SK_LITEDL_USES 16
669 #endif 675 #endif
670 676
671 SkLiteDL:: SkLiteDL() : fUsesRemaining(SK_LITEDL_USES) {} 677 SkLiteDL:: SkLiteDL() : fUsed(0), fReserved(0), fUsesRemaining(SK_LITEDL_USES) { }
672 SkLiteDL::~SkLiteDL() {} 678 SkLiteDL::~SkLiteDL() {}
673 679
674 // If you're tempted to make this lock free, please don't forget about ABA. 680 // If you're tempted to make this lock free, please don't forget about ABA.
675 static SkSpinlock gFreeStackLock; 681 static SkSpinlock gFreeStackLock;
676 static SkLiteDL* gFreeStack = nullptr; 682 static SkLiteDL* gFreeStack = nullptr;
677 683
678 sk_sp<SkLiteDL> SkLiteDL::New(SkRect bounds) { 684 sk_sp<SkLiteDL> SkLiteDL::New(SkRect bounds) {
679 sk_sp<SkLiteDL> dl; 685 sk_sp<SkLiteDL> dl;
680 { 686 {
681 SkAutoMutexAcquire lock(gFreeStackLock); 687 SkAutoMutexAcquire lock(gFreeStackLock);
(...skipping 10 matching lines...) Expand all
692 dl->fBounds = bounds; 698 dl->fBounds = bounds;
693 return dl; 699 return dl;
694 } 700 }
695 701
696 void SkLiteDL::internal_dispose() const { 702 void SkLiteDL::internal_dispose() const {
697 // Whether we delete this or leave it on the free stack, 703 // Whether we delete this or leave it on the free stack,
698 // we want its refcnt at 1. 704 // we want its refcnt at 1.
699 this->internal_dispose_restore_refcnt_to_1(); 705 this->internal_dispose_restore_refcnt_to_1();
700 706
701 auto self = const_cast<SkLiteDL*>(this); 707 auto self = const_cast<SkLiteDL*>(this);
702 map(&self->fBytes, [](Op* op) { op->~Op(); }); 708 self->map([](Op* op) { op->~Op(); });
703 709
704 if (--self->fUsesRemaining > 0) { 710 if (--self->fUsesRemaining > 0) {
705 self->fBytes.rewind(); 711 self->fUsed = 0;
706 712
707 SkAutoMutexAcquire lock(gFreeStackLock); 713 SkAutoMutexAcquire lock(gFreeStackLock);
708 self->fNext = gFreeStack; 714 self->fNext = gFreeStack;
709 gFreeStack = self; 715 gFreeStack = self;
710 return; 716 return;
711 } 717 }
712 718
713 delete this; 719 delete this;
714 } 720 }
715 721
716 void SkLiteDL::PurgeFreelist() { 722 void SkLiteDL::PurgeFreelist() {
717 SkAutoMutexAcquire lock(gFreeStackLock); 723 SkAutoMutexAcquire lock(gFreeStackLock);
718 while (gFreeStack) { 724 while (gFreeStack) {
719 SkLiteDL* top = gFreeStack; 725 SkLiteDL* top = gFreeStack;
720 gFreeStack = gFreeStack->fNext; 726 gFreeStack = gFreeStack->fNext;
721 delete top; // Calling unref() here would just put it back on the list ! 727 delete top; // Calling unref() here would just put it back on the list !
722 } 728 }
723 } 729 }
OLDNEW
« no previous file with comments | « src/core/SkLiteDL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698