OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/resources/single_release_callback.h" | 5 #include "cc/resources/single_release_callback.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
11 | 11 |
12 SingleReleaseCallback::SingleReleaseCallback(const ReleaseCallback& callback) | 12 SingleReleaseCallback::SingleReleaseCallback(const ReleaseCallback& callback) |
13 : callback_(callback) { | 13 : callback_(callback) { |
14 DCHECK(!callback_.is_null()) | 14 DCHECK(!callback_.is_null()) |
15 << "Use a NULL SingleReleaseCallback for an empty callback."; | 15 << "Use a NULL SingleReleaseCallback for an empty callback."; |
16 } | 16 } |
17 | 17 |
| 18 SingleReleaseCallback::SingleReleaseCallback( |
| 19 std::unique_ptr<PtrHolder> ptr_holder) |
| 20 : ptr_holder_(std::move(ptr_holder)) {} |
| 21 |
18 SingleReleaseCallback::~SingleReleaseCallback() { | 22 SingleReleaseCallback::~SingleReleaseCallback() { |
19 DCHECK(callback_.is_null()) << "SingleReleaseCallback was never run."; | 23 DCHECK(callback_.is_null()) << "SingleReleaseCallback was never run."; |
| 24 DCHECK(!ptr_holder_) << "SingleReleaseCallback was never run."; |
20 } | 25 } |
21 | 26 |
22 void SingleReleaseCallback::Run(const gpu::SyncToken& sync_token, | 27 void SingleReleaseCallback::Run(const gpu::SyncToken& sync_token, |
23 bool is_lost) { | 28 bool is_lost) { |
24 DCHECK(!callback_.is_null()) | 29 DCHECK(callback_ || ptr_holder_) |
25 << "SingleReleaseCallback was run more than once."; | 30 << "SingleReleaseCallback was run more than once."; |
26 base::ResetAndReturn(&callback_).Run(sync_token, is_lost); | 31 if (ptr_holder_) |
| 32 ptr_holder_->Release(sync_token, is_lost); |
| 33 else |
| 34 callback_.Run(sync_token, is_lost); |
| 35 ptr_holder_.reset(); |
| 36 callback_.Reset(); |
27 } | 37 } |
28 | 38 |
29 } // namespace cc | 39 } // namespace cc |
OLD | NEW |