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 // This class retains the release_callback_ of the CopyOutputResult that is | |
12 // being sent over mojo. A TextureMailboxReleaserPtr that talks to this impl | |
13 // object will be sent over mojo instead of the release_callback_ (which is not | |
14 // serializable). Once the client calls Release, the release_callback_ will be | |
15 // called. An object of this class will remain alive until the MessagePipe | |
16 // attached to it goes away (i.e. StrongBinding is used). | |
17 class TextureMailboxReleaserImpl : public cc::mojom::TextureMailboxReleaser { | |
18 public: | |
19 TextureMailboxReleaserImpl( | |
20 std::unique_ptr<cc::SingleReleaseCallback> release_callback) | |
21 : release_callback_(std::move(release_callback)) { | |
22 DCHECK(release_callback_); | |
23 } | |
24 | |
25 ~TextureMailboxReleaserImpl() override { | |
26 // If the client fails to call Release, we should do it ourselves because | |
danakj
2017/02/13 20:50:16
This should be a DCHECK instead I think, the same
Saman Sami
2017/02/13 21:03:01
I'm not sure we want the display compositor to cra
danakj
2017/02/13 22:43:17
Oh this is on the other process, okay. Ya I agree.
| |
27 // release_callback_ will fail if it's never called. | |
28 if (release_callback_) | |
29 release_callback_->Run(gpu::SyncToken(), true); | |
30 } | |
31 | |
32 // mojom::TextureMailboxReleaser implementation: | |
33 void Release(const gpu::SyncToken& sync_token, bool is_lost) override { | |
34 DCHECK(release_callback_) | |
danakj
2017/02/13 20:50:16
The SingleReleaseCallback already does this why do
Saman Sami
2017/02/13 21:03:01
SingleReleaseCallback doesn't do anything because
danakj
2017/02/13 22:43:17
Oh I was thinking if the reset() isnt there, but y
Saman Sami
2017/02/13 23:23:43
That's right. I'll get rid of the DCHECK.
| |
35 << "TextureMailboxReleaser::Release cannot be called twice"; | |
36 release_callback_->Run(sync_token, is_lost); | |
37 release_callback_.reset(); | |
38 } | |
39 | |
40 private: | |
41 std::unique_ptr<cc::SingleReleaseCallback> release_callback_; | |
42 }; | |
43 | |
44 void Release(cc::mojom::TextureMailboxReleaserPtr ptr, | |
45 const gpu::SyncToken& sync_token, | |
46 bool is_lost) { | |
47 ptr->Release(sync_token, is_lost); | |
48 } | |
49 | |
50 } // namespace | |
51 | |
7 namespace mojo { | 52 namespace mojo { |
8 | 53 |
9 // static | 54 // static |
55 const SkBitmap& StructTraits<cc::mojom::CopyOutputResultDataView, | |
56 std::unique_ptr<cc::CopyOutputResult>>:: | |
57 bitmap(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
58 static SkBitmap* null_bitmap = new SkBitmap(); | |
59 if (!result->bitmap_) | |
60 return *null_bitmap; | |
61 return *result->bitmap_; | |
62 } | |
63 | |
64 // static | |
65 cc::mojom::TextureMailboxReleaserPtr | |
66 StructTraits<cc::mojom::CopyOutputResultDataView, | |
67 std::unique_ptr<cc::CopyOutputResult>>:: | |
68 releaser(const std::unique_ptr<cc::CopyOutputResult>& result) { | |
69 if (!result->release_callback_) | |
70 return {}; | |
71 cc::mojom::TextureMailboxReleaserPtr releaser; | |
72 auto impl = base::MakeUnique<TextureMailboxReleaserImpl>( | |
73 std::move(result->release_callback_)); | |
74 MakeStrongBinding(std::move(impl), MakeRequest(&releaser)); | |
75 return releaser; | |
76 } | |
77 | |
78 // static | |
10 bool StructTraits<cc::mojom::CopyOutputResultDataView, | 79 bool StructTraits<cc::mojom::CopyOutputResultDataView, |
11 std::unique_ptr<cc::CopyOutputResult>>:: | 80 std::unique_ptr<cc::CopyOutputResult>>:: |
12 Read(cc::mojom::CopyOutputResultDataView data, | 81 Read(cc::mojom::CopyOutputResultDataView data, |
13 std::unique_ptr<cc::CopyOutputResult>* out_p) { | 82 std::unique_ptr<cc::CopyOutputResult>* out_p) { |
14 auto result = cc::CopyOutputResult::CreateEmptyResult(); | 83 auto result = cc::CopyOutputResult::CreateEmptyResult(); |
15 | 84 |
16 if (!data.ReadSize(&result->size_)) | 85 if (!data.ReadSize(&result->size_)) |
17 return false; | 86 return false; |
18 | 87 |
19 result->bitmap_ = base::MakeUnique<SkBitmap>(); | 88 result->bitmap_ = base::MakeUnique<SkBitmap>(); |
20 if (!data.ReadBitmap(result->bitmap_.get())) | 89 if (!data.ReadBitmap(result->bitmap_.get())) |
21 return false; | 90 return false; |
22 | 91 |
23 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) | 92 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) |
24 return false; | 93 return false; |
25 | 94 |
95 auto releaser = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>(); | |
96 if (releaser) { | |
97 // CopyOutputResult does not have a TextureMailboxReleaserPtr member. | |
98 // We use base::Bind to turn TextureMailboxReleaser::Release into a | |
99 // ReleaseCallback. | |
100 result->release_callback_ = cc::SingleReleaseCallback::Create( | |
101 base::Bind(Release, base::Passed(&releaser))); | |
102 } | |
103 | |
104 // Check that release callback and texture mailbox are set together. | |
105 if (!!result->release_callback_ != result->texture_mailbox_.IsValid()) | |
danakj
2017/02/13 20:50:16
you could just if (!releaser) return false above r
Saman Sami
2017/02/13 21:03:01
What if the result is bitmap?
danakj
2017/02/13 22:43:17
Oh ya ok. This is a nit, but I think it'd maybe be
Saman Sami
2017/02/13 23:23:43
Added the check for both bitmap and texture.
| |
106 return false; | |
107 | |
26 *out_p = std::move(result); | 108 *out_p = std::move(result); |
27 | 109 |
28 return true; | 110 return true; |
29 } | 111 } |
30 | 112 |
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 | 113 } // namespace mojo |
OLD | NEW |