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.
5 #include "cc/resources/display_list_recording_source.h"
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"
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
20 const int kPixelDistanceToRecord
= 8000;
21 // We don't perform solid color analysis on images that have more than 10 skia
23 const int kOpCountThatIsOkToAnalyze
= 10;
29 DisplayListRecordingSource::DisplayListRecordingSource()
30 : slow_down_raster_scale_factor_for_debug_(0),
31 requires_clear_(false),
32 is_solid_color_(false),
33 solid_color_(SK_ColorTRANSPARENT
),
34 background_color_(SK_ColorTRANSPARENT
),
35 pixel_record_distance_(kPixelDistanceToRecord
),
36 is_suitable_for_gpu_rasterization_(true) {
39 DisplayListRecordingSource::~DisplayListRecordingSource() {
42 bool DisplayListRecordingSource::UpdateAndExpandInvalidation(
43 ContentLayerClient
* painter
,
45 const gfx::Size
& layer_size
,
46 const gfx::Rect
& visible_layer_rect
,
48 RecordingMode recording_mode
) {
51 if (size_
!= layer_size
) {
56 gfx::Rect old_recorded_viewport
= recorded_viewport_
;
57 recorded_viewport_
= visible_layer_rect
;
58 recorded_viewport_
.Inset(-pixel_record_distance_
, -pixel_record_distance_
);
59 recorded_viewport_
.Intersect(gfx::Rect(GetSize()));
61 if (recorded_viewport_
!= old_recorded_viewport
) {
62 // Invalidate newly-exposed and no-longer-exposed areas.
63 Region
newly_exposed_region(recorded_viewport_
);
64 newly_exposed_region
.Subtract(old_recorded_viewport
);
65 invalidation
->Union(newly_exposed_region
);
67 Region
no_longer_exposed_region(old_recorded_viewport
);
68 no_longer_exposed_region
.Subtract(recorded_viewport_
);
69 invalidation
->Union(no_longer_exposed_region
);
74 if (!updated
&& !invalidation
->Intersects(recorded_viewport_
))
77 ContentLayerClient::PaintingControlSetting painting_control
=
78 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL
;
80 switch (recording_mode
) {
82 // Already setup for normal recording.
84 case RECORD_WITH_SK_NULL_CANVAS
:
85 // TODO(schenney): Remove this when DisplayList recording is the only
86 // option. For now, fall through and disable construction.
87 case RECORD_WITH_PAINTING_DISABLED
:
88 painting_control
= ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED
;
90 case RECORD_WITH_CACHING_DISABLED
:
91 painting_control
= ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED
;
98 if (slow_down_raster_scale_factor_for_debug_
> 1) {
99 repeat_count
= slow_down_raster_scale_factor_for_debug_
;
100 if (painting_control
!=
101 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED
) {
102 painting_control
= ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED
;
105 for (int i
= 0; i
< repeat_count
; ++i
) {
106 display_list_
= painter
->PaintContentsToDisplayList(recorded_viewport_
,
109 display_list_
->set_layer_rect(recorded_viewport_
);
110 is_suitable_for_gpu_rasterization_
=
111 display_list_
->IsSuitableForGpuRasterization();
113 DetermineIfSolidColor();
114 display_list_
->EmitTraceSnapshot();
116 display_list_
->CreateAndCacheSkPicture();
121 void DisplayListRecordingSource::DidMoveToNewCompositor() {
122 // No invalidation history to worry about here.
125 gfx::Size
DisplayListRecordingSource::GetSize() const {
129 void DisplayListRecordingSource::SetEmptyBounds() {
134 void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor
) {
135 slow_down_raster_scale_factor_for_debug_
= factor
;
138 void DisplayListRecordingSource::SetBackgroundColor(SkColor background_color
) {
139 background_color_
= background_color
;
142 void DisplayListRecordingSource::SetRequiresClear(bool requires_clear
) {
143 requires_clear_
= requires_clear
;
146 void DisplayListRecordingSource::SetUnsuitableForGpuRasterizationForTesting() {
147 is_suitable_for_gpu_rasterization_
= false;
150 bool DisplayListRecordingSource::IsSuitableForGpuRasterization() const {
151 return is_suitable_for_gpu_rasterization_
;
154 scoped_refptr
<RasterSource
> DisplayListRecordingSource::CreateRasterSource(
155 bool can_use_lcd_text
) const {
156 return scoped_refptr
<RasterSource
>(
157 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
158 this, can_use_lcd_text
));
161 gfx::Size
DisplayListRecordingSource::GetTileGridSizeForTesting() const {
165 void DisplayListRecordingSource::DetermineIfSolidColor() {
166 DCHECK(display_list_
.get());
167 is_solid_color_
= false;
168 solid_color_
= SK_ColorTRANSPARENT
;
170 if (display_list_
->ApproximateOpCount() > kOpCountThatIsOkToAnalyze
)
173 gfx::Size layer_size
= GetSize();
174 skia::AnalysisCanvas
canvas(layer_size
.width(), layer_size
.height());
175 display_list_
->Raster(&canvas
, nullptr, 1.f
);
176 is_solid_color_
= canvas
.GetColorIfSolid(&solid_color_
);
179 void DisplayListRecordingSource::Clear() {
180 recorded_viewport_
= gfx::Rect();
181 display_list_
= NULL
;
182 is_solid_color_
= false;