blob: 1fa1d7c02dc0d34e15d5de6349198bc93c4bfc7f [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
vmpstre17fd212016-03-30 20:03:3244RecordingSource::~RecordingSource() {}
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,
104 const size_t& painter_reported_memory_usage) {
105 display_list_ = display_list;
106 painter_reported_memory_usage_ = painter_reported_memory_usage;
Bartosz Fabianowski85a823812015-04-16 10:27:51107
dtrainorfb0a1622015-12-11 16:20:15108 FinishDisplayItemListUpdate();
ajuma5e77f7d42014-11-27 14:19:14109}
110
vmpstre17fd212016-03-30 20:03:32111gfx::Size RecordingSource::GetSize() const {
ajuma5e77f7d42014-11-27 14:19:14112 return size_;
113}
114
vmpstre17fd212016-03-30 20:03:32115void RecordingSource::SetEmptyBounds() {
ajuma5e77f7d42014-11-27 14:19:14116 size_ = gfx::Size();
mlliu51126b72016-08-02 22:18:24117 is_solid_color_ = false;
118
119 recorded_viewport_ = gfx::Rect();
120 display_list_ = nullptr;
121 painter_reported_memory_usage_ = 0;
ajuma5e77f7d42014-11-27 14:19:14122}
123
vmpstre17fd212016-03-30 20:03:32124void RecordingSource::SetSlowdownRasterScaleFactor(int factor) {
ajuma5e77f7d42014-11-27 14:19:14125 slow_down_raster_scale_factor_for_debug_ = factor;
126}
127
vmpstre17fd212016-03-30 20:03:32128void RecordingSource::SetBackgroundColor(SkColor background_color) {
enneffe57812015-02-14 02:37:20129 background_color_ = background_color;
130}
131
vmpstre17fd212016-03-30 20:03:32132void RecordingSource::SetRequiresClear(bool requires_clear) {
enneffe57812015-02-14 02:37:20133 requires_clear_ = requires_clear;
134}
135
nyquistfbaee112016-06-24 23:15:13136const DisplayItemList* RecordingSource::GetDisplayItemList() {
137 return display_list_.get();
138}
139
Vladimir Levin55c66402017-07-13 02:21:06140scoped_refptr<RasterSource> RecordingSource::CreateRasterSource() const {
141 return scoped_refptr<RasterSource>(new RasterSource(this));
ajuma5e77f7d42014-11-27 14:19:14142}
143
malaykeshav55c9f6d2017-08-03 01:05:43144void RecordingSource::SetRecordingScaleFactor(float recording_scale_factor) {
145 recording_scale_factor_ = recording_scale_factor;
146}
147
vmpstre17fd212016-03-30 20:03:32148void RecordingSource::DetermineIfSolidColor() {
pdr8a191b472015-09-22 22:25:37149 DCHECK(display_list_);
ajuma5e77f7d42014-11-27 14:19:14150 is_solid_color_ = false;
151 solid_color_ = SK_ColorTRANSPARENT;
152
Eric Karl8efa3b72017-07-14 01:00:35153 if (display_list_->op_count() > kMaxOpsToAnalyzeForLayer)
ajuma5e77f7d42014-11-27 14:19:14154 return;
155
wangxianzhua382d932016-05-16 18:03:30156 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
danakjf4730d52017-06-06 22:03:02157 display_list_->op_count());
Eric Karl8efa3b72017-07-14 01:00:35158 is_solid_color_ = display_list_->GetColorIfSolidInRect(
159 gfx::Rect(GetSize()), &solid_color_, kMaxOpsToAnalyzeForLayer);
ajuma5e77f7d42014-11-27 14:19:14160}
161
ajuma5e77f7d42014-11-27 14:19:14162} // namespace cc