Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1203)

Side by Side Diff: cc/playback/recording_source.cc

Issue 2141233002: cc: Clean up RecordingSource API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move types to the beginning of the access block Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/playback/recording_source.h" 5 #include "cc/playback/recording_source.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 18 matching lines...) Expand all
29 29
30 namespace cc { 30 namespace cc {
31 31
32 RecordingSource::RecordingSource() 32 RecordingSource::RecordingSource()
33 : slow_down_raster_scale_factor_for_debug_(0), 33 : slow_down_raster_scale_factor_for_debug_(0),
34 generate_discardable_images_metadata_(false), 34 generate_discardable_images_metadata_(false),
35 requires_clear_(false), 35 requires_clear_(false),
36 is_solid_color_(false), 36 is_solid_color_(false),
37 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), 37 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
38 solid_color_(SK_ColorTRANSPARENT), 38 solid_color_(SK_ColorTRANSPARENT),
39 background_color_(SK_ColorTRANSPARENT), 39 background_color_(SK_ColorTRANSPARENT) {}
40 painter_reported_memory_usage_(0) {}
41 40
42 RecordingSource::~RecordingSource() {} 41 RecordingSource::~RecordingSource() {}
43 42
44 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const { 43 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const {
45 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport());
46 SizeToProto(size_, proto->mutable_size()); 44 SizeToProto(size_, proto->mutable_size());
47 proto->set_slow_down_raster_scale_factor_for_debug( 45 proto->set_slow_down_raster_scale_factor_for_debug(
48 slow_down_raster_scale_factor_for_debug_); 46 slow_down_raster_scale_factor_for_debug_);
49 proto->set_generate_discardable_images_metadata( 47 proto->set_generate_discardable_images_metadata(
50 generate_discardable_images_metadata_); 48 generate_discardable_images_metadata_);
51 proto->set_requires_clear(requires_clear_); 49 proto->set_requires_clear(requires_clear_);
52 proto->set_is_solid_color(is_solid_color_); 50 proto->set_is_solid_color(is_solid_color_);
53 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); 51 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_);
54 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); 52 proto->set_solid_color(static_cast<uint64_t>(solid_color_));
55 proto->set_background_color(static_cast<uint64_t>(background_color_)); 53 proto->set_background_color(static_cast<uint64_t>(background_color_));
56 if (display_list_)
57 display_list_->ToProtobuf(proto->mutable_display_list());
58 } 54 }
59 55
60 void RecordingSource::FromProtobuf( 56 void RecordingSource::FromProtobuf(
61 const proto::RecordingSource& proto, 57 const proto::RecordingSource& proto,
62 ClientPictureCache* client_picture_cache, 58 const scoped_refptr<DisplayItemList>& display_list) {
63 std::vector<uint32_t>* used_engine_picture_ids) {
64 DCHECK(client_picture_cache);
65 recorded_viewport_ = ProtoToRect(proto.recorded_viewport());
66 size_ = ProtoToSize(proto.size()); 59 size_ = ProtoToSize(proto.size());
67 slow_down_raster_scale_factor_for_debug_ = 60 slow_down_raster_scale_factor_for_debug_ =
68 proto.slow_down_raster_scale_factor_for_debug(); 61 proto.slow_down_raster_scale_factor_for_debug();
69 generate_discardable_images_metadata_ = 62 generate_discardable_images_metadata_ =
70 proto.generate_discardable_images_metadata(); 63 proto.generate_discardable_images_metadata();
71 requires_clear_ = proto.requires_clear(); 64 requires_clear_ = proto.requires_clear();
72 is_solid_color_ = proto.is_solid_color(); 65 is_solid_color_ = proto.is_solid_color();
73 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); 66 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color();
74 solid_color_ = static_cast<SkColor>(proto.solid_color()); 67 solid_color_ = static_cast<SkColor>(proto.solid_color());
75 background_color_ = static_cast<SkColor>(proto.background_color()); 68 background_color_ = static_cast<SkColor>(proto.background_color());
76 69
77 // This might not exist if the |display_list_| of the serialized 70 if (display_list) {
78 // RecordingSource was null, wich can happen if |Clear()| is 71 FinishDisplayItemListUpdate(display_list);
79 // called.
80 if (proto.has_display_list()) {
81 display_list_ = DisplayItemList::CreateFromProto(
82 proto.display_list(), client_picture_cache, used_engine_picture_ids);
83 FinishDisplayItemListUpdate();
84 } else {
85 display_list_ = nullptr;
86 } 72 }
73 display_list_ = display_list;
87 } 74 }
88 75
89 void RecordingSource::UpdateInvalidationForNewViewport( 76 void RecordingSource::UpdateInvalidationForNewViewport(
90 const gfx::Rect& old_recorded_viewport, 77 const gfx::Rect& old_recorded_viewport,
91 const gfx::Rect& new_recorded_viewport, 78 const gfx::Rect& new_recorded_viewport,
92 Region* invalidation) { 79 Region* invalidation) {
93 // Invalidate newly-exposed and no-longer-exposed areas. 80 // Invalidate newly-exposed and no-longer-exposed areas.
94 Region newly_exposed_region(new_recorded_viewport); 81 Region newly_exposed_region(new_recorded_viewport);
95 newly_exposed_region.Subtract(old_recorded_viewport); 82 newly_exposed_region.Subtract(old_recorded_viewport);
96 invalidation->Union(newly_exposed_region); 83 invalidation->Union(newly_exposed_region);
97 84
98 Region no_longer_exposed_region(old_recorded_viewport); 85 Region no_longer_exposed_region(old_recorded_viewport);
99 no_longer_exposed_region.Subtract(new_recorded_viewport); 86 no_longer_exposed_region.Subtract(new_recorded_viewport);
100 invalidation->Union(no_longer_exposed_region); 87 invalidation->Union(no_longer_exposed_region);
101 } 88 }
102 89
103 void RecordingSource::FinishDisplayItemListUpdate() { 90 void RecordingSource::FinishDisplayItemListUpdate(
91 const scoped_refptr<DisplayItemList>& display_list) {
104 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate"); 92 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate");
105 DetermineIfSolidColor(); 93 DetermineIfSolidColor(display_list);
106 display_list_->EmitTraceSnapshot(); 94 display_list->EmitTraceSnapshot();
107 if (generate_discardable_images_metadata_) 95 if (generate_discardable_images_metadata_)
108 display_list_->GenerateDiscardableImagesMetadata(); 96 display_list->GenerateDiscardableImagesMetadata();
109 } 97 }
110 98
111 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { 99 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) {
112 if (!layer_rect.IsEmpty()) { 100 if (!layer_rect.IsEmpty()) {
113 // Clamp invalidation to the layer bounds. 101 // Clamp invalidation to the layer bounds.
114 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); 102 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_)));
115 } 103 }
116 } 104 }
117 105
118 bool RecordingSource::UpdateAndExpandInvalidation( 106 bool RecordingSource::UpdateAndExpandInvalidation(
119 ContentLayerClient* painter, 107 ContentLayerClient* painter,
120 Region* invalidation, 108 Region* invalidation,
121 const gfx::Size& layer_size, 109 const gfx::Size& layer_size,
122 int frame_number, 110 const gfx::Rect& new_recorded_viewport,
123 RecordingMode recording_mode) { 111 const scoped_refptr<DisplayItemList>& display_list,
112 const size_t& painter_reported_memory_usage) {
124 bool updated = false; 113 bool updated = false;
125 114
126 if (size_ != layer_size) 115 if (size_ != layer_size)
127 size_ = layer_size; 116 size_ = layer_size;
128 117
129 invalidation_.Swap(invalidation); 118 invalidation_.Swap(invalidation);
130 invalidation_.Clear(); 119 invalidation_.Clear();
131 120
132 gfx::Rect new_recorded_viewport = painter->PaintableRegion();
133 if (new_recorded_viewport != recorded_viewport_) { 121 if (new_recorded_viewport != recorded_viewport_) {
134 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, 122 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport,
135 invalidation); 123 invalidation);
136 recorded_viewport_ = new_recorded_viewport; 124 recorded_viewport_ = new_recorded_viewport;
137 updated = true; 125 updated = true;
138 } 126 }
139 127
140 if (!updated && !invalidation->Intersects(recorded_viewport_)) 128 if (!updated && !invalidation->Intersects(recorded_viewport_))
141 return false; 129 return false;
142 130
143 if (invalidation->IsEmpty()) 131 if (invalidation->IsEmpty())
144 return false; 132 return false;
145 133
146 ContentLayerClient::PaintingControlSetting painting_control = 134 FinishDisplayItemListUpdate(display_list);
147 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL;
148 135
149 switch (recording_mode) { 136 display_list_ = display_list;
vmpstr 2016/07/25 22:03:26 We can set these earlier in the function right? Th
Menglin 2016/07/26 17:49:41 Done.
150 case RECORD_NORMALLY: 137 painter_reported_memory_usage_ = painter_reported_memory_usage;
151 // Already setup for normal recording.
152 break;
153 case RECORD_WITH_PAINTING_DISABLED:
154 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED;
155 break;
156 case RECORD_WITH_CACHING_DISABLED:
157 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED;
158 break;
159 case RECORD_WITH_CONSTRUCTION_DISABLED:
160 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED;
161 break;
162 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED:
163 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED;
164 break;
165 case RECORD_WITH_SK_NULL_CANVAS:
166 case RECORDING_MODE_COUNT:
167 NOTREACHED();
168 }
169
170 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able
171 // to slow down recording.
172 display_list_ = painter->PaintContentsToDisplayList(painting_control);
173 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage();
174
175 FinishDisplayItemListUpdate();
176 138
177 return true; 139 return true;
178 } 140 }
179 141
180 gfx::Size RecordingSource::GetSize() const { 142 gfx::Size RecordingSource::GetSize() const {
181 return size_; 143 return size_;
182 } 144 }
183 145
184 void RecordingSource::SetEmptyBounds() { 146 void RecordingSource::SetEmptyBounds() {
185 size_ = gfx::Size(); 147 size_ = gfx::Size();
186 Clear(); 148 is_solid_color_ = false;
149
150 recorded_viewport_ = gfx::Rect();
151 display_list_ = nullptr;
152 painter_reported_memory_usage_ = 0;
187 } 153 }
188 154
189 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) { 155 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) {
190 slow_down_raster_scale_factor_for_debug_ = factor; 156 slow_down_raster_scale_factor_for_debug_ = factor;
191 } 157 }
192 158
193 void RecordingSource::SetGenerateDiscardableImagesMetadata( 159 void RecordingSource::SetGenerateDiscardableImagesMetadata(
194 bool generate_metadata) { 160 bool generate_metadata) {
195 generate_discardable_images_metadata_ = generate_metadata; 161 generate_discardable_images_metadata_ = generate_metadata;
196 } 162 }
197 163
198 void RecordingSource::SetBackgroundColor(SkColor background_color) { 164 void RecordingSource::SetBackgroundColor(SkColor background_color) {
199 background_color_ = background_color; 165 background_color_ = background_color;
200 } 166 }
201 167
202 void RecordingSource::SetRequiresClear(bool requires_clear) { 168 void RecordingSource::SetRequiresClear(bool requires_clear) {
203 requires_clear_ = requires_clear; 169 requires_clear_ = requires_clear;
204 } 170 }
205 171
206 bool RecordingSource::IsSuitableForGpuRasterization() const {
207 // The display list needs to be created (see: UpdateAndExpandInvalidation)
208 // before checking for suitability. There are cases where an update will not
209 // create a display list (e.g., if the size is empty). We return true in these
210 // cases because the gpu suitability bit sticks false.
211 return !display_list_ || display_list_->IsSuitableForGpuRasterization();
212 }
213
214 const DisplayItemList* RecordingSource::GetDisplayItemList() {
215 return display_list_.get();
216 }
217
218 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( 172 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource(
219 bool can_use_lcd_text) const { 173 bool can_use_lcd_text) const {
220 return scoped_refptr<RasterSource>( 174 return scoped_refptr<RasterSource>(
221 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); 175 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text));
222 } 176 }
223 177
224 void RecordingSource::DetermineIfSolidColor() { 178 void RecordingSource::DetermineIfSolidColor(
225 DCHECK(display_list_); 179 const scoped_refptr<DisplayItemList>& display_list) {
180 DCHECK(display_list);
226 is_solid_color_ = false; 181 is_solid_color_ = false;
227 solid_color_ = SK_ColorTRANSPARENT; 182 solid_color_ = SK_ColorTRANSPARENT;
228 183
229 if (!display_list_->ShouldBeAnalyzedForSolidColor()) 184 if (!display_list->ShouldBeAnalyzedForSolidColor())
230 return; 185 return;
231 186
232 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", 187 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
233 display_list_->ApproximateOpCount()); 188 display_list->ApproximateOpCount());
234 gfx::Size layer_size = GetSize(); 189 gfx::Size layer_size = GetSize();
235 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); 190 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
236 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); 191 display_list->Raster(&canvas, nullptr, gfx::Rect(), 1.f);
237 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); 192 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
238 } 193 }
239 194
240 void RecordingSource::Clear() {
241 recorded_viewport_ = gfx::Rect();
242 display_list_ = nullptr;
243 painter_reported_memory_usage_ = 0;
244 is_solid_color_ = false;
245 }
246
247 } // namespace cc 195 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698