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 can_use_lcd_text_(true),
32 is_solid_color_(false),
33 solid_color_(SK_ColorTRANSPARENT
),
34 pixel_record_distance_(kPixelDistanceToRecord
),
35 is_suitable_for_gpu_rasterization_(true) {
38 DisplayListRecordingSource::~DisplayListRecordingSource() {
41 bool DisplayListRecordingSource::UpdateAndExpandInvalidation(
42 ContentLayerClient
* painter
,
44 bool can_use_lcd_text
,
45 const gfx::Size
& layer_size
,
46 const gfx::Rect
& visible_layer_rect
,
48 RecordingMode recording_mode
) {
51 if (size_
!= layer_size
) {
56 if (can_use_lcd_text_
!= can_use_lcd_text
) {
57 can_use_lcd_text_
= can_use_lcd_text
;
58 invalidation
->Union(gfx::Rect(GetSize()));
62 gfx::Rect old_recorded_viewport
= recorded_viewport_
;
63 // TODO(wangxianzhu): Blink slimming paint doesn't support incremental
64 // painting for now so we must record for the whole layer. Should measure
65 // performance and determine the best choice. Consider display item caching.
66 recorded_viewport_
= gfx::Rect(GetSize());
68 if (recorded_viewport_
!= old_recorded_viewport
) {
69 // Invalidate newly-exposed and no-longer-exposed areas.
70 Region
newly_exposed_region(recorded_viewport_
);
71 newly_exposed_region
.Subtract(old_recorded_viewport
);
72 invalidation
->Union(newly_exposed_region
);
74 Region
no_longer_exposed_region(old_recorded_viewport
);
75 no_longer_exposed_region
.Subtract(recorded_viewport_
);
76 invalidation
->Union(no_longer_exposed_region
);
81 if (!updated
&& !invalidation
->Intersects(recorded_viewport_
))
84 ContentLayerClient::PaintingControlSetting painting_control
=
85 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL
;
87 switch (recording_mode
) {
89 // Already setup for normal recording.
91 case RECORD_WITH_SK_NULL_CANVAS
:
92 // TODO(schenney): Remove this when DisplayList recording is the only
93 // option. For now, fall through and disable construction.
94 case RECORD_WITH_PAINTING_DISABLED
:
95 painting_control
= ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED
;
97 case RECORD_WITH_CACHING_DISABLED
:
98 painting_control
= ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED
;
104 int repeat_count
= 1;
105 if (slow_down_raster_scale_factor_for_debug_
> 1) {
106 repeat_count
= slow_down_raster_scale_factor_for_debug_
;
107 if (painting_control
!=
108 ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED
) {
109 painting_control
= ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED
;
112 for (int i
= 0; i
< repeat_count
; ++i
) {
113 display_list_
= painter
->PaintContentsToDisplayList(recorded_viewport_
,
116 display_list_
->set_layer_rect(recorded_viewport_
);
117 is_suitable_for_gpu_rasterization_
=
118 display_list_
->IsSuitableForGpuRasterization();
120 DetermineIfSolidColor();
121 display_list_
->EmitTraceSnapshot();
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::SetUnsuitableForGpuRasterizationForTesting() {
139 is_suitable_for_gpu_rasterization_
= false;
142 bool DisplayListRecordingSource::IsSuitableForGpuRasterization() const {
143 return is_suitable_for_gpu_rasterization_
;
146 scoped_refptr
<RasterSource
> DisplayListRecordingSource::CreateRasterSource()
148 return scoped_refptr
<RasterSource
>(
149 DisplayListRasterSource::CreateFromDisplayListRecordingSource(this));
152 gfx::Size
DisplayListRecordingSource::GetTileGridSizeForTesting() const {
156 void DisplayListRecordingSource::DetermineIfSolidColor() {
157 DCHECK(display_list_
.get());
158 is_solid_color_
= false;
159 solid_color_
= SK_ColorTRANSPARENT
;
161 if (display_list_
->ApproximateOpCount() > kOpCountThatIsOkToAnalyze
)
164 gfx::Size layer_size
= GetSize();
165 skia::AnalysisCanvas
canvas(layer_size
.width(), layer_size
.height());
166 display_list_
->Raster(&canvas
, nullptr, 1.f
);
167 is_solid_color_
= canvas
.GetColorIfSolid(&solid_color_
);
170 void DisplayListRecordingSource::Clear() {
171 recorded_viewport_
= gfx::Rect();
172 display_list_
= NULL
;
173 is_solid_color_
= false;