Index: cc/paint/paint_op_buffer.h |
diff --git a/cc/paint/paint_op_buffer.h b/cc/paint/paint_op_buffer.h |
index fb3518b9d92f112a09748cc3db5f2047a2059958..1018b66069d068bc08966e622a718fd9ea312001 100644 |
--- a/cc/paint/paint_op_buffer.h |
+++ b/cc/paint/paint_op_buffer.h |
@@ -85,6 +85,7 @@ struct CC_PAINT_EXPORT PaintOp { |
void RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const; |
int CountSlowPaths() const { return 0; } |
+ bool HasDiscardableImages() const { return false; } |
// Returns the number of bytes used by this op in referenced sub records |
// and display lists. This doesn't count other objects like paths or blobs. |
@@ -281,6 +282,7 @@ struct CC_PAINT_EXPORT DrawDisplayItemListOp final : PaintOp { |
~DrawDisplayItemListOp(); |
void Raster(SkCanvas* canvas) const; |
size_t AdditionalBytesUsed() const; |
+ bool HasDiscardableImages() const; |
// TODO(enne): DisplayItemList should know number of slow paths. |
scoped_refptr<DisplayItemList> list; |
@@ -311,6 +313,7 @@ struct CC_PAINT_EXPORT DrawImageOp final : PaintOp { |
const PaintFlags* flags); |
~DrawImageOp(); |
void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
+ bool HasDiscardableImages() const; |
PaintImage image; |
SkScalar left; |
@@ -329,6 +332,7 @@ struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOp { |
PaintCanvas::SrcRectConstraint constraint); |
~DrawImageRectOp(); |
void RasterWithFlags(SkCanvas* canvas, const PaintFlags& flags) const; |
+ bool HasDiscardableImages() const; |
PaintImage image; |
PaintFlags flags; |
@@ -412,6 +416,7 @@ struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { |
~DrawRecordOp(); |
void Raster(SkCanvas* canvas) const; |
size_t AdditionalBytesUsed() const; |
+ bool HasDiscardableImages() const; |
sk_sp<const PaintRecord> record; |
}; |
@@ -570,6 +575,7 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
return sizeof(*this) + reserved_ + subrecord_bytes_used_; |
} |
int numSlowPaths() const { return num_slow_paths_; } |
+ bool HasDiscardableImages() const { return has_discardable_images_; } |
// Resize the PaintOpBuffer to exactly fit the current amount of used space. |
void ShrinkToFit(); |
@@ -721,6 +727,23 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
static int Count(const T* op) { return op->flags.getPathEffect() ? 1 : 0; } |
}; |
+ template <typename T, bool HasFlags> |
+ struct HasDiscardableImagesFromFlags { |
+ static bool HasDiscardableImages(const T* op) { return false; } |
+ }; |
+ |
+ template <typename T> |
+ struct HasDiscardableImagesFromFlags<T, true> { |
+ static bool HasDiscardableImages(const T* op) { |
+ if (!op->kIsDrawOp) |
+ return false; |
+ |
+ SkShader* shader = op->flags.getShader(); |
+ SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr; |
+ return image ? image->isLazyGenerated() : false; |
vmpstr
2017/04/25 17:43:40
return image && image->isLazyGenerated();
|
+ } |
+ }; |
+ |
template <typename T, typename... Args> |
T* push_internal(size_t bytes, Args&&... args) { |
size_t skip = SkAlignPtr(sizeof(T) + bytes); |
@@ -745,6 +768,7 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
op->type = static_cast<uint32_t>(T::kType); |
op->skip = 0; |
op_count_++; |
+ AnalyzeAddedOp(op); |
return op; |
} |
} |
@@ -763,13 +787,20 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
op->type = static_cast<uint32_t>(T::kType); |
op->skip = skip; |
op_count_++; |
+ AnalyzeAddedOp(op); |
+ return op; |
+ } |
+ template <typename T> |
+ void AnalyzeAddedOp(const T* op) { |
num_slow_paths_ += CountSlowPathsFromFlags<T, T::kHasPaintFlags>::Count(op); |
num_slow_paths_ += op->CountSlowPaths(); |
- subrecord_bytes_used_ += op->AdditionalBytesUsed(); |
+ has_discardable_images_ |= op->HasDiscardableImages(); |
+ has_discardable_images_ |= HasDiscardableImagesFromFlags< |
+ T, T::kHasPaintFlags>::HasDiscardableImages(op); |
- return op; |
+ subrecord_bytes_used_ += op->AdditionalBytesUsed(); |
} |
// As a performance optimization because n=1 is an extremely common case just |
@@ -785,6 +816,7 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt { |
int num_slow_paths_ = 0; |
// Record additional bytes used by referenced sub-records and display lists. |
size_t subrecord_bytes_used_ = 0; |
+ bool has_discardable_images_ = false; |
SkRect cull_rect_; |
DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); |