blob: c33ad76f22810dba76d03771fdb3dc823e2600c9 [file] [log] [blame]
ajuma5e77f7d42014-11-27 14:19:141// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
chrishtrac41ff92017-03-17 05:07:305#include "cc/layers/recording_source.h"
ajuma5e77f7d42014-11-27 14:19:146
avi02a4d172015-12-21 06:14:367#include <stdint.h>
8
ajuma5e77f7d42014-11-27 14:19:149#include <algorithm>
10
vmpstre2e1a4f02015-09-30 19:04:0911#include "base/numerics/safe_math.h"
ajuma5e77f7d42014-11-27 14:19:1412#include "cc/base/region.h"
13#include "cc/layers/content_layer_client.h"
chrishtrac41ff92017-03-17 05:07:3014#include "cc/paint/display_item_list.h"
Vladimir Levinaee539102017-06-23 16:46:0815#include "cc/paint/solid_color_analyzer.h"
chrishtrac41ff92017-03-17 05:07:3016#include "cc/raster/raster_source.h"
ajuma5e77f7d42014-11-27 14:19:1417#include "skia/ext/analysis_canvas.h"
18
19namespace {
20
danakja5ac8cc2015-06-03 20:58:5521#ifdef NDEBUG
22const bool kDefaultClearCanvasSetting = false;
23#else
24const bool kDefaultClearCanvasSetting = true;
25#endif
26
Eric Karl8efa3b72017-07-14 01:00:3527// We don't perform per-layer solid color analysis when there are too many skia
28// operations.
29const int kMaxOpsToAnalyzeForLayer = 10;
30
ajuma5e77f7d42014-11-27 14:19:1431} // namespace
32
33namespace cc {
34
vmpstre17fd212016-03-30 20:03:3235RecordingSource::RecordingSource()
jbroman16d628c2015-05-29 20:11:5936 : slow_down_raster_scale_factor_for_debug_(0),
enneffe57812015-02-14 02:37:2037 requires_clear_(false),
ajuma5e77f7d42014-11-27 14:19:1438 is_solid_color_(false),
danakja5ac8cc2015-06-03 20:58:5539 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
ajuma5e77f7d42014-11-27 14:19:1440 solid_color_(SK_ColorTRANSPARENT),
malaykeshav55c9f6d2017-08-03 01:05:4341 background_color_(SK_ColorTRANSPARENT),
42 recording_scale_factor_(1.f) {}
ajuma5e77f7d42014-11-27 14:19:1443
Chris Watkinsf6353292017-12-04 02:36:0544RecordingSource::~RecordingSource() = default;
ajuma5e77f7d42014-11-27 14:19:1445
vmpstre17fd212016-03-30 20:03:3246void RecordingSource::UpdateInvalidationForNewViewport(
chrishtr01539b802015-11-24 08:11:3247 const gfx::Rect& old_recorded_viewport,
48 const gfx::Rect& new_recorded_viewport,
49 Region* invalidation) {
50 // Invalidate newly-exposed and no-longer-exposed areas.
51 Region newly_exposed_region(new_recorded_viewport);
52 newly_exposed_region.Subtract(old_recorded_viewport);
53 invalidation->Union(newly_exposed_region);
chrishtr877f83702015-07-01 18:22:2554
chrishtr01539b802015-11-24 08:11:3255 Region no_longer_exposed_region(old_recorded_viewport);
56 no_longer_exposed_region.Subtract(new_recorded_viewport);
57 invalidation->Union(no_longer_exposed_region);
chrishtr877f83702015-07-01 18:22:2558}
59
vmpstre17fd212016-03-30 20:03:3260void RecordingSource::FinishDisplayItemListUpdate() {
wangxianzhua382d932016-05-16 18:03:3061 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate");
dtrainorfb0a1622015-12-11 16:20:1562 DetermineIfSolidColor();
63 display_list_->EmitTraceSnapshot();
vmpstr5cff918d2017-04-27 17:48:3564 display_list_->GenerateDiscardableImagesMetadata();
dtrainorfb0a1622015-12-11 16:20:1565}
66
vmpstre17fd212016-03-30 20:03:3267void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) {
chrishtrc41aca7b2016-03-18 15:44:2968 if (!layer_rect.IsEmpty()) {
69 // Clamp invalidation to the layer bounds.
70 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_)));
71 }
72}
73
vmpstre17fd212016-03-30 20:03:3274bool RecordingSource::UpdateAndExpandInvalidation(
ajuma5e77f7d42014-11-27 14:19:1475 Region* invalidation,
ajuma5e77f7d42014-11-27 14:19:1476 const gfx::Size& layer_size,
mlliu51126b72016-08-02 22:18:2477 const gfx::Rect& new_recorded_viewport) {
ajuma5e77f7d42014-11-27 14:19:1478 bool updated = false;
79
chrishtr7271c4e62016-04-21 22:34:4680 if (size_ != layer_size)
ajuma5e77f7d42014-11-27 14:19:1481 size_ = layer_size;
ajuma5e77f7d42014-11-27 14:19:1482
chrishtrc41aca7b2016-03-18 15:44:2983 invalidation_.Swap(invalidation);
84 invalidation_.Clear();
85
chrishtr01539b802015-11-24 08:11:3286 if (new_recorded_viewport != recorded_viewport_) {
87 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport,
88 invalidation);
89 recorded_viewport_ = new_recorded_viewport;
ajuma5e77f7d42014-11-27 14:19:1490 updated = true;
91 }
92
93 if (!updated && !invalidation->Intersects(recorded_viewport_))
94 return false;
95
chrishtrc41aca7b2016-03-18 15:44:2996 if (invalidation->IsEmpty())
97 return false;
98
mlliu51126b72016-08-02 22:18:2499 return true;
100}
schenney0154bfa2015-02-05 19:46:49101
mlliu51126b72016-08-02 22:18:24102void RecordingSource::UpdateDisplayItemList(
103 const scoped_refptr<DisplayItemList>& display_list,
F#m57abc3e2017-11-30 01:49:35104 const size_t& painter_reported_memory_usage,
105 float recording_scale_factor) {
106 recording_scale_factor_ = recording_scale_factor;
107
mlliu51126b72016-08-02 22:18:24108 display_list_ = display_list;
109 painter_reported_memory_usage_ = painter_reported_memory_usage;
Bartosz Fabianowski85a823812015-04-16 10:27:51110
dtrainorfb0a1622015-12-11 16:20:15111 FinishDisplayItemListUpdate();
ajuma5e77f7d42014-11-27 14:19:14112}
113
vmpstre17fd212016-03-30 20:03:32114gfx::Size RecordingSource::GetSize() const {
ajuma5e77f7d42014-11-27 14:19:14115 return size_;
116}
117
vmpstre17fd212016-03-30 20:03:32118void RecordingSource::SetEmptyBounds() {
ajuma5e77f7d42014-11-27 14:19:14119 size_ = gfx::Size();
mlliu51126b72016-08-02 22:18:24120 is_solid_color_ = false;
121
122 recorded_viewport_ = gfx::Rect();
123 display_list_ = nullptr;
124 painter_reported_memory_usage_ = 0;
ajuma5e77f7d42014-11-27 14:19:14125}
126
vmpstre17fd212016-03-30 20:03:32127void RecordingSource::SetSlowdownRasterScaleFactor(int factor) {
ajuma5e77f7d42014-11-27 14:19:14128 slow_down_raster_scale_factor_for_debug_ = factor;
129}
130
vmpstre17fd212016-03-30 20:03:32131void RecordingSource::SetBackgroundColor(SkColor background_color) {
enneffe57812015-02-14 02:37:20132 background_color_ = background_color;
133}
134
vmpstre17fd212016-03-30 20:03:32135void RecordingSource::SetRequiresClear(bool requires_clear) {
enneffe57812015-02-14 02:37:20136 requires_clear_ = requires_clear;
137}
138
nyquistfbaee112016-06-24 23:15:13139const DisplayItemList* RecordingSource::GetDisplayItemList() {
140 return display_list_.get();
141}
142
Vladimir Levin55c66402017-07-13 02:21:06143scoped_refptr<RasterSource> RecordingSource::CreateRasterSource() const {
144 return scoped_refptr<RasterSource>(new RasterSource(this));
ajuma5e77f7d42014-11-27 14:19:14145}
146
vmpstre17fd212016-03-30 20:03:32147void RecordingSource::DetermineIfSolidColor() {
pdr8a191b472015-09-22 22:25:37148 DCHECK(display_list_);
ajuma5e77f7d42014-11-27 14:19:14149 is_solid_color_ = false;
150 solid_color_ = SK_ColorTRANSPARENT;
151
Eric Karl8efa3b72017-07-14 01:00:35152 if (display_list_->op_count() > kMaxOpsToAnalyzeForLayer)
ajuma5e77f7d42014-11-27 14:19:14153 return;
154
wangxianzhua382d932016-05-16 18:03:30155 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
danakjf4730d52017-06-06 22:03:02156 display_list_->op_count());
Eric Karl8efa3b72017-07-14 01:00:35157 is_solid_color_ = display_list_->GetColorIfSolidInRect(
F#m6e66c7482017-09-20 01:22:35158 gfx::ScaleToRoundedRect(gfx::Rect(GetSize()), recording_scale_factor_),
159 &solid_color_, kMaxOpsToAnalyzeForLayer);
ajuma5e77f7d42014-11-27 14:19:14160}
161
ajuma5e77f7d42014-11-27 14:19:14162} // namespace cc