diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 15:06:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:48:58 +0000 |
commit | daa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch) | |
tree | 96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/cc/tiles | |
parent | be59a35641616a4cf23c4a13fa0632624b021c1b (diff) | |
download | qtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz |
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/cc/tiles')
21 files changed, 1206 insertions, 1178 deletions
diff --git a/chromium/cc/tiles/checker_image_tracker.cc b/chromium/cc/tiles/checker_image_tracker.cc index ccdfd3f936e..ee5e756243d 100644 --- a/chromium/cc/tiles/checker_image_tracker.cc +++ b/chromium/cc/tiles/checker_image_tracker.cc @@ -36,10 +36,9 @@ enum class CheckerImagingDecision { // Vetoed because checkering of images has been disabled. kVetoedForceDisable = 9, - // Vetoed because we only checker images on tiles required for activation. - kVetoedNotRequiredForActivation = 10, + // 10 used to be kVetoedNotRequiredForActivation. - kCheckerImagingDecisionCount, + kCheckerImagingDecisionCount = 11, }; std::string ToString(PaintImage::Id paint_image_id, @@ -261,8 +260,7 @@ void CheckerImageTracker::DidFinishImageDecode( } bool CheckerImageTracker::ShouldCheckerImage(const DrawImage& draw_image, - WhichTree tree, - bool required_for_activation) { + WhichTree tree) { const PaintImage& image = draw_image.paint_image(); PaintImage::Id image_id = image.stable_id(); TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", @@ -306,15 +304,11 @@ bool CheckerImageTracker::ShouldCheckerImage(const DrawImage& draw_image, CheckerImagingDecision decision = GetCheckerImagingDecision( image, draw_image.src_rect(), min_image_bytes_to_checker_, image_controller_->image_cache_max_limit_bytes()); - if (decision == CheckerImagingDecision::kCanChecker) { - if (force_disabled_) { - // Get the decision for all the veto reasons first, so we can UMA the - // images that were not checkered only because checker-imaging was force - // disabled. - decision = CheckerImagingDecision::kVetoedForceDisable; - } else if (!required_for_activation) { - decision = CheckerImagingDecision::kVetoedNotRequiredForActivation; - } + if (decision == CheckerImagingDecision::kCanChecker && force_disabled_) { + // Get the decision for all the veto reasons first, so we can UMA the + // images that were not checkered only because checker-imaging was force + // disabled. + decision = CheckerImagingDecision::kVetoedForceDisable; } it->second.policy = decision == CheckerImagingDecision::kCanChecker @@ -362,6 +356,7 @@ 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() { @@ -400,7 +395,7 @@ void CheckerImageTracker::ScheduleNextImageDecode() { it->second.filter_quality, SkMatrix::MakeScale(it->second.scale.width(), it->second.scale.height()), - it->second.color_space); + it->second.frame_index, it->second.color_space); outstanding_image_decode_.emplace(candidate); break; } diff --git a/chromium/cc/tiles/checker_image_tracker.h b/chromium/cc/tiles/checker_image_tracker.h index 095c868fb3d..9a1157a2e09 100644 --- a/chromium/cc/tiles/checker_image_tracker.h +++ b/chromium/cc/tiles/checker_image_tracker.h @@ -59,9 +59,7 @@ class CC_EXPORT CheckerImageTracker { // Returns true if the decode for |image| will be deferred to the image decode // service and it should be be skipped during raster. - bool ShouldCheckerImage(const DrawImage& image, - WhichTree tree, - bool required_for_activation); + bool ShouldCheckerImage(const DrawImage& image, WhichTree tree); // Provides a prioritized queue of images to decode. using ImageDecodeQueue = std::vector<ImageDecodeRequest>; @@ -130,6 +128,7 @@ 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/chromium/cc/tiles/checker_image_tracker_unittest.cc b/chromium/cc/tiles/checker_image_tracker_unittest.cc index ef0fcdddafe..9872893575d 100644 --- a/chromium/cc/tiles/checker_image_tracker_unittest.cc +++ b/chromium/cc/tiles/checker_image_tracker_unittest.cc @@ -113,7 +113,7 @@ class CheckerImageTrackerTest : public testing::Test, } auto generator = CreatePaintImageGenerator(gfx::Size(dimension, dimension)); - return DrawImage(PaintImageBuilder() + return DrawImage(PaintImageBuilder::WithDefault() .set_id(PaintImage::GetNextId()) .set_paint_image_generator(std::move(generator)) .set_animation_type(animation) @@ -121,13 +121,12 @@ class CheckerImageTrackerTest : public testing::Test, .set_is_multipart(is_multipart) .TakePaintImage(), SkIRect::MakeWH(dimension, dimension), - kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), + PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); } bool ShouldCheckerImage(const DrawImage& draw_image, WhichTree tree) { - bool required_for_activation = true; - return checker_image_tracker_->ShouldCheckerImage(draw_image, tree, - required_for_activation); + return checker_image_tracker_->ShouldCheckerImage(draw_image, tree); } CheckerImageTracker::ImageDecodeQueue BuildImageDecodeQueue( @@ -428,12 +427,13 @@ TEST_F(CheckerImageTrackerTest, CheckersOnlyStaticCompletedImages) { gfx::Size image_size = gfx::Size(partial_image.paint_image().width(), partial_image.paint_image().height()); DrawImage completed_paint_image = DrawImage( - PaintImageBuilder() + PaintImageBuilder::WithDefault() .set_id(partial_image.paint_image().stable_id()) .set_paint_image_generator(CreatePaintImageGenerator(image_size)) .TakePaintImage(), SkIRect::MakeWH(image_size.width(), image_size.height()), - kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), PaintImage::kDefaultFrameIndex, + gfx::ColorSpace()); EXPECT_FALSE( ShouldCheckerImage(completed_paint_image, WhichTree::PENDING_TREE)); } @@ -460,10 +460,12 @@ TEST_F(CheckerImageTrackerTest, ChoosesMaxScaleAndQuality) { SetUpTracker(true); DrawImage image = CreateImage(ImageType::CHECKERABLE); - DrawImage scaled_image1(image, 0.5f, gfx::ColorSpace()); + DrawImage scaled_image1(image, 0.5f, PaintImage::kDefaultFrameIndex, + gfx::ColorSpace()); DrawImage scaled_image2 = DrawImage(image.paint_image(), image.src_rect(), kHigh_SkFilterQuality, - SkMatrix::MakeScale(1.8f), gfx::ColorSpace()); + SkMatrix::MakeScale(1.8f), PaintImage::kDefaultFrameIndex, + gfx::ColorSpace()); std::vector<DrawImage> draw_images = {scaled_image1, scaled_image2}; CheckerImageTracker::ImageDecodeQueue image_decode_queue = @@ -538,7 +540,7 @@ TEST_F(CheckerImageTrackerTest, UseSrcRectForSize) { DrawImage image = CreateImage(ImageType::CHECKERABLE); image = DrawImage(image.paint_image(), SkIRect::MakeWH(200, 200), image.filter_quality(), SkMatrix::I(), - image.target_color_space()); + PaintImage::kDefaultFrameIndex, image.target_color_space()); EXPECT_FALSE(ShouldCheckerImage(image, WhichTree::PENDING_TREE)); } @@ -560,26 +562,5 @@ TEST_F(CheckerImageTrackerTest, DisableForSoftwareRaster) { EXPECT_FALSE(ShouldCheckerImage(image2, WhichTree::PENDING_TREE)); } -TEST_F(CheckerImageTrackerTest, OnlyCheckerRequiredForActivation) { - SetUpTracker(true); - - // Should checker when required for activation. - DrawImage image1 = CreateImage(ImageType::CHECKERABLE); - bool required_for_activation = true; - EXPECT_TRUE(checker_image_tracker_->ShouldCheckerImage( - image1, WhichTree::PENDING_TREE, required_for_activation)); - - // Now the same image is not required for activation. We should still continue - // checkering it. - required_for_activation = false; - EXPECT_TRUE(checker_image_tracker_->ShouldCheckerImage( - image1, WhichTree::PENDING_TREE, required_for_activation)); - - // New image should not be checkered if it is not required for activation. - DrawImage image2 = CreateImage(ImageType::CHECKERABLE); - EXPECT_FALSE(checker_image_tracker_->ShouldCheckerImage( - image2, WhichTree::PENDING_TREE, required_for_activation)); -} - } // namespace } // namespace cc diff --git a/chromium/cc/tiles/decoded_image_tracker.cc b/chromium/cc/tiles/decoded_image_tracker.cc index 00cf27ae598..ebe3cc0b4cb 100644 --- a/chromium/cc/tiles/decoded_image_tracker.cc +++ b/chromium/cc/tiles/decoded_image_tracker.cc @@ -29,10 +29,8 @@ 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(), target_color_space); + SkMatrix::I(), image.frame_index(), target_color_space); image_controller_->QueueImageDecode( draw_image, base::Bind(&DecodedImageTracker::ImageDecodeFinished, base::Unretained(this), callback)); diff --git a/chromium/cc/tiles/gpu_image_decode_cache.cc b/chromium/cc/tiles/gpu_image_decode_cache.cc index 168c6344191..47aa4261f6a 100644 --- a/chromium/cc/tiles/gpu_image_decode_cache.cc +++ b/chromium/cc/tiles/gpu_image_decode_cache.cc @@ -121,7 +121,8 @@ 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) { - const SkImage* image = draw_image.paint_image().GetSkImage().get(); + sk_sp<SkImage> image = + draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index()); 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, @@ -210,7 +211,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().GetSkImage().get(), + &image_.paint_image(), devtools_instrumentation::ScopedImageDecodeTask::kGpu, ImageDecodeCache::ToScopedTaskType(tracing_info_.task_type)); cache_->DecodeImage(image_, tracing_info_.task_type); @@ -442,33 +443,30 @@ GpuImageDecodeCache::~GpuImageDecodeCache() { base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); } -bool GpuImageDecodeCache::GetTaskForImageAndRef(const DrawImage& draw_image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) { +ImageDecodeCache::TaskResult GpuImageDecodeCache::GetTaskForImageAndRef( + const DrawImage& draw_image, + const TracingInfo& tracing_info) { DCHECK_EQ(tracing_info.task_type, TaskType::kInRaster); - return GetTaskForImageAndRefInternal( - draw_image, tracing_info, DecodeTaskType::PART_OF_UPLOAD_TASK, task); + return GetTaskForImageAndRefInternal(draw_image, tracing_info, + DecodeTaskType::PART_OF_UPLOAD_TASK); } -bool GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& draw_image, - scoped_refptr<TileTask>* task) { +ImageDecodeCache::TaskResult +GpuImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& draw_image) { return GetTaskForImageAndRefInternal( draw_image, TracingInfo(0, TilePriority::NOW, TaskType::kOutOfRaster), - DecodeTaskType::STAND_ALONE_DECODE_TASK, task); + DecodeTaskType::STAND_ALONE_DECODE_TASK); } -bool GpuImageDecodeCache::GetTaskForImageAndRefInternal( +ImageDecodeCache::TaskResult GpuImageDecodeCache::GetTaskForImageAndRefInternal( const DrawImage& draw_image, const TracingInfo& tracing_info, - DecodeTaskType task_type, - scoped_refptr<TileTask>* task) { + DecodeTaskType task_type) { TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), "GpuImageDecodeCache::GetTaskForImageAndRef"); - if (SkipImage(draw_image)) { - *task = nullptr; - return false; - } + if (SkipImage(draw_image)) + return TaskResult(false); base::AutoLock lock(lock_); const PaintImage::FrameKey frame_key = draw_image.frame_key(); @@ -480,36 +478,30 @@ bool GpuImageDecodeCache::GetTaskForImageAndRefInternal( image_data = new_data.get(); } else if (image_data->is_at_raster) { // Image is at-raster, just return, this usage will be at-raster as well. - *task = nullptr; - return false; + return TaskResult(false); } else if (image_data->decode.decode_failure) { // We have already tried and failed to decode this image, so just return. - *task = nullptr; - return false; + return TaskResult(false); } else if (image_data->upload.image()) { // The image is already uploaded, ref and return. RefImage(draw_image); - *task = nullptr; - return true; + return TaskResult(true); } else if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK && image_data->upload.task) { // We had an existing upload task, ref the image and return the task. RefImage(draw_image); - *task = image_data->upload.task; - return true; + return TaskResult(image_data->upload.task); } else if (task_type == DecodeTaskType::STAND_ALONE_DECODE_TASK && image_data->decode.stand_alone_task) { // We had an existing out of raster task, ref the image and return the task. RefImage(draw_image); - *task = image_data->decode.stand_alone_task; - return true; + return TaskResult(image_data->decode.stand_alone_task); } // Ensure that the image we're about to decode/upload will fit in memory. if (!EnsureCapacity(image_data->size)) { // Image will not fit, do an at-raster decode. - *task = nullptr; - return false; + return TaskResult(false); } // If we had to create new image data, add it to our map now that we know it @@ -521,20 +513,21 @@ bool GpuImageDecodeCache::GetTaskForImageAndRefInternal( // it is their responsibility to release it by calling UnrefImage. RefImage(draw_image); + scoped_refptr<TileTask> task; if (task_type == DecodeTaskType::PART_OF_UPLOAD_TASK) { // Ref image and create a upload and decode tasks. We will release this ref // in UploadTaskCompleted. RefImage(draw_image); - *task = make_scoped_refptr(new ImageUploadTaskImpl( + task = base::MakeRefCounted<ImageUploadTaskImpl>( this, draw_image, GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type), - tracing_info)); - image_data->upload.task = *task; + tracing_info); + image_data->upload.task = task; } else { - *task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type); + task = GetImageDecodeTaskAndRef(draw_image, tracing_info, task_type); } - return true; + return TaskResult(task); } void GpuImageDecodeCache::UnrefImage(const DrawImage& draw_image) { @@ -858,8 +851,8 @@ scoped_refptr<TileTask> GpuImageDecodeCache::GetImageDecodeTaskAndRef( // Ref image decode and create a decode task. This ref will be released in // DecodeTaskCompleted. RefImageDecode(draw_image); - existing_task = make_scoped_refptr( - new ImageDecodeTaskImpl(this, draw_image, tracing_info, task_type)); + existing_task = base::MakeRefCounted<ImageDecodeTaskImpl>( + this, draw_image, tracing_info, task_type); } return existing_task; } @@ -1186,7 +1179,8 @@ 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. - SkImage* image = draw_image.paint_image().GetSkImage().get(); + sk_sp<SkImage> image = draw_image.paint_image().GetSkImageForFrame( + draw_image.frame_index()); if (!image->getDeferredTextureImageData( *context_threadsafe_proxy_.get(), &image_data->upload_params, 1, backing_memory->data(), nullptr, color_type_)) { @@ -1291,7 +1285,8 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) { auto params = SkImage::DeferredTextureImageUsageParams( SkMatrix::I(), CalculateDesiredFilterQuality(draw_image), upload_scale_mip_level); - SkImage* image = draw_image.paint_image().GetSkImage().get(); + sk_sp<SkImage> image = + draw_image.paint_image().GetSkImageForFrame(draw_image.frame_index()); size_t data_size = image->getDeferredTextureImageData( *context_threadsafe_proxy_.get(), ¶ms, 1, nullptr, nullptr, color_type_); @@ -1300,14 +1295,14 @@ GpuImageDecodeCache::CreateImageData(const DrawImage& draw_image) { // Can't upload image, too large or other failure. Try to use SW fallback. SkImageInfo image_info = CreateImageInfoForDrawImage(draw_image, upload_scale_mip_level); - data_size = image_info.getSafeSize(image_info.minRowBytes()); + data_size = image_info.computeMinByteSize(); mode = DecodedDataMode::CPU; } else { mode = DecodedDataMode::GPU; } - return make_scoped_refptr( - new ImageData(mode, data_size, draw_image.target_color_space(), params)); + return base::MakeRefCounted<ImageData>( + mode, data_size, draw_image.target_color_space(), params); } void GpuImageDecodeCache::DeletePendingImages() { diff --git a/chromium/cc/tiles/gpu_image_decode_cache.h b/chromium/cc/tiles/gpu_image_decode_cache.h index 4a845833f01..502d5c273f7 100644 --- a/chromium/cc/tiles/gpu_image_decode_cache.h +++ b/chromium/cc/tiles/gpu_image_decode_cache.h @@ -112,12 +112,10 @@ class CC_EXPORT GpuImageDecodeCache // Finds the existing uploaded image for the provided DrawImage. Creates an // upload task to upload the image if an exsiting image does not exist. - bool GetTaskForImageAndRef(const DrawImage& image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) override; - bool GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& image, - scoped_refptr<TileTask>* task) override; + TaskResult GetTaskForImageAndRef(const DrawImage& image, + const TracingInfo& tracing_info) override; + TaskResult GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& image) override; void UnrefImage(const DrawImage& image) override; DecodedDrawImage GetDecodedImageForDraw(const DrawImage& draw_image) override; void DrawWithImageFinished(const DrawImage& image, @@ -304,10 +302,9 @@ class CC_EXPORT GpuImageDecodeCache // Note that this function behaves as if it was public (all of the same locks // need to be acquired). - bool GetTaskForImageAndRefInternal(const DrawImage& image, - const TracingInfo& tracing_info, - DecodeTaskType task_type, - scoped_refptr<TileTask>* task); + TaskResult GetTaskForImageAndRefInternal(const DrawImage& image, + const TracingInfo& tracing_info, + DecodeTaskType task_type); void RefImageDecode(const DrawImage& draw_image); void UnrefImageDecode(const DrawImage& draw_image); diff --git a/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc b/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc index e8ad3457833..dc2d245fff8 100644 --- a/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc +++ b/chromium/cc/tiles/gpu_image_decode_cache_unittest.cc @@ -6,6 +6,7 @@ #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" @@ -56,25 +57,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSameImage) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - another_draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task.get() == another_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( + another_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(result.task.get() == another_result.task.get()); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -91,25 +90,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageSmallerScale) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - another_draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task.get() == another_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( + another_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(result.task.get() == another_result.task.get()); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(another_draw_image); @@ -124,24 +121,24 @@ 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, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + kHigh_SkFilterQuality, matrix, + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); DrawImage another_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - another_draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task.get() == another_task.get()); + kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( + another_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(result.task.get() == another_result.task.get()); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(another_draw_image); @@ -158,30 +155,28 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); PaintImage second_image = CreateDiscardablePaintImage(gfx::Size(100, 100)); DrawImage second_draw_image( second_image, SkIRect::MakeWH(second_image.width(), second_image.height()), quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); - - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); + + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(first_draw_image); cache.UnrefImage(second_draw_image); @@ -198,41 +193,38 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); cache.UnrefImage(first_draw_image); DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - third_draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task.get() == second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( + third_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task.get() == second_result.task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(second_draw_image); cache.UnrefImage(third_draw_image); @@ -249,38 +241,35 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - third_draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task.get() == first_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( + third_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task.get() == first_result.task.get()); - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(first_draw_image); cache.UnrefImage(second_draw_image); @@ -297,30 +286,30 @@ 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, DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + kLow_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); cache.UnrefImage(first_draw_image); DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), - kHigh_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(second_draw_image); } @@ -336,36 +325,34 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedAndLocked) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the decode but don't complete it (this will keep the decode locked). - TestTileTaskRunner::ScheduleTask(task->dependencies()[0].get()); - TestTileTaskRunner::RunTask(task->dependencies()[0].get()); + TestTileTaskRunner::ScheduleTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::RunTask(result.task->dependencies()[0].get()); // Cancel the upload. - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // Get the image again - we should have an upload task, but no dependent // decode task, as the decode was already locked. - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task); - EXPECT_EQ(another_task->dependencies().size(), 0u); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(another_result.task); + EXPECT_EQ(another_result.task->dependencies().size(), 0u); - TestTileTaskRunner::ProcessTask(another_task.get()); + TestTileTaskRunner::ProcessTask(another_result.task.get()); // Finally, complete the original decode task. - TestTileTaskRunner::CompleteTask(task->dependencies()[0].get()); + TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get()); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -382,37 +369,35 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyDecodedNotLocked) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the decode. - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); // Cancel the upload. - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // Unref the image. cache.UnrefImage(draw_image); // Get the image again - we should have an upload task and a dependent decode // task - this dependent task will typically just re-lock the image. - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task); - EXPECT_EQ(another_task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(another_result.task); + EXPECT_EQ(another_result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); - TestTileTaskRunner::ProcessTask(another_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(another_task.get()); + TestTileTaskRunner::ProcessTask(another_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(another_result.task.get()); cache.UnrefImage(draw_image); } @@ -428,26 +413,24 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageAlreadyUploaded) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); - - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ScheduleTask(task.get()); - TestTileTaskRunner::RunTask(task.get()); - - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(another_task); - - TestTileTaskRunner::CompleteTask(task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); + + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ScheduleTask(result.task.get()); + TestTileTaskRunner::RunTask(result.task.get()); + + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_FALSE(another_result.task); + + TestTileTaskRunner::CompleteTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -464,39 +447,36 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledGetsNewTask) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task.get() == task.get()); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(another_result.task.get() == result.task.get()); // Didn't run the task, so cancel it. - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // Fully cancel everything (so the raster would unref things). cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); // Here a new task is created. - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task); - EXPECT_FALSE(third_task.get() == task.get()); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_FALSE(third_result.task.get() == result.task.get()); - TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(third_task.get()); + TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(third_result.task.get()); cache.UnrefImage(draw_image); } @@ -512,25 +492,23 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - - ASSERT_GT(task->dependencies().size(), 0u); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task.get() == task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + + ASSERT_GT(result.task->dependencies().size(), 0u); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(another_result.task.get() == result.task.get()); // Didn't run the task, so cancel it. - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // 2 Unrefs, so that the decode is unlocked as well. cache.UnrefImage(draw_image); @@ -538,16 +516,15 @@ TEST_P(GpuImageDecodeCacheTest, GetTaskForImageCanceledWhileReffedGetsNewTask) { // Note that here, everything is reffed, but a new task is created. This is // possible with repeated schedule/cancel operations. - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task); - EXPECT_FALSE(third_task.get() == task.get()); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_FALSE(third_result.task.get() == result.task.get()); - ASSERT_GT(third_task->dependencies().size(), 0u); - TestTileTaskRunner::ProcessTask(third_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(third_task.get()); + ASSERT_GT(third_result.task->dependencies().size(), 0u); + TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(third_result.task.get()); // Unref! cache.UnrefImage(draw_image); @@ -564,25 +541,23 @@ TEST_P(GpuImageDecodeCacheTest, NoTaskForImageAlreadyFailedDecoding) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); // Didn't run the task, so cancel it. - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); cache.SetImageDecodingFailedForTesting(draw_image); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_FALSE(need_unref); - EXPECT_EQ(another_task.get(), nullptr); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(another_result.need_unref); + EXPECT_EQ(another_result.task.get(), nullptr); cache.UnrefImage(draw_image); } @@ -598,15 +573,14 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -634,15 +608,14 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -673,13 +646,12 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawAtRasterDecode) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(need_unref); - EXPECT_FALSE(task); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.need_unref); + EXPECT_FALSE(result.task); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -706,28 +678,26 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DrawImage larger_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.5f, 1.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> larger_task; - bool larger_need_unref = cache.GetTaskForImageAndRef( - larger_draw_image, ImageDecodeCache::TracingInfo(), &larger_task); - EXPECT_TRUE(larger_need_unref); - EXPECT_TRUE(larger_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult larger_result = cache.GetTaskForImageAndRef( + larger_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(larger_result.need_unref); + EXPECT_TRUE(larger_result.task); - TestTileTaskRunner::ProcessTask(larger_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(larger_task.get()); + TestTileTaskRunner::ProcessTask(larger_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(larger_result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -767,27 +737,27 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawHigherQuality) { PaintImage image = CreateDiscardablePaintImage(gfx::Size(100, 100)); DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + kLow_SkFilterQuality, matrix, + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DrawImage higher_quality_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kHigh_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> hq_task; - bool hq_needs_unref = cache.GetTaskForImageAndRef( - higher_quality_draw_image, ImageDecodeCache::TracingInfo(), &hq_task); - EXPECT_TRUE(hq_needs_unref); - EXPECT_TRUE(hq_task); + kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult hq_result = cache.GetTaskForImageAndRef( + higher_quality_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(hq_result.need_unref); + EXPECT_TRUE(hq_result.task); - TestTileTaskRunner::ProcessTask(hq_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(hq_task.get()); + TestTileTaskRunner::ProcessTask(hq_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(hq_result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -829,15 +799,14 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawNegative) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(-0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -867,15 +836,14 @@ TEST_P(GpuImageDecodeCacheTest, GetLargeScaledDecodedImageForDraw) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -909,13 +877,12 @@ TEST_P(GpuImageDecodeCacheTest, AtRasterUsedDirectlyIfSpaceAllows) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(need_unref); - EXPECT_FALSE(task); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.need_unref); + EXPECT_FALSE(result.task); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -934,11 +901,10 @@ TEST_P(GpuImageDecodeCacheTest, AtRasterUsedDirectlyIfSpaceAllows) { // cache. cache.DrawWithImageFinished(draw_image, decoded_draw_image); - scoped_refptr<TileTask> another_task; - bool another_task_needs_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(another_task_needs_unref); - EXPECT_FALSE(another_task); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_FALSE(another_result.task); cache.UnrefImage(draw_image); } @@ -956,7 +922,7 @@ TEST_P(GpuImageDecodeCacheTest, DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -990,7 +956,7 @@ TEST_P(GpuImageDecodeCacheTest, DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -1030,13 +996,12 @@ TEST_P(GpuImageDecodeCacheTest, ZeroSizedImagesAreSkipped) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.f, 0.f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(task); - EXPECT_FALSE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.task); + EXPECT_FALSE(result.need_unref); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -1059,13 +1024,12 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(task); - EXPECT_FALSE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.task); + EXPECT_FALSE(result.need_unref); // Must hold context lock before calling GetDecodedImageForDraw / // DrawWithImageFinished. @@ -1088,19 +1052,18 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); EXPECT_NE(0u, cache.GetBytesUsedForTesting()); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::CancelTask(task->dependencies()[0].get()); - TestTileTaskRunner::CompleteTask(task->dependencies()[0].get()); - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); cache.UnrefImage(draw_image); EXPECT_EQ(0u, cache.GetBytesUsedForTesting()); @@ -1117,37 +1080,36 @@ TEST_P(GpuImageDecodeCacheTest, ShouldAggressivelyFreeResources) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); { - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - } + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); - cache.UnrefImage(draw_image); + cache.UnrefImage(draw_image); - // We should now have data image in our cache. - EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); + // We should now have data image in our cache. + EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); - // Tell our cache to aggressively free resources. - cache.SetShouldAggressivelyFreeResources(true); - EXPECT_EQ(0u, cache.GetBytesUsedForTesting()); + // Tell our cache to aggressively free resources. + cache.SetShouldAggressivelyFreeResources(true); + EXPECT_EQ(0u, cache.GetBytesUsedForTesting()); + } // Attempting to upload a new image should succeed, but the image should not // be cached past its use. { - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); EXPECT_EQ(cache.GetBytesUsedForTesting(), 0u); @@ -1157,13 +1119,13 @@ TEST_P(GpuImageDecodeCacheTest, ShouldAggressivelyFreeResources) { // now be cached past its use. cache.SetShouldAggressivelyFreeResources(false); { - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); @@ -1182,12 +1144,11 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); // The budget should account for exactly one image. EXPECT_EQ(cache.GetBytesUsedForTesting(), @@ -1198,16 +1159,15 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(second_draw_image); @@ -1218,8 +1178,8 @@ TEST_P(GpuImageDecodeCacheTest, OrphanedImagesFreeOnReachingZeroRefs) { // Unref the first image, it was orphaned, so it should be immediately // deleted. - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); cache.UnrefImage(first_draw_image); // The budget should account for exactly one image. @@ -1239,15 +1199,14 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); - - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); + + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); cache.UnrefImage(first_draw_image); // The budget should account for exactly one image. @@ -1259,16 +1218,15 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(second_draw_image); @@ -1288,39 +1246,39 @@ TEST_P(GpuImageDecodeCacheTest, QualityCappedAtMedium) { // Create an image with kLow_FilterQuality. DrawImage low_draw_image(image, SkIRect::MakeWH(image.width(), image.height()), - kLow_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> low_task; - bool need_unref = cache.GetTaskForImageAndRef( - low_draw_image, ImageDecodeCache::TracingInfo(), &low_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(low_task); + kLow_SkFilterQuality, matrix, + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult low_result = cache.GetTaskForImageAndRef( + low_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(low_result.need_unref); + EXPECT_TRUE(low_result.task); // Get the same image at kMedium_SkFilterQuality. We can't re-use low, so we // should get a new task/ref. DrawImage medium_draw_image( image, SkIRect::MakeWH(image.width(), image.height()), - kMedium_SkFilterQuality, matrix, DefaultColorSpace()); - scoped_refptr<TileTask> medium_task; - need_unref = cache.GetTaskForImageAndRef( - medium_draw_image, ImageDecodeCache::TracingInfo(), &medium_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(medium_task.get()); - EXPECT_FALSE(low_task.get() == medium_task.get()); + kMedium_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult medium_result = cache.GetTaskForImageAndRef( + medium_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(medium_result.need_unref); + EXPECT_TRUE(medium_result.task.get()); + EXPECT_FALSE(low_result.task.get() == medium_result.task.get()); // 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, DefaultColorSpace()); - scoped_refptr<TileTask> large_task; - need_unref = cache.GetTaskForImageAndRef( - large_draw_image, ImageDecodeCache::TracingInfo(), &large_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(medium_task.get() == large_task.get()); - - TestTileTaskRunner::ProcessTask(low_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(low_task.get()); - TestTileTaskRunner::ProcessTask(medium_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(medium_task.get()); + kHigh_SkFilterQuality, matrix, PaintImage::kDefaultFrameIndex, + DefaultColorSpace()); + ImageDecodeCache::TaskResult large_result = cache.GetTaskForImageAndRef( + large_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(large_result.need_unref); + EXPECT_TRUE(medium_result.task.get() == large_result.task.get()); + + TestTileTaskRunner::ProcessTask(low_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(low_result.task.get()); + TestTileTaskRunner::ProcessTask(medium_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(medium_result.task.get()); cache.UnrefImage(low_draw_image); cache.UnrefImage(medium_draw_image); @@ -1341,18 +1299,17 @@ TEST_P(GpuImageDecodeCacheTest, GetDecodedImageForDrawMipUsageChange) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); // Cancel the task without ever using it. - TestTileTaskRunner::CancelTask(task->dependencies()[0].get()); - TestTileTaskRunner::CompleteTask(task->dependencies()[0].get()); - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::CompleteTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); cache.UnrefImage(draw_image); @@ -1364,7 +1321,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image_mips); cache.DrawWithImageFinished(draw_image_mips, decoded_draw_image); @@ -1380,15 +1337,15 @@ 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, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + kLow_SkFilterQuality, matrix, + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); // The image should be cached. @@ -1412,13 +1369,13 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) { // Attempts to get a task for the image will still succeed, as SUSPENDED // doesn't impact working set size. - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); // Nothing should be cached. @@ -1430,13 +1387,13 @@ TEST_P(GpuImageDecodeCacheTest, MemoryStateSuspended) { cache.SetShouldAggressivelyFreeResources(false); // We should now be able to create a task again (space available). - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } @@ -1449,17 +1406,17 @@ 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, DefaultColorSpace()); + kLow_SkFilterQuality, matrix, + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = - cache.GetOutOfRasterDecodeTaskForImageAndRef(draw_image, &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + ImageDecodeCache::TaskResult result = + cache.GetOutOfRasterDecodeTaskForImageAndRef(draw_image); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); EXPECT_TRUE(cache.IsInInUseCacheForTesting(draw_image)); // Run the decode task. - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // The image should remain in the cache till we unref it. EXPECT_TRUE(cache.IsInInUseCacheForTesting(draw_image)); @@ -1481,25 +1438,23 @@ TEST_P(GpuImageDecodeCacheTest, ZeroCacheNormalWorkingSet) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the task. - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // Request the same image - it should be cached. - scoped_refptr<TileTask> task2; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task2); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(task2); + ImageDecodeCache::TaskResult second_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_FALSE(second_result.task); // Unref both images. cache.UnrefImage(draw_image); @@ -1507,16 +1462,15 @@ TEST_P(GpuImageDecodeCacheTest, ZeroCacheNormalWorkingSet) { // Get the image again. As it was fully unreffed, it is no longer in the // working set and will be evicted due to 0 cache size. - scoped_refptr<TileTask> task3; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task3); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task3); - EXPECT_EQ(task3->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_EQ(third_result.task->dependencies().size(), 1u); + EXPECT_TRUE(third_result.task->dependencies()[0]); - TestTileTaskRunner::ProcessTask(task3->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task3.get()); + TestTileTaskRunner::ProcessTask(third_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(third_result.task.get()); cache.UnrefImage(draw_image); } @@ -1536,80 +1490,75 @@ TEST_P(GpuImageDecodeCacheTest, SmallCacheNormalWorkingSet) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); // Add an image to the cache and un-ref it. { - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the task and unref the image. - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } // Request the same image - it should be cached. { - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(task); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_FALSE(result.task); cache.UnrefImage(draw_image); } // Add a new image to the cache. It should push out the old one. { - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image2, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image2, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the task and unref the image. - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image2); } // Request the second image - it should be cached. { - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image2, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(task); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image2, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_FALSE(result.task); cache.UnrefImage(draw_image2); } // Request the first image - it should have been evicted and return a new // task. { - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - EXPECT_EQ(task->dependencies().size(), 1u); - EXPECT_TRUE(task->dependencies()[0]); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + EXPECT_EQ(result.task->dependencies().size(), 1u); + EXPECT_TRUE(result.task->dependencies()[0]); // Run the task and unref the image. - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } } @@ -1626,14 +1575,13 @@ TEST_P(GpuImageDecodeCacheTest, ClearCache) { DrawImage draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } @@ -1661,14 +1609,13 @@ TEST_P(GpuImageDecodeCacheTest, ClearCacheInUse) { DrawImage draw_image(image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); // We should now have data image in our cache. EXPECT_GT(cache.GetBytesUsedForTesting(), 0u); @@ -1701,38 +1648,35 @@ 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), - color_space_a); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, color_space_a); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); DrawImage second_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - color_space_b); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, color_space_b); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); DrawImage third_draw_image( first_image, SkIRect::MakeWH(first_image.width(), first_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - color_space_a); - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - third_draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task.get() == first_task.get()); - - TestTileTaskRunner::ProcessTask(first_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(first_task.get()); - TestTileTaskRunner::ProcessTask(second_task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + PaintImage::kDefaultFrameIndex, color_space_a); + ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( + third_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task.get() == first_result.task.get()); + + TestTileTaskRunner::ProcessTask(first_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); + TestTileTaskRunner::ProcessTask(second_result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(first_draw_image); cache.UnrefImage(second_draw_image); @@ -1752,15 +1696,14 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) { DrawImage draw_image( image, SkIRect::MakeWH(image.width(), image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); frame_keys.push_back(draw_image.frame_key()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - TestTileTaskRunner::ProcessTask(task->dependencies()[0].get()); - TestTileTaskRunner::ProcessTask(task.get()); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + TestTileTaskRunner::ProcessTask(result.task->dependencies()[0].get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } @@ -1775,6 +1718,64 @@ TEST_P(GpuImageDecodeCacheTest, RemoveUnusedImage) { } } +TEST_P(GpuImageDecodeCacheTest, CacheDecodesExpectedFrames) { + auto context_provider = TestContextProvider::Create(); + context_provider->BindToCurrentThread(); + TestGpuImageDecodeCache cache(context_provider.get(), GetParam()); + + std::vector<FrameMetadata> 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<FakePaintImageGenerator> generator = + sk_make_sp<FakePaintImageGenerator>(SkImageInfo::MakeN32Premul(10, 10), + frames); + PaintImage image = PaintImageBuilder::WithDefault() + .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/chromium/cc/tiles/image_controller.cc b/chromium/cc/tiles/image_controller.cc index ec90039d852..c2d896cafe6 100644 --- a/chromium/cc/tiles/image_controller.cc +++ b/chromium/cc/tiles/image_controller.cc @@ -141,23 +141,24 @@ void ImageController::SetImageDecodeCache(ImageDecodeCache* cache) { GenerateTasksForOrphanedRequests(); } } - void ImageController::GetTasksForImagesAndRef( - std::vector<DrawImage>* images, + std::vector<DrawImage>* sync_decoded_images, + std::vector<DrawImage>* at_raster_images, std::vector<scoped_refptr<TileTask>>* tasks, const ImageDecodeCache::TracingInfo& tracing_info) { DCHECK(cache_); - for (auto it = images->begin(); it != images->end();) { - scoped_refptr<TileTask> task; - bool need_to_unref_when_finished = - cache_->GetTaskForImageAndRef(*it, tracing_info, &task); - if (task) - tasks->push_back(std::move(task)); - - if (need_to_unref_when_finished) + for (auto it = sync_decoded_images->begin(); + it != sync_decoded_images->end();) { + ImageDecodeCache::TaskResult result = + cache_->GetTaskForImageAndRef(*it, tracing_info); + if (result.task) + tasks->push_back(std::move(result.task)); + if (at_raster_images && result.IsAtRaster()) + at_raster_images->push_back(*it); + if (result.need_unref) ++it; else - it = images->erase(it); + it = sync_decoded_images->erase(it); } } @@ -175,7 +176,7 @@ std::vector<scoped_refptr<TileTask>> ImageController::SetPredecodeImages( std::vector<DrawImage> images, const ImageDecodeCache::TracingInfo& tracing_info) { std::vector<scoped_refptr<TileTask>> new_tasks; - GetTasksForImagesAndRef(&images, &new_tasks, tracing_info); + GetTasksForImagesAndRef(&images, nullptr, &new_tasks, tracing_info); UnrefImages(predecode_locked_images_); predecode_locked_images_ = std::move(images); return new_tasks; @@ -194,19 +195,16 @@ ImageController::ImageDecodeRequestId ImageController::QueueImageDecode( bool is_image_lazy = draw_image.paint_image().IsLazyGenerated(); // Get the tasks for this decode. - scoped_refptr<TileTask> task; - bool need_unref = false; - if (is_image_lazy) { - need_unref = - cache_->GetOutOfRasterDecodeTaskForImageAndRef(draw_image, &task); - } + ImageDecodeCache::TaskResult result(false); + if (is_image_lazy) + result = cache_->GetOutOfRasterDecodeTaskForImageAndRef(draw_image); // If we don't need to unref this, we don't actually have a task. - DCHECK(need_unref || !task); + DCHECK(result.need_unref || !result.task); // Schedule the task and signal that there is more work. base::AutoLock hold(lock_); - image_decode_queue_[id] = - ImageDecodeRequest(id, draw_image, callback, std::move(task), need_unref); + image_decode_queue_[id] = ImageDecodeRequest( + id, draw_image, callback, std::move(result.task), result.need_unref); // If this is the only image decode request, schedule a task to run. // Otherwise, the task will be scheduled in the previou task's completion. @@ -336,8 +334,10 @@ void ImageController::GenerateTasksForOrphanedRequests() { DCHECK(!request.need_unref); if (request.draw_image.paint_image().IsLazyGenerated()) { // Get the task for this decode. - request.need_unref = cache_->GetOutOfRasterDecodeTaskForImageAndRef( - request.draw_image, &request.task); + ImageDecodeCache::TaskResult result = + cache_->GetOutOfRasterDecodeTaskForImageAndRef(request.draw_image); + request.need_unref = result.need_unref; + request.task = result.task; } image_decode_queue_[request.id] = std::move(request); } diff --git a/chromium/cc/tiles/image_controller.h b/chromium/cc/tiles/image_controller.h index 33b1400f27c..990b94949f8 100644 --- a/chromium/cc/tiles/image_controller.h +++ b/chromium/cc/tiles/image_controller.h @@ -37,7 +37,8 @@ class CC_EXPORT ImageController { void SetImageDecodeCache(ImageDecodeCache* cache); void GetTasksForImagesAndRef( - std::vector<DrawImage>* images, + std::vector<DrawImage>* sync_decoded_images, + std::vector<DrawImage>* at_raster_images, std::vector<scoped_refptr<TileTask>>* tasks, const ImageDecodeCache::TracingInfo& tracing_info); void UnrefImages(const std::vector<DrawImage>& images); diff --git a/chromium/cc/tiles/image_controller_unittest.cc b/chromium/cc/tiles/image_controller_unittest.cc index 631c3d77132..17e939d248c 100644 --- a/chromium/cc/tiles/image_controller_unittest.cc +++ b/chromium/cc/tiles/image_controller_unittest.cc @@ -69,13 +69,13 @@ class WorkerTaskRunner : public base::SequencedTaskRunner { public: WorkerTaskRunner() { thread_.Start(); } - bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, + bool PostNonNestableDelayedTask(const base::Location& from_here, base::OnceClosure task, base::TimeDelta delay) override { return PostDelayedTask(from_here, std::move(task), delay); } - bool PostDelayedTask(const tracked_objects::Location& from_here, + bool PostDelayedTask(const base::Location& from_here, base::OnceClosure task, base::TimeDelta delay) override { thread_.PostTask(std::move(task)); @@ -98,25 +98,22 @@ class TestableCache : public StubDecodeCache { public: ~TestableCache() override { EXPECT_EQ(number_of_refs_, 0); } - bool GetTaskForImageAndRef(const DrawImage& image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) override { + TaskResult GetTaskForImageAndRef(const DrawImage& image, + const TracingInfo& tracing_info) override { // Return false for large images to mimic "won't fit in memory" // behavior. if (image.paint_image() && image.paint_image().width() * image.paint_image().height() >= 1000 * 1000) { - return false; + return TaskResult(false); } - *task = task_to_use_; ++number_of_refs_; - return true; + return TaskResult(task_to_use_); } - bool GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& image, - scoped_refptr<TileTask>* task) override { - return GetTaskForImageAndRef(image, TracingInfo(), task); + TaskResult GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& image) override { + return GetTaskForImageAndRef(image, TracingInfo()); } void UnrefImage(const DrawImage& image) override { @@ -231,7 +228,8 @@ int kDefaultTimeoutSeconds = 10; DrawImage CreateDiscardableDrawImage(gfx::Size size) { return DrawImage(CreateDiscardablePaintImage(size), SkIRect::MakeWH(size.width(), size.height()), - kNone_SkFilterQuality, SkMatrix::I(), gfx::ColorSpace()); + kNone_SkFilterQuality, SkMatrix::I(), + PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); } class ImageControllerTest : public testing::Test { @@ -242,7 +240,7 @@ class ImageControllerTest : public testing::Test { ~ImageControllerTest() override = default; void SetUp() override { - worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner); + worker_task_runner_ = base::MakeRefCounted<WorkerTaskRunner>(); controller_.reset( new ImageController(task_runner_.get(), worker_task_runner_)); cache_ = TestableCache(); @@ -320,12 +318,13 @@ 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(), gfx::ColorSpace()); + DrawImage image = + DrawImage(PaintImageBuilder::WithDefault() + .set_id(PaintImage::GetNextId()) + .set_image(SkImage::MakeFromBitmap(bitmap)) + .TakePaintImage(), + SkIRect::MakeWH(1, 1), kNone_SkFilterQuality, SkMatrix::I(), + PaintImage::kDefaultFrameIndex, gfx::ColorSpace()); ImageController::ImageDecodeRequestId expected_id = controller()->QueueImageDecode( diff --git a/chromium/cc/tiles/image_decode_cache.cc b/chromium/cc/tiles/image_decode_cache.cc index 680264da26b..7c83ee45a15 100644 --- a/chromium/cc/tiles/image_decode_cache.cc +++ b/chromium/cc/tiles/image_decode_cache.cc @@ -5,9 +5,20 @@ #include "cc/tiles/image_decode_cache.h" #include "base/metrics/histogram_macros.h" +#include "cc/raster/tile_task.h" namespace cc { +ImageDecodeCache::TaskResult::TaskResult(bool need_unref) + : need_unref(need_unref) {} + +ImageDecodeCache::TaskResult::TaskResult(scoped_refptr<TileTask> task) + : task(std::move(task)), need_unref(true) {} + +ImageDecodeCache::TaskResult::TaskResult(const TaskResult& result) = default; + +ImageDecodeCache::TaskResult::~TaskResult() = default; + void ImageDecodeCache::RecordImageMipLevelUMA(int mip_level) { DCHECK_GE(mip_level, 0); DCHECK_LT(mip_level, 32); diff --git a/chromium/cc/tiles/image_decode_cache.h b/chromium/cc/tiles/image_decode_cache.h index 6994ba571a6..557059ca463 100644 --- a/chromium/cc/tiles/image_decode_cache.h +++ b/chromium/cc/tiles/image_decode_cache.h @@ -7,14 +7,14 @@ #include "base/memory/ref_counted.h" #include "cc/base/devtools_instrumentation.h" +#include "cc/cc_export.h" #include "cc/paint/decoded_draw_image.h" #include "cc/paint/draw_image.h" +#include "cc/raster/tile_task.h" #include "cc/tiles/tile_priority.h" namespace cc { -class TileTask; - // ImageDecodeCache is responsible for generating decode tasks, decoding // images, storing images in cache, and being able to return the decoded images // when requested. @@ -74,23 +74,32 @@ class CC_EXPORT ImageDecodeCache { virtual ~ImageDecodeCache() {} + struct CC_EXPORT TaskResult { + explicit TaskResult(bool need_unref); + explicit TaskResult(scoped_refptr<TileTask> task); + TaskResult(const TaskResult& result); + ~TaskResult(); + + bool IsAtRaster() const { return !task && !need_unref; } + + scoped_refptr<TileTask> task; + bool need_unref = false; + }; // Fill in an TileTask which will decode the given image when run. In // case the image is already cached, fills in nullptr. Returns true if the // image needs to be unreffed when the caller is finished with it. // // This is called by the tile manager (on the compositor thread) when creating // a raster task. - virtual bool GetTaskForImageAndRef(const DrawImage& image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) = 0; + virtual TaskResult GetTaskForImageAndRef(const DrawImage& image, + const TracingInfo& tracing_info) = 0; // Similar to GetTaskForImageAndRef, except that it returns tasks that are not // meant to be run as part of raster. That is, this is part of a predecode // API. Note that this should only return a task responsible for decoding (and // not uploading), since it will be run on a worker thread which may not have // the right GPU context for upload. - virtual bool GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& image, - scoped_refptr<TileTask>* task) = 0; + virtual TaskResult GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& image) = 0; // Unrefs an image. When the tile is finished, this should be called for every // GetTaskForImageAndRef call that returned true. diff --git a/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc b/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc index b485b7a2ede..d7e37b3dea2 100644 --- a/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc +++ b/chromium/cc/tiles/picture_layer_tiling_set_unittest.cc @@ -250,7 +250,7 @@ class PictureLayerTilingSetTestWithResources : public testing::Test { ASSERT_TRUE(context_provider->BindToCurrentThread()); auto shared_bitmap_manager = std::make_unique<TestSharedBitmapManager>(); std::unique_ptr<ResourceProvider> resource_provider = - FakeResourceProvider::Create<LayerTreeResourceProvider>( + FakeResourceProvider::CreateLayerTreeResourceProvider( context_provider.get(), shared_bitmap_manager.get()); FakePictureLayerTilingClient client(resource_provider.get()); diff --git a/chromium/cc/tiles/software_image_decode_cache.cc b/chromium/cc/tiles/software_image_decode_cache.cc index b9e3f757e99..9d0bb6a6a0f 100644 --- a/chromium/cc/tiles/software_image_decode_cache.cc +++ b/chromium/cc/tiles/software_image_decode_cache.cc @@ -52,6 +52,9 @@ const size_t kMemoryThresholdToSubrect = 64 * 1024 * 1024; const int kMinDimensionToSubrect = 4 * 1024; const float kMemoryRatioToSubrect = 0.5f; +// Tracing ID sequence for use in DecodedImage. +base::AtomicSequenceNumber g_next_tracing_id_; + class AutoRemoveKeyFromTaskMap { public: AutoRemoveKeyFromTaskMap( @@ -217,28 +220,27 @@ SoftwareImageDecodeCache::~SoftwareImageDecodeCache() { base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this); } -bool SoftwareImageDecodeCache::GetTaskForImageAndRef( +ImageDecodeCache::TaskResult SoftwareImageDecodeCache::GetTaskForImageAndRef( const DrawImage& image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) { + const TracingInfo& tracing_info) { DCHECK_EQ(tracing_info.task_type, TaskType::kInRaster); - return GetTaskForImageAndRefInternal( - image, tracing_info, DecodeTaskType::USE_IN_RASTER_TASKS, task); + return GetTaskForImageAndRefInternal(image, tracing_info, + DecodeTaskType::USE_IN_RASTER_TASKS); } -bool SoftwareImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& image, - scoped_refptr<TileTask>* task) { +ImageDecodeCache::TaskResult +SoftwareImageDecodeCache::GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& image) { return GetTaskForImageAndRefInternal( image, TracingInfo(0, TilePriority::NOW, TaskType::kOutOfRaster), - DecodeTaskType::USE_OUT_OF_RASTER_TASKS, task); + DecodeTaskType::USE_OUT_OF_RASTER_TASKS); } -bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( +ImageDecodeCache::TaskResult +SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( const DrawImage& image, const TracingInfo& tracing_info, - DecodeTaskType task_type, - scoped_refptr<TileTask>* task) { + DecodeTaskType task_type) { // If the image already exists or if we're going to create a task for it, then // we'll likely need to ref this image (the exception is if we're prerolling // the image only). That means the image is or will be in the cache. When the @@ -254,8 +256,7 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( // If the target size is empty, we can skip this image during draw (and thus // we don't need to decode it or ref it). if (key.target_size().IsEmpty()) { - *task = nullptr; - return false; + return TaskResult(false); } base::AutoLock lock(lock_); @@ -269,14 +270,13 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( if (image_was_locked || (new_image_fits_in_memory && decoded_it->second->Lock())) { RefImage(key); - *task = nullptr; // If the image wasn't locked, then we just succeeded in locking it. if (!image_was_locked) { RecordLockExistingCachedImageHistogram(tracing_info.requesting_tile_bin, true); } - return true; + return TaskResult(true); } // If the image fits in memory, then we at least tried to lock it and @@ -299,8 +299,7 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( : pending_out_of_raster_image_tasks_[key]; if (existing_task) { RefImage(key); - *task = existing_task; - return true; + return TaskResult(existing_task); } // At this point, we have to create a new image/task, so we need to abort if @@ -310,17 +309,15 @@ bool SoftwareImageDecodeCache::GetTaskForImageAndRefInternal( // ref to the image that is now being reffed for the new schedule. if (!new_image_fits_in_memory && (decoded_images_ref_counts_.find(key) == decoded_images_ref_counts_.end())) { - *task = nullptr; - return false; + return TaskResult(false); } // Actually create the task. RefImage will account for memory on the first // ref. RefImage(key); - existing_task = make_scoped_refptr( - new ImageDecodeTaskImpl(this, key, image, task_type, tracing_info)); - *task = existing_task; - return true; + existing_task = base::MakeRefCounted<ImageDecodeTaskImpl>( + this, key, image, task_type, tracing_info); + return TaskResult(existing_task); } void SoftwareImageDecodeCache::RefImage(const ImageKey& key) { @@ -452,12 +449,15 @@ SoftwareImageDecodeCache::DecodeImageInternal(const ImageKey& key, // that scale, or // - If we're not doing a scale at all (which is supported by all decoders and // subsetting is handled in the draw calls). - // TODO(vmpstr): See if we can subrect thing decoded to native scale. + // TODO(vmpstr): See if we can subrect the result of decoded to scale. SkIRect full_size_rect = SkIRect::MakeWH(paint_image.width(), paint_image.height()); bool need_subset = (gfx::RectToSkIRect(key.src_rect()) != full_size_rect); SkISize exact_size = SkISize::Make(key.target_size().width(), key.target_size().height()); + // TODO(vmpstr): If an image of a bigger size is already decoded and is + // lock-able then it might be faster to just scale that instead of redecoding + // to exact scale. We need to profile this. if ((!need_subset && exact_size == paint_image.GetSupportedDecodeSize(exact_size)) || SkIRect::MakeSize(exact_size) == full_size_rect) { @@ -599,7 +599,8 @@ SoftwareImageDecodeCache::GetExactSizeImageDecode( "SoftwareImageDecodeCache::GetOriginalSizeImageDecode - " "decode"); bool result = paint_image.Decode(decoded_pixels->data(), &decoded_info, - key.target_color_space().ToSkColorSpace()); + key.target_color_space().ToSkColorSpace(), + key.frame_key().frame_index()); if (!result) { decoded_pixels->Unlock(); return nullptr; @@ -607,8 +608,7 @@ SoftwareImageDecodeCache::GetExactSizeImageDecode( } return std::make_unique<DecodedImage>(decoded_info, std::move(decoded_pixels), - SkSize::Make(0, 0), - next_tracing_id_.GetNext()); + SkSize::Make(0, 0)); } std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> @@ -622,7 +622,8 @@ 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.target_color_space()); + SkMatrix::I(), key.frame_key().frame_index(), + key.target_color_space()); ImageKey exact_size_key = ImageKey::FromDrawImage(exact_size_draw_image, color_type_); @@ -672,11 +673,10 @@ SoftwareImageDecodeCache::GetSubrectImageDecode(const ImageKey& key, DCHECK(result); } - return base::WrapUnique(new DecodedImage( + return std::make_unique<DecodedImage>( subrect_info.makeColorSpace(decoded_draw_image.image()->refColorSpace()), std::move(subrect_pixels), - SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), - next_tracing_id_.GetNext())); + SkSize::Make(-key.src_rect().x(), -key.src_rect().y())); } std::unique_ptr<SoftwareImageDecodeCache::DecodedImage> @@ -696,7 +696,8 @@ 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.target_color_space()); + SkMatrix::I(), key.frame_key().frame_index(), + key.target_color_space()); ImageKey exact_size_key = ImageKey::FromDrawImage(exact_size_draw_image, color_type_); @@ -755,8 +756,7 @@ SoftwareImageDecodeCache::GetScaledImageDecode(const ImageKey& key, return std::make_unique<DecodedImage>( scaled_info.makeColorSpace(decoded_draw_image.image()->refColorSpace()), std::move(scaled_pixels), - SkSize::Make(-key.src_rect().x(), -key.src_rect().y()), - next_tracing_id_.GetNext()); + SkSize::Make(-key.src_rect().x(), -key.src_rect().y())); } void SoftwareImageDecodeCache::DrawWithImageFinished( @@ -994,6 +994,10 @@ ImageDecodeCacheKey ImageDecodeCacheKey::FromDrawImage(const DrawImage& image, } else { quality = kMedium_SkFilterQuality; // Update the target size to be a mip level size. + // TODO(vmpstr): MipMapUtil and JPEG decoders disagree on what to do with + // odd sizes. If width = 2k + 1, and the mip level is 1, then this will + // return width = k; JPEG decoder, however, will support decoding to width = + // k + 1. We need to figure out what to do in this case. SkSize mip_scale_adjustment = MipMapUtil::GetScaleAdjustmentForLevel(src_rect.size(), mip_level); target_size.set_width(src_rect.width() * mip_scale_adjustment.width()); @@ -1093,13 +1097,12 @@ std::string ImageDecodeCacheKey::ToString() const { SoftwareImageDecodeCache::DecodedImage::DecodedImage( const SkImageInfo& info, std::unique_ptr<base::DiscardableMemory> memory, - const SkSize& src_rect_offset, - uint64_t tracing_id) + const SkSize& src_rect_offset) : locked_(true), image_info_(info), memory_(std::move(memory)), src_rect_offset_(src_rect_offset), - tracing_id_(tracing_id) { + tracing_id_(g_next_tracing_id_.GetNext()) { SkPixmap pixmap(image_info_, memory_->data(), image_info_.minRowBytes()); image_ = SkImage::MakeFromRaster( pixmap, [](const void* pixels, void* context) {}, nullptr); diff --git a/chromium/cc/tiles/software_image_decode_cache.h b/chromium/cc/tiles/software_image_decode_cache.h index a59cdf2637c..222ad090578 100644 --- a/chromium/cc/tiles/software_image_decode_cache.h +++ b/chromium/cc/tiles/software_image_decode_cache.h @@ -124,12 +124,10 @@ class CC_EXPORT SoftwareImageDecodeCache ~SoftwareImageDecodeCache() override; // ImageDecodeCache overrides. - bool GetTaskForImageAndRef(const DrawImage& image, - const TracingInfo& tracing_info, - scoped_refptr<TileTask>* task) override; - bool GetOutOfRasterDecodeTaskForImageAndRef( - const DrawImage& image, - scoped_refptr<TileTask>* task) override; + TaskResult GetTaskForImageAndRef(const DrawImage& image, + const TracingInfo& tracing_info) override; + TaskResult GetOutOfRasterDecodeTaskForImageAndRef( + const DrawImage& image) override; void UnrefImage(const DrawImage& image) override; DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; void DrawWithImageFinished(const DrawImage& image, @@ -163,8 +161,7 @@ class CC_EXPORT SoftwareImageDecodeCache public: DecodedImage(const SkImageInfo& info, std::unique_ptr<base::DiscardableMemory> memory, - const SkSize& src_rect_offset, - uint64_t tracing_id); + const SkSize& src_rect_offset); ~DecodedImage(); const sk_sp<SkImage>& image() const { @@ -295,10 +292,9 @@ class CC_EXPORT SoftwareImageDecodeCache // Helper method to get the different tasks. Note that this should be used as // if it was public (ie, all of the locks need to be properly acquired). - bool GetTaskForImageAndRefInternal(const DrawImage& image, - const TracingInfo& tracing_info, - DecodeTaskType type, - scoped_refptr<TileTask>* task); + TaskResult GetTaskForImageAndRefInternal(const DrawImage& image, + const TracingInfo& tracing_info, + DecodeTaskType type); void CacheDecodedImages(const ImageKey& key, std::unique_ptr<DecodedImage> decoded_image); @@ -336,9 +332,6 @@ class CC_EXPORT SoftwareImageDecodeCache SkColorType color_type_; size_t max_items_in_cache_; - - // Used to uniquely identify DecodedImages for memory traces. - base::AtomicSequenceNumber next_tracing_id_; }; } // namespace cc diff --git a/chromium/cc/tiles/software_image_decode_cache_perftest.cc b/chromium/cc/tiles/software_image_decode_cache_perftest.cc index fd9f4e8dcff..24bae708790 100644 --- a/chromium/cc/tiles/software_image_decode_cache_perftest.cc +++ b/chromium/cc/tiles/software_image_decode_cache_perftest.cc @@ -57,12 +57,12 @@ class SoftwareImageDecodeCachePerfTest : public testing::Test { auto& subrect = rect_subrect.second; for (auto& scale : scales) { images.emplace_back( - PaintImageBuilder() + PaintImageBuilder::WithDefault() .set_id(PaintImage::GetNextId()) .set_image(CreateImage(rect.width(), rect.height())) .TakePaintImage(), subrect, quality, - CreateMatrix(SkSize::Make(scale.first, scale.second)), + CreateMatrix(SkSize::Make(scale.first, scale.second)), 0u, gfx::ColorSpace()); } } diff --git a/chromium/cc/tiles/software_image_decode_cache_unittest.cc b/chromium/cc/tiles/software_image_decode_cache_unittest.cc index 321bf021be2..c5e0ff9186f 100644 --- a/chromium/cc/tiles/software_image_decode_cache_unittest.cc +++ b/chromium/cc/tiles/software_image_decode_cache_unittest.cc @@ -6,6 +6,7 @@ #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" @@ -51,7 +52,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -72,7 +73,7 @@ TEST(SoftwareImageDecodeCacheTest, paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kLow_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -90,7 +91,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -108,7 +109,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType); @@ -127,7 +128,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kARGB_4444_SkColorType); @@ -146,7 +147,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -165,7 +166,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -184,7 +185,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -203,7 +204,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -223,7 +224,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -243,7 +244,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -263,7 +264,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -283,7 +284,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -302,7 +303,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -321,7 +322,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -340,7 +341,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -359,7 +360,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -378,7 +379,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -397,7 +398,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -417,7 +418,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -436,7 +437,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -458,7 +459,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -478,7 +479,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -497,7 +498,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -517,7 +518,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -537,7 +538,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -556,7 +557,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -569,7 +570,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto another_key = ImageDecodeCacheKey::FromDrawImage(another_draw_image, kN32_SkColorType); @@ -592,7 +593,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -612,7 +613,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); auto key = ImageDecodeCacheKey::FromDrawImage(draw_image, kN32_SkColorType); EXPECT_EQ(draw_image.frame_key(), key.frame_key()); @@ -632,24 +633,22 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); DrawImage another_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - another_draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task.get() == another_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult another_result = cache.GetTaskForImageAndRef( + another_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(result.task.get() == another_result.task.get()); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -664,29 +663,27 @@ TEST(SoftwareImageDecodeCacheTest, GetTaskForImageSameImageDifferentQuality) { paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kHigh_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> high_quality_task; - bool need_unref = cache.GetTaskForImageAndRef(high_quality_draw_image, - ImageDecodeCache::TracingInfo(), - &high_quality_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(high_quality_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult high_quality_result = + cache.GetTaskForImageAndRef(high_quality_draw_image, + ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(high_quality_result.need_unref); + EXPECT_TRUE(high_quality_result.task); DrawImage none_quality_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), kNone_SkFilterQuality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> none_quality_task; - need_unref = cache.GetTaskForImageAndRef(none_quality_draw_image, - ImageDecodeCache::TracingInfo(), - &none_quality_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(none_quality_task); - EXPECT_TRUE(high_quality_task.get() != none_quality_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult none_quality_result = + cache.GetTaskForImageAndRef(none_quality_draw_image, + ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(none_quality_result.need_unref); + EXPECT_TRUE(none_quality_result.task); + EXPECT_TRUE(high_quality_result.task.get() != none_quality_result.task.get()); - TestTileTaskRunner::ProcessTask(high_quality_task.get()); - TestTileTaskRunner::ProcessTask(none_quality_task.get()); + TestTileTaskRunner::ProcessTask(high_quality_result.task.get()); + TestTileTaskRunner::ProcessTask(none_quality_result.task.get()); cache.UnrefImage(high_quality_draw_image); cache.UnrefImage(none_quality_draw_image); @@ -701,27 +698,25 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> half_size_task; - bool need_unref = cache.GetTaskForImageAndRef( - half_size_draw_image, ImageDecodeCache::TracingInfo(), &half_size_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(half_size_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult half_size_result = cache.GetTaskForImageAndRef( + half_size_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(half_size_result.need_unref); + EXPECT_TRUE(half_size_result.task); 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), - DefaultColorSpace()); - scoped_refptr<TileTask> quarter_size_task; - need_unref = cache.GetTaskForImageAndRef(quarter_size_draw_image, - ImageDecodeCache::TracingInfo(), - &quarter_size_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(quarter_size_task); - EXPECT_TRUE(half_size_task.get() != quarter_size_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult quarter_size_result = + cache.GetTaskForImageAndRef(quarter_size_draw_image, + ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(quarter_size_result.need_unref); + EXPECT_TRUE(quarter_size_result.task); + EXPECT_TRUE(half_size_result.task.get() != quarter_size_result.task.get()); - TestTileTaskRunner::ProcessTask(half_size_task.get()); - TestTileTaskRunner::ProcessTask(quarter_size_task.get()); + TestTileTaskRunner::ProcessTask(half_size_result.task.get()); + TestTileTaskRunner::ProcessTask(quarter_size_result.task.get()); cache.UnrefImage(half_size_draw_image); cache.UnrefImage(quarter_size_draw_image); @@ -737,28 +732,26 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); PaintImage second_paint_image = CreatePaintImage(100, 100); DrawImage second_draw_image( second_paint_image, SkIRect::MakeWH(second_paint_image.width(), second_paint_image.height()), quality, CreateMatrix(SkSize::Make(0.25f, 0.25f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); - TestTileTaskRunner::ProcessTask(first_task.get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(first_draw_image); cache.UnrefImage(second_draw_image); @@ -787,37 +780,34 @@ 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), - color_space_b); - scoped_refptr<TileTask> first_task; - bool need_unref = cache.GetTaskForImageAndRef( - first_draw_image, ImageDecodeCache::TracingInfo(), &first_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(first_task); + PaintImage::kDefaultFrameIndex, color_space_b); + ImageDecodeCache::TaskResult first_result = cache.GetTaskForImageAndRef( + first_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(first_result.need_unref); + EXPECT_TRUE(first_result.task); DrawImage second_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - color_space_c); - scoped_refptr<TileTask> second_task; - need_unref = cache.GetTaskForImageAndRef( - second_draw_image, ImageDecodeCache::TracingInfo(), &second_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(second_task); - EXPECT_TRUE(first_task.get() != second_task.get()); + PaintImage::kDefaultFrameIndex, color_space_c); + ImageDecodeCache::TaskResult second_result = cache.GetTaskForImageAndRef( + second_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(second_result.need_unref); + EXPECT_TRUE(second_result.task); + EXPECT_TRUE(first_result.task.get() != second_result.task.get()); DrawImage third_draw_image( paint_image, SkIRect::MakeWH(paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(1.0f, 1.0f), is_decomposable), - color_space_b); - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - third_draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task); - EXPECT_TRUE(first_task.get() == third_task.get()); + PaintImage::kDefaultFrameIndex, color_space_b); + ImageDecodeCache::TaskResult third_result = cache.GetTaskForImageAndRef( + third_draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_TRUE(first_result.task.get() == third_result.task.get()); - TestTileTaskRunner::ProcessTask(first_task.get()); - TestTileTaskRunner::ProcessTask(second_task.get()); + TestTileTaskRunner::ProcessTask(first_result.task.get()); + TestTileTaskRunner::ProcessTask(second_result.task.get()); cache.UnrefImage(first_draw_image); cache.UnrefImage(second_draw_image); @@ -833,23 +823,21 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ScheduleTask(task.get()); - TestTileTaskRunner::RunTask(task.get()); + TestTileTaskRunner::ScheduleTask(result.task.get()); + TestTileTaskRunner::RunTask(result.task.get()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(another_task); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_FALSE(another_result.task); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -864,29 +852,26 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ScheduleTask(task.get()); - TestTileTaskRunner::RunTask(task.get()); + TestTileTaskRunner::ScheduleTask(result.task.get()); + TestTileTaskRunner::RunTask(result.task.get()); - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(another_task); + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_FALSE(another_result.task); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_FALSE(third_task); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_FALSE(third_result.task); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -902,36 +887,33 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task.get() == task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(another_result.task.get() == result.task.get()); // Didn't run the task, complete it (it was canceled). - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // Fully cancel everything (so the raster would unref things). cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); // Here a new task is created. - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task); - EXPECT_FALSE(third_task.get() == task.get()); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_FALSE(third_result.task.get() == result.task.get()); - TestTileTaskRunner::ProcessTask(third_task.get()); + TestTileTaskRunner::ProcessTask(third_result.task.get()); cache.UnrefImage(draw_image); } @@ -946,35 +928,32 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - - scoped_refptr<TileTask> another_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &another_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(another_task.get() == task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + + ImageDecodeCache::TaskResult another_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(another_result.need_unref); + EXPECT_TRUE(another_result.task.get() == result.task.get()); // Didn't run the task, complete it (it was canceled). - TestTileTaskRunner::CancelTask(task.get()); - TestTileTaskRunner::CompleteTask(task.get()); + TestTileTaskRunner::CancelTask(result.task.get()); + TestTileTaskRunner::CompleteTask(result.task.get()); // Note that here, everything is reffed, but a new task is created. This is // possible with repeated schedule/cancel operations. - scoped_refptr<TileTask> third_task; - need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &third_task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(third_task); - EXPECT_FALSE(third_task.get() == task.get()); + ImageDecodeCache::TaskResult third_result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(third_result.need_unref); + EXPECT_TRUE(third_result.task); + EXPECT_FALSE(third_result.task.get() == result.task.get()); - TestTileTaskRunner::ProcessTask(third_task.get()); + TestTileTaskRunner::ProcessTask(third_result.task.get()); - // 3 Unrefs! + // 3 Unrefs!!! cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); cache.UnrefImage(draw_image); @@ -989,14 +968,13 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1024,14 +1002,13 @@ TEST(SoftwareImageDecodeCacheTest, paint_image, SkIRect::MakeXYWH(20, 30, paint_image.width(), paint_image.height()), quality, CreateMatrix(SkSize::Make(0.5f, 0.5f), is_decomposable), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1057,7 +1034,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1083,7 +1060,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1115,7 +1092,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1128,13 +1105,12 @@ TEST(SoftwareImageDecodeCacheTest, EXPECT_FALSE(decoded_draw_image.is_scale_adjustment_identity()); EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage another_decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1161,7 +1137,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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1174,17 +1150,16 @@ TEST(SoftwareImageDecodeCacheTest, EXPECT_FALSE(decoded_draw_image.is_scale_adjustment_identity()); EXPECT_TRUE(decoded_draw_image.is_at_raster_decode()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); // If we finish the draw here, then we will use it for the locked decode // instead of decoding again. cache.DrawWithImageFinished(draw_image, decoded_draw_image); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage another_decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1207,13 +1182,12 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(task); - EXPECT_FALSE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.task); + EXPECT_FALSE(result.need_unref); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1232,13 +1206,12 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(task); - EXPECT_FALSE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.task); + EXPECT_FALSE(result.need_unref); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1256,15 +1229,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1285,15 +1257,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1319,15 +1290,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1351,15 +1321,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1383,15 +1352,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1415,15 +1383,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1447,15 +1414,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1479,15 +1445,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1511,15 +1476,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1543,15 +1507,14 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(task); - EXPECT_TRUE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.task); + EXPECT_TRUE(result.need_unref); - TestTileTaskRunner::ProcessTask(task.get()); + TestTileTaskRunner::ProcessTask(result.task.get()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1575,13 +1538,12 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_FALSE(task); - EXPECT_FALSE(need_unref); + ImageDecodeCache::TaskResult result = + cache.GetTaskForImageAndRef(draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_FALSE(result.task); + EXPECT_FALSE(result.need_unref); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); @@ -1600,24 +1562,22 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); - scoped_refptr<TileTask> task_50; - bool need_unref_50 = cache.GetTaskForImageAndRef( - draw_image_50, ImageDecodeCache::TracingInfo(), &task_50); - EXPECT_TRUE(task_50); - EXPECT_TRUE(need_unref_50); - scoped_refptr<TileTask> task_49; - bool need_unref_49 = cache.GetTaskForImageAndRef( - draw_image_49, ImageDecodeCache::TracingInfo(), &task_49); - EXPECT_TRUE(task_49); - EXPECT_TRUE(need_unref_49); + ImageDecodeCache::TaskResult result_50 = cache.GetTaskForImageAndRef( + draw_image_50, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result_50.task); + EXPECT_TRUE(result_50.need_unref); + ImageDecodeCache::TaskResult result_49 = cache.GetTaskForImageAndRef( + draw_image_49, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result_49.task); + EXPECT_TRUE(result_49.need_unref); - TestTileTaskRunner::ProcessTask(task_49.get()); + TestTileTaskRunner::ProcessTask(result_49.task.get()); DecodedDrawImage decoded_draw_image_50 = cache.GetDecodedImageForDraw(draw_image_50); @@ -1653,13 +1613,12 @@ 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), - DefaultColorSpace()); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - TestTileTaskRunner::ProcessTask(task.get()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.UnrefImage(draw_image); } @@ -1683,16 +1642,15 @@ 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), - DefaultColorSpace()); + PaintImage::kDefaultFrameIndex, DefaultColorSpace()); frame_keys.push_back(draw_image.frame_key()); DecodedDrawImage decoded_draw_image = cache.GetDecodedImageForDraw(draw_image); - scoped_refptr<TileTask> task; - bool need_unref = cache.GetTaskForImageAndRef( - draw_image, ImageDecodeCache::TracingInfo(), &task); - EXPECT_TRUE(need_unref); - EXPECT_TRUE(task); - TestTileTaskRunner::ProcessTask(task.get()); + ImageDecodeCache::TaskResult result = cache.GetTaskForImageAndRef( + draw_image, ImageDecodeCache::TracingInfo()); + EXPECT_TRUE(result.need_unref); + EXPECT_TRUE(result.task); + TestTileTaskRunner::ProcessTask(result.task.get()); cache.DrawWithImageFinished(draw_image, decoded_draw_image); cache.UnrefImage(draw_image); } @@ -1707,5 +1665,58 @@ TEST(SoftwareImageDecodeCacheTest, RemoveUnusedImage) { } } +TEST(SoftwareImageDecodeCacheTest, CacheDecodesExpectedFrames) { + TestSoftwareImageDecodeCache cache; + std::vector<FrameMetadata> 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<FakePaintImageGenerator> generator = + sk_make_sp<FakePaintImageGenerator>( + SkImageInfo::MakeN32Premul(10, 10, SkColorSpace::MakeSRGB()), frames); + PaintImage image = PaintImageBuilder::WithDefault() + .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/chromium/cc/tiles/tile_manager.cc b/chromium/cc/tiles/tile_manager.cc index 8b916dea259..007fff3b0fb 100644 --- a/chromium/cc/tiles/tile_manager.cc +++ b/chromium/cc/tiles/tile_manager.cc @@ -242,7 +242,7 @@ void InsertNodeForDecodeTask(TaskGraph* graph, if (!dependency->HasCompleted()) { InsertNodeForDecodeTask(graph, dependency, use_foreground_category, priority); - graph->edges.push_back(TaskGraph::Edge(dependency, task)); + graph->edges.emplace_back(dependency, task); dependency_count = 1u; } } @@ -293,7 +293,7 @@ void InsertNodesForRasterTask(TaskGraph* graph, priority); } - graph->edges.push_back(TaskGraph::Edge(decode_task, raster_task)); + graph->edges.emplace_back(decode_task, raster_task); } InsertNodeForTask( @@ -883,7 +883,8 @@ void TileManager::PartitionImagesForCheckering( const PrioritizedTile& prioritized_tile, const gfx::ColorSpace& raster_color_space, std::vector<DrawImage>* sync_decoded_images, - std::vector<PaintImage>* checkered_images) { + std::vector<PaintImage>* checkered_images, + base::flat_map<PaintImage::Id, size_t>* image_to_frame_index) { Tile* tile = prioritized_tile.tile(); std::vector<const DrawImage*> images_in_tile; prioritized_tile.raster_source()->GetDiscardableImagesInRect( @@ -891,10 +892,18 @@ void TileManager::PartitionImagesForCheckering( WhichTree tree = tile->tiling()->tree(); for (const auto* original_draw_image : images_in_tile) { + size_t frame_index = original_draw_image->paint_image().frame_index(); + if (tile_manager_settings_.enable_image_animations) { + const auto& image = original_draw_image->paint_image(); + frame_index = client_->GetFrameIndexForImage(image, tree); + if (image_to_frame_index) { + (*image_to_frame_index)[image.stable_id()] = frame_index; + } + } + DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(), - raster_color_space); - if (checker_image_tracker_.ShouldCheckerImage( - draw_image, tree, tile->required_for_activation())) + frame_index, raster_color_space); + if (checker_image_tracker_.ShouldCheckerImage(draw_image, tree)) checkered_images->push_back(draw_image.paint_image()); else sync_decoded_images->push_back(std::move(draw_image)); @@ -913,12 +922,15 @@ void TileManager::AddCheckeredImagesToDecodeQueue( WhichTree tree = tile->tiling()->tree(); for (const auto* original_draw_image : images_in_tile) { + size_t frame_index = original_draw_image->paint_image().frame_index(); + if (tile_manager_settings_.enable_image_animations) { + frame_index = client_->GetFrameIndexForImage( + original_draw_image->paint_image(), tree); + } DrawImage draw_image(*original_draw_image, tile->raster_transform().scale(), - raster_color_space); - if (checker_image_tracker_.ShouldCheckerImage( - draw_image, tree, tile->required_for_activation())) { - image_decode_queue->push_back(CheckerImageTracker::ImageDecodeRequest( - draw_image.paint_image(), decode_type)); + frame_index, raster_color_space); + if (checker_image_tracker_.ShouldCheckerImage(draw_image, tree)) { + image_decode_queue->emplace_back(draw_image.paint_image(), decode_type); } } } @@ -978,16 +990,14 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) { if (tile->required_for_activation()) { required_for_activate_count++; - graph_.edges.push_back( - TaskGraph::Edge(task, required_for_activation_done_task.get())); + graph_.edges.emplace_back(task, required_for_activation_done_task.get()); } if (tile->required_for_draw()) { required_for_draw_count++; - graph_.edges.push_back( - TaskGraph::Edge(task, required_for_draw_done_task.get())); + graph_.edges.emplace_back(task, required_for_draw_done_task.get()); } all_count++; - graph_.edges.push_back(TaskGraph::Edge(task, all_done_task.get())); + graph_.edges.emplace_back(task, all_done_task.get()); // A tile should use a foreground task cateogry if it is either blocking // future compositing (required for draw or required for activation), or if @@ -1017,9 +1027,8 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) { // For checkered-images, send them to the decode service. for (auto& image : checkered_images) { - work_to_schedule.checker_image_decode_queue.push_back( - CheckerImageTracker::ImageDecodeRequest( - std::move(image), CheckerImageTracker::DecodeType::kPreDecode)); + work_to_schedule.checker_image_decode_queue.emplace_back( + std::move(image), CheckerImageTracker::DecodeType::kPreDecode); } } @@ -1043,7 +1052,7 @@ void TileManager::ScheduleTasks(PrioritizedWorkToSchedule work_to_schedule) { InsertNodeForDecodeTask(&graph_, task.get(), false, priority++); all_count++; - graph_.edges.push_back(TaskGraph::Edge(task.get(), all_done_task.get())); + graph_.edges.emplace_back(task.get(), all_done_task.get()); } // The old locked images tasks have to stay around until past the @@ -1136,11 +1145,15 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask( scheduled_draw_images_[tile->id()]; sync_decoded_images.clear(); PaintImageIdFlatSet images_to_skip; + base::flat_map<PaintImage::Id, size_t> image_id_to_current_frame_index; if (!skip_images) { std::vector<PaintImage> checkered_images; PartitionImagesForCheckering(prioritized_tile, color_space, - &sync_decoded_images, &checkered_images); + &sync_decoded_images, &checkered_images, + &image_id_to_current_frame_index); 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 @@ -1148,9 +1161,8 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask( // skipping images for these tiles, we don't need to decode them since // they will not be required on the next active tree. if (prioritized_tile.should_decode_checkered_images_for_tile()) { - checker_image_decode_queue->push_back( - CheckerImageTracker::ImageDecodeRequest( - image, CheckerImageTracker::DecodeType::kRaster)); + checker_image_decode_queue->emplace_back( + image, CheckerImageTracker::DecodeType::kRaster); } } } @@ -1164,25 +1176,37 @@ scoped_refptr<TileTask> TileManager::CreateRasterTask( ImageDecodeCache::TracingInfo tracing_info( prepare_tiles_count_, prioritized_tile.priority().priority_bin, ImageDecodeCache::TaskType::kInRaster); - image_controller_.GetTasksForImagesAndRef(&sync_decoded_images, &decode_tasks, - tracing_info); + std::vector<DrawImage> at_raster_images; + image_controller_.GetTasksForImagesAndRef( + &sync_decoded_images, &at_raster_images, &decode_tasks, tracing_info); std::unique_ptr<RasterBuffer> raster_buffer = raster_buffer_provider_->AcquireBufferForRaster( resource, resource_content_id, tile->invalidated_id()); base::Optional<PlaybackImageProvider> image_provider; - const bool has_predecoded_images = !sync_decoded_images.empty(); - if (skip_images || has_checker_images || has_predecoded_images) { - image_provider.emplace(skip_images, std::move(images_to_skip), - image_controller_.cache(), color_space); + const bool has_sync_decoded_images = !sync_decoded_images.empty(); + const bool has_at_raster_images = !at_raster_images.empty(); + if (skip_images || has_checker_images || has_sync_decoded_images || + has_at_raster_images) { + base::Optional<PlaybackImageProvider::Settings> settings; + if (!skip_images) { + settings.emplace(); + settings->images_to_skip = std::move(images_to_skip); + settings->at_raster_images = std::move(at_raster_images); + settings->image_to_current_frame_index = + std::move(image_id_to_current_frame_index); + } + + image_provider.emplace(image_controller_.cache(), color_space, + std::move(settings)); } - return make_scoped_refptr(new RasterTaskImpl( + return base::MakeRefCounted<RasterTaskImpl>( this, tile, resource, prioritized_tile.raster_source(), playback_settings, prioritized_tile.priority().resolution, invalidated_rect, prepare_tiles_count_, std::move(raster_buffer), &decode_tasks, - use_gpu_rasterization_, std::move(image_provider))); + use_gpu_rasterization_, std::move(image_provider)); } void TileManager::ResetSignalsForTesting() { @@ -1211,6 +1235,11 @@ void TileManager::OnRasterTaskCompleted( // Unref all the images. auto images_it = scheduled_draw_images_.find(tile_id); + // Every raster task unconditionally creates sync_decoded_images_ entry in + // CreateRasterTask. This is the only place it's cleared. So we should have + // the images_it here that doesn't point to end. This check is here to debug + // crbug.com/757049. + CHECK(images_it != scheduled_draw_images_.end()); image_controller_.UnrefImages(images_it->second); scheduled_draw_images_.erase(images_it); @@ -1582,9 +1611,9 @@ void TileManager::CheckPendingGpuWorkTiles(bool issue_signals, bool flush) { // posts |callback| to |task_runner| when run. scoped_refptr<TileTask> TileManager::CreateTaskSetFinishedTask( void (TileManager::*callback)()) { - return make_scoped_refptr(new TaskSetFinishedTaskImpl( + return base::MakeRefCounted<TaskSetFinishedTaskImpl>( task_runner_, - base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr()))); + base::Bind(callback, task_set_finished_weak_ptr_factory_.GetWeakPtr())); } std::unique_ptr<base::trace_event::ConvertableToTraceFormat> diff --git a/chromium/cc/tiles/tile_manager.h b/chromium/cc/tiles/tile_manager.h index d9a7cbfdfef..58de5f05f0e 100644 --- a/chromium/cc/tiles/tile_manager.h +++ b/chromium/cc/tiles/tile_manager.h @@ -87,6 +87,9 @@ 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() {} }; @@ -357,10 +360,12 @@ 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<DrawImage>* sync_decoded_images, - std::vector<PaintImage>* checkered_images); + void PartitionImagesForCheckering( + const PrioritizedTile& prioritized_tile, + const gfx::ColorSpace& raster_color_space, + std::vector<DrawImage>* sync_decoded_images, + std::vector<PaintImage>* checkered_images, + base::flat_map<PaintImage::Id, size_t>* image_to_frame_index = nullptr); void AddCheckeredImagesToDecodeQueue( const PrioritizedTile& prioritized_tile, const gfx::ColorSpace& raster_color_space, diff --git a/chromium/cc/tiles/tile_manager_settings.h b/chromium/cc/tiles/tile_manager_settings.h index 6a7f7fb1f0c..7a3d158af07 100644 --- a/chromium/cc/tiles/tile_manager_settings.h +++ b/chromium/cc/tiles/tile_manager_settings.h @@ -13,6 +13,7 @@ struct CC_EXPORT TileManagerSettings { bool use_partial_raster = false; bool enable_checker_imaging = false; size_t min_image_bytes_to_checker = 1 * 1024 * 1024; + bool enable_image_animations = false; }; } // namespace cc diff --git a/chromium/cc/tiles/tile_manager_unittest.cc b/chromium/cc/tiles/tile_manager_unittest.cc index 3834ba3e48f..7c319683256 100644 --- a/chromium/cc/tiles/tile_manager_unittest.cc +++ b/chromium/cc/tiles/tile_manager_unittest.cc @@ -22,6 +22,7 @@ #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" @@ -29,7 +30,6 @@ #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" @@ -58,7 +58,7 @@ namespace { // posted should run synchronously. class SynchronousSimpleTaskRunner : public base::TestSimpleTaskRunner { public: - bool PostDelayedTask(const tracked_objects::Location& from_here, + bool PostDelayedTask(const base::Location& from_here, base::OnceClosure task, base::TimeDelta delay) override { TestSimpleTaskRunner::PostDelayedTask(from_here, std::move(task), delay); @@ -67,7 +67,7 @@ class SynchronousSimpleTaskRunner : public base::TestSimpleTaskRunner { return true; } - bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here, + bool PostNonNestableDelayedTask(const base::Location& from_here, base::OnceClosure task, base::TimeDelta delay) override { return PostDelayedTask(from_here, std::move(task), delay); @@ -2307,10 +2307,10 @@ TEST_F(TileManagerReadyToDrawTest, ReadyToDrawRespectsRequirementChange) { class CheckerImagingTileManagerTest : public TestLayerTreeHostBase { public: - class MockImageGenerator : public StubPaintImageGenerator { + class MockImageGenerator : public FakePaintImageGenerator { public: explicit MockImageGenerator(const gfx::Size& size) - : StubPaintImageGenerator( + : FakePaintImageGenerator( SkImageInfo::MakeN32Premul(size.width(), size.height())) {} MOCK_METHOD5(GetPixels, @@ -2337,7 +2337,7 @@ class CheckerImagingTileManagerTest : public TestLayerTreeHostBase { const LayerTreeSettings& settings, TaskRunnerProvider* task_runner_provider, TaskGraphRunner* task_graph_runner) override { - task_runner_ = make_scoped_refptr(new SynchronousSimpleTaskRunner); + task_runner_ = base::MakeRefCounted<SynchronousSimpleTaskRunner>(); return std::make_unique<FakeLayerTreeHostImpl>( settings, task_runner_provider, task_graph_runner, task_runner_); } @@ -2374,7 +2374,7 @@ TEST_F(CheckerImagingTileManagerTest, auto generator = sk_make_sp<testing::StrictMock<MockImageGenerator>>(gfx::Size(512, 512)); - PaintImage image = PaintImageBuilder() + PaintImage image = PaintImageBuilder::WithDefault() .set_id(PaintImage::GetNextId()) .set_paint_image_generator(generator) .TakePaintImage(); |