| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/tiles/image_manager.h" | 5 #include "cc/tiles/image_manager.h" |
| 6 | 6 |
| 7 namespace cc { | 7 namespace cc { |
| 8 | 8 |
| 9 ImageManager::ImageManager() = default; | 9 ImageManager::ImageManager() = default; |
| 10 ImageManager::~ImageManager() = default; | 10 ImageManager::~ImageManager() = default; |
| 11 | 11 |
| 12 void ImageManager::SetImageDecodeController(ImageDecodeController* controller) { | 12 void ImageManager::SetImageDecodeCache(ImageDecodeCache* cache) { |
| 13 // We can only switch from null to non-null and back. | 13 // We can only switch from null to non-null and back. |
| 14 // CHECK to debug crbug.com/650234. | 14 // CHECK to debug crbug.com/650234. |
| 15 CHECK(controller || controller_); | 15 CHECK(cache || cache_); |
| 16 CHECK(!controller || !controller_); | 16 CHECK(!cache || !cache_); |
| 17 | 17 |
| 18 if (!controller) { | 18 if (!cache) { |
| 19 SetPredecodeImages(std::vector<DrawImage>(), | 19 SetPredecodeImages(std::vector<DrawImage>(), |
| 20 ImageDecodeController::TracingInfo()); | 20 ImageDecodeCache::TracingInfo()); |
| 21 } | 21 } |
| 22 controller_ = controller; | 22 cache_ = cache; |
| 23 // Debugging information for crbug.com/650234. | 23 // Debugging information for crbug.com/650234. |
| 24 ++num_times_controller_was_set_; | 24 ++num_times_cache_was_set_; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ImageManager::GetTasksForImagesAndRef( | 27 void ImageManager::GetTasksForImagesAndRef( |
| 28 std::vector<DrawImage>* images, | 28 std::vector<DrawImage>* images, |
| 29 std::vector<scoped_refptr<TileTask>>* tasks, | 29 std::vector<scoped_refptr<TileTask>>* tasks, |
| 30 const ImageDecodeController::TracingInfo& tracing_info) { | 30 const ImageDecodeCache::TracingInfo& tracing_info) { |
| 31 DCHECK(controller_); | 31 DCHECK(cache_); |
| 32 for (auto it = images->begin(); it != images->end();) { | 32 for (auto it = images->begin(); it != images->end();) { |
| 33 scoped_refptr<TileTask> task; | 33 scoped_refptr<TileTask> task; |
| 34 bool need_to_unref_when_finished = | 34 bool need_to_unref_when_finished = |
| 35 controller_->GetTaskForImageAndRef(*it, tracing_info, &task); | 35 cache_->GetTaskForImageAndRef(*it, tracing_info, &task); |
| 36 if (task) | 36 if (task) |
| 37 tasks->push_back(std::move(task)); | 37 tasks->push_back(std::move(task)); |
| 38 | 38 |
| 39 if (need_to_unref_when_finished) | 39 if (need_to_unref_when_finished) |
| 40 ++it; | 40 ++it; |
| 41 else | 41 else |
| 42 it = images->erase(it); | 42 it = images->erase(it); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 void ImageManager::UnrefImages(const std::vector<DrawImage>& images) { | 46 void ImageManager::UnrefImages(const std::vector<DrawImage>& images) { |
| 47 // Debugging information for crbug.com/650234. | 47 // Debugging information for crbug.com/650234. |
| 48 CHECK(controller_) << num_times_controller_was_set_; | 48 CHECK(cache_) << num_times_cache_was_set_; |
| 49 for (auto image : images) | 49 for (auto image : images) |
| 50 controller_->UnrefImage(image); | 50 cache_->UnrefImage(image); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void ImageManager::ReduceMemoryUsage() { | 53 void ImageManager::ReduceMemoryUsage() { |
| 54 DCHECK(controller_); | 54 DCHECK(cache_); |
| 55 controller_->ReduceCacheUsage(); | 55 cache_->ReduceCacheUsage(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 std::vector<scoped_refptr<TileTask>> ImageManager::SetPredecodeImages( | 58 std::vector<scoped_refptr<TileTask>> ImageManager::SetPredecodeImages( |
| 59 std::vector<DrawImage> images, | 59 std::vector<DrawImage> images, |
| 60 const ImageDecodeController::TracingInfo& tracing_info) { | 60 const ImageDecodeCache::TracingInfo& tracing_info) { |
| 61 std::vector<scoped_refptr<TileTask>> new_tasks; | 61 std::vector<scoped_refptr<TileTask>> new_tasks; |
| 62 GetTasksForImagesAndRef(&images, &new_tasks, tracing_info); | 62 GetTasksForImagesAndRef(&images, &new_tasks, tracing_info); |
| 63 UnrefImages(predecode_locked_images_); | 63 UnrefImages(predecode_locked_images_); |
| 64 predecode_locked_images_ = std::move(images); | 64 predecode_locked_images_ = std::move(images); |
| 65 return new_tasks; | 65 return new_tasks; |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace cc | 68 } // namespace cc |
| OLD | NEW |