blob: 6e6525936506b17e37a8670e16f7d6ca784996bf [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
18namespace {
19
Eric Karl8efa3b72017-07-14 01:00:3520// We don't perform per-layer solid color analysis when there are too many skia
21// operations.
22const int kMaxOpsToAnalyzeForLayer = 10;
23
ajuma5e77f7d42014-11-27 14:19:1424} // namespace
25
26namespace cc {
27
vmpstre17fd212016-03-30 20:03:3228RecordingSource::RecordingSource()
jbroman16d628c2015-05-29 20:11:5929 : slow_down_raster_scale_factor_for_debug_(0),
enneffe57812015-02-14 02:37:2030 requires_clear_(false),
ajuma5e77f7d42014-11-27 14:19:1431 is_solid_color_(false),
32 solid_color_(SK_ColorTRANSPARENT),
malaykeshav55c9f6d2017-08-03 01:05:4333 background_color_(SK_ColorTRANSPARENT),
34 recording_scale_factor_(1.f) {}
ajuma5e77f7d42014-11-27 14:19:1435
Chris Watkinsf6353292017-12-04 02:36:0536RecordingSource::~RecordingSource() = default;
ajuma5e77f7d42014-11-27 14:19:1437
vmpstre17fd212016-03-30 20:03:3238void RecordingSource::UpdateInvalidationForNewViewport(
chrishtr01539b802015-11-24 08:11:3239 const gfx::Rect& old_recorded_viewport,
40 const gfx::Rect& new_recorded_viewport,
41 Region* invalidation) {
42 // Invalidate newly-exposed and no-longer-exposed areas.
43 Region newly_exposed_region(new_recorded_viewport);
44 newly_exposed_region.Subtract(old_recorded_viewport);
45 invalidation->Union(newly_exposed_region);
chrishtr877f83702015-07-01 18:22:2546
chrishtr01539b802015-11-24 08:11:3247 Region no_longer_exposed_region(old_recorded_viewport);
48 no_longer_exposed_region.Subtract(new_recorded_viewport);
49 invalidation->Union(no_longer_exposed_region);
chrishtr877f83702015-07-01 18:22:2550}
51
vmpstre17fd212016-03-30 20:03:3252void RecordingSource::FinishDisplayItemListUpdate() {
wangxianzhua382d932016-05-16 18:03:3053 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate");
dtrainorfb0a1622015-12-11 16:20:1554 DetermineIfSolidColor();
55 display_list_->EmitTraceSnapshot();
vmpstr5cff918d2017-04-27 17:48:3556 display_list_->GenerateDiscardableImagesMetadata();
dtrainorfb0a1622015-12-11 16:20:1557}
58
vmpstre17fd212016-03-30 20:03:3259void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) {
chrishtrc41aca7b2016-03-18 15:44:2960 if (!layer_rect.IsEmpty()) {
61 // Clamp invalidation to the layer bounds.
62 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_)));
63 }
64}
65
vmpstre17fd212016-03-30 20:03:3266bool RecordingSource::UpdateAndExpandInvalidation(
ajuma5e77f7d42014-11-27 14:19:1467 Region* invalidation,
ajuma5e77f7d42014-11-27 14:19:1468 const gfx::Size& layer_size,
mlliu51126b72016-08-02 22:18:2469 const gfx::Rect& new_recorded_viewport) {
ajuma5e77f7d42014-11-27 14:19:1470 bool updated = false;
71
chrishtr7271c4e62016-04-21 22:34:4672 if (size_ != layer_size)
ajuma5e77f7d42014-11-27 14:19:1473 size_ = layer_size;
ajuma5e77f7d42014-11-27 14:19:1474
chrishtrc41aca7b2016-03-18 15:44:2975 invalidation_.Swap(invalidation);
76 invalidation_.Clear();
77
chrishtr01539b802015-11-24 08:11:3278 if (new_recorded_viewport != recorded_viewport_) {
79 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport,
80 invalidation);
81 recorded_viewport_ = new_recorded_viewport;
ajuma5e77f7d42014-11-27 14:19:1482 updated = true;
83 }
84
85 if (!updated && !invalidation->Intersects(recorded_viewport_))
86 return false;
87
chrishtrc41aca7b2016-03-18 15:44:2988 if (invalidation->IsEmpty())
89 return false;
90
mlliu51126b72016-08-02 22:18:2491 return true;
92}
schenney0154bfa2015-02-05 19:46:4993
mlliu51126b72016-08-02 22:18:2494void RecordingSource::UpdateDisplayItemList(
95 const scoped_refptr<DisplayItemList>& display_list,
F#m57abc3e2017-11-30 01:49:3596 const size_t& painter_reported_memory_usage,
97 float recording_scale_factor) {
98 recording_scale_factor_ = recording_scale_factor;
99
mlliu51126b72016-08-02 22:18:24100 display_list_ = display_list;
101 painter_reported_memory_usage_ = painter_reported_memory_usage;
Bartosz Fabianowski85a823812015-04-16 10:27:51102
dtrainorfb0a1622015-12-11 16:20:15103 FinishDisplayItemListUpdate();
ajuma5e77f7d42014-11-27 14:19:14104}
105
vmpstre17fd212016-03-30 20:03:32106gfx::Size RecordingSource::GetSize() const {
ajuma5e77f7d42014-11-27 14:19:14107 return size_;
108}
109
vmpstre17fd212016-03-30 20:03:32110void RecordingSource::SetEmptyBounds() {
ajuma5e77f7d42014-11-27 14:19:14111 size_ = gfx::Size();
mlliu51126b72016-08-02 22:18:24112 is_solid_color_ = false;
113
114 recorded_viewport_ = gfx::Rect();
115 display_list_ = nullptr;
116 painter_reported_memory_usage_ = 0;
ajuma5e77f7d42014-11-27 14:19:14117}
118
vmpstre17fd212016-03-30 20:03:32119void RecordingSource::SetSlowdownRasterScaleFactor(int factor) {
ajuma5e77f7d42014-11-27 14:19:14120 slow_down_raster_scale_factor_for_debug_ = factor;
121}
122
vmpstre17fd212016-03-30 20:03:32123void RecordingSource::SetBackgroundColor(SkColor background_color) {
enneffe57812015-02-14 02:37:20124 background_color_ = background_color;
125}
126
vmpstre17fd212016-03-30 20:03:32127void RecordingSource::SetRequiresClear(bool requires_clear) {
enneffe57812015-02-14 02:37:20128 requires_clear_ = requires_clear;
129}
130
Vladimir Levin55c66402017-07-13 02:21:06131scoped_refptr<RasterSource> RecordingSource::CreateRasterSource() const {
132 return scoped_refptr<RasterSource>(new RasterSource(this));
ajuma5e77f7d42014-11-27 14:19:14133}
134
vmpstre17fd212016-03-30 20:03:32135void RecordingSource::DetermineIfSolidColor() {
pdr8a191b472015-09-22 22:25:37136 DCHECK(display_list_);
ajuma5e77f7d42014-11-27 14:19:14137 is_solid_color_ = false;
138 solid_color_ = SK_ColorTRANSPARENT;
139
Xianzhu Wang02333c52018-04-06 03:17:22140 if (display_list_->TotalOpCount() > kMaxOpsToAnalyzeForLayer)
ajuma5e77f7d42014-11-27 14:19:14141 return;
142
wangxianzhua382d932016-05-16 18:03:30143 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
Xianzhu Wang02333c52018-04-06 03:17:22144 display_list_->TotalOpCount());
Eric Karl8efa3b72017-07-14 01:00:35145 is_solid_color_ = display_list_->GetColorIfSolidInRect(
F#m6e66c7482017-09-20 01:22:35146 gfx::ScaleToRoundedRect(gfx::Rect(GetSize()), recording_scale_factor_),
147 &solid_color_, kMaxOpsToAnalyzeForLayer);
ajuma5e77f7d42014-11-27 14:19:14148}
149
ajuma5e77f7d42014-11-27 14:19:14150} // namespace cc