Update V8 to version 4.7.42.
[chromium-blink-merge.git] / cc / playback / picture_pile.cc
blob37ec30b7f9e62d2899615fa416fcf926aa96d9a7
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/playback/picture_pile.h"
7 #include <algorithm>
8 #include <limits>
9 #include <vector>
11 #include "cc/base/histograms.h"
12 #include "cc/base/region.h"
13 #include "cc/playback/picture_pile_impl.h"
14 #include "skia/ext/analysis_canvas.h"
16 namespace {
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;
22 // Dimensions of the tiles in this picture pile as well as the dimensions of
23 // the base picture in each tile.
24 const int kBasePictureSize = 512;
26 // TODO(humper): The density threshold here is somewhat arbitrary; need a
27 // way to set // this from the command line so we can write a benchmark
28 // script and find a sweet spot.
29 const float kDensityThreshold = 0.5f;
31 bool rect_sort_y(const gfx::Rect& r1, const gfx::Rect& r2) {
32 return r1.y() < r2.y() || (r1.y() == r2.y() && r1.x() < r2.x());
35 bool rect_sort_x(const gfx::Rect& r1, const gfx::Rect& r2) {
36 return r1.x() < r2.x() || (r1.x() == r2.x() && r1.y() < r2.y());
39 float PerformClustering(const std::vector<gfx::Rect>& tiles,
40 std::vector<gfx::Rect>* clustered_rects) {
41 // These variables track the record area and invalid area
42 // for the entire clustering
43 int total_record_area = 0;
44 int total_invalid_area = 0;
46 // These variables track the record area and invalid area
47 // for the current cluster being constructed.
48 gfx::Rect cur_record_rect;
49 int cluster_record_area = 0, cluster_invalid_area = 0;
51 for (std::vector<gfx::Rect>::const_iterator it = tiles.begin();
52 it != tiles.end();
53 it++) {
54 gfx::Rect invalid_tile = *it;
56 // For each tile, we consider adding the invalid tile to the
57 // current record rectangle. Only add it if the amount of empty
58 // space created is below a density threshold.
59 int tile_area = invalid_tile.width() * invalid_tile.height();
61 gfx::Rect proposed_union = cur_record_rect;
62 proposed_union.Union(invalid_tile);
63 int proposed_area = proposed_union.width() * proposed_union.height();
64 float proposed_density =
65 static_cast<float>(cluster_invalid_area + tile_area) /
66 static_cast<float>(proposed_area);
68 if (proposed_density >= kDensityThreshold) {
69 // It's okay to add this invalid tile to the
70 // current recording rectangle.
71 cur_record_rect = proposed_union;
72 cluster_record_area = proposed_area;
73 cluster_invalid_area += tile_area;
74 total_invalid_area += tile_area;
75 } else {
76 // Adding this invalid tile to the current recording rectangle
77 // would exceed our badness threshold, so put the current rectangle
78 // in the list of recording rects, and start a new one.
79 clustered_rects->push_back(cur_record_rect);
80 total_record_area += cluster_record_area;
81 cur_record_rect = invalid_tile;
82 cluster_invalid_area = tile_area;
83 cluster_record_area = tile_area;
87 DCHECK(!cur_record_rect.IsEmpty());
88 clustered_rects->push_back(cur_record_rect);
89 total_record_area += cluster_record_area;;
91 DCHECK_NE(total_record_area, 0);
93 return static_cast<float>(total_invalid_area) /
94 static_cast<float>(total_record_area);
97 void ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles,
98 std::vector<gfx::Rect>* record_rects) {
99 TRACE_EVENT1("cc", "ClusterTiles",
100 "count",
101 invalid_tiles.size());
102 if (invalid_tiles.size() <= 1) {
103 // Quickly handle the special case for common
104 // single-invalidation update, and also the less common
105 // case of no tiles passed in.
106 *record_rects = invalid_tiles;
107 return;
110 // Sort the invalid tiles by y coordinate.
111 std::vector<gfx::Rect> invalid_tiles_vertical = invalid_tiles;
112 std::sort(invalid_tiles_vertical.begin(),
113 invalid_tiles_vertical.end(),
114 rect_sort_y);
116 std::vector<gfx::Rect> vertical_clustering;
117 float vertical_density =
118 PerformClustering(invalid_tiles_vertical, &vertical_clustering);
120 // If vertical density is optimal, then we can return early.
121 if (vertical_density == 1.f) {
122 *record_rects = vertical_clustering;
123 return;
126 // Now try again with a horizontal sort, see which one is best
127 std::vector<gfx::Rect> invalid_tiles_horizontal = invalid_tiles;
128 std::sort(invalid_tiles_horizontal.begin(),
129 invalid_tiles_horizontal.end(),
130 rect_sort_x);
132 std::vector<gfx::Rect> horizontal_clustering;
133 float horizontal_density =
134 PerformClustering(invalid_tiles_horizontal, &horizontal_clustering);
136 if (vertical_density < horizontal_density) {
137 *record_rects = horizontal_clustering;
138 return;
141 *record_rects = vertical_clustering;
144 #ifdef NDEBUG
145 const bool kDefaultClearCanvasSetting = false;
146 #else
147 const bool kDefaultClearCanvasSetting = true;
148 #endif
150 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(
151 ScopedPicturePileUpdateTimer,
152 "Compositing.%s.PicturePile.UpdateUs",
153 "Compositing.%s.PicturePile.UpdateInvalidatedAreaPerMs");
155 } // namespace
157 namespace cc {
159 PicturePile::PicturePile(float min_contents_scale,
160 const gfx::Size& tile_grid_size)
161 : min_contents_scale_(0),
162 slow_down_raster_scale_factor_for_debug_(0),
163 gather_images_(false),
164 has_any_recordings_(false),
165 clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
166 requires_clear_(true),
167 is_solid_color_(false),
168 solid_color_(SK_ColorTRANSPARENT),
169 background_color_(SK_ColorTRANSPARENT),
170 pixel_record_distance_(kPixelDistanceToRecord),
171 is_suitable_for_gpu_rasterization_(true) {
172 tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize));
173 SetMinContentsScale(min_contents_scale);
174 SetTileGridSize(tile_grid_size);
177 PicturePile::~PicturePile() {
180 bool PicturePile::UpdateAndExpandInvalidation(
181 ContentLayerClient* painter,
182 Region* invalidation,
183 const gfx::Size& layer_size,
184 const gfx::Rect& visible_layer_rect,
185 int frame_number,
186 RecordingSource::RecordingMode recording_mode) {
187 ScopedPicturePileUpdateTimer timer;
189 gfx::Rect interest_rect = visible_layer_rect;
190 interest_rect.Inset(-pixel_record_distance_, -pixel_record_distance_);
191 recorded_viewport_ = interest_rect;
192 recorded_viewport_.Intersect(gfx::Rect(layer_size));
194 bool updated = ApplyInvalidationAndResize(interest_rect, invalidation,
195 layer_size, frame_number);
197 // Count the area that is being invalidated.
198 Region recorded_invalidation(*invalidation);
199 recorded_invalidation.Intersect(recorded_viewport_);
200 for (Region::Iterator it(recorded_invalidation); it.has_rect(); it.next())
201 timer.AddArea(it.rect().size().GetArea());
203 std::vector<gfx::Rect> invalid_tiles;
204 GetInvalidTileRects(interest_rect, &invalid_tiles);
205 std::vector<gfx::Rect> record_rects;
206 ClusterTiles(invalid_tiles, &record_rects);
208 if (record_rects.empty())
209 return updated;
211 CreatePictures(painter, recording_mode, record_rects);
213 DetermineIfSolidColor();
215 has_any_recordings_ = true;
216 DCHECK(CanRasterSlowTileCheck(recorded_viewport_));
217 return true;
220 bool PicturePile::ApplyInvalidationAndResize(const gfx::Rect& interest_rect,
221 Region* invalidation,
222 const gfx::Size& layer_size,
223 int frame_number) {
224 bool updated = false;
226 Region synthetic_invalidation;
227 gfx::Size old_tiling_size = GetSize();
228 if (old_tiling_size != layer_size) {
229 tiling_.SetTilingSize(layer_size);
230 updated = true;
233 gfx::Rect interest_rect_over_tiles =
234 tiling_.ExpandRectToTileBounds(interest_rect);
236 if (old_tiling_size != layer_size) {
237 gfx::Size min_tiling_size(
238 std::min(GetSize().width(), old_tiling_size.width()),
239 std::min(GetSize().height(), old_tiling_size.height()));
240 gfx::Size max_tiling_size(
241 std::max(GetSize().width(), old_tiling_size.width()),
242 std::max(GetSize().height(), old_tiling_size.height()));
244 has_any_recordings_ = false;
246 // Drop recordings that are outside the new or old layer bounds or that
247 // changed size. Newly exposed areas are considered invalidated.
248 // Previously exposed areas that are now outside of bounds also need to
249 // be invalidated, as they may become part of raster when scale < 1.
250 std::vector<PictureMapKey> to_erase;
251 int min_toss_x = tiling_.num_tiles_x();
252 if (max_tiling_size.width() > min_tiling_size.width()) {
253 min_toss_x =
254 tiling_.FirstBorderTileXIndexFromSrcCoord(min_tiling_size.width());
256 int min_toss_y = tiling_.num_tiles_y();
257 if (max_tiling_size.height() > min_tiling_size.height()) {
258 min_toss_y =
259 tiling_.FirstBorderTileYIndexFromSrcCoord(min_tiling_size.height());
261 for (const auto& key_picture_pair : picture_map_) {
262 const PictureMapKey& key = key_picture_pair.first;
263 if (key.first < min_toss_x && key.second < min_toss_y) {
264 has_any_recordings_ = true;
265 continue;
267 to_erase.push_back(key);
270 for (size_t i = 0; i < to_erase.size(); ++i)
271 picture_map_.erase(to_erase[i]);
273 // If a recording is dropped and not re-recorded below, invalidate that
274 // full recording to cause any raster tiles that would use it to be
275 // dropped.
276 // If the recording will be replaced below, invalidate newly exposed
277 // areas and previously exposed areas to force raster tiles that include the
278 // old recording to know there is new recording to display.
279 gfx::Rect min_tiling_rect_over_tiles =
280 tiling_.ExpandRectToTileBounds(gfx::Rect(min_tiling_size));
281 if (min_toss_x < tiling_.num_tiles_x()) {
282 // The bounds which we want to invalidate are the tiles along the old
283 // edge of the pile when expanding, or the new edge of the pile when
284 // shrinking. In either case, it's the difference of the two, so we'll
285 // call this bounding box the DELTA EDGE RECT.
287 // In the picture below, the delta edge rect would be the bounding box of
288 // tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index of
289 // the same tiles.
291 // min pile edge-v max pile edge-v
292 // ---------------+ - - - - - - - -+
293 // mmppssvvyybbeeh|h .
294 // mmppssvvyybbeeh|h .
295 // nnqqttwwzzccffi|i .
296 // nnqqttwwzzccffi|i .
297 // oorruuxxaaddggj|j .
298 // oorruuxxaaddggj|j .
299 // ---------------+ - - - - - - - -+ <- min pile edge
300 // .
301 // - - - - - - - - - - - - - - - -+ <- max pile edge
303 // If you were to slide a vertical beam from the left edge of the
304 // delta edge rect toward the right, it would either hit the right edge
305 // of the delta edge rect, or the interest rect (expanded to the bounds
306 // of the tiles it touches). The same is true for a beam parallel to
307 // any of the four edges, sliding across the delta edge rect. We use
308 // the union of these four rectangles generated by these beams to
309 // determine which part of the delta edge rect is outside of the expanded
310 // interest rect.
312 // Case 1: Intersect rect is outside the delta edge rect. It can be
313 // either on the left or the right. The |left_rect| and |right_rect|,
314 // cover this case, one will be empty and one will cover the full
315 // delta edge rect. In the picture below, |left_rect| would cover the
316 // delta edge rect, and |right_rect| would be empty.
317 // +----------------------+ |^^^^^^^^^^^^^^^|
318 // |===> DELTA EDGE RECT | | |
319 // |===> | | INTEREST RECT |
320 // |===> | | |
321 // |===> | | |
322 // +----------------------+ |vvvvvvvvvvvvvvv|
324 // Case 2: Interest rect is inside the delta edge rect. It will always
325 // fill the entire delta edge rect horizontally since the old edge rect
326 // is a single tile wide, and the interest rect has been expanded to the
327 // bounds of the tiles it touches. In this case the |left_rect| and
328 // |right_rect| will be empty, but the case is handled by the |top_rect|
329 // and |bottom_rect|. In the picture below, neither the |top_rect| nor
330 // |bottom_rect| would empty, they would each cover the area of the old
331 // edge rect outside the expanded interest rect.
332 // +-----------------+
333 // |:::::::::::::::::|
334 // |:::::::::::::::::|
335 // |vvvvvvvvvvvvvvvvv|
336 // | |
337 // +-----------------+
338 // | INTEREST RECT |
339 // | |
340 // +-----------------+
341 // | |
342 // | DELTA EDGE RECT |
343 // +-----------------+
345 // Lastly, we need to consider tiles inside the expanded interest rect.
346 // For those tiles, we want to invalidate exactly the newly exposed
347 // pixels. In the picture below the tiles in the delta edge rect have
348 // been resized and the area covered by periods must be invalidated. The
349 // |exposed_rect| will cover exactly that area.
350 // v-min pile edge
351 // +---------+-------+
352 // | ........|
353 // | ........|
354 // | DELTA EDGE.RECT.|
355 // | ........|
356 // | ........|
357 // | ........|
358 // | ........|
359 // | ........|
360 // | ........|
361 // +---------+-------+
363 int left = tiling_.TilePositionX(min_toss_x);
364 int right = left + tiling_.TileSizeX(min_toss_x);
365 int top = min_tiling_rect_over_tiles.y();
366 int bottom = min_tiling_rect_over_tiles.bottom();
368 int left_until = std::min(interest_rect_over_tiles.x(), right);
369 int right_until = std::max(interest_rect_over_tiles.right(), left);
370 int top_until = std::min(interest_rect_over_tiles.y(), bottom);
371 int bottom_until = std::max(interest_rect_over_tiles.bottom(), top);
373 int exposed_left = min_tiling_size.width();
374 int exposed_left_until = max_tiling_size.width();
375 int exposed_top = top;
376 int exposed_bottom = max_tiling_size.height();
377 DCHECK_GE(exposed_left, left);
379 gfx::Rect left_rect(left, top, left_until - left, bottom - top);
380 gfx::Rect right_rect(right_until, top, right - right_until, bottom - top);
381 gfx::Rect top_rect(left, top, right - left, top_until - top);
382 gfx::Rect bottom_rect(
383 left, bottom_until, right - left, bottom - bottom_until);
384 gfx::Rect exposed_rect(exposed_left,
385 exposed_top,
386 exposed_left_until - exposed_left,
387 exposed_bottom - exposed_top);
388 synthetic_invalidation.Union(left_rect);
389 synthetic_invalidation.Union(right_rect);
390 synthetic_invalidation.Union(top_rect);
391 synthetic_invalidation.Union(bottom_rect);
392 synthetic_invalidation.Union(exposed_rect);
394 if (min_toss_y < tiling_.num_tiles_y()) {
395 // The same thing occurs here as in the case above, but the invalidation
396 // rect is the bounding box around the bottom row of tiles in the min
397 // pile. This would be tiles {o,r,u,x,a,d,g,j} in the above picture.
399 int top = tiling_.TilePositionY(min_toss_y);
400 int bottom = top + tiling_.TileSizeY(min_toss_y);
401 int left = min_tiling_rect_over_tiles.x();
402 int right = min_tiling_rect_over_tiles.right();
404 int top_until = std::min(interest_rect_over_tiles.y(), bottom);
405 int bottom_until = std::max(interest_rect_over_tiles.bottom(), top);
406 int left_until = std::min(interest_rect_over_tiles.x(), right);
407 int right_until = std::max(interest_rect_over_tiles.right(), left);
409 int exposed_top = min_tiling_size.height();
410 int exposed_top_until = max_tiling_size.height();
411 int exposed_left = left;
412 int exposed_right = max_tiling_size.width();
413 DCHECK_GE(exposed_top, top);
415 gfx::Rect left_rect(left, top, left_until - left, bottom - top);
416 gfx::Rect right_rect(right_until, top, right - right_until, bottom - top);
417 gfx::Rect top_rect(left, top, right - left, top_until - top);
418 gfx::Rect bottom_rect(
419 left, bottom_until, right - left, bottom - bottom_until);
420 gfx::Rect exposed_rect(exposed_left,
421 exposed_top,
422 exposed_right - exposed_left,
423 exposed_top_until - exposed_top);
424 synthetic_invalidation.Union(left_rect);
425 synthetic_invalidation.Union(right_rect);
426 synthetic_invalidation.Union(top_rect);
427 synthetic_invalidation.Union(bottom_rect);
428 synthetic_invalidation.Union(exposed_rect);
432 // Detect cases where the full pile is invalidated, in this situation we
433 // can just drop/invalidate everything.
434 if (invalidation->Contains(gfx::Rect(old_tiling_size)) ||
435 invalidation->Contains(gfx::Rect(GetSize()))) {
436 updated = !picture_map_.empty();
437 picture_map_.clear();
438 } else {
439 // Expand invalidation that is on tiles that aren't in the interest rect and
440 // will not be re-recorded below. These tiles are no longer valid and should
441 // be considerered fully invalid, so we can know to not keep around raster
442 // tiles that intersect with these recording tiles.
443 Region invalidation_expanded_to_full_tiles;
445 for (Region::Iterator i(*invalidation); i.has_rect(); i.next()) {
446 gfx::Rect invalid_rect = i.rect();
448 // This rect covers the bounds (excluding borders) of all tiles whose
449 // bounds (including borders) touch the |interest_rect|. This matches
450 // the iteration of the |invalid_rect| below which includes borders when
451 // calling Invalidate() on pictures.
452 gfx::Rect invalid_rect_outside_interest_rect_tiles =
453 tiling_.ExpandRectToTileBounds(invalid_rect);
454 // We subtract the |interest_rect_over_tiles| which represents the bounds
455 // of tiles that will be re-recorded below. This matches the iteration of
456 // |interest_rect| below which includes borders.
457 // TODO(danakj): We should have a Rect-subtract-Rect-to-2-rects operator
458 // instead of using Rect::Subtract which gives you the bounding box of the
459 // subtraction.
460 invalid_rect_outside_interest_rect_tiles.Subtract(
461 interest_rect_over_tiles);
462 invalidation_expanded_to_full_tiles.Union(
463 invalid_rect_outside_interest_rect_tiles);
465 // Split this inflated invalidation across tile boundaries and apply it
466 // to all tiles that it touches.
467 bool include_borders = true;
468 for (TilingData::Iterator iter(&tiling_, invalid_rect, include_borders);
469 iter;
470 ++iter) {
471 const PictureMapKey& key = iter.index();
473 PictureMap::iterator picture_it = picture_map_.find(key);
474 if (picture_it == picture_map_.end())
475 continue;
477 updated = true;
478 picture_map_.erase(key);
480 // Invalidate drops the picture so the whole tile better be invalidated
481 // if it won't be re-recorded below.
482 DCHECK_IMPLIES(!tiling_.TileBounds(key.first, key.second)
483 .Intersects(interest_rect_over_tiles),
484 invalidation_expanded_to_full_tiles.Contains(
485 tiling_.TileBounds(key.first, key.second)));
488 invalidation->Union(invalidation_expanded_to_full_tiles);
491 invalidation->Union(synthetic_invalidation);
492 return updated;
495 void PicturePile::GetInvalidTileRects(const gfx::Rect& interest_rect,
496 std::vector<gfx::Rect>* invalid_tiles) {
497 // Make a list of all invalid tiles; we will attempt to
498 // cluster these into multiple invalidation regions.
499 bool include_borders = true;
500 for (TilingData::Iterator it(&tiling_, interest_rect, include_borders); it;
501 ++it) {
502 const PictureMapKey& key = it.index();
503 if (picture_map_.find(key) == picture_map_.end())
504 invalid_tiles->push_back(tiling_.TileBounds(key.first, key.second));
508 void PicturePile::CreatePictures(ContentLayerClient* painter,
509 RecordingSource::RecordingMode recording_mode,
510 const std::vector<gfx::Rect>& record_rects) {
511 for (const auto& record_rect : record_rects) {
512 gfx::Rect padded_record_rect = PadRect(record_rect);
514 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be
515 // able to slow down recording.
516 scoped_refptr<Picture> picture =
517 Picture::Create(padded_record_rect, painter, tile_grid_size_,
518 gather_images_, recording_mode);
519 // Note the '&&' with previous is-suitable state.
520 // This means that once a picture-pile becomes unsuitable for gpu
521 // rasterization due to some content, it will continue to be unsuitable even
522 // if that content is replaced by gpu-friendly content. This is an
523 // optimization to avoid iterating though all pictures in the pile after
524 // each invalidation.
525 if (is_suitable_for_gpu_rasterization_) {
526 const char* reason = nullptr;
527 is_suitable_for_gpu_rasterization_ &=
528 picture->IsSuitableForGpuRasterization(&reason);
530 if (!is_suitable_for_gpu_rasterization_) {
531 TRACE_EVENT_INSTANT1("cc", "GPU Rasterization Veto",
532 TRACE_EVENT_SCOPE_THREAD, "reason", reason);
536 bool found_tile_for_recorded_picture = false;
538 bool include_borders = true;
539 for (TilingData::Iterator it(&tiling_, padded_record_rect, include_borders);
540 it; ++it) {
541 const PictureMapKey& key = it.index();
542 gfx::Rect tile = PaddedRect(key);
543 if (padded_record_rect.Contains(tile)) {
544 picture_map_[key] = picture;
545 found_tile_for_recorded_picture = true;
548 DCHECK(found_tile_for_recorded_picture);
552 scoped_refptr<RasterSource> PicturePile::CreateRasterSource(
553 bool can_use_lcd_text) const {
554 return scoped_refptr<RasterSource>(
555 PicturePileImpl::CreateFromPicturePile(this, can_use_lcd_text));
558 gfx::Size PicturePile::GetSize() const {
559 return tiling_.tiling_size();
562 void PicturePile::SetEmptyBounds() {
563 tiling_.SetTilingSize(gfx::Size());
564 Clear();
567 void PicturePile::SetMinContentsScale(float min_contents_scale) {
568 DCHECK(min_contents_scale);
569 if (min_contents_scale_ == min_contents_scale)
570 return;
572 // Picture contents are played back scaled. When the final contents scale is
573 // less than 1 (i.e. low res), then multiple recorded pixels will be used
574 // to raster one final pixel. To avoid splitting a final pixel across
575 // pictures (which would result in incorrect rasterization due to blending), a
576 // buffer margin is added so that any picture can be snapped to integral
577 // final pixels.
579 // For example, if a 1/4 contents scale is used, then that would be 3 buffer
580 // pixels, since that's the minimum number of pixels to add so that resulting
581 // content can be snapped to a four pixel aligned grid.
582 int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1);
583 buffer_pixels = std::max(0, buffer_pixels);
584 SetBufferPixels(buffer_pixels);
585 min_contents_scale_ = min_contents_scale;
588 void PicturePile::SetSlowdownRasterScaleFactor(int factor) {
589 slow_down_raster_scale_factor_for_debug_ = factor;
592 void PicturePile::SetGatherDiscardableImages(bool gather_images) {
593 gather_images_ = gather_images;
596 void PicturePile::SetBackgroundColor(SkColor background_color) {
597 background_color_ = background_color;
600 void PicturePile::SetRequiresClear(bool requires_clear) {
601 requires_clear_ = requires_clear;
604 bool PicturePile::IsSuitableForGpuRasterization() const {
605 return is_suitable_for_gpu_rasterization_;
608 void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) {
609 DCHECK_GT(tile_grid_size.width(), 0);
610 DCHECK_GT(tile_grid_size.height(), 0);
612 tile_grid_size_ = tile_grid_size;
615 void PicturePile::SetUnsuitableForGpuRasterizationForTesting() {
616 is_suitable_for_gpu_rasterization_ = false;
619 gfx::Size PicturePile::GetTileGridSizeForTesting() const {
620 return tile_grid_size_;
623 bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const {
624 bool include_borders = false;
625 for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders);
626 tile_iter; ++tile_iter) {
627 PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index());
628 if (map_iter == picture_map_.end())
629 return false;
631 return true;
634 void PicturePile::DetermineIfSolidColor() {
635 is_solid_color_ = false;
636 solid_color_ = SK_ColorTRANSPARENT;
638 if (picture_map_.empty()) {
639 return;
642 PictureMap::const_iterator it = picture_map_.begin();
643 const Picture* picture = it->second.get();
645 // Missing recordings due to frequent invalidations or being too far away
646 // from the interest rect will cause the a null picture to exist.
647 if (!picture)
648 return;
650 // Don't bother doing more work if the first image is too complicated.
651 if (!picture->ShouldBeAnalyzedForSolidColor())
652 return;
654 // Make sure all of the mapped images point to the same picture.
655 for (++it; it != picture_map_.end(); ++it) {
656 if (it->second.get() != picture)
657 return;
660 gfx::Size layer_size = GetSize();
661 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
663 picture->Raster(&canvas, nullptr, Region(), 1.0f);
664 is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
667 gfx::Rect PicturePile::PaddedRect(const PictureMapKey& key) const {
668 gfx::Rect tile = tiling_.TileBounds(key.first, key.second);
669 return PadRect(tile);
672 gfx::Rect PicturePile::PadRect(const gfx::Rect& rect) const {
673 gfx::Rect padded_rect = rect;
674 padded_rect.Inset(-buffer_pixels(), -buffer_pixels(), -buffer_pixels(),
675 -buffer_pixels());
676 return padded_rect;
679 void PicturePile::Clear() {
680 picture_map_.clear();
681 recorded_viewport_ = gfx::Rect();
682 has_any_recordings_ = false;
683 is_solid_color_ = false;
686 void PicturePile::SetBufferPixels(int new_buffer_pixels) {
687 if (new_buffer_pixels == buffer_pixels())
688 return;
690 Clear();
691 tiling_.SetBorderTexels(new_buffer_pixels);
694 } // namespace cc