OSDN Git Service

intel-vaapi-driver 2.2.0.pre1
[android-x86/hardware-intel-common-vaapi.git] / test / i965_surface_test.cpp
1 /*
2  * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24
25 #include "i965_test_fixture.h"
26
27 #include <algorithm>
28 #include <set>
29
30 static const std::set<unsigned> pixelFormats = {
31     /** Defined in va/va.h **/
32     VA_FOURCC_NV12, VA_FOURCC_AI44, VA_FOURCC_RGBA, VA_FOURCC_RGBX,
33     VA_FOURCC_BGRA, VA_FOURCC_BGRX, VA_FOURCC_ARGB, VA_FOURCC_XRGB,
34     VA_FOURCC_ABGR, VA_FOURCC_XBGR, VA_FOURCC_UYVY, VA_FOURCC_YUY2,
35     VA_FOURCC_AYUV, VA_FOURCC_NV11, VA_FOURCC_YV12, VA_FOURCC_P208,
36     VA_FOURCC_IYUV, VA_FOURCC_YV24, VA_FOURCC_YV32, VA_FOURCC_Y800,
37     VA_FOURCC_IMC3, VA_FOURCC_411P, VA_FOURCC_422H, VA_FOURCC_422V,
38     VA_FOURCC_444P, VA_FOURCC_RGBP, VA_FOURCC_BGRP, VA_FOURCC_411R,
39     VA_FOURCC_YV16, VA_FOURCC_P010, VA_FOURCC_P016,
40
41     /** Defined in i965_fourcc.h **/
42     VA_FOURCC_I420, VA_FOURCC_IA44, VA_FOURCC_IA88, VA_FOURCC_AI88,
43     VA_FOURCC_IMC1, VA_FOURCC_YVY2,
44
45     /** Bogus pixel formats **/
46     VA_FOURCC('B','E','E','F'), VA_FOURCC('P','O','R','K'),
47     VA_FOURCC('F','I','S','H'),
48 };
49
50 class CreateSurfacesTest
51     : public I965TestFixture
52 {
53 protected:
54     const std::set<unsigned> supported = {
55         VA_FOURCC_NV12, VA_FOURCC_I420, VA_FOURCC_IYUV, VA_FOURCC_IMC3,
56         VA_FOURCC_YV12, VA_FOURCC_IMC1, VA_FOURCC_P010, VA_FOURCC_422H,
57         VA_FOURCC_422V, VA_FOURCC_YV16, VA_FOURCC_YUY2, VA_FOURCC_UYVY,
58         VA_FOURCC_444P, VA_FOURCC_411P, VA_FOURCC_Y800, VA_FOURCC_RGBA,
59         VA_FOURCC_RGBX, VA_FOURCC_BGRA, VA_FOURCC_BGRX,
60     };
61 };
62
63 TEST_F(CreateSurfacesTest, SupportedPixelFormats)
64 {
65     SurfaceAttribs attributes(1);
66     attributes.front().flags = VA_SURFACE_ATTRIB_SETTABLE;
67     attributes.front().type = VASurfaceAttribPixelFormat;
68     attributes.front().value.type = VAGenericValueTypeInteger;
69
70     for (const unsigned fourcc : supported) {
71         SCOPED_TRACE(
72             ::testing::Message()
73             << std::string(reinterpret_cast<const char*>(&fourcc), 4)
74             << "(0x" << std::hex << fourcc << std::dec << ")");
75
76         const i965_fourcc_info *info = get_fourcc_info(fourcc);
77         EXPECT_PTR(info);
78         EXPECT_TRUE(info->flag & 1);
79
80         attributes.front().value.value.i = fourcc;
81         Surfaces surfaces = createSurfaces(
82             10, 10, VA_RT_FORMAT_YUV420, 1, attributes);
83         destroySurfaces(surfaces);
84     }
85 }
86
87 TEST_F(CreateSurfacesTest, UnsupportedPixelFormats)
88 {
89     SurfaceAttribs attributes(1);
90     attributes.front().flags = VA_SURFACE_ATTRIB_SETTABLE;
91     attributes.front().type = VASurfaceAttribPixelFormat;
92     attributes.front().value.type = VAGenericValueTypeInteger;
93
94     std::set<unsigned> unsupported;
95     std::set_difference(pixelFormats.begin(), pixelFormats.end(),
96         supported.begin(), supported.end(),
97         std::inserter(unsupported, unsupported.begin()));
98
99     EXPECT_EQ(pixelFormats.size() - supported.size(), unsupported.size());
100
101     for (const unsigned fourcc : unsupported) {
102         SCOPED_TRACE(
103             ::testing::Message()
104             << std::string(reinterpret_cast<const char*>(&fourcc), 4)
105             << "(0x" << std::hex << fourcc << std::dec << ")");
106
107         const i965_fourcc_info *info = get_fourcc_info(fourcc);
108         EXPECT_FALSE(info ? info->flag & 1 : false);
109
110         attributes.front().value.value.i = fourcc;
111         Surfaces surfaces;
112         EXPECT_NONFATAL_FAILURE(
113             surfaces = createSurfaces(
114                 10, 10, VA_RT_FORMAT_YUV420, 1, attributes),
115             "VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT"
116         );
117         EXPECT_NONFATAL_FAILURE(
118             destroySurfaces(surfaces), "VA_STATUS_ERROR_INVALID_SURFACE");
119     }
120 }