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 { | |
Fady Samuel
2017/02/11 16:36:57
nit: Please add a comment about where this code ru
| |
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, | |
Fady Samuel
2017/02/11 16:36:57
nit: Please a comment about where this is used: in
| |
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::mojom::TextureMailboxReleaserPtr | |
48 StructTraits<cc::mojom::CopyOutputResultDataView, | |
49 std::unique_ptr<cc::CopyOutputResult>>:: | |
50 releaser(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
51 if (!result->release_callback_) | |
52 return {}; | |
53 cc::mojom::TextureMailboxReleaserPtr releaser; | |
54 auto impl = base::MakeUnique<TextureMailboxReleaserImpl>( | |
55 std::move(result->release_callback_)); | |
56 MakeStrongBinding(std::move(impl), MakeRequest(&releaser)); | |
57 return releaser; | |
58 } | |
59 | |
60 // static | |
10 bool StructTraits<cc::mojom::CopyOutputResultDataView, | 61 bool StructTraits<cc::mojom::CopyOutputResultDataView, |
11 std::unique_ptr<cc::CopyOutputResult>>:: | 62 std::unique_ptr<cc::CopyOutputResult>>:: |
12 Read(cc::mojom::CopyOutputResultDataView data, | 63 Read(cc::mojom::CopyOutputResultDataView data, |
13 std::unique_ptr<cc::CopyOutputResult>* out_p) { | 64 std::unique_ptr<cc::CopyOutputResult>* out_p) { |
14 auto result = cc::CopyOutputResult::CreateEmptyResult(); | 65 auto result = cc::CopyOutputResult::CreateEmptyResult(); |
15 | 66 |
16 if (!data.ReadSize(&result->size_)) | 67 if (!data.ReadSize(&result->size_)) |
17 return false; | 68 return false; |
18 | 69 |
19 result->bitmap_ = base::MakeUnique<SkBitmap>(); | 70 result->bitmap_ = base::MakeUnique<SkBitmap>(); |
20 if (!data.ReadBitmap(result->bitmap_.get())) | 71 if (!data.ReadBitmap(result->bitmap_.get())) |
21 return false; | 72 return false; |
22 | 73 |
23 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) | 74 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) |
24 return false; | 75 return false; |
25 | 76 |
77 auto releaser = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>(); | |
78 if (releaser) { | |
79 result->release_callback_ = cc::SingleReleaseCallback::Create( | |
80 base::Bind(Release, base::Passed(&releaser))); | |
81 } | |
82 | |
26 *out_p = std::move(result); | 83 *out_p = std::move(result); |
27 | 84 |
28 return true; | 85 return true; |
29 } | 86 } |
30 | 87 |
31 // static | |
32 const SkBitmap& StructTraits<cc::mojom::CopyOutputResultDataView, | |
33 std::unique_ptr<cc::CopyOutputResult>>:: | |
34 bitmap(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
35 static SkBitmap* null_bitmap = new SkBitmap(); | |
36 if (!result->bitmap_) | |
37 return *null_bitmap; | |
38 return *result->bitmap_; | |
39 } | |
40 | |
41 } // namespace mojo | 88 } // namespace mojo |
OLD | NEW |