| OLD | NEW |
| 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/display_item_list.h" | 7 #include "cc/paint/display_item_list.h" |
| 8 #include "cc/paint/paint_record.h" | 8 #include "cc/paint/paint_record.h" |
| 9 #include "third_party/skia/include/core/SkAnnotation.h" | 9 #include "third_party/skia/include/core/SkAnnotation.h" |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 const SkMatrix& original_ctm) { | 113 const SkMatrix& original_ctm) { |
| 114 op->Raster(canvas); | 114 op->Raster(canvas); |
| 115 } | 115 } |
| 116 static void RasterWithAlpha(const DrawRecordOp* op, | 116 static void RasterWithAlpha(const DrawRecordOp* op, |
| 117 SkCanvas* canvas, | 117 SkCanvas* canvas, |
| 118 uint8_t alpha) { | 118 uint8_t alpha) { |
| 119 // This "looking into records" optimization is done here instead of | 119 // This "looking into records" optimization is done here instead of |
| 120 // in the PaintOpBuffer::Raster function as DisplayItemList calls | 120 // in the PaintOpBuffer::Raster function as DisplayItemList calls |
| 121 // into RasterWithAlpha directly. | 121 // into RasterWithAlpha directly. |
| 122 if (op->record->approximateOpCount() == 1) { | 122 if (op->record->approximateOpCount() == 1) { |
| 123 op->record->GetFirstOp()->RasterWithAlpha(canvas, alpha); | 123 PaintOp* single_op = op->record->GetFirstOp(); |
| 124 return; | 124 // RasterWithAlpha only supported for draw ops. |
| 125 if (single_op->IsDrawOp()) { |
| 126 single_op->RasterWithAlpha(canvas, alpha); |
| 127 return; |
| 128 } |
| 125 } | 129 } |
| 126 | 130 |
| 127 canvas->saveLayerAlpha(nullptr, alpha); | 131 canvas->saveLayerAlpha(nullptr, alpha); |
| 128 op->Raster(canvas); | 132 op->Raster(canvas); |
| 129 canvas->restore(); | 133 canvas->restore(); |
| 130 } | 134 } |
| 131 }; | 135 }; |
| 132 | 136 |
| 133 // TODO(enne): partially specialize RasterWithAlpha for draw color? | 137 // TODO(enne): partially specialize RasterWithAlpha for draw color? |
| 134 | 138 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 355 } |
| 352 | 356 |
| 353 void PaintOp::Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const { | 357 void PaintOp::Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const { |
| 354 g_raster_functions[type](this, canvas, original_ctm); | 358 g_raster_functions[type](this, canvas, original_ctm); |
| 355 } | 359 } |
| 356 | 360 |
| 357 void PaintOp::RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const { | 361 void PaintOp::RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const { |
| 358 g_raster_alpha_functions[type](this, canvas, alpha); | 362 g_raster_alpha_functions[type](this, canvas, alpha); |
| 359 } | 363 } |
| 360 | 364 |
| 361 DrawDisplayItemListOp::DrawDisplayItemListOp( | |
| 362 scoped_refptr<DisplayItemList> list) | |
| 363 : list(list) {} | |
| 364 | |
| 365 size_t DrawDisplayItemListOp::AdditionalBytesUsed() const { | |
| 366 return list->ApproximateMemoryUsage(); | |
| 367 } | |
| 368 | |
| 369 int ClipPathOp::CountSlowPaths() const { | 365 int ClipPathOp::CountSlowPaths() const { |
| 370 return antialias && !path.isConvex() ? 1 : 0; | 366 return antialias && !path.isConvex() ? 1 : 0; |
| 371 } | 367 } |
| 372 | 368 |
| 373 int DrawLineOp::CountSlowPaths() const { | 369 int DrawLineOp::CountSlowPaths() const { |
| 374 if (const SkPathEffect* effect = flags.getPathEffect()) { | 370 if (const SkPathEffect* effect = flags.getPathEffect()) { |
| 375 SkPathEffect::DashInfo info; | 371 SkPathEffect::DashInfo info; |
| 376 SkPathEffect::DashType dashType = effect->asADash(&info); | 372 SkPathEffect::DashType dashType = effect->asADash(&info); |
| 377 if (flags.getStrokeCap() != PaintFlags::kRound_Cap && | 373 if (flags.getStrokeCap() != PaintFlags::kRound_Cap && |
| 378 dashType == SkPathEffect::kDash_DashType && info.fCount == 2) { | 374 dashType == SkPathEffect::kDash_DashType && info.fCount == 2) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 405 } | 401 } |
| 406 } | 402 } |
| 407 | 403 |
| 408 AnnotateOp::AnnotateOp(PaintCanvas::AnnotationType annotation_type, | 404 AnnotateOp::AnnotateOp(PaintCanvas::AnnotationType annotation_type, |
| 409 const SkRect& rect, | 405 const SkRect& rect, |
| 410 sk_sp<SkData> data) | 406 sk_sp<SkData> data) |
| 411 : annotation_type(annotation_type), rect(rect), data(std::move(data)) {} | 407 : annotation_type(annotation_type), rect(rect), data(std::move(data)) {} |
| 412 | 408 |
| 413 AnnotateOp::~AnnotateOp() = default; | 409 AnnotateOp::~AnnotateOp() = default; |
| 414 | 410 |
| 411 DrawDisplayItemListOp::DrawDisplayItemListOp( |
| 412 scoped_refptr<DisplayItemList> list) |
| 413 : list(list) {} |
| 414 |
| 415 size_t DrawDisplayItemListOp::AdditionalBytesUsed() const { |
| 416 return list->ApproximateMemoryUsage(); |
| 417 } |
| 418 |
| 419 DrawDisplayItemListOp::DrawDisplayItemListOp(const DrawDisplayItemListOp& op) = |
| 420 default; |
| 421 |
| 422 DrawDisplayItemListOp& DrawDisplayItemListOp::operator=( |
| 423 const DrawDisplayItemListOp& op) = default; |
| 424 |
| 415 DrawDisplayItemListOp::~DrawDisplayItemListOp() = default; | 425 DrawDisplayItemListOp::~DrawDisplayItemListOp() = default; |
| 416 | 426 |
| 417 DrawImageOp::DrawImageOp(const PaintImage& image, | 427 DrawImageOp::DrawImageOp(const PaintImage& image, |
| 418 SkScalar left, | 428 SkScalar left, |
| 419 SkScalar top, | 429 SkScalar top, |
| 420 const PaintFlags* flags) | 430 const PaintFlags* flags) |
| 421 : image(image), | 431 : image(image), |
| 422 left(left), | 432 left(left), |
| 423 top(top), | 433 top(top), |
| 424 flags(flags ? *flags : PaintFlags()) {} | 434 flags(flags ? *flags : PaintFlags()) {} |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 557 } |
| 548 | 558 |
| 549 void PaintOpBuffer::ShrinkToFit() { | 559 void PaintOpBuffer::ShrinkToFit() { |
| 550 if (!used_ || used_ == reserved_) | 560 if (!used_ || used_ == reserved_) |
| 551 return; | 561 return; |
| 552 data_.realloc(used_); | 562 data_.realloc(used_); |
| 553 reserved_ = used_; | 563 reserved_ = used_; |
| 554 } | 564 } |
| 555 | 565 |
| 556 } // namespace cc | 566 } // namespace cc |
| OLD | NEW |