Chromium Code Reviews| Index: ui/gl/gl_image_io_surface_unittest.cc |
| diff --git a/ui/gl/gl_image_io_surface_unittest.cc b/ui/gl/gl_image_io_surface_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..22470002254ea84c4200006925f551a82180b1e2 |
| --- /dev/null |
| +++ b/ui/gl/gl_image_io_surface_unittest.cc |
| @@ -0,0 +1,113 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gl/gl_image_io_surface.h" |
| +#include "ui/gl/test/gl_image_test_template.h" |
| + |
| +namespace gfx { |
| +namespace { |
| +void AddIntegerValue(CFMutableDictionaryRef dictionary, |
| + const CFStringRef key, |
| + int32 value) { |
| + base::ScopedCFTypeRef<CFNumberRef> number( |
| + CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| + CFDictionaryAddValue(dictionary, key, number.get()); |
| +} |
| + |
| +IOSurfaceRef CreateIOSurface(const gfx::Size& size) { |
|
reveman
2015/10/27 19:31:54
hm, can we move the IOSurfaceManager interface and
Daniele Castagna
2015/10/29 20:09:05
This function is similar to GpuMemoryBufferFactory
|
| + size_t num_planes = 2; |
| + base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
| + kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
| + |
| + base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_y( |
| + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| + AddIntegerValue(plane_y, kIOSurfacePlaneWidth, size.width()); |
| + AddIntegerValue(plane_y, kIOSurfacePlaneHeight, size.height()); |
| + AddIntegerValue(plane_y, kIOSurfacePlaneBytesPerElement, 1); |
| + CFArrayAppendValue(planes, plane_y); |
| + |
| + base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_uv( |
| + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| + AddIntegerValue(plane_uv, kIOSurfacePlaneWidth, size.width() / 2); |
| + AddIntegerValue(plane_uv, kIOSurfacePlaneHeight, size.height() / 2); |
| + AddIntegerValue(plane_uv, kIOSurfacePlaneBytesPerElement, 2); |
| + CFArrayAppendValue(planes, plane_uv); |
| + |
| + base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| + CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| + &kCFTypeDictionaryKeyCallBacks, |
| + &kCFTypeDictionaryValueCallBacks)); |
| + AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| + AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| + AddIntegerValue(properties, kIOSurfacePixelFormat, '420v'); |
| + CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
| + |
| + return IOSurfaceCreate(properties); |
| +} |
| + |
| +void SetBuffersDataToColor(const uint8_t color[4], |
|
reveman
2015/10/27 19:31:54
Can this be part of GLImageTestSupport::SetBufferD
Daniele Castagna
2015/10/29 20:09:04
Done.
|
| + const Size& size, |
| + uint8* y_data, |
| + int stride_y, |
| + uint8* uv_data, |
| + int stride_uv) { |
| + uint8_t yuv[] = { |
| + (0.257 * color[0]) + (0.504 * color[1]) + (0.098 * color[2]) + 16, |
| + -(0.148 * color[0]) - (0.291 * color[1]) + (0.439 * color[2]) + 128, |
| + (0.439 * color[0]) - (0.368 * color[1]) - (0.071 * color[2]) + 128}; |
| + for (int x = 0; x < size.width(); ++x) { |
| + for (int y = 0; y < size.height(); ++y) { |
| + y_data[stride_y * y + x] = yuv[0]; |
| + } |
| + } |
| + for (int x = 0; x < size.width() / 2; ++x) { |
| + for (int y = 0; y < size.height() / 2; ++y) { |
| + uv_data[stride_uv * y + x * 2] = yuv[1]; |
| + uv_data[stride_uv * y + x * 2 + 1] = yuv[2]; |
| + } |
| + } |
| +} |
| + |
| +class GLImageIOSurface420vTestDelegate { |
| + public: |
| + scoped_refptr<GLImage> CreateSolidColorImage(const Size& size, |
| + const uint8_t color[4]) const { |
| + scoped_refptr<GLImageIOSurface> image( |
| + new GLImageIOSurface(size, GL_RGB_YCBCR_420V_CHROMIUM)); |
| + IOSurfaceRef surface_ref = CreateIOSurface(size); |
| + IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); |
| + EXPECT_NE(status, kIOReturnCannotLock); |
| + void* y_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 0); |
| + void* uv_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 1); |
| + |
| + SetBuffersDataToColor(color, size, static_cast<uint8*>(y_data), |
| + IOSurfaceGetBytesPerRowOfPlane(surface_ref, 0), |
| + static_cast<uint8*>(uv_data), |
| + IOSurfaceGetBytesPerRowOfPlane(surface_ref, 1)); |
| + |
| + IOSurfaceUnlock(surface_ref, 0, nullptr); |
| + |
| + bool rv = image->Initialize(surface_ref, GenericSharedMemoryId(1), |
| + BufferFormat::YUV_420_BIPLANAR); |
| + EXPECT_TRUE(rv); |
| + |
| + return image; |
| + } |
| +}; |
| + |
| +INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
| + GLImageTest, |
| + GLImageIOSurface420vTestDelegate); |
| + |
| +INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
| + GLImageCopyTest, |
| + GLImageIOSurface420vTestDelegate); |
| + |
| +} // namespace |
| +} // namespace gfx |