Commit 43a2762d by Tobin Ehlis Committed by Commit Bot

Refactoring EGL validation

Migrating much of EGL validation to use existing macros. Added new Validate* functions for eglDestroySurface(), eglDestroyContext(), eglWaitNative() functions. This continues the EGL validation refactor begun with SwapBuffers. Following similar pattern used there, but putting this out as an intermediate change to verify that code looks good and is going in the desired direction. Bug: angleproject:798 Change-Id: Id7309b9686543c20b20e273b35df1f8b9010fcd3 Reviewed-on: https://chromium-review.googlesource.com/1178750 Commit-Queue: Tobin Ehlis <tobine@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 3394a73d
......@@ -610,9 +610,8 @@ Error ValidateLabeledObject(Thread *thread,
return NoError();
}
} // namespace
Error ValidateDisplay(const Display *display)
// This is a common sub-check of Display status that's shared by multiple functions
Error ValidateDisplayPointer(const Display *display)
{
if (display == EGL_NO_DISPLAY)
{
......@@ -624,6 +623,15 @@ Error ValidateDisplay(const Display *display)
return EglBadDisplay() << "display is not a valid display.";
}
return NoError();
}
} // namespace
Error ValidateDisplay(const Display *display)
{
ANGLE_TRY(ValidateDisplayPointer(display));
if (!display->isInitialized())
{
return EglNotInitialized() << "display is not initialized.";
......@@ -780,6 +788,16 @@ LabeledObject *GetLabeledObjectIfValid(Thread *thread,
return labeledObject;
}
Error ValidateInitialize(const Display *display)
{
return ValidateDisplayPointer(display);
}
Error ValidateTerminate(const Display *display)
{
return ValidateDisplayPointer(display);
}
Error ValidateCreateContext(Display *display,
Config *configuration,
gl::Context *shareContext,
......@@ -2472,6 +2490,34 @@ Error ValidateGetSyncValuesCHROMIUM(const Display *display,
return NoError();
}
Error ValidateDestroySurface(const Display *display,
const Surface *surface,
const EGLSurface eglSurface)
{
ANGLE_TRY(ValidateSurface(display, surface));
if (eglSurface == EGL_NO_SURFACE)
{
return EglBadSurface();
}
return NoError();
}
Error ValidateDestroyContext(const Display *display,
const gl::Context *glCtx,
const EGLContext eglCtx)
{
ANGLE_TRY(ValidateContext(display, glCtx));
if (eglCtx == EGL_NO_CONTEXT)
{
return EglBadContext();
}
return NoError();
}
Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface *eglSurface)
{
ANGLE_TRY(ValidateSurface(display, eglSurface));
......@@ -2490,6 +2536,18 @@ Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface
return NoError();
}
Error ValidateWaitNative(const Display *display, const EGLint engine)
{
ANGLE_TRY(ValidateDisplay(display));
if (engine != EGL_CORE_NATIVE_ENGINE)
{
return EglBadParameter() << "the 'engine' parameter has an unrecognized value";
}
return NoError();
}
Error ValidateSwapBuffersWithDamageKHR(const Display *display,
const Surface *surface,
EGLint *rects,
......
......@@ -56,6 +56,10 @@ LabeledObject *GetLabeledObjectIfValid(Thread *thread,
EGLObjectKHR object);
// Entry point validation
Error ValidateInitialize(const Display *display);
Error ValidateTerminate(const Display *display);
Error ValidateCreateContext(Display *display,
Config *configuration,
gl::Context *shareContext,
......@@ -130,8 +134,18 @@ Error ValidateGetSyncValuesCHROMIUM(const Display *display,
const EGLuint64KHR *msc,
const EGLuint64KHR *sbc);
Error ValidateDestroySurface(const Display *display,
const Surface *surface,
const EGLSurface eglSurface);
Error ValidateDestroyContext(const Display *display,
const gl::Context *glCtx,
const EGLContext eglCtx);
Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface *surface);
Error ValidateWaitNative(const Display *display, const EGLint engine);
Error ValidateSwapBuffersWithDamageKHR(const Display *display,
const Surface *surface,
EGLint *rects,
......
......@@ -77,18 +77,11 @@ EGLBoolean EGLAPIENTRY Initialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
Thread *thread = GetCurrentThread();
Display *display = static_cast<Display *>(dpy);
if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
{
thread->setError(EglBadDisplay(), GetDebug(), "eglInitialize", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateInitialize(display), "eglInitialize",
GetDisplayIfValid(display), EGL_FALSE);
Error error = display->initialize();
if (error.isError())
{
thread->setError(error, GetDebug(), "eglInitialize", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->initialize(), "eglInitialize", GetDisplayIfValid(display),
EGL_FALSE);
if (major)
*major = 1;
......@@ -105,23 +98,16 @@ EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy)
Thread *thread = GetCurrentThread();
Display *display = static_cast<Display *>(dpy);
if (dpy == EGL_NO_DISPLAY || !Display::isValidDisplay(display))
{
thread->setError(EglBadDisplay(), GetDebug(), "eglTerminate", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateTerminate(display), "eglTerminate",
GetDisplayIfValid(display), EGL_FALSE);
if (display->isValidContext(thread->getContext()))
{
thread->setCurrent(nullptr);
}
Error error = display->terminate(thread);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglTerminate", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->terminate(thread), "eglTerminate",
GetDisplayIfValid(display), EGL_FALSE);
thread->setSuccess();
return EGL_TRUE;
......@@ -135,12 +121,8 @@ const char *EGLAPIENTRY QueryString(EGLDisplay dpy, EGLint name)
Display *display = static_cast<Display *>(dpy);
if (!(display == EGL_NO_DISPLAY && name == EGL_EXTENSIONS))
{
Error error = ValidateDisplay(display);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglQueryString", GetDisplayIfValid(display));
return nullptr;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateDisplay(display), "eglQueryString",
GetDisplayIfValid(display), nullptr);
}
const char *result;
......@@ -188,12 +170,8 @@ EGLBoolean EGLAPIENTRY GetConfigs(EGLDisplay dpy,
Display *display = static_cast<Display *>(dpy);
Error error = ValidateGetConfigs(display, config_size, num_config);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglGetConfigs", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateGetConfigs(display, config_size, num_config),
"eglGetConfigs", GetDisplayIfValid(display), EGL_FALSE);
ClipConfigs(display->getConfigs(AttributeMap()), configs, config_size, num_config);
......@@ -216,12 +194,8 @@ EGLBoolean EGLAPIENTRY ChooseConfig(EGLDisplay dpy,
Display *display = static_cast<Display *>(dpy);
AttributeMap attribMap = AttributeMap::CreateFromIntArray(attrib_list);
Error error = ValidateChooseConfig(display, attribMap, config_size, num_config);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglChooseConfig", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateChooseConfig(display, attribMap, config_size, num_config),
"eglChooseConfig", GetDisplayIfValid(display), EGL_FALSE);
ClipConfigs(display->getConfigs(attribMap), configs, config_size, num_config);
......@@ -243,12 +217,8 @@ EGLBoolean EGLAPIENTRY GetConfigAttrib(EGLDisplay dpy,
Display *display = static_cast<Display *>(dpy);
Config *configuration = static_cast<Config *>(config);
Error error = ValidateGetConfigAttrib(display, configuration, attribute);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglGetConfigAttrib", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateGetConfigAttrib(display, configuration, attribute),
"eglGetConfigAttrib", GetDisplayIfValid(display), EGL_FALSE);
QueryConfigAttrib(configuration, attribute, value);
......@@ -271,20 +241,14 @@ EGLSurface EGLAPIENTRY CreateWindowSurface(EGLDisplay dpy,
Config *configuration = static_cast<Config *>(config);
AttributeMap attributes = AttributeMap::CreateFromIntArray(attrib_list);
Error error = ValidateCreateWindowSurface(display, configuration, win, attributes);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreateWindowSurface", GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
ANGLE_EGL_TRY_RETURN(thread,
ValidateCreateWindowSurface(display, configuration, win, attributes),
"eglCreateWindowSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
egl::Surface *surface = nullptr;
error = display->createWindowSurface(configuration, win, attributes, &surface);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreateWindowSurface", GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
ANGLE_EGL_TRY_RETURN(thread,
display->createWindowSurface(configuration, win, attributes, &surface),
"eglCreateWindowSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
return static_cast<EGLSurface>(surface);
}
......@@ -303,20 +267,12 @@ EGLSurface EGLAPIENTRY CreatePbufferSurface(EGLDisplay dpy,
Config *configuration = static_cast<Config *>(config);
AttributeMap attributes = AttributeMap::CreateFromIntArray(attrib_list);
Error error = ValidateCreatePbufferSurface(display, configuration, attributes);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreatePbufferSurface", GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateCreatePbufferSurface(display, configuration, attributes),
"eglCreatePbufferSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
egl::Surface *surface = nullptr;
error = display->createPbufferSurface(configuration, attributes, &surface);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreatePbufferSurface", GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
ANGLE_EGL_TRY_RETURN(thread, display->createPbufferSurface(configuration, attributes, &surface),
"eglCreatePbufferSurface", GetDisplayIfValid(display), EGL_NO_SURFACE);
return static_cast<EGLSurface>(surface);
}
......@@ -336,12 +292,8 @@ EGLSurface EGLAPIENTRY CreatePixmapSurface(EGLDisplay dpy,
Display *display = static_cast<Display *>(dpy);
Config *configuration = static_cast<Config *>(config);
Error error = ValidateConfig(display, configuration);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreatePixmapSurface", GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateConfig(display, configuration), "eglCreatePixmapSurface",
GetDisplayIfValid(display), EGL_NO_SURFACE);
UNIMPLEMENTED(); // FIXME
......@@ -357,28 +309,11 @@ EGLBoolean EGLAPIENTRY DestroySurface(EGLDisplay dpy, EGLSurface surface)
Display *display = static_cast<Display *>(dpy);
Surface *eglSurface = static_cast<Surface *>(surface);
Error error = ValidateSurface(display, eglSurface);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglDestroySurface",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE)
{
thread->setError(EglBadSurface(), GetDebug(), "eglDestroySurface",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateDestroySurface(display, eglSurface, surface),
"eglDestroySurface", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
error = display->destroySurface(eglSurface);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglDestroySurface",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->destroySurface(eglSurface), "eglDestroySurface",
GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
thread->setSuccess();
return EGL_TRUE;
......@@ -398,13 +333,8 @@ EGLBoolean EGLAPIENTRY QuerySurface(EGLDisplay dpy,
const Display *display = static_cast<const Display *>(dpy);
const Surface *eglSurface = static_cast<const Surface *>(surface);
Error error = ValidateQuerySurface(display, eglSurface, attribute, value);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglQuerySurface",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateQuerySurface(display, eglSurface, attribute, value),
"eglQuerySurface", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
QuerySurfaceAttrib(eglSurface, attribute, value);
......@@ -429,20 +359,14 @@ EGLContext EGLAPIENTRY CreateContext(EGLDisplay dpy,
gl::Context *sharedGLContext = static_cast<gl::Context *>(share_context);
AttributeMap attributes = AttributeMap::CreateFromIntArray(attrib_list);
Error error = ValidateCreateContext(display, configuration, sharedGLContext, attributes);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreateContext", GetDisplayIfValid(display));
return EGL_NO_CONTEXT;
}
ANGLE_EGL_TRY_RETURN(thread,
ValidateCreateContext(display, configuration, sharedGLContext, attributes),
"eglCreateContext", GetDisplayIfValid(display), EGL_NO_CONTEXT);
gl::Context *context = nullptr;
error = display->createContext(configuration, sharedGLContext, attributes, &context);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglCreateContext", GetDisplayIfValid(display));
return EGL_NO_CONTEXT;
}
ANGLE_EGL_TRY_RETURN(
thread, display->createContext(configuration, sharedGLContext, attributes, &context),
"eglCreateContext", GetDisplayIfValid(display), EGL_NO_CONTEXT);
thread->setSuccess();
return static_cast<EGLContext>(context);
......@@ -456,30 +380,13 @@ EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx)
Display *display = static_cast<Display *>(dpy);
gl::Context *context = static_cast<gl::Context *>(ctx);
Error error = ValidateContext(display, context);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglDestroyContext",
GetContextIfValid(display, context));
return EGL_FALSE;
}
if (ctx == EGL_NO_CONTEXT)
{
thread->setError(EglBadContext(), GetDebug(), "eglDestroyContext",
GetContextIfValid(display, context));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateDestroyContext(display, context, ctx), "eglDestroyContext",
GetContextIfValid(display, context), EGL_FALSE);
bool contextWasCurrent = context == thread->getContext();
error = display->destroyContext(thread, context);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglDestroyContext",
GetContextIfValid(display, context));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->destroyContext(thread, context), "eglDestroyContext",
GetContextIfValid(display, context), EGL_FALSE);
if (contextWasCurrent)
{
......@@ -577,12 +484,8 @@ EGLBoolean EGLAPIENTRY QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attri
Display *display = static_cast<Display *>(dpy);
gl::Context *context = static_cast<gl::Context *>(ctx);
Error error = ValidateQueryContext(display, context, attribute, value);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglQueryContext", GetContextIfValid(display, context));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateQueryContext(display, context, attribute, value),
"eglQueryContext", GetContextIfValid(display, context), EGL_FALSE);
QueryContextAttrib(context, attribute, value);
......@@ -597,21 +500,13 @@ EGLBoolean EGLAPIENTRY WaitGL(void)
Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglWaitGL", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateDisplay(display), "eglWaitGL", GetDisplayIfValid(display),
EGL_FALSE);
// eglWaitGL like calling eglWaitClient with the OpenGL ES API bound. Since we only implement
// OpenGL ES we can do the call directly.
error = display->waitClient(thread->getContext());
if (error.isError())
{
thread->setError(error, GetDebug(), "eglWaitGL", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->waitClient(thread->getContext()), "eglWaitGL",
GetDisplayIfValid(display), EGL_FALSE);
thread->setSuccess();
return EGL_TRUE;
......@@ -624,26 +519,11 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglWaitNative", GetThreadIfValid(thread));
return EGL_FALSE;
}
if (engine != EGL_CORE_NATIVE_ENGINE)
{
thread->setError(EglBadParameter() << "the 'engine' parameter has an unrecognized value",
GetDebug(), "eglWaitNative", GetDisplayIfValid(display));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, ValidateWaitNative(display, engine), "eglWaitNative",
GetThreadIfValid(thread), EGL_FALSE);
error = display->waitNative(thread->getContext(), engine);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglWaitNative", GetThreadIfValid(thread));
return EGL_FALSE;
}
ANGLE_EGL_TRY_RETURN(thread, display->waitNative(thread->getContext(), engine), "eglWaitNative",
GetThreadIfValid(thread), EGL_FALSE);
thread->setSuccess();
return EGL_TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment