Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: cc/tiles/image_controller.cc

Issue 2699533010: cc: Fix cleanup path for image decode requests in ImageController. (Closed)
Patch Set: .. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | cc/tiles/image_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_controller.h" 5 #include "cc/tiles/image_controller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/task_scheduler/post_task.h" 8 #include "base/task_scheduler/post_task.h"
9 #include "base/task_scheduler/task_traits.h" 9 #include "base/task_scheduler/task_traits.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 cache_->UnrefImage(image_pair.second); 70 cache_->UnrefImage(image_pair.second);
71 requested_locked_images_.clear(); 71 requested_locked_images_.clear();
72 72
73 // Now, complete the tasks that already ran but haven't completed. These would 73 // Now, complete the tasks that already ran but haven't completed. These would
74 // be posted in the run loop, but since we invalidated the weak ptrs, we need 74 // be posted in the run loop, but since we invalidated the weak ptrs, we need
75 // to run everything manually. 75 // to run everything manually.
76 for (auto& request_to_complete : requests_needing_completion_) { 76 for (auto& request_to_complete : requests_needing_completion_) {
77 ImageDecodeRequestId id = request_to_complete.first; 77 ImageDecodeRequestId id = request_to_complete.first;
78 ImageDecodeRequest& request = request_to_complete.second; 78 ImageDecodeRequest& request = request_to_complete.second;
79 79
80 // The task (if one exists) would have run already, so we just need to 80 // The task (if one exists) would have run already, we just need to make
81 // complete it. 81 // sure it was completed. Multiple requests for the same image use the same
82 if (request.task) 82 // task so it could have already been completed.
83 if (request.task && !request.task->HasCompleted())
83 request.task->DidComplete(); 84 request.task->DidComplete();
84 85
85 // Issue the callback, and unref the image immediately. This is so that any 86 // Issue the callback, and unref the image immediately. This is so that any
86 // code waiting on the callback can proceed, although we're breaking the 87 // code waiting on the callback can proceed, although we're breaking the
87 // promise of having this image decoded. This is unfortunate, but it seems 88 // promise of having this image decoded. This is unfortunate, but it seems
88 // like the least complexity to process an image decode controller becoming 89 // like the least complexity to process an image decode controller becoming
89 // nullptr. 90 // nullptr.
90 request.callback.Run(id); 91 request.callback.Run(id);
91 if (request.need_unref) 92 if (request.need_unref)
92 cache_->UnrefImage(request.draw_image); 93 cache_->UnrefImage(request.draw_image);
93 } 94 }
94 requests_needing_completion_.clear(); 95 requests_needing_completion_.clear();
95 96
96 // Finally, complete all of the tasks that never started running. This is 97 // Finally, complete all of the tasks that never started running. This is
97 // similar to the |requests_needing_completion_|, but happens at a different 98 // similar to the |requests_needing_completion_|, but happens at a different
98 // stage in the pipeline. 99 // stage in the pipeline.
99 for (auto& request_pair : image_decode_queue_) { 100 for (auto& request_pair : image_decode_queue_) {
100 ImageDecodeRequestId id = request_pair.first; 101 ImageDecodeRequestId id = request_pair.first;
101 ImageDecodeRequest& request = request_pair.second; 102 ImageDecodeRequest& request = request_pair.second;
102 103
103 if (request.task) { 104 if (request.task) {
104 // This task may have run via a different request, so only cancel it if 105 // This task may have run via a different request, so only cancel it if
105 // it's "new". That is, the same task could have been referenced by 106 // it's "new". That is, the same task could have been referenced by
106 // several different image deque requests for the same image. 107 // several different image deque requests for the same image.
107 if (request.task->state().IsNew()) 108 if (request.task->state().IsNew())
108 request.task->state().DidCancel(); 109 request.task->state().DidCancel();
109 request.task->DidComplete(); 110
111 if (!request.task->HasCompleted())
112 request.task->DidComplete();
110 } 113 }
111 // Run the callback and unref the image. 114 // Run the callback and unref the image.
112 request.callback.Run(id); 115 request.callback.Run(id);
113 cache_->UnrefImage(request.draw_image); 116 cache_->UnrefImage(request.draw_image);
114 } 117 }
115 image_decode_queue_.clear(); 118 image_decode_queue_.clear();
116 } 119 }
117 120
118 void ImageController::SetImageDecodeCache(ImageDecodeCache* cache) { 121 void ImageController::SetImageDecodeCache(ImageDecodeCache* cache) {
122 DCHECK(!cache_ || !cache);
123
119 if (!cache) { 124 if (!cache) {
120 SetPredecodeImages(std::vector<DrawImage>(), 125 SetPredecodeImages(std::vector<DrawImage>(),
121 ImageDecodeCache::TracingInfo()); 126 ImageDecodeCache::TracingInfo());
122 StopWorkerTasks(); 127 StopWorkerTasks();
123 } 128 }
129
124 cache_ = cache; 130 cache_ = cache;
125 } 131 }
126 132
127 void ImageController::GetTasksForImagesAndRef( 133 void ImageController::GetTasksForImagesAndRef(
128 std::vector<DrawImage>* images, 134 std::vector<DrawImage>* images,
129 std::vector<scoped_refptr<TileTask>>* tasks, 135 std::vector<scoped_refptr<TileTask>>* tasks,
130 const ImageDecodeCache::TracingInfo& tracing_info) { 136 const ImageDecodeCache::TracingInfo& tracing_info) {
131 DCHECK(cache_); 137 DCHECK(cache_);
132 for (auto it = images->begin(); it != images->end();) { 138 for (auto it = images->begin(); it != images->end();) {
133 scoped_refptr<TileTask> task; 139 scoped_refptr<TileTask> task;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ImageController::ImageDecodeRequest::ImageDecodeRequest( 314 ImageController::ImageDecodeRequest::ImageDecodeRequest(
309 const ImageDecodeRequest& other) = default; 315 const ImageDecodeRequest& other) = default;
310 ImageController::ImageDecodeRequest::~ImageDecodeRequest() = default; 316 ImageController::ImageDecodeRequest::~ImageDecodeRequest() = default;
311 317
312 ImageController::ImageDecodeRequest& ImageController::ImageDecodeRequest:: 318 ImageController::ImageDecodeRequest& ImageController::ImageDecodeRequest::
313 operator=(ImageDecodeRequest&& other) = default; 319 operator=(ImageDecodeRequest&& other) = default;
314 ImageController::ImageDecodeRequest& ImageController::ImageDecodeRequest:: 320 ImageController::ImageDecodeRequest& ImageController::ImageDecodeRequest::
315 operator=(const ImageDecodeRequest& other) = default; 321 operator=(const ImageDecodeRequest& other) = default;
316 322
317 } // namespace cc 323 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/tiles/image_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698