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

Unified Diff: cc/tiles/image_manager.cc

Issue 2339703005: cc: Add ImageManager to keep all the image locking in the same place. (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: cc/tiles/image_manager.cc
diff --git a/cc/tiles/image_manager.cc b/cc/tiles/image_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cb11e9ec19266ae01c1577b07fb3b2dfe7e13996
--- /dev/null
+++ b/cc/tiles/image_manager.cc
@@ -0,0 +1,46 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/tiles/image_manager.h"
+
+namespace cc {
+
+ImageManager::ImageManager() = default;
+ImageManager::~ImageManager() = default;
+
+void ImageManager::SetImageDecodeController(ImageDecodeController* controller) {
+ controller_ = controller;
enne (OOO) 2016/09/15 17:42:15 This is an awkward API. I realize that the image
vmpstr 2016/09/15 18:16:35 So you're absolutely right that this can change. F
enne (OOO) 2016/09/15 18:27:02 Ok, that's fine if you want to just handle it here
+}
+
+void ImageManager::GetTasksForImagesAndRef(
+ std::vector<DrawImage>* images,
+ std::vector<scoped_refptr<TileTask>>* tasks,
+ const ImageDecodeController::TracingInfo& tracing_info) {
+ DCHECK(controller_);
+ for (auto it = images->begin(); it != images->end();) {
+ scoped_refptr<TileTask> task;
+ bool need_to_unref_when_finished =
+ controller_->GetTaskForImageAndRef(*it, tracing_info, &task);
+ if (task)
+ tasks->push_back(std::move(task));
+
+ if (need_to_unref_when_finished)
+ ++it;
+ else
+ it = images->erase(it);
+ }
+}
+
+void ImageManager::UnrefImages(const std::vector<DrawImage>& images) {
+ DCHECK(controller_);
+ for (auto image : images)
+ controller_->UnrefImage(image);
+}
+
+void ImageManager::ReduceMemoryUsage() {
+ DCHECK(controller_);
+ controller_->ReduceCacheUsage();
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698