diff --git a/cc/BUILD.gn b/cc/BUILD.gn index 65d2b69200c4cd..56d68f26be6e3d 100644 --- a/cc/BUILD.gn +++ b/cc/BUILD.gn @@ -282,8 +282,6 @@ cc_component("cc") { "trees/element_id.h", "trees/frame_rate_counter.cc", "trees/frame_rate_counter.h", - "trees/image_animation_controller.cc", - "trees/image_animation_controller.h", "trees/latency_info_swap_promise.cc", "trees/latency_info_swap_promise.h", "trees/latency_info_swap_promise_monitor.cc", @@ -412,8 +410,6 @@ cc_static_library("test_support") { "test/fake_output_surface.h", "test/fake_output_surface_client.cc", "test/fake_output_surface_client.h", - "test/fake_paint_image_generator.cc", - "test/fake_paint_image_generator.h", "test/fake_painted_scrollbar_layer.cc", "test/fake_painted_scrollbar_layer.h", "test/fake_picture_layer.cc", @@ -489,6 +485,8 @@ cc_static_library("test_support") { "test/stub_layer_tree_host_client.h", "test/stub_layer_tree_host_single_thread_client.cc", "test/stub_layer_tree_host_single_thread_client.h", + "test/stub_paint_image_generator.cc", + "test/stub_paint_image_generator.h", "test/task_graph_runner_test_template.cc", "test/task_graph_runner_test_template.h", "test/test_context_provider.cc", @@ -647,7 +645,6 @@ cc_test("cc_unittests") { "tiles/tile_priority_unittest.cc", "trees/blocking_task_runner_unittest.cc", "trees/damage_tracker_unittest.cc", - "trees/image_animation_controller_unittest.cc", "trees/layer_tree_frame_sink_unittest.cc", "trees/layer_tree_host_common_unittest.cc", "trees/layer_tree_host_impl_unittest.cc", diff --git a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc index e28e367bbdc5c3..c0690b68e9cd8d 100644 --- a/cc/benchmarks/rasterize_and_record_benchmark_impl.cc +++ b/cc/benchmarks/rasterize_and_record_benchmark_impl.cc @@ -60,7 +60,7 @@ void RunBenchmark(RasterSource* raster_source, PlaybackImageProvider image_provider(false, PaintImageIdFlatSet(), {}, image_decode_cache, - gfx::ColorSpace(), {}); + gfx::ColorSpace()); RasterSource::PlaybackSettings settings; settings.image_provider = &image_provider; diff --git a/cc/layers/picture_layer_impl.cc b/cc/layers/picture_layer_impl.cc index e64010639a0081..f81e7104f86ffe 100644 --- a/cc/layers/picture_layer_impl.cc +++ b/cc/layers/picture_layer_impl.cc @@ -20,7 +20,6 @@ #include "cc/debug/debug_colors.h" #include "cc/layers/append_quads_data.h" #include "cc/layers/solid_color_layer_impl.h" -#include "cc/paint/display_item_list.h" #include "cc/tiles/tile_manager.h" #include "cc/tiles/tiling_set_raster_queue_all.h" #include "cc/trees/layer_tree_impl.h" @@ -120,9 +119,6 @@ PictureLayerImpl::~PictureLayerImpl() { if (twin_layer_) twin_layer_->twin_layer_ = nullptr; layer_tree_impl()->UnregisterPictureLayerImpl(this); - - // Unregister for all images on the current raster source. - UnregisterAnimatedImages(); } void PictureLayerImpl::SetLayerMaskType(Layer::LayerMaskType mask_type) { @@ -602,27 +598,11 @@ void PictureLayerImpl::UpdateRasterSource( << " bounds " << bounds().ToString() << " pile " << raster_source->GetSize().ToString(); - // We have an updated recording if the DisplayItemList in the new RasterSource - // is different. - const bool recording_updated = - !raster_source_ || raster_source_->GetDisplayItemList() != - raster_source->GetDisplayItemList(); - - // Unregister for all images on the current raster source, if the recording - // was updated. - if (recording_updated) - UnregisterAnimatedImages(); - // The |raster_source_| is initially null, so have to check for that for the // first frame. bool could_have_tilings = raster_source_.get() && CanHaveTilings(); raster_source_.swap(raster_source); - // Register images from the new raster source, if the recording was updated. - // TODO(khushalsagar): UMA the number of animated images in layer? - if (recording_updated) - RegisterAnimatedImages(); - // The |new_invalidation| must be cleared before updating tilings since they // access the invalidation through the PictureLayerTilingClient interface. invalidation_.Clear(); @@ -766,26 +746,6 @@ gfx::Rect PictureLayerImpl::GetEnclosingRectInTargetSpace() const { return GetScaledEnclosingRectInTargetSpace(MaximumTilingContentsScale()); } -bool PictureLayerImpl::ShouldAnimate(PaintImage::Id paint_image_id) const { - DCHECK(raster_source_); - - // Only animate images for layers which HasValidTilePriorities. This check is - // important for 2 reasons: - // 1) It avoids doing additional work for layers we don't plan to rasterize - // and/or draw. The updated state will be pulled by the animation system - // if the draw properties change. - // 2) It eliminates considering layers on the recycle tree. Once the pending - // tree is activated, the layers on the recycle tree remain registered as - // animation drivers, but should not drive animations since they don't have - // updated draw properties. - // - // Additionally only animate images which are on-screen, animations are - // paused once they are not visible. - return HasValidTilePriorities() && - raster_source_->GetRectForImage(paint_image_id) - .Intersects(visible_layer_rect()); -} - gfx::Size PictureLayerImpl::CalculateTileSize( const gfx::Size& content_bounds) const { int max_texture_size = @@ -1542,38 +1502,4 @@ void PictureLayerImpl::InvalidateRegionForImages( "Invalidation", invalidation.ToString()); } -void PictureLayerImpl::RegisterAnimatedImages() { - if (!raster_source_ || !raster_source_->GetDisplayItemList()) - return; - - auto* controller = layer_tree_impl()->image_animation_controller(); - if (!controller) - return; - - const auto& metadata = raster_source_->GetDisplayItemList() - ->discardable_image_map() - .animated_images_metadata(); - for (const auto& data : metadata) { - // Only update the metadata from updated recordings received from a commit. - if (layer_tree_impl()->IsSyncTree()) - controller->UpdateAnimatedImage(data); - controller->RegisterAnimationDriver(data.paint_image_id, this); - } -} - -void PictureLayerImpl::UnregisterAnimatedImages() { - if (!raster_source_ || !raster_source_->GetDisplayItemList()) - return; - - auto* controller = layer_tree_impl()->image_animation_controller(); - if (!controller) - return; - - const auto& metadata = raster_source_->GetDisplayItemList() - ->discardable_image_map() - .animated_images_metadata(); - for (const auto& data : metadata) - controller->UnregisterAnimationDriver(data.paint_image_id, this); -} - } // namespace cc diff --git a/cc/layers/picture_layer_impl.h b/cc/layers/picture_layer_impl.h index 10ebaed0caa577..62cdcff7182c30 100644 --- a/cc/layers/picture_layer_impl.h +++ b/cc/layers/picture_layer_impl.h @@ -20,7 +20,6 @@ #include "cc/tiles/picture_layer_tiling.h" #include "cc/tiles/picture_layer_tiling_set.h" #include "cc/tiles/tiling_set_eviction_queue.h" -#include "cc/trees/image_animation_controller.h" namespace cc { @@ -28,10 +27,8 @@ class AppendQuadsData; class MicroBenchmarkImpl; class Tile; -class CC_EXPORT PictureLayerImpl - : public LayerImpl, - public PictureLayerTilingClient, - public ImageAnimationController::AnimationDriver { +class CC_EXPORT PictureLayerImpl : public LayerImpl, + public PictureLayerTilingClient { public: static std::unique_ptr Create(LayerTreeImpl* tree_impl, int id, Layer::LayerMaskType mask_type) { @@ -66,9 +63,6 @@ class CC_EXPORT PictureLayerImpl bool RequiresHighResToDraw() const override; gfx::Rect GetEnclosingRectInTargetSpace() const override; - // ImageAnimationController::AnimationDriver overrides. - bool ShouldAnimate(PaintImage::Id paint_image_id) const override; - void set_gpu_raster_max_texture_size(gfx::Size gpu_raster_max_texture_size) { gpu_raster_max_texture_size_ = gpu_raster_max_texture_size; } @@ -113,8 +107,6 @@ class CC_EXPORT PictureLayerImpl bool RasterSourceUsesLCDTextForTesting() const { return can_use_lcd_text_; } - const Region& InvalidationForTesting() const { return invalidation_; } - protected: PictureLayerImpl(LayerTreeImpl* tree_impl, int id, @@ -144,9 +136,6 @@ class CC_EXPORT PictureLayerImpl float MaximumTilingContentsScale() const; std::unique_ptr CreatePictureLayerTilingSet(); - void RegisterAnimatedImages(); - void UnregisterAnimatedImages(); - PictureLayerImpl* twin_layer_; std::unique_ptr tilings_; diff --git a/cc/layers/picture_layer_impl_unittest.cc b/cc/layers/picture_layer_impl_unittest.cc index 465463d7c97a19..f80d13ca917b22 100644 --- a/cc/layers/picture_layer_impl_unittest.cc +++ b/cc/layers/picture_layer_impl_unittest.cc @@ -29,7 +29,6 @@ #include "cc/test/fake_recording_source.h" #include "cc/test/geometry_test_utils.h" #include "cc/test/layer_test_common.h" -#include "cc/test/skia_common.h" #include "cc/test/test_layer_tree_host_base.h" #include "cc/test/test_task_graph_runner.h" #include "cc/test/test_web_graphics_context_3d.h" @@ -85,7 +84,6 @@ class PictureLayerImplTest : public TestLayerTreeHostBase { settings.create_low_res_tiling = true; settings.resource_settings.buffer_to_texture_target_map = viz::DefaultBufferToTextureTargetMapForTesting(); - settings.enable_image_animations = true; return settings; } @@ -5201,59 +5199,5 @@ TEST_F(PictureLayerImplTest, ChangeRasterTranslationNukeActiveLayerTiles) { } } -TEST_F(PictureLayerImplTest, AnimatedImages) { - gfx::Size layer_bounds(1000, 1000); - - // Set up a raster source with 2 animated images. - auto recording_source = FakeRecordingSource::CreateRecordingSource( - gfx::Rect(layer_bounds), layer_bounds); - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(1)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(1))}; - PaintImage image1 = CreateAnimatedImage(gfx::Size(200, 200), frames); - PaintImage image2 = CreateAnimatedImage(gfx::Size(200, 200), frames); - recording_source->add_draw_image(image1, gfx::Point(100, 100)); - recording_source->add_draw_image(image2, gfx::Point(500, 500)); - recording_source->Rerecord(); - scoped_refptr raster_source = - recording_source->CreateRasterSource(); - - // All images should be registered on the pending layer. - SetupPendingTree(raster_source, gfx::Size(), Region(gfx::Rect(layer_bounds))); - auto* controller = host_impl()->image_animation_controller(); - EXPECT_EQ(controller->GetDriversForTesting(image1.stable_id()) - .count(pending_layer()), - 1u); - EXPECT_EQ(controller->GetDriversForTesting(image2.stable_id()) - .count(pending_layer()), - 1u); - - // Make only the first image visible and verify that only this image is - // animated. - gfx::Rect visible_rect(0, 0, 300, 300); - pending_layer()->set_visible_layer_rect(visible_rect); - EXPECT_TRUE(pending_layer()->ShouldAnimate(image1.stable_id())); - EXPECT_FALSE(pending_layer()->ShouldAnimate(image2.stable_id())); - - // Now activate and make sure the active layer is registered as well. - ActivateTree(); - active_layer()->set_visible_layer_rect(visible_rect); - EXPECT_EQ(controller->GetDriversForTesting(image1.stable_id()) - .count(active_layer()), - 1u); - EXPECT_EQ(controller->GetDriversForTesting(image2.stable_id()) - .count(active_layer()), - 1u); - - // Once activated, only the active layer should drive animations for these - // images. Since DrawProperties are not updated on the recycle tree, it has - // stale state for visibility of images. - ASSERT_EQ(old_pending_layer()->visible_layer_rect(), visible_rect); - EXPECT_FALSE(old_pending_layer()->ShouldAnimate(image1.stable_id())); - EXPECT_FALSE(old_pending_layer()->ShouldAnimate(image2.stable_id())); - EXPECT_TRUE(active_layer()->ShouldAnimate(image1.stable_id())); - EXPECT_FALSE(active_layer()->ShouldAnimate(image2.stable_id())); -} - } // namespace } // namespace cc diff --git a/cc/layers/recording_source_unittest.cc b/cc/layers/recording_source_unittest.cc index 82c424ff8efadf..002ec5c90991c1 100644 --- a/cc/layers/recording_source_unittest.cc +++ b/cc/layers/recording_source_unittest.cc @@ -111,8 +111,7 @@ TEST(RecordingSourceTest, DiscardableImagesWithTransform) { std::vector images; raster_source->GetDiscardableImagesInRect(gfx::Rect(130, 0, 128, 128), &images); - DrawImage image(*images[0], scale, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + DrawImage image(*images[0], scale, DefaultColorSpace()); EXPECT_EQ(1u, images.size()); EXPECT_FLOAT_EQ(scale, image.scale().width()); EXPECT_FLOAT_EQ(scale, image.scale().height()); diff --git a/cc/paint/discardable_image_map.h b/cc/paint/discardable_image_map.h index d3b66aaa40b714..b3113020bdf7a9 100644 --- a/cc/paint/discardable_image_map.h +++ b/cc/paint/discardable_image_map.h @@ -30,7 +30,7 @@ class PaintOpBuffer; // rect and get back a list of DrawImages in that rect. class CC_PAINT_EXPORT DiscardableImageMap { public: - struct CC_PAINT_EXPORT AnimatedImageMetadata { + struct AnimatedImageMetadata { AnimatedImageMetadata(PaintImage::Id paint_image_id, PaintImage::CompletionState completion_state, std::vector frames, diff --git a/cc/paint/discardable_image_map_unittest.cc b/cc/paint/discardable_image_map_unittest.cc index 0e8a6d20e20744..fcfc0743ae1c3e 100644 --- a/cc/paint/discardable_image_map_unittest.cc +++ b/cc/paint/discardable_image_map_unittest.cc @@ -9,7 +9,6 @@ #include #include "base/memory/ref_counted.h" -#include "base/test/gtest_util.h" #include "base/values.h" #include "cc/base/region.h" #include "cc/paint/paint_flags.h" @@ -61,8 +60,7 @@ class DiscardableImageMapTest : public testing::Test { image_map.GetDiscardableImagesInRect(rect, &draw_image_ptrs); std::vector draw_images; for (const auto* image : draw_image_ptrs) - draw_images.push_back(DrawImage( - *image, 1.f, PaintImage::kDefaultFrameIndex, target_color_space)); + draw_images.push_back(DrawImage(*image, 1.f, target_color_space)); std::vector position_draw_images; for (DrawImage& image : image_map.images_rtree_.Search(rect)) { @@ -700,16 +698,11 @@ TEST_F(DiscardableImageMapTest, GathersAnimatedImages) { FakeContentLayerClient content_layer_client; content_layer_client.set_bounds(visible_rect.size()); - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - gfx::Size image_size(100, 100); PaintImage static_image = CreateDiscardablePaintImage(image_size); PaintImage animated_loop_none = - CreateAnimatedImage(image_size, frames, kAnimationNone); - PaintImage animation_loop_infinite = - CreateAnimatedImage(image_size, frames, 1u); + CreateAnimatedImage(image_size, {FrameMetadata()}, kAnimationNone); + PaintImage animation_loop_infinite = CreateAnimatedImage(image_size); PaintFlags flags; content_layer_client.add_draw_image(static_image, gfx::Point(0, 0), flags); @@ -734,17 +727,6 @@ TEST_F(DiscardableImageMapTest, GathersAnimatedImages) { animation_loop_infinite.GetFrameMetadata()); EXPECT_EQ(animated_images_metadata[0].repetition_count, animation_loop_infinite.repetition_count()); - - std::vector images; - display_list->discardable_image_map().GetDiscardableImagesInRect(visible_rect, - &images); - ASSERT_EQ(images.size(), 3u); - EXPECT_EQ(images[0]->paint_image(), static_image); - EXPECT_DCHECK_DEATH(images[0]->frame_index()); - EXPECT_EQ(images[1]->paint_image(), animated_loop_none); - EXPECT_DCHECK_DEATH(images[1]->frame_index()); - EXPECT_EQ(images[2]->paint_image(), animation_loop_infinite); - EXPECT_DCHECK_DEATH(images[2]->frame_index()); } class DiscardableImageMapColorSpaceTest diff --git a/cc/paint/draw_image.cc b/cc/paint/draw_image.cc index a1a78af3b6c8c1..7b7314b3cb1b9e 100644 --- a/cc/paint/draw_image.cc +++ b/cc/paint/draw_image.cc @@ -32,19 +32,16 @@ DrawImage::DrawImage(PaintImage image, const SkIRect& src_rect, SkFilterQuality filter_quality, const SkMatrix& matrix, - base::Optional frame_index, const base::Optional& color_space) : paint_image_(std::move(image)), src_rect_(src_rect), filter_quality_(filter_quality), - frame_index_(frame_index), target_color_space_(color_space) { matrix_is_decomposable_ = ExtractScale(matrix, &scale_); } DrawImage::DrawImage(const DrawImage& other, float scale_adjustment, - size_t frame_index, const gfx::ColorSpace& color_space) : paint_image_(other.paint_image_), src_rect_(other.src_rect_), @@ -52,7 +49,6 @@ DrawImage::DrawImage(const DrawImage& other, scale_(SkSize::Make(other.scale_.width() * scale_adjustment, other.scale_.height() * scale_adjustment)), matrix_is_decomposable_(other.matrix_is_decomposable_), - frame_index_(frame_index), target_color_space_(color_space) {} DrawImage::DrawImage(const DrawImage& other) = default; diff --git a/cc/paint/draw_image.h b/cc/paint/draw_image.h index 81c45d1cfd25a2..58c46d98b58377 100644 --- a/cc/paint/draw_image.h +++ b/cc/paint/draw_image.h @@ -25,13 +25,11 @@ class CC_PAINT_EXPORT DrawImage { const SkIRect& src_rect, SkFilterQuality filter_quality, const SkMatrix& matrix, - base::Optional frame_index = base::nullopt, const base::Optional& color_space = base::nullopt); // Constructs a DrawImage from |other| by adjusting its scale and setting a // new color_space. DrawImage(const DrawImage& other, float scale_adjustment, - size_t frame_index, const gfx::ColorSpace& color_space); DrawImage(const DrawImage& other); DrawImage(DrawImage&& other); @@ -52,11 +50,7 @@ class CC_PAINT_EXPORT DrawImage { return *target_color_space_; } PaintImage::FrameKey frame_key() const { - return paint_image_.GetKeyForFrame(frame_index()); - } - size_t frame_index() const { - DCHECK(frame_index_.has_value()); - return frame_index_.value(); + return paint_image_.GetKeyForFrame(paint_image_.frame_index()); } private: @@ -65,7 +59,6 @@ class CC_PAINT_EXPORT DrawImage { SkFilterQuality filter_quality_; SkSize scale_; bool matrix_is_decomposable_; - base::Optional frame_index_; base::Optional target_color_space_; }; diff --git a/cc/paint/paint_image.cc b/cc/paint/paint_image.cc index f941d608baf079..b18eb20b725a11 100644 --- a/cc/paint/paint_image.cc +++ b/cc/paint/paint_image.cc @@ -18,9 +18,6 @@ base::AtomicSequenceNumber s_next_id_; base::AtomicSequenceNumber s_next_content_id_; } // namespace -const int PaintImage::kNonLazyStableId = -1; -const size_t PaintImage::kDefaultFrameIndex = 0u; - PaintImage::PaintImage() = default; PaintImage::PaintImage(const PaintImage& other) = default; PaintImage::PaintImage(PaintImage&& other) = default; @@ -121,8 +118,7 @@ SkImageInfo PaintImage::CreateDecodeImageInfo(const SkISize& size, bool PaintImage::Decode(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const { + sk_sp color_space) const { // We only support decode to supported decode size. DCHECK(info->dimensions() == GetSupportedDecodeSize(info->dimensions())); @@ -133,15 +129,13 @@ bool PaintImage::Decode(void* memory, // requested size into the space of the original image. For now, fallback to // DecodeFromSkImage(). if (paint_image_generator_ && subset_rect_.IsEmpty()) - return DecodeFromGenerator(memory, info, std::move(color_space), - frame_index); - return DecodeFromSkImage(memory, info, std::move(color_space), frame_index); + return DecodeFromGenerator(memory, info, std::move(color_space)); + return DecodeFromSkImage(memory, info, std::move(color_space)); } bool PaintImage::DecodeFromGenerator(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const { + sk_sp color_space) const { DCHECK(subset_rect_.IsEmpty()); // First convert the info to have the requested color space, since the decoder @@ -157,7 +151,7 @@ bool PaintImage::DecodeFromGenerator(void* memory, bool result = paint_image_generator_->GetPixels(n32info, n32memory.get(), n32info.minRowBytes(), - frame_index, unique_id()); + frame_index(), unique_id()); if (!result) return false; @@ -178,14 +172,13 @@ bool PaintImage::DecodeFromGenerator(void* memory, } return paint_image_generator_->GetPixels(*info, memory, info->minRowBytes(), - frame_index, unique_id()); + frame_index(), unique_id()); } bool PaintImage::DecodeFromSkImage(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const { - auto image = GetSkImageForFrame(frame_index); + sk_sp color_space) const { + auto image = GetSkImage(); DCHECK(image); if (color_space) { image = @@ -203,7 +196,7 @@ bool PaintImage::DecodeFromSkImage(void* memory, bool PaintImage::ShouldAnimate() const { return animation_type_ == AnimationType::ANIMATED && - repetition_count_ != kAnimationNone && FrameCount() > 1; + repetition_count_ != kAnimationNone; } PaintImage::FrameKey PaintImage::GetKeyForFrame(size_t frame_index) const { @@ -237,19 +230,6 @@ size_t PaintImage::FrameCount() const { : 1u; } -sk_sp PaintImage::GetSkImageForFrame(size_t index) const { - DCHECK_LT(index, FrameCount()); - - if (index == frame_index_) - return GetSkImage(); - - sk_sp image = SkImage::MakeFromGenerator( - base::MakeUnique(paint_image_generator_, index)); - if (!subset_rect_.IsEmpty()) - image = image->makeSubset(gfx::RectToSkIRect(subset_rect_)); - return image; -} - std::string PaintImage::ToString() const { std::ostringstream str; str << "sk_image_: " << sk_image_ << " paint_record_: " << paint_record_ diff --git a/cc/paint/paint_image.h b/cc/paint/paint_image.h index 83e237bc4acbde..9eeff94eacda36 100644 --- a/cc/paint/paint_image.h +++ b/cc/paint/paint_image.h @@ -39,11 +39,11 @@ class CC_PAINT_EXPORT PaintImage { // An id that can be used for all non-lazy images. Note that if an image is // not lazy, it does not mean that this id must be used; one can still use // GetNextId to generate a stable id for such images. - static const Id kNonLazyStableId; + static const Id kNonLazyStableId = -1; // The default frame index to use if no index is provided. For multi-frame // images, this would imply the first frame of the animation. - static const size_t kDefaultFrameIndex; + static const size_t kDefaultFrameIndex = 0; class CC_PAINT_EXPORT FrameKey { public: @@ -53,7 +53,6 @@ class CC_PAINT_EXPORT PaintImage { uint64_t hash() const { return hash_; } std::string ToString() const; - size_t frame_index() const { return frame_index_; } private: ContentId content_id_; @@ -113,8 +112,7 @@ class CC_PAINT_EXPORT PaintImage { // is texture backed. bool Decode(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const; + sk_sp color_space) const; Id stable_id() const { return id_; } const sk_sp& GetSkImage() const; @@ -144,9 +142,6 @@ class CC_PAINT_EXPORT PaintImage { // Returns the total number of frames known to exist in this image. size_t FrameCount() const; - // Returns an SkImage for the frame at |index|. - sk_sp GetSkImageForFrame(size_t index) const; - std::string ToString() const; private: @@ -156,12 +151,10 @@ class CC_PAINT_EXPORT PaintImage { bool DecodeFromGenerator(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const; + sk_sp color_space) const; bool DecodeFromSkImage(void* memory, SkImageInfo* info, - sk_sp color_space, - size_t frame_index) const; + sk_sp color_space) const; sk_sp sk_image_; diff --git a/cc/paint/paint_image_builder.cc b/cc/paint/paint_image_builder.cc index da6387db339061..399ac0ba4ba555 100644 --- a/cc/paint/paint_image_builder.cc +++ b/cc/paint/paint_image_builder.cc @@ -43,13 +43,6 @@ PaintImage PaintImageBuilder::TakePaintImage() const { DCHECK(!paint_image_.sk_image_); DCHECK(!paint_image_.paint_record_); } - - if (paint_image_.ShouldAnimate()) { - DCHECK(paint_image_.paint_image_generator_) - << "Animated images must provide a generator"; - for (const auto& frame : paint_image_.GetFrameMetadata()) - DCHECK_GT(frame.duration, base::TimeDelta()); - } #endif return std::move(paint_image_); diff --git a/cc/paint/paint_image_unittest.cc b/cc/paint/paint_image_unittest.cc index d3f743bb81ee9a..0fe9a4ffda1111 100644 --- a/cc/paint/paint_image_unittest.cc +++ b/cc/paint/paint_image_unittest.cc @@ -5,8 +5,6 @@ #include "cc/paint/paint_image.h" #include "base/test/gtest_util.h" -#include "cc/paint/paint_image_builder.h" -#include "cc/test/fake_paint_image_generator.h" #include "cc/test/skia_common.h" #include "testing/gtest/include/gtest/gtest.h" @@ -33,42 +31,4 @@ TEST(PaintImageTest, Subsetting) { EXPECT_DCHECK_DEATH(image.MakeSubset(gfx::Rect())); } -TEST(PaintImageTest, DecodesCorrectFrames) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - sk_sp generator = - sk_make_sp(SkImageInfo::MakeN32Premul(10, 10), - frames); - PaintImage image = PaintImageBuilder() - .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(generator) - .set_frame_index(0u) - .TakePaintImage(); - - // The recorded index is 0u but ask for 1u frame. - SkImageInfo info = SkImageInfo::MakeN32Premul(10, 10); - std::vector memory(info.getSafeSize(info.minRowBytes())); - image.Decode(memory.data(), &info, nullptr, 1u); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(1u), 1u); - generator->reset_frames_decoded(); - - // Subsetted. - PaintImage subset_image = image.MakeSubset(gfx::Rect(0, 0, 5, 5)); - SkImageInfo subset_info = info.makeWH(5, 5); - subset_image.Decode(memory.data(), &subset_info, nullptr, 1u); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(1u), 1u); - generator->reset_frames_decoded(); - - // Not N32 color type. - info.makeColorType(kRGB_565_SkColorType); - memory = std::vector(info.getSafeSize(info.minRowBytes())); - image.Decode(memory.data(), &info, nullptr, 1u); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(1u), 1u); - generator->reset_frames_decoded(); -} - } // namespace cc diff --git a/cc/raster/playback_image_provider.cc b/cc/raster/playback_image_provider.cc index 86bc53b6dc7303..d6856fdc994f9d 100644 --- a/cc/raster/playback_image_provider.cc +++ b/cc/raster/playback_image_provider.cc @@ -22,14 +22,12 @@ PlaybackImageProvider::PlaybackImageProvider( PaintImageIdFlatSet images_to_skip, std::vector at_raster_images, ImageDecodeCache* cache, - const gfx::ColorSpace& target_color_space, - base::flat_map image_to_current_frame_index) + const gfx::ColorSpace& target_color_space) : skip_all_images_(skip_all_images), images_to_skip_(std::move(images_to_skip)), at_raster_images_(std::move(at_raster_images)), cache_(cache), - target_color_space_(target_color_space), - image_to_current_frame_index_(std::move(image_to_current_frame_index)) { + target_color_space_(target_color_space) { DCHECK(cache_); } @@ -79,14 +77,8 @@ PlaybackImageProvider::GetDecodedDrawImage(const DrawImage& draw_image) { SkSize::Make(1.f, 1.f), draw_image.filter_quality())); } - const auto& it = image_to_current_frame_index_.find(paint_image.stable_id()); - size_t frame_index = it == image_to_current_frame_index_.end() - ? paint_image.frame_index() - : it->second; - - DrawImage adjusted_image(draw_image, 1.f, frame_index, target_color_space_); + DrawImage adjusted_image(draw_image, 1.f, target_color_space_); auto decoded_draw_image = cache_->GetDecodedImageForDraw(adjusted_image); - return ScopedDecodedDrawImage( decoded_draw_image, base::BindOnce(&UnrefImageFromCache, std::move(adjusted_image), cache_)); diff --git a/cc/raster/playback_image_provider.h b/cc/raster/playback_image_provider.h index ddd2633c0df23a..bb2fc3411a19b5 100644 --- a/cc/raster/playback_image_provider.h +++ b/cc/raster/playback_image_provider.h @@ -5,7 +5,6 @@ #ifndef CC_RASTER_PLAYBACK_IMAGE_PROVIDER_H_ #define CC_RASTER_PLAYBACK_IMAGE_PROVIDER_H_ -#include "base/containers/flat_map.h" #include "cc/cc_export.h" #include "cc/paint/image_id.h" #include "cc/paint/image_provider.h" @@ -22,13 +21,11 @@ class ImageDecodeCache; // only be used for lazy generated images. class CC_EXPORT PlaybackImageProvider : public ImageProvider { public: - PlaybackImageProvider( - bool skip_all_images, - PaintImageIdFlatSet images_to_skip, - std::vector at_raster_images, - ImageDecodeCache* cache, - const gfx::ColorSpace& taget_color_space, - base::flat_map image_to_current_frame_index); + PlaybackImageProvider(bool skip_all_images, + PaintImageIdFlatSet images_to_skip, + std::vector at_raster_images, + ImageDecodeCache* cache, + const gfx::ColorSpace& taget_color_space); ~PlaybackImageProvider() override; void BeginRaster() override; @@ -49,7 +46,6 @@ class CC_EXPORT PlaybackImageProvider : public ImageProvider { std::vector decoded_at_raster_; ImageDecodeCache* cache_; gfx::ColorSpace target_color_space_; - base::flat_map image_to_current_frame_index_; DISALLOW_COPY_AND_ASSIGN(PlaybackImageProvider); }; diff --git a/cc/raster/playback_image_provider_unittest.cc b/cc/raster/playback_image_provider_unittest.cc index 153b4845f8a573..42d7783494cf3a 100644 --- a/cc/raster/playback_image_provider_unittest.cc +++ b/cc/raster/playback_image_provider_unittest.cc @@ -30,7 +30,6 @@ class MockDecodeCache : public StubDecodeCache { DecodedDrawImage GetDecodedImageForDraw( const DrawImage& draw_image) override { - last_image_ = draw_image; images_decoded_++; refed_image_count_++; return CreateDecode(); @@ -45,17 +44,15 @@ class MockDecodeCache : public StubDecodeCache { int refed_image_count() const { return refed_image_count_; } int images_decoded() const { return images_decoded_; } - const DrawImage& last_image() { return last_image_; } private: int refed_image_count_ = 0; int images_decoded_ = 0; - DrawImage last_image_; }; TEST(PlaybackImageProviderTest, SkipsAllImages) { MockDecodeCache cache; - PlaybackImageProvider provider(true, {}, {}, &cache, gfx::ColorSpace(), {}); + PlaybackImageProvider provider(true, {}, {}, &cache, gfx::ColorSpace()); provider.BeginRaster(); SkIRect rect = SkIRect::MakeWH(10, 10); @@ -80,7 +77,7 @@ TEST(PlaybackImageProviderTest, SkipsSomeImages) { MockDecodeCache cache; PaintImage skip_image = CreateDiscardablePaintImage(gfx::Size(10, 10)); PlaybackImageProvider provider(false, {skip_image.stable_id()}, {}, &cache, - gfx::ColorSpace(), {}); + gfx::ColorSpace()); provider.BeginRaster(); SkIRect rect = SkIRect::MakeWH(10, 10); @@ -93,7 +90,7 @@ TEST(PlaybackImageProviderTest, SkipsSomeImages) { TEST(PlaybackImageProviderTest, RefAndUnrefDecode) { MockDecodeCache cache; - PlaybackImageProvider provider(false, {}, {}, &cache, gfx::ColorSpace(), {}); + PlaybackImageProvider provider(false, {}, {}, &cache, gfx::ColorSpace()); provider.BeginRaster(); { @@ -123,7 +120,7 @@ TEST(PlaybackImageProviderTest, AtRasterImages) { size, nullptr, rect, kMedium_SkFilterQuality, matrix); PlaybackImageProvider provider(false, {}, {draw_image1, draw_image2}, &cache, - gfx::ColorSpace(), {}); + gfx::ColorSpace()); EXPECT_EQ(cache.refed_image_count(), 0); provider.BeginRaster(); @@ -135,29 +132,5 @@ TEST(PlaybackImageProviderTest, AtRasterImages) { EXPECT_EQ(cache.images_decoded(), 2); } -TEST(PlaybackImageProviderTest, SwapsGivenFrames) { - MockDecodeCache cache; - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - PaintImage image = CreateAnimatedImage(gfx::Size(10, 10), frames); - - base::flat_map image_to_frame; - image_to_frame[image.stable_id()] = 1u; - PlaybackImageProvider provider(false, {}, {}, &cache, gfx::ColorSpace(), - image_to_frame); - provider.BeginRaster(); - - SkIRect rect = SkIRect::MakeWH(10, 10); - SkMatrix matrix = SkMatrix::I(); - DrawImage draw_image(image, rect, kMedium_SkFilterQuality, matrix); - provider.GetDecodedDrawImage(draw_image); - ASSERT_TRUE(cache.last_image().paint_image()); - ASSERT_EQ(cache.last_image().paint_image(), image); - ASSERT_EQ(cache.last_image().frame_index(), 1u); - - provider.EndRaster(); -} - } // namespace } // namespace cc diff --git a/cc/raster/raster_source_unittest.cc b/cc/raster/raster_source_unittest.cc index b89083e9a8419c..b6de90c478d683 100644 --- a/cc/raster/raster_source_unittest.cc +++ b/cc/raster/raster_source_unittest.cc @@ -215,8 +215,7 @@ TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { std::vector images; raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), &images); EXPECT_EQ(1u, images.size()); - DrawImage image(*images[0], 1.f, PaintImage::kDefaultFrameIndex, - target_color_space); + DrawImage image(*images[0], 1.f, target_color_space); EXPECT_EQ(discardable_image[0][0], images[0]->paint_image()); EXPECT_EQ(target_color_space, image.target_color_space()); } @@ -226,8 +225,7 @@ TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { std::vector images; raster->GetDiscardableImagesInRect(gfx::Rect(260, 260, 256, 256), &images); EXPECT_EQ(1u, images.size()); - DrawImage image(*images[0], 1.f, PaintImage::kDefaultFrameIndex, - target_color_space); + DrawImage image(*images[0], 1.f, target_color_space); EXPECT_EQ(discardable_image[1][1], images[0]->paint_image()); EXPECT_EQ(target_color_space, image.target_color_space()); } diff --git a/cc/scheduler/scheduler_state_machine.cc b/cc/scheduler/scheduler_state_machine.cc index f101af62190563..494ecabe879b00 100644 --- a/cc/scheduler/scheduler_state_machine.cc +++ b/cc/scheduler/scheduler_state_machine.cc @@ -592,8 +592,6 @@ bool SchedulerStateMachine::ShouldPerformImplSideInvalidation() const { // Only perform impl side invalidation after the frame ends so that we wait // for any commit to happen before invalidating. - // TODO(khushalsagar): Invalidate at the beginning of the frame if there is no - // commit request from the main thread. if (begin_impl_frame_state_ != BEGIN_IMPL_FRAME_STATE_INSIDE_DEADLINE) return false; diff --git a/cc/test/fake_tile_manager_client.cc b/cc/test/fake_tile_manager_client.cc index 28bd30478fc24d..8325acc039992f 100644 --- a/cc/test/fake_tile_manager_client.cc +++ b/cc/test/fake_tile_manager_client.cc @@ -29,10 +29,4 @@ gfx::ColorSpace FakeTileManagerClient::GetRasterColorSpace() const { return gfx::ColorSpace(); } -size_t FakeTileManagerClient::GetFrameIndexForImage( - const PaintImage& paint_image, - WhichTree tree) const { - return paint_image.frame_index(); -} - } // namespace cc diff --git a/cc/test/fake_tile_manager_client.h b/cc/test/fake_tile_manager_client.h index c618a39dccca56..3597d7952e2ae7 100644 --- a/cc/test/fake_tile_manager_client.h +++ b/cc/test/fake_tile_manager_client.h @@ -29,8 +29,6 @@ class FakeTileManagerClient : public TileManagerClient { void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override {} gfx::ColorSpace GetRasterColorSpace() const override; void RequestImplSideInvalidationForCheckerImagedTiles() override {} - size_t GetFrameIndexForImage(const PaintImage& paint_image, - WhichTree tree) const override; }; } // namespace cc diff --git a/cc/test/skia_common.cc b/cc/test/skia_common.cc index 0219b14fabfcbb..2effb65f3cfb1a 100644 --- a/cc/test/skia_common.cc +++ b/cc/test/skia_common.cc @@ -11,7 +11,7 @@ #include "cc/paint/draw_image.h" #include "cc/paint/paint_canvas.h" #include "cc/paint/paint_image_builder.h" -#include "cc/test/fake_paint_image_generator.h" +#include "cc/test/stub_paint_image_generator.h" #include "third_party/skia/include/core/SkImageGenerator.h" #include "third_party/skia/include/core/SkPixmap.h" #include "ui/gfx/geometry/rect.h" @@ -19,6 +19,30 @@ namespace cc { +namespace { + +class TestImageGenerator : public StubPaintImageGenerator { + public: + explicit TestImageGenerator(const SkImageInfo& info) + : StubPaintImageGenerator(info), + image_backing_memory_(info.getSafeSize(info.minRowBytes()), 0), + image_pixmap_(info, image_backing_memory_.data(), info.minRowBytes()) {} + + bool GetPixels(const SkImageInfo& info, + void* pixels, + size_t rowBytes, + size_t frame_index, + uint32_t lazy_pixel_ref) override { + return image_pixmap_.readPixels(info, pixels, rowBytes, 0, 0); + } + + private: + std::vector image_backing_memory_; + SkPixmap image_pixmap_; +}; + +} // anonymous namespace + void DrawDisplayList(unsigned char* buffer, const gfx::Rect& layer_rect, scoped_refptr list) { @@ -47,7 +71,7 @@ bool AreDisplayListDrawingResultsSame(const gfx::Rect& layer_rect, } sk_sp CreatePaintImageGenerator(const gfx::Size& size) { - return sk_make_sp( + return sk_make_sp( SkImageInfo::MakeN32Premul(size.width(), size.height())); } @@ -55,7 +79,7 @@ PaintImage CreateDiscardablePaintImage(const gfx::Size& size, sk_sp color_space) { return PaintImageBuilder() .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(sk_make_sp( + .set_paint_image_generator(sk_make_sp( SkImageInfo::MakeN32Premul(size.width(), size.height(), color_space))) .TakePaintImage(); } @@ -74,16 +98,13 @@ DrawImage CreateDiscardableDrawImage(const gfx::Size& size, PaintImage CreateAnimatedImage(const gfx::Size& size, std::vector frames, - int repetition_count, - size_t frame_index) { + int repetition_count) { return PaintImageBuilder() .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(sk_make_sp( - SkImageInfo::MakeN32Premul(size.width(), size.height()), - std::move(frames))) + .set_paint_image_generator(sk_make_sp( + SkImageInfo::MakeN32Premul(size.width(), size.height()))) .set_animation_type(PaintImage::AnimationType::ANIMATED) .set_repetition_count(repetition_count) - .set_frame_index(frame_index) .TakePaintImage(); } diff --git a/cc/test/skia_common.h b/cc/test/skia_common.h index b0c3241efce5a2..4cc4429ee44131 100644 --- a/cc/test/skia_common.h +++ b/cc/test/skia_common.h @@ -45,9 +45,8 @@ DrawImage CreateDiscardableDrawImage(const gfx::Size& size, PaintImage CreateAnimatedImage( const gfx::Size& size, - std::vector frames, - int repetition_count = kAnimationLoopInfinite, - size_t frame_index = PaintImage::kDefaultFrameIndex); + std::vector frames = {FrameMetadata()}, + int repetition_count = kAnimationLoopInfinite); } // namespace cc diff --git a/cc/test/fake_paint_image_generator.cc b/cc/test/stub_paint_image_generator.cc similarity index 50% rename from cc/test/fake_paint_image_generator.cc rename to cc/test/stub_paint_image_generator.cc index bf0412d1300b79..dce837217757f8 100644 --- a/cc/test/fake_paint_image_generator.cc +++ b/cc/test/stub_paint_image_generator.cc @@ -2,42 +2,31 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include +#include "cc/test/stub_paint_image_generator.h" namespace cc { -FakePaintImageGenerator::FakePaintImageGenerator( - const SkImageInfo& info, - std::vector frames) - : PaintImageGenerator(info, std::move(frames)), - image_backing_memory_(info.getSafeSize(info.minRowBytes()), 0), - image_pixmap_(info, image_backing_memory_.data(), info.minRowBytes()) {} - -FakePaintImageGenerator::~FakePaintImageGenerator() = default; - -sk_sp FakePaintImageGenerator::GetEncodedData() const { +sk_sp StubPaintImageGenerator::GetEncodedData() const { return nullptr; } -bool FakePaintImageGenerator::GetPixels(const SkImageInfo& info, +bool StubPaintImageGenerator::GetPixels(const SkImageInfo& info, void* pixels, size_t row_bytes, size_t frame_index, uint32_t lazy_pixel_ref) { - frames_decoded_.insert(frame_index); - return true; + return false; } -bool FakePaintImageGenerator::QueryYUV8(SkYUVSizeInfo* info, +bool StubPaintImageGenerator::QueryYUV8(SkYUVSizeInfo* info, SkYUVColorSpace* color_space) const { return false; } -bool FakePaintImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& info, +bool StubPaintImageGenerator::GetYUV8Planes(const SkYUVSizeInfo& info, void* planes[3], size_t frame_index, uint32_t lazy_pixel_ref) { - NOTREACHED(); return false; } diff --git a/cc/test/fake_paint_image_generator.h b/cc/test/stub_paint_image_generator.h similarity index 51% rename from cc/test/fake_paint_image_generator.h rename to cc/test/stub_paint_image_generator.h index c8f44915775749..0d566cd21435ae 100644 --- a/cc/test/fake_paint_image_generator.h +++ b/cc/test/stub_paint_image_generator.h @@ -2,20 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CC_TEST_FAKE_PAINT_IMAGE_GENERATOR_H_ -#define CC_TEST_FAKE_PAINT_IMAGE_GENERATOR_H_ +#ifndef CC_TEST_STUB_PAINT_IMAGE_GENERATOR_H_ +#define CC_TEST_STUB_PAINT_IMAGE_GENERATOR_H_ -#include "base/containers/flat_set.h" #include "cc/paint/paint_image_generator.h" namespace cc { -class FakePaintImageGenerator : public PaintImageGenerator { +class StubPaintImageGenerator : public PaintImageGenerator { public: - explicit FakePaintImageGenerator(const SkImageInfo& info, - std::vector frames = { - FrameMetadata()}); - ~FakePaintImageGenerator() override; + explicit StubPaintImageGenerator(const SkImageInfo& info) + : PaintImageGenerator(info) {} sk_sp GetEncodedData() const override; bool GetPixels(const SkImageInfo& info, @@ -29,18 +26,8 @@ class FakePaintImageGenerator : public PaintImageGenerator { void* planes[3], size_t frame_index, uint32_t lazy_pixel_ref) override; - - const base::flat_set& frames_decoded() const { - return frames_decoded_; - } - void reset_frames_decoded() { frames_decoded_.clear(); } - - private: - std::vector image_backing_memory_; - SkPixmap image_pixmap_; - base::flat_set frames_decoded_; }; } // namespace cc -#endif // CC_TEST_FAKE_PAINT_IMAGE_GENERATOR_H_ +#endif // CC_TEST_STUB_PAINT_IMAGE_GENERATOR_H_ diff --git a/cc/tiles/checker_image_tracker.cc b/cc/tiles/checker_image_tracker.cc index d1f221a194aeee..ccdfd3f936ed5a 100644 --- a/cc/tiles/checker_image_tracker.cc +++ b/cc/tiles/checker_image_tracker.cc @@ -362,7 +362,6 @@ void CheckerImageTracker::UpdateDecodeState(const DrawImage& draw_image, decode_state->filter_quality = std::max(decode_state->filter_quality, draw_image.filter_quality()); decode_state->color_space = draw_image.target_color_space(); - decode_state->frame_index = draw_image.frame_index(); } void CheckerImageTracker::ScheduleNextImageDecode() { @@ -401,7 +400,7 @@ void CheckerImageTracker::ScheduleNextImageDecode() { it->second.filter_quality, SkMatrix::MakeScale(it->second.scale.width(), it->second.scale.height()), - it->second.frame_index, it->second.color_space); + it->second.color_space); outstanding_image_decode_.emplace(candidate); break; } diff --git a/cc/tiles/checker_image_tracker.h b/cc/tiles/checker_image_tracker.h index f415f8677d09ab..095c868fb3d08e 100644 --- a/cc/tiles/checker_image_tracker.h +++ b/cc/tiles/checker_image_tracker.h @@ -130,7 +130,6 @@ class CC_EXPORT CheckerImageTracker { SkFilterQuality filter_quality = kNone_SkFilterQuality; SkSize scale = SkSize::MakeEmpty(); gfx::ColorSpace color_space; - size_t frame_index = PaintImage::kDefaultFrameIndex; }; // Wrapper to unlock an image decode requested from the ImageController on diff --git a/cc/tiles/checker_image_tracker_unittest.cc b/cc/tiles/checker_image_tracker_unittest.cc index 504a16f9a0cab7..ef0fcdddafe4db 100644 --- a/cc/tiles/checker_image_tracker_unittest.cc +++ b/cc/tiles/checker_image_tracker_unittest.cc @@ -121,8 +121,7 @@ class CheckerImageTrackerTest : public testing::Test, .set_is_multipart(is_multipart) .TakePaintImage(), SkIRect::MakeWH(dimension, dimension), - kNone_SkFilterQuality, SkMatrix::I(), - PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); } bool ShouldCheckerImage(const DrawImage& draw_image, WhichTree tree) { @@ -434,8 +433,7 @@ TEST_F(CheckerImageTrackerTest, CheckersOnlyStaticCompletedImages) { .set_paint_image_generator(CreatePaintImageGenerator(image_size)) .TakePaintImage(), SkIRect::MakeWH(image_size.width(), image_size.height()), - kNone_SkFilterQuality, SkMatrix::I(), PaintImage::kDefaultFrameIndex, - gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); EXPECT_FALSE( ShouldCheckerImage(completed_paint_image, WhichTree::PENDING_TREE)); } @@ -462,12 +460,10 @@ TEST_F(CheckerImageTrackerTest, ChoosesMaxScaleAndQuality) { SetUpTracker(true); DrawImage image = CreateImage(ImageType::CHECKERABLE); - DrawImage scaled_image1(image, 0.5f, PaintImage::kDefaultFrameIndex, - gfx::ColorSpace()); + DrawImage scaled_image1(image, 0.5f, gfx::ColorSpace()); DrawImage scaled_image2 = DrawImage(image.paint_image(), image.src_rect(), kHigh_SkFilterQuality, - SkMatrix::MakeScale(1.8f), PaintImage::kDefaultFrameIndex, - gfx::ColorSpace()); + SkMatrix::MakeScale(1.8f), gfx::ColorSpace()); std::vector draw_images = {scaled_image1, scaled_image2}; CheckerImageTracker::ImageDecodeQueue image_decode_queue = @@ -542,7 +538,7 @@ TEST_F(CheckerImageTrackerTest, UseSrcRectForSize) { DrawImage image = CreateImage(ImageType::CHECKERABLE); image = DrawImage(image.paint_image(), SkIRect::MakeWH(200, 200), image.filter_quality(), SkMatrix::I(), - PaintImage::kDefaultFrameIndex, image.target_color_space()); + image.target_color_space()); EXPECT_FALSE(ShouldCheckerImage(image, WhichTree::PENDING_TREE)); } diff --git a/cc/tiles/decoded_image_tracker.cc b/cc/tiles/decoded_image_tracker.cc index ebe3cc0b4cb897..00cf27ae598375 100644 --- a/cc/tiles/decoded_image_tracker.cc +++ b/cc/tiles/decoded_image_tracker.cc @@ -29,8 +29,10 @@ void DecodedImageTracker::QueueImageDecode( gfx::ColorSpace target_color_space; auto image_bounds = SkIRect::MakeWH(image.width(), image.height()); + // TODO(khushalsagar): Eliminate the use of an incorrect id here and have all + // call-sites provide PaintImage to the ImageController. DrawImage draw_image(image, image_bounds, kNone_SkFilterQuality, - SkMatrix::I(), image.frame_index(), target_color_space); + SkMatrix::I(), target_color_space); image_controller_->QueueImageDecode( draw_image, base::Bind(&DecodedImageTracker::ImageDecodeFinished, base::Unretained(this), callback)); diff --git a/cc/tiles/gpu_image_decode_cache.cc b/cc/tiles/gpu_image_decode_cache.cc index 6c2028f13e4ea7..c96aeff1e4e221 100644 --- a/cc/tiles/gpu_image_decode_cache.cc +++ b/cc/tiles/gpu_image_decode_cache.cc @@ -121,8 +121,7 @@ gfx::Size CalculateSizeForMipLevel(const DrawImage& draw_image, int mip_level) { // if not, decodes to a compatible temporary pixmap and then converts that into // the |target_pixmap|. bool DrawAndScaleImage(const DrawImage& draw_image, SkPixmap* target_pixmap) { - sk_sp image = - draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index()); + const SkImage* image = draw_image.paint_image().GetSkImage().get(); if (image->dimensions() == target_pixmap->bounds().size() || target_pixmap->info().colorType() == kN32_SkColorType) { // If no scaling is occurring, or if the target colortype is already N32, @@ -211,7 +210,7 @@ class ImageDecodeTaskImpl : public TileTask { TRACE_EVENT2("cc", "ImageDecodeTaskImpl::RunOnWorkerThread", "mode", "gpu", "source_prepare_tiles_id", tracing_info_.prepare_tiles_id); devtools_instrumentation::ScopedImageDecodeTask image_decode_task( - &image_.paint_image(), + image_.paint_image().GetSkImage().get(), devtools_instrumentation::ScopedImageDecodeTask::kGpu, ImageDecodeCache::ToScopedTaskType(tracing_info_.task_type)); cache_->DecodeImage(image_, tracing_info_.task_type); @@ -1179,8 +1178,7 @@ void GpuImageDecodeCache::DecodeImageIfNecessary(const DrawImage& draw_image, // TODO(crbug.com/649167): Params should not have changed since initial // sizing. Somehow this still happens. We should investigate and re-add // DCHECKs here to enforce this. - sk_sp image = draw_image.paint_image().GetSkImageForFrame( - draw_image.frame_index()); + SkImage* image = draw_image.paint_image().GetSkImage().get(); if (!image->getDeferredTextureImageData( *context_threadsafe_proxy_.get(), &image_data->upload_params, 1, backing_memory->data(), nullptr, color_type_)) { @@ -1285,8 +1283,7 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) { auto params = SkImage::DeferredTextureImageUsageParams( SkMatrix::I(), CalculateDesiredFilterQuality(draw_image), upload_scale_mip_level); - sk_sp image = - draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index()); + SkImage* image = draw_image.paint_image().GetSkImage().get(); size_t data_size = image->getDeferredTextureImageData( *context_threadsafe_proxy_.get(), ¶ms, 1, nullptr, nullptr, color_type_); diff --git a/cc/tiles/gpu_image_decode_cache_unittest.cc b/cc/tiles/gpu_image_decode_cache_unittest.cc index 56b5d1f448d740..61c4e0b669e7e9 100644 --- a/cc/tiles/gpu_image_decode_cache_unittest.cc +++ b/cc/tiles/gpu_image_decode_cache_unittest.cc @@ -6,7 +6,6 @@ #include "cc/paint/draw_image.h" #include "cc/paint/paint_image_builder.h" -#include "cc/test/fake_paint_image_generator.h" #include "cc/test/skia_common.h" #include "cc/test/test_context_provider.h" #include "cc/test/test_tile_task_runner.h" @@ -57,7 +56,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSameImage) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -66,7 +65,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSameImage) { DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( another_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(another_result.need_unref); @@ -90,7 +89,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSmallerScale) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -99,7 +98,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSmallerScale) { DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( another_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(another_result.need_unref); @@ -121,8 +120,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLowerQuality) { SkMatrix matrix = CreateMatrix(SkSize::Make(0.4f, 0.4f), is_decomposable); DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kHigh_SkFilterQuality, matrix, - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + kHigh_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -130,8 +128,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLowerQuality) { DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( another_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(another_result.need_unref); @@ -155,7 +152,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentImage) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -166,7 +163,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentImage) { second_image, SkIRect::MakeWH(second_image.width(), second_image.height()), quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -193,7 +190,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScale) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -207,7 +204,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScale) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -217,7 +214,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScale) { DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( third_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(third_result.need_unref); @@ -241,7 +238,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScaleNoReuse) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -250,7 +247,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScaleNoReuse) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -260,7 +257,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageLargerScaleNoReuse) { DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( third_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(third_result.need_unref); @@ -286,8 +283,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageHigherQuality) { PaintImage first_image = CreateDiscardablePaintImage(gfx::Size(100, 100)); DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), - kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -300,8 +296,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageHigherQuality) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), - kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kHigh_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -325,7 +320,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedAndLocked) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -369,7 +364,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedNotLocked) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -413,7 +408,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyUploaded) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -447,7 +442,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -492,7 +487,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -541,7 +536,7 @@ TEST_P(GpuImageDecodeCacheTest, NoTaskForImageAlreadyFailedDecoding) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -573,7 +568,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -608,7 +603,7 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -646,7 +641,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -678,7 +673,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawLargerScale) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), kLow_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -690,7 +685,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawLargerScale) { DrawImage larger_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult larger_result = cache.GetTaskForImageAndRef( larger_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(larger_result.need_unref); @@ -737,8 +732,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawHigherQuality) { PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100)); DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -749,8 +743,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawHigherQuality) { DrawImage higher_quality_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kHigh_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult hq_result = cache.GetTaskForImageAndRef( higher_quality_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(hq_result.need_unref); @@ -799,7 +792,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawNegative) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(-0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -836,7 +829,7 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeScaledDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -877,7 +870,7 @@ TEST_P(GpuImageDecodeCacheTest, AtRasterUsedDirectlyIfSpaceAllows) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -922,7 +915,7 @@ TEST_P(GpuImageDecodeCacheTest, DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -956,7 +949,7 @@ TEST_P(GpuImageDecodeCacheTest, DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -996,7 +989,7 @@ TEST_P(GpuImageDecodeCacheTest, ZeroSizedImagesAreSkipped) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1024,7 +1017,7 @@ TEST_P(GpuImageDecodeCacheTest, NonOverlappingSrcRectImagesAreSkipped) { DrawImage draw_image( image, SkIRect::MakeXYWH(150, 150, image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1052,7 +1045,7 @@ TEST_P(GpuImageDecodeCacheTest, CanceledTasksDoNotCountAgainstBudget) { DrawImage draw_image( image, SkIRect::MakeXYWH(0, 0, image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1080,7 +1073,8 @@ TEST_P(GpuImageDecodeCacheTest, ShouldAggressivelyFreeResources) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); + { ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( draw_image, ImageDecodeCache::TracingInfo()); @@ -1144,7 +1138,7 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -1159,7 +1153,7 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -1199,7 +1193,7 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedZeroRefImagesImmediatelyDeleted) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -1218,7 +1212,7 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedZeroRefImagesImmediatelyDeleted) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -1246,8 +1240,7 @@ TEST_P(GpuImageDecodeCacheTest, QualityCappedAtMedium) { // Create an image with kLow_FilterQuality. DrawImage low_draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult low_result = cache.GetTaskForImageAndRef( low_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(low_result.need_unref); @@ -1257,8 +1250,7 @@ TEST_P(GpuImageDecodeCacheTest, QualityCappedAtMedium) { // should get a new task/ref. DrawImage medium_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kMedium_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kMedium_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult medium_result = cache.GetTaskForImageAndRef( medium_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(medium_result.need_unref); @@ -1268,8 +1260,7 @@ TEST_P(GpuImageDecodeCacheTest, QualityCappedAtMedium) { // Get the same image at kHigh_FilterQuality. We should re-use medium. DrawImage large_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, - DefaultColorSpace()); + kHigh_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult large_result = cache.GetTaskForImageAndRef( large_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(large_result.need_unref); @@ -1299,7 +1290,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawMipUsageChange) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1321,7 +1312,7 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawMipUsageChange) { DrawImage draw_image_mips( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.6f, 0.6f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image_mips); cache.DrawWithImageFinished(draw_image_mips, decoded_draw_image); @@ -1337,8 +1328,7 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) { bool is_decomposable = true; SkMatrix matrix = CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable); DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1406,8 +1396,7 @@ TEST_P(GpuImageDecodeCacheTest, OutOfRasterDecodeTask) { bool is_decomposable = true; SkMatrix matrix = CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable); DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + kLow_SkFilterQuality, matrix, DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetOutOfRasterDecodeTaskForImageAndRef(draw_image); @@ -1438,7 +1427,7 @@ TEST_P(GpuImageDecodeCacheTest, ZeroCacheNormalWorkingSet) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1490,13 +1479,13 @@ TEST_P(GpuImageDecodeCacheTest, SmallCacheNormalWorkingSet) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); PaintImage image2 = CreateDiscardablePaintImage(gfx::Size(100, 100)); DrawImage draw_image2( image2, SkIRect::MakeWH(image2.width(), image2.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); // Add an image to the cache and un-ref it. { @@ -1575,7 +1564,7 @@ TEST_P(GpuImageDecodeCacheTest, ClearCache) { DrawImage draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1609,7 +1598,7 @@ TEST_P(GpuImageDecodeCacheTest, ClearCacheInUse) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1648,7 +1637,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentColorSpace) { DrawImage first_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_a); + color_space_a); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -1657,7 +1646,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentColorSpace) { DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_b); + color_space_b); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -1667,7 +1656,7 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageDifferentColorSpace) { DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_a); + color_space_a); ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( third_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(third_result.need_unref); @@ -1696,7 +1685,7 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) { DrawImage draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); frame_keys.push_back(draw_image.frame_key()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( draw_image, ImageDecodeCache::TracingInfo()); @@ -1718,64 +1707,6 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) { } } -TEST_P(GpuImageDecodeCacheTest, CacheDecodesExpectedFrames) { - auto context_provider = TestContextProvider::Create(); - context_provider->BindToCurrentThread(); - TestGpuImageDecodeCache cache(context_provider.get(), GetParam()); - - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)), - }; - sk_sp generator = - sk_make_sp(SkImageInfo::MakeN32Premul(10, 10), - frames); - PaintImage image = PaintImageBuilder() - .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(generator) - .set_frame_index(0u) - .TakePaintImage(); - - viz::ContextProvider::ScopedContextLock context_lock(context_provider.get()); - - bool is_decomposable = true; - SkFilterQuality quality = kHigh_SkFilterQuality; - DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - quality, - CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - 1u, DefaultColorSpace()); - auto decoded_image = cache.GetDecodedImageForDraw(draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(1u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(draw_image, decoded_image); - - // Scaled. - DrawImage scaled_draw_image(draw_image, 0.5f, 2u, - draw_image.target_color_space()); - decoded_image = cache.GetDecodedImageForDraw(scaled_draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(2u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(scaled_draw_image, decoded_image); - - // Subset. - DrawImage subset_draw_image( - image, SkIRect::MakeWH(5, 5), quality, - CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), 3u, - DefaultColorSpace()); - decoded_image = cache.GetDecodedImageForDraw(subset_draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(3u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(subset_draw_image, decoded_image); -} - INSTANTIATE_TEST_CASE_P(GpuImageDecodeCacheTests, GpuImageDecodeCacheTest, ::testing::Values(kN32_SkColorType, diff --git a/cc/tiles/image_controller_unittest.cc b/cc/tiles/image_controller_unittest.cc index 081c46c6eb4a32..fd4d8093b0b637 100644 --- a/cc/tiles/image_controller_unittest.cc +++ b/cc/tiles/image_controller_unittest.cc @@ -228,8 +228,7 @@ int kDefaultTimeoutSeconds = 10; DrawImage CreateDiscardableDrawImage(gfx::Size size) { return DrawImage(CreateDiscardablePaintImage(size), SkIRect::MakeWH(size.width(), size.height()), - kNone_SkFilterQuality, SkMatrix::I(), - PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); } class ImageControllerTest : public testing::Test { @@ -318,13 +317,12 @@ TEST_F(ImageControllerTest, QueueImageDecodeNonLazy) { SkBitmap bitmap; bitmap.allocN32Pixels(1, 1); - DrawImage image = - DrawImage(PaintImageBuilder() - .set_id(PaintImage::GetNextId()) - .set_image(SkImage::MakeFromBitmap(bitmap)) - .TakePaintImage(), - SkIRect::MakeWH(1, 1), kNone_SkFilterQuality, SkMatrix::I(), - PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); + DrawImage image = DrawImage(PaintImageBuilder() + .set_id(PaintImage::GetNextId()) + .set_image(SkImage::MakeFromBitmap(bitmap)) + .TakePaintImage(), + SkIRect::MakeWH(1, 1), kNone_SkFilterQuality, + SkMatrix::I(), gfx::ColorSpace()); ImageController::ImageDecodeRequestId expected_id = controller()->QueueImageDecode( diff --git a/cc/tiles/software_image_decode_cache.cc b/cc/tiles/software_image_decode_cache.cc index def638c7e7fed4..786fefa5dfa94e 100644 --- a/cc/tiles/software_image_decode_cache.cc +++ b/cc/tiles/software_image_decode_cache.cc @@ -596,8 +596,7 @@ SoftwareImageDecodeCache::GetExactSizeImageDecode( "SoftwareImageDecodeCache::GetOriginalSizeImageDecode - " "decode"); bool result = paint_image.Decode(decoded_pixels->data(), &decoded_info, - key.target_color_space().ToSkColorSpace(), - key.frame_key().frame_index()); + key.target_color_space().ToSkColorSpace()); if (!result) { decoded_pixels->Unlock(); return nullptr; @@ -620,8 +619,7 @@ SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key, // so. We could also subrect scaled images. SkIRect exact_size_rect = SkIRect::MakeWH(image.width(), image.height()); DrawImage exact_size_draw_image(image, exact_size_rect, kNone_SkFilterQuality, - SkMatrix::I(), key.frame_key().frame_index(), - key.target_color_space()); + SkMatrix::I(), key.target_color_space()); ImageKey exact_size_key = ImageKey::FromDrawImage(exact_size_draw_image, color_type_); @@ -695,8 +693,7 @@ SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key, key.target_size().width(), key.target_size().height()))); DrawImage exact_size_draw_image(image, exact_size_rect, kNone_SkFilterQuality, - SkMatrix::I(), key.frame_key().frame_index(), - key.target_color_space()); + SkMatrix::I(), key.target_color_space()); ImageKey exact_size_key = ImageKey::FromDrawImage(exact_size_draw_image, color_type_); diff --git a/cc/tiles/software_image_decode_cache_perftest.cc b/cc/tiles/software_image_decode_cache_perftest.cc index 02fb94633208a0..fd9f4e8dcffffb 100644 --- a/cc/tiles/software_image_decode_cache_perftest.cc +++ b/cc/tiles/software_image_decode_cache_perftest.cc @@ -62,7 +62,7 @@ class SoftwareImageDecodeCachePerfTest : public testing::Test { .set_image(CreateImage(rect.width(), rect.height())) .TakePaintImage(), subrect, quality, - CreateMatrix(SkSize::Make(scale.first, scale.second)), 0u, + CreateMatrix(SkSize::Make(scale.first, scale.second)), gfx::ColorSpace()); } } diff --git a/cc/tiles/software_image_decode_cache_unittest.cc b/cc/tiles/software_image_decode_cache_unittest.cc index 807902cd5b11fd..52499201f22fa6 100644 --- a/cc/tiles/software_image_decode_cache_unittest.cc +++ b/cc/tiles/software_image_decode_cache_unittest.cc @@ -6,7 +6,6 @@ #include "cc/paint/draw_image.h" #include "cc/paint/paint_image_builder.h" -#include "cc/test/fake_paint_image_generator.h" #include "cc/test/skia_common.h" #include "cc/test/test_tile_task_runner.h" #include "testing/gtest/include/gtest/gtest.h" @@ -52,7 +51,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyNoneQuality) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kNone_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -73,7 +72,7 @@ TEST(SoftwareImageDecodeCacheTest, paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kLow_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -91,7 +90,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropsToLowIfMipLevel0) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kMedium_SkFilterQuality, CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -109,7 +108,7 @@ TEST(SoftwareImageDecodeCacheTest, LowUnscalableFormatStaysLow) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kLow_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType); @@ -128,7 +127,7 @@ TEST(SoftwareImageDecodeCacheTest, HighUnscalableFormatBecomesLow) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kHigh_SkFilterQuality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType); @@ -147,7 +146,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyLowQualityKeptLowIfUpscale) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kLow_SkFilterQuality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -166,7 +165,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQuality) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.4f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -185,7 +184,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropToLowIfEnlarging) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -204,7 +203,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityDropToLowIfIdentity) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -224,7 +223,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.001f, 1.001f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -244,7 +243,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.999f, 0.999f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -264,7 +263,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -284,7 +283,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt1_5Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -303,7 +302,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt1_0cale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -322,7 +321,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyLowQualityAt0_75Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -341,7 +340,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_5Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -360,7 +359,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_49Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -379,7 +378,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_1Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.1f, 0.1f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -398,7 +397,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyMediumQualityAt0_01Scale) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.01f, 0.01f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -418,7 +417,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.2f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -437,7 +436,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyUpscaleIsLowQuality) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(2.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -459,7 +458,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyHighQualityDropToMediumIfTooLarge) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.45f, 0.45f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -479,7 +478,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -498,7 +497,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageKeyHighQualityDropToLowIfIdentity) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -518,7 +517,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.001f, 1.001f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -538,7 +537,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.999f, 0.999f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -557,7 +556,7 @@ TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -570,7 +569,7 @@ TEST(SoftwareImageDecodeCacheTest, OriginalDecodesAreEqual) { DrawImage another_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto another_key = ImageDecodeCacheKey::FromDrawImage(another_draw_image, kN32_SkColorType); @@ -593,7 +592,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageRectDoesNotContainSrcRect) { paint_image, SkIRect::MakeXYWH(25, 35, paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -613,7 +612,7 @@ TEST(SoftwareImageDecodeCacheTest, ImageRectDoesNotContainSrcRectWithScale) { paint_image, SkIRect::MakeXYWH(20, 30, paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -633,7 +632,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImage) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -642,7 +641,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImage) { DrawImage another_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( another_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(another_result.need_unref); @@ -663,7 +662,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentQuality) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kHigh_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult high_quality_result = cache.GetTaskForImageAndRef(high_quality_draw_image, ImageDecodeCache::TracingInfo()); @@ -674,7 +673,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentQuality) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kNone_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult none_quality_result = cache.GetTaskForImageAndRef(none_quality_draw_image, ImageDecodeCache::TracingInfo()); @@ -698,7 +697,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentSize) { DrawImage half_size_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult half_size_result = cache.GetTaskForImageAndRef( half_size_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(half_size_result.need_unref); @@ -707,7 +706,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentSize) { DrawImage quarter_size_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult quarter_size_result = cache.GetTaskForImageAndRef(quarter_size_draw_image, ImageDecodeCache::TracingInfo()); @@ -732,7 +731,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageDifferentImage) { first_paint_image, SkIRect::MakeWH(first_paint_image.width(), first_paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -743,7 +742,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageDifferentImage) { second_paint_image, SkIRect::MakeWH(second_paint_image.width(), second_paint_image.height()), quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -780,7 +779,7 @@ TEST(SoftwareImageDecodeCacheTest, MAYBE_GetTaskForImageDifferentColorSpace) { DrawImage first_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_b); + color_space_b); ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( first_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(first_result.need_unref); @@ -789,7 +788,7 @@ TEST(SoftwareImageDecodeCacheTest, MAYBE_GetTaskForImageDifferentColorSpace) { DrawImage second_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_c); + color_space_c); ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( second_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(second_result.need_unref); @@ -799,7 +798,7 @@ TEST(SoftwareImageDecodeCacheTest, MAYBE_GetTaskForImageDifferentColorSpace) { DrawImage third_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, color_space_b); + color_space_b); ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( third_draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(third_result.need_unref); @@ -823,7 +822,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageAlreadyDecoded) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -852,7 +851,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageAlreadyPrerolled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -887,7 +886,7 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -928,7 +927,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -968,7 +967,7 @@ TEST(SoftwareImageDecodeCacheTest, GetDecodedImageForDraw) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1002,7 +1001,7 @@ TEST(SoftwareImageDecodeCacheTest, paint_image, SkIRect::MakeXYWH(20, 30, paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1034,7 +1033,7 @@ TEST(SoftwareImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1060,7 +1059,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1092,7 +1091,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1137,7 +1136,7 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1182,7 +1181,7 @@ TEST(SoftwareImageDecodeCacheTest, ZeroSizedImagesAreSkipped) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1206,7 +1205,7 @@ TEST(SoftwareImageDecodeCacheTest, NonOverlappingSrcRectImagesAreSkipped) { paint_image, SkIRect::MakeXYWH(150, 150, paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1229,7 +1228,7 @@ TEST(SoftwareImageDecodeCacheTest, LowQualityFilterIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1257,7 +1256,7 @@ TEST(SoftwareImageDecodeCacheTest, LowQualityScaledSubrectIsHandled) { PaintImage paint_image = CreatePaintImage(100, 100); DrawImage draw_image(paint_image, SkIRect::MakeXYWH(10, 10, 80, 80), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1290,7 +1289,7 @@ TEST(SoftwareImageDecodeCacheTest, NoneQualityScaledSubrectIsHandled) { PaintImage paint_image = CreatePaintImage(100, 100); DrawImage draw_image(paint_image, SkIRect::MakeXYWH(10, 10, 80, 80), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1321,7 +1320,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt01_5ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1352,7 +1351,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt1_0ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.f, 1.f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1383,7 +1382,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_75ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.75f, 0.75f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1414,7 +1413,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_5ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1445,7 +1444,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_49ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1476,7 +1475,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_1ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.1f, 0.1f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1507,7 +1506,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_01ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.01f, 0.01f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1538,7 +1537,7 @@ TEST(SoftwareImageDecodeCacheTest, MediumQualityAt0_001ScaleIsHandled) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.001f, 0.001f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); @@ -1562,11 +1561,11 @@ TEST(SoftwareImageDecodeCacheTest, DrawImage draw_image_50( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); DrawImage draw_image_49( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.49f, 0.49f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result_50 = cache.GetTaskForImageAndRef( draw_image_50, ImageDecodeCache::TracingInfo()); @@ -1613,7 +1612,7 @@ TEST(SoftwareImageDecodeCacheTest, ClearCache) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( draw_image, ImageDecodeCache::TracingInfo()); EXPECT_TRUE(result.need_unref); @@ -1642,7 +1641,7 @@ TEST(SoftwareImageDecodeCacheTest, RemoveUnusedImage) { DrawImage draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + DefaultColorSpace()); frame_keys.push_back(draw_image.frame_key()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1665,58 +1664,5 @@ TEST(SoftwareImageDecodeCacheTest, RemoveUnusedImage) { } } -TEST(SoftwareImageDecodeCacheTest, CacheDecodesExpectedFrames) { - TestSoftwareImageDecodeCache cache; - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)), - }; - sk_sp generator = - sk_make_sp(SkImageInfo::MakeN32Premul(10, 10), - frames); - PaintImage image = PaintImageBuilder() - .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(generator) - .set_frame_index(0u) - .TakePaintImage(); - - bool is_decomposable = true; - SkFilterQuality quality = kHigh_SkFilterQuality; - DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - quality, - CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - 1u, DefaultColorSpace()); - auto decoded_image = cache.GetDecodedImageForDraw(draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(1u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(draw_image, decoded_image); - - // Scaled. - DrawImage scaled_draw_image(draw_image, 0.5f, 2u, - draw_image.target_color_space()); - decoded_image = cache.GetDecodedImageForDraw(scaled_draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(2u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(scaled_draw_image, decoded_image); - - // Subset. - DrawImage subset_draw_image( - image, SkIRect::MakeWH(5, 5), quality, - CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), 3u, - DefaultColorSpace()); - decoded_image = cache.GetDecodedImageForDraw(subset_draw_image); - ASSERT_TRUE(decoded_image.image()); - ASSERT_EQ(generator->frames_decoded().size(), 1u); - EXPECT_EQ(generator->frames_decoded().count(3u), 1u); - generator->reset_frames_decoded(); - cache.DrawWithImageFinished(subset_draw_image, decoded_image); -} - } // namespace } // namespace cc diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc index 21c016b924a173..618b973b863cdf 100644 --- a/cc/tiles/tile_manager.cc +++ b/cc/tiles/tile_manager.cc @@ -883,8 +883,7 @@ void TileManager::PartitionImagesForCheckering( const PrioritizedTile& prioritized_tile, const gfx::ColorSpace& raster_color_space, std::vector* sync_decoded_images, - std::vector* checkered_images, - base::flat_map* image_to_frame_index) { + std::vector* checkered_images) { Tile* tile = prioritized_tile.tile(); std::vector images_in_tile; prioritized_tile.raster_source()->GetDiscardableImagesInRect( @@ -892,15 +891,8 @@ void TileManager::PartitionImagesForCheckering( WhichTree tree = tile->tiling()->tree(); for (const auto* original_draw_image : images_in_tile) { - size_t frame_index = client_->GetFrameIndexForImage( - original_draw_image->paint_image(), tree); DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(), - frame_index, raster_color_space); - if (image_to_frame_index) { - (*image_to_frame_index)[draw_image.paint_image().stable_id()] = - frame_index; - } - + raster_color_space); if (checker_image_tracker_.ShouldCheckerImage( draw_image, tree, tile->required_for_activation())) checkered_images->push_back(draw_image.paint_image()); @@ -921,10 +913,9 @@ void TileManager::AddCheckeredImagesToDecodeQueue( WhichTree tree = tile->tiling()->tree(); for (const auto* original_draw_image : images_in_tile) { - size_t frame_index = client_->GetFrameIndexForImage( - original_draw_image->paint_image(), tree); DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(), - frame_index, raster_color_space); + raster_color_space); + if (checker_image_tracker_.ShouldCheckerImage( draw_image, tree, tile->required_for_activation())) { image_decode_queue->emplace_back(draw_image.paint_image(), decode_type); @@ -1142,15 +1133,11 @@ scoped_refptr TileManager::CreateRasterTask( scheduled_draw_images_[tile->id()]; sync_decoded_images.clear(); PaintImageIdFlatSet images_to_skip; - base::flat_map image_id_to_current_frame_index; if (!skip_images) { std::vector checkered_images; PartitionImagesForCheckering(prioritized_tile, color_space, - &sync_decoded_images, &checkered_images, - &image_id_to_current_frame_index); + &sync_decoded_images, &checkered_images); for (const auto& image : checkered_images) { - DCHECK(!image.ShouldAnimate()); - images_to_skip.insert(image.stable_id()); // This can be the case for tiles on the active tree that will be replaced @@ -1188,8 +1175,7 @@ scoped_refptr TileManager::CreateRasterTask( has_at_raster_images) { image_provider.emplace(skip_images, std::move(images_to_skip), std::move(at_raster_images), - image_controller_.cache(), color_space, - std::move(image_id_to_current_frame_index)); + image_controller_.cache(), color_space); } return make_scoped_refptr(new RasterTaskImpl( diff --git a/cc/tiles/tile_manager.h b/cc/tiles/tile_manager.h index 58de5f05f0eaf5..d9a7cbfdfef037 100644 --- a/cc/tiles/tile_manager.h +++ b/cc/tiles/tile_manager.h @@ -87,9 +87,6 @@ class CC_EXPORT TileManagerClient { // rasterized with missing images need to be invalidated. virtual void RequestImplSideInvalidationForCheckerImagedTiles() = 0; - virtual size_t GetFrameIndexForImage(const PaintImage& paint_image, - WhichTree tree) const = 0; - protected: virtual ~TileManagerClient() {} }; @@ -360,12 +357,10 @@ class CC_EXPORT TileManager : CheckerImageTrackerClient { PrioritizedWorkToSchedule AssignGpuMemoryToTiles(); void ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule); - void PartitionImagesForCheckering( - const PrioritizedTile& prioritized_tile, - const gfx::ColorSpace& raster_color_space, - std::vector* sync_decoded_images, - std::vector* checkered_images, - base::flat_map* image_to_frame_index = nullptr); + void PartitionImagesForCheckering(const PrioritizedTile& prioritized_tile, + const gfx::ColorSpace& raster_color_space, + std::vector* sync_decoded_images, + std::vector* checkered_images); void AddCheckeredImagesToDecodeQueue( const PrioritizedTile& prioritized_tile, const gfx::ColorSpace& raster_color_space, diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc index 71cf49c18715b3..02b1a752967be9 100644 --- a/cc/tiles/tile_manager_unittest.cc +++ b/cc/tiles/tile_manager_unittest.cc @@ -22,7 +22,6 @@ #include "cc/test/fake_layer_tree_frame_sink.h" #include "cc/test/fake_layer_tree_frame_sink_client.h" #include "cc/test/fake_layer_tree_host_impl.h" -#include "cc/test/fake_paint_image_generator.h" #include "cc/test/fake_picture_layer_impl.h" #include "cc/test/fake_picture_layer_tiling_client.h" #include "cc/test/fake_raster_source.h" @@ -30,6 +29,7 @@ #include "cc/test/fake_tile_manager.h" #include "cc/test/fake_tile_task_manager.h" #include "cc/test/skia_common.h" +#include "cc/test/stub_paint_image_generator.h" #include "cc/test/test_layer_tree_host_base.h" #include "cc/test/test_task_graph_runner.h" #include "cc/test/test_tile_priorities.h" @@ -2307,10 +2307,10 @@ TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) { class CheckerImagingTileManagerTest : public TestLayerTreeHostBase { public: - class MockImageGenerator : public FakePaintImageGenerator { + class MockImageGenerator : public StubPaintImageGenerator { public: explicit MockImageGenerator(const gfx::Size& size) - : FakePaintImageGenerator( + : StubPaintImageGenerator( SkImageInfo::MakeN32Premul(size.width(), size.height())) {} MOCK_METHOD5(GetPixels, diff --git a/cc/trees/image_animation_controller.cc b/cc/trees/image_animation_controller.cc deleted file mode 100644 index 09e30236bc9a18..00000000000000 --- a/cc/trees/image_animation_controller.cc +++ /dev/null @@ -1,401 +0,0 @@ -// Copyright 2017 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. - -#include "cc/trees/image_animation_controller.h" - -#include "base/bind.h" -#include "base/trace_event/trace_event.h" -#include "cc/paint/image_animation_count.h" - -namespace cc { -namespace { - -// The maximum number of time an animation can be delayed before it is reset to -// start from the beginning, instead of fast-forwarding to catch up to the -// desired frame. -const base::TimeDelta kAnimationResyncCutoff = base::TimeDelta::FromMinutes(5); - -} // namespace - -ImageAnimationController::ImageAnimationController( - base::SingleThreadTaskRunner* task_runner, - base::Closure invalidation_callback) - : notifier_(task_runner, invalidation_callback) {} - -ImageAnimationController::~ImageAnimationController() = default; - -void ImageAnimationController::UpdateAnimatedImage( - const DiscardableImageMap::AnimatedImageMetadata& data) { - AnimationState& animation_state = animation_state_map_[data.paint_image_id]; - animation_state.UpdateMetadata(data); -} - -void ImageAnimationController::RegisterAnimationDriver( - PaintImage::Id paint_image_id, - AnimationDriver* driver) { - auto it = animation_state_map_.find(paint_image_id); - DCHECK(it != animation_state_map_.end()); - it->second.AddDriver(driver); -} - -void ImageAnimationController::UnregisterAnimationDriver( - PaintImage::Id paint_image_id, - AnimationDriver* driver) { - auto it = animation_state_map_.find(paint_image_id); - DCHECK(it != animation_state_map_.end()); - it->second.RemoveDriver(driver); -} - -const PaintImageIdFlatSet& ImageAnimationController::AnimateForSyncTree( - base::TimeTicks now) { - TRACE_EVENT0("cc", "ImageAnimationController::AnimateImagesForSyncTree"); - DCHECK(images_animated_on_sync_tree_.empty()); - - notifier_.WillAnimate(); - base::Optional next_invalidation_time; - - for (auto id : active_animations_) { - auto it = animation_state_map_.find(id); - DCHECK(it != animation_state_map_.end()); - AnimationState& state = it->second; - - // Is anyone still interested in animating this image? - if (!state.ShouldAnimate()) - continue; - - // If we were able to advance this animation, invalidate it on the sync - // tree. - if (state.AdvanceFrame(now)) - images_animated_on_sync_tree_.insert(id); - - // Update the next invalidation time to the earliest time at which we need - // a frame to animate an image. - // Note its important to check ShouldAnimate() here again since advancing to - // a new frame on the sync tree means we might not need to animate this - // image any longer. - if (!state.ShouldAnimate()) - continue; - - DCHECK_GT(state.next_desired_frame_time(), now); - if (!next_invalidation_time.has_value()) { - next_invalidation_time.emplace(state.next_desired_frame_time()); - } else { - next_invalidation_time = std::min(state.next_desired_frame_time(), - next_invalidation_time.value()); - } - } - - if (next_invalidation_time.has_value()) - notifier_.Schedule(now, next_invalidation_time.value()); - else - notifier_.Cancel(); - - return images_animated_on_sync_tree_; -} - -void ImageAnimationController::UpdateStateFromDrivers(base::TimeTicks now) { - TRACE_EVENT0("cc", "UpdateStateFromAnimationDrivers"); - - base::Optional next_invalidation_time; - for (auto& it : animation_state_map_) { - AnimationState& state = it.second; - state.UpdateStateFromDrivers(); - - // If we don't need to animate this image anymore, remove it from the list - // of active animations. - // Note that by not updating the |next_invalidation_time| from this image - // here, we will cancel any pending invalidation scheduled for this image - // when updating the |notifier_| at the end of this loop. - if (!state.ShouldAnimate()) { - active_animations_.erase(it.first); - continue; - } - - active_animations_.insert(it.first); - if (!next_invalidation_time.has_value()) { - next_invalidation_time.emplace(state.next_desired_frame_time()); - } else { - next_invalidation_time = std::min(next_invalidation_time.value(), - state.next_desired_frame_time()); - } - } - - if (next_invalidation_time.has_value()) - notifier_.Schedule(now, next_invalidation_time.value()); - else - notifier_.Cancel(); -} - -void ImageAnimationController::DidActivate() { - TRACE_EVENT0("cc", "ImageAnimationController::WillActivate"); - - for (auto id : images_animated_on_sync_tree_) { - auto it = animation_state_map_.find(id); - DCHECK(it != animation_state_map_.end()); - it->second.PushPendingToActive(); - } - - images_animated_on_sync_tree_.clear(); -} - -size_t ImageAnimationController::GetFrameIndexForImage( - PaintImage::Id paint_image_id, - WhichTree tree) const { - const auto& it = animation_state_map_.find(paint_image_id); - DCHECK(it != animation_state_map_.end()); - return tree == WhichTree::PENDING_TREE ? it->second.pending_index() - : it->second.active_index(); -} - -const base::flat_set& -ImageAnimationController::GetDriversForTesting( - PaintImage::Id paint_image_id) const { - const auto& it = animation_state_map_.find(paint_image_id); - DCHECK(it != animation_state_map_.end()); - return it->second.drivers_for_testing(); -} - -ImageAnimationController::AnimationState::AnimationState() = default; - -ImageAnimationController::AnimationState::AnimationState( - AnimationState&& other) = default; - -ImageAnimationController::AnimationState& -ImageAnimationController::AnimationState::operator=(AnimationState&& other) = - default; - -ImageAnimationController::AnimationState::~AnimationState() { - DCHECK(drivers_.empty()); -} - -bool ImageAnimationController::AnimationState::ShouldAnimate() const { - DCHECK(repetitions_completed_ == 0 || is_complete()); - - // If we have no drivers for this image, no need to animate it. - if (!should_animate_from_drivers_) - return false; - - switch (requested_repetitions_) { - case kAnimationLoopOnce: - if (repetitions_completed_ >= 1) - return false; - break; - case kAnimationNone: - NOTREACHED() << "We shouldn't be tracking kAnimationNone images"; - break; - case kAnimationLoopInfinite: - break; - default: - if (requested_repetitions_ <= repetitions_completed_) - return false; - } - - // If we have all data for this image and the policy allows it, we can - // continue animating it. - if (completion_state_ == PaintImage::CompletionState::DONE) - return true; - - // If we have not yet received all data for this image, we can not advance to - // an incomplete frame. - if (!frames_[NextFrameIndex()].complete) - return false; - - // If we don't have all data for this image, we can not trust the frame count - // and loop back to the first frame. - size_t last_frame_index = frames_.size() - 1; - if (pending_index_ == last_frame_index) - return false; - - return true; -} - -bool ImageAnimationController::AnimationState::AdvanceFrame( - base::TimeTicks now) { - DCHECK(ShouldAnimate()); - - // Start the animation from the first frame, if not yet started. We don't need - // an invalidation here since the pending/active tree should be displaying the - // first frame. - if (!animation_started_) { - DCHECK_EQ(pending_index_, 0u); - DCHECK_EQ(pending_index_, active_index_); - - next_desired_frame_time_ = now + frames_[0].duration; - animation_started_ = true; - return false; - } - - // Don't advance the animation if its not time yet to move to the next frame. - if (now < next_desired_frame_time_) - return false; - - // If the animation is more than 5 min out of date, we don't bother catching - // up and start again from the current frame. - // Note that we don't need to invalidate this image since the active tree - // is already displaying the current frame. - if (now - next_desired_frame_time_ > kAnimationResyncCutoff) { - DCHECK_EQ(pending_index_, active_index_); - next_desired_frame_time_ = now + frames_[pending_index_].duration; - return false; - } - - // Keep catching up the animation until we reach the frame we should be - // displaying now. - // TODO(khushalsagar): Avoid unnecessary iterations for skipping whole loops - // in the animations. - size_t last_frame_index = frames_.size() - 1; - while (next_desired_frame_time_ <= now && ShouldAnimate()) { - size_t next_frame_index = NextFrameIndex(); - base::TimeTicks next_desired_frame_time = - next_desired_frame_time_ + frames_[next_frame_index].duration; - - // The image may load more slowly than it's supposed to animate, so that by - // the time we reach the end of the first repetition, we're well behind. - // Start the animation from the first frame in this case, so that we don't - // skip frames (or whole iterations) trying to "catch up". This is a - // tradeoff: It guarantees users see the whole animation the second time - // through and don't miss any repetitions, and is closer to what other - // browsers do; on the other hand, it makes animations "less accurate" for - // pages that try to sync an image and some other resource (e.g. audio), - // especially if users switch tabs (and thus stop drawing the animation, - // which will pause it) during that initial loop, then switch back later. - if (next_frame_index == 0u && repetitions_completed_ == 1 && - next_desired_frame_time <= now) { - pending_index_ = 0u; - next_desired_frame_time_ = now + frames_[0].duration; - repetitions_completed_ = 0; - break; - } - - pending_index_ = next_frame_index; - next_desired_frame_time_ = next_desired_frame_time; - - // If we are advancing to the last frame and the image has been completely - // loaded (which means that the frame count is known to be accurate), we - // just finished a loop in the animation. - if (pending_index_ == last_frame_index && is_complete()) - repetitions_completed_++; - } - - return pending_index_ != active_index_; -} - -void ImageAnimationController::AnimationState::UpdateMetadata( - const DiscardableImageMap::AnimatedImageMetadata& data) { - paint_image_id_ = data.paint_image_id; - - DCHECK_NE(data.repetition_count, kAnimationNone); - requested_repetitions_ = data.repetition_count; - - DCHECK(frames_.size() <= data.frames.size()) - << "Updated recordings can only append frames"; - frames_ = data.frames; - DCHECK_GT(frames_.size(), 1u); - - DCHECK(completion_state_ != PaintImage::CompletionState::DONE || - data.completion_state == PaintImage::CompletionState::DONE) - << "If the image was marked complete before, it can not be incomplete in " - "a new update"; - completion_state_ = data.completion_state; - - // Update the repetition count in case we have displayed the last frame and - // we now know the frame count to be accurate. - size_t last_frame_index = frames_.size() - 1; - if (pending_index_ == last_frame_index && is_complete() && - repetitions_completed_ == 0) - repetitions_completed_++; -} - -void ImageAnimationController::AnimationState::PushPendingToActive() { - active_index_ = pending_index_; -} - -void ImageAnimationController::AnimationState::AddDriver( - AnimationDriver* driver) { - drivers_.insert(driver); -} - -void ImageAnimationController::AnimationState::RemoveDriver( - AnimationDriver* driver) { - drivers_.erase(driver); -} - -void ImageAnimationController::AnimationState::UpdateStateFromDrivers() { - should_animate_from_drivers_ = false; - for (auto* driver : drivers_) { - if (driver->ShouldAnimate(paint_image_id_)) { - should_animate_from_drivers_ = true; - break; - } - } -} - -size_t ImageAnimationController::AnimationState::NextFrameIndex() const { - if (!animation_started_) - return 0u; - return (pending_index_ + 1) % frames_.size(); -} - -ImageAnimationController::DelayedNotifier::DelayedNotifier( - base::SingleThreadTaskRunner* task_runner, - base::Closure closure) - : task_runner_(task_runner), - closure_(std::move(closure)), - weak_factory_(this) { - DCHECK(task_runner_->BelongsToCurrentThread()); -} - -ImageAnimationController::DelayedNotifier::~DelayedNotifier() { - DCHECK(task_runner_->BelongsToCurrentThread()); -} - -void ImageAnimationController::DelayedNotifier::Schedule( - base::TimeTicks now, - base::TimeTicks notification_time) { - // If an animation is already pending, don't schedule another invalidation. - // We will schedule the next invalidation based on the latest animation state - // during AnimateForSyncTree. - if (animation_pending_) - return; - - // The requested notification time can be in the past. For instance, if an - // animation was paused because the image became invisible. - if (notification_time < now) - notification_time = now; - - // If we already have a notification scheduled to run at this time, no need to - // Cancel it. - if (pending_notification_time_.has_value() && - notification_time == pending_notification_time_.value()) - return; - - // Cancel the pending notification since we the requested notification time - // has changed. - Cancel(); - - TRACE_EVENT2("cc", "ScheduleInvalidationForImageAnimation", - "notification_time", notification_time, "now", now); - pending_notification_time_.emplace(notification_time); - task_runner_->PostDelayedTask( - FROM_HERE, - base::Bind(&DelayedNotifier::Notify, weak_factory_.GetWeakPtr()), - notification_time - now); -} - -void ImageAnimationController::DelayedNotifier::Cancel() { - pending_notification_time_.reset(); - weak_factory_.InvalidateWeakPtrs(); -} - -void ImageAnimationController::DelayedNotifier::Notify() { - pending_notification_time_.reset(); - animation_pending_ = true; - closure_.Run(); -} - -void ImageAnimationController::DelayedNotifier::WillAnimate() { - animation_pending_ = false; -} - -} // namespace cc diff --git a/cc/trees/image_animation_controller.h b/cc/trees/image_animation_controller.h deleted file mode 100644 index f536021b596ba8..00000000000000 --- a/cc/trees/image_animation_controller.h +++ /dev/null @@ -1,224 +0,0 @@ -// Copyright 2017 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_TREES_IMAGE_ANIMATION_CONTROLLER_H_ -#define CC_TREES_IMAGE_ANIMATION_CONTROLLER_H_ - -#include "base/cancelable_callback.h" -#include "base/containers/flat_map.h" -#include "base/containers/flat_set.h" -#include "base/memory/weak_ptr.h" -#include "base/optional.h" -#include "base/time/time.h" -#include "cc/cc_export.h" -#include "cc/paint/discardable_image_map.h" -#include "cc/paint/image_id.h" -#include "cc/paint/paint_image.h" -#include "cc/paint/paint_image_generator.h" -#include "cc/tiles/tile_priority.h" - -namespace cc { -class PaintImage; - -// ImageAnimationController is responsible for tracking state for ticking image -// animations in the compositor. -// -// 1) It receives the updated metadata for these images from new recordings -// received from the client using UpdateAnimatedImage. The controller tracks -// the frame index of an image used on a tree, and advances the animation to -// the desired frame each time a new sync tree is created. -// -// 2) An AnimationDriver can register itself for deciding whether the -// controller animates an image. The animation is paused if there are no -// registered drivers interested in animating it. -// -// 3) An animation is only advanced on the sync tree, which is requested to be -// created using the |invalidation_callback|. This effectively means that -// the frame of the image used remains consistent throughout the lifetime of -// a tree, guaranteeing that the image update is atomic. -class CC_EXPORT ImageAnimationController { - public: - // AnimationDrivers are clients interested in driving image animations. An - // animation is ticked if there is at least one driver registered for which - // ShouldAnimate returns true. Once - // no drivers are registered for an image, or none of the registered drivers - // want us to animate, the animation is no longer ticked. - class CC_EXPORT AnimationDriver { - public: - virtual ~AnimationDriver() {} - - // Returns true if the image should be animated. - virtual bool ShouldAnimate(PaintImage::Id paint_image_id) const = 0; - }; - - // |invalidation_callback| is the callback to trigger an invalidation and - // create a sync tree for advancing an image animation. The controller is - // guaranteed to receive a call to AnimateForSyncTree when the sync tree is - // created. - // |task_runner| is the thread on which the controller is used. The - // invalidation_callback can only be run on this thread. - ImageAnimationController(base::SingleThreadTaskRunner* task_runner, - base::Closure invalidation_callback); - ~ImageAnimationController(); - - // Called to update the state for a PaintImage received in a new recording. - void UpdateAnimatedImage( - const DiscardableImageMap::AnimatedImageMetadata& data); - - // Registers/Unregisters an animation driver interested in animating this - // image. - // Note that the state for this image must have been populated to the - // controller using UpdatePaintImage prior to registering any drivers. - void RegisterAnimationDriver(PaintImage::Id paint_image_id, - AnimationDriver* driver); - void UnregisterAnimationDriver(PaintImage::Id paint_image_id, - AnimationDriver* driver); - - // Called to advance the animations to the frame to be used on the sync tree. - // This should be called only once for a sync tree and must be followed with - // a call to DidActivate when this tree is activated. - // Returns the set of images that were animated and should be invalidated on - // this sync tree. - const PaintImageIdFlatSet& AnimateForSyncTree(base::TimeTicks now); - - // Called whenever the ShouldAnimate response for a driver could have changed. - // For instance on a change in the visibility of the image, we would pause - // off-screen animations. - // This is called after every DrawProperties update and commit. - void UpdateStateFromDrivers(base::TimeTicks now); - - // Called when the sync tree was activated and the animations' associated - // state should be pushed to the active tree. - void DidActivate(); - - // Returns the frame index to use for the given PaintImage and tree. - size_t GetFrameIndexForImage(PaintImage::Id paint_image_id, - WhichTree tree) const; - - const base::flat_set& GetDriversForTesting( - PaintImage::Id paint_image_id) const; - - private: - class AnimationState { - public: - AnimationState(); - AnimationState(AnimationState&& other); - AnimationState& operator=(AnimationState&& other); - ~AnimationState(); - - bool ShouldAnimate() const; - bool AdvanceFrame(base::TimeTicks now); - void UpdateMetadata(const DiscardableImageMap::AnimatedImageMetadata& data); - void PushPendingToActive(); - - void AddDriver(AnimationDriver* driver); - void RemoveDriver(AnimationDriver* driver); - void UpdateStateFromDrivers(); - - size_t pending_index() const { return pending_index_; } - size_t active_index() const { return active_index_; } - base::TimeTicks next_desired_frame_time() const { - return next_desired_frame_time_; - } - const base::flat_set& drivers_for_testing() const { - return drivers_; - } - - private: - size_t NextFrameIndex() const; - bool is_complete() const { - return completion_state_ == PaintImage::CompletionState::DONE; - } - - PaintImage::Id paint_image_id_ = PaintImage::kNonLazyStableId; - - // The frame metadata received from the most updated recording with this - // PaintImage. - std::vector frames_; - - // The number of animation loops requested for this image. For a value > 0, - // this number represents the exact number of iterations requested. A few - // special cases are represented using constants defined in - // cc/paint/image_animation_count.h - int requested_repetitions_ = kAnimationNone; - - // The number of loops the animation has finished so far. - int repetitions_completed_ = 0; - - // A set of drivers interested in animating this image. - base::flat_set drivers_; - - // The index being used on the active tree, if a recording with this image - // is still present. - size_t active_index_ = PaintImage::kDefaultFrameIndex; - - // The index being displayed on the pending tree. - size_t pending_index_ = PaintImage::kDefaultFrameIndex; - - // The time at which we would like to display the next frame. This can be in - // the past, for instance, if we pause the animation from the image becoming - // invisible. - base::TimeTicks next_desired_frame_time_; - - // Set if there is at least one driver interested in animating this image, - // cached from the last update. - bool should_animate_from_drivers_ = false; - - // Set if the animation has been started. - bool animation_started_ = false; - - // Whether the image is known to be completely loaded in the most recent - // recording received. - PaintImage::CompletionState completion_state_ = - PaintImage::CompletionState::PARTIALLY_DONE; - - DISALLOW_COPY_AND_ASSIGN(AnimationState); - }; - - class DelayedNotifier { - public: - DelayedNotifier(base::SingleThreadTaskRunner* task_runner, - base::Closure closure); - ~DelayedNotifier(); - - void Schedule(base::TimeTicks now, base::TimeTicks notification_time); - void Cancel(); - void WillAnimate(); - - private: - void Notify(); - - base::SingleThreadTaskRunner* task_runner_; - base::Closure closure_; - - // Set if a notification is currently pending. - base::Optional pending_notification_time_; - - // Set if the notification was dispatched and the resulting animation on the - // next sync tree is pending. - bool animation_pending_ = false; - - base::WeakPtrFactory weak_factory_; - }; - - // The AnimationState for images is persisted until they are cleared on - // navigation. This is because while an image might not be painted anymore, if - // it moves out of the interest rect for instance, the state retained is - // necessary to resume the animation. - // TODO(khushalsagar): Implement clearing of state on navigations. - using AnimationStateMap = base::flat_map; - AnimationStateMap animation_state_map_; - - // The set of currently active animations. - PaintImageIdFlatSet active_animations_; - - // The set of images that were animated and invalidated on the last sync tree. - PaintImageIdFlatSet images_animated_on_sync_tree_; - - DelayedNotifier notifier_; -}; - -} // namespace cc - -#endif // CC_TREES_IMAGE_ANIMATION_CONTROLLER_H_ diff --git a/cc/trees/image_animation_controller_unittest.cc b/cc/trees/image_animation_controller_unittest.cc deleted file mode 100644 index db983ea5baa5d2..00000000000000 --- a/cc/trees/image_animation_controller_unittest.cc +++ /dev/null @@ -1,679 +0,0 @@ -// Copyright 2017 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. - -#include "cc/trees/image_animation_controller.h" - -#include "base/memory/ptr_util.h" -#include "base/run_loop.h" -#include "base/test/gtest_util.h" -#include "base/threading/thread_task_runner_handle.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace cc { - -class FakeAnimationDriver : public ImageAnimationController::AnimationDriver { - public: - FakeAnimationDriver() {} - ~FakeAnimationDriver() override {} - - void set_should_animate(bool should_animate) { - should_animate_ = should_animate; - } - - // ImageAnimationController::AnimationDriver implementation. - bool ShouldAnimate(PaintImage::Id paint_image_id) const override { - return should_animate_; - } - - private: - bool should_animate_ = true; -}; - -class DelayTrackingTaskRunner : public base::SingleThreadTaskRunner { - public: - explicit DelayTrackingTaskRunner(base::SingleThreadTaskRunner* task_runner) - : task_runner_(task_runner) {} - - bool PostDelayedTask(const base::Location& from_here, - base::OnceClosure task, - base::TimeDelta delay) override { - last_delay_.emplace(delay); - return task_runner_->PostTask(from_here, std::move(task)); - } - - bool RunsTasksInCurrentSequence() const override { - return task_runner_->RunsTasksInCurrentSequence(); - } - - bool PostNonNestableDelayedTask(const base::Location& from_here, - base::OnceClosure task, - base::TimeDelta delay) override { - last_delay_.emplace(delay); - return task_runner_->PostTask(from_here, std::move(task)); - } - - void VerifyDelay(base::TimeDelta expected) { - DCHECK(last_delay_.has_value()); - EXPECT_EQ(last_delay_.value(), expected); - last_delay_.reset(); - } - - bool has_delay() const { return last_delay_.has_value(); } - - private: - ~DelayTrackingTaskRunner() override = default; - - base::Optional last_delay_; - base::SingleThreadTaskRunner* task_runner_; -}; - -class ImageAnimationControllerTest : public testing::Test { - public: - void SetUp() override { - task_runner_ = - new DelayTrackingTaskRunner(base::ThreadTaskRunnerHandle::Get().get()); - base::Closure invalidation_callback = - base::Bind(&ImageAnimationControllerTest::RequestInvalidation, - base::Unretained(this)); - controller_ = base::MakeUnique( - task_runner_.get(), invalidation_callback); - now_ += base::TimeDelta::FromSeconds(10); - } - - void TearDown() override { controller_.reset(); } - - void LoopOnceNoDelay(PaintImage::Id paint_image_id, - const std::vector& frames, - size_t num_of_frames_to_loop, - int repetitions_completed) { - DCHECK_LE(num_of_frames_to_loop, frames.size()); - - invalidation_count_ = 0; - for (size_t i = 0; i < num_of_frames_to_loop; ++i) { - SCOPED_TRACE(i); - - // Run the pending invalidation. - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, static_cast(i + 1)); - - // Animate the image on the sync tree. - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(controller_->GetFrameIndexForImage(paint_image_id, - WhichTree::PENDING_TREE), - i); - size_t active_index = i - 1; - if (i == 0u) { - // If we are displaying the first frame on the pending tree, then the - // active tree has the first frame as well if this is the first loop, - // otherwise it should be the last frame since we are starting a new - // loop. - if (repetitions_completed == 0) - active_index = 0u; - else - active_index = frames.size() - 1; - } - - EXPECT_EQ(controller_->GetFrameIndexForImage(paint_image_id, - WhichTree::ACTIVE_TREE), - active_index); - - if (i == 0u && repetitions_completed == 0) { - // Starting the animation does not perform any invalidation. - EXPECT_EQ(animated_images.size(), 0u); - } else { - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(paint_image_id), 1u); - } - - // Animating should schedule an invalidation for the next frame, until we - // reach the last frame. - if (i != num_of_frames_to_loop - 1) - task_runner_->VerifyDelay(frames[i].duration); - - // Activate and advance time to the next frame. - controller_->DidActivate(); - AdvanceNow(frames[i].duration); - } - } - - protected: - void RequestInvalidation() { invalidation_count_++; } - - void AdvanceNow(base::TimeDelta delta) { now_ += delta; } - - base::TimeTicks now_; - int invalidation_count_ = 0; - std::unique_ptr controller_; - scoped_refptr task_runner_; -}; - -TEST_F(ImageAnimationControllerTest, AnimationWithDelays) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, - kAnimationLoopInfinite); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Display 2 loops in the animation. - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0); - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1); - - // now_ is set to the time at which the first frame should be displayed for - // the third iteration. Add a delay that causes us to skip the first frame. - base::TimeDelta additional_delay = base::TimeDelta::FromMilliseconds(1); - AdvanceNow(data.frames[0].duration + additional_delay); - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(data.paint_image_id), 1u); - - // The pending tree displays the second frame while the active tree has the - // third frame. - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 1u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 2u); - - // Invalidation delay is based on the duration of the second frame and the - // delay in creating this sync tree. - task_runner_->VerifyDelay(frames[1].duration - additional_delay); - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - // Activate and animate with a delay that causes us to skip another frame. - controller_->DidActivate(); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 1u); - AdvanceNow(data.frames[1].duration + data.frames[2].duration); - animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(data.paint_image_id), 1u); - - // The pending tree displays the first frame, while the active tree has the - // second frame. - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 1u); - - // Invalidation delay is based on the duration of the first frame and the - // initial additionaly delay. - task_runner_->VerifyDelay(frames[0].duration - additional_delay); - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, DriversControlAnimationTicking) { - std::vector first_image_frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - DiscardableImageMap::AnimatedImageMetadata first_data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, - first_image_frames, kAnimationLoopOnce); - controller_->UpdateAnimatedImage(first_data); - FakeAnimationDriver first_driver; - controller_->RegisterAnimationDriver(first_data.paint_image_id, - &first_driver); - - std::vector second_image_frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(5)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - DiscardableImageMap::AnimatedImageMetadata second_data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, - second_image_frames, kAnimationLoopOnce); - controller_->UpdateAnimatedImage(second_data); - FakeAnimationDriver second_driver; - controller_->RegisterAnimationDriver(second_data.paint_image_id, - &second_driver); - - // Disable animating from all drivers, no invalidation request should be made. - first_driver.set_should_animate(false); - second_driver.set_should_animate(false); - controller_->UpdateStateFromDrivers(now_); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - - // Enable animating from the first driver, which should schedule an - // invalidation to advance this animation. - first_driver.set_should_animate(true); - controller_->UpdateStateFromDrivers(now_); - task_runner_->VerifyDelay(base::TimeDelta()); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - // Start animating the first image. - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 0u); - - // Invalidation should be scheduled for this image. - task_runner_->VerifyDelay(first_image_frames[0].duration); - - // Now enable animating the second image instead. - second_driver.set_should_animate(true); - controller_->UpdateStateFromDrivers(now_); - - // Invalidation is triggered to start with no delay since the second image has - // not started animating yet. - task_runner_->VerifyDelay(base::TimeDelta()); - - // Disable animating all images. - first_driver.set_should_animate(false); - second_driver.set_should_animate(false); - controller_->UpdateStateFromDrivers(now_); - - // Any scheduled invalidation should be cancelled. - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - controller_->UnregisterAnimationDriver(first_data.paint_image_id, - &first_driver); - controller_->UnregisterAnimationDriver(second_data.paint_image_id, - &second_driver); -} - -TEST_F(ImageAnimationControllerTest, RepetitionsRequested) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, - kAnimationLoopOnce); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Finish a single loop in the animation. - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0); - - // No invalidation should be scheduled now, since the requested number of - // loops have been completed. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); - - // Now with a repetition count of 5. - data.paint_image_id = PaintImage::GetNextId(); - data.repetition_count = 5; - controller_->UpdateAnimatedImage(data); - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - for (int i = 0; i < data.repetition_count; ++i) { - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), i); - - // Since we will be looping back to the first frame, the invalidation should - // have the delay of the last frame. Until we reach the end of requested - // iterations. - if (i < data.repetition_count - 1) - task_runner_->VerifyDelay(frames.back().duration); - invalidation_count_ = 0; - } - - // No invalidation should be scheduled now, since the requested number of - // loops have been completed. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); - - // Now with kAnimationLoopInfinite. - data.paint_image_id = PaintImage::GetNextId(); - data.repetition_count = kAnimationLoopInfinite; - controller_->UpdateAnimatedImage(data); - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - for (int i = 0; i < 7; ++i) { - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), i); - - // Since we will be looping back to the first frame, the invalidation should - // have the delay of the last frame. Until we reach the end of requested - // iterations. - if (i < data.repetition_count - 1) - task_runner_->VerifyDelay(frames.back().duration); - invalidation_count_ = 0; - } - - // We still have an invalidation scheduled since the image will keep looping - // till the drivers keep the animation active. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); - - // Now try with a kAnimationNone image, which should result in a DCHECK - // failure. - data.paint_image_id = PaintImage::GetNextId(); - data.repetition_count = kAnimationNone; - EXPECT_DCHECK_DEATH(controller_->UpdateAnimatedImage(data)); -} - -TEST_F(ImageAnimationControllerTest, DisplayCompleteFrameOnly) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(false, base::TimeDelta::FromMilliseconds(4))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE, - frames, kAnimationLoopInfinite); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Advance until the second frame. - LoopOnceNoDelay(data.paint_image_id, frames, 2, 0); - - // We have no invalidation scheduled since its not possible to animate the - // image further until the second frame is completed. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - - // The frame is still incomplete but the image has been marked complete, which - // should push the animation forward. - data.completion_state = PaintImage::CompletionState::DONE; - controller_->UpdateAnimatedImage(data); - controller_->UpdateStateFromDrivers(now_); - - // There is no delay for advancing to this frame since we advanced the time - // in the loop iteration above. - task_runner_->VerifyDelay(base::TimeDelta()); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, DontLoopPartiallyLoadedImages) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE, - frames, 2); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Finish the first loop. - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0); - - // We shouldn't be looping back to the first frame until the image is known to - // be completely loaded. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - - // Now add another frame and mark the image complete. The animation should - // advance and we should see another repetition. This verifies that we don't - // mark loops complete on reaching the last frame until the image is - // completely loaded and the frame count is known to be accurate. - frames.push_back(FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))); - data.completion_state = PaintImage::CompletionState::DONE; - data.frames = frames; - controller_->UpdateAnimatedImage(data); - controller_->UpdateStateFromDrivers(now_); - - // The animation advances to the last frame. We don't have a delay since we - // already advanced to the desired time in the loop above. - task_runner_->VerifyDelay(base::TimeDelta()); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 2u); - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(data.paint_image_id), 1u); - controller_->DidActivate(); - - // Advancing the animation scheduled an invalidation for the next iteration. - task_runner_->VerifyDelay(frames.back().duration); - - // Perform another loop in the animation. - AdvanceNow(frames.back().duration); - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1); - - // No invalidation should have been requested at the end of the second loop. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, DontAdvanceUntilDesiredTime) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, - kAnimationLoopOnce); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Advance the first frame. - task_runner_->VerifyDelay(base::TimeDelta()); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 0u); - EXPECT_EQ(animated_images.size(), 0u); - controller_->DidActivate(); - - // We have an invalidation request for the second frame. - task_runner_->VerifyDelay(frames[0].duration); - - // While there is still time for the second frame, we get a new sync tree. The - // animation is not advanced. - base::TimeDelta time_remaining = base::TimeDelta::FromMilliseconds(1); - AdvanceNow(frames[0].duration - time_remaining); - animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 0u); - EXPECT_EQ(animated_images.size(), 0u); - controller_->DidActivate(); - - // We did not get another invalidation request because there is no change in - // the desired time and the previous request is still pending. - EXPECT_FALSE(task_runner_->has_delay()); - - // We have a sync tree before the invalidation task could run. - AdvanceNow(time_remaining); - animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(data.paint_image_id), 1u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 1u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 0u); - controller_->DidActivate(); - - // We shouldn't have an invalidation because the animation was already - // advanced to the last frame and the previous one should have been cancelled. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 0); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, RestartAfterSyncCutoff) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, - kAnimationLoopOnce); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Advance the first frame. - task_runner_->VerifyDelay(base::TimeDelta()); - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 0u); - controller_->DidActivate(); - - // Invalidation request for the second frame. - task_runner_->VerifyDelay(frames[0].duration); - - // Advance the time by 10 min. - AdvanceNow(base::TimeDelta::FromMinutes(10)); - - // Animate again, it starts from the first frame. We don't see an - // invalidation, because that's the frame we are already displaying. - animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 0u); - controller_->DidActivate(); - - // New invalidation request since the desired invalidation time changed. - task_runner_->VerifyDelay(frames[0].duration); - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, DontSkipLoopsToCatchUpAfterLoad) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(5))}; - - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::PARTIALLY_DONE, - frames, kAnimationLoopInfinite); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Perform the first loop while the image is partially loaded, until the third - // frame. - LoopOnceNoDelay(data.paint_image_id, frames, 3u, 0); - - // The invalidation has been scheduled with a delay for the third frame's - // duration. - task_runner_->VerifyDelay(frames[2].duration); - - // |now_| is set to the desired time for the fourth frame. Advance further so - // we would reach the time for the second frame. - AdvanceNow(frames[3].duration + frames[0].duration); - - // Finish the image load. - data.completion_state = PaintImage::CompletionState::DONE; - controller_->UpdateAnimatedImage(data); - controller_->UpdateStateFromDrivers(now_); - - // Invalidation is scheduled immediately because we are way past the desired - // time. We should start from the first frame after the image is loaded - // instead of skipping frames. - task_runner_->VerifyDelay(base::TimeDelta()); - auto animated_images = controller_->AnimateForSyncTree(now_); - EXPECT_EQ(animated_images.size(), 1u); - EXPECT_EQ(animated_images.count(data.paint_image_id), 1u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - 2u); - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -TEST_F(ImageAnimationControllerTest, FinishRepetitionsDuringCatchUp) { - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromMilliseconds(2)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(3)), - FrameMetadata(true, base::TimeDelta::FromMilliseconds(4))}; - - // The animation wants 3 loops. - DiscardableImageMap::AnimatedImageMetadata data( - PaintImage::GetNextId(), PaintImage::CompletionState::DONE, frames, 3); - controller_->UpdateAnimatedImage(data); - FakeAnimationDriver driver; - controller_->RegisterAnimationDriver(data.paint_image_id, &driver); - controller_->UpdateStateFromDrivers(now_); - - // Finish 2 loops. - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 0); - LoopOnceNoDelay(data.paint_image_id, frames, frames.size(), 1); - - // now_ is set to the desired time for the first frame. Advance it so we would - // reach way beyond the third repeition. - AdvanceNow(base::TimeDelta::FromMinutes(1)); - - // Advance the animation, we should see the last frame since the desired - // repetition count will be reached during catch up. - invalidation_count_ = 0; - base::RunLoop().RunUntilIdle(); - EXPECT_EQ(invalidation_count_, 1); - auto animated_images = controller_->AnimateForSyncTree(now_); - // No invalidation since the active tree is already at the last frame. - EXPECT_EQ(animated_images.size(), 0u); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::PENDING_TREE), - frames.size() - 1); - EXPECT_EQ(controller_->GetFrameIndexForImage(data.paint_image_id, - WhichTree::ACTIVE_TREE), - frames.size() - 1); - - controller_->UnregisterAnimationDriver(data.paint_image_id, &driver); -} - -} // namespace cc diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc index 3ce444ddc9ed0a..e7605f17509e2a 100644 --- a/cc/trees/layer_tree_host_impl.cc +++ b/cc/trees/layer_tree_host_impl.cc @@ -67,7 +67,6 @@ #include "cc/trees/draw_property_utils.h" #include "cc/trees/effect_node.h" #include "cc/trees/frame_rate_counter.h" -#include "cc/trees/image_animation_controller.h" #include "cc/trees/latency_info_swap_promise_monitor.h" #include "cc/trees/layer_tree_frame_sink.h" #include "cc/trees/layer_tree_host_common.h" @@ -271,16 +270,6 @@ LayerTreeHostImpl::LayerTreeHostImpl( settings.top_controls_hide_threshold); tile_manager_.SetDecodedImageTracker(&decoded_image_tracker_); - - if (settings_.enable_image_animations) { - // It is safe to use base::Unretained here since we will outlive the - // ImageAnimationController. - base::Closure invalidation_callback = - base::Bind(&LayerTreeHostImpl::RequestInvalidationForAnimatedImages, - base::Unretained(this)); - image_animation_controller_.emplace(GetTaskRunner(), - std::move(invalidation_callback)); - } } LayerTreeHostImpl::~LayerTreeHostImpl() { @@ -355,6 +344,9 @@ void LayerTreeHostImpl::CommitComplete() { } void LayerTreeHostImpl::UpdateSyncTreeAfterCommitOrImplSideInvalidation() { + sync_tree()->InvalidateRegionForImages( + tile_manager_.TakeImagesToInvalidateOnSyncTree()); + if (CommitToActiveTree()) { active_tree_->HandleScrollbarShowRequestsFromMain(); @@ -390,20 +382,6 @@ void LayerTreeHostImpl::UpdateSyncTreeAfterCommitOrImplSideInvalidation() { // layer can or cannot use lcd text. So, this is the cleanup pass to // determine if lcd state needs to switch due to draw properties. sync_tree()->UpdateCanUseLCDText(); - - // Defer invalidating images until UpdateDrawProperties is performed since - // that updates whether an image should be animated based on its visibility - // and the updated data for the image from the main frame. - PaintImageIdFlatSet images_to_invalidate = - tile_manager_.TakeImagesToInvalidateOnSyncTree(); - if (image_animation_controller_.has_value()) { - const auto& animated_images = - image_animation_controller_.value().AnimateForSyncTree( - CurrentBeginFrameArgs().frame_time); - images_to_invalidate.insert(animated_images.begin(), animated_images.end()); - } - sync_tree()->InvalidateRegionForImages(images_to_invalidate); - // Start working on newly created tiles immediately if needed. // TODO(vmpstr): Investigate always having PrepareTiles issue // NotifyReadyToActivate, instead of handling it here. @@ -1428,15 +1406,6 @@ void LayerTreeHostImpl::RequestImplSideInvalidationForCheckerImagedTiles() { client_->NeedsImplSideInvalidation(needs_first_draw_on_activation); } -size_t LayerTreeHostImpl::GetFrameIndexForImage(const PaintImage& paint_image, - WhichTree tree) const { - if (!paint_image.ShouldAnimate() || !image_animation_controller_.has_value()) - return paint_image.frame_index(); - - return image_animation_controller_.value().GetFrameIndexForImage( - paint_image.stable_id(), tree); -} - void LayerTreeHostImpl::NotifyReadyToActivate() { pending_tree_raster_duration_timer_.reset(); client_->NotifyReadyToActivate(); @@ -2237,17 +2206,8 @@ void LayerTreeHostImpl::ActivateSyncTree() { UpdateViewportContainerSizes(); - // Inform the ImageAnimationController and TileManager before dirtying tile - // priorities. Since these components cache tree specific state, these should - // be updated before DidModifyTilePriorities which can synchronously issue a - // PrepareTiles. - if (image_animation_controller_) - image_animation_controller_->DidActivate(); - tile_manager_.DidActivateSyncTree(); - active_tree_->DidBecomeActive(); client_->RenewTreePriority(); - // If we have any picture layers, then by activating we also modified tile // priorities. if (!active_tree_->picture_layers().empty()) @@ -4540,13 +4500,4 @@ void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { animation_controller->DidScrollUpdate(); } -void LayerTreeHostImpl::RequestInvalidationForAnimatedImages() { - DCHECK(image_animation_controller_); - - // If we are animating an image, we want at least one draw of the active tree - // before a new tree is activated. - bool needs_first_draw_on_activation = true; - client_->NeedsImplSideInvalidation(needs_first_draw_on_activation); -} - } // namespace cc diff --git a/cc/trees/layer_tree_host_impl.h b/cc/trees/layer_tree_host_impl.h index 0373670ff3e82f..250d679ed8e454 100644 --- a/cc/trees/layer_tree_host_impl.h +++ b/cc/trees/layer_tree_host_impl.h @@ -59,7 +59,6 @@ class LayerTreeFrameSink; class DebugRectHistory; class EvictionTilePriorityQueue; class FrameRateCounter; -class ImageAnimationController; class LayerImpl; class LayerTreeImpl; class MemoryHistory; @@ -355,8 +354,6 @@ class CC_EXPORT LayerTreeHostImpl void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) override; gfx::ColorSpace GetRasterColorSpace() const override; void RequestImplSideInvalidationForCheckerImagedTiles() override; - size_t GetFrameIndexForImage(const PaintImage& paint_image, - WhichTree tree) const override; // ScrollbarAnimationControllerClient implementation. void PostDelayedScrollbarAnimationTask(const base::Closure& task, @@ -420,11 +417,6 @@ class CC_EXPORT LayerTreeHostImpl } ResourcePool* resource_pool() { return resource_pool_.get(); } ImageDecodeCache* image_decode_cache() { return image_decode_cache_.get(); } - ImageAnimationController* image_animation_controller() { - if (!image_animation_controller_.has_value()) - return nullptr; - return &image_animation_controller_.value(); - } virtual void WillBeginImplFrame(const viz::BeginFrameArgs& args); virtual void DidFinishImplFrame(); @@ -741,9 +733,6 @@ class CC_EXPORT LayerTreeHostImpl // tree, because the active tree value always takes precedence for scrollbars. void PushScrollbarOpacitiesFromActiveToPending(); - // Request an impl-side invalidation to animate an image. - void RequestInvalidationForAnimatedImages(); - using UIResourceMap = std::unordered_map; UIResourceMap ui_resource_map_; @@ -907,8 +896,6 @@ class CC_EXPORT LayerTreeHostImpl ImplThreadPhase impl_thread_phase_; - base::Optional image_animation_controller_; - DISALLOW_COPY_AND_ASSIGN(LayerTreeHostImpl); }; diff --git a/cc/trees/layer_tree_host_unittest.cc b/cc/trees/layer_tree_host_unittest.cc index 84dcd17f1b824b..67ab40aad76a0c 100644 --- a/cc/trees/layer_tree_host_unittest.cc +++ b/cc/trees/layer_tree_host_unittest.cc @@ -25,12 +25,10 @@ #include "cc/layers/picture_layer.h" #include "cc/layers/solid_color_layer.h" #include "cc/layers/video_layer.h" -#include "cc/paint/image_animation_count.h" #include "cc/resources/ui_resource_manager.h" #include "cc/test/fake_content_layer_client.h" #include "cc/test/fake_layer_tree_host_client.h" #include "cc/test/fake_output_surface.h" -#include "cc/test/fake_paint_image_generator.h" #include "cc/test/fake_painted_scrollbar_layer.h" #include "cc/test/fake_picture_layer.h" #include "cc/test/fake_picture_layer_impl.h" @@ -7843,8 +7841,7 @@ class LayerTreeHostTestQueueImageDecode : public LayerTreeHostTest { image_ = DrawImage(CreateDiscardablePaintImage(gfx::Size(400, 400)), SkIRect::MakeWH(400, 400), kNone_SkFilterQuality, - SkMatrix::I(), PaintImage::kDefaultFrameIndex, - gfx::ColorSpace()); + SkMatrix::I(), gfx::ColorSpace()); auto callback = base::Bind(&LayerTreeHostTestQueueImageDecode::ImageDecodeFinished, base::Unretained(this)); @@ -8044,86 +8041,5 @@ class LayerTreeHostTestDiscardAckAfterRelease : public LayerTreeHostTest { SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDiscardAckAfterRelease); -class LayerTreeHostTestImageAnimation : public LayerTreeHostTest { - public: - void BeginTest() override { PostSetNeedsCommitToMainThread(); } - - void InitializeSettings(LayerTreeSettings* settings) override { - settings->enable_image_animations = true; - } - - void SetupTree() override { - gfx::Size layer_size(1000, 500); - content_layer_client_.set_bounds(layer_size); - content_layer_client_.set_fill_with_nonsolid_color(true); - std::vector frames = { - FrameMetadata(true, base::TimeDelta::FromSeconds(1)), - FrameMetadata(true, base::TimeDelta::FromSeconds(1)), - FrameMetadata(true, base::TimeDelta::FromSeconds(1))}; - generator_ = sk_make_sp( - SkImageInfo::MakeN32Premul(500, 500), frames); - PaintImage image = - PaintImageBuilder() - .set_id(PaintImage::GetNextId()) - .set_paint_image_generator(generator_) - .set_frame_index(0u) - .set_animation_type(PaintImage::AnimationType::ANIMATED) - .set_repetition_count(kAnimationLoopOnce) - .TakePaintImage(); - content_layer_client_.add_draw_image(image, gfx::Point(0, 0), PaintFlags()); - - layer_tree_host()->SetRootLayer( - FakePictureLayer::Create(&content_layer_client_)); - layer_tree_host()->root_layer()->SetBounds(layer_size); - LayerTreeTest::SetupTree(); - } - - void WillPrepareToDrawOnThread(LayerTreeHostImpl* host_impl) override { - gfx::Rect image_rect(-1, -1, 502, 502); - auto* layer = static_cast( - host_impl->active_tree()->root_layer_for_testing()); - switch (++draw_count_) { - case 1: - // First draw, everything is invalid. - EXPECT_EQ(layer->InvalidationForTesting().bounds(), - gfx::Rect(layer->bounds())); - EXPECT_EQ(layer->update_rect(), gfx::Rect(layer->bounds())); - EXPECT_EQ(generator_->frames_decoded().size(), 1u); - EXPECT_EQ(generator_->frames_decoded().count(0u), 1u); - break; - case 2: - // Every frame after the first one should invalidate only the image. - EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect); - EXPECT_EQ(layer->update_rect(), image_rect); - EXPECT_EQ(generator_->frames_decoded().size(), 2u); - EXPECT_EQ(generator_->frames_decoded().count(1u), 1u); - break; - case 3: - EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect); - EXPECT_EQ(layer->update_rect(), image_rect); - EXPECT_EQ(generator_->frames_decoded().size(), 3u); - EXPECT_EQ(generator_->frames_decoded().count(2u), 1u); - break; - default: - // Only 3 draws should happen for 3 frames of the animate image. - NOTREACHED(); - } - - if (draw_count_ == 3) - EndTest(); - } - - void AfterTest() override { - EXPECT_EQ(generator_->frames_decoded().size(), 3u); - } - - private: - FakeContentLayerClient content_layer_client_; - sk_sp generator_; - int draw_count_ = 0; -}; - -MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimation); - } // namespace } // namespace cc diff --git a/cc/trees/layer_tree_impl.cc b/cc/trees/layer_tree_impl.cc index 55b4daef44aff8..fa1b7be01dc7a7 100644 --- a/cc/trees/layer_tree_impl.cc +++ b/cc/trees/layer_tree_impl.cc @@ -1119,11 +1119,6 @@ bool LayerTreeImpl::UpdateDrawProperties() { "layers_updated_count", layers_updated_count); } - if (image_animation_controller()) { - image_animation_controller()->UpdateStateFromDrivers( - host_impl_->CurrentBeginFrameArgs().frame_time); - } - DCHECK(!needs_update_draw_properties_) << "CalcDrawProperties should not set_needs_update_draw_properties()"; return true; @@ -1333,10 +1328,6 @@ ImageDecodeCache* LayerTreeImpl::image_decode_cache() const { return host_impl_->image_decode_cache(); } -ImageAnimationController* LayerTreeImpl::image_animation_controller() const { - return host_impl_->image_animation_controller(); -} - FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { return host_impl_->fps_counter(); } diff --git a/cc/trees/layer_tree_impl.h b/cc/trees/layer_tree_impl.h index 38bf8c26460dad..a4a3feddef1003 100644 --- a/cc/trees/layer_tree_impl.h +++ b/cc/trees/layer_tree_impl.h @@ -111,7 +111,6 @@ class CC_EXPORT LayerTreeImpl { LayerTreeResourceProvider* resource_provider() const; TileManager* tile_manager() const; ImageDecodeCache* image_decode_cache() const; - ImageAnimationController* image_animation_controller() const; FrameRateCounter* frame_rate_counter() const; MemoryHistory* memory_history() const; gfx::Size device_viewport_size() const; diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h index 804478ac8092ff..0b68410298b992 100644 --- a/cc/trees/layer_tree_settings.h +++ b/cc/trees/layer_tree_settings.h @@ -145,9 +145,6 @@ class CC_EXPORT LayerTreeSettings { // Whether to use out of process raster. If true, whenever gpu raster // would have been used, out of process gpu raster will be used instead. bool enable_oop_rasterization = false; - - // Whether images should be animated in the compositor. - bool enable_image_animations = false; }; } // namespace cc diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 7bcbc0bfc078a8..4c3ae74909c33d 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -2539,7 +2539,6 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( switches::kDisableWebGLImageChromium, switches::kDomAutomationController, switches::kEnableBrowserSideNavigation, - switches::kEnableCompositorImageAnimations, switches::kEnableDisplayList2dCanvas, switches::kEnableDistanceFieldText, switches::kEnableExperimentalCanvasFeatures, diff --git a/content/public/common/content_switches.cc b/content/public/common/content_switches.cc index 6ad7f331ecb45b..7005c8e528061d 100644 --- a/content/public/common/content_switches.cc +++ b/content/public/common/content_switches.cc @@ -362,10 +362,6 @@ const char kEnableBlinkFeatures[] = "enable-blink-features"; const char kDisableBrowserSideNavigation[] = "disable-browser-side-navigation"; const char kEnableBrowserSideNavigation[] = "enable-browser-side-navigation"; -// Enable animating of images in the compositor instead of blink. -const char kEnableCompositorImageAnimations[] = - "enable-compositor-image-animations"; - // Enables display list based 2d canvas implementation. Options: // 1. Enable: allow browser to use display list for 2d canvas (browser makes // decision). diff --git a/content/public/common/content_switches.h b/content/public/common/content_switches.h index d11eab14829768..b1bdada7e0f72d 100644 --- a/content/public/common/content_switches.h +++ b/content/public/common/content_switches.h @@ -115,7 +115,6 @@ CONTENT_EXPORT extern const char kEnablePreferCompositingToLCDText[]; CONTENT_EXPORT extern const char kEnableBlinkFeatures[]; CONTENT_EXPORT extern const char kEnableBackgroundFetchPersistence[]; CONTENT_EXPORT extern const char kEnableBrowserSideNavigation[]; -CONTENT_EXPORT extern const char kEnableCompositorImageAnimations[]; CONTENT_EXPORT extern const char kEnableDisplayList2dCanvas[]; CONTENT_EXPORT extern const char kEnableDistanceFieldText[]; CONTENT_EXPORT extern const char kEnableExperimentalCanvasFeatures[]; diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index fbd0f3884d28a9..aeb94bc6750e7f 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -595,9 +595,6 @@ cc::LayerTreeSettings RenderWidgetCompositor::GenerateLayerTreeSettings( settings.wait_for_all_pipeline_stages_before_draw = cmd.HasSwitch(cc::switches::kRunAllCompositorStagesBeforeDraw); - settings.enable_image_animations = - cmd.HasSwitch(switches::kEnableCompositorImageAnimations); - return settings; } diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index 5dc03fa29e7fcd..4c342e71bcad05 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -857,9 +857,6 @@ void RenderThreadImpl::Init( is_distance_field_text_enabled_ = false; } - WebRuntimeFeatures::EnableCompositorImageAnimations( - command_line.HasSwitch(switches::kEnableCompositorImageAnimations)); - // Note that under Linux, the media library will normally already have // been initialized by the Zygote before this instance became a Renderer. media::InitializeMediaLibrary(); diff --git a/third_party/WebKit/Source/platform/exported/WebRuntimeFeatures.cpp b/third_party/WebKit/Source/platform/exported/WebRuntimeFeatures.cpp index 73839bfa887bd0..fd8b0e09dc5e55 100644 --- a/third_party/WebKit/Source/platform/exported/WebRuntimeFeatures.cpp +++ b/third_party/WebKit/Source/platform/exported/WebRuntimeFeatures.cpp @@ -96,10 +96,6 @@ void WebRuntimeFeatures::EnableCompositorTouchAction(bool enable) { RuntimeEnabledFeatures::SetCompositorTouchActionEnabled(enable); } -void WebRuntimeFeatures::EnableCompositorImageAnimations(bool enable) { - RuntimeEnabledFeatures::SetCompositorImageAnimationsEnabled(enable); -} - void WebRuntimeFeatures::EnableCSSHexAlphaColor(bool enable) { RuntimeEnabledFeatures::SetCSSHexAlphaColorEnabled(enable); } diff --git a/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp b/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp index 722e42e59ea71b..18f0ecd76745ee 100644 --- a/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp +++ b/third_party/WebKit/Source/platform/graphics/BitmapImage.cpp @@ -257,14 +257,6 @@ Image::SizeAvailability BitmapImage::DataChanged(bool all_data_received) { } } - // If the image is being animated by the compositor, clear the cached_frame_ - // on a data update to push it to the compositor. Since we never advance the - // animation here, the |cached_frame_index_| is always the first frame and the - // |cached_frame_| might have not have been cleared in the loop above. - if (RuntimeEnabledFeatures::CompositorImageAnimationsEnabled() - && MaybeAnimated()) - cached_frame_ = PaintImage(); - // Feed all the data we've seen so far to the image decoder. all_data_received_ = all_data_received; @@ -484,9 +476,6 @@ int BitmapImage::RepetitionCount() { } bool BitmapImage::ShouldAnimate() { - if (RuntimeEnabledFeatures::CompositorImageAnimationsEnabled()) - return false; - bool animated = RepetitionCount() != kAnimationNone && !animation_finished_ && GetImageObserver(); if (animated && animation_policy_ == kImageAnimationPolicyNoAnimation) diff --git a/third_party/WebKit/Source/platform/runtime_enabled_features.json5 b/third_party/WebKit/Source/platform/runtime_enabled_features.json5 index 8d4b8a22ef1260..c8932de5e69b8e 100644 --- a/third_party/WebKit/Source/platform/runtime_enabled_features.json5 +++ b/third_party/WebKit/Source/platform/runtime_enabled_features.json5 @@ -165,10 +165,6 @@ settable_from_internals: true, status: "stable", }, - { - name: "CompositorImageAnimations", - status: "test", - }, { name: "CompositorTouchAction", status: "test", diff --git a/third_party/WebKit/public/platform/WebRuntimeFeatures.h b/third_party/WebKit/public/platform/WebRuntimeFeatures.h index 6080d09afaa312..eb160c55cdd84a 100644 --- a/third_party/WebKit/public/platform/WebRuntimeFeatures.h +++ b/third_party/WebKit/public/platform/WebRuntimeFeatures.h @@ -67,8 +67,6 @@ class WebRuntimeFeatures { BLINK_PLATFORM_EXPORT static void EnableCompositorTouchAction(bool); - BLINK_PLATFORM_EXPORT static void EnableCompositorImageAnimations(bool); - BLINK_PLATFORM_EXPORT static void EnableDisplayList2dCanvas(bool); BLINK_PLATFORM_EXPORT static void ForceDisplayList2dCanvas(bool);