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

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

Issue 2703633004: cc: Make image controller return a status with the callback. (Closed)
Patch Set: update Created 3 years, 9 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 | « cc/tiles/decoded_image_tracker.h ('k') | cc/tiles/decoded_image_tracker_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/decoded_image_tracker.h" 5 #include "cc/tiles/decoded_image_tracker.h"
6 6
7 namespace cc { 7 namespace cc {
8 namespace { 8 namespace {
9 const int kNumFramesToLock = 2; 9 const int kNumFramesToLock = 2;
10 } // namespace 10 } // namespace
11 11
12 DecodedImageTracker::DecodedImageTracker() = default; 12 DecodedImageTracker::DecodedImageTracker() = default;
13 DecodedImageTracker::~DecodedImageTracker() { 13 DecodedImageTracker::~DecodedImageTracker() {
14 for (auto& pair : locked_images_) 14 for (auto& pair : locked_images_)
15 image_controller_->UnlockImageDecode(pair.first); 15 image_controller_->UnlockImageDecode(pair.first);
16 } 16 }
17 17
18 void DecodedImageTracker::QueueImageDecode(sk_sp<const SkImage> image, 18 void DecodedImageTracker::QueueImageDecode(
19 const base::Closure& callback) { 19 sk_sp<const SkImage> image,
20 const base::Callback<void(bool)>& callback) {
20 DCHECK(image_controller_); 21 DCHECK(image_controller_);
21 // Queue the decode in the image controller, but switch out the callback for 22 // Queue the decode in the image controller, but switch out the callback for
22 // our own. 23 // our own.
23 image_controller_->QueueImageDecode( 24 image_controller_->QueueImageDecode(
24 std::move(image), base::Bind(&DecodedImageTracker::ImageDecodeFinished, 25 std::move(image), base::Bind(&DecodedImageTracker::ImageDecodeFinished,
25 base::Unretained(this), callback)); 26 base::Unretained(this), callback));
26 } 27 }
27 28
28 void DecodedImageTracker::NotifyFrameFinished() { 29 void DecodedImageTracker::NotifyFrameFinished() {
29 // Go through the images and if the frame ref count goes to 0, unlock the 30 // Go through the images and if the frame ref count goes to 0, unlock the
30 // image in the controller. 31 // image in the controller.
31 for (auto it = locked_images_.begin(); it != locked_images_.end();) { 32 for (auto it = locked_images_.begin(); it != locked_images_.end();) {
32 auto id = it->first; 33 auto id = it->first;
33 int& ref_count = it->second; 34 int& ref_count = it->second;
34 if (--ref_count != 0) { 35 if (--ref_count != 0) {
35 ++it; 36 ++it;
36 continue; 37 continue;
37 } 38 }
38 image_controller_->UnlockImageDecode(id); 39 image_controller_->UnlockImageDecode(id);
39 it = locked_images_.erase(it); 40 it = locked_images_.erase(it);
40 } 41 }
41 } 42 }
42 43
43 void DecodedImageTracker::ImageDecodeFinished( 44 void DecodedImageTracker::ImageDecodeFinished(
44 const base::Closure& callback, 45 const base::Callback<void(bool)>& callback,
45 ImageController::ImageDecodeRequestId id) { 46 ImageController::ImageDecodeRequestId id,
46 locked_images_.push_back(std::make_pair(id, kNumFramesToLock)); 47 ImageController::ImageDecodeResult result) {
47 callback.Run(); 48 if (result == ImageController::ImageDecodeResult::SUCCESS)
49 locked_images_.push_back(std::make_pair(id, kNumFramesToLock));
50 bool decode_succeeded =
51 result == ImageController::ImageDecodeResult::SUCCESS ||
52 result == ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED;
53 callback.Run(decode_succeeded);
48 } 54 }
49 55
50 } // namespace cc 56 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/decoded_image_tracker.h ('k') | cc/tiles/decoded_image_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698