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::SetImageDecodeController(ImageDecodeController* controller) { |
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 DCHECK(controller || controller_); | 14 // CHECK to debug crbug.com/650234. |
15 DCHECK(!controller || !controller_); | 15 CHECK(controller || controller_); |
| 16 CHECK(!controller || !controller_); |
16 | 17 |
17 if (!controller) { | 18 if (!controller) { |
18 SetPredecodeImages(std::vector<DrawImage>(), | 19 SetPredecodeImages(std::vector<DrawImage>(), |
19 ImageDecodeController::TracingInfo()); | 20 ImageDecodeController::TracingInfo()); |
20 } | 21 } |
21 controller_ = controller; | 22 controller_ = controller; |
| 23 // Debugging information for crbug.com/650234. |
| 24 ++num_times_controller_was_set_; |
22 } | 25 } |
23 | 26 |
24 void ImageManager::GetTasksForImagesAndRef( | 27 void ImageManager::GetTasksForImagesAndRef( |
25 std::vector<DrawImage>* images, | 28 std::vector<DrawImage>* images, |
26 std::vector<scoped_refptr<TileTask>>* tasks, | 29 std::vector<scoped_refptr<TileTask>>* tasks, |
27 const ImageDecodeController::TracingInfo& tracing_info) { | 30 const ImageDecodeController::TracingInfo& tracing_info) { |
28 DCHECK(controller_); | 31 DCHECK(controller_); |
29 for (auto it = images->begin(); it != images->end();) { | 32 for (auto it = images->begin(); it != images->end();) { |
30 scoped_refptr<TileTask> task; | 33 scoped_refptr<TileTask> task; |
31 bool need_to_unref_when_finished = | 34 bool need_to_unref_when_finished = |
32 controller_->GetTaskForImageAndRef(*it, tracing_info, &task); | 35 controller_->GetTaskForImageAndRef(*it, tracing_info, &task); |
33 if (task) | 36 if (task) |
34 tasks->push_back(std::move(task)); | 37 tasks->push_back(std::move(task)); |
35 | 38 |
36 if (need_to_unref_when_finished) | 39 if (need_to_unref_when_finished) |
37 ++it; | 40 ++it; |
38 else | 41 else |
39 it = images->erase(it); | 42 it = images->erase(it); |
40 } | 43 } |
41 } | 44 } |
42 | 45 |
43 void ImageManager::UnrefImages(const std::vector<DrawImage>& images) { | 46 void ImageManager::UnrefImages(const std::vector<DrawImage>& images) { |
44 DCHECK(controller_); | 47 // Debugging information for crbug.com/650234. |
| 48 CHECK(controller_) << num_times_controller_was_set_; |
45 for (auto image : images) | 49 for (auto image : images) |
46 controller_->UnrefImage(image); | 50 controller_->UnrefImage(image); |
47 } | 51 } |
48 | 52 |
49 void ImageManager::ReduceMemoryUsage() { | 53 void ImageManager::ReduceMemoryUsage() { |
50 DCHECK(controller_); | 54 DCHECK(controller_); |
51 controller_->ReduceCacheUsage(); | 55 controller_->ReduceCacheUsage(); |
52 } | 56 } |
53 | 57 |
54 std::vector<scoped_refptr<TileTask>> ImageManager::SetPredecodeImages( | 58 std::vector<scoped_refptr<TileTask>> ImageManager::SetPredecodeImages( |
55 std::vector<DrawImage> images, | 59 std::vector<DrawImage> images, |
56 const ImageDecodeController::TracingInfo& tracing_info) { | 60 const ImageDecodeController::TracingInfo& tracing_info) { |
57 std::vector<scoped_refptr<TileTask>> new_tasks; | 61 std::vector<scoped_refptr<TileTask>> new_tasks; |
58 GetTasksForImagesAndRef(&images, &new_tasks, tracing_info); | 62 GetTasksForImagesAndRef(&images, &new_tasks, tracing_info); |
59 UnrefImages(predecode_locked_images_); | 63 UnrefImages(predecode_locked_images_); |
60 predecode_locked_images_ = std::move(images); | 64 predecode_locked_images_ = std::move(images); |
61 return new_tasks; | 65 return new_tasks; |
62 } | 66 } |
63 | 67 |
64 } // namespace cc | 68 } // namespace cc |
OLD | NEW |