| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/buffer.h" | 5 #include "components/exo/buffer.h" |
| 6 #include "components/exo/display.h" | 6 #include "components/exo/display.h" |
| 7 #include "components/exo/shared_memory.h" | 7 #include "components/exo/shared_memory.h" |
| 8 #include "components/exo/shell_surface.h" | 8 #include "components/exo/shell_surface.h" |
| 9 #include "components/exo/sub_surface.h" | 9 #include "components/exo/sub_surface.h" |
| 10 #include "components/exo/surface.h" | 10 #include "components/exo/surface.h" |
| 11 #include "components/exo/test/exo_test_base.h" | 11 #include "components/exo/test/exo_test_base.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 #if defined(USE_OZONE) |
| 15 #include "ui/ozone/public/native_pixmap.h" |
| 16 #include "ui/ozone/public/ozone_platform.h" |
| 17 #include "ui/ozone/public/surface_factory_ozone.h" |
| 18 #endif |
| 19 |
| 14 namespace exo { | 20 namespace exo { |
| 15 namespace { | 21 namespace { |
| 16 | 22 |
| 17 using DisplayTest = test::ExoTestBase; | 23 using DisplayTest = test::ExoTestBase; |
| 18 | 24 |
| 19 TEST_F(DisplayTest, CreateSurface) { | 25 TEST_F(DisplayTest, CreateSurface) { |
| 20 scoped_ptr<Display> display(new Display); | 26 scoped_ptr<Display> display(new Display); |
| 21 | 27 |
| 22 // Creating a surface should succeed. | 28 // Creating a surface should succeed. |
| 23 scoped_ptr<Surface> surface = display->CreateSurface(); | 29 scoped_ptr<Surface> surface = display->CreateSurface(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 39 // Creating a shared memory instance from a valid handle should succeed. | 45 // Creating a shared memory instance from a valid handle should succeed. |
| 40 scoped_ptr<SharedMemory> shm1 = display->CreateSharedMemory(handle, shm_size); | 46 scoped_ptr<SharedMemory> shm1 = display->CreateSharedMemory(handle, shm_size); |
| 41 EXPECT_TRUE(shm1); | 47 EXPECT_TRUE(shm1); |
| 42 | 48 |
| 43 // Creating a shared memory instance from a invalid handle should fail. | 49 // Creating a shared memory instance from a invalid handle should fail. |
| 44 scoped_ptr<SharedMemory> shm2 = | 50 scoped_ptr<SharedMemory> shm2 = |
| 45 display->CreateSharedMemory(base::SharedMemoryHandle(), shm_size); | 51 display->CreateSharedMemory(base::SharedMemoryHandle(), shm_size); |
| 46 EXPECT_FALSE(shm2); | 52 EXPECT_FALSE(shm2); |
| 47 } | 53 } |
| 48 | 54 |
| 55 #if defined(USE_OZONE) |
| 56 TEST_F(DisplayTest, CreatePrimeBuffer) { |
| 57 const gfx::Size buffer_size(256, 256); |
| 58 |
| 59 scoped_ptr<Display> display(new Display); |
| 60 |
| 61 // Creating a prime buffer from a native pixmap handle should succeed. |
| 62 scoped_refptr<ui::NativePixmap> pixmap = |
| 63 ui::OzonePlatform::GetInstance() |
| 64 ->GetSurfaceFactoryOzone() |
| 65 ->CreateNativePixmap(gfx::kNullAcceleratedWidget, buffer_size, |
| 66 gfx::BufferFormat::RGBA_8888, |
| 67 gfx::BufferUsage::GPU_READ); |
| 68 gfx::NativePixmapHandle native_pixmap_handle = pixmap->ExportHandle(); |
| 69 scoped_ptr<Buffer> buffer1 = display->CreatePrimeBuffer( |
| 70 base::ScopedFD(native_pixmap_handle.fd.fd), buffer_size, |
| 71 gfx::BufferFormat::RGBA_8888, native_pixmap_handle.stride); |
| 72 EXPECT_TRUE(buffer1); |
| 73 |
| 74 // Creating a prime buffer using an invalid fd should fail. |
| 75 scoped_ptr<Buffer> buffer2 = display->CreatePrimeBuffer( |
| 76 base::ScopedFD(), buffer_size, gfx::BufferFormat::RGBA_8888, |
| 77 buffer_size.width() * 4); |
| 78 EXPECT_FALSE(buffer2); |
| 79 } |
| 80 #endif |
| 81 |
| 49 TEST_F(DisplayTest, CreateShellSurface) { | 82 TEST_F(DisplayTest, CreateShellSurface) { |
| 50 scoped_ptr<Display> display(new Display); | 83 scoped_ptr<Display> display(new Display); |
| 51 | 84 |
| 52 // Create two surfaces. | 85 // Create two surfaces. |
| 53 scoped_ptr<Surface> surface1 = display->CreateSurface(); | 86 scoped_ptr<Surface> surface1 = display->CreateSurface(); |
| 54 ASSERT_TRUE(surface1); | 87 ASSERT_TRUE(surface1); |
| 55 scoped_ptr<Surface> surface2 = display->CreateSurface(); | 88 scoped_ptr<Surface> surface2 = display->CreateSurface(); |
| 56 ASSERT_TRUE(surface2); | 89 ASSERT_TRUE(surface2); |
| 57 | 90 |
| 58 // Create a shell surface for surface1. | 91 // Create a shell surface for surface1. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // Attempting to create a sub surface for parent with grandchild as its parent | 159 // Attempting to create a sub surface for parent with grandchild as its parent |
| 127 // should fail. | 160 // should fail. |
| 128 EXPECT_FALSE(display->CreateSubSurface(parent.get(), grandchild.get())); | 161 EXPECT_FALSE(display->CreateSubSurface(parent.get(), grandchild.get())); |
| 129 | 162 |
| 130 // Create a sub surface for parent. | 163 // Create a sub surface for parent. |
| 131 EXPECT_TRUE(display->CreateSubSurface(parent.get(), toplevel.get())); | 164 EXPECT_TRUE(display->CreateSubSurface(parent.get(), toplevel.get())); |
| 132 } | 165 } |
| 133 | 166 |
| 134 } // namespace | 167 } // namespace |
| 135 } // namespace exo | 168 } // namespace exo |
| OLD | NEW |