Commit d20e80b8 by Tobin Ehlis Committed by Commit Bot

More EGL validation refactor

Added separate Validate* functions for CopyBuffers(), BindTexImage(), ReleaseTexImage(), SwapInterval(), and BindAPI(). For ValidateBindTexImage() the textureObject is set by validation when appropriate and then used in the core function to prevent replicating the textureObject look-up code. Bug: angleproject:798 Change-Id: Ia32076a10aa0b044c2bdc8e2e24dd36d002c5022 Reviewed-on: https://chromium-review.googlesource.com/1180090Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent f26b27e2
...@@ -2536,18 +2536,6 @@ Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface ...@@ -2536,18 +2536,6 @@ Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface
return NoError(); 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, Error ValidateSwapBuffersWithDamageKHR(const Display *display,
const Surface *surface, const Surface *surface,
EGLint *rects, EGLint *rects,
...@@ -2586,6 +2574,129 @@ Error ValidateSwapBuffersWithDamageKHR(const Display *display, ...@@ -2586,6 +2574,129 @@ Error ValidateSwapBuffersWithDamageKHR(const Display *display,
return NoError(); 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 ValidateCopyBuffers(Display *display, const Surface *surface)
{
ANGLE_TRY(ValidateSurface(display, surface));
if (display->testDeviceLost())
{
return EglContextLost();
}
return NoError();
}
// Validate state for eglBindTexImage. If context is non-null then textureObject will be set to
// surface's texture that will have an image bound to it
Error ValidateBindTexImage(const Display *display,
const Surface *surface,
const EGLSurface eglSurface,
const EGLint buffer,
const gl::Context *context,
gl::Texture **textureObject)
{
ANGLE_TRY(ValidateSurface(display, surface));
if (buffer != EGL_BACK_BUFFER)
{
return EglBadParameter();
}
if (eglSurface == EGL_NO_SURFACE || surface->getType() == EGL_WINDOW_BIT)
{
return EglBadSurface();
}
if (surface->getBoundTexture())
{
return EglBadAccess();
}
if (surface->getTextureFormat() == TextureFormat::NoTexture)
{
return EglBadMatch();
}
if (context)
{
gl::TextureType type = egl_gl::EGLTextureTargetToTextureType(surface->getTextureTarget());
*textureObject = context->getTargetTexture(type);
ASSERT(*textureObject != nullptr);
if ((*textureObject)->getImmutableFormat())
{
return EglBadMatch();
}
}
return NoError();
}
Error ValidateReleaseTexImage(const Display *display,
const Surface *surface,
const EGLSurface eglSurface,
const EGLint buffer)
{
ANGLE_TRY(ValidateSurface(display, surface));
if (buffer != EGL_BACK_BUFFER)
{
return EglBadParameter();
}
if (eglSurface == EGL_NO_SURFACE || surface->getType() == EGL_WINDOW_BIT)
{
return EglBadSurface();
}
if (surface->getTextureFormat() == TextureFormat::NoTexture)
{
return EglBadMatch();
}
return NoError();
}
Error ValidateSwapInterval(const Display *display, const Surface *draw_surface)
{
ANGLE_TRY(ValidateDisplay(display));
if (draw_surface == nullptr)
{
return EglBadSurface();
}
return NoError();
}
Error ValidateBindAPI(const EGLenum api)
{
switch (api)
{
case EGL_OPENGL_API:
case EGL_OPENVG_API:
return EglBadParameter(); // Not supported by this implementation
case EGL_OPENGL_ES_API:
break;
default:
return EglBadParameter();
}
return NoError();
}
Error ValidatePresentationTimeANDROID(const Display *display, Error ValidatePresentationTimeANDROID(const Display *display,
const Surface *surface, const Surface *surface,
EGLnsecsANDROID time) EGLnsecsANDROID time)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "common/PackedEnums.h" #include "common/PackedEnums.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/Texture.h"
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
...@@ -146,11 +147,29 @@ Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface ...@@ -146,11 +147,29 @@ Error ValidateSwapBuffers(Thread *thread, const Display *display, const Surface
Error ValidateWaitNative(const Display *display, const EGLint engine); Error ValidateWaitNative(const Display *display, const EGLint engine);
Error ValidateCopyBuffers(Display *display, const Surface *surface);
Error ValidateSwapBuffersWithDamageKHR(const Display *display, Error ValidateSwapBuffersWithDamageKHR(const Display *display,
const Surface *surface, const Surface *surface,
EGLint *rects, EGLint *rects,
EGLint n_rects); EGLint n_rects);
Error ValidateBindTexImage(const Display *display,
const Surface *surface,
const EGLSurface eglSurface,
const EGLint buffer,
const gl::Context *context,
gl::Texture **textureObject);
Error ValidateReleaseTexImage(const Display *display,
const Surface *surface,
const EGLSurface eglSurface,
const EGLint buffer);
Error ValidateSwapInterval(const Display *display, const Surface *draw_surface);
Error ValidateBindAPI(const EGLenum api);
Error ValidatePresentationTimeANDROID(const Display *display, Error ValidatePresentationTimeANDROID(const Display *display,
const Surface *surface, const Surface *surface,
EGLnsecsANDROID time); EGLnsecsANDROID time);
......
...@@ -558,20 +558,8 @@ EGLBoolean EGLAPIENTRY CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNative ...@@ -558,20 +558,8 @@ EGLBoolean EGLAPIENTRY CopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNative
Display *display = static_cast<Display *>(dpy); Display *display = static_cast<Display *>(dpy);
Surface *eglSurface = static_cast<Surface *>(surface); Surface *eglSurface = static_cast<Surface *>(surface);
Error error = ValidateSurface(display, eglSurface); ANGLE_EGL_TRY_RETURN(thread, ValidateCopyBuffers(display, eglSurface), "eglCopyBuffers",
if (error.isError()) GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
{
thread->setError(error, GetDebug(), "eglCopyBuffers",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (display->testDeviceLost())
{
thread->setError(EglContextLost(), GetDebug(), "eglCopyBuffers",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
UNIMPLEMENTED(); // FIXME UNIMPLEMENTED(); // FIXME
...@@ -588,65 +576,17 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b ...@@ -588,65 +576,17 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b
Display *display = static_cast<Display *>(dpy); Display *display = static_cast<Display *>(dpy);
Surface *eglSurface = static_cast<Surface *>(surface); Surface *eglSurface = static_cast<Surface *>(surface);
gl::Context *context = thread->getContext();
gl::Texture *textureObject = nullptr;
Error error = ValidateSurface(display, eglSurface); ANGLE_EGL_TRY_RETURN(
if (error.isError()) thread, ValidateBindTexImage(display, eglSurface, surface, buffer, context, &textureObject),
{ "eglBindTexImage", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
thread->setError(error, GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (buffer != EGL_BACK_BUFFER)
{
thread->setError(EglBadParameter(), GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE || eglSurface->getType() == EGL_WINDOW_BIT)
{
thread->setError(EglBadSurface(), GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (eglSurface->getBoundTexture())
{
thread->setError(EglBadAccess(), GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (eglSurface->getTextureFormat() == TextureFormat::NoTexture)
{
thread->setError(EglBadMatch(), GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
gl::Context *context = thread->getContext();
if (context) if (context)
{ {
gl::TextureType type = ANGLE_EGL_TRY_RETURN(thread, eglSurface->bindTexImage(context, textureObject, buffer),
egl_gl::EGLTextureTargetToTextureType(eglSurface->getTextureTarget()); "eglBindTexImage", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
gl::Texture *textureObject = context->getTargetTexture(type);
ASSERT(textureObject != nullptr);
if (textureObject->getImmutableFormat())
{
thread->setError(EglBadMatch(), GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
error = eglSurface->bindTexImage(context, textureObject, buffer);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglBindTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
} }
thread->setSuccess(); thread->setSuccess();
...@@ -667,13 +607,8 @@ EGLBoolean EGLAPIENTRY SurfaceAttrib(EGLDisplay dpy, ...@@ -667,13 +607,8 @@ EGLBoolean EGLAPIENTRY SurfaceAttrib(EGLDisplay dpy,
Display *display = static_cast<Display *>(dpy); Display *display = static_cast<Display *>(dpy);
Surface *eglSurface = static_cast<Surface *>(surface); Surface *eglSurface = static_cast<Surface *>(surface);
Error error = ValidateSurfaceAttrib(display, eglSurface, attribute, value); ANGLE_EGL_TRY_RETURN(thread, ValidateSurfaceAttrib(display, eglSurface, attribute, value),
if (error.isError()) "eglSurfaceAttrib", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
{
thread->setError(error, GetDebug(), "eglSurfaceAttrib",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
SetSurfaceAttrib(eglSurface, attribute, value); SetSurfaceAttrib(eglSurface, attribute, value);
...@@ -690,46 +625,16 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin ...@@ -690,46 +625,16 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin
Display *display = static_cast<Display *>(dpy); Display *display = static_cast<Display *>(dpy);
Surface *eglSurface = static_cast<Surface *>(surface); Surface *eglSurface = static_cast<Surface *>(surface);
Error error = ValidateSurface(display, eglSurface); ANGLE_EGL_TRY_RETURN(thread, ValidateReleaseTexImage(display, eglSurface, surface, buffer),
if (error.isError()) "eglReleaseTexImage", GetSurfaceIfValid(display, eglSurface), EGL_FALSE);
{
thread->setError(error, GetDebug(), "eglReleaseTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (buffer != EGL_BACK_BUFFER)
{
thread->setError(EglBadParameter(), GetDebug(), "eglReleaseTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (surface == EGL_NO_SURFACE || eglSurface->getType() == EGL_WINDOW_BIT)
{
thread->setError(EglBadSurface(), GetDebug(), "eglReleaseTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
if (eglSurface->getTextureFormat() == TextureFormat::NoTexture)
{
thread->setError(EglBadMatch(), GetDebug(), "eglReleaseTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
gl::Texture *texture = eglSurface->getBoundTexture(); gl::Texture *texture = eglSurface->getBoundTexture();
if (texture) if (texture)
{ {
error = eglSurface->releaseTexImage(thread->getContext(), buffer); ANGLE_EGL_TRY_RETURN(thread, eglSurface->releaseTexImage(thread->getContext(), buffer),
if (error.isError()) "eglReleaseTexImage", GetSurfaceIfValid(display, eglSurface),
{ EGL_FALSE);
thread->setError(error, GetDebug(), "eglReleaseTexImage",
GetSurfaceIfValid(display, eglSurface));
return EGL_FALSE;
}
} }
thread->setSuccess(); thread->setSuccess();
...@@ -742,22 +647,10 @@ EGLBoolean EGLAPIENTRY SwapInterval(EGLDisplay dpy, EGLint interval) ...@@ -742,22 +647,10 @@ EGLBoolean EGLAPIENTRY SwapInterval(EGLDisplay dpy, EGLint interval)
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
Display *display = static_cast<Display *>(dpy); Display *display = static_cast<Display *>(dpy);
Error error = ValidateDisplay(display);
if (error.isError())
{
thread->setError(error, GetDebug(), "eglSwapInterval", GetDisplayIfValid(display));
return EGL_FALSE;
}
Surface *draw_surface = static_cast<Surface *>(thread->getCurrentDrawSurface()); Surface *draw_surface = static_cast<Surface *>(thread->getCurrentDrawSurface());
if (draw_surface == nullptr) ANGLE_EGL_TRY_RETURN(thread, ValidateSwapInterval(display, draw_surface), "eglSwapInterval",
{ GetDisplayIfValid(display), EGL_FALSE);
thread->setError(EglBadSurface(), GetDebug(), "eglSwapInterval",
GetDisplayIfValid(display));
return EGL_FALSE;
}
const egl::Config *surfaceConfig = draw_surface->getConfig(); const egl::Config *surfaceConfig = draw_surface->getConfig();
EGLint clampedInterval = std::min(std::max(interval, surfaceConfig->minSwapInterval), EGLint clampedInterval = std::min(std::max(interval, surfaceConfig->minSwapInterval),
...@@ -775,18 +668,8 @@ EGLBoolean EGLAPIENTRY BindAPI(EGLenum api) ...@@ -775,18 +668,8 @@ EGLBoolean EGLAPIENTRY BindAPI(EGLenum api)
EVENT("(EGLenum api = 0x%X)", api); EVENT("(EGLenum api = 0x%X)", api);
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
switch (api) ANGLE_EGL_TRY_RETURN(thread, ValidateBindAPI(api), "eglBindAPI", GetThreadIfValid(thread),
{ EGL_FALSE);
case EGL_OPENGL_API:
case EGL_OPENVG_API:
thread->setError(EglBadParameter(), GetDebug(), "eglBindAPI", GetThreadIfValid(thread));
return EGL_FALSE; // Not supported by this implementation
case EGL_OPENGL_ES_API:
break;
default:
thread->setError(EglBadParameter(), GetDebug(), "eglBindAPI", GetThreadIfValid(thread));
return EGL_FALSE;
}
thread->setAPI(api); thread->setAPI(api);
...@@ -821,24 +704,17 @@ EGLSurface EGLAPIENTRY CreatePbufferFromClientBuffer(EGLDisplay dpy, ...@@ -821,24 +704,17 @@ EGLSurface EGLAPIENTRY CreatePbufferFromClientBuffer(EGLDisplay dpy,
Config *configuration = static_cast<Config *>(config); Config *configuration = static_cast<Config *>(config);
AttributeMap attributes = AttributeMap::CreateFromIntArray(attrib_list); AttributeMap attributes = AttributeMap::CreateFromIntArray(attrib_list);
Error error = ANGLE_EGL_TRY_RETURN(
ValidateCreatePbufferFromClientBuffer(display, buftype, buffer, configuration, attributes); thread,
if (error.isError()) ValidateCreatePbufferFromClientBuffer(display, buftype, buffer, configuration, attributes),
{ "eglCreatePbufferFromClientBuffer", GetDisplayIfValid(display), EGL_NO_SURFACE);
thread->setError(error, GetDebug(), "eglCreatePbufferFromClientBuffer",
GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
egl::Surface *surface = nullptr; egl::Surface *surface = nullptr;
error = display->createPbufferFromClientBuffer(configuration, buftype, buffer, attributes, ANGLE_EGL_TRY_RETURN(thread,
&surface); display->createPbufferFromClientBuffer(configuration, buftype, buffer,
if (error.isError()) attributes, &surface),
{ "eglCreatePbufferFromClientBuffer", GetDisplayIfValid(display),
thread->setError(error, GetDebug(), "eglCreatePbufferFromClientBuffer", EGL_NO_SURFACE);
GetDisplayIfValid(display));
return EGL_NO_SURFACE;
}
return static_cast<EGLSurface>(surface); return static_cast<EGLSurface>(surface);
} }
...@@ -862,19 +738,11 @@ EGLBoolean EGLAPIENTRY WaitClient(void) ...@@ -862,19 +738,11 @@ EGLBoolean EGLAPIENTRY WaitClient(void)
Display *display = thread->getCurrentDisplay(); Display *display = thread->getCurrentDisplay();
gl::Context *context = thread->getContext(); gl::Context *context = thread->getContext();
Error error = ValidateDisplay(display); ANGLE_EGL_TRY_RETURN(thread, ValidateDisplay(display), "eglWaitClient",
if (error.isError()) GetContextIfValid(display, context), EGL_FALSE);
{
thread->setError(error, GetDebug(), "eglWaitClient", GetContextIfValid(display, context));
return EGL_FALSE;
}
error = display->waitClient(context); ANGLE_EGL_TRY_RETURN(thread, display->waitClient(context), "eglWaitClient",
if (error.isError()) GetContextIfValid(display, context), EGL_FALSE);
{
thread->setError(error, GetDebug(), "eglWaitClient", GetContextIfValid(display, context));
return EGL_FALSE;
}
thread->setSuccess(); thread->setSuccess();
return EGL_TRUE; return EGL_TRUE;
...@@ -994,12 +862,8 @@ EGLDisplay EGLAPIENTRY GetPlatformDisplay(EGLenum platform, ...@@ -994,12 +862,8 @@ EGLDisplay EGLAPIENTRY GetPlatformDisplay(EGLenum platform,
platform, native_display, attrib_list); platform, native_display, attrib_list);
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
Error err = ValidateGetPlatformDisplay(platform, native_display, attrib_list); ANGLE_EGL_TRY_RETURN(thread, ValidateGetPlatformDisplay(platform, native_display, attrib_list),
thread->setError(err, GetDebug(), "eglGetPlatformDisplay", GetThreadIfValid(thread)); "eglGetPlatformDisplay", GetThreadIfValid(thread), EGL_NO_DISPLAY);
if (err.isError())
{
return EGL_NO_DISPLAY;
}
const auto &attribMap = AttributeMap::CreateFromAttribArray(attrib_list); const auto &attribMap = AttributeMap::CreateFromAttribArray(attrib_list);
if (platform == EGL_PLATFORM_ANGLE_ANGLE) if (platform == EGL_PLATFORM_ANGLE_ANGLE)
......
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