Hash :
188b679b
Author :
Date :
2019-08-15T09:02:43
Remove GL/EGL function pointers from tests. The auto-gen loader code should be able to handle all these cases. Bug: angleproject:3393 Change-Id: If0a90fb29d79f2892fdf76fe0cb91ed0036ee1e3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1756083 Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: Courtney Goeltzenleuchter <courtneygo@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
//
// Copyright 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// EGLSyncControlTest.cpp:
// Tests pertaining to eglGetSyncValuesCHROMIUM.
#include <d3d11.h>
#include "test_utils/ANGLETest.h"
#include "util/OSWindow.h"
#include "util/com_utils.h"
using namespace angle;
class EGLSyncControlTest : public testing::Test
{
protected:
EGLSyncControlTest() {}
void SetUp() override
{
mD3D11Module = LoadLibrary(TEXT("d3d11.dll"));
if (mD3D11Module == nullptr)
{
std::cout << "Unable to LoadLibrary D3D11" << std::endl;
return;
}
mD3D11CreateDevice = reinterpret_cast<PFN_D3D11_CREATE_DEVICE>(
GetProcAddress(mD3D11Module, "D3D11CreateDevice"));
if (mD3D11CreateDevice == nullptr)
{
std::cout << "Could not retrieve D3D11CreateDevice from d3d11.dll" << std::endl;
return;
}
mD3D11Available = true;
const char *extensionString =
static_cast<const char *>(eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS));
if (strstr(extensionString, "EGL_ANGLE_device_creation"))
{
if (strstr(extensionString, "EGL_ANGLE_device_creation_d3d11"))
{
mDeviceCreationD3D11ExtAvailable = true;
}
}
}
void TearDown() override
{
SafeRelease(mDevice);
SafeRelease(mDeviceContext);
OSWindow::Delete(&mOSWindow);
if (mSurface != EGL_NO_SURFACE)
{
eglDestroySurface(mDisplay, mSurface);
mSurface = EGL_NO_SURFACE;
}
if (mContext != EGL_NO_CONTEXT)
{
eglDestroyContext(mDisplay, mContext);
mContext = EGL_NO_CONTEXT;
}
if (mDisplay != EGL_NO_DISPLAY)
{
eglTerminate(mDisplay);
mDisplay = EGL_NO_DISPLAY;
}
}
void CreateD3D11Device()
{
ASSERT_TRUE(mD3D11Available);
ASSERT_EQ(nullptr, mDevice); // The device shouldn't be created twice
HRESULT hr =
mD3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, 0, 0, nullptr, 0,
D3D11_SDK_VERSION, &mDevice, &mFeatureLevel, &mDeviceContext);
ASSERT_TRUE(SUCCEEDED(hr));
}
void InitializeDisplay()
{
EGLint displayAttribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE,
EGL_DONT_CARE,
EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE,
EGL_DONT_CARE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE,
EGL_NONE};
// Create an OS Window
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLSyncControlTest", 64, 64);
mOSWindow->setVisible(true);
// Create an EGLDisplay using the EGLDevice
mDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
displayAttribs);
ASSERT_TRUE(mDisplay != EGL_NO_DISPLAY);
EGLint majorVersion, minorVersion;
ASSERT_TRUE(eglInitialize(mDisplay, &majorVersion, &minorVersion) == EGL_TRUE);
}
void CreateWindowSurface()
{
eglBindAPI(EGL_OPENGL_ES_API);
ASSERT_EGL_SUCCESS();
// Choose a config
const EGLint configAttributes[] = {EGL_NONE};
EGLint configCount = 0;
ASSERT_EGL_TRUE(eglChooseConfig(mDisplay, configAttributes, &mConfig, 1, &configCount));
const EGLint surfaceAttributes[] = {EGL_DIRECT_COMPOSITION_ANGLE, EGL_TRUE, EGL_NONE};
// Create window surface
mSurface = eglCreateWindowSurface(mDisplay, mConfig, mOSWindow->getNativeWindow(),
surfaceAttributes);
if (mSurface == nullptr)
{
std::cout << "Unable to create window surface with Direct Composition" << std::endl;
return;
}
mDirectCompositionSurfaceAvailable = true;
// Create EGL context
EGLint contextAttibutes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
mContext = eglCreateContext(mDisplay, mConfig, nullptr, contextAttibutes);
ASSERT_EGL_SUCCESS();
// Make the surface current
eglMakeCurrent(mDisplay, mSurface, mSurface, mContext);
ASSERT_EGL_SUCCESS();
}
bool mD3D11Available = false;
HMODULE mD3D11Module = nullptr;
PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice = nullptr;
ID3D11Device *mDevice = nullptr;
ID3D11DeviceContext *mDeviceContext = nullptr;
D3D_FEATURE_LEVEL mFeatureLevel;
bool mDeviceCreationD3D11ExtAvailable = false;
bool mDirectCompositionSurfaceAvailable = false;
OSWindow *mOSWindow = nullptr;
EGLDisplay mDisplay = EGL_NO_DISPLAY;
EGLSurface mSurface = EGL_NO_SURFACE;
EGLContext mContext = EGL_NO_CONTEXT;
EGLConfig mConfig = 0;
};
// Basic test for eglGetSyncValuesCHROMIUM extension. Verifies that eglGetSyncValuesCHROMIUM
// can be called on DX11 with direct composition and that it returns reasonable enough values.
TEST_F(EGLSyncControlTest, DISABLED_SyncValuesTest)
{
static const DWORD kPollInterval = 10;
static const int kNumPollIterations = 100;
if (!mD3D11Available)
{
std::cout << "D3D11 not available, skipping test" << std::endl;
return;
}
CreateD3D11Device();
InitializeDisplay();
CreateWindowSurface();
if (!mDirectCompositionSurfaceAvailable)
{
std::cout << "Direct Composition surface not available, skipping test" << std::endl;
return;
}
const char *extensionString =
static_cast<const char *>(eglQueryString(mDisplay, EGL_EXTENSIONS));
ASSERT_TRUE(strstr(extensionString, "EGL_CHROMIUM_sync_control"));
EGLuint64KHR ust = 0, msc = 0, sbc = 0;
// It appears there is a race condition so the very first call to eglGetSyncValuesCHROMIUM
// can fail within D3D with DXGI_ERROR_FRAME_STATISTICS_DISJOINT.
// Should that be handled inside eglGetSyncValuesCHROMIUM?
eglGetSyncValuesCHROMIUM(mDisplay, mSurface, &ust, &msc, &sbc);
ASSERT_EGL_TRUE(eglGetSyncValuesCHROMIUM(mDisplay, mSurface, &ust, &msc, &sbc));
// Initial msc and sbc value should be true. Initial ust value is unspecified.
ASSERT_EQ(0ull, msc);
ASSERT_EQ(0ull, sbc);
// Perform some very basic rendering.
glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
ASSERT_EGL_TRUE(eglSwapBuffers(mDisplay, mSurface));
// Poll until sbc value increases. Normally it should change within 16-17 ms.
for (int i = 0; i < kNumPollIterations; i++)
{
::Sleep(kPollInterval);
ASSERT_EGL_TRUE(eglGetSyncValuesCHROMIUM(mDisplay, mSurface, &ust, &msc, &sbc));
if (sbc > 0)
break;
}
// sbc should change to 1. msc and ust to some non-zero values.
ASSERT_EQ(1ull, sbc);
ASSERT_GT(ust, 0ull);
ASSERT_GT(msc, 0ull);
// Perform more rendering.
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ASSERT_GL_NO_ERROR();
ASSERT_EGL_TRUE(eglSwapBuffers(mDisplay, mSurface));
// Poll until sbc value increases. Normally it should change within 16-17 ms.
EGLuint64KHR ust2 = 0, msc2 = 0, sbc2 = 0;
for (int i = 0; i < kNumPollIterations; i++)
{
::Sleep(kPollInterval);
ASSERT_EGL_TRUE(eglGetSyncValuesCHROMIUM(mDisplay, mSurface, &ust2, &msc2, &sbc2));
if (sbc2 > sbc)
break;
}
// sbc2 should be 2. msc2 and ust2 should be greater than previous msc and ust values.
ASSERT_EQ(2ull, sbc2);
ASSERT_GT(ust2, ust);
ASSERT_GT(msc2, msc);
}