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/resources/display_list_recording_source.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "cc/base/region.h" | |
10 #include "cc/layers/content_layer_client.h" | |
11 #include "cc/resources/display_item_list.h" | |
12 #include "cc/resources/display_list_raster_source.h" | |
13 #include "skia/ext/analysis_canvas.h" | |
14 | |
15 namespace { | |
16 | |
17 // Layout pixel buffer around the visible layer rect to record. Any base | |
18 // picture that intersects the visible layer rect expanded by this distance | |
19 // will be recorded. | |
20 const int kPixelDistanceToRecord = 8000; | |
21 // We don't perform solid color analysis on images that have more than 10 skia | |
22 // operations. | |
23 const int kOpCountThatIsOkToAnalyze = 10; | |
24 | |
25 } // namespace | |
26 | |
27 namespace cc { | |
28 | |
29 DisplayListRecordingSource::DisplayListRecordingSource() | |
30 : slow_down_raster_scale_factor_for_debug_(0), | |
31 gather_pixel_refs_(false), | |
32 requires_clear_(false), | |
33 is_solid_color_(false), | |
34 solid_color_(SK_ColorTRANSPARENT), | |
35 background_color_(SK_ColorTRANSPARENT), | |
36 pixel_record_distance_(kPixelDistanceToRecord), | |
37 is_suitable_for_gpu_rasterization_(true) { | |
38 } | |
39 | |
40 DisplayListRecordingSource::~DisplayListRecordingSource() { | |
41 } | |
42 | |
43 bool DisplayListRecordingSource::UpdateAndExpandInvalidation( | |
44 ContentLayerClient* painter, | |
45 Region* invalidation, | |
46 const gfx::Size& layer_size, | |
47 const gfx::Rect& visible_layer_rect, | |
48 int frame_number, | |
49 RecordingMode recording_mode) { | |
50 bool updated = false; | |
51 | |
52 if (size_ != layer_size) { | |
53 size_ = layer_size; | |
54 updated = true; | |
55 } | |
56 | |
57 gfx::Rect old_recorded_viewport = recorded_viewport_; | |
58 recorded_viewport_ = visible_layer_rect; | |
59 recorded_viewport_.Inset(-pixel_record_distance_, -pixel_record_distance_); | |
60 recorded_viewport_.Intersect(gfx::Rect(GetSize())); | |
61 | |
62 if (recorded_viewport_ != old_recorded_viewport) { | |
63 // Invalidate newly-exposed and no-longer-exposed areas. | |
64 Region newly_exposed_region(recorded_viewport_); | |
65 newly_exposed_region.Subtract(old_recorded_viewport); | |
66 invalidation->Union(newly_exposed_region); | |
67 | |
68 Region no_longer_exposed_region(old_recorded_viewport); | |
69 no_longer_exposed_region.Subtract(recorded_viewport_); | |
70 invalidation->Union(no_longer_exposed_region); | |
71 | |
72 updated = true; | |
73 } | |
74 | |
75 if (!updated && !invalidation->Intersects(recorded_viewport_)) | |
76 return false; | |
77 | |
78 ContentLayerClient::PaintingControlSetting painting_control = | |
79 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL; | |
80 | |
81 switch (recording_mode) { | |
82 case RECORD_NORMALLY: | |
83 // Already setup for normal recording. | |
84 break; | |
85 case RECORD_WITH_SK_NULL_CANVAS: | |
86 // TODO(schenney): Remove this when DisplayList recording is the only | |
87 // option. For now, fall through and disable construction. | |
88 case RECORD_WITH_PAINTING_DISABLED: | |
89 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED; | |
90 break; | |
91 case RECORD_WITH_CACHING_DISABLED: | |
92 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
93 break; | |
94 default: | |
95 NOTREACHED(); | |
96 } | |
97 | |
98 int repeat_count = 1; | |
99 if (slow_down_raster_scale_factor_for_debug_ > 1) { | |
100 repeat_count = slow_down_raster_scale_factor_for_debug_; | |
101 if (painting_control != | |
102 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED) { | |
103 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED; | |
104 } | |
105 } | |
106 for (int i = 0; i < repeat_count; ++i) { | |
107 display_list_ = painter->PaintContentsToDisplayList(recorded_viewport_, | |
108 painting_control); | |
109 } | |
110 display_list_->set_layer_rect(recorded_viewport_); | |
111 is_suitable_for_gpu_rasterization_ = | |
112 display_list_->IsSuitableForGpuRasterization(); | |
113 | |
114 DetermineIfSolidColor(); | |
115 display_list_->EmitTraceSnapshot(); | |
116 | |
117 display_list_->CreateAndCacheSkPicture(); | |
118 | |
119 return true; | |
120 } | |
121 | |
122 void DisplayListRecordingSource::DidMoveToNewCompositor() { | |
123 // No invalidation history to worry about here. | |
124 } | |
125 | |
126 gfx::Size DisplayListRecordingSource::GetSize() const { | |
127 return size_; | |
128 } | |
129 | |
130 void DisplayListRecordingSource::SetEmptyBounds() { | |
131 size_ = gfx::Size(); | |
132 Clear(); | |
133 } | |
134 | |
135 void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor) { | |
136 slow_down_raster_scale_factor_for_debug_ = factor; | |
137 } | |
138 | |
139 void DisplayListRecordingSource::SetGatherPixelRefs(bool gather_pixel_refs) { | |
140 gather_pixel_refs_ = gather_pixel_refs; | |
141 } | |
142 | |
143 void DisplayListRecordingSource::SetBackgroundColor(SkColor background_color) { | |
144 background_color_ = background_color; | |
145 } | |
146 | |
147 void DisplayListRecordingSource::SetRequiresClear(bool requires_clear) { | |
148 requires_clear_ = requires_clear; | |
149 } | |
150 | |
151 void DisplayListRecordingSource::SetUnsuitableForGpuRasterizationForTesting() { | |
152 is_suitable_for_gpu_rasterization_ = false; | |
153 } | |
154 | |
155 bool DisplayListRecordingSource::IsSuitableForGpuRasterization() const { | |
156 return is_suitable_for_gpu_rasterization_; | |
157 } | |
158 | |
159 scoped_refptr<RasterSource> DisplayListRecordingSource::CreateRasterSource( | |
160 bool can_use_lcd_text) const { | |
161 return scoped_refptr<RasterSource>( | |
162 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | |
163 this, can_use_lcd_text)); | |
164 } | |
165 | |
166 gfx::Size DisplayListRecordingSource::GetTileGridSizeForTesting() const { | |
167 return gfx::Size(); | |
168 } | |
169 | |
170 void DisplayListRecordingSource::DetermineIfSolidColor() { | |
171 DCHECK(display_list_.get()); | |
172 is_solid_color_ = false; | |
173 solid_color_ = SK_ColorTRANSPARENT; | |
174 | |
175 if (display_list_->ApproximateOpCount() > kOpCountThatIsOkToAnalyze) | |
176 return; | |
177 | |
178 gfx::Size layer_size = GetSize(); | |
179 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height()); | |
180 display_list_->Raster(&canvas, nullptr, 1.f); | |
181 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_); | |
182 } | |
183 | |
184 void DisplayListRecordingSource::Clear() { | |
185 recorded_viewport_ = gfx::Rect(); | |
186 display_list_ = NULL; | |
187 is_solid_color_ = false; | |
188 } | |
189 | |
190 } // namespace cc | |
OLD | NEW |