Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Unified Diff: cc/resources/picture_pile.cc

Issue 723343002: Update from https://crrev.com/304121 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/picture_pile.h ('k') | cc/resources/picture_pile_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/picture_pile.cc
diff --git a/cc/resources/picture_pile.cc b/cc/resources/picture_pile.cc
index 1ad673b7222bb39fe157f292d0230f12ac91ac64..ab138cab658f1766bce72e33a1aea7edc136f439 100644
--- a/cc/resources/picture_pile.cc
+++ b/cc/resources/picture_pile.cc
@@ -9,7 +9,7 @@
#include <vector>
#include "cc/base/region.h"
-#include "cc/debug/rendering_stats_instrumentation.h"
+#include "cc/resources/picture_pile_impl.h"
#include "cc/resources/raster_worker_pool.h"
#include "skia/ext/analysis_canvas.h"
@@ -22,6 +22,24 @@ const int kPixelDistanceToRecord = 8000;
// operations.
const int kOpCountThatIsOkToAnalyze = 10;
+// Dimensions of the tiles in this picture pile as well as the dimensions of
+// the base picture in each tile.
+const int kBasePictureSize = 512;
+const int kTileGridBorderPixels = 1;
+#ifdef NDEBUG
+const bool kDefaultClearCanvasSetting = false;
+#else
+const bool kDefaultClearCanvasSetting = true;
+#endif
+
+// Invalidation frequency settings. kInvalidationFrequencyThreshold is a value
+// between 0 and 1 meaning invalidation frequency between 0% and 100% that
+// indicates when to stop invalidating offscreen regions.
+// kFrequentInvalidationDistanceThreshold defines what it means to be
+// "offscreen" in terms of distance to visible in css pixels.
+const float kInvalidationFrequencyThreshold = 0.75f;
+const int kFrequentInvalidationDistanceThreshold = 512;
+
// TODO(humper): The density threshold here is somewhat arbitrary; need a
// way to set // this from the command line so we can write a benchmark
// script and find a sweet spot.
@@ -149,8 +167,21 @@ float ClusterTiles(const std::vector<gfx::Rect>& invalid_tiles,
namespace cc {
PicturePile::PicturePile()
- : is_suitable_for_gpu_rasterization_(true),
- pixel_record_distance_(kPixelDistanceToRecord) {
+ : min_contents_scale_(0),
+ slow_down_raster_scale_factor_for_debug_(0),
+ contents_opaque_(false),
+ contents_fill_bounds_completely_(false),
+ clear_canvas_with_debug_color_(kDefaultClearCanvasSetting),
+ has_any_recordings_(false),
+ is_mask_(false),
+ is_solid_color_(false),
+ solid_color_(SK_ColorTRANSPARENT),
+ pixel_record_distance_(kPixelDistanceToRecord),
+ is_suitable_for_gpu_rasterization_(true) {
+ tiling_.SetMaxTextureSize(gfx::Size(kBasePictureSize, kBasePictureSize));
+ tile_grid_info_.fTileInterval.setEmpty();
+ tile_grid_info_.fMargin.setEmpty();
+ tile_grid_info_.fOffset.setZero();
}
PicturePile::~PicturePile() {
@@ -165,8 +196,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
const gfx::Size& layer_size,
const gfx::Rect& visible_layer_rect,
int frame_number,
- Picture::RecordingMode recording_mode,
- RenderingStatsInstrumentation* stats_instrumentation) {
+ Picture::RecordingMode recording_mode) {
background_color_ = background_color;
contents_opaque_ = contents_opaque;
contents_fill_bounds_completely_ = contents_fill_bounds_completely;
@@ -174,7 +204,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
bool updated = false;
Region resize_invalidation;
- gfx::Size old_tiling_size = tiling_size();
+ gfx::Size old_tiling_size = GetSize();
if (old_tiling_size != layer_size) {
tiling_.SetTilingSize(layer_size);
updated = true;
@@ -183,26 +213,35 @@ bool PicturePile::UpdateAndExpandInvalidation(
gfx::Rect interest_rect = visible_layer_rect;
interest_rect.Inset(-pixel_record_distance_, -pixel_record_distance_);
recorded_viewport_ = interest_rect;
- recorded_viewport_.Intersect(gfx::Rect(tiling_size()));
+ recorded_viewport_.Intersect(gfx::Rect(GetSize()));
gfx::Rect interest_rect_over_tiles =
tiling_.ExpandRectToTileBounds(interest_rect);
+ gfx::Size min_tiling_size(
+ std::min(GetSize().width(), old_tiling_size.width()),
+ std::min(GetSize().height(), old_tiling_size.height()));
+ gfx::Size max_tiling_size(
+ std::max(GetSize().width(), old_tiling_size.width()),
+ std::max(GetSize().height(), old_tiling_size.height()));
+
if (old_tiling_size != layer_size) {
has_any_recordings_ = false;
- // Drop recordings that are outside the new layer bounds or that changed
- // size.
+ // Drop recordings that are outside the new or old layer bounds or that
+ // changed size. Newly exposed areas are considered invalidated.
+ // Previously exposed areas that are now outside of bounds also need to
+ // be invalidated, as they may become part of raster when scale < 1.
std::vector<PictureMapKey> to_erase;
int min_toss_x = tiling_.num_tiles_x();
- if (tiling_size().width() > old_tiling_size.width()) {
+ if (max_tiling_size.width() > min_tiling_size.width()) {
min_toss_x =
- tiling_.FirstBorderTileXIndexFromSrcCoord(old_tiling_size.width());
+ tiling_.FirstBorderTileXIndexFromSrcCoord(min_tiling_size.width());
}
int min_toss_y = tiling_.num_tiles_y();
- if (tiling_size().height() > old_tiling_size.height()) {
+ if (max_tiling_size.height() > min_tiling_size.height()) {
min_toss_y =
- tiling_.FirstBorderTileYIndexFromSrcCoord(old_tiling_size.height());
+ tiling_.FirstBorderTileYIndexFromSrcCoord(min_tiling_size.height());
}
for (PictureMap::const_iterator it = picture_map_.begin();
it != picture_map_.end();
@@ -221,20 +260,22 @@ bool PicturePile::UpdateAndExpandInvalidation(
// If a recording is dropped and not re-recorded below, invalidate that
// full recording to cause any raster tiles that would use it to be
// dropped.
- // If the recording will be replaced below, just invalidate newly exposed
- // areas to force raster tiles that include the old recording to know
- // there is new recording to display.
- gfx::Rect old_tiling_rect_over_tiles =
- tiling_.ExpandRectToTileBounds(gfx::Rect(old_tiling_size));
+ // If the recording will be replaced below, invalidate newly exposed
+ // areas and previously exposed areas to force raster tiles that include the
+ // old recording to know there is new recording to display.
+ gfx::Rect min_tiling_rect_over_tiles =
+ tiling_.ExpandRectToTileBounds(gfx::Rect(min_tiling_size));
if (min_toss_x < tiling_.num_tiles_x()) {
// The bounds which we want to invalidate are the tiles along the old
- // edge of the pile. We'll call this bounding box the OLD EDGE RECT.
+ // edge of the pile when expanding, or the new edge of the pile when
+ // shrinking. In either case, it's the difference of the two, so we'll
+ // call this bounding box the DELTA EDGE RECT.
//
- // In the picture below, the old edge rect would be the bounding box
- // of tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index
- // of the same tiles.
+ // In the picture below, the delta edge rect would be the bounding box of
+ // tiles {h,i,j}. |min_toss_x| would be equal to the horizontal index of
+ // the same tiles.
//
- // old pile edge-v new pile edge-v
+ // min pile edge-v max pile edge-v
// ---------------+ - - - - - - - -+
// mmppssvvyybbeeh|h .
// mmppssvvyybbeeh|h .
@@ -242,33 +283,33 @@ bool PicturePile::UpdateAndExpandInvalidation(
// nnqqttwwzzccffi|i .
// oorruuxxaaddggj|j .
// oorruuxxaaddggj|j .
- // ---------------+ - - - - - - - -+ <- old pile edge
+ // ---------------+ - - - - - - - -+ <- min pile edge
// .
- // - - - - - - - - - - - - - - - -+ <- new pile edge
+ // - - - - - - - - - - - - - - - -+ <- max pile edge
//
// If you were to slide a vertical beam from the left edge of the
- // old edge rect toward the right, it would either hit the right edge
- // of the old edge rect, or the interest rect (expanded to the bounds
+ // delta edge rect toward the right, it would either hit the right edge
+ // of the delta edge rect, or the interest rect (expanded to the bounds
// of the tiles it touches). The same is true for a beam parallel to
- // any of the four edges, sliding accross the old edge rect. We use
+ // any of the four edges, sliding across the delta edge rect. We use
// the union of these four rectangles generated by these beams to
- // determine which part of the old edge rect is outside of the expanded
+ // determine which part of the delta edge rect is outside of the expanded
// interest rect.
//
- // Case 1: Intersect rect is outside the old edge rect. It can be
+ // Case 1: Intersect rect is outside the delta edge rect. It can be
// either on the left or the right. The |left_rect| and |right_rect|,
// cover this case, one will be empty and one will cover the full
- // old edge rect. In the picture below, |left_rect| would cover the
- // old edge rect, and |right_rect| would be empty.
+ // delta edge rect. In the picture below, |left_rect| would cover the
+ // delta edge rect, and |right_rect| would be empty.
// +----------------------+ |^^^^^^^^^^^^^^^|
- // |===> OLD EDGE RECT | | |
+ // |===> DELTA EDGE RECT | | |
// |===> | | INTEREST RECT |
// |===> | | |
// |===> | | |
// +----------------------+ |vvvvvvvvvvvvvvv|
//
- // Case 2: Interest rect is inside the old edge rect. It will always
- // fill the entire old edge rect horizontally since the old edge rect
+ // Case 2: Interest rect is inside the delta edge rect. It will always
+ // fill the entire delta edge rect horizontally since the old edge rect
// is a single tile wide, and the interest rect has been expanded to the
// bounds of the tiles it touches. In this case the |left_rect| and
// |right_rect| will be empty, but the case is handled by the |top_rect|
@@ -285,19 +326,19 @@ bool PicturePile::UpdateAndExpandInvalidation(
// | |
// +-----------------+
// | |
- // | OLD EDGE RECT |
+ // | DELTA EDGE RECT |
// +-----------------+
//
// Lastly, we need to consider tiles inside the expanded interest rect.
// For those tiles, we want to invalidate exactly the newly exposed
- // pixels. In the picture below the tiles in the old edge rect have been
- // resized and the area covered by periods must be invalidated. The
+ // pixels. In the picture below the tiles in the delta edge rect have
+ // been resized and the area covered by periods must be invalidated. The
// |exposed_rect| will cover exactly that area.
- // v-old pile edge
+ // v-min pile edge
// +---------+-------+
// | ........|
// | ........|
- // | OLD EDGE.RECT..|
+ // | DELTA EDGE.RECT.|
// | ........|
// | ........|
// | ........|
@@ -308,18 +349,18 @@ bool PicturePile::UpdateAndExpandInvalidation(
int left = tiling_.TilePositionX(min_toss_x);
int right = left + tiling_.TileSizeX(min_toss_x);
- int top = old_tiling_rect_over_tiles.y();
- int bottom = old_tiling_rect_over_tiles.bottom();
+ int top = min_tiling_rect_over_tiles.y();
+ int bottom = min_tiling_rect_over_tiles.bottom();
int left_until = std::min(interest_rect_over_tiles.x(), right);
int right_until = std::max(interest_rect_over_tiles.right(), left);
int top_until = std::min(interest_rect_over_tiles.y(), bottom);
int bottom_until = std::max(interest_rect_over_tiles.bottom(), top);
- int exposed_left = old_tiling_size.width();
- int exposed_left_until = tiling_size().width();
+ int exposed_left = min_tiling_size.width();
+ int exposed_left_until = max_tiling_size.width();
int exposed_top = top;
- int exposed_bottom = tiling_size().height();
+ int exposed_bottom = max_tiling_size.height();
DCHECK_GE(exposed_left, left);
gfx::Rect left_rect(left, top, left_until - left, bottom - top);
@@ -339,23 +380,23 @@ bool PicturePile::UpdateAndExpandInvalidation(
}
if (min_toss_y < tiling_.num_tiles_y()) {
// The same thing occurs here as in the case above, but the invalidation
- // rect is the bounding box around the bottom row of tiles in the old
+ // rect is the bounding box around the bottom row of tiles in the min
// pile. This would be tiles {o,r,u,x,a,d,g,j} in the above picture.
int top = tiling_.TilePositionY(min_toss_y);
int bottom = top + tiling_.TileSizeY(min_toss_y);
- int left = old_tiling_rect_over_tiles.x();
- int right = old_tiling_rect_over_tiles.right();
+ int left = min_tiling_rect_over_tiles.x();
+ int right = min_tiling_rect_over_tiles.right();
int top_until = std::min(interest_rect_over_tiles.y(), bottom);
int bottom_until = std::max(interest_rect_over_tiles.bottom(), top);
int left_until = std::min(interest_rect_over_tiles.x(), right);
int right_until = std::max(interest_rect_over_tiles.right(), left);
- int exposed_top = old_tiling_size.height();
- int exposed_top_until = tiling_size().height();
+ int exposed_top = min_tiling_size.height();
+ int exposed_top_until = max_tiling_size.height();
int exposed_left = left;
- int exposed_right = tiling_size().width();
+ int exposed_right = max_tiling_size.width();
DCHECK_GE(exposed_top, top);
gfx::Rect left_rect(left, top, left_until - left, bottom - top);
@@ -378,7 +419,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
// Detect cases where the full pile is invalidated, in this situation we
// can just drop/invalidate everything.
if (invalidation->Contains(gfx::Rect(old_tiling_size)) ||
- invalidation->Contains(gfx::Rect(tiling_size()))) {
+ invalidation->Contains(gfx::Rect(GetSize()))) {
for (auto& it : picture_map_)
updated = it.second.Invalidate(frame_number) || updated;
} else {
@@ -489,9 +530,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
bool gather_pixel_refs = RasterWorkerPool::GetNumRasterThreads() > 1;
{
- base::TimeDelta best_duration = base::TimeDelta::Max();
for (int i = 0; i < repeat_count; i++) {
- base::TimeTicks start_time = stats_instrumentation->StartRecording();
picture = Picture::Create(record_rect,
painter,
tile_grid_info_,
@@ -505,13 +544,7 @@ bool PicturePile::UpdateAndExpandInvalidation(
// the pile after each invalidation.
is_suitable_for_gpu_rasterization_ &=
picture->IsSuitableForGpuRasterization();
- base::TimeDelta duration =
- stats_instrumentation->EndRecording(start_time);
- best_duration = std::min(duration, best_duration);
}
- int recorded_pixel_count =
- picture->LayerRect().width() * picture->LayerRect().height();
- stats_instrumentation->AddRecord(best_duration, recorded_pixel_count);
}
bool found_tile_for_recorded_picture = false;
@@ -536,11 +569,93 @@ bool PicturePile::UpdateAndExpandInvalidation(
return true;
}
+gfx::Size PicturePile::GetSize() const {
+ return tiling_.tiling_size();
+}
+
void PicturePile::SetEmptyBounds() {
tiling_.SetTilingSize(gfx::Size());
Clear();
}
+void PicturePile::SetMinContentsScale(float min_contents_scale) {
+ DCHECK(min_contents_scale);
+ if (min_contents_scale_ == min_contents_scale)
+ return;
+
+ // Picture contents are played back scaled. When the final contents scale is
+ // less than 1 (i.e. low res), then multiple recorded pixels will be used
+ // to raster one final pixel. To avoid splitting a final pixel across
+ // pictures (which would result in incorrect rasterization due to blending), a
+ // buffer margin is added so that any picture can be snapped to integral
+ // final pixels.
+ //
+ // For example, if a 1/4 contents scale is used, then that would be 3 buffer
+ // pixels, since that's the minimum number of pixels to add so that resulting
+ // content can be snapped to a four pixel aligned grid.
+ int buffer_pixels = static_cast<int>(ceil(1 / min_contents_scale) - 1);
+ buffer_pixels = std::max(0, buffer_pixels);
+ SetBufferPixels(buffer_pixels);
+ min_contents_scale_ = min_contents_scale;
+}
+
+// static
+void PicturePile::ComputeTileGridInfo(const gfx::Size& tile_grid_size,
+ SkTileGridFactory::TileGridInfo* info) {
+ DCHECK(info);
+ info->fTileInterval.set(tile_grid_size.width() - 2 * kTileGridBorderPixels,
+ tile_grid_size.height() - 2 * kTileGridBorderPixels);
+ DCHECK_GT(info->fTileInterval.width(), 0);
+ DCHECK_GT(info->fTileInterval.height(), 0);
+ info->fMargin.set(kTileGridBorderPixels, kTileGridBorderPixels);
+ // Offset the tile grid coordinate space to take into account the fact
+ // that the top-most and left-most tiles do not have top and left borders
+ // respectively.
+ info->fOffset.set(-kTileGridBorderPixels, -kTileGridBorderPixels);
+}
+
+void PicturePile::SetTileGridSize(const gfx::Size& tile_grid_size) {
+ ComputeTileGridInfo(tile_grid_size, &tile_grid_info_);
+}
+
+void PicturePile::SetSlowdownRasterScaleFactor(int factor) {
+ slow_down_raster_scale_factor_for_debug_ = factor;
+}
+
+void PicturePile::SetIsMask(bool is_mask) {
+ is_mask_ = is_mask;
+}
+
+void PicturePile::SetUnsuitableForGpuRasterizationForTesting() {
+ is_suitable_for_gpu_rasterization_ = false;
+}
+
+bool PicturePile::IsSuitableForGpuRasterization() const {
+ return is_suitable_for_gpu_rasterization_;
+}
+
+scoped_refptr<RasterSource> PicturePile::CreateRasterSource() const {
+ return scoped_refptr<RasterSource>(
+ PicturePileImpl::CreateFromPicturePile(this));
+}
+
+SkTileGridFactory::TileGridInfo PicturePile::GetTileGridInfoForTesting() const {
+ return tile_grid_info_;
+}
+
+bool PicturePile::CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const {
+ bool include_borders = false;
+ for (TilingData::Iterator tile_iter(&tiling_, layer_rect, include_borders);
+ tile_iter; ++tile_iter) {
+ PictureMap::const_iterator map_iter = picture_map_.find(tile_iter.index());
+ if (map_iter == picture_map_.end())
+ return false;
+ if (!map_iter->second.GetPicture())
+ return false;
+ }
+ return true;
+}
+
void PicturePile::DetermineIfSolidColor() {
is_solid_color_ = false;
solid_color_ = SK_ColorTRANSPARENT;
@@ -573,4 +688,81 @@ void PicturePile::DetermineIfSolidColor() {
is_solid_color_ = canvas.GetColorIfSolid(&solid_color_);
}
+gfx::Rect PicturePile::PaddedRect(const PictureMapKey& key) const {
+ gfx::Rect tile = tiling_.TileBounds(key.first, key.second);
+ return PadRect(tile);
+}
+
+gfx::Rect PicturePile::PadRect(const gfx::Rect& rect) const {
+ gfx::Rect padded_rect = rect;
+ padded_rect.Inset(-buffer_pixels(), -buffer_pixels(), -buffer_pixels(),
+ -buffer_pixels());
+ return padded_rect;
+}
+
+void PicturePile::Clear() {
+ picture_map_.clear();
+ recorded_viewport_ = gfx::Rect();
+ has_any_recordings_ = false;
+ is_solid_color_ = false;
+}
+
+PicturePile::PictureInfo::PictureInfo() : last_frame_number_(0) {
+}
+
+PicturePile::PictureInfo::~PictureInfo() {
+}
+
+void PicturePile::PictureInfo::AdvanceInvalidationHistory(int frame_number) {
+ DCHECK_GE(frame_number, last_frame_number_);
+ if (frame_number == last_frame_number_)
+ return;
+
+ invalidation_history_ <<= (frame_number - last_frame_number_);
+ last_frame_number_ = frame_number;
+}
+
+bool PicturePile::PictureInfo::Invalidate(int frame_number) {
+ AdvanceInvalidationHistory(frame_number);
+ invalidation_history_.set(0);
+
+ bool did_invalidate = !!picture_.get();
+ picture_ = NULL;
+ return did_invalidate;
+}
+
+bool PicturePile::PictureInfo::NeedsRecording(int frame_number,
+ int distance_to_visible) {
+ AdvanceInvalidationHistory(frame_number);
+
+ // We only need recording if we don't have a picture. Furthermore, we only
+ // need a recording if we're within frequent invalidation distance threshold
+ // or the invalidation is not frequent enough (below invalidation frequency
+ // threshold).
+ return !picture_.get() &&
+ ((distance_to_visible <= kFrequentInvalidationDistanceThreshold) ||
+ (GetInvalidationFrequency() < kInvalidationFrequencyThreshold));
+}
+
+void PicturePile::SetBufferPixels(int new_buffer_pixels) {
+ if (new_buffer_pixels == buffer_pixels())
+ return;
+
+ Clear();
+ tiling_.SetBorderTexels(new_buffer_pixels);
+}
+
+void PicturePile::PictureInfo::SetPicture(scoped_refptr<Picture> picture) {
+ picture_ = picture;
+}
+
+const Picture* PicturePile::PictureInfo::GetPicture() const {
+ return picture_.get();
+}
+
+float PicturePile::PictureInfo::GetInvalidationFrequency() const {
+ return invalidation_history_.count() /
+ static_cast<float>(INVALIDATION_FRAMES_TRACKED);
+}
+
} // namespace cc
« no previous file with comments | « cc/resources/picture_pile.h ('k') | cc/resources/picture_pile_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698