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(); | |
danakj
2017/02/10 18:32:51
curious why do we need this, given that bitmap() i
Saman Sami
2017/02/10 19:10:07
SkBitmap is nullable (The struct traits has IsNull
danakj
2017/02/10 22:51:03
If there is IsNull() would this ever be called whe
danakj
2017/02/13 20:50:16
Still wondering this
Saman Sami
2017/02/13 21:03:01
Sorry I missed this one. I don't think IsNull repl
danakj
2017/02/13 22:43:17
Oh... it's rather unfortunate you have to deserial
Saman Sami
2017/02/13 23:23:43
This method doesn't do any deserialization. It jus
danakj
2017/02/14 17:49:10
I guess so, I just keep looking at this malloc :p
| |
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_) { | |
danakj
2017/02/10 18:32:51
Prefer early outs to if/else. Here:
if (!release
Saman Sami
2017/02/10 19:10:07
Done.
| |
52 cc::mojom::TextureMailboxReleaserPtr releaser; | |
53 auto impl = base::MakeUnique<TextureMailboxReleaserImpl>( | |
54 std::move(result->release_callback_)); | |
55 MakeStrongBinding(std::move(impl), MakeRequest(&releaser)); | |
56 return releaser; | |
57 } else { | |
58 return cc::mojom::TextureMailboxReleaserPtr(); | |
danakj
2017/02/10 18:32:51
nit: you could "return {};" here
Saman Sami
2017/02/10 19:10:07
Done.
| |
59 } | |
60 } | |
61 | |
62 // static | |
10 bool StructTraits<cc::mojom::CopyOutputResultDataView, | 63 bool StructTraits<cc::mojom::CopyOutputResultDataView, |
11 std::unique_ptr<cc::CopyOutputResult>>:: | 64 std::unique_ptr<cc::CopyOutputResult>>:: |
12 Read(cc::mojom::CopyOutputResultDataView data, | 65 Read(cc::mojom::CopyOutputResultDataView data, |
13 std::unique_ptr<cc::CopyOutputResult>* out_p) { | 66 std::unique_ptr<cc::CopyOutputResult>* out_p) { |
14 auto result = cc::CopyOutputResult::CreateEmptyResult(); | 67 auto result = cc::CopyOutputResult::CreateEmptyResult(); |
15 | 68 |
16 if (!data.ReadSize(&result->size_)) | 69 if (!data.ReadSize(&result->size_)) |
17 return false; | 70 return false; |
18 | 71 |
19 result->bitmap_ = base::MakeUnique<SkBitmap>(); | 72 result->bitmap_ = base::MakeUnique<SkBitmap>(); |
20 if (!data.ReadBitmap(result->bitmap_.get())) | 73 if (!data.ReadBitmap(result->bitmap_.get())) |
21 return false; | 74 return false; |
22 | 75 |
23 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) | 76 if (!data.ReadTextureMailbox(&result->texture_mailbox_)) |
24 return false; | 77 return false; |
25 | 78 |
79 auto releaser = data.TakeReleaser<cc::mojom::TextureMailboxReleaserPtr>(); | |
80 if (releaser) { | |
81 result->release_callback_ = cc::SingleReleaseCallback::Create( | |
82 base::Bind(Release, base::Passed(&releaser))); | |
danakj
2017/02/10 18:32:51
you can bind directly to TextureMailboxReleaserPtr
Saman Sami
2017/02/10 19:10:07
TextureMailboxReleaserPtr does not have a Release
danakj
2017/02/10 22:52:51
Ohh, wild. ok :)
| |
83 } | |
84 | |
26 *out_p = std::move(result); | 85 *out_p = std::move(result); |
27 | 86 |
28 return true; | 87 return true; |
29 } | 88 } |
30 | 89 |
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 | 90 } // namespace mojo |
OLD | NEW |