Chromium Code Reviews| 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 #ifndef CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ | 5 #ifndef CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ |
| 6 #define CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ | 6 #define CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/resources/release_callback.h" | 12 #include "cc/resources/release_callback.h" |
| 13 #include "mojo/public/cpp/bindings/struct_traits.h" | |
| 14 | |
| 15 namespace mojo { | |
| 16 template <class T> | |
| 17 class InterfacePtr; | |
| 18 } | |
| 13 | 19 |
| 14 namespace cc { | 20 namespace cc { |
| 15 | 21 |
| 22 namespace mojom { | |
| 23 class SingleReleaseCallbackDataView; | |
| 24 class TextureMailboxReleaser; | |
| 25 typedef mojo::InterfacePtr<TextureMailboxReleaser> TextureMailboxReleaserPtr; | |
| 26 } | |
| 27 | |
| 16 class CC_EXPORT SingleReleaseCallback { | 28 class CC_EXPORT SingleReleaseCallback { |
| 29 class PtrHolder { | |
| 30 public: | |
| 31 virtual mojom::TextureMailboxReleaserPtr TakePtr() = 0; | |
| 32 virtual void Release(const gpu::SyncToken& sync_token, bool is_lost) = 0; | |
| 33 }; | |
| 34 | |
| 35 template <class T> | |
| 36 class PtrHolderImpl : public PtrHolder { | |
|
danakj
2017/02/08 20:53:31
If this is implemented right here, I'm not sure wh
Saman Sami
2017/02/08 21:44:21
We use the virtuals because this template cannot b
danakj
2017/02/08 23:24:17
It's fine to have a test impl and a production imp
Saman Sami
2017/02/09 16:30:00
OK. I can avoid the template if having duplicate c
| |
| 37 public: | |
| 38 explicit PtrHolderImpl(T ptr) : ptr_(std::move(ptr)) {} | |
| 39 T TakePtr() { return std::move(ptr_); } | |
| 40 void Release(const gpu::SyncToken& sync_token, bool is_lost) override { | |
| 41 return ptr_->Release(sync_token, is_lost); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 T ptr_; | |
| 46 }; | |
| 47 | |
| 17 public: | 48 public: |
| 18 static std::unique_ptr<SingleReleaseCallback> Create( | 49 static std::unique_ptr<SingleReleaseCallback> Create( |
| 19 const ReleaseCallback& cb) { | 50 const ReleaseCallback& cb) { |
| 20 return base::WrapUnique(new SingleReleaseCallback(cb)); | 51 return base::WrapUnique(new SingleReleaseCallback(cb)); |
| 21 } | 52 } |
| 22 | 53 |
| 54 template <class T> | |
|
danakj
2017/02/08 20:53:31
Why template and not pass a unique_ptr<PtrHolder>?
Saman Sami
2017/02/08 21:44:21
I think this looks better and more intuitive than
| |
| 55 static std::unique_ptr<SingleReleaseCallback> Create(T ptr) { | |
| 56 auto ptr_holder = base::MakeUnique<PtrHolderImpl<T>>(std::move(ptr)); | |
| 57 return base::WrapUnique(new SingleReleaseCallback(std::move(ptr_holder))); | |
| 58 } | |
| 59 | |
| 23 ~SingleReleaseCallback(); | 60 ~SingleReleaseCallback(); |
| 24 | 61 |
| 25 void Run(const gpu::SyncToken& sync_token, bool is_lost); | 62 void Run(const gpu::SyncToken& sync_token, bool is_lost); |
| 26 | 63 |
| 27 private: | 64 private: |
| 65 friend struct mojo::StructTraits<mojom::SingleReleaseCallbackDataView, | |
| 66 std::unique_ptr<SingleReleaseCallback>>; | |
| 67 | |
| 28 explicit SingleReleaseCallback(const ReleaseCallback& callback); | 68 explicit SingleReleaseCallback(const ReleaseCallback& callback); |
| 69 explicit SingleReleaseCallback(std::unique_ptr<PtrHolder> ptr_holder); | |
| 29 | 70 |
| 30 ReleaseCallback callback_; | 71 ReleaseCallback callback_; |
| 72 std::unique_ptr<PtrHolder> ptr_holder_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(SingleReleaseCallback); | |
| 31 }; | 75 }; |
| 32 | 76 |
| 33 } // namespace cc | 77 } // namespace cc |
| 34 | 78 |
| 35 #endif // CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ | 79 #endif // CC_RESOURCES_SINGLE_RELEASE_CALLBACK_H_ |
| OLD | NEW |