OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/playback/recording_source.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <algorithm> | |
10 | |
11 #include "base/numerics/safe_math.h" | |
12 #include "cc/base/region.h" | |
13 #include "cc/layers/content_layer_client.h" | |
14 #include "cc/playback/display_item_list.h" | |
15 #include "cc/playback/raster_source.h" | |
16 #include "skia/ext/analysis_canvas.h" | |
17 | |
18 namespace { | |
19 | |
20 #ifdef NDEBUG | |
21 const bool kDefaultClearCanvasSetting = false; | |
22 #else | |
23 const bool kDefaultClearCanvasSetting = true; | |
24 #endif | |
25 | |
26 } // namespace | |
27 | |
28 namespace cc { | |
29 | |
30 RecordingSource::RecordingSource() | |
31 : slow_down_raster_scale_factor_for_debug_(0), | |
32 generate_discardable_images_metadata_(false), | |
33 requires_clear_(false), | |
34 is_solid_color_(false), | |
35 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), | |
36 solid_color_(SK_ColorTRANSPARENT), | |
37 background_color_(SK_ColorTRANSPARENT) {} | |
38 | |
39 RecordingSource::~RecordingSource() {} | |
40 | |
41 void RecordingSource::UpdateInvalidationForNewViewport( | |
42 const gfx::Rect& old_recorded_viewport, | |
43 const gfx::Rect& new_recorded_viewport, | |
44 Region* invalidation) { | |
45 // Invalidate newly-exposed and no-longer-exposed areas. | |
46 Region newly_exposed_region(new_recorded_viewport); | |
47 newly_exposed_region.Subtract(old_recorded_viewport); | |
48 invalidation->Union(newly_exposed_region); | |
49 | |
50 Region no_longer_exposed_region(old_recorded_viewport); | |
51 no_longer_exposed_region.Subtract(new_recorded_viewport); | |
52 invalidation->Union(no_longer_exposed_region); | |
53 } | |
54 | |
55 void RecordingSource::FinishDisplayItemListUpdate() { | |
56 TRACE_EVENT0("cc", "RecordingSource::FinishDisplayItemListUpdate"); | |
57 DetermineIfSolidColor(); | |
58 display_list_->EmitTraceSnapshot(); | |
59 if (generate_discardable_images_metadata_) | |
60 display_list_->GenerateDiscardableImagesMetadata(); | |
61 } | |
62 | |
63 void RecordingSource::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | |
64 if (!layer_rect.IsEmpty()) { | |
65 // Clamp invalidation to the layer bounds. | |
66 invalidation_.Union(gfx::IntersectRects(layer_rect, gfx::Rect(size_))); | |
67 } | |
68 } | |
69 | |
70 bool RecordingSource::UpdateAndExpandInvalidation( | |
71 Region* invalidation, | |
72 const gfx::Size& layer_size, | |
73 const gfx::Rect& new_recorded_viewport) { | |
74 bool updated = false; | |
75 | |
76 if (size_ != layer_size) | |
77 size_ = layer_size; | |
78 | |
79 invalidation_.Swap(invalidation); | |
80 invalidation_.Clear(); | |
81 | |
82 if (new_recorded_viewport != recorded_viewport_) { | |
83 UpdateInvalidationForNewViewport(recorded_viewport_, new_recorded_viewport, | |
84 invalidation); | |
85 recorded_viewport_ = new_recorded_viewport; | |
86 updated = true; | |
87 } | |
88 | |
89 if (!updated && !invalidation->Intersects(recorded_viewport_)) | |
90 return false; | |
91 | |
92 if (invalidation->IsEmpty()) | |
93 return false; | |
94 | |
95 return true; | |
96 } | |
97 | |
98 void RecordingSource::UpdateDisplayItemList( | |
99 const scoped_refptr<DisplayItemList>& display_list, | |
100 const size_t& painter_reported_memory_usage) { | |
101 display_list_ = display_list; | |
102 painter_reported_memory_usage_ = painter_reported_memory_usage; | |
103 | |
104 FinishDisplayItemListUpdate(); | |
105 } | |
106 | |
107 gfx::Size RecordingSource::GetSize() const { | |
108 return size_; | |
109 } | |
110 | |
111 void RecordingSource::SetEmptyBounds() { | |
112 size_ = gfx::Size(); | |
113 is_solid_color_ = false; | |
114 | |
115 recorded_viewport_ = gfx::Rect(); | |
116 display_list_ = nullptr; | |
117 painter_reported_memory_usage_ = 0; | |
118 } | |
119 | |
120 void RecordingSource::SetSlowdownRasterScaleFactor(int factor) { | |
121 slow_down_raster_scale_factor_for_debug_ = factor; | |
122 } | |
123 | |
124 void RecordingSource::SetGenerateDiscardableImagesMetadata( | |
125 bool generate_metadata) { | |
126 generate_discardable_images_metadata_ = generate_metadata; | |
127 } | |
128 | |
129 void RecordingSource::SetBackgroundColor(SkColor background_color) { | |
130 background_color_ = background_color; | |
131 } | |
132 | |
133 void RecordingSource::SetRequiresClear(bool requires_clear) { | |
134 requires_clear_ = requires_clear; | |
135 } | |
136 | |
137 const DisplayItemList* RecordingSource::GetDisplayItemList() { | |
138 return display_list_.get(); | |
139 } | |
140 | |
141 scoped_refptr<RasterSource> RecordingSource::CreateRasterSource( | |
142 bool can_use_lcd_text) const { | |
143 return scoped_refptr<RasterSource>( | |
144 RasterSource::CreateFromRecordingSource(this, can_use_lcd_text)); | |
145 } | |
146 | |
147 void RecordingSource::DetermineIfSolidColor() { | |
148 DCHECK(display_list_); | |
149 is_solid_color_ = false; | |
150 solid_color_ = SK_ColorTRANSPARENT; | |
151 | |
152 if (!display_list_->ShouldBeAnalyzedForSolidColor()) | |
153 return; | |
154 | |
155 TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount", | |
156 display_list_->ApproximateOpCount()); | |
157 gfx::Size layer_size = GetSize(); | |
158 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | |
159 display_list_->Raster(&canvas, nullptr, gfx::Rect(layer_size), 1.f); | |
160 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | |
161 } | |
162 | |
163 } // namespace cc | |
OLD | NEW |