diff options
author | fmalita <fmalita@chromium.org> | 2015-09-09 12:47:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-09 19:48:22 +0000 |
commit | 7913ee5c052986141a1947428abf7a37cc053026 (patch) | |
tree | 2ae967558989303132151e55c59f70fcfcdb1523 /cc | |
parent | 84fec63dbc6667f4c1e03eed4b6f11b4c9865a40 (diff) | |
download | chromium_src-7913ee5c052986141a1947428abf7a37cc053026.zip chromium_src-7913ee5c052986141a1947428abf7a37cc053026.tar.gz chromium_src-7913ee5c052986141a1947428abf7a37cc053026.tar.bz2 |
Convert pixel_ref_map -> discardable_image_map
As blink now only creates discardable images (not discardable
bitmaps/pixelrefs, we need to track the images.
(based on reed's http://crrev.com/1318323003)
BUG=527246
R=reed@google.com,vmpstr@chromium.org
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel
Review URL: https://codereview.chromium.org/1314353005
Cr-Commit-Position: refs/heads/master@{#347985}
Diffstat (limited to 'cc')
39 files changed, 768 insertions, 675 deletions
diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 004a1b8..1f9fe77 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -290,6 +290,8 @@ component("cc") { "playback/clip_path_display_item.h", "playback/compositing_display_item.cc", "playback/compositing_display_item.h", + "playback/discardable_image_map.cc", + "playback/discardable_image_map.h", "playback/display_item.cc", "playback/display_item.h", "playback/display_item_list.cc", @@ -314,8 +316,6 @@ component("cc") { "playback/picture_pile.h", "playback/picture_pile_impl.cc", "playback/picture_pile_impl.h", - "playback/pixel_ref_map.cc", - "playback/pixel_ref_map.h", "playback/raster_source.h", "playback/raster_source_helper.cc", "playback/raster_source_helper.h", @@ -783,13 +783,13 @@ test("cc_unittests") { "output/shader_unittest.cc", "output/software_renderer_unittest.cc", "output/texture_mailbox_deleter_unittest.cc", + "playback/discardable_image_map_unittest.cc", "playback/display_item_list_unittest.cc", "playback/display_list_raster_source_unittest.cc", "playback/display_list_recording_source_unittest.cc", "playback/picture_pile_impl_unittest.cc", "playback/picture_pile_unittest.cc", "playback/picture_unittest.cc", - "playback/pixel_ref_map_unittest.cc", "playback/recording_source_unittest.cc", "quads/draw_polygon_unittest.cc", "quads/draw_quad_unittest.cc", @@ -347,6 +347,8 @@ 'playback/clip_path_display_item.h', 'playback/compositing_display_item.cc', 'playback/compositing_display_item.h', + 'playback/discardable_image_map.cc', + 'playback/discardable_image_map.h', 'playback/display_item.cc', 'playback/display_item.h', 'playback/display_item_list.cc', @@ -371,8 +373,6 @@ 'playback/picture_pile.h', 'playback/picture_pile_impl.cc', 'playback/picture_pile_impl.h', - 'playback/pixel_ref_map.cc', - 'playback/pixel_ref_map.h', 'playback/raster_source.h', 'playback/raster_source_helper.cc', 'playback/raster_source_helper.h', diff --git a/cc/cc_tests.gyp b/cc/cc_tests.gyp index 534e5e6..c824da0 100644 --- a/cc/cc_tests.gyp +++ b/cc/cc_tests.gyp @@ -79,13 +79,13 @@ 'output/shader_unittest.cc', 'output/software_renderer_unittest.cc', 'output/texture_mailbox_deleter_unittest.cc', + 'playback/discardable_image_map_unittest.cc', 'playback/display_item_list_unittest.cc', 'playback/display_list_raster_source_unittest.cc', 'playback/display_list_recording_source_unittest.cc', 'playback/picture_pile_impl_unittest.cc', 'playback/picture_pile_unittest.cc', 'playback/picture_unittest.cc', - 'playback/pixel_ref_map_unittest.cc', 'playback/recording_source_unittest.cc', 'quads/draw_polygon_unittest.cc', 'quads/draw_quad_unittest.cc', diff --git a/cc/debug/devtools_instrumentation.h b/cc/debug/devtools_instrumentation.h index 8f03f8c..3a28579 100644 --- a/cc/debug/devtools_instrumentation.h +++ b/cc/debug/devtools_instrumentation.h @@ -52,9 +52,10 @@ class ScopedLayerTask { class ScopedImageDecodeTask { public: - explicit ScopedImageDecodeTask(void* pixelRef) { + explicit ScopedImageDecodeTask(const void* imagePtr) { TRACE_EVENT_BEGIN1(internal::kCategory, internal::kImageDecodeTask, - internal::kPixelRefId, reinterpret_cast<uint64>(pixelRef)); + internal::kPixelRefId, + reinterpret_cast<uint64>(imagePtr)); } ~ScopedImageDecodeTask() { TRACE_EVENT_END0(internal::kCategory, internal::kImageDecodeTask); diff --git a/cc/layers/picture_layer.cc b/cc/layers/picture_layer.cc index 53d5d97..9590f11 100644 --- a/cc/layers/picture_layer.cc +++ b/cc/layers/picture_layer.cc @@ -101,7 +101,7 @@ void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { } recording_source_->SetSlowdownRasterScaleFactor( host->debug_state().slow_down_raster_scale_factor); - recording_source_->SetGatherPixelRefs(settings.gather_pixel_refs); + recording_source_->SetGatherDiscardableImages(settings.gather_images); } void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { diff --git a/cc/playback/pixel_ref_map.cc b/cc/playback/discardable_image_map.cc index 5abd00b..e115277 100644 --- a/cc/playback/pixel_ref_map.cc +++ b/cc/playback/discardable_image_map.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/playback/pixel_ref_map.h" +#include "cc/playback/discardable_image_map.h" #include <algorithm> #include <limits> @@ -10,20 +10,20 @@ #include "cc/base/math_util.h" #include "cc/playback/display_item_list.h" #include "cc/playback/picture.h" -#include "skia/ext/pixel_ref_utils.h" +#include "skia/ext/discardable_image_utils.h" #include "ui/gfx/geometry/rect_conversions.h" namespace cc { -PixelRefMap::PixelRefMap(const gfx::Size& cell_size) : cell_size_(cell_size) { +DiscardableImageMap::DiscardableImageMap(const gfx::Size& cell_size) + : cell_size_(cell_size) { DCHECK(!cell_size.IsEmpty()); } -PixelRefMap::~PixelRefMap() { -} +DiscardableImageMap::~DiscardableImageMap() {} -void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture, - const gfx::Rect& layer_rect) { +void DiscardableImageMap::GatherImagesFromPicture(SkPicture* picture, + const gfx::Rect& layer_rect) { DCHECK(picture); int min_x = std::numeric_limits<int>::max(); @@ -31,17 +31,17 @@ void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture, int max_x = 0; int max_y = 0; - skia::DiscardablePixelRefList pixel_refs; - skia::PixelRefUtils::GatherDiscardablePixelRefs(picture, &pixel_refs); - for (skia::DiscardablePixelRefList::const_iterator it = pixel_refs.begin(); - it != pixel_refs.end(); ++it) { + skia::DiscardableImageList images; + skia::DiscardableImageUtils::GatherDiscardableImages(picture, &images); + for (skia::DiscardableImageList::const_iterator it = images.begin(); + it != images.end(); ++it) { // The image rect is in space relative to the picture, but it can extend far // beyond the picture itself (since it represents the rect of actual image // contained within the picture, not clipped to picture bounds). We only // care about image queries that intersect the picture, so insert only into // the intersection of the two rects. gfx::Rect rect_clipped_to_picture = gfx::IntersectRects( - gfx::ToEnclosingRect(gfx::SkRectToRectF(it->pixel_ref_rect)), + gfx::ToEnclosingRect(gfx::SkRectToRectF(it->image_rect)), gfx::Rect(layer_rect.size())); gfx::Point min(MathUtil::UncheckedRoundDown(rect_clipped_to_picture.x(), @@ -59,17 +59,13 @@ void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture, // information. However, since picture pile / display list also returns this // information, it would be nice to express it relative to the layer, not // relative to the particular implementation of the raster source. - skia::PositionPixelRef position_pixel_ref = *it; - position_pixel_ref.pixel_ref_rect.setXYWH( - position_pixel_ref.pixel_ref_rect.x() + layer_rect.x(), - position_pixel_ref.pixel_ref_rect.y() + layer_rect.y(), - position_pixel_ref.pixel_ref_rect.width(), - position_pixel_ref.pixel_ref_rect.height()); + skia::PositionImage position_image = *it; + position_image.image_rect.offset(layer_rect.x(), layer_rect.y()); for (int y = min.y(); y <= max.y(); y += cell_size_.height()) { for (int x = min.x(); x <= max.x(); x += cell_size_.width()) { - PixelRefMapKey key(x, y); - data_hash_map_[key].push_back(position_pixel_ref); + ImageMapKey key(x, y); + data_hash_map_[key].push_back(position_image); } } @@ -83,47 +79,46 @@ void PixelRefMap::GatherPixelRefsFromPicture(SkPicture* picture, max_pixel_cell_ = gfx::Point(max_x, max_y); } -base::LazyInstance<PixelRefs> PixelRefMap::Iterator::empty_pixel_refs_; +base::LazyInstance<Images> DiscardableImageMap::Iterator::empty_images_; -PixelRefMap::Iterator::Iterator() - : target_pixel_ref_map_(NULL), - current_pixel_refs_(empty_pixel_refs_.Pointer()), +DiscardableImageMap::Iterator::Iterator() + : target_image_map_(NULL), + current_images_(empty_images_.Pointer()), current_index_(0), min_point_(-1, -1), max_point_(-1, -1), current_x_(0), - current_y_(0) { -} + current_y_(0) {} -PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, const Picture* picture) - : target_pixel_ref_map_(&(picture->pixel_refs_)), - current_pixel_refs_(empty_pixel_refs_.Pointer()), +DiscardableImageMap::Iterator::Iterator(const gfx::Rect& rect, + const Picture* picture) + : target_image_map_(&(picture->images_)), + current_images_(empty_images_.Pointer()), current_index_(0) { map_layer_rect_ = picture->layer_rect_; - PointToFirstPixelRef(rect); + PointToFirstImage(rect); } -PixelRefMap::Iterator::Iterator(const gfx::Rect& rect, - const DisplayItemList* display_list) - : target_pixel_ref_map_(display_list->pixel_refs_.get()), - current_pixel_refs_(empty_pixel_refs_.Pointer()), +DiscardableImageMap::Iterator::Iterator(const gfx::Rect& rect, + const DisplayItemList* display_list) + : target_image_map_(display_list->images_.get()), + current_images_(empty_images_.Pointer()), current_index_(0) { map_layer_rect_ = display_list->layer_rect_; - PointToFirstPixelRef(rect); + PointToFirstImage(rect); } -PixelRefMap::Iterator::~Iterator() { -} +DiscardableImageMap::Iterator::~Iterator() {} -PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() { +DiscardableImageMap::Iterator& DiscardableImageMap::Iterator::operator++() { ++current_index_; // If we're not at the end of the list, then we have the next item. - if (current_index_ < current_pixel_refs_->size()) + if (current_index_ < current_images_->size()) return *this; DCHECK(current_y_ <= max_point_.y()); while (true) { - gfx::Size cell_size = target_pixel_ref_map_->cell_size_; + gfx::Size cell_size = target_image_map_->cell_size_; // Advance the current grid cell. current_x_ += cell_size.width(); @@ -131,31 +126,31 @@ PixelRefMap::Iterator& PixelRefMap::Iterator::operator++() { current_y_ += cell_size.height(); current_x_ = min_point_.x(); if (current_y_ > max_point_.y()) { - current_pixel_refs_ = empty_pixel_refs_.Pointer(); + current_images_ = empty_images_.Pointer(); current_index_ = 0; break; } } // If there are no pixel refs at this grid cell, keep incrementing. - PixelRefMapKey key(current_x_, current_y_); - PixelRefHashmap::const_iterator iter = - target_pixel_ref_map_->data_hash_map_.find(key); - if (iter == target_pixel_ref_map_->data_hash_map_.end()) + ImageMapKey key(current_x_, current_y_); + ImageHashmap::const_iterator iter = + target_image_map_->data_hash_map_.find(key); + if (iter == target_image_map_->data_hash_map_.end()) continue; // We found a non-empty list: store it and get the first pixel ref. - current_pixel_refs_ = &iter->second; + current_images_ = &iter->second; current_index_ = 0; break; } return *this; } -void PixelRefMap::Iterator::PointToFirstPixelRef(const gfx::Rect& rect) { +void DiscardableImageMap::Iterator::PointToFirstImage(const gfx::Rect& rect) { gfx::Rect query_rect(rect); // Early out if the query rect doesn't intersect this picture. - if (!query_rect.Intersects(map_layer_rect_) || !target_pixel_ref_map_) { + if (!query_rect.Intersects(map_layer_rect_) || !target_image_map_) { min_point_ = gfx::Point(0, 0); max_point_ = gfx::Point(0, 0); current_x_ = 1; @@ -166,8 +161,8 @@ void PixelRefMap::Iterator::PointToFirstPixelRef(const gfx::Rect& rect) { // First, subtract the layer origin as cells are stored in layer space. query_rect.Offset(-map_layer_rect_.OffsetFromOrigin()); - DCHECK(!target_pixel_ref_map_->cell_size_.IsEmpty()); - gfx::Size cell_size(target_pixel_ref_map_->cell_size_); + DCHECK(!target_image_map_->cell_size_.IsEmpty()); + gfx::Size cell_size(target_image_map_->cell_size_); // We have to find a cell_size aligned point that corresponds to // query_rect. Point is a multiple of cell_size. min_point_ = gfx::Point( @@ -180,11 +175,11 @@ void PixelRefMap::Iterator::PointToFirstPixelRef(const gfx::Rect& rect) { // Limit the points to known pixel ref boundaries. min_point_ = gfx::Point( - std::max(min_point_.x(), target_pixel_ref_map_->min_pixel_cell_.x()), - std::max(min_point_.y(), target_pixel_ref_map_->min_pixel_cell_.y())); + std::max(min_point_.x(), target_image_map_->min_pixel_cell_.x()), + std::max(min_point_.y(), target_image_map_->min_pixel_cell_.y())); max_point_ = gfx::Point( - std::min(max_point_.x(), target_pixel_ref_map_->max_pixel_cell_.x()), - std::min(max_point_.y(), target_pixel_ref_map_->max_pixel_cell_.y())); + std::min(max_point_.x(), target_image_map_->max_pixel_cell_.x()), + std::min(max_point_.y(), target_image_map_->max_pixel_cell_.y())); // Make the current x be cell_size.width() less than min point, so that // the first increment will point at min_point_. diff --git a/cc/playback/discardable_image_map.h b/cc/playback/discardable_image_map.h new file mode 100644 index 0000000..68b8ac1 --- /dev/null +++ b/cc/playback/discardable_image_map.h @@ -0,0 +1,94 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ +#define CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ + +#include <utility> +#include <vector> + +#include "base/containers/hash_tables.h" +#include "base/lazy_instance.h" +#include "base/memory/ref_counted.h" +#include "cc/base/cc_export.h" +#include "skia/ext/discardable_image_utils.h" +#include "third_party/skia/include/core/SkPicture.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" + +class SkImage; + +namespace cc { + +class Picture; +class DisplayItemList; + +typedef std::pair<int, int> ImageMapKey; +typedef std::vector<skia::PositionImage> Images; +typedef base::hash_map<ImageMapKey, Images> ImageHashmap; + +// This class is used and owned by cc Picture class. It is used to gather images +// which would happen after record. It takes in |cell_size| to decide how +// big each grid cell should be. +class CC_EXPORT DiscardableImageMap { + public: + explicit DiscardableImageMap(const gfx::Size& cell_size); + ~DiscardableImageMap(); + + void GatherImagesFromPicture(SkPicture* picture, const gfx::Rect& layer_rect); + + bool empty() const { return data_hash_map_.empty(); } + + // This iterator imprecisely returns the set of images that are needed to + // raster this layer rect from this picture. Internally, images are + // clumped into tile grid buckets, so there may be false positives. + class CC_EXPORT Iterator { + public: + // Default iterator constructor that is used as place holder for invalid + // Iterator. + Iterator(); + Iterator(const gfx::Rect& layer_rect, const Picture* picture); + Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture); + ~Iterator(); + + const skia::PositionImage* operator->() const { + DCHECK_LT(current_index_, current_images_->size()); + return &(*current_images_)[current_index_]; + } + + const skia::PositionImage& operator*() const { + DCHECK_LT(current_index_, current_images_->size()); + return (*current_images_)[current_index_]; + } + + Iterator& operator++(); + operator bool() const { return current_index_ < current_images_->size(); } + + private: + void PointToFirstImage(const gfx::Rect& query_rect); + + static base::LazyInstance<Images> empty_images_; + const DiscardableImageMap* target_image_map_; + const Images* current_images_; + unsigned current_index_; + + gfx::Rect map_layer_rect_; + + gfx::Point min_point_; + gfx::Point max_point_; + int current_x_; + int current_y_; + }; + + private: + gfx::Point min_pixel_cell_; + gfx::Point max_pixel_cell_; + gfx::Size cell_size_; + + ImageHashmap data_hash_map_; +}; + +} // namespace cc + +#endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_ diff --git a/cc/playback/pixel_ref_map_unittest.cc b/cc/playback/discardable_image_map_unittest.cc index 25ede2d..70061ea 100644 --- a/cc/playback/pixel_ref_map_unittest.cc +++ b/cc/playback/discardable_image_map_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "cc/playback/pixel_ref_map.h" +#include "cc/playback/discardable_image_map.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" @@ -12,13 +12,27 @@ #include "cc/test/skia_common.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/skia/include/core/SkGraphics.h" +#include "third_party/skia/include/core/SkImageGenerator.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/skia_util.h" namespace cc { namespace { -TEST(PixelRefMapTest, PixelRefMapIterator) { +class TestImageGenerator : public SkImageGenerator { + public: + explicit TestImageGenerator(const SkImageInfo& info) + : SkImageGenerator(info) {} +}; + +skia::RefPtr<SkImage> CreateDiscardableImage(const gfx::Size& size) { + const SkImageInfo info = + SkImageInfo::MakeN32Premul(size.width(), size.height()); + return skia::AdoptRef( + SkImage::NewFromGenerator(new TestImageGenerator(info))); +} + +TEST(DiscardableImageMapTest, DiscardableImageMapIterator) { gfx::Rect layer_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); @@ -35,14 +49,14 @@ TEST(PixelRefMapTest, PixelRefMapIterator) { // |---|---|---|---| // | x | | x | | // |---|---|---|---| - SkBitmap discardable_bitmap[4][4]; + skia::RefPtr<SkImage> discardable_image[4][4]; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { if ((x + y) & 1) { - CreateDiscardableBitmap(gfx::Size(500, 500), &discardable_bitmap[y][x]); + discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); SkPaint paint; - content_layer_client.add_draw_bitmap( - discardable_bitmap[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), + content_layer_client.add_draw_image( + discardable_image[y][x].get(), gfx::Point(x * 512 + 6, y * 512 + 6), paint); } } @@ -54,92 +68,93 @@ TEST(PixelRefMapTest, PixelRefMapIterator) { // Default iterator does not have any pixel refs. { - PixelRefMap::Iterator iterator; + DiscardableImageMap::Iterator iterator; EXPECT_FALSE(iterator); } for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { - PixelRefMap::Iterator iterator(gfx::Rect(x * 512, y * 512, 500, 500), - picture.get()); + DiscardableImageMap::Iterator iterator( + gfx::Rect(x * 512, y * 512, 500, 500), picture.get()); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[y][x].pixelRef()) + EXPECT_TRUE(iterator->image == discardable_image[y][x].get()) << x << " " << y; EXPECT_EQ(gfx::RectF(x * 512 + 6, y * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator) << x << " " << y; } else { EXPECT_FALSE(iterator) << x << " " << y; } } } + // Capture 4 pixel refs. { - PixelRefMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), - picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), + picture.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } { // Copy test. - PixelRefMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), - picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048), + picture.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); // copy now points to the same spot as iterator, // but both can be incremented independently. - PixelRefMap::Iterator copy = iterator; + DiscardableImageMap::Iterator copy = iterator; EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); EXPECT_TRUE(copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_TRUE(++copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_TRUE(++copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_FALSE(++copy); } } -TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) { +TEST(DiscardableImageMapTest, DiscardableImageMapIteratorNonZeroLayer) { gfx::Rect layer_rect(1024, 0, 2048, 2048); gfx::Size tile_grid_size(512, 512); @@ -156,14 +171,14 @@ TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) { // |---|---|---|---| // | x | | x | | // |---|---|---|---| - SkBitmap discardable_bitmap[4][4]; + skia::RefPtr<SkImage> discardable_image[4][4]; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { if ((x + y) & 1) { - CreateDiscardableBitmap(gfx::Size(500, 500), &discardable_bitmap[y][x]); + discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); SkPaint paint; - content_layer_client.add_draw_bitmap( - discardable_bitmap[y][x], + content_layer_client.add_draw_image( + discardable_image[y][x].get(), gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); } } @@ -175,20 +190,20 @@ TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) { // Default iterator does not have any pixel refs. { - PixelRefMap::Iterator iterator; + DiscardableImageMap::Iterator iterator; EXPECT_FALSE(iterator); } for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { - PixelRefMap::Iterator iterator( + DiscardableImageMap::Iterator iterator( gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get()); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[y][x].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[y][x].get()); EXPECT_EQ( gfx::RectF(1024 + x * 512 + 6, y * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator) << x << " " << y; } else { EXPECT_FALSE(iterator) << x << " " << y; @@ -197,91 +212,92 @@ TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) { } // Capture 4 pixel refs. { - PixelRefMap::Iterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048), - picture.get()); + DiscardableImageMap::Iterator iterator( + gfx::Rect(1024 + 512, 512, 2048, 2048), picture.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(1024 + 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } // Copy test. { - PixelRefMap::Iterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048), - picture.get()); + DiscardableImageMap::Iterator iterator( + gfx::Rect(1024 + 512, 512, 2048, 2048), picture.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(1024 + 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); // copy now points to the same spot as iterator, // but both can be incremented independently. - PixelRefMap::Iterator copy = iterator; + DiscardableImageMap::Iterator copy = iterator; EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); EXPECT_TRUE(copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[2][1].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[2][1].get()); EXPECT_EQ(gfx::RectF(1024 + 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_TRUE(++copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[2][3].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[2][3].get()); EXPECT_EQ(gfx::RectF(1024 + 3 * 512 + 6, 2 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_TRUE(++copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[3][2].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[3][2].get()); EXPECT_EQ(gfx::RectF(1024 + 2 * 512 + 6, 3 * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_FALSE(++copy); } // Non intersecting rects { - PixelRefMap::Iterator iterator(gfx::Rect(0, 0, 1000, 1000), picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(0, 0, 1000, 1000), + picture.get()); EXPECT_FALSE(iterator); } { - PixelRefMap::Iterator iterator(gfx::Rect(3500, 0, 1000, 1000), - picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(3500, 0, 1000, 1000), + picture.get()); EXPECT_FALSE(iterator); } { - PixelRefMap::Iterator iterator(gfx::Rect(0, 1100, 1000, 1000), - picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(0, 1100, 1000, 1000), + picture.get()); EXPECT_FALSE(iterator); } { - PixelRefMap::Iterator iterator(gfx::Rect(3500, 1100, 1000, 1000), - picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(3500, 1100, 1000, 1000), + picture.get()); EXPECT_FALSE(iterator); } } -TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) { +TEST(DiscardableImageMapTest, DiscardableImageMapIteratorOnePixelQuery) { gfx::Rect layer_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); @@ -298,14 +314,14 @@ TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) { // |---|---|---|---| // | x | | x | | // |---|---|---|---| - SkBitmap discardable_bitmap[4][4]; + skia::RefPtr<SkImage> discardable_image[4][4]; for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { if ((x + y) & 1) { - CreateDiscardableBitmap(gfx::Size(500, 500), &discardable_bitmap[y][x]); + discardable_image[y][x] = CreateDiscardableImage(gfx::Size(500, 500)); SkPaint paint; - content_layer_client.add_draw_bitmap( - discardable_bitmap[y][x], gfx::Point(x * 512 + 6, y * 512 + 6), + content_layer_client.add_draw_image( + discardable_image[y][x].get(), gfx::Point(x * 512 + 6, y * 512 + 6), paint); } } @@ -317,19 +333,19 @@ TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) { // Default iterator does not have any pixel refs. { - PixelRefMap::Iterator iterator; + DiscardableImageMap::Iterator iterator; EXPECT_FALSE(iterator); } for (int y = 0; y < 4; ++y) { for (int x = 0; x < 4; ++x) { - PixelRefMap::Iterator iterator(gfx::Rect(x * 512, y * 512 + 256, 1, 1), - picture.get()); + DiscardableImageMap::Iterator iterator( + gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); if ((x + y) & 1) { EXPECT_TRUE(iterator) << x << " " << y; - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[y][x].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[y][x].get()); EXPECT_EQ(gfx::RectF(x * 512 + 6, y * 512 + 6, 500, 500).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator) << x << " " << y; } else { EXPECT_FALSE(iterator) << x << " " << y; @@ -338,26 +354,26 @@ TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) { } } -TEST(PixelRefMapTest, PixelRefMapIteratorMassiveImage) { +TEST(DiscardableImageMapTest, DiscardableImageMapIteratorMassiveImage) { gfx::Rect layer_rect(2048, 2048); gfx::Size tile_grid_size(512, 512); FakeContentLayerClient content_layer_client; - SkBitmap discardable_bitmap; - CreateDiscardableBitmap(gfx::Size(1 << 25, 1 << 25), &discardable_bitmap); + skia::RefPtr<SkImage> discardable_image; + discardable_image = CreateDiscardableImage(gfx::Size(1 << 25, 1 << 25)); SkPaint paint; - content_layer_client.add_draw_bitmap(discardable_bitmap, gfx::Point(0, 0), - paint); + content_layer_client.add_draw_image(discardable_image.get(), gfx::Point(0, 0), + paint); scoped_refptr<Picture> picture = Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true, RecordingSource::RECORD_NORMALLY); - PixelRefMap::Iterator iterator(gfx::Rect(0, 0, 1, 1), picture.get()); + DiscardableImageMap::Iterator iterator(gfx::Rect(0, 0, 1, 1), picture.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap.pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image.get()); EXPECT_EQ(gfx::RectF(0, 0, 1 << 25, 1 << 25).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } diff --git a/cc/playback/display_item_list.cc b/cc/playback/display_item_list.cc index 050e029..6959c69 100644 --- a/cc/playback/display_item_list.cc +++ b/cc/playback/display_item_list.cc @@ -293,16 +293,16 @@ void DisplayItemList::EmitTraceSnapshot() const { DisplayItemsTracingEnabled())); } -void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) { +void DisplayItemList::GatherDiscardableImages(const gfx::Size& grid_cell_size) { DCHECK(ProcessAppendedItemsCalled()); // This should be only called once, and only after CreateAndCacheSkPicture. DCHECK(picture_); - DCHECK(!pixel_refs_); - pixel_refs_ = make_scoped_ptr(new PixelRefMap(grid_cell_size)); + DCHECK(!images_); + images_ = make_scoped_ptr(new DiscardableImageMap(grid_cell_size)); if (!picture_->willPlayBackBitmaps()) return; - pixel_refs_->GatherPixelRefsFromPicture(picture_.get(), layer_rect_); + images_->GatherImagesFromPicture(picture_.get(), layer_rect_); } void* DisplayItemList::GetSidecar(DisplayItem* display_item) { diff --git a/cc/playback/display_item_list.h b/cc/playback/display_item_list.h index 3778b00..92a423e 100644 --- a/cc/playback/display_item_list.h +++ b/cc/playback/display_item_list.h @@ -12,8 +12,8 @@ #include "cc/base/cc_export.h" #include "cc/base/scoped_ptr_vector.h" #include "cc/base/sidecar_list_container.h" +#include "cc/playback/discardable_image_map.h" #include "cc/playback/display_item.h" -#include "cc/playback/pixel_ref_map.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkPicture.h" #include "ui/gfx/geometry/rect.h" @@ -80,7 +80,7 @@ class CC_EXPORT DisplayItemList void EmitTraceSnapshot() const; - void GatherPixelRefs(const gfx::Size& grid_cell_size); + void GatherDiscardableImages(const gfx::Size& grid_cell_size); // Finds the sidecar for a display item in this list. void* GetSidecar(DisplayItem* display_item); @@ -122,10 +122,10 @@ class CC_EXPORT DisplayItemList // Memory usage due to external data held by display items. size_t external_memory_usage_; - scoped_ptr<PixelRefMap> pixel_refs_; + scoped_ptr<DiscardableImageMap> images_; friend class base::RefCountedThreadSafe<DisplayItemList>; - friend class PixelRefMap::Iterator; + friend class DiscardableImageMap::Iterator; FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); DISALLOW_COPY_AND_ASSIGN(DisplayItemList); }; diff --git a/cc/playback/display_list_raster_source.cc b/cc/playback/display_list_raster_source.cc index ee48065..d0ef20a 100644 --- a/cc/playback/display_list_raster_source.cc +++ b/cc/playback/display_list_raster_source.cc @@ -161,14 +161,14 @@ void DisplayListRasterSource::PerformSolidColorAnalysis( analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); } -void DisplayListRasterSource::GatherPixelRefs( +void DisplayListRasterSource::GatherDiscardableImages( const gfx::Rect& layer_rect, - std::vector<skia::PositionPixelRef>* pixel_refs) const { - DCHECK_EQ(0u, pixel_refs->size()); + std::vector<skia::PositionImage>* images) const { + DCHECK_EQ(0u, images->size()); - PixelRefMap::Iterator iterator(layer_rect, display_list_.get()); + DiscardableImageMap::Iterator iterator(layer_rect, display_list_.get()); while (iterator) { - pixel_refs->push_back(*iterator); + images->push_back(*iterator); ++iterator; } } diff --git a/cc/playback/display_list_raster_source.h b/cc/playback/display_list_raster_source.h index d8071b1..56f70dd 100644 --- a/cc/playback/display_list_raster_source.h +++ b/cc/playback/display_list_raster_source.h @@ -40,9 +40,9 @@ class CC_EXPORT DisplayListRasterSource : public RasterSource { bool IsSolidColor() const override; SkColor GetSolidColor() const override; gfx::Size GetSize() const override; - void GatherPixelRefs( + void GatherDiscardableImages( const gfx::Rect& layer_rect, - std::vector<skia::PositionPixelRef>* pixel_refs) const override; + std::vector<skia::PositionImage>* images) const override; bool CoversRect(const gfx::Rect& layer_rect) const override; bool HasRecordings() const override; gfx::Rect RecordedViewport() const override; diff --git a/cc/playback/display_list_raster_source_unittest.cc b/cc/playback/display_list_raster_source_unittest.cc index 499a555..33cd4ae 100644 --- a/cc/playback/display_list_raster_source_unittest.cc +++ b/cc/playback/display_list_raster_source_unittest.cc @@ -175,10 +175,10 @@ TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { scoped_ptr<FakeDisplayListRecordingSource> recording_source = FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); - SkBitmap discardable_bitmap[2][2]; - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][0]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][1]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][1]); + skia::RefPtr<SkImage> discardable_image[2][2]; + discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); // Discardable pixel refs are found in the following cells: // |---|---| @@ -186,12 +186,13 @@ TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { // |---|---| // | | x | // |---|---| - recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[0][1], - gfx::Point(260, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[1][1], - gfx::Point(260, 260)); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image(discardable_image[0][0].get(), + gfx::Point(0, 0)); + recording_source->add_draw_image(discardable_image[0][1].get(), + gfx::Point(260, 0)); + recording_source->add_draw_image(discardable_image[1][1].get(), + gfx::Point(260, 260)); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<DisplayListRasterSource> raster = @@ -200,42 +201,42 @@ TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { // Tile sized iterators. These should find only one pixel ref. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); + std::vector<skia::PositionImage> images; + raster->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_EQ(1u, images.size()); + EXPECT_EQ(discardable_image[0][0].get(), images[0].image); EXPECT_EQ(gfx::RectF(32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } // Shifted tile sized iterators. These should find only one pixel ref. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[0].pixel_ref); + std::vector<skia::PositionImage> images; + raster->GatherDiscardableImages(gfx::Rect(260, 260, 256, 256), &images); + EXPECT_EQ(1u, images.size()); + EXPECT_EQ(discardable_image[1][1].get(), images[0].image); EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } // Ensure there's no discardable pixel refs in the empty cell { - std::vector<skia::PositionPixelRef> pixel_refs; - raster->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), &pixel_refs); - EXPECT_EQ(0u, pixel_refs.size()); + std::vector<skia::PositionImage> images; + raster->GatherDiscardableImages(gfx::Rect(0, 256, 256, 256), &images); + EXPECT_EQ(0u, images.size()); } // Layer sized iterators. These should find three pixel ref. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), &pixel_refs); - EXPECT_EQ(3u, pixel_refs.size()); - EXPECT_EQ(discardable_bitmap[0][0].pixelRef(), pixel_refs[0].pixel_ref); - EXPECT_EQ(discardable_bitmap[0][1].pixelRef(), pixel_refs[1].pixel_ref); - EXPECT_EQ(discardable_bitmap[1][1].pixelRef(), pixel_refs[2].pixel_ref); + std::vector<skia::PositionImage> images; + raster->GatherDiscardableImages(gfx::Rect(0, 0, 512, 512), &images); + EXPECT_EQ(3u, images.size()); + EXPECT_EQ(discardable_image[0][0].get(), images[0].image); + EXPECT_EQ(discardable_image[0][1].get(), images[1].image); + EXPECT_EQ(discardable_image[1][1].get(), images[2].image); EXPECT_EQ(gfx::RectF(32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[1].image_rect).ToString()); EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[2].image_rect).ToString()); } } diff --git a/cc/playback/display_list_recording_source.cc b/cc/playback/display_list_recording_source.cc index 6bd14ff..39126ed 100644 --- a/cc/playback/display_list_recording_source.cc +++ b/cc/playback/display_list_recording_source.cc @@ -44,7 +44,7 @@ namespace cc { DisplayListRecordingSource::DisplayListRecordingSource( const gfx::Size& grid_cell_size) : slow_down_raster_scale_factor_for_debug_(0), - gather_pixel_refs_(false), + gather_images_(false), requires_clear_(false), is_solid_color_(false), clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), @@ -187,8 +187,8 @@ bool DisplayListRecordingSource::UpdateAndExpandInvalidation( display_list_->IsSuitableForGpuRasterization(); DetermineIfSolidColor(); display_list_->EmitTraceSnapshot(); - if (gather_pixel_refs_) - display_list_->GatherPixelRefs(grid_cell_size_); + if (gather_images_) + display_list_->GatherDiscardableImages(grid_cell_size_); return true; } @@ -206,8 +206,9 @@ void DisplayListRecordingSource::SetSlowdownRasterScaleFactor(int factor) { slow_down_raster_scale_factor_for_debug_ = factor; } -void DisplayListRecordingSource::SetGatherPixelRefs(bool gather_pixel_refs) { - gather_pixel_refs_ = gather_pixel_refs; +void DisplayListRecordingSource::SetGatherDiscardableImages( + bool gather_images) { + gather_images_ = gather_images; } void DisplayListRecordingSource::SetBackgroundColor(SkColor background_color) { diff --git a/cc/playback/display_list_recording_source.h b/cc/playback/display_list_recording_source.h index a0ba8df..daef594 100644 --- a/cc/playback/display_list_recording_source.h +++ b/cc/playback/display_list_recording_source.h @@ -29,7 +29,7 @@ class CC_EXPORT DisplayListRecordingSource : public RecordingSource { gfx::Size GetSize() const final; void SetEmptyBounds() override; void SetSlowdownRasterScaleFactor(int factor) override; - void SetGatherPixelRefs(bool gather_pixel_refs) override; + void SetGatherDiscardableImages(bool gather_images) override; void SetBackgroundColor(SkColor background_color) override; void SetRequiresClear(bool requires_clear) override; bool IsSuitableForGpuRasterization() const override; @@ -50,7 +50,7 @@ class CC_EXPORT DisplayListRecordingSource : public RecordingSource { gfx::Rect recorded_viewport_; gfx::Size size_; int slow_down_raster_scale_factor_for_debug_; - bool gather_pixel_refs_; + bool gather_images_; bool requires_clear_; bool is_solid_color_; bool clear_canvas_with_debug_color_; diff --git a/cc/playback/display_list_recording_source_unittest.cc b/cc/playback/display_list_recording_source_unittest.cc index 5fb4867..1ac4092 100644 --- a/cc/playback/display_list_recording_source_unittest.cc +++ b/cc/playback/display_list_recording_source_unittest.cc @@ -19,7 +19,7 @@ class DisplayListRecordingSourceTest : public testing::Test { void SetUp() override {} }; -TEST_F(DisplayListRecordingSourceTest, DiscardablePixelRefsWithTransform) { +TEST_F(DisplayListRecordingSourceTest, DiscardableImagesWithTransform) { gfx::Size grid_cell_size(128, 128); gfx::Rect recorded_viewport(256, 256); @@ -27,19 +27,19 @@ TEST_F(DisplayListRecordingSourceTest, DiscardablePixelRefsWithTransform) { FakeDisplayListRecordingSource::CreateFilledRecordingSource( recorded_viewport.size()); recording_source->SetGridCellSize(grid_cell_size); - SkBitmap discardable_bitmap[2][2]; + skia::RefPtr<SkImage> discardable_image[2][2]; gfx::Transform identity_transform; - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][0]); + discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); // Translate transform is equivalent to moving using point. gfx::Transform translate_transform; translate_transform.Translate(0, 130); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][0]); + discardable_image[1][0] = CreateDiscardableImage(gfx::Size(32, 32)); // This moves the bitmap to center of viewport and rotate, this would make // this bitmap in all four tile grids. gfx::Transform rotate_transform; rotate_transform.Translate(112, 112); rotate_transform.Rotate(45); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][1]); + discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); gfx::RectF rect(0, 0, 32, 32); gfx::RectF translate_rect = rect; @@ -47,13 +47,13 @@ TEST_F(DisplayListRecordingSourceTest, DiscardablePixelRefsWithTransform) { gfx::RectF rotate_rect = rect; rotate_transform.TransformRect(&rotate_rect); - recording_source->add_draw_bitmap_with_transform(discardable_bitmap[0][0], - identity_transform); - recording_source->add_draw_bitmap_with_transform(discardable_bitmap[1][0], - translate_transform); - recording_source->add_draw_bitmap_with_transform(discardable_bitmap[1][1], - rotate_transform); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image_with_transform(discardable_image[0][0].get(), + identity_transform); + recording_source->add_draw_image_with_transform(discardable_image[1][0].get(), + translate_transform); + recording_source->add_draw_image_with_transform(discardable_image[1][1].get(), + rotate_transform); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); bool can_use_lcd_text = true; @@ -63,66 +63,68 @@ TEST_F(DisplayListRecordingSourceTest, DiscardablePixelRefsWithTransform) { // Tile sized iterators. These should find only one pixel ref. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), &pixel_refs); - EXPECT_EQ(2u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_TRUE(pixel_refs[1].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 128, 128), &images); + EXPECT_EQ(2u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); + EXPECT_TRUE(images[1].image == discardable_image[1][1].get()); EXPECT_EQ(rect.ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[1].image_rect).ToString()); } // Shifted tile sized iterators. These should find only one pixel ref. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 140, 128, 128), + &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[1][1].get()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } // The rotated bitmap would still be in the top right tile. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 0, 128, 128), + &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[1][1].get()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } // Layer sized iterators. These should find all 6 pixel refs, including 1 // pixel ref bitmap[0][0], 1 pixel ref for bitmap[1][0], and 4 pixel refs for // bitmap[1][1]. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_EQ(6u, pixel_refs.size()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_EQ(6u, images.size()); // Top left tile with bitmap[0][0] and bitmap[1][1]. - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_TRUE(pixel_refs[1].pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); + EXPECT_TRUE(images[1].image == discardable_image[1][1].get()); // Top right tile with bitmap[1][1]. - EXPECT_TRUE(pixel_refs[2].pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(images[2].image == discardable_image[1][1].get()); // Bottom left tile with bitmap[1][0] and bitmap[1][1]. - EXPECT_TRUE(pixel_refs[3].pixel_ref == discardable_bitmap[1][0].pixelRef()); - EXPECT_TRUE(pixel_refs[4].pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(images[3].image == discardable_image[1][0].get()); + EXPECT_TRUE(images[4].image == discardable_image[1][1].get()); // Bottom right tile with bitmap[1][1]. - EXPECT_TRUE(pixel_refs[5].pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(images[5].image == discardable_image[1][1].get()); EXPECT_EQ(rect.ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[1].image_rect).ToString()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[2].image_rect).ToString()); EXPECT_EQ(translate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[3].image_rect).ToString()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[4].image_rect).ToString()); EXPECT_EQ(rotate_rect.ToString(), - gfx::SkRectToRectF(pixel_refs[5].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[5].image_rect).ToString()); } } diff --git a/cc/playback/picture.cc b/cc/playback/picture.cc index f2429ac..102e076 100644 --- a/cc/playback/picture.cc +++ b/cc/playback/picture.cc @@ -16,7 +16,7 @@ #include "cc/debug/traced_picture.h" #include "cc/debug/traced_value.h" #include "cc/layers/content_layer_client.h" -#include "skia/ext/pixel_ref_utils.h" +#include "skia/ext/discardable_image_utils.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPictureRecorder.h" @@ -58,20 +58,20 @@ scoped_refptr<Picture> Picture::Create( const gfx::Rect& layer_rect, ContentLayerClient* client, const gfx::Size& tile_grid_size, - bool gather_pixel_refs, + bool gather_discardable_images, RecordingSource::RecordingMode recording_mode) { scoped_refptr<Picture> picture = make_scoped_refptr(new Picture(layer_rect, tile_grid_size)); picture->Record(client, recording_mode); - if (gather_pixel_refs) - picture->GatherPixelRefs(); + if (gather_discardable_images) + picture->GatherDiscardableImages(); return picture; } Picture::Picture(const gfx::Rect& layer_rect, const gfx::Size& tile_grid_size) - : layer_rect_(layer_rect), pixel_refs_(tile_grid_size) { + : layer_rect_(layer_rect), images_(tile_grid_size) { // Instead of recording a trace event for object creation here, we wait for // the picture to be recorded in Picture::Record. } @@ -128,14 +128,12 @@ scoped_refptr<Picture> Picture::CreateFromValue(const base::Value* raw_value) { Picture::Picture(SkPicture* picture, const gfx::Rect& layer_rect) : layer_rect_(layer_rect), picture_(skia::AdoptRef(picture)), - pixel_refs_(layer_rect.size()) { -} + images_(layer_rect.size()) {} Picture::Picture(const skia::RefPtr<SkPicture>& picture, const gfx::Rect& layer_rect, - const PixelRefMap& pixel_refs) - : layer_rect_(layer_rect), picture_(picture), pixel_refs_(pixel_refs) { -} + const DiscardableImageMap& images) + : layer_rect_(layer_rect), picture_(picture), images_(images) {} Picture::~Picture() { TRACE_EVENT_OBJECT_DELETED_WITH_ID( @@ -232,17 +230,16 @@ void Picture::Record(ContentLayerClient* painter, EmitTraceSnapshot(); } -void Picture::GatherPixelRefs() { - TRACE_EVENT2("cc", "Picture::GatherPixelRefs", - "width", layer_rect_.width(), - "height", layer_rect_.height()); +void Picture::GatherDiscardableImages() { + TRACE_EVENT2("cc", "Picture::GatherDiscardableImages", "width", + layer_rect_.width(), "height", layer_rect_.height()); DCHECK(picture_); - DCHECK(pixel_refs_.empty()); + DCHECK(images_.empty()); if (!WillPlayBackBitmaps()) return; - pixel_refs_.GatherPixelRefsFromPicture(picture_.get(), layer_rect_); + images_.GatherImagesFromPicture(picture_.get(), layer_rect_); } int Picture::Raster(SkCanvas* canvas, @@ -276,9 +273,8 @@ int Picture::Raster(SkCanvas* canvas, SkIRect bounds; canvas->getClipDeviceBounds(&bounds); canvas->restore(); - TRACE_EVENT_END1( - "cc", "Picture::Raster", - "num_pixels_rasterized", bounds.width() * bounds.height()); + TRACE_EVENT_END1("cc", "Picture::Raster", "num_pixels_rasterized", + bounds.width() * bounds.height()); return bounds.width() * bounds.height(); } @@ -288,8 +284,8 @@ void Picture::Replay(SkCanvas* canvas, SkPicture::AbortCallback* callback) { picture_->playback(canvas, callback); SkIRect bounds; canvas->getClipDeviceBounds(&bounds); - TRACE_EVENT_END1("cc", "Picture::Replay", - "num_pixels_replayed", bounds.width() * bounds.height()); + TRACE_EVENT_END1("cc", "Picture::Replay", "num_pixels_replayed", + bounds.width() * bounds.height()); } scoped_ptr<base::Value> Picture::AsValue() const { @@ -320,9 +316,9 @@ void Picture::EmitTraceSnapshotAlias(Picture* original) const { TracedPicture::AsTraceablePictureAlias(original)); } -PixelRefMap::Iterator Picture::GetPixelRefMapIterator( +DiscardableImageMap::Iterator Picture::GetDiscardableImageMapIterator( const gfx::Rect& layer_rect) const { - return PixelRefMap::Iterator(layer_rect, this); + return DiscardableImageMap::Iterator(layer_rect, this); } scoped_refptr<base::trace_event::ConvertableToTraceFormat> diff --git a/cc/playback/picture.h b/cc/playback/picture.h index f8f6118..4cb3367 100644 --- a/cc/playback/picture.h +++ b/cc/playback/picture.h @@ -14,14 +14,12 @@ #include "base/trace_event/trace_event.h" #include "cc/base/cc_export.h" #include "cc/base/region.h" -#include "cc/playback/pixel_ref_map.h" +#include "cc/playback/discardable_image_map.h" #include "cc/playback/recording_source.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkPicture.h" #include "ui/gfx/geometry/rect.h" -class SkPixelRef; - namespace base { class Value; } @@ -41,7 +39,7 @@ class CC_EXPORT Picture const gfx::Rect& layer_rect, ContentLayerClient* client, const gfx::Size& tile_grid_size, - bool gather_pixels_refs, + bool gather_discardable_images, RecordingSource::RecordingMode recording_mode); static scoped_refptr<Picture> CreateFromValue(const base::Value* value); static scoped_refptr<Picture> CreateFromSkpValue(const base::Value* value); @@ -78,7 +76,7 @@ class CC_EXPORT Picture bool WillPlayBackBitmaps() const { return picture_->willPlayBackBitmaps(); } - PixelRefMap::Iterator GetPixelRefMapIterator( + DiscardableImageMap::Iterator GetDiscardableImageMapIterator( const gfx::Rect& layer_rect) const; private: @@ -87,7 +85,7 @@ class CC_EXPORT Picture // ownership to this picture. Picture(const skia::RefPtr<SkPicture>&, const gfx::Rect& layer_rect, - const PixelRefMap& pixel_refs); + const DiscardableImageMap& images); // This constructor will call AdoptRef on the SkPicture. Picture(SkPicture*, const gfx::Rect& layer_rect); ~Picture(); @@ -97,13 +95,13 @@ class CC_EXPORT Picture void Record(ContentLayerClient* client, RecordingSource::RecordingMode recording_mode); - // Gather pixel refs from recording. - void GatherPixelRefs(); + // Gather discardable images from recording. + void GatherDiscardableImages(); gfx::Rect layer_rect_; skia::RefPtr<SkPicture> picture_; - PixelRefMap pixel_refs_; + DiscardableImageMap images_; scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableRasterData(float scale) const; @@ -111,7 +109,7 @@ class CC_EXPORT Picture AsTraceableRecordData() const; friend class base::RefCountedThreadSafe<Picture>; - friend class PixelRefMap::Iterator; + friend class DiscardableImageMap::Iterator; DISALLOW_COPY_AND_ASSIGN(Picture); }; diff --git a/cc/playback/picture_pile.cc b/cc/playback/picture_pile.cc index bdb4700..37ec30b 100644 --- a/cc/playback/picture_pile.cc +++ b/cc/playback/picture_pile.cc @@ -160,7 +160,7 @@ PicturePile::PicturePile(float min_contents_scale, const gfx::Size& tile_grid_size) : min_contents_scale_(0), slow_down_raster_scale_factor_for_debug_(0), - gather_pixel_refs_(false), + gather_images_(false), has_any_recordings_(false), clear_canvas_with_debug_color_(kDefaultClearCanvasSetting), requires_clear_(true), @@ -515,7 +515,7 @@ void PicturePile::CreatePictures(ContentLayerClient* painter, // able to slow down recording. scoped_refptr<Picture> picture = Picture::Create(padded_record_rect, painter, tile_grid_size_, - gather_pixel_refs_, recording_mode); + gather_images_, recording_mode); // Note the '&&' with previous is-suitable state. // This means that once a picture-pile becomes unsuitable for gpu // rasterization due to some content, it will continue to be unsuitable even @@ -589,8 +589,8 @@ void PicturePile::SetSlowdownRasterScaleFactor(int factor) { slow_down_raster_scale_factor_for_debug_ = factor; } -void PicturePile::SetGatherPixelRefs(bool gather_pixel_refs) { - gather_pixel_refs_ = gather_pixel_refs; +void PicturePile::SetGatherDiscardableImages(bool gather_images) { + gather_images_ = gather_images; } void PicturePile::SetBackgroundColor(SkColor background_color) { diff --git a/cc/playback/picture_pile.h b/cc/playback/picture_pile.h index 889e9f5..e5c0984 100644 --- a/cc/playback/picture_pile.h +++ b/cc/playback/picture_pile.h @@ -34,7 +34,7 @@ class CC_EXPORT PicturePile : public RecordingSource { gfx::Size GetSize() const final; void SetEmptyBounds() override; void SetSlowdownRasterScaleFactor(int factor) override; - void SetGatherPixelRefs(bool gather_pixel_refs) override; + void SetGatherDiscardableImages(bool gather_images) override; void SetBackgroundColor(SkColor background_color) override; void SetRequiresClear(bool requires_clear) override; bool IsSuitableForGpuRasterization() const override; @@ -71,7 +71,7 @@ class CC_EXPORT PicturePile : public RecordingSource { float min_contents_scale_; gfx::Size tile_grid_size_; int slow_down_raster_scale_factor_for_debug_; - bool gather_pixel_refs_; + bool gather_images_; // A hint about whether there are any recordings. This may be a false // positive. bool has_any_recordings_; diff --git a/cc/playback/picture_pile_impl.cc b/cc/playback/picture_pile_impl.cc index 6227d83..736bb91 100644 --- a/cc/playback/picture_pile_impl.cc +++ b/cc/playback/picture_pile_impl.cc @@ -298,12 +298,12 @@ void PicturePileImpl::PerformSolidColorAnalysis( analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); } -void PicturePileImpl::GatherPixelRefs( +void PicturePileImpl::GatherDiscardableImages( const gfx::Rect& layer_rect, - std::vector<skia::PositionPixelRef>* pixel_refs) const { - DCHECK_EQ(0u, pixel_refs->size()); - for (PixelRefIterator iter(layer_rect, this); iter; ++iter) { - pixel_refs->push_back(*iter); + std::vector<skia::PositionImage>* images) const { + DCHECK_EQ(0u, images->size()); + for (ImageIterator iter(layer_rect, this); iter; ++iter) { + images->push_back(*iter); } } @@ -401,7 +401,7 @@ scoped_refptr<RasterSource> PicturePileImpl::CreateCloneWithoutLCDText() const { new PicturePileImpl(this, can_use_lcd_text)); } -PicturePileImpl::PixelRefIterator::PixelRefIterator( +PicturePileImpl::ImageIterator::ImageIterator( const gfx::Rect& layer_rect, const PicturePileImpl* picture_pile) : picture_pile_(picture_pile), @@ -413,24 +413,22 @@ PicturePileImpl::PixelRefIterator::PixelRefIterator( if (!tile_iterator_) return; - AdvanceToTilePictureWithPixelRefs(); + AdvanceToTilePictureWithImages(); } -PicturePileImpl::PixelRefIterator::~PixelRefIterator() { -} +PicturePileImpl::ImageIterator::~ImageIterator() {} -PicturePileImpl::PixelRefIterator& - PicturePileImpl::PixelRefIterator::operator++() { - ++pixel_ref_iterator_; - if (pixel_ref_iterator_) +PicturePileImpl::ImageIterator& PicturePileImpl::ImageIterator::operator++() { + ++image_iterator_; + if (image_iterator_) return *this; ++tile_iterator_; - AdvanceToTilePictureWithPixelRefs(); + AdvanceToTilePictureWithImages(); return *this; } -void PicturePileImpl::PixelRefIterator::AdvanceToTilePictureWithPixelRefs() { +void PicturePileImpl::ImageIterator::AdvanceToTilePictureWithImages() { for (; tile_iterator_; ++tile_iterator_) { PictureMap::const_iterator it = picture_pile_->picture_map_.find(tile_iterator_.index()); @@ -443,8 +441,8 @@ void PicturePileImpl::PixelRefIterator::AdvanceToTilePictureWithPixelRefs() { continue; processed_pictures_.insert(picture); - pixel_ref_iterator_ = picture->GetPixelRefMapIterator(layer_rect_); - if (pixel_ref_iterator_) + image_iterator_ = picture->GetDiscardableImageMapIterator(layer_rect_); + if (image_iterator_) break; } } diff --git a/cc/playback/picture_pile_impl.h b/cc/playback/picture_pile_impl.h index a7f1e8f..61288de 100644 --- a/cc/playback/picture_pile_impl.h +++ b/cc/playback/picture_pile_impl.h @@ -12,15 +12,14 @@ #include "base/time/time.h" #include "cc/base/cc_export.h" #include "cc/debug/rendering_stats_instrumentation.h" +#include "cc/playback/discardable_image_map.h" #include "cc/playback/picture_pile.h" -#include "cc/playback/pixel_ref_map.h" #include "cc/playback/raster_source.h" #include "skia/ext/analysis_canvas.h" #include "skia/ext/refptr.h" class SkCanvas; class SkPicture; -class SkPixelRef; namespace gfx { class Rect; @@ -49,9 +48,9 @@ class CC_EXPORT PicturePileImpl : public RasterSource { const gfx::Rect& content_rect, float contents_scale, RasterSource::SolidColorAnalysis* analysis) const override; - void GatherPixelRefs( + void GatherDiscardableImages( const gfx::Rect& layer_rect, - std::vector<skia::PositionPixelRef>* pixel_refs) const override; + std::vector<skia::PositionImage>* images) const override; bool CoversRect(const gfx::Rect& layer_rect) const override; void SetShouldAttemptToUseDistanceFieldText() override; bool ShouldAttemptToUseDistanceFieldText() const override; @@ -69,36 +68,34 @@ class CC_EXPORT PicturePileImpl : public RasterSource { skia::RefPtr<SkPicture> GetFlattenedPicture() override; size_t GetPictureMemoryUsage() const override; - // Iterator used to return SkPixelRefs from this picture pile. + // Iterator used to return SkImages from this picture pile. // Public for testing. - class CC_EXPORT PixelRefIterator { + class CC_EXPORT ImageIterator { public: - PixelRefIterator(const gfx::Rect& layer_rect, - const PicturePileImpl* picture_pile); - ~PixelRefIterator(); + ImageIterator(const gfx::Rect& layer_rect, + const PicturePileImpl* picture_pile); + ~ImageIterator(); - const skia::PositionPixelRef* operator->() const { - return &(*pixel_ref_iterator_); + const skia::PositionImage* operator->() const { + return &(*image_iterator_); } - const skia::PositionPixelRef& operator*() const { - return *pixel_ref_iterator_; - } - PixelRefIterator& operator++(); - operator bool() const { return pixel_ref_iterator_; } + const skia::PositionImage& operator*() const { return *image_iterator_; } + ImageIterator& operator++(); + operator bool() const { return image_iterator_; } private: - void AdvanceToTilePictureWithPixelRefs(); + void AdvanceToTilePictureWithImages(); const PicturePileImpl* picture_pile_; gfx::Rect layer_rect_; TilingData::Iterator tile_iterator_; - PixelRefMap::Iterator pixel_ref_iterator_; + DiscardableImageMap::Iterator image_iterator_; std::set<const void*> processed_pictures_; }; protected: friend class PicturePile; - friend class PixelRefIterator; + friend class ImageIterator; using PictureMapKey = PicturePile::PictureMapKey; using PictureMap = PicturePile::PictureMap; diff --git a/cc/playback/picture_pile_impl_unittest.cc b/cc/playback/picture_pile_impl_unittest.cc index 4ea3ba5..3931f8d 100644 --- a/cc/playback/picture_pile_impl_unittest.cc +++ b/cc/playback/picture_pile_impl_unittest.cc @@ -157,17 +157,17 @@ TEST(PicturePileImplTest, AnalyzeIsSolidEmpty) { EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); } -TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { +TEST(PicturePileImplTest, ImageIteratorDiscardableImagesOneTile) { gfx::Size tile_size(256, 256); gfx::Size layer_bounds(512, 512); scoped_ptr<FakePicturePile> recording_source = FakePicturePile::CreateFilledPile(tile_size, layer_bounds); - SkBitmap discardable_bitmap[2][2]; - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][0]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][1]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][1]); + skia::RefPtr<SkImage> discardable_image[2][2]; + discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); // Discardable pixel refs are found in the following cells: // |---|---| @@ -175,12 +175,13 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { // |---|---| // | | x | // |---|---| - recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[0][1], - gfx::Point(260, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[1][1], - gfx::Point(260, 260)); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image(discardable_image[0][0].get(), + gfx::Point(0, 0)); + recording_source->add_draw_image(discardable_image[0][1].get(), + gfx::Point(260, 0)); + recording_source->add_draw_image(discardable_image[1][1].get(), + gfx::Point(260, 260)); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<FakePicturePileImpl> pile = @@ -188,79 +189,79 @@ TEST(PicturePileImplTest, PixelRefIteratorDiscardableRefsOneTile) { // Tile sized iterators. These should find only one pixel ref. { - PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 256, 256), - pile.get()); + PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 256, 256), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), + EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); + EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), gfx::RectF(32, 32).ToString()); EXPECT_FALSE(++iterator); } // Shifted tile sized iterators. These should find only one pixel ref. { - PicturePileImpl::PixelRefIterator iterator(gfx::Rect(260, 260, 256, 256), - pile.get()); + PicturePileImpl::ImageIterator iterator(gfx::Rect(260, 260, 256, 256), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef()); - EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), + EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); + EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), gfx::RectF(260, 260, 32, 32).ToString()); EXPECT_FALSE(++iterator); } // Ensure there's no discardable pixel refs in the empty cell { - PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 256, 256, 256), - pile.get()); + PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 256, 256, 256), + pile.get()); EXPECT_FALSE(iterator); } // Layer sized iterators. These should find three pixel ref. { - PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), - pile.get()); + PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 512, 512), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), + EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); + EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), gfx::RectF(32, 32).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef()); - EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), + EXPECT_TRUE(iterator->image == discardable_image[0][1].get()); + EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), gfx::RectF(260, 0, 32, 32).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef()); - EXPECT_EQ(gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString(), + EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); + EXPECT_EQ(gfx::SkRectToRectF(iterator->image_rect).ToString(), gfx::RectF(260, 260, 32, 32).ToString()); EXPECT_FALSE(++iterator); } { // Copy test. - PicturePileImpl::PixelRefIterator iterator(gfx::Rect(0, 0, 512, 512), - pile.get()); + PicturePileImpl::ImageIterator iterator(gfx::Rect(0, 0, 512, 512), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][0].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[0][0].get()); EXPECT_EQ(gfx::RectF(32, 32).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[0][1].get()); EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); // copy now points to the same spot as iterator, // but both can be incremented independently. - PicturePileImpl::PixelRefIterator copy = iterator; + PicturePileImpl::ImageIterator copy = iterator; EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); EXPECT_TRUE(copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[0][1].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[0][1].get()); EXPECT_EQ(gfx::RectF(260, 0, 32, 32).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_TRUE(++copy); - EXPECT_TRUE(copy->pixel_ref == discardable_bitmap[1][1].pixelRef()); + EXPECT_TRUE(copy->image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(260, 260, 32, 32).ToString(), - gfx::SkRectToRectF(copy->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(copy->image_rect).ToString()); EXPECT_FALSE(++copy); } } @@ -431,7 +432,7 @@ INSTANTIATE_TEST_CASE_P(PicturePileImpl, OverlapTest, ::testing::Values(1.f, 0.873f, 1.f / 4.f, 4.f)); -TEST(PicturePileImplTest, PixelRefIteratorBorders) { +TEST(PicturePileImplTest, ImageIteratorBorders) { // 3 tile width / 1 tile height pile gfx::Size tile_size(128, 128); gfx::Size layer_bounds(320, 128); @@ -455,15 +456,15 @@ TEST(PicturePileImplTest, PixelRefIteratorBorders) { gfx::RectF(recording_source->tiling().TileBounds(1, 0)), gfx::RectF(recording_source->tiling().TileBounds(2, 0)), }; - SkBitmap discardable_bitmap[arraysize(bitmap_rects)]; + skia::RefPtr<SkImage> discardable_image[arraysize(bitmap_rects)]; for (size_t i = 0; i < arraysize(bitmap_rects); ++i) { - CreateDiscardableBitmap(bitmap_rects[i].size(), &discardable_bitmap[i]); - recording_source->add_draw_bitmap(discardable_bitmap[i], - bitmap_rects[i].origin()); + discardable_image[i] = CreateDiscardableImage(bitmap_rects[i].size()); + recording_source->add_draw_image(discardable_image[i].get(), + bitmap_rects[i].origin()); } - recording_source->SetGatherPixelRefs(true); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<FakePicturePileImpl> pile = @@ -487,50 +488,50 @@ TEST(PicturePileImplTest, PixelRefIteratorBorders) { // Tile-sized iterators. { // Because tile 0's borders extend onto tile 1, it will include both - // bitmap 0 and 1. However, it should *not* include bitmap 2. - PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(0, 0), - pile.get()); + // image 0 and 1. However, it should *not* include image 2. + PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(0, 0), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[0].get()); EXPECT_EQ(expected_rects[0].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1].get()); EXPECT_EQ(expected_rects[1].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } { - // Tile 1 + borders hits all bitmaps. - PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(1, 0), - pile.get()); + // Tile 1 + borders hits all images. + PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(1, 0), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[0].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[0].get()); EXPECT_EQ(expected_rects[0].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1].get()); EXPECT_EQ(expected_rects[1].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2].get()); EXPECT_EQ(expected_rects[2].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } { - // Tile 2 should not include bitmap 0, which is only on tile 0 and the + // Tile 2 should not include image 0, which is only on tile 0 and the // borders of tile 1. - PicturePileImpl::PixelRefIterator iterator(pile->tiling().TileBounds(2, 0), - pile.get()); + PicturePileImpl::ImageIterator iterator(pile->tiling().TileBounds(2, 0), + pile.get()); EXPECT_TRUE(iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[1].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[1].get()); EXPECT_EQ(expected_rects[1].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_TRUE(++iterator); - EXPECT_TRUE(iterator->pixel_ref == discardable_bitmap[2].pixelRef()); + EXPECT_TRUE(iterator->image == discardable_image[2].get()); EXPECT_EQ(expected_rects[2].ToString(), - gfx::SkRectToRectF(iterator->pixel_ref_rect).ToString()); + gfx::SkRectToRectF(iterator->image_rect).ToString()); EXPECT_FALSE(++iterator); } } diff --git a/cc/playback/pixel_ref_map.h b/cc/playback/pixel_ref_map.h deleted file mode 100644 index f8c8ca7..0000000 --- a/cc/playback/pixel_ref_map.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CC_PLAYBACK_PIXEL_REF_MAP_H_ -#define CC_PLAYBACK_PIXEL_REF_MAP_H_ - -#include <utility> -#include <vector> - -#include "base/containers/hash_tables.h" -#include "base/lazy_instance.h" -#include "base/memory/ref_counted.h" -#include "cc/base/cc_export.h" -#include "skia/ext/pixel_ref_utils.h" -#include "third_party/skia/include/core/SkPicture.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/geometry/size.h" - -class SkPixelRef; - -namespace cc { - -class Picture; -class DisplayItemList; - -typedef std::pair<int, int> PixelRefMapKey; -typedef std::vector<skia::PositionPixelRef> PixelRefs; -typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefHashmap; - -// This class is used and owned by cc Picture class. It is used to gather pixel -// refs which would happen after record. It takes in |cell_size| to decide how -// big each grid cell should be. -class CC_EXPORT PixelRefMap { - public: - explicit PixelRefMap(const gfx::Size& cell_size); - ~PixelRefMap(); - void GatherPixelRefsFromPicture(SkPicture* picture, - const gfx::Rect& layer_rect); - - bool empty() const { return data_hash_map_.empty(); } - - // This iterator imprecisely returns the set of pixel refs that are needed to - // raster this layer rect from this picture. Internally, pixel refs are - // clumped into tile grid buckets, so there may be false positives. - class CC_EXPORT Iterator { - public: - // Default iterator constructor that is used as place holder for invalid - // Iterator. - Iterator(); - Iterator(const gfx::Rect& layer_rect, const Picture* picture); - Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture); - ~Iterator(); - - const skia::PositionPixelRef* operator->() const { - DCHECK_LT(current_index_, current_pixel_refs_->size()); - return &(*current_pixel_refs_)[current_index_]; - } - - const skia::PositionPixelRef& operator*() const { - DCHECK_LT(current_index_, current_pixel_refs_->size()); - return (*current_pixel_refs_)[current_index_]; - } - - Iterator& operator++(); - operator bool() const { - return current_index_ < current_pixel_refs_->size(); - } - - private: - void PointToFirstPixelRef(const gfx::Rect& query_rect); - - static base::LazyInstance<PixelRefs> empty_pixel_refs_; - const PixelRefMap* target_pixel_ref_map_; - const PixelRefs* current_pixel_refs_; - unsigned current_index_; - - gfx::Rect map_layer_rect_; - - gfx::Point min_point_; - gfx::Point max_point_; - int current_x_; - int current_y_; - }; - - private: - gfx::Point min_pixel_cell_; - gfx::Point max_pixel_cell_; - gfx::Size cell_size_; - - PixelRefHashmap data_hash_map_; -}; - -} // namespace cc - -#endif // CC_PLAYBACK_PIXEL_REF_MAP_H_ diff --git a/cc/playback/raster_source.h b/cc/playback/raster_source.h index 0c7c2bb..a9bbcf1 100644 --- a/cc/playback/raster_source.h +++ b/cc/playback/raster_source.h @@ -10,10 +10,9 @@ #include "base/memory/ref_counted.h" #include "cc/base/cc_export.h" #include "cc/debug/traced_value.h" -#include "skia/ext/pixel_ref_utils.h" +#include "skia/ext/discardable_image_utils.h" #include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkPixelRef.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -70,11 +69,11 @@ class CC_EXPORT RasterSource : public base::RefCountedThreadSafe<RasterSource> { // Returns the size of this raster source. virtual gfx::Size GetSize() const = 0; - // Populate the given list with all SkPixelRefs that may overlap the given + // Populate the given list with all images that may overlap the given // rect in layer space. - virtual void GatherPixelRefs( + virtual void GatherDiscardableImages( const gfx::Rect& layer_rect, - std::vector<skia::PositionPixelRef>* pixel_refs) const = 0; + std::vector<skia::PositionImage>* images) const = 0; // Return true iff this raster source can raster the given rect in layer // space. diff --git a/cc/playback/recording_source.h b/cc/playback/recording_source.h index cf8c7c4..7505e5f 100644 --- a/cc/playback/recording_source.h +++ b/cc/playback/recording_source.h @@ -48,7 +48,7 @@ class CC_EXPORT RecordingSource { virtual gfx::Size GetSize() const = 0; virtual void SetEmptyBounds() = 0; virtual void SetSlowdownRasterScaleFactor(int factor) = 0; - virtual void SetGatherPixelRefs(bool gather_pixel_refs) = 0; + virtual void SetGatherDiscardableImages(bool gather_images) = 0; virtual void SetBackgroundColor(SkColor background_color) = 0; virtual void SetRequiresClear(bool requires_clear) = 0; virtual bool IsSuitableForGpuRasterization() const = 0; diff --git a/cc/playback/recording_source_unittest.cc b/cc/playback/recording_source_unittest.cc index e0e602e0..949fdce 100644 --- a/cc/playback/recording_source_unittest.cc +++ b/cc/playback/recording_source_unittest.cc @@ -65,34 +65,34 @@ typedef Types<FakePicturePile, FakeDisplayListRecordingSource> TYPED_TEST_CASE(RecordingSourceTest, RecordingSourceImplementations); -TYPED_TEST(RecordingSourceTest, NoGatherPixelRefEmptyPixelRefs) { +TYPED_TEST(RecordingSourceTest, NoGatherImageEmptyImages) { gfx::Size grid_cell_size(128, 128); gfx::Rect recorded_viewport(0, 0, 256, 256); scoped_ptr<TypeParam> recording_source = CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size); - recording_source->SetGatherPixelRefs(false); + recording_source->SetGatherDiscardableImages(false); recording_source->Rerecord(); scoped_refptr<RasterSource> raster_source = CreateRasterSource<TypeParam>(recording_source.get()); - // If recording source do not gather pixel ref, raster source is not going to - // get pixel refs. + // If recording source do not gather images, raster source is not going to + // get images. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(recorded_viewport, &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(recorded_viewport, &images); + EXPECT_TRUE(images.empty()); } } -TYPED_TEST(RecordingSourceTest, EmptyPixelRefs) { +TYPED_TEST(RecordingSourceTest, EmptyImages) { gfx::Size grid_cell_size(128, 128); gfx::Rect recorded_viewport(0, 0, 256, 256); scoped_ptr<TypeParam> recording_source = CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size); - recording_source->SetGatherPixelRefs(true); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<RasterSource> raster_source = @@ -100,25 +100,26 @@ TYPED_TEST(RecordingSourceTest, EmptyPixelRefs) { // Tile sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 128, 128), &images); + EXPECT_TRUE(images.empty()); } // Shifted tile sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 140, 128, 128), + &images); + EXPECT_TRUE(images.empty()); } // Layer sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_TRUE(images.empty()); } } -TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) { +TYPED_TEST(RecordingSourceTest, NoDiscardableImages) { gfx::Size grid_cell_size(128, 128); gfx::Rect recorded_viewport(0, 0, 256, 256); @@ -131,6 +132,8 @@ TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) { SkBitmap non_discardable_bitmap; non_discardable_bitmap.allocN32Pixels(128, 128); non_discardable_bitmap.setImmutable(); + skia::RefPtr<SkImage> non_discardable_image = + skia::AdoptRef(SkImage::NewFromBitmap(non_discardable_bitmap)); recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 256, 256), simple_paint); @@ -140,11 +143,13 @@ TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) { simple_paint); recording_source->add_draw_rect_with_paint(gfx::Rect(0, 512, 256, 256), simple_paint); - recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(128, 0)); - recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 128)); - recording_source->add_draw_bitmap(non_discardable_bitmap, - gfx::Point(150, 150)); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image(non_discardable_image.get(), + gfx::Point(128, 0)); + recording_source->add_draw_image(non_discardable_image.get(), + gfx::Point(0, 128)); + recording_source->add_draw_image(non_discardable_image.get(), + gfx::Point(150, 150)); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<RasterSource> raster_source = @@ -152,98 +157,102 @@ TYPED_TEST(RecordingSourceTest, NoDiscardablePixelRefs) { // Tile sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 128, 128), &images); + EXPECT_TRUE(images.empty()); } // Shifted tile sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 140, 128, 128), + &images); + EXPECT_TRUE(images.empty()); } // Layer sized iterators. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_TRUE(images.empty()); } } -TYPED_TEST(RecordingSourceTest, DiscardablePixelRefs) { +TYPED_TEST(RecordingSourceTest, DiscardableImages) { gfx::Size grid_cell_size(128, 128); gfx::Rect recorded_viewport(0, 0, 256, 256); scoped_ptr<TypeParam> recording_source = CreateRecordingSource<TypeParam>(recorded_viewport, grid_cell_size); - SkBitmap discardable_bitmap[2][2]; - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[0][0]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][0]); - CreateDiscardableBitmap(gfx::Size(32, 32), &discardable_bitmap[1][1]); + skia::RefPtr<SkImage> discardable_image[2][2]; + discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[1][0] = CreateDiscardableImage(gfx::Size(32, 32)); + discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); - // Discardable pixel refs are found in the following cells: + // Discardable images are found in the following cells: // |---|---| // | x | | // |---|---| // | x | x | // |---|---| - recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[1][0], - gfx::Point(0, 130)); - recording_source->add_draw_bitmap(discardable_bitmap[1][1], - gfx::Point(140, 140)); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image(discardable_image[0][0].get(), + gfx::Point(0, 0)); + recording_source->add_draw_image(discardable_image[1][0].get(), + gfx::Point(0, 130)); + recording_source->add_draw_image(discardable_image[1][1].get(), + gfx::Point(140, 140)); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<RasterSource> raster_source = CreateRasterSource<TypeParam>(recording_source.get()); - // Tile sized iterators. These should find only one pixel ref. + // Tile sized iterators. These should find only one image. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 128, 128), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 128, 128), &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); EXPECT_EQ(gfx::RectF(32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } - // Shifted tile sized iterators. These should find only one pixel ref. + // Shifted tile sized iterators. These should find only one image. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 140, 128, 128), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 140, 128, 128), + &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(140, 140, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } - // Ensure there's no discardable pixel refs in the empty cell + // Ensure there's no discardable images in the empty cell { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(140, 0, 128, 128), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(140, 0, 128, 128), + &images); + EXPECT_TRUE(images.empty()); } - // Layer sized iterators. These should find all 3 pixel refs. + // Layer sized iterators. These should find all 3 images. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_EQ(3u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_TRUE(pixel_refs[1].pixel_ref == discardable_bitmap[1][0].pixelRef()); - EXPECT_TRUE(pixel_refs[2].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_EQ(3u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); + EXPECT_TRUE(images[1].image == discardable_image[1][0].get()); + EXPECT_TRUE(images[2].image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); EXPECT_EQ(gfx::RectF(0, 130, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[1].image_rect).ToString()); EXPECT_EQ(gfx::RectF(140, 140, 32, 32).ToString(), - gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[2].image_rect).ToString()); } } -TYPED_TEST(RecordingSourceTest, DiscardablePixelRefsBaseNonDiscardable) { +TYPED_TEST(RecordingSourceTest, DiscardableImagesBaseNonDiscardable) { gfx::Size grid_cell_size(256, 256); gfx::Rect recorded_viewport(0, 0, 512, 512); @@ -253,69 +262,75 @@ TYPED_TEST(RecordingSourceTest, DiscardablePixelRefsBaseNonDiscardable) { SkBitmap non_discardable_bitmap; non_discardable_bitmap.allocN32Pixels(512, 512); non_discardable_bitmap.setImmutable(); + skia::RefPtr<SkImage> non_discardable_image = + skia::AdoptRef(SkImage::NewFromBitmap(non_discardable_bitmap)); - SkBitmap discardable_bitmap[2][2]; - CreateDiscardableBitmap(gfx::Size(128, 128), &discardable_bitmap[0][0]); - CreateDiscardableBitmap(gfx::Size(128, 128), &discardable_bitmap[0][1]); - CreateDiscardableBitmap(gfx::Size(128, 128), &discardable_bitmap[1][1]); + skia::RefPtr<SkImage> discardable_image[2][2]; + discardable_image[0][0] = CreateDiscardableImage(gfx::Size(128, 128)); + discardable_image[0][1] = CreateDiscardableImage(gfx::Size(128, 128)); + discardable_image[1][1] = CreateDiscardableImage(gfx::Size(128, 128)); - // One large non-discardable bitmap covers the whole grid. - // Discardable pixel refs are found in the following cells: + // One large non-discardable image covers the whole grid. + // Discardable images are found in the following cells: // |---|---| // | x | x | // |---|---| // | | x | // |---|---| - recording_source->add_draw_bitmap(non_discardable_bitmap, gfx::Point(0, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[0][0], gfx::Point(0, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[0][1], - gfx::Point(260, 0)); - recording_source->add_draw_bitmap(discardable_bitmap[1][1], - gfx::Point(260, 260)); - recording_source->SetGatherPixelRefs(true); + recording_source->add_draw_image(non_discardable_image.get(), + gfx::Point(0, 0)); + recording_source->add_draw_image(discardable_image[0][0].get(), + gfx::Point(0, 0)); + recording_source->add_draw_image(discardable_image[0][1].get(), + gfx::Point(260, 0)); + recording_source->add_draw_image(discardable_image[1][1].get(), + gfx::Point(260, 260)); + recording_source->SetGatherDiscardableImages(true); recording_source->Rerecord(); scoped_refptr<RasterSource> raster_source = CreateRasterSource<TypeParam>(recording_source.get()); - // Tile sized iterators. These should find only one pixel ref. + // Tile sized iterators. These should find only one image. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 256, 256), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 256, 256), &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); EXPECT_EQ(gfx::RectF(128, 128).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } - // Shifted tile sized iterators. These should find only one pixel ref. + // Shifted tile sized iterators. These should find only one image. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(260, 260, 256, 256), &pixel_refs); - EXPECT_EQ(1u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(260, 260, 256, 256), + &images); + EXPECT_EQ(1u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(260, 260, 128, 128).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); } - // Ensure there's no discardable pixel refs in the empty cell + // Ensure there's no discardable images in the empty cell { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 256, 256, 256), &pixel_refs); - EXPECT_TRUE(pixel_refs.empty()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 256, 256, 256), + &images); + EXPECT_TRUE(images.empty()); } - // Layer sized iterators. These should find three pixel ref. + // Layer sized iterators. These should find three images. { - std::vector<skia::PositionPixelRef> pixel_refs; - raster_source->GatherPixelRefs(gfx::Rect(0, 0, 512, 512), &pixel_refs); - EXPECT_EQ(3u, pixel_refs.size()); - EXPECT_TRUE(pixel_refs[0].pixel_ref == discardable_bitmap[0][0].pixelRef()); - EXPECT_TRUE(pixel_refs[1].pixel_ref == discardable_bitmap[0][1].pixelRef()); - EXPECT_TRUE(pixel_refs[2].pixel_ref == discardable_bitmap[1][1].pixelRef()); + std::vector<skia::PositionImage> images; + raster_source->GatherDiscardableImages(gfx::Rect(0, 0, 512, 512), &images); + EXPECT_EQ(3u, images.size()); + EXPECT_TRUE(images[0].image == discardable_image[0][0].get()); + EXPECT_TRUE(images[1].image == discardable_image[0][1].get()); + EXPECT_TRUE(images[2].image == discardable_image[1][1].get()); EXPECT_EQ(gfx::RectF(128, 128).ToString(), - gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[0].image_rect).ToString()); EXPECT_EQ(gfx::RectF(260, 0, 128, 128).ToString(), - gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[1].image_rect).ToString()); EXPECT_EQ(gfx::RectF(260, 260, 128, 128).ToString(), - gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect).ToString()); + gfx::SkRectToRectF(images[2].image_rect).ToString()); } } diff --git a/cc/test/fake_content_layer_client.cc b/cc/test/fake_content_layer_client.cc index 0cbb92a..77fa2d0 100644 --- a/cc/test/fake_content_layer_client.cc +++ b/cc/test/fake_content_layer_client.cc @@ -28,6 +28,18 @@ FakeContentLayerClient::BitmapData::BitmapData(const SkBitmap& bitmap, FakeContentLayerClient::BitmapData::~BitmapData() { } +FakeContentLayerClient::ImageData::ImageData(const SkImage* img, + const gfx::Point& point, + const SkPaint& paint) + : image(skia::SharePtr(img)), point(point), paint(paint) {} + +FakeContentLayerClient::ImageData::ImageData(const SkImage* img, + const gfx::Transform& transform, + const SkPaint& paint) + : image(skia::SharePtr(img)), transform(transform), paint(paint) {} + +FakeContentLayerClient::ImageData::~ImageData() {} + FakeContentLayerClient::FakeContentLayerClient() : fill_with_nonsolid_color_(false), last_canvas_(nullptr), @@ -57,6 +69,12 @@ void FakeContentLayerClient::PaintContents( canvas->drawBitmap(it->bitmap, it->point.x(), it->point.y(), &it->paint); } + for (ImageVector::const_iterator it = draw_images_.begin(); + it != draw_images_.end(); ++it) { + canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), + &it->paint); + } + if (fill_with_nonsolid_color_) { gfx::Rect draw_rect = paint_rect; bool red = true; @@ -113,6 +131,24 @@ FakeContentLayerClient::PaintContentsToDisplayList( } } + for (ImageVector::const_iterator it = draw_images_.begin(); + it != draw_images_.end(); ++it) { + if (!it->transform.IsIdentity()) { + auto* item = display_list->CreateAndAppendItem<TransformDisplayItem>(); + item->SetNew(it->transform); + } + canvas = skia::SharePtr( + recorder.beginRecording(it->image->width(), it->image->height())); + canvas->drawImage(it->image.get(), it->point.x(), it->point.y(), + &it->paint); + picture = skia::AdoptRef(recorder.endRecordingAsPicture()); + auto* item = display_list->CreateAndAppendItem<DrawingDisplayItem>(); + item->SetNew(picture.Pass()); + if (!it->transform.IsIdentity()) { + display_list->CreateAndAppendItem<EndTransformDisplayItem>(); + } + } + if (fill_with_nonsolid_color_) { gfx::Rect draw_rect = clip; bool red = true; diff --git a/cc/test/fake_content_layer_client.h b/cc/test/fake_content_layer_client.h index 44160e4..771a901 100644 --- a/cc/test/fake_content_layer_client.h +++ b/cc/test/fake_content_layer_client.h @@ -35,6 +35,20 @@ class FakeContentLayerClient : public ContentLayerClient { SkPaint paint; }; + struct ImageData { + ImageData(const SkImage* image, + const gfx::Point& point, + const SkPaint& paint); + ImageData(const SkImage* image, + const gfx::Transform& transform, + const SkPaint& paint); + ~ImageData(); + skia::RefPtr<const SkImage> image; + gfx::Point point; + gfx::Transform transform; + SkPaint paint; + }; + FakeContentLayerClient(); ~FakeContentLayerClient() override; @@ -73,6 +87,20 @@ class FakeContentLayerClient : public ContentLayerClient { draw_bitmaps_.push_back(data); } + void add_draw_image(const SkImage* image, + const gfx::Point& point, + const SkPaint& paint) { + ImageData data(image, point, paint); + draw_images_.push_back(data); + } + + void add_draw_image_with_transform(const SkImage* image, + const gfx::Transform& transform, + const SkPaint& paint) { + ImageData data(image, transform, paint); + draw_images_.push_back(data); + } + SkCanvas* last_canvas() const { return last_canvas_; } PaintingControlSetting last_painting_control() const { @@ -86,10 +114,12 @@ class FakeContentLayerClient : public ContentLayerClient { private: typedef std::vector<std::pair<gfx::RectF, SkPaint>> RectPaintVector; typedef std::vector<BitmapData> BitmapVector; + typedef std::vector<ImageData> ImageVector; bool fill_with_nonsolid_color_; RectPaintVector draw_rects_; BitmapVector draw_bitmaps_; + ImageVector draw_images_; SkCanvas* last_canvas_; PaintingControlSetting last_painting_control_; size_t reported_memory_usage_; diff --git a/cc/test/fake_display_list_recording_source.h b/cc/test/fake_display_list_recording_source.h index d5471a4..896ec7a 100644 --- a/cc/test/fake_display_list_recording_source.h +++ b/cc/test/fake_display_list_recording_source.h @@ -78,6 +78,17 @@ class FakeDisplayListRecordingSource : public DisplayListRecordingSource { client_.add_draw_rectf(rect, paint); } + void add_draw_image(const SkImage* image, const gfx::Point& point) { + client_.add_draw_image(image, point, default_paint_); + } + + void add_draw_image_with_transform(const SkImage* image, + const gfx::Transform& transform) { + client_.add_draw_image_with_transform(image, transform, default_paint_); + } + + // TODO(fmalita): we should be able to remove a bunch (all?) of + // add_draw_bitmap* variants at this point. void add_draw_bitmap(const SkBitmap& bitmap, const gfx::Point& point) { client_.add_draw_bitmap(bitmap, point, default_paint_); } diff --git a/cc/test/fake_picture_pile.cc b/cc/test/fake_picture_pile.cc index 52a70ec..c11515b 100644 --- a/cc/test/fake_picture_pile.cc +++ b/cc/test/fake_picture_pile.cc @@ -67,7 +67,7 @@ void FakePicturePile::AddRecordingAt(int x, int y) { bounds.Inset(-buffer_pixels(), -buffer_pixels()); scoped_refptr<Picture> picture( - Picture::Create(bounds, &client_, tile_grid_size_, gather_pixel_refs_, + Picture::Create(bounds, &client_, tile_grid_size_, gather_images_, RecordingSource::RECORD_NORMALLY)); picture_map_[std::pair<int, int>(x, y)] = picture; EXPECT_TRUE(HasRecordingAt(x, y)); diff --git a/cc/test/fake_picture_pile.h b/cc/test/fake_picture_pile.h index cc888ab..1183e28 100644 --- a/cc/test/fake_picture_pile.h +++ b/cc/test/fake_picture_pile.h @@ -93,6 +93,10 @@ class FakePicturePile : public PicturePile { client_.add_draw_rectf(rect, paint); } + void add_draw_image(const SkImage* image, const gfx::Point& point) { + client_.add_draw_image(image, point, default_paint_); + } + void add_draw_bitmap(const SkBitmap& bitmap, const gfx::Point& point) { add_draw_bitmap_with_paint(bitmap, point, default_paint_); } diff --git a/cc/test/skia_common.cc b/cc/test/skia_common.cc index a25df8d..bcb5f1a 100644 --- a/cc/test/skia_common.cc +++ b/cc/test/skia_common.cc @@ -50,10 +50,11 @@ void DrawDisplayList(unsigned char* buffer, list->Raster(&canvas, NULL, gfx::Rect(), 1.0f); } -void CreateDiscardableBitmap(const gfx::Size& size, SkBitmap* bitmap) { +skia::RefPtr<SkImage> CreateDiscardableImage(const gfx::Size& size) { const SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); - SkInstallDiscardablePixelRef(new TestImageGenerator(info), bitmap); + return skia::AdoptRef( + SkImage::NewFromGenerator(new TestImageGenerator(info))); } } // namespace cc diff --git a/cc/test/skia_common.h b/cc/test/skia_common.h index 2dc79b0..8603e10 100644 --- a/cc/test/skia_common.h +++ b/cc/test/skia_common.h @@ -7,9 +7,9 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "third_party/skia/include/core/SkFlattenable.h" -#include "third_party/skia/include/core/SkPixelRef.h" +#include "third_party/skia/include/core/SkImage.h" namespace gfx { class Rect; @@ -28,7 +28,7 @@ void DrawDisplayList(unsigned char* buffer, const gfx::Rect& layer_rect, scoped_refptr<DisplayItemList> list); -void CreateDiscardableBitmap(const gfx::Size& size, SkBitmap* bitmap); +skia::RefPtr<SkImage> CreateDiscardableImage(const gfx::Size& size); } // namespace cc diff --git a/cc/tiles/image_decode_controller.cc b/cc/tiles/image_decode_controller.cc index 6991fc1..601f3a0 100644 --- a/cc/tiles/image_decode_controller.cc +++ b/cc/tiles/image_decode_controller.cc @@ -12,11 +12,11 @@ namespace { class ImageDecodeTaskImpl : public ImageDecodeTask { public: ImageDecodeTaskImpl(ImageDecodeController* controller, - SkPixelRef* pixel_ref, + const SkImage* image, int layer_id, uint64_t source_prepare_tiles_id) : controller_(controller), - pixel_ref_(skia::SharePtr(pixel_ref)), + image_(skia::SharePtr(image)), layer_id_(layer_id), source_prepare_tiles_id_(source_prepare_tiles_id) {} @@ -25,18 +25,18 @@ class ImageDecodeTaskImpl : public ImageDecodeTask { TRACE_EVENT1("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "source_prepare_tiles_id", source_prepare_tiles_id_); devtools_instrumentation::ScopedImageDecodeTask image_decode_task( - pixel_ref_.get()); - controller_->DecodePixelRef(pixel_ref_.get()); + image_.get()); + controller_->DecodeImage(image_.get()); // Release the reference after decoding image to ensure that it is not kept // alive unless needed. - pixel_ref_.clear(); + image_.clear(); } // Overridden from TileTask: void ScheduleOnOriginThread(TileTaskClient* client) override {} void CompleteOnOriginThread(TileTaskClient* client) override { - controller_->OnImageDecodeTaskCompleted(layer_id_, pixel_ref_.get(), + controller_->OnImageDecodeTaskCompleted(layer_id_, image_.get(), !HasFinishedRunning()); } @@ -45,7 +45,7 @@ class ImageDecodeTaskImpl : public ImageDecodeTask { private: ImageDecodeController* controller_; - skia::RefPtr<SkPixelRef> pixel_ref_; + skia::RefPtr<const SkImage> image_; int layer_id_; uint64_t source_prepare_tiles_id_; @@ -58,31 +58,28 @@ ImageDecodeController::ImageDecodeController() {} ImageDecodeController::~ImageDecodeController() {} -scoped_refptr<ImageDecodeTask> ImageDecodeController::GetTaskForPixelRef( - const skia::PositionPixelRef& pixel_ref, +scoped_refptr<ImageDecodeTask> ImageDecodeController::GetTaskForImage( + const skia::PositionImage& image, int layer_id, uint64_t prepare_tiles_id) { - uint32_t generation_id = pixel_ref.pixel_ref->getGenerationID(); + uint32_t generation_id = image.image->uniqueID(); scoped_refptr<ImageDecodeTask>& decode_task = image_decode_tasks_[layer_id][generation_id]; if (!decode_task) - decode_task = - CreateTaskForPixelRef(pixel_ref.pixel_ref, layer_id, prepare_tiles_id); + decode_task = CreateTaskForImage(image.image, layer_id, prepare_tiles_id); return decode_task; } -scoped_refptr<ImageDecodeTask> ImageDecodeController::CreateTaskForPixelRef( - SkPixelRef* pixel_ref, +scoped_refptr<ImageDecodeTask> ImageDecodeController::CreateTaskForImage( + const SkImage* image, int layer_id, uint64_t prepare_tiles_id) { return make_scoped_refptr( - new ImageDecodeTaskImpl(this, pixel_ref, layer_id, prepare_tiles_id)); + new ImageDecodeTaskImpl(this, image, layer_id, prepare_tiles_id)); } -void ImageDecodeController::DecodePixelRef(SkPixelRef* pixel_ref) { - // This will cause the image referred to by pixel ref to be decoded. - pixel_ref->lockPixels(); - pixel_ref->unlockPixels(); +void ImageDecodeController::DecodeImage(const SkImage* image) { + image->preroll(); } void ImageDecodeController::AddLayerUsedCount(int layer_id) { @@ -99,26 +96,25 @@ void ImageDecodeController::SubtractLayerUsedCount(int layer_id) { } void ImageDecodeController::OnImageDecodeTaskCompleted(int layer_id, - SkPixelRef* pixel_ref, + const SkImage* image, bool was_canceled) { // If the task has successfully finished, then keep the task until the layer - // is no longer in use. This ensures that we only decode a pixel ref once. + // is no longer in use. This ensures that we only decode a image once. // TODO(vmpstr): Remove this when decode lifetime is controlled by cc. if (!was_canceled) return; // Otherwise, we have to clean up the task so that a new one can be created if - // we need to decode the pixel ref again. - LayerPixelRefTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id); + // we need to decode the image again. + LayerImageTaskMap::iterator layer_it = image_decode_tasks_.find(layer_id); if (layer_it == image_decode_tasks_.end()) return; - PixelRefTaskMap& pixel_ref_tasks = layer_it->second; - PixelRefTaskMap::iterator task_it = - pixel_ref_tasks.find(pixel_ref->getGenerationID()); - if (task_it == pixel_ref_tasks.end()) + ImageTaskMap& image_tasks = layer_it->second; + ImageTaskMap::iterator task_it = image_tasks.find(image->uniqueID()); + if (task_it == image_tasks.end()) return; - pixel_ref_tasks.erase(task_it); + image_tasks.erase(task_it); } } // namespace cc diff --git a/cc/tiles/image_decode_controller.h b/cc/tiles/image_decode_controller.h index a9f423e..cbd5af1 100644 --- a/cc/tiles/image_decode_controller.h +++ b/cc/tiles/image_decode_controller.h @@ -9,9 +9,8 @@ #include "base/memory/ref_counted.h" #include "cc/base/cc_export.h" #include "cc/raster/tile_task_runner.h" -#include "skia/ext/pixel_ref_utils.h" +#include "skia/ext/discardable_image_utils.h" #include "skia/ext/refptr.h" -#include "third_party/skia/include/core/SkPixelRef.h" namespace cc { @@ -20,13 +19,13 @@ class ImageDecodeController { ImageDecodeController(); ~ImageDecodeController(); - scoped_refptr<ImageDecodeTask> GetTaskForPixelRef( - const skia::PositionPixelRef& pixel_ref, + scoped_refptr<ImageDecodeTask> GetTaskForImage( + const skia::PositionImage& image, int layer_id, uint64_t prepare_tiles_id); // Note that this function has to remain thread safe. - void DecodePixelRef(SkPixelRef* pixel_ref); + void DecodeImage(const SkImage* image); // TODO(vmpstr): This should go away once the controller is decoding images // based on priority and memory. @@ -34,19 +33,17 @@ class ImageDecodeController { void SubtractLayerUsedCount(int layer_id); void OnImageDecodeTaskCompleted(int layer_id, - SkPixelRef* pixel_ref, + const SkImage* image, bool was_canceled); private: - scoped_refptr<ImageDecodeTask> CreateTaskForPixelRef( - SkPixelRef* pixel_ref, - int layer_id, - uint64_t prepare_tiles_id); + scoped_refptr<ImageDecodeTask> CreateTaskForImage(const SkImage* image, + int layer_id, + uint64_t prepare_tiles_id); - using PixelRefTaskMap = - base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask>>; - using LayerPixelRefTaskMap = base::hash_map<int, PixelRefTaskMap>; - LayerPixelRefTaskMap image_decode_tasks_; + using ImageTaskMap = base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask>>; + using LayerImageTaskMap = base::hash_map<int, ImageTaskMap>; + LayerImageTaskMap image_decode_tasks_; using LayerCountMap = base::hash_map<int, int>; LayerCountMap used_layer_counts_; diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc index 68066ac..6f798e6 100644 --- a/cc/tiles/tile_manager.cc +++ b/cc/tiles/tile_manager.cc @@ -677,12 +677,12 @@ scoped_refptr<RasterTask> TileManager::CreateRasterTask( // Create and queue all image decode tasks that this tile depends on. ImageDecodeTask::Vector decode_tasks; - std::vector<skia::PositionPixelRef> pixel_refs; - prioritized_tile.raster_source()->GatherPixelRefs( - tile->enclosing_layer_rect(), &pixel_refs); - for (const skia::PositionPixelRef& pixel_ref : pixel_refs) { - decode_tasks.push_back(image_decode_controller_.GetTaskForPixelRef( - pixel_ref, tile->layer_id(), prepare_tiles_count_)); + std::vector<skia::PositionImage> images; + prioritized_tile.raster_source()->GatherDiscardableImages( + tile->enclosing_layer_rect(), &images); + for (const skia::PositionImage& image : images) { + decode_tasks.push_back(image_decode_controller_.GetTaskForImage( + image, tile->layer_id(), prepare_tiles_count_)); } return make_scoped_refptr(new RasterTaskImpl( diff --git a/cc/trees/layer_tree_settings.cc b/cc/trees/layer_tree_settings.cc index 6987384f..a257a1b 100644 --- a/cc/trees/layer_tree_settings.cc +++ b/cc/trees/layer_tree_settings.cc @@ -68,7 +68,7 @@ LayerTreeSettings::LayerTreeSettings() record_full_layer(false), use_display_lists(false), verify_property_trees(false), - gather_pixel_refs(false), + gather_images(false), use_compositor_animation_timelines(false), invert_viewport_scroll_order(false), wait_for_beginframe_interval(true), diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h index 4b4f0a4..37b45f4 100644 --- a/cc/trees/layer_tree_settings.h +++ b/cc/trees/layer_tree_settings.h @@ -82,7 +82,7 @@ class CC_EXPORT LayerTreeSettings { bool record_full_layer; bool use_display_lists; bool verify_property_trees; - bool gather_pixel_refs; + bool gather_images; bool use_compositor_animation_timelines; bool invert_viewport_scroll_order; bool wait_for_beginframe_interval; |