Commit 8efa3b7d authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Process up to 10 draw ops for full-layer solid color analysis

Currently, we only process 1 draw op when checking if a layer is solid
color, despite DisplayItemList::ShouldBeAnalyzedForSolidColor having
a cutoff of 10.

This change updates GetColorIfSolidInRect to take the number of ops to
analyze, and causes RecordingSource::DetermineIfSolidColor to use a
value of 10 for full-layer checks.

R=vmpstr
Bug:741219

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Id4b2a72994835d096ed0f4aad24deb663e90d459
Reviewed-on: https://chromium-review.googlesource.com/567554
Commit-Queue: Eric Karl <ericrk@chromium.org>
Reviewed-by: default avatarVladimir Levin <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486567}
parent 37dd3d78
...@@ -24,6 +24,10 @@ const bool kDefaultClearCanvasSetting = false; ...@@ -24,6 +24,10 @@ const bool kDefaultClearCanvasSetting = false;
const bool kDefaultClearCanvasSetting = true; const bool kDefaultClearCanvasSetting = true;
#endif #endif
// We don't perform per-layer solid color analysis when there are too many skia
// operations.
const int kMaxOpsToAnalyzeForLayer = 10;
} // namespace } // namespace
namespace cc { namespace cc {
...@@ -141,14 +145,13 @@ void RecordingSource::DetermineIfSolidColor() { ...@@ -141,14 +145,13 @@ void RecordingSource::DetermineIfSolidColor() {
is_solid_color_ = false; is_solid_color_ = false;
solid_color_ = SK_ColorTRANSPARENT; solid_color_ = SK_ColorTRANSPARENT;
// TODO(vmpstr): We can probably remove this check. if (display_list_->op_count() > kMaxOpsToAnalyzeForLayer)
if (!display_list_->ShouldBeAnalyzedForSolidColor())
return; return;
TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
display_list_->op_count()); display_list_->op_count());
is_solid_color_ = is_solid_color_ = display_list_->GetColorIfSolidInRect(
display_list_->GetColorIfSolidInRect(gfx::Rect(GetSize()), &solid_color_); gfx::Rect(GetSize()), &solid_color_, kMaxOpsToAnalyzeForLayer);
} }
} // namespace cc } // namespace cc
...@@ -26,10 +26,6 @@ namespace cc { ...@@ -26,10 +26,6 @@ namespace cc {
namespace { namespace {
// We don't perform per-layer solid color analysis when there are too many skia
// operations.
const int kOpCountThatIsOkToAnalyze = 10;
bool GetCanvasClipBounds(SkCanvas* canvas, gfx::Rect* clip_bounds) { bool GetCanvasClipBounds(SkCanvas* canvas, gfx::Rect* clip_bounds) {
SkRect canvas_clip_bounds; SkRect canvas_clip_bounds;
if (!canvas->getLocalClipBounds(&canvas_clip_bounds)) if (!canvas->getLocalClipBounds(&canvas_clip_bounds))
...@@ -86,10 +82,6 @@ size_t DisplayItemList::BytesUsed() const { ...@@ -86,10 +82,6 @@ size_t DisplayItemList::BytesUsed() const {
return sizeof(*this) + paint_op_buffer_.bytes_used(); return sizeof(*this) + paint_op_buffer_.bytes_used();
} }
bool DisplayItemList::ShouldBeAnalyzedForSolidColor() const {
return op_count() <= kOpCountThatIsOkToAnalyze;
}
void DisplayItemList::EmitTraceSnapshot() const { void DisplayItemList::EmitTraceSnapshot() const {
bool include_items; bool include_items;
TRACE_EVENT_CATEGORY_GROUP_ENABLED( TRACE_EVENT_CATEGORY_GROUP_ENABLED(
...@@ -196,7 +188,8 @@ sk_sp<PaintRecord> DisplayItemList::ReleaseAsRecord() { ...@@ -196,7 +188,8 @@ sk_sp<PaintRecord> DisplayItemList::ReleaseAsRecord() {
} }
bool DisplayItemList::GetColorIfSolidInRect(const gfx::Rect& rect, bool DisplayItemList::GetColorIfSolidInRect(const gfx::Rect& rect,
SkColor* color) { SkColor* color,
int max_ops_to_analyze) {
std::vector<size_t>* indices_to_use = nullptr; std::vector<size_t>* indices_to_use = nullptr;
std::vector<size_t> indices; std::vector<size_t> indices;
if (!rect.Contains(rtree_.GetBounds())) { if (!rect.Contains(rtree_.GetBounds())) {
...@@ -205,8 +198,8 @@ bool DisplayItemList::GetColorIfSolidInRect(const gfx::Rect& rect, ...@@ -205,8 +198,8 @@ bool DisplayItemList::GetColorIfSolidInRect(const gfx::Rect& rect,
} }
base::Optional<SkColor> solid_color = base::Optional<SkColor> solid_color =
SolidColorAnalyzer::DetermineIfSolidColor(&paint_op_buffer_, rect, SolidColorAnalyzer::DetermineIfSolidColor(
indices_to_use); &paint_op_buffer_, rect, max_ops_to_analyze, indices_to_use);
if (solid_color) { if (solid_color) {
*color = *solid_color; *color = *solid_color;
return true; return true;
......
...@@ -113,7 +113,6 @@ class CC_PAINT_EXPORT DisplayItemList ...@@ -113,7 +113,6 @@ class CC_PAINT_EXPORT DisplayItemList
// This gives the total number of PaintOps. // This gives the total number of PaintOps.
size_t op_count() const { return paint_op_buffer_.size(); } size_t op_count() const { return paint_op_buffer_.size(); }
size_t BytesUsed() const; size_t BytesUsed() const;
bool ShouldBeAnalyzedForSolidColor() const;
void EmitTraceSnapshot() const; void EmitTraceSnapshot() const;
...@@ -138,7 +137,12 @@ class CC_PAINT_EXPORT DisplayItemList ...@@ -138,7 +137,12 @@ class CC_PAINT_EXPORT DisplayItemList
// an empty state. // an empty state.
sk_sp<PaintRecord> ReleaseAsRecord(); sk_sp<PaintRecord> ReleaseAsRecord();
bool GetColorIfSolidInRect(const gfx::Rect& rect, SkColor* color); // If a rectangle is solid color, returns that color. |max_ops_to_analyze|
// indicates the maximum number of draw ops we consider when determining if a
// rectangle is solid color.
bool GetColorIfSolidInRect(const gfx::Rect& rect,
SkColor* color,
int max_ops_to_analyze = 1);
private: private:
FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoOps); FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, AsValueWithNoOps);
......
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
namespace cc { namespace cc {
namespace { namespace {
const int kMaxOpsToAnalyze = 1;
bool ActsLikeClear(SkBlendMode mode, unsigned src_alpha) { bool ActsLikeClear(SkBlendMode mode, unsigned src_alpha) {
switch (mode) { switch (mode) {
case SkBlendMode::kClear: case SkBlendMode::kClear:
...@@ -133,6 +131,7 @@ void CheckIfSolidRect(const SkCanvas& canvas, ...@@ -133,6 +131,7 @@ void CheckIfSolidRect(const SkCanvas& canvas,
base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor( base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
const PaintOpBuffer* buffer, const PaintOpBuffer* buffer,
const gfx::Rect& rect, const gfx::Rect& rect,
int max_ops_to_analyze,
const std::vector<size_t>* indices) { const std::vector<size_t>* indices) {
if (buffer->size() == 0 || (indices && indices->empty())) if (buffer->size() == 0 || (indices && indices->empty()))
return SK_ColorTRANSPARENT; return SK_ColorTRANSPARENT;
...@@ -212,7 +211,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor( ...@@ -212,7 +211,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
return base::nullopt; return base::nullopt;
case PaintOpType::DrawRect: { case PaintOpType::DrawRect: {
if (++num_ops > kMaxOpsToAnalyze) if (++num_ops > max_ops_to_analyze)
return base::nullopt; return base::nullopt;
const DrawRectOp* rect_op = static_cast<const DrawRectOp*>(op); const DrawRectOp* rect_op = static_cast<const DrawRectOp*>(op);
CheckIfSolidRect(canvas, rect_op->rect, rect_op->flags, &is_solid, CheckIfSolidRect(canvas, rect_op->rect, rect_op->flags, &is_solid,
...@@ -220,7 +219,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor( ...@@ -220,7 +219,7 @@ base::Optional<SkColor> SolidColorAnalyzer::DetermineIfSolidColor(
break; break;
} }
case PaintOpType::DrawColor: { case PaintOpType::DrawColor: {
if (++num_ops > kMaxOpsToAnalyze) if (++num_ops > max_ops_to_analyze)
return base::nullopt; return base::nullopt;
const DrawColorOp* color_op = static_cast<const DrawColorOp*>(op); const DrawColorOp* color_op = static_cast<const DrawColorOp*>(op);
CheckIfSolidColor(canvas, color_op->color, color_op->mode, &is_solid, CheckIfSolidColor(canvas, color_op->color, color_op->mode, &is_solid,
......
...@@ -22,6 +22,7 @@ class CC_PAINT_EXPORT SolidColorAnalyzer { ...@@ -22,6 +22,7 @@ class CC_PAINT_EXPORT SolidColorAnalyzer {
static base::Optional<SkColor> DetermineIfSolidColor( static base::Optional<SkColor> DetermineIfSolidColor(
const PaintOpBuffer* buffer, const PaintOpBuffer* buffer,
const gfx::Rect& rect, const gfx::Rect& rect,
int max_ops_to_analyze,
const std::vector<size_t>* indices = nullptr); const std::vector<size_t>* indices = nullptr);
}; };
......
...@@ -30,13 +30,13 @@ class SolidColorAnalyzerTest : public testing::Test { ...@@ -30,13 +30,13 @@ class SolidColorAnalyzerTest : public testing::Test {
bool IsSolidColor() { bool IsSolidColor() {
auto color = auto color =
SolidColorAnalyzer::DetermineIfSolidColor(&buffer_, rect_, nullptr); SolidColorAnalyzer::DetermineIfSolidColor(&buffer_, rect_, 1, nullptr);
return !!color; return !!color;
} }
SkColor GetColor() const { SkColor GetColor() const {
auto color = auto color =
SolidColorAnalyzer::DetermineIfSolidColor(&buffer_, rect_, nullptr); SolidColorAnalyzer::DetermineIfSolidColor(&buffer_, rect_, 1, nullptr);
EXPECT_TRUE(color); EXPECT_TRUE(color);
return color ? *color : SK_ColorTRANSPARENT; return color ? *color : SK_ColorTRANSPARENT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment