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

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: inline the initialization, constructor/destructor = default in .cc Created 4 years, 5 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
« no previous file with comments | « cc/playback/recording_source.h ('k') | cc/test/fake_recording_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 #ifdef NDEBUG 22 #ifdef NDEBUG
23 const bool kDefaultClearCanvasSetting = false; 23 const bool kDefaultClearCanvasSetting = false;
24 #else 24 #else
25 const bool kDefaultClearCanvasSetting = true; 25 const bool kDefaultClearCanvasSetting = true;
26 #endif 26 #endif
27 27
28 } // namespace 28 } // namespace
29 29
30 namespace cc { 30 namespace cc {
31 31
32 RecordingSource::Inputs::Inputs() = default;
33
34 RecordingSource::Inputs::~Inputs() = default;
35
32 RecordingSource::RecordingSource() 36 RecordingSource::RecordingSource()
33 : slow_down_raster_scale_factor_for_debug_(0), 37 : slow_down_raster_scale_factor_for_debug_(0),
34 generate_discardable_images_metadata_(false), 38 generate_discardable_images_metadata_(false),
35 requires_clear_(false), 39 requires_clear_(false),
36 is_solid_color_(false), 40 is_solid_color_(false),
37 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), 41 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
38 solid_color_(SK_ColorTRANSPARENT), 42 solid_color_(SK_ColorTRANSPARENT),
39 background_color_(SK_ColorTRANSPARENT), 43 background_color_(SK_ColorTRANSPARENT) {}
40 painter_reported_memory_usage_(0) {}
41 44
42 RecordingSource::~RecordingSource() {} 45 RecordingSource::~RecordingSource() {}
43 46
44 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const { 47 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const {
45 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport()); 48 RectToProto(inputs_.recorded_viewport, proto->mutable_recorded_viewport());
46 SizeToProto(size_, proto->mutable_size()); 49 SizeToProto(size_, proto->mutable_size());
47 proto->set_slow_down_raster_scale_factor_for_debug( 50 proto->set_slow_down_raster_scale_factor_for_debug(
48 slow_down_raster_scale_factor_for_debug_); 51 slow_down_raster_scale_factor_for_debug_);
49 proto->set_generate_discardable_images_metadata( 52 proto->set_generate_discardable_images_metadata(
50 generate_discardable_images_metadata_); 53 generate_discardable_images_metadata_);
51 proto->set_requires_clear(requires_clear_); 54 proto->set_requires_clear(requires_clear_);
52 proto->set_is_solid_color(is_solid_color_); 55 proto->set_is_solid_color(is_solid_color_);
53 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_); 56 proto->set_clear_canvas_with_debug_color(clear_canvas_with_debug_color_);
54 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); 57 proto->set_solid_color(static_cast<uint64_t>(solid_color_));
55 proto->set_background_color(static_cast<uint64_t>(background_color_)); 58 proto->set_background_color(static_cast<uint64_t>(background_color_));
56 if (display_list_) 59 if (inputs_.display_list)
57 display_list_->ToProtobuf(proto->mutable_display_list()); 60 inputs_.display_list->ToProtobuf(proto->mutable_display_list());
58 } 61 }
59 62
60 void RecordingSource::FromProtobuf( 63 void RecordingSource::FromProtobuf(
61 const proto::RecordingSource& proto, 64 const proto::RecordingSource& proto,
62 ClientPictureCache* client_picture_cache, 65 ClientPictureCache* client_picture_cache,
63 std::vector<uint32_t>* used_engine_picture_ids) { 66 std::vector<uint32_t>* used_engine_picture_ids) {
64 DCHECK(client_picture_cache); 67 DCHECK(client_picture_cache);
65 recorded_viewport_ = ProtoToRect(proto.recorded_viewport()); 68 inputs_.recorded_viewport = ProtoToRect(proto.recorded_viewport());
66 size_ = ProtoToSize(proto.size()); 69 size_ = ProtoToSize(proto.size());
67 slow_down_raster_scale_factor_for_debug_ = 70 slow_down_raster_scale_factor_for_debug_ =
68 proto.slow_down_raster_scale_factor_for_debug(); 71 proto.slow_down_raster_scale_factor_for_debug();
69 generate_discardable_images_metadata_ = 72 generate_discardable_images_metadata_ =
70 proto.generate_discardable_images_metadata(); 73 proto.generate_discardable_images_metadata();
71 requires_clear_ = proto.requires_clear(); 74 requires_clear_ = proto.requires_clear();
72 is_solid_color_ = proto.is_solid_color(); 75 is_solid_color_ = proto.is_solid_color();
73 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); 76 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color();
74 solid_color_ = static_cast<SkColor>(proto.solid_color()); 77 solid_color_ = static_cast<SkColor>(proto.solid_color());
75 background_color_ = static_cast<SkColor>(proto.background_color()); 78 background_color_ = static_cast<SkColor>(proto.background_color());
76 79
77 // This might not exist if the |display_list_| of the serialized 80 // This might not exist if the |inputs_.display_list| of the serialized
78 // RecordingSource was null, wich can happen if |Clear()| is 81 // RecordingSource was null, wich can happen if |Clear()| is
79 // called. 82 // called.
80 if (proto.has_display_list()) { 83 if (proto.has_display_list()) {
81 display_list_ = DisplayItemList::CreateFromProto( 84 inputs_.display_list = DisplayItemList::CreateFromProto(
82 proto.display_list(), client_picture_cache, used_engine_picture_ids); 85 proto.display_list(), client_picture_cache, used_engine_picture_ids);
83 FinishDisplayItemListUpdate(); 86 FinishDisplayItemListUpdate();
84 } else { 87 } else {
85 display_list_ = nullptr; 88 inputs_.display_list = nullptr;
86 } 89 }
87 } 90 }
88 91
89 void RecordingSource::UpdateInvalidationForNewViewport( 92 void RecordingSource::UpdateInvalidationForNewViewport(
90 const gfx::Rect& old_recorded_viewport, 93 const gfx::Rect& old_recorded_viewport,
91 const gfx::Rect& new_recorded_viewport, 94 const gfx::Rect& new_recorded_viewport,
92 Region* invalidation) { 95 Region* invalidation) {
93 // Invalidate newly-exposed and no-longer-exposed areas. 96 // Invalidate newly-exposed and no-longer-exposed areas.
94 Region newly_exposed_region(new_recorded_viewport); 97 Region newly_exposed_region(new_recorded_viewport);
95 newly_exposed_region.Subtract(old_recorded_viewport); 98 newly_exposed_region.Subtract(old_recorded_viewport);
96 invalidation->Union(newly_exposed_region); 99 invalidation->Union(newly_exposed_region);
97 100
98 Region no_longer_exposed_region(old_recorded_viewport); 101 Region no_longer_exposed_region(old_recorded_viewport);
99 no_longer_exposed_region.Subtract(new_recorded_viewport); 102 no_longer_exposed_region.Subtract(new_recorded_viewport);
100 invalidation->Union(no_longer_exposed_region); 103 invalidation->Union(no_longer_exposed_region);
101 } 104 }
102 105
103 void RecordingSource::FinishDisplayItemListUpdate() { 106 void RecordingSource::FinishDisplayItemListUpdate() {
104 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate"); 107 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate");
105 DetermineIfSolidColor(); 108 DetermineIfSolidColor();
106 display_list_->EmitTraceSnapshot(); 109 inputs_.display_list->EmitTraceSnapshot();
107 if (generate_discardable_images_metadata_) 110 if (generate_discardable_images_metadata_)
108 display_list_->GenerateDiscardableImagesMetadata(); 111 inputs_.display_list->GenerateDiscardableImagesMetadata();
109 } 112 }
110 113
111 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { 114 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) {
112 if (!layer_rect.IsEmpty()) { 115 if (!layer_rect.IsEmpty()) {
113 // Clamp invalidation to the layer bounds. 116 // Clamp invalidation to the layer bounds.
114 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); 117 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_)));
115 } 118 }
116 } 119 }
117 120
118 bool RecordingSource::UpdateAndExpandInvalidation( 121 bool RecordingSource::UpdateAndExpandInvalidation(
119 ContentLayerClient* painter, 122 ContentLayerClient* painter,
120 Region* invalidation, 123 Region* invalidation,
121 const gfx::Size& layer_size, 124 const gfx::Size& layer_size,
122 int frame_number, 125 int frame_number,
123 RecordingMode recording_mode) { 126 RecordingMode recording_mode) {
124 bool updated = false; 127 bool updated = false;
125 128
126 if (size_ != layer_size) 129 if (size_ != layer_size)
127 size_ = layer_size; 130 size_ = layer_size;
128 131
129 invalidation_.Swap(invalidation); 132 invalidation_.Swap(invalidation);
130 invalidation_.Clear(); 133 invalidation_.Clear();
131 134
132 gfx::Rect new_recorded_viewport = painter->PaintableRegion(); 135 gfx::Rect new_recorded_viewport = painter->PaintableRegion();
133 if (new_recorded_viewport != recorded_viewport_) { 136 if (new_recorded_viewport != inputs_.recorded_viewport) {
134 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, 137 UpdateInvalidationForNewViewport(inputs_.recorded_viewport,
135 invalidation); 138 new_recorded_viewport, invalidation);
136 recorded_viewport_ = new_recorded_viewport; 139 inputs_.recorded_viewport = new_recorded_viewport;
danakj 2016/07/13 20:05:34 I don't understand the reason behind this CL, can
Khushal 2016/07/13 20:16:50 We want to separate the data PictureLayer gets fro
danakj 2016/07/13 20:19:33 Why? They both come from blink.
Khushal 2016/07/13 20:55:16 On the client side we will mostly be replicating t
danakj 2016/07/14 20:15:17 I find it really strange that this function is set
137 updated = true; 140 updated = true;
138 } 141 }
139 142
140 if (!updated && !invalidation->Intersects(recorded_viewport_)) 143 if (!updated && !invalidation->Intersects(inputs_.recorded_viewport))
141 return false; 144 return false;
142 145
143 if (invalidation->IsEmpty()) 146 if (invalidation->IsEmpty())
144 return false; 147 return false;
145 148
146 ContentLayerClient::PaintingControlSetting painting_control = 149 ContentLayerClient::PaintingControlSetting painting_control =
147 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; 150 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL;
148 151
149 switch (recording_mode) { 152 switch (recording_mode) {
150 case RECORD_NORMALLY: 153 case RECORD_NORMALLY:
(...skipping 11 matching lines...) Expand all
162 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: 165 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED:
163 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; 166 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED;
164 break; 167 break;
165 case RECORD_WITH_SK_NULL_CANVAS: 168 case RECORD_WITH_SK_NULL_CANVAS:
166 case RECORDING_MODE_COUNT: 169 case RECORDING_MODE_COUNT:
167 NOTREACHED(); 170 NOTREACHED();
168 } 171 }
169 172
170 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able 173 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able
171 // to slow down recording. 174 // to slow down recording.
172 display_list_ = painter->PaintContentsToDisplayList(painting_control); 175 inputs_.display_list = painter->PaintContentsToDisplayList(painting_control);
173 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage(); 176 inputs_.painter_reported_memory_usage =
177 painter->GetApproximateUnsharedMemoryUsage();
174 178
175 FinishDisplayItemListUpdate(); 179 FinishDisplayItemListUpdate();
176 180
177 return true; 181 return true;
178 } 182 }
179 183
180 gfx::Size RecordingSource::GetSize() const { 184 gfx::Size RecordingSource::GetSize() const {
181 return size_; 185 return size_;
182 } 186 }
183 187
(...skipping 17 matching lines...) Expand all
201 205
202 void RecordingSource::SetRequiresClear(bool requires_clear) { 206 void RecordingSource::SetRequiresClear(bool requires_clear) {
203 requires_clear_ = requires_clear; 207 requires_clear_ = requires_clear;
204 } 208 }
205 209
206 bool RecordingSource::IsSuitableForGpuRasterization() const { 210 bool RecordingSource::IsSuitableForGpuRasterization() const {
207 // The display list needs to be created (see: UpdateAndExpandInvalidation) 211 // The display list needs to be created (see: UpdateAndExpandInvalidation)
208 // before checking for suitability. There are cases where an update will not 212 // 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 213 // 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. 214 // cases because the gpu suitability bit sticks false.
211 return !display_list_ || display_list_->IsSuitableForGpuRasterization(); 215 return !inputs_.display_list ||
216 inputs_.display_list->IsSuitableForGpuRasterization();
212 } 217 }
213 218
214 const DisplayItemList* RecordingSource::GetDisplayItemList() { 219 const DisplayItemList* RecordingSource::GetDisplayItemList() {
215 return display_list_.get(); 220 return inputs_.display_list.get();
216 } 221 }
217 222
218 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( 223 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource(
219 bool can_use_lcd_text) const { 224 bool can_use_lcd_text) const {
220 return scoped_refptr<RasterSource>( 225 return scoped_refptr<RasterSource>(
221 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); 226 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text));
222 } 227 }
223 228
224 void RecordingSource::DetermineIfSolidColor() { 229 void RecordingSource::DetermineIfSolidColor() {
225 DCHECK(display_list_); 230 DCHECK(inputs_.display_list);
226 is_solid_color_ = false; 231 is_solid_color_ = false;
227 solid_color_ = SK_ColorTRANSPARENT; 232 solid_color_ = SK_ColorTRANSPARENT;
228 233
229 if (!display_list_->ShouldBeAnalyzedForSolidColor()) 234 if (!inputs_.display_list->ShouldBeAnalyzedForSolidColor())
230 return; 235 return;
231 236
232 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", 237 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
233 display_list_->ApproximateOpCount()); 238 inputs_.display_list->ApproximateOpCount());
234 gfx::Size layer_size = GetSize(); 239 gfx::Size layer_size = GetSize();
235 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); 240 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
236 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); 241 inputs_.display_list->Raster(&canvas, nullptr, gfx::Rect(), 1.f);
237 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); 242 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
238 } 243 }
239 244
240 void RecordingSource::Clear() { 245 void RecordingSource::Clear() {
241 recorded_viewport_ = gfx::Rect(); 246 inputs_.recorded_viewport = gfx::Rect();
242 display_list_ = nullptr; 247 inputs_.display_list = nullptr;
243 painter_reported_memory_usage_ = 0; 248 inputs_.painter_reported_memory_usage = 0;
244 is_solid_color_ = false; 249 is_solid_color_ = false;
245 } 250 }
246 251
247 } // namespace cc 252 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/recording_source.h ('k') | cc/test/fake_recording_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698