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_request_struct_traits.h" | 5 #include "cc/ipc/copy_output_request_struct_traits.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | |
8 #include "mojo/public/cpp/bindings/strong_binding.h" | |
9 | |
10 namespace { | |
11 | |
12 // When we're sending a CopyOutputRequest, we keep the result_callback_ in a | |
13 // CopyOutputResultSenderImpl and send a CopyOutputResultSenderPtr to the other | |
14 // process. When SendResult is called, we run the stored result_callback_. | |
15 class CopyOutputResultSenderImpl : public cc::mojom::CopyOutputResultSender { | |
16 public: | |
17 CopyOutputResultSenderImpl( | |
18 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) | |
19 : result_callback_(result_callback) { | |
20 DCHECK(result_callback_); | |
21 } | |
22 | |
23 ~CopyOutputResultSenderImpl() override { | |
24 if (result_callback_) | |
25 result_callback_.Run(cc::CopyOutputResult::CreateEmptyResult()); | |
26 } | |
27 | |
28 // mojom::TextureMailboxReleaser implementation: | |
29 void SendResult(std::unique_ptr<cc::CopyOutputResult> result) override { | |
30 if (!result_callback_) | |
31 return; | |
32 base::ResetAndReturn(&result_callback_).Run(std::move(result)); | |
33 } | |
34 | |
35 private: | |
36 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback_; | |
37 }; | |
38 | |
39 void SendResult(cc::mojom::CopyOutputResultSenderPtr ptr, | |
40 std::unique_ptr<cc::CopyOutputResult> result) { | |
41 ptr->SendResult(std::move(result)); | |
42 } | |
43 | |
44 } // namespace | |
45 | |
7 namespace mojo { | 46 namespace mojo { |
8 | 47 |
9 // static | 48 // static |
49 cc::mojom::CopyOutputResultSenderPtr | |
50 StructTraits<cc::mojom::CopyOutputRequestDataView, | |
51 std::unique_ptr<cc::CopyOutputRequest>>:: | |
52 result_sender(const std::unique_ptr<cc::CopyOutputRequest>& request) { | |
53 cc::mojom::CopyOutputResultSenderPtr result_sender; | |
54 if (request->result_callback_) { | |
danakj
2017/02/15 19:48:19
This one shouldn't be needed. As you said cc::Copy
danakj
2017/02/15 19:50:26
Oh. Uh, I guess there is CreateEmptyRequest() whic
Saman Sami
2017/02/15 22:34:21
Right. We won't support empty requests.
| |
55 auto impl = base::MakeUnique<CopyOutputResultSenderImpl>( | |
56 std::move(request->result_callback_)); | |
57 MakeStrongBinding(std::move(impl), MakeRequest(&result_sender)); | |
58 } | |
59 return result_sender; | |
60 } | |
61 | |
62 // static | |
10 bool StructTraits<cc::mojom::CopyOutputRequestDataView, | 63 bool StructTraits<cc::mojom::CopyOutputRequestDataView, |
11 std::unique_ptr<cc::CopyOutputRequest>>:: | 64 std::unique_ptr<cc::CopyOutputRequest>>:: |
12 Read(cc::mojom::CopyOutputRequestDataView data, | 65 Read(cc::mojom::CopyOutputRequestDataView data, |
13 std::unique_ptr<cc::CopyOutputRequest>* out_p) { | 66 std::unique_ptr<cc::CopyOutputRequest>* out_p) { |
14 auto request = cc::CopyOutputRequest::CreateEmptyRequest(); | 67 auto request = cc::CopyOutputRequest::CreateEmptyRequest(); |
15 | 68 |
16 request->force_bitmap_result_ = data.force_bitmap_result(); | 69 request->force_bitmap_result_ = data.force_bitmap_result(); |
17 | 70 |
18 if (!data.ReadSource(&request->source_)) | 71 if (!data.ReadSource(&request->source_)) |
19 return false; | 72 return false; |
20 | 73 |
21 if (!data.ReadArea(&request->area_)) | 74 if (!data.ReadArea(&request->area_)) |
22 return false; | 75 return false; |
23 | 76 |
24 if (!data.ReadTextureMailbox(&request->texture_mailbox_)) | 77 if (!data.ReadTextureMailbox(&request->texture_mailbox_)) |
25 return false; | 78 return false; |
26 | 79 |
80 auto result_sender = | |
81 data.TakeResultSender<cc::mojom::CopyOutputResultSenderPtr>(); | |
82 if (result_sender) { | |
83 request->result_callback_ = | |
84 base::Bind(SendResult, base::Passed(&result_sender)); | |
85 } | |
86 | |
27 *out_p = std::move(request); | 87 *out_p = std::move(request); |
28 | 88 |
29 return true; | 89 return true; |
30 } | 90 } |
31 | 91 |
32 } // namespace mojo | 92 } // namespace mojo |
OLD | NEW |