Chromium Code Reviews| Index: cc/resources/single_release_callback.h |
| diff --git a/cc/resources/single_release_callback.h b/cc/resources/single_release_callback.h |
| index cfb2330a4c2a436756760bb0a46bf08b170ce5c8..d1a604f0547587be7ea4b0a3ea590c5487df9aeb 100644 |
| --- a/cc/resources/single_release_callback.h |
| +++ b/cc/resources/single_release_callback.h |
| @@ -10,24 +10,68 @@ |
| #include "base/memory/ptr_util.h" |
| #include "cc/base/cc_export.h" |
| #include "cc/resources/release_callback.h" |
| +#include "mojo/public/cpp/bindings/struct_traits.h" |
| + |
| +namespace mojo { |
| +template <class T> |
| +class InterfacePtr; |
| +} |
| namespace cc { |
| +namespace mojom { |
| +class SingleReleaseCallbackDataView; |
| +class TextureMailboxReleaser; |
| +typedef mojo::InterfacePtr<TextureMailboxReleaser> TextureMailboxReleaserPtr; |
| +} |
| + |
| class CC_EXPORT SingleReleaseCallback { |
| + class PtrHolder { |
| + public: |
| + virtual mojom::TextureMailboxReleaserPtr TakePtr() = 0; |
| + virtual void Release(const gpu::SyncToken& sync_token, bool is_lost) = 0; |
| + }; |
| + |
| + template <class T> |
| + 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
|
| + public: |
| + explicit PtrHolderImpl(T ptr) : ptr_(std::move(ptr)) {} |
| + T TakePtr() { return std::move(ptr_); } |
| + void Release(const gpu::SyncToken& sync_token, bool is_lost) override { |
| + return ptr_->Release(sync_token, is_lost); |
| + } |
| + |
| + private: |
| + T ptr_; |
| + }; |
| + |
| public: |
| static std::unique_ptr<SingleReleaseCallback> Create( |
| const ReleaseCallback& cb) { |
| return base::WrapUnique(new SingleReleaseCallback(cb)); |
| } |
| + 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
|
| + static std::unique_ptr<SingleReleaseCallback> Create(T ptr) { |
| + auto ptr_holder = base::MakeUnique<PtrHolderImpl<T>>(std::move(ptr)); |
| + return base::WrapUnique(new SingleReleaseCallback(std::move(ptr_holder))); |
| + } |
| + |
| ~SingleReleaseCallback(); |
| void Run(const gpu::SyncToken& sync_token, bool is_lost); |
| private: |
| + friend struct mojo::StructTraits<mojom::SingleReleaseCallbackDataView, |
| + std::unique_ptr<SingleReleaseCallback>>; |
| + |
| explicit SingleReleaseCallback(const ReleaseCallback& callback); |
| + explicit SingleReleaseCallback(std::unique_ptr<PtrHolder> ptr_holder); |
| ReleaseCallback callback_; |
| + std::unique_ptr<PtrHolder> ptr_holder_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(SingleReleaseCallback); |
| }; |
| } // namespace cc |