| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/run_loop.h" | |
| 7 #include "cc/ipc/traits_test_service.mojom.h" | 6 #include "cc/ipc/traits_test_service.mojom.h" |
| 8 #include "cc/quads/render_pass_id.h" | 7 #include "cc/quads/render_pass_id.h" |
| 9 #include "mojo/public/cpp/bindings/binding_set.h" | 8 #include "mojo/public/cpp/bindings/binding_set.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 10 |
| 12 namespace cc { | 11 namespace cc { |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { | 15 class StructTraitsTest : public testing::Test, public mojom::TraitsTestService { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 45 callback.Run(s); | 44 callback.Run(s); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void EchoTransferableResource( | 47 void EchoTransferableResource( |
| 49 const TransferableResource& t, | 48 const TransferableResource& t, |
| 50 const EchoTransferableResourceCallback& callback) override { | 49 const EchoTransferableResourceCallback& callback) override { |
| 51 callback.Run(t); | 50 callback.Run(t); |
| 52 } | 51 } |
| 53 | 52 |
| 54 mojo::BindingSet<TraitsTestService> traits_test_bindings_; | 53 mojo::BindingSet<TraitsTestService> traits_test_bindings_; |
| 54 DISALLOW_COPY_AND_ASSIGN(StructTraitsTest); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 TEST_F(StructTraitsTest, BeginFrameArgs) { | 59 TEST_F(StructTraitsTest, BeginFrameArgs) { |
| 60 const base::TimeTicks frame_time = base::TimeTicks::Now(); | 60 const base::TimeTicks frame_time = base::TimeTicks::Now(); |
| 61 const base::TimeTicks deadline = base::TimeTicks::Now(); | 61 const base::TimeTicks deadline = base::TimeTicks::Now(); |
| 62 const base::TimeDelta interval = base::TimeDelta::FromMilliseconds(1337); | 62 const base::TimeDelta interval = base::TimeDelta::FromMilliseconds(1337); |
| 63 const BeginFrameArgs::BeginFrameArgsType type = BeginFrameArgs::NORMAL; | 63 const BeginFrameArgs::BeginFrameArgsType type = BeginFrameArgs::NORMAL; |
| 64 const bool on_critical_path = true; | 64 const bool on_critical_path = true; |
| 65 BeginFrameArgs input; | 65 BeginFrameArgs input; |
| 66 input.frame_time = frame_time; | 66 input.frame_time = frame_time; |
| 67 input.deadline = deadline; | 67 input.deadline = deadline; |
| 68 input.interval = interval; | 68 input.interval = interval; |
| 69 input.type = type; | 69 input.type = type; |
| 70 input.on_critical_path = on_critical_path; | 70 input.on_critical_path = on_critical_path; |
| 71 base::RunLoop loop; | |
| 72 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 71 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 73 proxy->EchoBeginFrameArgs( | 72 BeginFrameArgs output; |
| 74 input, [frame_time, deadline, interval, type, on_critical_path, | 73 proxy->EchoBeginFrameArgs(input, &output); |
| 75 &loop](const BeginFrameArgs& pass) { | 74 EXPECT_EQ(frame_time, output.frame_time); |
| 76 EXPECT_EQ(frame_time, pass.frame_time); | 75 EXPECT_EQ(deadline, output.deadline); |
| 77 EXPECT_EQ(deadline, pass.deadline); | 76 EXPECT_EQ(interval, output.interval); |
| 78 EXPECT_EQ(interval, pass.interval); | 77 EXPECT_EQ(type, output.type); |
| 79 EXPECT_EQ(type, pass.type); | 78 EXPECT_EQ(on_critical_path, output.on_critical_path); |
| 80 EXPECT_EQ(on_critical_path, pass.on_critical_path); | |
| 81 loop.Quit(); | |
| 82 }); | |
| 83 loop.Run(); | |
| 84 } | 79 } |
| 85 | 80 |
| 86 TEST_F(StructTraitsTest, RenderPassId) { | 81 TEST_F(StructTraitsTest, RenderPassId) { |
| 87 const int layer_id = 1337; | 82 const int layer_id = 1337; |
| 88 const uint32_t index = 0xdeadbeef; | 83 const uint32_t index = 0xdeadbeef; |
| 89 RenderPassId input(layer_id, index); | 84 RenderPassId input(layer_id, index); |
| 90 base::RunLoop loop; | |
| 91 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 85 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 92 proxy->EchoRenderPassId(input, | 86 RenderPassId output; |
| 93 [layer_id, index, &loop](const RenderPassId& pass) { | 87 proxy->EchoRenderPassId(input, &output); |
| 94 EXPECT_EQ(layer_id, pass.layer_id); | 88 EXPECT_EQ(layer_id, output.layer_id); |
| 95 EXPECT_EQ(index, pass.index); | 89 EXPECT_EQ(index, output.index); |
| 96 loop.Quit(); | |
| 97 }); | |
| 98 loop.Run(); | |
| 99 } | 90 } |
| 100 | 91 |
| 101 TEST_F(StructTraitsTest, ReturnedResource) { | 92 TEST_F(StructTraitsTest, ReturnedResource) { |
| 102 const uint32_t id = 1337; | 93 const uint32_t id = 1337; |
| 103 const gpu::CommandBufferNamespace command_buffer_namespace = gpu::IN_PROCESS; | 94 const gpu::CommandBufferNamespace command_buffer_namespace = gpu::IN_PROCESS; |
| 104 const int32_t extra_data_field = 0xbeefbeef; | 95 const int32_t extra_data_field = 0xbeefbeef; |
| 105 const gpu::CommandBufferId command_buffer_id( | 96 const gpu::CommandBufferId command_buffer_id( |
| 106 gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef)); | 97 gpu::CommandBufferId::FromUnsafeValue(0xdeadbeef)); |
| 107 const uint64_t release_count = 0xdeadbeefdead; | 98 const uint64_t release_count = 0xdeadbeefdead; |
| 108 const gpu::SyncToken sync_token(command_buffer_namespace, extra_data_field, | 99 const gpu::SyncToken sync_token(command_buffer_namespace, extra_data_field, |
| 109 command_buffer_id, release_count); | 100 command_buffer_id, release_count); |
| 110 const int count = 1234; | 101 const int count = 1234; |
| 111 const bool lost = true; | 102 const bool lost = true; |
| 112 | 103 |
| 113 ReturnedResource input; | 104 ReturnedResource input; |
| 114 input.id = id; | 105 input.id = id; |
| 115 input.sync_token = sync_token; | 106 input.sync_token = sync_token; |
| 116 input.count = count; | 107 input.count = count; |
| 117 input.lost = lost; | 108 input.lost = lost; |
| 118 base::RunLoop loop; | |
| 119 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 109 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 120 proxy->EchoReturnedResource(input, [id, sync_token, count, lost, | 110 ReturnedResource output; |
| 121 &loop](const ReturnedResource& pass) { | 111 proxy->EchoReturnedResource(input, &output); |
| 122 EXPECT_EQ(id, pass.id); | 112 EXPECT_EQ(id, output.id); |
| 123 EXPECT_EQ(sync_token, pass.sync_token); | 113 EXPECT_EQ(sync_token, output.sync_token); |
| 124 EXPECT_EQ(count, pass.count); | 114 EXPECT_EQ(count, output.count); |
| 125 EXPECT_EQ(lost, pass.lost); | 115 EXPECT_EQ(lost, output.lost); |
| 126 loop.Quit(); | |
| 127 }); | |
| 128 loop.Run(); | |
| 129 } | 116 } |
| 130 | 117 |
| 131 TEST_F(StructTraitsTest, SurfaceId) { | 118 TEST_F(StructTraitsTest, SurfaceId) { |
| 132 const uint32_t id_namespace = 1337; | 119 const uint32_t id_namespace = 1337; |
| 133 const uint32_t local_id = 0xfbadbeef; | 120 const uint32_t local_id = 0xfbadbeef; |
| 134 const uint64_t nonce = 0xdeadbeef; | 121 const uint64_t nonce = 0xdeadbeef; |
| 135 SurfaceId input(id_namespace, local_id, nonce); | 122 SurfaceId input(id_namespace, local_id, nonce); |
| 136 base::RunLoop loop; | |
| 137 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 123 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 138 proxy->EchoSurfaceId( | 124 SurfaceId output; |
| 139 input, [id_namespace, local_id, nonce, &loop](const SurfaceId& pass) { | 125 proxy->EchoSurfaceId(input, &output); |
| 140 EXPECT_EQ(id_namespace, pass.id_namespace()); | 126 EXPECT_EQ(id_namespace, output.id_namespace()); |
| 141 EXPECT_EQ(local_id, pass.local_id()); | 127 EXPECT_EQ(local_id, output.local_id()); |
| 142 EXPECT_EQ(nonce, pass.nonce()); | 128 EXPECT_EQ(nonce, output.nonce()); |
| 143 loop.Quit(); | |
| 144 }); | |
| 145 loop.Run(); | |
| 146 } | 129 } |
| 147 | 130 |
| 148 TEST_F(StructTraitsTest, TransferableResource) { | 131 TEST_F(StructTraitsTest, TransferableResource) { |
| 149 const uint32_t id = 1337; | 132 const uint32_t id = 1337; |
| 150 const ResourceFormat format = ALPHA_8; | 133 const ResourceFormat format = ALPHA_8; |
| 151 const uint32_t filter = 1234; | 134 const uint32_t filter = 1234; |
| 152 const gfx::Size size(1234, 5678); | 135 const gfx::Size size(1234, 5678); |
| 153 const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = { | 136 const int8_t mailbox_name[GL_MAILBOX_SIZE_CHROMIUM] = { |
| 154 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, | 137 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, |
| 155 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7, | 138 8, 7, 6, 5, 4, 3, 2, 1, 9, 7, 5, 3, 1, 2, 4, 6, 8, 0, 0, 9, 8, 7, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 174 TransferableResource input; | 157 TransferableResource input; |
| 175 input.id = id; | 158 input.id = id; |
| 176 input.format = format; | 159 input.format = format; |
| 177 input.filter = filter; | 160 input.filter = filter; |
| 178 input.size = size; | 161 input.size = size; |
| 179 input.mailbox_holder = mailbox_holder; | 162 input.mailbox_holder = mailbox_holder; |
| 180 input.read_lock_fences_enabled = read_lock_fences_enabled; | 163 input.read_lock_fences_enabled = read_lock_fences_enabled; |
| 181 input.is_software = is_software; | 164 input.is_software = is_software; |
| 182 input.gpu_memory_buffer_id.id = gpu_memory_buffer_id; | 165 input.gpu_memory_buffer_id.id = gpu_memory_buffer_id; |
| 183 input.is_overlay_candidate = is_overlay_candidate; | 166 input.is_overlay_candidate = is_overlay_candidate; |
| 184 base::RunLoop loop; | |
| 185 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); | 167 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); |
| 186 proxy->EchoTransferableResource( | 168 TransferableResource output; |
| 187 input, [id, format, filter, size, mailbox_holder, | 169 proxy->EchoTransferableResource(input, &output); |
| 188 read_lock_fences_enabled, is_software, gpu_memory_buffer_id, | 170 EXPECT_EQ(id, output.id); |
| 189 is_overlay_candidate, &loop](const TransferableResource& pass) { | 171 EXPECT_EQ(format, output.format); |
| 190 EXPECT_EQ(id, pass.id); | 172 EXPECT_EQ(filter, output.filter); |
| 191 EXPECT_EQ(format, pass.format); | 173 EXPECT_EQ(size, output.size); |
| 192 EXPECT_EQ(filter, pass.filter); | 174 EXPECT_EQ(mailbox_holder.mailbox, output.mailbox_holder.mailbox); |
| 193 EXPECT_EQ(size, pass.size); | 175 EXPECT_EQ(mailbox_holder.sync_token, output.mailbox_holder.sync_token); |
| 194 EXPECT_EQ(mailbox_holder.mailbox, pass.mailbox_holder.mailbox); | 176 EXPECT_EQ(mailbox_holder.texture_target, |
| 195 EXPECT_EQ(mailbox_holder.sync_token, pass.mailbox_holder.sync_token); | 177 output.mailbox_holder.texture_target); |
| 196 EXPECT_EQ(mailbox_holder.texture_target, | 178 EXPECT_EQ(read_lock_fences_enabled, output.read_lock_fences_enabled); |
| 197 pass.mailbox_holder.texture_target); | 179 EXPECT_EQ(is_software, output.is_software); |
| 198 EXPECT_EQ(read_lock_fences_enabled, pass.read_lock_fences_enabled); | 180 EXPECT_EQ(gpu_memory_buffer_id, output.gpu_memory_buffer_id.id); |
| 199 EXPECT_EQ(is_software, pass.is_software); | 181 EXPECT_EQ(is_overlay_candidate, output.is_overlay_candidate); |
| 200 EXPECT_EQ(gpu_memory_buffer_id, pass.gpu_memory_buffer_id.id); | |
| 201 EXPECT_EQ(is_overlay_candidate, pass.is_overlay_candidate); | |
| 202 loop.Quit(); | |
| 203 }); | |
| 204 loop.Run(); | |
| 205 } | 182 } |
| 206 | 183 |
| 207 } // namespace cc | 184 } // namespace cc |
| OLD | NEW |