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 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
| |
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 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.
| |
55 const Size& size, | |
56 uint8* y_data, | |
57 int stride_y, | |
58 uint8* uv_data, | |
59 int stride_uv) { | |
60 uint8_t yuv[] = { | |
61 (0.257 * color[0]) + (0.504 * color[1]) + (0.098 * color[2]) + 16, | |
62 -(0.148 * color[0]) - (0.291 * color[1]) + (0.439 * color[2]) + 128, | |
63 (0.439 * color[0]) - (0.368 * color[1]) - (0.071 * color[2]) + 128}; | |
64 for (int x = 0; x < size.width(); ++x) { | |
65 for (int y = 0; y < size.height(); ++y) { | |
66 y_data[stride_y * y + x] = yuv[0]; | |
67 } | |
68 } | |
69 for (int x = 0; x < size.width() / 2; ++x) { | |
70 for (int y = 0; y < size.height() / 2; ++y) { | |
71 uv_data[stride_uv * y + x * 2] = yuv[1]; | |
72 uv_data[stride_uv * y + x * 2 + 1] = yuv[2]; | |
73 } | |
74 } | |
75 } | |
76 | |
77 class GLImageIOSurface420vTestDelegate { | |
78 public: | |
79 scoped_refptr<GLImage> CreateSolidColorImage(const Size& size, | |
80 const uint8_t color[4]) const { | |
81 scoped_refptr<GLImageIOSurface> image( | |
82 new GLImageIOSurface(size, GL_RGB_YCBCR_420V_CHROMIUM)); | |
83 IOSurfaceRef surface_ref = CreateIOSurface(size); | |
84 IOReturn status = IOSurfaceLock(surface_ref, 0, nullptr); | |
85 EXPECT_NE(status, kIOReturnCannotLock); | |
86 void* y_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 0); | |
87 void* uv_data = IOSurfaceGetBaseAddressOfPlane(surface_ref, 1); | |
88 | |
89 SetBuffersDataToColor(color, size, static_cast<uint8*>(y_data), | |
90 IOSurfaceGetBytesPerRowOfPlane(surface_ref, 0), | |
91 static_cast<uint8*>(uv_data), | |
92 IOSurfaceGetBytesPerRowOfPlane(surface_ref, 1)); | |
93 | |
94 IOSurfaceUnlock(surface_ref, 0, nullptr); | |
95 | |
96 bool rv = image->Initialize(surface_ref, GenericSharedMemoryId(1), | |
97 BufferFormat::YUV_420_BIPLANAR); | |
98 EXPECT_TRUE(rv); | |
99 | |
100 return image; | |
101 } | |
102 }; | |
103 | |
104 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, | |
105 GLImageTest, | |
106 GLImageIOSurface420vTestDelegate); | |
107 | |
108 INSTANTIATE_TYPED_TEST_CASE_P(GLImageIOSurface, | |
109 GLImageCopyTest, | |
110 GLImageIOSurface420vTestDelegate); | |
111 | |
112 } // namespace | |
113 } // namespace gfx | |
OLD | NEW |