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/gl/gl_image_io_surface.h" |
| 7 #include "ui/gl/test/gl_image_test_template.h" |
| 8 |
| 9 namespace gfx { |
| 10 namespace { |
| 11 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
| 12 const CFStringRef key, |
| 13 int32 value) { |
| 14 base::ScopedCFTypeRef<CFNumberRef> number( |
| 15 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
| 16 CFDictionaryAddValue(dictionary, key, number.get()); |
| 17 } |
| 18 |
| 19 IOSurfaceRef CreateIOSurface(const Size& size) { |
| 20 size_t num_planes = 2; |
| 21 base::ScopedCFTypeRef<CFMutableArrayRef> planes(CFArrayCreateMutable( |
| 22 kCFAllocatorDefault, num_planes, &kCFTypeArrayCallBacks)); |
| 23 |
| 24 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_y( |
| 25 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 26 &kCFTypeDictionaryKeyCallBacks, |
| 27 &kCFTypeDictionaryValueCallBacks)); |
| 28 AddIntegerValue(plane_y, kIOSurfacePlaneWidth, size.width()); |
| 29 AddIntegerValue(plane_y, kIOSurfacePlaneHeight, size.height()); |
| 30 AddIntegerValue(plane_y, kIOSurfacePlaneBytesPerElement, 1); |
| 31 CFArrayAppendValue(planes, plane_y); |
| 32 |
| 33 base::ScopedCFTypeRef<CFMutableDictionaryRef> plane_uv( |
| 34 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 35 &kCFTypeDictionaryKeyCallBacks, |
| 36 &kCFTypeDictionaryValueCallBacks)); |
| 37 AddIntegerValue(plane_uv, kIOSurfacePlaneWidth, size.width() / 2); |
| 38 AddIntegerValue(plane_uv, kIOSurfacePlaneHeight, size.height() / 2); |
| 39 AddIntegerValue(plane_uv, kIOSurfacePlaneBytesPerElement, 2); |
| 40 CFArrayAppendValue(planes, plane_uv); |
| 41 |
| 42 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties( |
| 43 CFDictionaryCreateMutable(kCFAllocatorDefault, 0, |
| 44 &kCFTypeDictionaryKeyCallBacks, |
| 45 &kCFTypeDictionaryValueCallBacks)); |
| 46 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
| 47 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
| 48 AddIntegerValue(properties, kIOSurfacePixelFormat, '420v'); |
| 49 CFDictionaryAddValue(properties, kIOSurfacePlaneInfo, planes); |
| 50 |
| 51 return IOSurfaceCreate(properties); |
| 52 } |
| 53 |
| 54 class GLImageIOSurface420vTestDelegate { |
| 55 public: |
| 56 scoped_refptr<gl::GLImage> CreateSolidColorImage( |
| 57 const Size& size, |
| 58 const uint8_t color[4]) const { |
| 59 scoped_refptr<gl::GLImageIOSurface> image( |
| 60 new gl::GLImageIOSurface(size, GL_RGB_YCBCR_420V_CHROMIUM)); |
| 61 IOSurfaceRef surface_ref = CreateIOSurface(size); |
| 62 IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); |
| 63 EXPECT_NE(status, kIOReturnCannotLock); |
| 64 void* y_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 0); |
| 65 void* uv_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 1); |
| 66 uint8_t* data[] = {static_cast<uint8_t*>(y_data), |
| 67 static_cast<uint8_t*>(uv_data)}; |
| 68 int strides[] = {IOSurfaceGetBytesPerRowOfPlane(surface_ref, 0), |
| 69 IOSurfaceGetBytesPerRowOfPlane(surface_ref, 1)}; |
| 70 |
| 71 GLImageTestSupport::SetBufferDataToColor( |
| 72 size.width(), size.height(), strides, BufferFormat::YUV_420_BIPLANAR, |
| 73 color, data); |
| 74 IOSurfaceUnlock(surface_ref, 0, nullptr); |
| 75 |
| 76 bool rv = image->Initialize(surface_ref, GenericSharedMemoryId(1), |
| 77 BufferFormat::YUV_420_BIPLANAR); |
| 78 EXPECT_TRUE(rv); |
| 79 |
| 80 return image; |
| 81 } |
| 82 }; |
| 83 |
| 84 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
| 85 GLImageTest, |
| 86 GLImageIOSurface420vTestDelegate); |
| 87 |
| 88 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, |
| 89 GLImageCopyTest, |
| 90 GLImageIOSurface420vTestDelegate); |
| 91 |
| 92 } // namespace |
| 93 } // namespace gfx |
OLD | NEW |