OSDN Git Service

test: add wrapper for CreateSurfaces2
[android-x86/hardware-intel-common-vaapi.git] / test / i965_test_fixture.h
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 #ifndef I965_TEST_FIXTURE_H
26 #define I965_TEST_FIXTURE_H
27
28 #include "test.h"
29 #include "i965_internal_decl.h"
30
31 #include <string>
32 #include <vector>
33
34 typedef std::vector<VASurfaceID> Surfaces;
35 typedef std::vector<VASurfaceAttrib> SurfaceAttribs;
36 typedef std::vector<VAConfigAttrib> ConfigAttribs;
37
38 /**
39  * This test fixture handles initialization and termination of the i965 driver
40  * and display. It defines various operators to make it implicitly convertible
41  * to a VADriverContextP, VADisplay, VADisplayContextP, and i965_driver_data*.
42  * Other operators may be defined, too.  These operators allow an instance of
43  * the test fixture to be passed to various driver functions that take one of
44  * those parameter types.  Various driver functions are also wrapped by this
45  * test fixture to simplify writing test cases.
46  *
47  * Test cases that wish to use this fixture should define their own test
48  * fixture class that derives from this one.  The derived test fixture may
49  * override the SetUp() and TearDown() methods.  These two methods are invoked
50  * by gtest before and after a TEST_F test body is executed, respectively.  The
51  * derived test fixture should be sure to call the I965TestFixture::SetUp() and
52  * I965TestFixture::TearDown() methods when they are overridden to ensure
53  * proper initialization and termination of the driver and display.
54  *
55  * See the "Test Fixtures" section in gtest/docs/Primer.md for more details
56  * on how test fixtures are used.
57  */
58 class I965TestFixture
59     : public ::testing::Test
60 {
61 public:
62     I965TestFixture();
63     virtual ~I965TestFixture();
64
65 protected:
66     /**
67      * This is invoked by gtest before the test body is executed.  Gtest will
68      * not run the test body if this method generates a fatal test assertion
69      * failure.
70      */
71     virtual void SetUp()
72     {
73         ASSERT_NO_FATAL_FAILURE(initialize());
74     }
75
76     /**
77      * This is invoked by gtest after the test body is executed... even if the
78      * test body generates a fatal or non-fatal test assertion failure.  If
79      * SetUp() generates a fatal test assertion, this is also invoked by gtest
80      * afterwards.
81      */
82     virtual void TearDown()
83     {
84         terminate();
85     }
86
87     const std::string getFullTestName() const;
88
89 public:
90     /**
91      * Initializes the i965 driver and display.  May generate a fatal or
92      * non-fatal test assertion failure.
93      */
94     void initialize();
95
96     /**
97      * Terminates the i965 driver and display.  May generate a non-fatal
98      * test assertion failure.
99      */
100     void terminate();
101
102     /**
103      * Convenience wrapper for i965_CreateSurfaces or i965_CreateSurfaces2.
104      * If SurfaceAttribs are specified then i965_CreateSurfaces2 is used,
105      * otherwise i965_CreateSurfaces is used. May generate a non-fatal test
106      * assertion failure.
107      */
108     Surfaces createSurfaces(int w, int h, int format, size_t count = 1,
109         const SurfaceAttribs& = SurfaceAttribs());
110
111     /**
112      * Convenience wrapper for i965_DestroySurfaces.  May generate a non-fatal
113      * test assertion failure.
114      */
115     void destroySurfaces(Surfaces&);
116
117     /**
118      * Convenience wrapper for i965_CreateConfig.  May generate a non-fatal
119      * test assertion failure.
120      */
121     VAConfigID createConfig(VAProfile, VAEntrypoint, ConfigAttribs&);
122
123     /**
124      * Convenience wrapper for i965_DestroyConfig.  May generate a non-fatal
125      * test assertion failure.
126      */
127     void destroyConfig(VAConfigID);
128
129     /**
130      * Convenience wrapper for i965_CreateContext.  May generate a non-fatal
131      * test assertion failure.
132      */
133     VAContextID createContext(VAConfigID, int, int, int, Surfaces&);
134
135     /**
136      * Convenience wrapper for i965_DestroyContext.  May generate a non-fatal
137      * test assertion failure.
138      */
139     void destroyContext(VAContextID);
140
141     /**
142      * Convenience wrapper for i965_CreateBuffer.  May generate a non-fatal
143      * test assertion failure.
144      */
145     VABufferID createBuffer(
146         VAContextID, VABufferType, unsigned, unsigned = 1, const void * = NULL);
147
148     /**
149      * Convenience wrapper for i965_DestroyBuffer.  May generate a non-fatal
150      * test assertion failure.
151      */
152     void destroyBuffer(VABufferID);
153
154     /**
155      * Convenience wrapper for i965_MapBuffer.  May generate a non-fatal
156      * test assertion failure.
157      */
158     template<typename T>
159     T* mapBuffer(VABufferID id)
160     {
161         T* data = NULL;
162         EXPECT_STATUS(
163             i965_MapBuffer(*this, id, (void**)&data));
164         EXPECT_PTR(data);
165         return data;
166     }
167
168     /**
169      * Convenience Wrapper for i965_UnmapBuffer.  May generate a non-fatal
170      * test assertion failure.
171      */
172     void unmapBuffer(VABufferID id)
173     {
174         EXPECT_STATUS(
175             i965_UnmapBuffer(*this, id));
176     }
177
178     /**
179      * Convenience wrapper for i965_BeginPicture.  May generate a non-fatal
180      * test assertion failure.
181      */
182     void beginPicture(VAContextID, VASurfaceID);
183
184     /**
185      * Convenience wrapper for i965_RenderPicture.  May generate a non-fatal
186      * test assertion failure.
187      */
188     void renderPicture(VAContextID, VABufferID *, int = 1);
189
190     /**
191      * Convenience wrapper for i965_EndPicture.  May generate a non-fatal
192      * test assertion failure.
193      */
194     void endPicture(VAContextID);
195
196     /**
197      * Convenience wrapper for i965_DeriveImage.  May generate a non-fatal
198      * test assertion failure.
199      */
200     void deriveImage(VASurfaceID, VAImage &);
201
202     /**
203      * Convenience wrapper for i965_DestroyImage.  May generate a non-fatal
204      * test assertion failure.
205      */
206     void destroyImage(VAImage &);
207
208     /**
209      * VADisplay implicit and explicit conversion operator.
210      */
211     operator VADisplay();
212
213     /**
214      * VADisplayContextP implict and explicit conversion operator.
215      */
216     inline operator VADisplayContextP()
217     {
218         return (VADisplayContextP)((VADisplay)*this);
219     }
220
221     /**
222      * VADriverContextP implict and explicit conversion operator.
223      */
224     inline operator VADriverContextP()
225     {
226         VADisplayContextP dctx(*this);
227         return dctx ? dctx->pDriverContext : NULL;
228     }
229
230     /**
231      * i965_driver_data * implict and explicit conversion operator.
232      */
233     inline operator struct i965_driver_data *()
234     {
235         VADriverContextP ctx(*this);
236         return ctx ? i965_driver_data(ctx) : NULL;
237     }
238
239 private:
240     int m_handle; /* current native display handle */
241     VADisplay m_vaDisplay; /* current VADisplay handle */
242 };
243
244 #endif