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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "ui/gfx/buffer_format_util.h" | 6 #include "ui/gfx/buffer_format_util.h" |
7 #include "ui/gfx/mac/io_surface_manager.h" | 7 #include "ui/gfx/mac/io_surface_manager.h" |
8 #include "ui/gl/gl_image_io_surface.h" | 8 #include "ui/gl/gl_image_io_surface.h" |
9 #include "ui/gl/test/gl_image_test_template.h" | 9 #include "ui/gl/test/gl_image_test_template.h" |
10 | 10 |
11 namespace gl { | 11 namespace gl { |
12 namespace { | 12 namespace { |
13 | 13 |
14 template <gfx::BufferFormat format> | |
15 class GLImageIOSurfaceTestDelegate { | 14 class GLImageIOSurfaceTestDelegate { |
16 public: | 15 public: |
17 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, | 16 scoped_refptr<GLImage> CreateSolidColorImage(const gfx::Size& size, |
| 17 gfx::BufferFormat format, |
18 const uint8_t color[4]) const { | 18 const uint8_t color[4]) const { |
19 scoped_refptr<GLImageIOSurface> image(new GLImageIOSurface( | 19 scoped_refptr<GLImageIOSurface> image(new GLImageIOSurface( |
20 size, GLImageIOSurface::GetInternalFormatForTesting(format))); | 20 size, GLImageIOSurface::GetInternalFormatForTesting(format))); |
21 IOSurfaceRef surface_ref = | 21 IOSurfaceRef surface_ref = |
22 gfx::IOSurfaceManager::CreateIOSurface(size, format); | 22 gfx::IOSurfaceManager::CreateIOSurface(size, format); |
23 IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); | 23 IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); |
24 EXPECT_NE(status, kIOReturnCannotLock); | 24 EXPECT_NE(status, kIOReturnCannotLock); |
25 for (size_t plane = 0; plane < NumberOfPlanesForBufferFormat(format); | 25 for (size_t plane = 0; plane < NumberOfPlanesForBufferFormat(format); |
26 ++plane) { | 26 ++plane) { |
27 void* data = IOSurfaceGetBaseAddressOfPlane(surface_ref, plane); | 27 void* data = IOSurfaceGetBaseAddressOfPlane(surface_ref, plane); |
28 GLImageTestSupport::SetBufferDataToColor( | 28 GLImageTestSupport::SetBufferDataToColor( |
29 size.width(), size.height(), | 29 size.width(), size.height(), |
30 IOSurfaceGetBytesPerRowOfPlane(surface_ref, plane), plane, format, | 30 IOSurfaceGetBytesPerRowOfPlane(surface_ref, plane), plane, format, |
31 color, static_cast<uint8_t*>(data)); | 31 color, static_cast<uint8_t*>(data)); |
32 } | 32 } |
33 IOSurfaceUnlock(surface_ref, 0, nullptr); | 33 IOSurfaceUnlock(surface_ref, 0, nullptr); |
34 | 34 |
35 bool rv = | 35 bool rv = |
36 image->Initialize(surface_ref, gfx::GenericSharedMemoryId(1), format); | 36 image->Initialize(surface_ref, gfx::GenericSharedMemoryId(1), format); |
37 EXPECT_TRUE(rv); | 37 EXPECT_TRUE(rv); |
38 | 38 |
39 return image; | 39 return image; |
40 } | 40 } |
| 41 |
| 42 static bool IsSupported(gfx::BufferFormat format) { |
| 43 switch (format) { |
| 44 case gfx::BufferFormat::RGBA_8888: |
| 45 case gfx::BufferFormat::BGRA_8888: |
| 46 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 47 return true; |
| 48 default: |
| 49 return false; |
| 50 } |
| 51 return false; |
| 52 } |
41 }; | 53 }; |
42 | 54 |
43 using GLImageTestTypes = testing::Types< | 55 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
44 GLImageIOSurfaceTestDelegate<gfx::BufferFormat::RGBA_8888>, | 56 GLImageTest, |
45 GLImageIOSurfaceTestDelegate<gfx::BufferFormat::BGRA_8888>, | 57 GLImageIOSurfaceTestDelegate); |
46 GLImageIOSurfaceTestDelegate<gfx::BufferFormat::YUV_420_BIPLANAR>>; | |
47 | 58 |
48 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, GLImageTest, GLImageTestTypes); | 59 class GLImageIOSurfaceCopyTestDelegate : public GLImageIOSurfaceTestDelegate { |
| 60 static bool IsSupported(gfx::BufferFormat format) { |
| 61 switch (format) { |
| 62 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 63 return true; |
| 64 default: |
| 65 return false; |
| 66 } |
| 67 return false; |
| 68 } |
| 69 }; |
49 | 70 |
50 INSTANTIATE_TYPED_TEST_CASE_P( | 71 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
51 GLImageIOSurface, | 72 GLImageCopyTest, |
52 GLImageCopyTest, | 73 GLImageIOSurfaceCopyTestDelegate); |
53 GLImageIOSurfaceTestDelegate<gfx::BufferFormat::YUV_420_BIPLANAR>); | |
54 | 74 |
55 } // namespace | 75 } // namespace |
56 } // namespace gl | 76 } // namespace gl |
OLD | NEW |