fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CC_IPC_TRANSFERABLE_RESOURCE_STRUCT_TRAITS_H_ |
| 6 | #define CC_IPC_TRANSFERABLE_RESOURCE_STRUCT_TRAITS_H_ |
| 7 | |
xlai | 8f40538 | 2016-09-01 19:46:22 | [diff] [blame] | 8 | #include "cc/ipc/transferable_resource.mojom-shared.h" |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 9 | #include "cc/resources/transferable_resource.h" |
hubbe | ce990b1 | 2017-04-18 22:53:32 | [diff] [blame] | 10 | #include "ui/gfx/ipc/color/gfx_param_traits.h" |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 11 | |
| 12 | namespace mojo { |
| 13 | |
| 14 | template <> |
yzshen | 1764bb9 | 2016-08-24 01:44:12 | [diff] [blame] | 15 | struct StructTraits<cc::mojom::TransferableResourceDataView, |
| 16 | cc::TransferableResource> { |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 17 | static uint32_t id(const cc::TransferableResource& resource) { |
| 18 | return resource.id; |
| 19 | } |
| 20 | |
| 21 | static cc::mojom::ResourceFormat format( |
| 22 | const cc::TransferableResource& resource) { |
| 23 | return static_cast<cc::mojom::ResourceFormat>(resource.format); |
| 24 | } |
| 25 | |
dcastagna | 8409354 | 2017-03-14 02:11:13 | [diff] [blame] | 26 | static gfx::mojom::BufferFormat buffer_format( |
| 27 | const cc::TransferableResource& resource) { |
| 28 | return static_cast<gfx::mojom::BufferFormat>(resource.buffer_format); |
| 29 | } |
| 30 | |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 31 | static uint32_t filter(const cc::TransferableResource& resource) { |
| 32 | return resource.filter; |
| 33 | } |
| 34 | |
| 35 | static gfx::Size size(const cc::TransferableResource& resource) { |
| 36 | return resource.size; |
| 37 | } |
| 38 | |
fsamuel | 605998f | 2016-06-08 20:22:38 | [diff] [blame] | 39 | static const gpu::MailboxHolder& mailbox_holder( |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 40 | const cc::TransferableResource& resource) { |
| 41 | return resource.mailbox_holder; |
| 42 | } |
| 43 | |
| 44 | static bool read_lock_fences_enabled( |
| 45 | const cc::TransferableResource& resource) { |
| 46 | return resource.read_lock_fences_enabled; |
| 47 | } |
| 48 | |
| 49 | static bool is_software(const cc::TransferableResource& resource) { |
| 50 | return resource.is_software; |
| 51 | } |
| 52 | |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 53 | static bool is_overlay_candidate(const cc::TransferableResource& resource) { |
| 54 | return resource.is_overlay_candidate; |
| 55 | } |
| 56 | |
liberato | 304dc19 | 2016-12-09 20:55:26 | [diff] [blame] | 57 | static bool is_backed_by_surface_texture( |
| 58 | const cc::TransferableResource& resource) { |
| 59 | #if defined(OS_ANDROID) |
| 60 | // TransferableResource has this in an #ifdef, but mojo doesn't let us. |
| 61 | // TODO(https://crbug.com/671901) |
| 62 | return resource.is_backed_by_surface_texture; |
| 63 | #else |
| 64 | return false; |
| 65 | #endif |
| 66 | } |
| 67 | |
| 68 | static bool wants_promotion_hint(const cc::TransferableResource& resource) { |
| 69 | #if defined(OS_ANDROID) |
| 70 | // TransferableResource has this in an #ifdef, but mojo doesn't let us. |
| 71 | // TODO(https://crbug.com/671901) |
| 72 | return resource.wants_promotion_hint; |
| 73 | #else |
| 74 | return false; |
| 75 | #endif |
| 76 | } |
| 77 | |
hubbe | ce990b1 | 2017-04-18 22:53:32 | [diff] [blame] | 78 | static const gfx::ColorSpace& color_space( |
| 79 | const cc::TransferableResource& resource) { |
| 80 | return resource.color_space; |
| 81 | } |
| 82 | |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 83 | static bool Read(cc::mojom::TransferableResourceDataView data, |
fsamuel | ce098fb | 2016-06-27 16:43:06 | [diff] [blame] | 84 | cc::TransferableResource* out); |
fsamuel | 6ee49c4 | 2016-06-01 11:16:55 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace mojo |
| 88 | |
| 89 | #endif // CC_IPC_TRANSFERABLE_RESOURCE_STRUCT_TRAITS_H_ |