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

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

Issue 1982893002: [blimp] Add SkPicture caching support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: git merge origin/master Created 4 years, 6 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
11 #include "base/numerics/safe_math.h" 11 #include "base/numerics/safe_math.h"
12 #include "cc/base/region.h" 12 #include "cc/base/region.h"
13 #include "cc/layers/content_layer_client.h" 13 #include "cc/layers/content_layer_client.h"
14 #include "cc/playback/display_item_list.h" 14 #include "cc/playback/display_item_list.h"
15 #include "cc/playback/raster_source.h" 15 #include "cc/playback/raster_source.h"
16 #include "cc/proto/gfx_conversions.h" 16 #include "cc/proto/gfx_conversions.h"
17 #include "cc/proto/picture_cache.h"
17 #include "cc/proto/recording_source.pb.h" 18 #include "cc/proto/recording_source.pb.h"
18 #include "skia/ext/analysis_canvas.h" 19 #include "skia/ext/analysis_canvas.h"
19 20
20 namespace { 21 namespace {
21 22
22 #ifdef NDEBUG 23 #ifdef NDEBUG
23 const bool kDefaultClearCanvasSetting = false; 24 const bool kDefaultClearCanvasSetting = false;
24 #else 25 #else
25 const bool kDefaultClearCanvasSetting = true; 26 const bool kDefaultClearCanvasSetting = true;
26 #endif 27 #endif
27 28
28 } // namespace 29 } // namespace
29 30
30 namespace cc { 31 namespace cc {
31 class ImageSerializationProcessor;
32 32
33 RecordingSource::RecordingSource() 33 RecordingSource::RecordingSource()
34 : slow_down_raster_scale_factor_for_debug_(0), 34 : slow_down_raster_scale_factor_for_debug_(0),
35 generate_discardable_images_metadata_(false), 35 generate_discardable_images_metadata_(false),
36 requires_clear_(false), 36 requires_clear_(false),
37 is_solid_color_(false), 37 is_solid_color_(false),
38 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), 38 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
39 solid_color_(SK_ColorTRANSPARENT), 39 solid_color_(SK_ColorTRANSPARENT),
40 background_color_(SK_ColorTRANSPARENT), 40 background_color_(SK_ColorTRANSPARENT),
41 engine_picture_cache_(nullptr),
42 client_picture_cache_(nullptr),
41 painter_reported_memory_usage_(0) {} 43 painter_reported_memory_usage_(0) {}
42 44
43 RecordingSource::~RecordingSource() {} 45 RecordingSource::~RecordingSource() {}
44 46
45 void RecordingSource::ToProtobuf( 47 void RecordingSource::ToProtobuf(proto::RecordingSource* proto) const {
46 proto::RecordingSource* proto,
47 ImageSerializationProcessor* image_serialization_processor) const {
48 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport()); 48 RectToProto(recorded_viewport_, proto->mutable_recorded_viewport());
49 SizeToProto(size_, proto->mutable_size()); 49 SizeToProto(size_, proto->mutable_size());
50 proto->set_slow_down_raster_scale_factor_for_debug( 50 proto->set_slow_down_raster_scale_factor_for_debug(
51 slow_down_raster_scale_factor_for_debug_); 51 slow_down_raster_scale_factor_for_debug_);
52 proto->set_generate_discardable_images_metadata( 52 proto->set_generate_discardable_images_metadata(
53 generate_discardable_images_metadata_); 53 generate_discardable_images_metadata_);
54 proto->set_requires_clear(requires_clear_); 54 proto->set_requires_clear(requires_clear_);
55 proto->set_is_solid_color(is_solid_color_); 55 proto->set_is_solid_color(is_solid_color_);
56 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_);
57 proto->set_solid_color(static_cast<uint64_t>(solid_color_)); 57 proto->set_solid_color(static_cast<uint64_t>(solid_color_));
58 proto->set_background_color(static_cast<uint64_t>(background_color_)); 58 proto->set_background_color(static_cast<uint64_t>(background_color_));
59 if (display_list_) { 59 if (display_list_)
60 display_list_->ToProtobuf(proto->mutable_display_list(), 60 display_list_->ToProtobuf(proto->mutable_display_list());
61 image_serialization_processor);
62 }
63 } 61 }
64 62
65 void RecordingSource::FromProtobuf( 63 void RecordingSource::FromProtobuf(const proto::RecordingSource& proto) {
66 const proto::RecordingSource& proto, 64 DCHECK(client_picture_cache_);
67 ImageSerializationProcessor* image_serialization_processor) {
68 recorded_viewport_ = ProtoToRect(proto.recorded_viewport()); 65 recorded_viewport_ = ProtoToRect(proto.recorded_viewport());
69 size_ = ProtoToSize(proto.size()); 66 size_ = ProtoToSize(proto.size());
70 slow_down_raster_scale_factor_for_debug_ = 67 slow_down_raster_scale_factor_for_debug_ =
71 proto.slow_down_raster_scale_factor_for_debug(); 68 proto.slow_down_raster_scale_factor_for_debug();
72 generate_discardable_images_metadata_ = 69 generate_discardable_images_metadata_ =
73 proto.generate_discardable_images_metadata(); 70 proto.generate_discardable_images_metadata();
74 requires_clear_ = proto.requires_clear(); 71 requires_clear_ = proto.requires_clear();
75 is_solid_color_ = proto.is_solid_color(); 72 is_solid_color_ = proto.is_solid_color();
76 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color(); 73 clear_canvas_with_debug_color_ = proto.clear_canvas_with_debug_color();
77 solid_color_ = static_cast<SkColor>(proto.solid_color()); 74 solid_color_ = static_cast<SkColor>(proto.solid_color());
78 background_color_ = static_cast<SkColor>(proto.background_color()); 75 background_color_ = static_cast<SkColor>(proto.background_color());
79 76
80 // This might not exist if the |display_list_| of the serialized 77 // This might not exist if the |display_list_| of the serialized
81 // RecordingSource was null, wich can happen if |Clear()| is 78 // RecordingSource was null, wich can happen if |Clear()| is
82 // called. 79 // called. Whenever the |display_list_| is updated, first unregister the
80 // current content, and then register the new content directly afterwards.
81 MarkForUnregistration();
82 display_list_ = nullptr;
83 if (proto.has_display_list()) { 83 if (proto.has_display_list()) {
84 display_list_ = DisplayItemList::CreateFromProto( 84 display_list_ = DisplayItemList::CreateFromProto(proto.display_list(),
85 proto.display_list(), image_serialization_processor); 85 client_picture_cache_);
86 FinishDisplayItemListUpdate(); 86 FinishDisplayItemListUpdate();
87 } else {
88 display_list_ = nullptr;
89 } 87 }
88 MarkForRegistration();
89 }
90
91 void RecordingSource::MarkForRegistration() {
92 if (!display_list_)
93 return;
94
95 if (engine_picture_cache_)
vmpstr 2016/06/01 00:10:57 Can you explain in a few sentences why both server
nyquist 2016/06/04 00:24:58 Hmm... I split these out to separate methods, so n
96 display_list_->MarkForRegistrationEngine(engine_picture_cache_);
97 if (client_picture_cache_)
98 display_list_->MarkForRegistrationClient(client_picture_cache_);
99 }
100
101 void RecordingSource::MarkForUnregistration() {
102 if (!display_list_)
103 return;
104
105 if (engine_picture_cache_)
106 display_list_->MarkForUnregistrationEngine(engine_picture_cache_);
107 if (client_picture_cache_)
108 display_list_->MarkForUnregistrationClient(client_picture_cache_);
90 } 109 }
91 110
92 void RecordingSource::UpdateInvalidationForNewViewport( 111 void RecordingSource::UpdateInvalidationForNewViewport(
93 const gfx::Rect& old_recorded_viewport, 112 const gfx::Rect& old_recorded_viewport,
94 const gfx::Rect& new_recorded_viewport, 113 const gfx::Rect& new_recorded_viewport,
95 Region* invalidation) { 114 Region* invalidation) {
96 // Invalidate newly-exposed and no-longer-exposed areas. 115 // Invalidate newly-exposed and no-longer-exposed areas.
97 Region newly_exposed_region(new_recorded_viewport); 116 Region newly_exposed_region(new_recorded_viewport);
98 newly_exposed_region.Subtract(old_recorded_viewport); 117 newly_exposed_region.Subtract(old_recorded_viewport);
99 invalidation->Union(newly_exposed_region); 118 invalidation->Union(newly_exposed_region);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED: 184 case RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED:
166 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED; 185 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED;
167 break; 186 break;
168 case RECORD_WITH_SK_NULL_CANVAS: 187 case RECORD_WITH_SK_NULL_CANVAS:
169 case RECORDING_MODE_COUNT: 188 case RECORDING_MODE_COUNT:
170 NOTREACHED(); 189 NOTREACHED();
171 } 190 }
172 191
173 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able 192 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able
174 // to slow down recording. 193 // to slow down recording.
194 // Whenever the |display_list_| is updated, first unregister the
195 // current content, and then register the new content directly afterwards.
196 MarkForUnregistration();
175 display_list_ = painter->PaintContentsToDisplayList(painting_control); 197 display_list_ = painter->PaintContentsToDisplayList(painting_control);
198 MarkForRegistration();
199
176 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage(); 200 painter_reported_memory_usage_ = painter->GetApproximateUnsharedMemoryUsage();
177 201
178 FinishDisplayItemListUpdate(); 202 FinishDisplayItemListUpdate();
179 203
180 return true; 204 return true;
181 } 205 }
182 206
183 gfx::Size RecordingSource::GetSize() const { 207 gfx::Size RecordingSource::GetSize() const {
184 return size_; 208 return size_;
185 } 209 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 254
231 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", 255 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
232 display_list_->ApproximateOpCount()); 256 display_list_->ApproximateOpCount());
233 gfx::Size layer_size = GetSize(); 257 gfx::Size layer_size = GetSize();
234 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); 258 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
235 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f); 259 display_list_->Raster(&canvas, nullptr, gfx::Rect(), 1.f);
236 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); 260 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
237 } 261 }
238 262
239 void RecordingSource::Clear() { 263 void RecordingSource::Clear() {
264 MarkForUnregistration();
240 recorded_viewport_ = gfx::Rect(); 265 recorded_viewport_ = gfx::Rect();
241 display_list_ = nullptr; 266 display_list_ = nullptr;
242 painter_reported_memory_usage_ = 0; 267 painter_reported_memory_usage_ = 0;
243 is_solid_color_ = false; 268 is_solid_color_ = false;
244 } 269 }
245 270
246 } // namespace cc 271 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698