Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: ui/gfx/mojo/struct_traits_unittest.cc

Issue 2534533002: gfx: Fix [de]serializing non-shm GpuMemoryBufferHandle. (Closed)
Patch Set: test Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/mojo/buffer_types_traits.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "mojo/public/cpp/bindings/binding_set.h" 6 #include "mojo/public/cpp/bindings/binding_set.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/mojo/traits_test_service.mojom.h" 8 #include "ui/gfx/mojo/traits_test_service.mojom.h"
9 #include "ui/gfx/native_widget_types.h" 9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/gfx/selection_bound.h" 10 #include "ui/gfx/selection_bound.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); 137 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
138 gfx::AcceleratedWidget output; 138 gfx::AcceleratedWidget output;
139 proxy->EchoAcceleratedWidget(input, &output); 139 proxy->EchoAcceleratedWidget(input, &output);
140 EXPECT_EQ(input, output); 140 EXPECT_EQ(input, output);
141 } 141 }
142 142
143 TEST_F(StructTraitsTest, GpuMemoryBufferHandle) { 143 TEST_F(StructTraitsTest, GpuMemoryBufferHandle) {
144 const gfx::GpuMemoryBufferId kId(99); 144 const gfx::GpuMemoryBufferId kId(99);
145 const uint32_t kOffset = 126; 145 const uint32_t kOffset = 126;
146 const int32_t kStride = 256; 146 const int32_t kStride = 256;
147 #if defined(USE_OZONE)
148 const uint64_t kSize = kOffset + kStride;
149 const uint64_t kModifier = 2;
150 #endif
151 base::SharedMemory shared_memory; 147 base::SharedMemory shared_memory;
152 ASSERT_TRUE(shared_memory.CreateAnonymous(1024)); 148 ASSERT_TRUE(shared_memory.CreateAnonymous(1024));
153 ASSERT_TRUE(shared_memory.Map(1024)); 149 ASSERT_TRUE(shared_memory.Map(1024));
154 150
155 gfx::GpuMemoryBufferHandle handle; 151 gfx::GpuMemoryBufferHandle handle;
156 handle.type = gfx::SHARED_MEMORY_BUFFER; 152 handle.type = gfx::SHARED_MEMORY_BUFFER;
157 handle.id = kId; 153 handle.id = kId;
158 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory.handle()); 154 handle.handle = base::SharedMemory::DuplicateHandle(shared_memory.handle());
159 handle.offset = kOffset; 155 handle.offset = kOffset;
160 handle.stride = kStride; 156 handle.stride = kStride;
161 157
162 #if defined(USE_OZONE)
163 handle.native_pixmap_handle.planes.emplace_back(kOffset, kStride, kSize,
164 kModifier);
165 #endif
166
167 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); 158 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
168 gfx::GpuMemoryBufferHandle output; 159 gfx::GpuMemoryBufferHandle output;
169 proxy->EchoGpuMemoryBufferHandle(handle, &output); 160 proxy->EchoGpuMemoryBufferHandle(handle, &output);
170 EXPECT_EQ(gfx::SHARED_MEMORY_BUFFER, output.type); 161 EXPECT_EQ(gfx::SHARED_MEMORY_BUFFER, output.type);
171 EXPECT_EQ(kId, output.id); 162 EXPECT_EQ(kId, output.id);
172 EXPECT_EQ(kOffset, output.offset); 163 EXPECT_EQ(kOffset, output.offset);
173 EXPECT_EQ(kStride, output.stride); 164 EXPECT_EQ(kStride, output.stride);
174 165
175 #if defined(USE_OZONE)
176 ASSERT_EQ(1u, output.native_pixmap_handle.planes.size());
177 EXPECT_EQ(kSize, output.native_pixmap_handle.planes.back().size);
178 EXPECT_EQ(kModifier, output.native_pixmap_handle.planes.back().modifier);
179 #endif
180
181 #if !defined(OS_MACOSX) && !defined(OS_IOS) 166 #if !defined(OS_MACOSX) && !defined(OS_IOS)
182 // TODO: Add support for mach_port on mac. 167 // TODO: Add support for mach_port on mac.
183 base::SharedMemory output_memory(output.handle, true); 168 base::SharedMemory output_memory(output.handle, true);
184 EXPECT_TRUE(output_memory.Map(1024)); 169 EXPECT_TRUE(output_memory.Map(1024));
185 #endif 170 #endif
171
172 #if defined(USE_OZONE)
173 const uint64_t kSize = kOffset + kStride;
174 const uint64_t kModifier = 2;
175 handle.type = gfx::OZONE_NATIVE_PIXMAP;
176 handle.id = kId;
177 handle.native_pixmap_handle.planes.emplace_back(kOffset, kStride, kSize,
178 kModifier);
179 proxy->EchoGpuMemoryBufferHandle(handle, &output);
180 EXPECT_EQ(gfx::OZONE_NATIVE_PIXMAP, output.type);
181 EXPECT_EQ(kId, output.id);
182 ASSERT_EQ(1u, output.native_pixmap_handle.planes.size());
183 EXPECT_EQ(kSize, output.native_pixmap_handle.planes.back().size);
184 EXPECT_EQ(kModifier, output.native_pixmap_handle.planes.back().modifier);
185 #endif
186 } 186 }
187 187
188 TEST_F(StructTraitsTest, NullGpuMemoryBufferHandle) { 188 TEST_F(StructTraitsTest, NullGpuMemoryBufferHandle) {
189 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy(); 189 mojom::TraitsTestServicePtr proxy = GetTraitsTestProxy();
190 GpuMemoryBufferHandle output; 190 GpuMemoryBufferHandle output;
191 proxy->EchoGpuMemoryBufferHandle(GpuMemoryBufferHandle(), &output); 191 proxy->EchoGpuMemoryBufferHandle(GpuMemoryBufferHandle(), &output);
192 EXPECT_TRUE(output.is_null()); 192 EXPECT_TRUE(output.is_null());
193 } 193 }
194 194
195 } // namespace gfx 195 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/mojo/buffer_types_traits.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698