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