Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/ipc/copy_output_result_struct_traits.h" | 5 #include "cc/ipc/copy_output_result_struct_traits.h" |
| 6 | 6 |
| 7 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 class TextureMailboxReleaserImpl : public cc::mojom::TextureMailboxReleaser { | |
| 12 public: | |
| 13 TextureMailboxReleaserImpl( | |
| 14 std::unique_ptr<cc::SingleReleaseCallback> release_callback) | |
| 15 : release_callback_(std::move(release_callback)) {} | |
| 16 | |
| 17 // mojom::TextureMailboxReleaser implementation: | |
| 18 void Release(const gpu::SyncToken& sync_token, bool is_lost) override { | |
| 19 release_callback_->Run(sync_token, is_lost); | |
| 20 } | |
| 21 | |
| 22 private: | |
| 23 std::unique_ptr<cc::SingleReleaseCallback> release_callback_; | |
| 24 }; | |
| 25 | |
| 26 void Release(cc::mojom::TextureMailboxReleaserPtr ptr, | |
| 27 const gpu::SyncToken& sync_token, | |
| 28 bool is_lost) { | |
| 29 ptr->Release(sync_token, is_lost); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 7 namespace mojo { | 34 namespace mojo { |
| 8 | 35 |
| 9 // static | 36 // static |
| 37 const SkBitmap& StructTraits<cc::mojom::CopyOutputResultDataView, | |
| 38 std::unique_ptr<cc::CopyOutputResult>>:: | |
| 39 bitmap(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
| 40 static SkBitmap* null_bitmap = new SkBitmap(); | |
| 41 if (!result->bitmap_) | |
| 42 return *null_bitmap; | |
| 43 return *result->bitmap_; | |
| 44 } | |
| 45 | |
| 46 // static | |
| 47 cc::TextureMailboxWithRelease | |
| 48 StructTraits<cc::mojom::CopyOutputResultDataView, | |
| 49 std::unique_ptr<cc::CopyOutputResult>>:: | |
| 50 texture_mailbox(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
| 51 cc::mojom::TextureMailboxReleaserPtr releaser; | |
| 52 if (result->release_callback_) { | |
| 53 auto impl = base::MakeUnique<TextureMailboxReleaserImpl>( | |
| 54 std::move(result->release_callback_)); | |
| 55 MakeStrongBinding(std::move(impl), MakeRequest(&releaser)); | |
| 56 } | |
| 57 return cc::TextureMailboxWithRelease{result->texture_mailbox_, releaser}; | |
| 58 } | |
| 59 | |
| 60 /* | |
|
danakj
2017/02/13 18:41:04
this would be deleted
| |
| 61 // static | |
| 62 cc::mojom::TextureMailboxReleaserPtr | |
| 63 StructTraits<cc::mojom::CopyOutputResultDataView, | |
| 64 std::unique_ptr<cc::CopyOutputResult>>:: | |
| 65 releaser(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
| 66 if (!result->release_callback_) | |
| 67 return {}; | |
| 68 cc::mojom::TextureMailboxReleaserPtr releaser; | |
| 69 auto impl = base::MakeUnique<TextureMailboxReleaserImpl>( | |
| 70 std::move(result->release_callback_)); | |
| 71 MakeStrongBinding(std::move(impl), MakeRequest(&releaser)); | |
| 72 return releaser; | |
| 73 } | |
| 74 */ | |
| 75 | |
| 76 // static | |
| 10 bool StructTraits<cc::mojom::CopyOutputResultDataView, | 77 bool StructTraits<cc::mojom::CopyOutputResultDataView, |
| 11 std::unique_ptr<cc::CopyOutputResult>>:: | 78 std::unique_ptr<cc::CopyOutputResult>>:: |
| 12 Read(cc::mojom::CopyOutputResultDataView data, | 79 Read(cc::mojom::CopyOutputResultDataView data, |
| 13 std::unique_ptr<cc::CopyOutputResult>* out_p) { | 80 std::unique_ptr<cc::CopyOutputResult>* out_p) { |
| 14 auto result = cc::CopyOutputResult::CreateEmptyResult(); | 81 auto result = cc::CopyOutputResult::CreateEmptyResult(); |
| 15 | 82 |
| 16 if (!data.ReadSize(&result->size_)) | 83 if (!data.ReadSize(&result->size_)) |
| 17 return false; | 84 return false; |
| 18 | 85 |
| 19 result->bitmap_ = base::MakeUnique<SkBitmap>(); | 86 result->bitmap_ = base::MakeUnique<SkBitmap>(); |
| 20 if (!data.ReadBitmap(result->bitmap_.get())) | 87 if (!data.ReadBitmap(result->bitmap_.get())) |
| 21 return false; | 88 return false; |
| 22 | 89 |
| 23 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) | 90 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) |
| 24 return false; | 91 return false; |
| 25 | 92 |
| 93 auto releaser = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>(); | |
|
danakj
2017/02/13 18:41:05
This won't work right? It should be using the Read
| |
| 94 if (releaser) { | |
| 95 result->release_callback_ = cc::SingleReleaseCallback::Create( | |
| 96 base::Bind(Release, base::Passed(&releaser))); | |
| 97 } | |
| 98 | |
| 26 *out_p = std::move(result); | 99 *out_p = std::move(result); |
| 27 | 100 |
| 28 return true; | 101 return true; |
| 29 } | 102 } |
| 30 | 103 |
| 31 // static | 104 // static |
| 32 const SkBitmap& StructTraits<cc::mojom::CopyOutputResultDataView, | 105 bool StructTraits<cc::mojom::TextureMailboxWithReleaseDataView, |
| 33 std::unique_ptr<cc::CopyOutputResult>>:: | 106 std::unique_ptr<cc::TextureMailboxWithRelease>>:: |
| 34 bitmap(const std::unique_ptr<cc::CopyOutputResult>& result) { | 107 Read(cc::mojom::TextureMailboxWithReleaseDataView data, |
| 35 static SkBitmap* null_bitmap = new SkBitmap(); | 108 cc::TextureMailboxWithRelease* out_p) { |
| 36 if (!result->bitmap_) | 109 *out_p = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>(); |
| 37 return *null_bitmap; | 110 return *data.ReadTextureMailbox(&out.texture_mailbox); |
| 38 return *result->bitmap_; | |
| 39 } | 111 } |
| 40 | 112 |
| 41 } // namespace mojo | 113 } // namespace mojo |
| OLD | NEW |