1 // Copyright 2012 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/picture_pile.h"
11 #include "cc/base/region.h"
12 #include "cc/resources/picture_pile_impl.h"
13 #include "skia/ext/analysis_canvas.h"
16 // Layout pixel buffer around the visible layer rect to record. Any base
17 // picture that intersects the visible layer rect expanded by this distance
19 const int kPixelDistanceToRecord
= 8000;
20 // We don't perform solid color analysis on images that have more than 10 skia
22 const int kOpCountThatIsOkToAnalyze
= 10;
24 // Dimensions of the tiles in this picture pile as well as the dimensions of
25 // the base picture in each tile.
26 const int kBasePictureSize
= 512;
28 // TODO(humper): The density threshold here is somewhat arbitrary; need a
29 // way to set // this from the command line so we can write a benchmark
30 // script and find a sweet spot.
31 const float kDensityThreshold
= 0.5f
;
33 bool rect_sort_y(const gfx::Rect
& r1
, const gfx::Rect
& r2
) {
34 return r1
.y() < r2
.y() || (r1
.y() == r2
.y() && r1
.x() < r2
.x());
37 bool rect_sort_x(const gfx::Rect
& r1
, const gfx::Rect
& r2
) {
38 return r1
.x() < r2
.x() || (r1
.x() == r2
.x() && r1
.y() < r2
.y());
41 float PerformClustering(const std::vector
<gfx::Rect
>& tiles
,
42 std::vector
<gfx::Rect
>* clustered_rects
) {
43 // These variables track the record area and invalid area
44 // for the entire clustering
45 int total_record_area
= 0;
46 int total_invalid_area
= 0;
48 // These variables track the record area and invalid area
49 // for the current cluster being constructed.
50 gfx::Rect cur_record_rect
;
51 int cluster_record_area
= 0, cluster_invalid_area
= 0;
53 for (std::vector
<gfx::Rect
>::const_iterator it
= tiles
.begin();
56 gfx::Rect invalid_tile
= *it
;
58 // For each tile, we consider adding the invalid tile to the
59 // current record rectangle. Only add it if the amount of empty
60 // space created is below a density threshold.
61 int tile_area
= invalid_tile
.width() * invalid_tile
.height();
63 gfx::Rect proposed_union
= cur_record_rect
;
64 proposed_union
.Union(invalid_tile
);
65 int proposed_area
= proposed_union
.width() * proposed_union
.height();
66 float proposed_density
=
67 static_cast<float>(cluster_invalid_area
+ tile_area
) /
68 static_cast<float>(proposed_area
);
70 if (proposed_density
>= kDensityThreshold
) {
71 // It's okay to add this invalid tile to the
72 // current recording rectangle.
73 cur_record_rect
= proposed_union
;
74 cluster_record_area
= proposed_area
;
75 cluster_invalid_area
+= tile_area
;
76 total_invalid_area
+= tile_area
;
78 // Adding this invalid tile to the current recording rectangle
79 // would exceed our badness threshold, so put the current rectangle
80 // in the list of recording rects, and start a new one.
81 clustered_rects
->push_back(cur_record_rect
);
82 total_record_area
+= cluster_record_area
;
83 cur_record_rect
= invalid_tile
;
84 cluster_invalid_area
= tile_area
;
85 cluster_record_area
= tile_area
;
89 DCHECK(!cur_record_rect
.IsEmpty());
90 clustered_rects
->push_back(cur_record_rect
);
91 total_record_area
+= cluster_record_area
;;
93 DCHECK_NE(total_record_area
, 0);
95 return static_cast<float>(total_invalid_area
) /
96 static_cast<float>(total_record_area
);
99 void ClusterTiles(const std::vector
<gfx::Rect
>& invalid_tiles
,
100 std::vector
<gfx::Rect
>* record_rects
) {
101 TRACE_EVENT1("cc", "ClusterTiles",
103 invalid_tiles
.size());
104 if (invalid_tiles
.size() <= 1) {
105 // Quickly handle the special case for common
106 // single-invalidation update, and also the less common
107 // case of no tiles passed in.
108 *record_rects
= invalid_tiles
;
112 // Sort the invalid tiles by y coordinate.
113 std::vector
<gfx::Rect
> invalid_tiles_vertical
= invalid_tiles
;
114 std::sort(invalid_tiles_vertical
.begin(),
115 invalid_tiles_vertical
.end(),
118 std::vector
<gfx::Rect
> vertical_clustering
;
119 float vertical_density
=
120 PerformClustering(invalid_tiles_vertical
, &vertical_clustering
);
122 // If vertical density is optimal, then we can return early.
123 if (vertical_density
== 1.f
) {
124 *record_rects
= vertical_clustering
;
128 // Now try again with a horizontal sort, see which one is best
129 std::vector
<gfx::Rect
> invalid_tiles_horizontal
= invalid_tiles
;
130 std::sort(invalid_tiles_horizontal
.begin(),
131 invalid_tiles_horizontal
.end(),
134 std::vector
<gfx::Rect
> horizontal_clustering
;
135 float horizontal_density
=
136 PerformClustering(invalid_tiles_horizontal
, &horizontal_clustering
);
138 if (vertical_density
< horizontal_density
) {
139 *record_rects
= horizontal_clustering
;
143 *record_rects
= vertical_clustering
;
147 const bool kDefaultClearCanvasSetting
= false;
149 const bool kDefaultClearCanvasSetting
= true;
156 PicturePile::PicturePile(float min_contents_scale
,
157 const gfx::Size
& tile_grid_size
)
158 : min_contents_scale_(0),
159 slow_down_raster_scale_factor_for_debug_(0),
160 gather_pixel_refs_(false),
161 has_any_recordings_(false),
162 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting
),
163 requires_clear_(true),
164 is_solid_color_(false),
165 solid_color_(SK_ColorTRANSPARENT
),
166 background_color_(SK_ColorTRANSPARENT
),
167 pixel_record_distance_(kPixelDistanceToRecord
),
168 is_suitable_for_gpu_rasterization_(true) {
169 tiling_
.SetMaxTextureSize(gfx::Size(kBasePictureSize
, kBasePictureSize
));
170 SetMinContentsScale(min_contents_scale
);
171 SetTileGridSize(tile_grid_size
);
174 PicturePile::~PicturePile() {
177 bool PicturePile::UpdateAndExpandInvalidation(
178 ContentLayerClient
* painter
,
179 Region
* invalidation
,
180 const gfx::Size
& layer_size
,
181 const gfx::Rect
& visible_layer_rect
,
183 RecordingSource::RecordingMode recording_mode
) {
184 gfx::Rect interest_rect
= visible_layer_rect
;
185 interest_rect
.Inset(-pixel_record_distance_
, -pixel_record_distance_
);
186 recorded_viewport_
= interest_rect
;
187 recorded_viewport_
.Intersect(gfx::Rect(layer_size
));
189 bool updated
= ApplyInvalidationAndResize(interest_rect
, invalidation
,
190 layer_size
, frame_number
);
191 std::vector
<gfx::Rect
> invalid_tiles
;
192 GetInvalidTileRects(interest_rect
, invalidation
, visible_layer_rect
,
193 frame_number
, &invalid_tiles
);
194 std::vector
<gfx::Rect
> record_rects
;
195 ClusterTiles(invalid_tiles
, &record_rects
);
197 if (record_rects
.empty())
200 CreatePictures(painter
, recording_mode
, record_rects
);
202 DetermineIfSolidColor();
204 has_any_recordings_
= true;
205 DCHECK(CanRasterSlowTileCheck(recorded_viewport_
));
209 bool PicturePile::ApplyInvalidationAndResize(const gfx::Rect
& interest_rect
,
210 Region
* invalidation
,
211 const gfx::Size
& layer_size
,
213 bool updated
= false;
215 Region synthetic_invalidation
;
216 gfx::Size old_tiling_size
= GetSize();
217 if (old_tiling_size
!= layer_size
) {
218 tiling_
.SetTilingSize(layer_size
);
222 gfx::Rect interest_rect_over_tiles
=
223 tiling_
.ExpandRectToTileBounds(interest_rect
);
225 if (old_tiling_size
!= layer_size
) {
226 gfx::Size
min_tiling_size(
227 std::min(GetSize().width(), old_tiling_size
.width()),
228 std::min(GetSize().height(), old_tiling_size
.height()));
229 gfx::Size
max_tiling_size(
230 std::max(GetSize().width(), old_tiling_size
.width()),
231 std::max(GetSize().height(), old_tiling_size
.height()));
233 has_any_recordings_
= false;
235 // Drop recordings that are outside the new or old layer bounds or that
236 // changed size. Newly exposed areas are considered invalidated.
237 // Previously exposed areas that are now outside of bounds also need to
238 // be invalidated, as they may become part of raster when scale < 1.
239 std::vector
<PictureMapKey
> to_erase
;
240 int min_toss_x
= tiling_
.num_tiles_x();
241 if (max_tiling_size
.width() > min_tiling_size
.width()) {
243 tiling_
.FirstBorderTileXIndexFromSrcCoord(min_tiling_size
.width());
245 int min_toss_y
= tiling_
.num_tiles_y();
246 if (max_tiling_size
.height() > min_tiling_size
.height()) {
248 tiling_
.FirstBorderTileYIndexFromSrcCoord(min_tiling_size
.height());
250 for (const auto& key_picture_pair
: picture_map_
) {
251 const PictureMapKey
& key
= key_picture_pair
.first
;
252 if (key
.first
< min_toss_x
&& key
.second
< min_toss_y
) {
253 has_any_recordings_
= true;
256 to_erase
.push_back(key
);
259 for (size_t i
= 0; i
< to_erase
.size(); ++i
)
260 picture_map_
.erase(to_erase
[i
]);
262 // If a recording is dropped and not re-recorded below, invalidate that
263 // full recording to cause any raster tiles that would use it to be
265 // If the recording will be replaced below, invalidate newly exposed
266 // areas and previously exposed areas to force raster tiles that include the
267 // old recording to know there is new recording to display.
268 gfx::Rect min_tiling_rect_over_tiles
=
269 tiling_
.ExpandRectToTileBounds(gfx::Rect(min_tiling_size
));
270 if (min_toss_x
< tiling_
.num_tiles_x()) {
271 // The bounds which we want to invalidate are the tiles along the old
272 // edge of the pile when expanding, or the new edge of the pile when
273 // shrinking. In either case, it's the difference of the two, so we'll
274 // call this bounding box the DELTA EDGE RECT.
276 // In the picture below, the delta edge rect would be the bounding box of
277 // tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index of
280 // min pile edge-v max pile edge-v
281 // ---------------+ - - - - - - - -+
282 // mmppssvvyybbeeh|h .
283 // mmppssvvyybbeeh|h .
284 // nnqqttwwzzccffi|i .
285 // nnqqttwwzzccffi|i .
286 // oorruuxxaaddggj|j .
287 // oorruuxxaaddggj|j .
288 // ---------------+ - - - - - - - -+ <- min pile edge
290 // - - - - - - - - - - - - - - - -+ <- max pile edge
292 // If you were to slide a vertical beam from the left edge of the
293 // delta edge rect toward the right, it would either hit the right edge
294 // of the delta edge rect, or the interest rect (expanded to the bounds
295 // of the tiles it touches). The same is true for a beam parallel to
296 // any of the four edges, sliding across the delta edge rect. We use
297 // the union of these four rectangles generated by these beams to
298 // determine which part of the delta edge rect is outside of the expanded
301 // Case 1: Intersect rect is outside the delta edge rect. It can be
302 // either on the left or the right. The |left_rect| and |right_rect|,
303 // cover this case, one will be empty and one will cover the full
304 // delta edge rect. In the picture below, |left_rect| would cover the
305 // delta edge rect, and |right_rect| would be empty.
306 // +----------------------+ |^^^^^^^^^^^^^^^|
307 // |===> DELTA EDGE RECT | | |
308 // |===> | | INTEREST RECT |
311 // +----------------------+ |vvvvvvvvvvvvvvv|
313 // Case 2: Interest rect is inside the delta edge rect. It will always
314 // fill the entire delta edge rect horizontally since the old edge rect
315 // is a single tile wide, and the interest rect has been expanded to the
316 // bounds of the tiles it touches. In this case the |left_rect| and
317 // |right_rect| will be empty, but the case is handled by the |top_rect|
318 // and |bottom_rect|. In the picture below, neither the |top_rect| nor
319 // |bottom_rect| would empty, they would each cover the area of the old
320 // edge rect outside the expanded interest rect.
321 // +-----------------+
322 // |:::::::::::::::::|
323 // |:::::::::::::::::|
324 // |vvvvvvvvvvvvvvvvv|
326 // +-----------------+
329 // +-----------------+
331 // | DELTA EDGE RECT |
332 // +-----------------+
334 // Lastly, we need to consider tiles inside the expanded interest rect.
335 // For those tiles, we want to invalidate exactly the newly exposed
336 // pixels. In the picture below the tiles in the delta edge rect have
337 // been resized and the area covered by periods must be invalidated. The
338 // |exposed_rect| will cover exactly that area.
340 // +---------+-------+
343 // | DELTA EDGE.RECT.|
350 // +---------+-------+
352 int left
= tiling_
.TilePositionX(min_toss_x
);
353 int right
= left
+ tiling_
.TileSizeX(min_toss_x
);
354 int top
= min_tiling_rect_over_tiles
.y();
355 int bottom
= min_tiling_rect_over_tiles
.bottom();
357 int left_until
= std::min(interest_rect_over_tiles
.x(), right
);
358 int right_until
= std::max(interest_rect_over_tiles
.right(), left
);
359 int top_until
= std::min(interest_rect_over_tiles
.y(), bottom
);
360 int bottom_until
= std::max(interest_rect_over_tiles
.bottom(), top
);
362 int exposed_left
= min_tiling_size
.width();
363 int exposed_left_until
= max_tiling_size
.width();
364 int exposed_top
= top
;
365 int exposed_bottom
= max_tiling_size
.height();
366 DCHECK_GE(exposed_left
, left
);
368 gfx::Rect
left_rect(left
, top
, left_until
- left
, bottom
- top
);
369 gfx::Rect
right_rect(right_until
, top
, right
- right_until
, bottom
- top
);
370 gfx::Rect
top_rect(left
, top
, right
- left
, top_until
- top
);
371 gfx::Rect
bottom_rect(
372 left
, bottom_until
, right
- left
, bottom
- bottom_until
);
373 gfx::Rect
exposed_rect(exposed_left
,
375 exposed_left_until
- exposed_left
,
376 exposed_bottom
- exposed_top
);
377 synthetic_invalidation
.Union(left_rect
);
378 synthetic_invalidation
.Union(right_rect
);
379 synthetic_invalidation
.Union(top_rect
);
380 synthetic_invalidation
.Union(bottom_rect
);
381 synthetic_invalidation
.Union(exposed_rect
);
383 if (min_toss_y
< tiling_
.num_tiles_y()) {
384 // The same thing occurs here as in the case above, but the invalidation
385 // rect is the bounding box around the bottom row of tiles in the min
386 // pile. This would be tiles {o,r,u,x,a,d,g,j} in the above picture.
388 int top
= tiling_
.TilePositionY(min_toss_y
);
389 int bottom
= top
+ tiling_
.TileSizeY(min_toss_y
);
390 int left
= min_tiling_rect_over_tiles
.x();
391 int right
= min_tiling_rect_over_tiles
.right();
393 int top_until
= std::min(interest_rect_over_tiles
.y(), bottom
);
394 int bottom_until
= std::max(interest_rect_over_tiles
.bottom(), top
);
395 int left_until
= std::min(interest_rect_over_tiles
.x(), right
);
396 int right_until
= std::max(interest_rect_over_tiles
.right(), left
);
398 int exposed_top
= min_tiling_size
.height();
399 int exposed_top_until
= max_tiling_size
.height();
400 int exposed_left
= left
;
401 int exposed_right
= max_tiling_size
.width();
402 DCHECK_GE(exposed_top
, top
);
404 gfx::Rect
left_rect(left
, top
, left_until
- left
, bottom
- top
);
405 gfx::Rect
right_rect(right_until
, top
, right
- right_until
, bottom
- top
);
406 gfx::Rect
top_rect(left
, top
, right
- left
, top_until
- top
);
407 gfx::Rect
bottom_rect(
408 left
, bottom_until
, right
- left
, bottom
- bottom_until
);
409 gfx::Rect
exposed_rect(exposed_left
,
411 exposed_right
- exposed_left
,
412 exposed_top_until
- exposed_top
);
413 synthetic_invalidation
.Union(left_rect
);
414 synthetic_invalidation
.Union(right_rect
);
415 synthetic_invalidation
.Union(top_rect
);
416 synthetic_invalidation
.Union(bottom_rect
);
417 synthetic_invalidation
.Union(exposed_rect
);
421 // Detect cases where the full pile is invalidated, in this situation we
422 // can just drop/invalidate everything.
423 if (invalidation
->Contains(gfx::Rect(old_tiling_size
)) ||
424 invalidation
->Contains(gfx::Rect(GetSize()))) {
425 updated
= !picture_map_
.empty();
426 picture_map_
.clear();
428 // Expand invalidation that is on tiles that aren't in the interest rect and
429 // will not be re-recorded below. These tiles are no longer valid and should
430 // be considerered fully invalid, so we can know to not keep around raster
431 // tiles that intersect with these recording tiles.
432 Region invalidation_expanded_to_full_tiles
;
434 for (Region::Iterator
i(*invalidation
); i
.has_rect(); i
.next()) {
435 gfx::Rect invalid_rect
= i
.rect();
437 // This rect covers the bounds (excluding borders) of all tiles whose
438 // bounds (including borders) touch the |interest_rect|. This matches
439 // the iteration of the |invalid_rect| below which includes borders when
440 // calling Invalidate() on pictures.
441 gfx::Rect invalid_rect_outside_interest_rect_tiles
=
442 tiling_
.ExpandRectToTileBounds(invalid_rect
);
443 // We subtract the |interest_rect_over_tiles| which represents the bounds
444 // of tiles that will be re-recorded below. This matches the iteration of
445 // |interest_rect| below which includes borders.
446 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator
447 // instead of using Rect::Subtract which gives you the bounding box of the
449 invalid_rect_outside_interest_rect_tiles
.Subtract(
450 interest_rect_over_tiles
);
451 invalidation_expanded_to_full_tiles
.Union(
452 invalid_rect_outside_interest_rect_tiles
);
454 // Split this inflated invalidation across tile boundaries and apply it
455 // to all tiles that it touches.
456 bool include_borders
= true;
457 for (TilingData::Iterator
iter(&tiling_
, invalid_rect
, include_borders
);
460 const PictureMapKey
& key
= iter
.index();
462 PictureMap::iterator picture_it
= picture_map_
.find(key
);
463 if (picture_it
== picture_map_
.end())
467 picture_map_
.erase(key
);
469 // Invalidate drops the picture so the whole tile better be invalidated
470 // if it won't be re-recorded below.
471 DCHECK_IMPLIES(!tiling_
.TileBounds(key
.first
, key
.second
)
472 .Intersects(interest_rect_over_tiles
),
473 invalidation_expanded_to_full_tiles
.Contains(
474 tiling_
.TileBounds(key
.first
, key
.second
)));
477 invalidation
->Union(invalidation_expanded_to_full_tiles
);
480 invalidation
->Union(synthetic_invalidation
);
484 void PicturePile::GetInvalidTileRects(const gfx::Rect
& interest_rect
,
485 Region
* invalidation
,
486 const gfx::Rect
& visible_layer_rect
,
488 std::vector
<gfx::Rect
>* invalid_tiles
) {
489 // Make a list of all invalid tiles; we will attempt to
490 // cluster these into multiple invalidation regions.
491 bool include_borders
= true;
492 for (TilingData::Iterator
it(&tiling_
, interest_rect
, include_borders
); it
;
494 const PictureMapKey
& key
= it
.index();
495 if (picture_map_
.find(key
) == picture_map_
.end())
496 invalid_tiles
->push_back(tiling_
.TileBounds(key
.first
, key
.second
));
500 void PicturePile::CreatePictures(ContentLayerClient
* painter
,
501 RecordingSource::RecordingMode recording_mode
,
502 const std::vector
<gfx::Rect
>& record_rects
) {
503 for (const auto& record_rect
: record_rects
) {
504 gfx::Rect padded_record_rect
= PadRect(record_rect
);
506 int repeat_count
= std::max(1, slow_down_raster_scale_factor_for_debug_
);
507 scoped_refptr
<Picture
> picture
;
509 for (int i
= 0; i
< repeat_count
; i
++) {
510 picture
= Picture::Create(padded_record_rect
, painter
, tile_grid_size_
,
511 gather_pixel_refs_
, recording_mode
);
512 // Note the '&&' with previous is-suitable state.
513 // This means that once a picture-pile becomes unsuitable for gpu
514 // rasterization due to some content, it will continue to be unsuitable
515 // even if that content is replaced by gpu-friendly content.
516 // This is an optimization to avoid iterating though all pictures in
517 // the pile after each invalidation.
518 if (is_suitable_for_gpu_rasterization_
) {
519 const char* reason
= nullptr;
520 is_suitable_for_gpu_rasterization_
&=
521 picture
->IsSuitableForGpuRasterization(&reason
);
523 if (!is_suitable_for_gpu_rasterization_
) {
524 TRACE_EVENT_INSTANT1("cc", "GPU Rasterization Veto",
525 TRACE_EVENT_SCOPE_THREAD
, "reason", reason
);
530 bool found_tile_for_recorded_picture
= false;
532 bool include_borders
= true;
533 for (TilingData::Iterator
it(&tiling_
, padded_record_rect
, include_borders
);
535 const PictureMapKey
& key
= it
.index();
536 gfx::Rect tile
= PaddedRect(key
);
537 if (padded_record_rect
.Contains(tile
)) {
538 picture_map_
[key
] = picture
;
539 found_tile_for_recorded_picture
= true;
542 DCHECK(found_tile_for_recorded_picture
);
546 scoped_refptr
<RasterSource
> PicturePile::CreateRasterSource(
547 bool can_use_lcd_text
) const {
548 return scoped_refptr
<RasterSource
>(
549 PicturePileImpl::CreateFromPicturePile(this, can_use_lcd_text
));
552 gfx::Size
PicturePile::GetSize() const {
553 return tiling_
.tiling_size();
556 void PicturePile::SetEmptyBounds() {
557 tiling_
.SetTilingSize(gfx::Size());
561 void PicturePile::SetMinContentsScale(float min_contents_scale
) {
562 DCHECK(min_contents_scale
);
563 if (min_contents_scale_
== min_contents_scale
)
566 // Picture contents are played back scaled. When the final contents scale is
567 // less than 1 (i.e. low res), then multiple recorded pixels will be used
568 // to raster one final pixel. To avoid splitting a final pixel across
569 // pictures (which would result in incorrect rasterization due to blending), a
570 // buffer margin is added so that any picture can be snapped to integral
573 // For example, if a 1/4 contents scale is used, then that would be 3 buffer
574 // pixels, since that's the minimum number of pixels to add so that resulting
575 // content can be snapped to a four pixel aligned grid.
576 int buffer_pixels
= static_cast<int>(ceil(1 / min_contents_scale
) - 1);
577 buffer_pixels
= std::max(0, buffer_pixels
);
578 SetBufferPixels(buffer_pixels
);
579 min_contents_scale_
= min_contents_scale
;
582 void PicturePile::SetSlowdownRasterScaleFactor(int factor
) {
583 slow_down_raster_scale_factor_for_debug_
= factor
;
586 void PicturePile::SetGatherPixelRefs(bool gather_pixel_refs
) {
587 gather_pixel_refs_
= gather_pixel_refs
;
590 void PicturePile::SetBackgroundColor(SkColor background_color
) {
591 background_color_
= background_color
;
594 void PicturePile::SetRequiresClear(bool requires_clear
) {
595 requires_clear_
= requires_clear
;
598 bool PicturePile::IsSuitableForGpuRasterization() const {
599 return is_suitable_for_gpu_rasterization_
;
602 void PicturePile::SetTileGridSize(const gfx::Size
& tile_grid_size
) {
603 DCHECK_GT(tile_grid_size
.width(), 0);
604 DCHECK_GT(tile_grid_size
.height(), 0);
606 tile_grid_size_
= tile_grid_size
;
609 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() {
610 is_suitable_for_gpu_rasterization_
= false;
613 gfx::Size
PicturePile::GetTileGridSizeForTesting() const {
614 return tile_grid_size_
;
617 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect
& layer_rect
) const {
618 bool include_borders
= false;
619 for (TilingData::Iterator
tile_iter(&tiling_
, layer_rect
, include_borders
);
620 tile_iter
; ++tile_iter
) {
621 PictureMap::const_iterator map_iter
= picture_map_
.find(tile_iter
.index());
622 if (map_iter
== picture_map_
.end())
628 void PicturePile::DetermineIfSolidColor() {
629 is_solid_color_
= false;
630 solid_color_
= SK_ColorTRANSPARENT
;
632 if (picture_map_
.empty()) {
636 PictureMap::const_iterator it
= picture_map_
.begin();
637 const Picture
* picture
= it
->second
.get();
639 // Missing recordings due to frequent invalidations or being too far away
640 // from the interest rect will cause the a null picture to exist.
644 // Don't bother doing more work if the first image is too complicated.
645 if (picture
->ApproximateOpCount() > kOpCountThatIsOkToAnalyze
)
648 // Make sure all of the mapped images point to the same picture.
649 for (++it
; it
!= picture_map_
.end(); ++it
) {
650 if (it
->second
.get() != picture
)
654 gfx::Size layer_size
= GetSize();
655 skia::AnalysisCanvas
canvas(layer_size
.width(), layer_size
.height());
657 picture
->Raster(&canvas
, nullptr, Region(), 1.0f
);
658 is_solid_color_
= canvas
.GetColorIfSolid(&solid_color_
);
661 gfx::Rect
PicturePile::PaddedRect(const PictureMapKey
& key
) const {
662 gfx::Rect tile
= tiling_
.TileBounds(key
.first
, key
.second
);
663 return PadRect(tile
);
666 gfx::Rect
PicturePile::PadRect(const gfx::Rect
& rect
) const {
667 gfx::Rect padded_rect
= rect
;
668 padded_rect
.Inset(-buffer_pixels(), -buffer_pixels(), -buffer_pixels(),
673 void PicturePile::Clear() {
674 picture_map_
.clear();
675 recorded_viewport_
= gfx::Rect();
676 has_any_recordings_
= false;
677 is_solid_color_
= false;
680 void PicturePile::SetBufferPixels(int new_buffer_pixels
) {
681 if (new_buffer_pixels
== buffer_pixels())
685 tiling_
.SetBorderTexels(new_buffer_pixels
);