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

Side by Side Diff: cc/paint/paint_op_buffer.cc

Issue 2842333003: cc: Update discardable image metadata generation to get PaintImages. (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/paint/paint_op_buffer.h" 5 #include "cc/paint/paint_op_buffer.h"
6 6
7 #include "cc/paint/discardable_image_store.h"
7 #include "cc/paint/display_item_list.h" 8 #include "cc/paint/display_item_list.h"
8 #include "cc/paint/paint_record.h" 9 #include "cc/paint/paint_record.h"
9 #include "third_party/skia/include/core/SkAnnotation.h" 10 #include "third_party/skia/include/core/SkAnnotation.h"
10 11
11 namespace cc { 12 namespace cc {
13 namespace {
14 // Currently this function only handles extracting images from SkImageShaders
15 // embedded in SkPaints. Other embedded image cases, such as SkPictures,
16 // are not yet handled.
17 void AddImageFromFlags(DiscardableImageStore* image_store,
vmpstr 2017/04/27 16:28:54 It feels like this should be a member on Discardab
Khushal 2017/04/27 22:06:02 Done.
18 const SkRect& rect,
19 const PaintFlags& flags) {
20 SkShader* shader = flags.getShader();
21 if (shader) {
22 SkMatrix matrix;
23 SkShader::TileMode xy[2];
24 SkImage* image = shader->isAImage(&matrix, xy);
25 if (image) {
26 PaintImage paint_image(sk_ref_sp(image),
27 PaintImage::AnimationType::UNKNOWN,
28 PaintImage::CompletionState::UNKNOWN);
29 // TODO(ericrk): Handle cases where we only need a sub-rect from the
30 // image. crbug.com/671821
31 image_store->AddImage(paint_image, SkRect::MakeFromIRect(image->bounds()),
32 rect, &matrix, flags);
33 }
34 }
35 }
36
37 } // namespace
12 38
13 #define TYPES(M) \ 39 #define TYPES(M) \
14 M(AnnotateOp) \ 40 M(AnnotateOp) \
15 M(ClipPathOp) \ 41 M(ClipPathOp) \
16 M(ClipRectOp) \ 42 M(ClipRectOp) \
17 M(ClipRRectOp) \ 43 M(ClipRRectOp) \
18 M(ConcatOp) \ 44 M(ConcatOp) \
19 M(DrawArcOp) \ 45 M(DrawArcOp) \
20 M(DrawCircleOp) \ 46 M(DrawCircleOp) \
21 M(DrawColorOp) \ 47 M(DrawColorOp) \
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 593
568 // TODO(enne): ideally callers would just iterate themselves and we 594 // TODO(enne): ideally callers would just iterate themselves and we
569 // can remove the entire notion of an abort callback. 595 // can remove the entire notion of an abort callback.
570 for (auto* op : Iterator(this)) { 596 for (auto* op : Iterator(this)) {
571 op->Raster(canvas, original); 597 op->Raster(canvas, original);
572 if (callback && callback->abort()) 598 if (callback && callback->abort())
573 return; 599 return;
574 } 600 }
575 } 601 }
576 602
603 void PaintOpBuffer::GatherDiscardableImages(
vmpstr 2017/04/27 16:28:54 hmmmmm. Have you considered flipping |this| and |i
Khushal 2017/04/27 22:06:02 Done.
604 DiscardableImageStore* image_store) const {
605 if (!has_discardable_images_)
606 return;
607
608 SkCanvas* canvas = image_store->NoDrawCanvas();
609 SkMatrix original = canvas->getTotalMatrix();
610 canvas->save();
611 for (auto* op : Iterator(this)) {
vmpstr 2017/04/27 16:28:54 I was hoping to implement a smarter iterator for t
Khushal 2017/04/27 22:06:02 Yeah. Its worth looking at in a follow up patch.
612 if (op->IsDrawOp()) {
613 switch (op->GetType()) {
614 case PaintOpType::DrawArc: {
615 auto* arc_op = static_cast<DrawArcOp*>(op);
616 AddImageFromFlags(image_store, arc_op->oval, arc_op->flags);
617 } break;
618 case PaintOpType::DrawCircle: {
619 auto* circle_op = static_cast<DrawCircleOp*>(op);
620 SkRect rect =
621 SkRect::MakeXYWH(circle_op->cx - circle_op->radius,
622 circle_op->cy - circle_op->radius,
623 2 * circle_op->radius, 2 * circle_op->radius);
624 AddImageFromFlags(image_store, rect, circle_op->flags);
625 } break;
626 case PaintOpType::DrawDisplayItemList: {
627 auto* list_op = static_cast<DrawDisplayItemListOp*>(op);
628 list_op->list->GatherDiscardableImages(image_store);
629 } break;
630 case PaintOpType::DrawImage: {
631 auto* image_op = static_cast<DrawImageOp*>(op);
632 const SkImage* sk_image = image_op->image.sk_image().get();
633 image_store->AddImage(
634 image_op->image,
635 SkRect::MakeIWH(sk_image->width(), sk_image->height()),
636 SkRect::MakeXYWH(image_op->left, image_op->top, sk_image->width(),
637 sk_image->height()),
638 nullptr, image_op->flags);
639 } break;
640 case PaintOpType::DrawImageRect: {
641 auto* image_rect_op = static_cast<DrawImageRectOp*>(op);
642 SkMatrix matrix;
643 matrix.setRectToRect(image_rect_op->src, image_rect_op->dst,
644 SkMatrix::kFill_ScaleToFit);
645 image_store->AddImage(image_rect_op->image, image_rect_op->src,
646 image_rect_op->dst, &matrix,
647 image_rect_op->flags);
648 } break;
649 case PaintOpType::DrawIRect: {
650 auto* rect_op = static_cast<DrawIRectOp*>(op);
651 AddImageFromFlags(image_store, SkRect::Make(rect_op->rect),
652 rect_op->flags);
653 } break;
654 case PaintOpType::DrawOval: {
655 auto* oval_op = static_cast<DrawOvalOp*>(op);
656 AddImageFromFlags(image_store, oval_op->oval, oval_op->flags);
657 } break;
658 case PaintOpType::DrawPath: {
659 auto* path_op = static_cast<DrawPathOp*>(op);
660 AddImageFromFlags(image_store, path_op->path.getBounds(),
661 path_op->flags);
662 } break;
663 case PaintOpType::DrawRecord: {
664 auto* record_op = static_cast<DrawRecordOp*>(op);
665 record_op->record->GatherDiscardableImages(image_store);
666 } break;
667 case PaintOpType::DrawRect: {
668 auto* rect_op = static_cast<DrawRectOp*>(op);
669 AddImageFromFlags(image_store, rect_op->rect, rect_op->flags);
670 } break;
671 case PaintOpType::DrawRRect: {
672 auto* rect_op = static_cast<DrawRRectOp*>(op);
673 AddImageFromFlags(image_store, rect_op->rrect.rect(), rect_op->flags);
674 } break;
675 // TODO(khushalsagar): Check if we should be querying images from any of
676 // the following ops.
677 case PaintOpType::DrawPosText:
678 case PaintOpType::DrawLine:
679 case PaintOpType::DrawDRRect:
680 case PaintOpType::DrawText:
681 case PaintOpType::DrawTextBlob:
682 case PaintOpType::DrawColor:
683 break;
684 default:
685 NOTREACHED();
686 }
687 } else {
688 op->Raster(canvas, original);
689 }
690 }
691 canvas->restore();
692 }
693
577 void PaintOpBuffer::ShrinkToFit() { 694 void PaintOpBuffer::ShrinkToFit() {
578 if (!used_ || used_ == reserved_) 695 if (!used_ || used_ == reserved_)
579 return; 696 return;
580 data_.realloc(used_); 697 data_.realloc(used_);
581 reserved_ = used_; 698 reserved_ = used_;
582 } 699 }
583 700
584 } // namespace cc 701 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698