teglCreateSurfaceTests.cpp revision 3c67e4f0ec73f9c30c6b2ed2adfbfe7faaf576a4
1/*------------------------------------------------------------------------- 2 * drawElements Quality Program EGL Module 3 * --------------------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief Simple surface construction test. 22 *//*--------------------------------------------------------------------*/ 23 24#include "teglCreateSurfaceTests.hpp" 25 26#include "egluNativeDisplay.hpp" 27#include "egluNativeWindow.hpp" 28#include "egluNativePixmap.hpp" 29#include "egluUtil.hpp" 30#include "egluUnique.hpp" 31 32#include "eglwLibrary.hpp" 33#include "eglwEnums.hpp" 34 35#include "teglSimpleConfigCase.hpp" 36#include "tcuTestContext.hpp" 37#include "tcuCommandLine.hpp" 38#include "tcuTestLog.hpp" 39 40#include "deSTLUtil.hpp" 41#include "deUniquePtr.hpp" 42 43#include <memory> 44 45namespace deqp 46{ 47namespace egl 48{ 49 50using std::vector; 51using tcu::TestLog; 52using namespace eglw; 53 54namespace 55{ 56 57void checkEGLPlatformSupport (const Library& egl, const char* platformExt) 58{ 59 std::vector<std::string> extensions = eglu::getPlatformExtensions(egl); 60 61 if (!de::contains(extensions.begin(), extensions.end(), platformExt)) 62 throw tcu::NotSupportedError((std::string("Platform extension '") + platformExt + "' not supported").c_str(), "", __FILE__, __LINE__); 63} 64 65EGLSurface createWindowSurface (EGLDisplay display, EGLConfig config, eglu::NativeDisplay& nativeDisplay, eglu::NativeWindow& window, bool useLegacyCreate) 66{ 67 const Library& egl = nativeDisplay.getLibrary(); 68 EGLSurface surface = EGL_NO_SURFACE; 69 70 if (useLegacyCreate) 71 { 72 surface = egl.createWindowSurface(display, config, window.getLegacyNative(), DE_NULL); 73 EGLU_CHECK_MSG(egl, "eglCreateWindowSurface() failed"); 74 } 75 else 76 { 77 checkEGLPlatformSupport(egl, nativeDisplay.getPlatformExtensionName()); 78 79 surface = egl.createPlatformWindowSurfaceEXT(display, config, window.getPlatformNative(), DE_NULL); 80 EGLU_CHECK_MSG(egl, "eglCreatePlatformWindowSurfaceEXT() failed"); 81 } 82 83 return surface; 84} 85 86EGLSurface createPixmapSurface (EGLDisplay display, EGLConfig config, eglu::NativeDisplay& nativeDisplay, eglu::NativePixmap& pixmap, bool useLegacyCreate) 87{ 88 const Library& egl = nativeDisplay.getLibrary(); 89 EGLSurface surface = EGL_NO_SURFACE; 90 91 if (useLegacyCreate) 92 { 93 surface = egl.createPixmapSurface(display, config, pixmap.getLegacyNative(), DE_NULL); 94 EGLU_CHECK_MSG(egl, "eglCreatePixmapSurface() failed"); 95 } 96 else 97 { 98 checkEGLPlatformSupport(egl, nativeDisplay.getPlatformExtensionName()); 99 100 surface = egl.createPlatformPixmapSurfaceEXT(display, config, pixmap.getPlatformNative(), DE_NULL); 101 EGLU_CHECK_MSG(egl, "eglCreatePlatformPixmapSurfaceEXT() failed"); 102 } 103 104 return surface; 105} 106 107class CreateWindowSurfaceCase : public SimpleConfigCase 108{ 109public: 110 CreateWindowSurfaceCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool useLegacyCreate, const eglu::FilterList& filters) 111 : SimpleConfigCase (eglTestCtx, name, description, filters) 112 , m_useLegacyCreate (useLegacyCreate) 113 { 114 } 115 116 void executeForConfig (EGLDisplay display, EGLConfig config) 117 { 118 const Library& egl = m_eglTestCtx.getLibrary(); 119 TestLog& log = m_testCtx.getLog(); 120 EGLint id = eglu::getConfigID(egl, display, config); 121 const eglu::NativeWindowFactory* windowFactory = eglu::selectNativeWindowFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine()); 122 123 if (!windowFactory) 124 TCU_THROW(NotSupportedError, "Windows not supported"); 125 126 // \todo [2011-03-23 pyry] Iterate thru all possible combinations of EGL_RENDER_BUFFER, EGL_VG_COLORSPACE and EGL_VG_ALPHA_FORMAT 127 128 if (m_useLegacyCreate) 129 { 130 if ((windowFactory->getCapabilities() & eglu::NativeWindow::CAPABILITY_CREATE_SURFACE_LEGACY) == 0) 131 TCU_THROW(NotSupportedError, "Native window doesn't support legacy eglCreateWindowSurface()"); 132 } 133 else 134 { 135 if ((windowFactory->getCapabilities() & eglu::NativeWindow::CAPABILITY_CREATE_SURFACE_PLATFORM) == 0) 136 TCU_THROW(NotSupportedError, "Native window doesn't support eglCreatePlatformWindowSurfaceEXT()"); 137 } 138 139 log << TestLog::Message << "Creating window surface with config ID " << id << TestLog::EndMessage; 140 EGLU_CHECK_MSG(egl, "init"); 141 142 { 143 const int width = 64; 144 const int height = 64; 145 de::UniquePtr<eglu::NativeWindow> window (windowFactory->createWindow(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, eglu::WindowParams(width, height, eglu::parseWindowVisibility(m_testCtx.getCommandLine())))); 146 eglu::UniqueSurface surface (egl, display, createWindowSurface(display, config, m_eglTestCtx.getNativeDisplay(), *window, m_useLegacyCreate)); 147 148 EGLint windowWidth = 0; 149 EGLint windowHeight = 0; 150 151 EGLU_CHECK_CALL(egl, querySurface(display, *surface, EGL_WIDTH, &windowWidth)); 152 EGLU_CHECK_CALL(egl, querySurface(display, *surface, EGL_HEIGHT, &windowHeight)); 153 154 if (windowWidth <= 0 || windowHeight <= 0) 155 { 156 log << TestLog::Message << " Fail, invalid surface size " << windowWidth << "x" << windowHeight << TestLog::EndMessage; 157 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid surface size"); 158 } 159 else 160 log << TestLog::Message << " Pass" << TestLog::EndMessage; 161 } 162 } 163 164private: 165 bool m_useLegacyCreate; 166}; 167 168class CreatePixmapSurfaceCase : public SimpleConfigCase 169{ 170public: 171 CreatePixmapSurfaceCase (EglTestContext& eglTestCtx, const char* name, const char* description, bool useLegacyCreate, const eglu::FilterList& filters) 172 : SimpleConfigCase(eglTestCtx, name, description, filters) 173 , m_useLegacyCreate (useLegacyCreate) 174 { 175 } 176 177 void executeForConfig (EGLDisplay display, EGLConfig config) 178 { 179 const Library& egl = m_eglTestCtx.getLibrary(); 180 TestLog& log = m_testCtx.getLog(); 181 EGLint id = eglu::getConfigID(egl, display, config); 182 const eglu::NativePixmapFactory* pixmapFactory = eglu::selectNativePixmapFactory(m_eglTestCtx.getNativeDisplayFactory(), m_testCtx.getCommandLine()); 183 184 if (!pixmapFactory) 185 TCU_THROW(NotSupportedError, "Pixmaps not supported"); 186 187 // \todo [2011-03-23 pyry] Iterate thru all possible combinations of EGL_RENDER_BUFFER, EGL_VG_COLORSPACE and EGL_VG_ALPHA_FORMAT 188 189 if (m_useLegacyCreate) 190 { 191 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_CREATE_SURFACE_LEGACY) == 0) 192 TCU_THROW(NotSupportedError, "Native pixmap doesn't support legacy eglCreatePixmapSurface()"); 193 } 194 else 195 { 196 if ((pixmapFactory->getCapabilities() & eglu::NativePixmap::CAPABILITY_CREATE_SURFACE_PLATFORM) == 0) 197 TCU_THROW(NotSupportedError, "Native pixmap doesn't support eglCreatePlatformPixmapSurfaceEXT()"); 198 } 199 200 log << TestLog::Message << "Creating pixmap surface with config ID " << id << TestLog::EndMessage; 201 EGLU_CHECK_MSG(egl, "init"); 202 203 { 204 const int width = 64; 205 const int height = 64; 206 de::UniquePtr<eglu::NativePixmap> pixmap (pixmapFactory->createPixmap(&m_eglTestCtx.getNativeDisplay(), display, config, DE_NULL, width, height)); 207 eglu::UniqueSurface surface (egl, display, createPixmapSurface(display, config, m_eglTestCtx.getNativeDisplay(), *pixmap, m_useLegacyCreate)); 208 EGLint pixmapWidth = 0; 209 EGLint pixmapHeight = 0; 210 211 EGLU_CHECK_CALL(egl, querySurface(display, *surface, EGL_WIDTH, &pixmapWidth)); 212 EGLU_CHECK_CALL(egl, querySurface(display, *surface, EGL_HEIGHT, &pixmapHeight)); 213 214 if (pixmapWidth <= 0 || pixmapHeight <= 0) 215 { 216 log << TestLog::Message << " Fail, invalid surface size " << pixmapWidth << "x" << pixmapHeight << TestLog::EndMessage; 217 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid surface size"); 218 } 219 else 220 log << TestLog::Message << " Pass" << TestLog::EndMessage; 221 } 222 } 223 224private: 225 bool m_useLegacyCreate; 226}; 227 228class CreatePbufferSurfaceCase : public SimpleConfigCase 229{ 230public: 231 CreatePbufferSurfaceCase (EglTestContext& eglTestCtx, const char* name, const char* description, const eglu::FilterList& filters) 232 : SimpleConfigCase(eglTestCtx, name, description, filters) 233 { 234 } 235 236 void executeForConfig (EGLDisplay display, EGLConfig config) 237 { 238 const Library& egl = m_eglTestCtx.getLibrary(); 239 TestLog& log = m_testCtx.getLog(); 240 EGLint id = eglu::getConfigID(egl, display, config); 241 int width = 64; 242 int height = 64; 243 244 // \todo [2011-03-23 pyry] Iterate thru all possible combinations of EGL_RENDER_BUFFER, EGL_VG_COLORSPACE and EGL_VG_ALPHA_FORMAT 245 246 log << TestLog::Message << "Creating pbuffer surface with config ID " << id << TestLog::EndMessage; 247 EGLU_CHECK_MSG(egl, "init"); 248 249 // Clamp to maximums reported by implementation 250 width = deMin32(width, eglu::getConfigAttribInt(egl, display, config, EGL_MAX_PBUFFER_WIDTH)); 251 height = deMin32(height, eglu::getConfigAttribInt(egl, display, config, EGL_MAX_PBUFFER_HEIGHT)); 252 253 if (width == 0 || height == 0) 254 { 255 log << TestLog::Message << " Fail, maximum pbuffer size of " << width << "x" << height << " reported" << TestLog::EndMessage; 256 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Invalid maximum pbuffer size"); 257 return; 258 } 259 260 // \todo [2011-03-23 pyry] Texture-backed variants! 261 262 const EGLint attribs[] = 263 { 264 EGL_WIDTH, width, 265 EGL_HEIGHT, height, 266 EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE, 267 EGL_NONE 268 }; 269 270 EGLSurface surface = egl.createPbufferSurface(display, config, attribs); 271 EGLU_CHECK_MSG(egl, "Failed to create pbuffer"); 272 TCU_CHECK(surface != EGL_NO_SURFACE); 273 egl.destroySurface(display, surface); 274 275 log << TestLog::Message << " Pass" << TestLog::EndMessage; 276 } 277}; 278 279} // anonymous 280 281CreateSurfaceTests::CreateSurfaceTests (EglTestContext& eglTestCtx) 282 : TestCaseGroup(eglTestCtx, "create_surface", "Basic surface construction tests") 283{ 284} 285 286CreateSurfaceTests::~CreateSurfaceTests (void) 287{ 288} 289 290template <deUint32 Type> 291static bool surfaceType (const eglu::CandidateConfig& c) 292{ 293 return (c.surfaceType() & Type) == Type; 294} 295 296void CreateSurfaceTests::init (void) 297{ 298 // Window surfaces 299 { 300 tcu::TestCaseGroup* windowGroup = new tcu::TestCaseGroup(m_testCtx, "window", "Window surfaces"); 301 addChild(windowGroup); 302 303 eglu::FilterList baseFilters; 304 baseFilters << surfaceType<EGL_WINDOW_BIT>; 305 306 vector<NamedFilterList> filterLists; 307 getDefaultFilterLists(filterLists, baseFilters); 308 309 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 310 windowGroup->addChild(new CreateWindowSurfaceCase(m_eglTestCtx, i->getName(), i->getDescription(), true, *i)); 311 } 312 313 // Pixmap surfaces 314 { 315 tcu::TestCaseGroup* pixmapGroup = new tcu::TestCaseGroup(m_testCtx, "pixmap", "Pixmap surfaces"); 316 addChild(pixmapGroup); 317 318 eglu::FilterList baseFilters; 319 baseFilters << surfaceType<EGL_PIXMAP_BIT>; 320 321 vector<NamedFilterList> filterLists; 322 getDefaultFilterLists(filterLists, baseFilters); 323 324 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 325 pixmapGroup->addChild(new CreatePixmapSurfaceCase(m_eglTestCtx, i->getName(), i->getDescription(), true, *i)); 326 } 327 328 // Pbuffer surfaces 329 { 330 tcu::TestCaseGroup* pbufferGroup = new tcu::TestCaseGroup(m_testCtx, "pbuffer", "Pbuffer surfaces"); 331 addChild(pbufferGroup); 332 333 eglu::FilterList baseFilters; 334 baseFilters << surfaceType<EGL_PBUFFER_BIT>; 335 336 vector<NamedFilterList> filterLists; 337 getDefaultFilterLists(filterLists, baseFilters); 338 339 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 340 pbufferGroup->addChild(new CreatePbufferSurfaceCase(m_eglTestCtx, i->getName(), i->getDescription(), *i)); 341 } 342 343 // Window surfaces with new platform extension 344 { 345 tcu::TestCaseGroup* windowGroup = new tcu::TestCaseGroup(m_testCtx, "platform_window", "Window surfaces with platform extension"); 346 addChild(windowGroup); 347 348 eglu::FilterList baseFilters; 349 baseFilters << surfaceType<EGL_WINDOW_BIT>; 350 351 vector<NamedFilterList> filterLists; 352 getDefaultFilterLists(filterLists, baseFilters); 353 354 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 355 windowGroup->addChild(new CreateWindowSurfaceCase(m_eglTestCtx, i->getName(), i->getDescription(), false, *i)); 356 } 357 358 // Pixmap surfaces with new platform extension 359 { 360 tcu::TestCaseGroup* pixmapGroup = new tcu::TestCaseGroup(m_testCtx, "platform_pixmap", "Pixmap surfaces with platform extension"); 361 addChild(pixmapGroup); 362 363 eglu::FilterList baseFilters; 364 baseFilters << surfaceType<EGL_PIXMAP_BIT>; 365 366 vector<NamedFilterList> filterLists; 367 getDefaultFilterLists(filterLists, baseFilters); 368 369 for (vector<NamedFilterList>::iterator i = filterLists.begin(); i != filterLists.end(); i++) 370 pixmapGroup->addChild(new CreatePixmapSurfaceCase(m_eglTestCtx, i->getName(), i->getDescription(), false, *i)); 371 } 372} 373 374} // egl 375} // deqp 376