Commit 61e16b44 by Jamie Madill

Context: Bind current display/surface.

Looking at the EGL spec, it says for eglGetCurrentDisplay: "The display for the current context in the calling thread, for the current rendering API, is returned." This implies that MakeCurrent binds a display to a Context. There's also pretty clear language for the read/draw Surface as well, that they can only be bound to one Context/thread at a time. Hence we don't need to duplicate this storage in the egl::Thread structure, merely storing a pointer to the current Context, which has access to the read/draw Surface and current Display. BUG=angleproject:1156 Change-Id: Ia3b99d50b3591012c43e851834c1af02ff62a33f Reviewed-on: https://chromium-review.googlesource.com/538865Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 12b0b399
......@@ -266,7 +266,8 @@ Context::Context(rx::EGLImplFactory *implFactory,
mContextLostForced(false),
mResetStrategy(GetResetStrategy(attribs)),
mRobustAccess(GetRobustAccess(attribs)),
mCurrentSurface(nullptr),
mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
mSurfacelessFramebuffer(nullptr),
mWebGLContext(GetWebGLContext(attribs)),
mScratchBuffer(1000u)
......@@ -460,6 +461,8 @@ Context::~Context()
void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{
mCurrentDisplay = display;
if (!mHasBeenCurrent)
{
initRendererString();
......
......@@ -800,6 +800,10 @@ class Context final : public ValidationContext
GLsizei height,
GLsizei depth);
egl::Display *getCurrentDisplay() const { return mCurrentDisplay; }
egl::Surface *getCurrentDrawSurface() const { return mCurrentSurface; }
egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; }
private:
void syncRendererState();
void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask);
......@@ -879,6 +883,7 @@ class Context final : public ValidationContext
GLenum mResetStrategy;
bool mRobustAccess;
egl::Surface *mCurrentSurface;
egl::Display *mCurrentDisplay;
Framebuffer *mSurfacelessFramebuffer;
bool mWebGLContext;
......
......@@ -16,9 +16,6 @@ namespace egl
Thread::Thread()
: mError(EGL_SUCCESS),
mAPI(EGL_OPENGL_ES_API),
mDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
mDrawSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mReadSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mContext(static_cast<gl::Context *>(EGL_NO_CONTEXT))
{
}
......@@ -43,30 +40,27 @@ EGLenum Thread::getAPI() const
return mAPI;
}
void Thread::setCurrent(Display *display,
Surface *drawSurface,
Surface *readSurface,
gl::Context *context)
void Thread::setCurrent(gl::Context *context)
{
mDisplay = display;
mDrawSurface = drawSurface;
mReadSurface = readSurface;
mContext = context;
mContext = context;
}
Display *Thread::getDisplay() const
Surface *Thread::getCurrentDrawSurface() const
{
return mDisplay;
}
Surface *Thread::getDrawSurface() const
{
return mDrawSurface;
if (mContext)
{
return mContext->getCurrentDrawSurface();
}
return nullptr;
}
Surface *Thread::getReadSurface() const
Surface *Thread::getCurrentReadSurface() const
{
return mReadSurface;
if (mContext)
{
return mContext->getCurrentReadSurface();
}
return nullptr;
}
gl::Context *Thread::getContext() const
......@@ -85,4 +79,13 @@ gl::Context *Thread::getValidContext() const
return mContext;
}
Display *Thread::getCurrentDisplay() const
{
if (mContext)
{
return mContext->getCurrentDisplay();
}
return nullptr;
}
} // namespace egl
......@@ -33,22 +33,16 @@ class Thread
void setAPI(EGLenum api);
EGLenum getAPI() const;
void setCurrent(Display *display,
Surface *drawSurface,
Surface *readSurface,
gl::Context *context);
Display *getDisplay() const;
Surface *getDrawSurface() const;
Surface *getReadSurface() const;
void setCurrent(gl::Context *context);
Surface *getCurrentDrawSurface() const;
Surface *getCurrentReadSurface() const;
gl::Context *getContext() const;
gl::Context *getValidContext() const;
Display *getCurrentDisplay() const;
private:
EGLint mError;
EGLenum mAPI;
egl::Display *mDisplay;
egl::Surface *mDrawSurface;
egl::Surface *mReadSurface;
gl::Context *mContext;
};
......
......@@ -3361,7 +3361,6 @@ bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *ma
}
bool ValidateEGLImageTargetTexture2DOES(Context *context,
egl::Display *display,
GLenum target,
egl::Image *image)
{
......@@ -3394,7 +3393,8 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context,
return false;
}
if (!display->isValidImage(image))
ASSERT(context->getCurrentDisplay());
if (!context->getCurrentDisplay()->isValidImage(image))
{
context->handleError(InvalidValue() << "EGL image is not valid.");
return false;
......@@ -3420,7 +3420,6 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context,
}
bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
egl::Display *display,
GLenum target,
egl::Image *image)
{
......@@ -3440,7 +3439,8 @@ bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
return false;
}
if (!display->isValidImage(image))
ASSERT(context->getCurrentDisplay());
if (!context->getCurrentDisplay()->isValidImage(image))
{
context->handleError(InvalidValue() << "EGL image is not valid.");
return false;
......
......@@ -342,11 +342,9 @@ bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *
bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker);
bool ValidateEGLImageTargetTexture2DOES(Context *context,
egl::Display *display,
GLenum target,
egl::Image *image);
bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
egl::Display *display,
GLenum target,
egl::Image *image);
......
......@@ -115,7 +115,7 @@ EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy)
if (display->isValidContext(thread->getContext()))
{
thread->setCurrent(nullptr, nullptr, nullptr, nullptr);
thread->setCurrent(nullptr);
}
display->terminate();
......@@ -564,7 +564,7 @@ EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx)
if (context == thread->getContext())
{
thread->setCurrent(nullptr, thread->getDrawSurface(), thread->getReadSurface(), nullptr);
thread->setCurrent(nullptr);
}
display->destroyContext(context);
......@@ -601,7 +601,7 @@ EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface r
}
gl::Context *previousContext = thread->getContext();
thread->setCurrent(display, drawSurface, readSurface, context);
thread->setCurrent(context);
// Release the surface from the previously-current context, to allow
// destroyed surfaces to delete themselves.
......@@ -622,12 +622,12 @@ EGLSurface EGLAPIENTRY GetCurrentSurface(EGLint readdraw)
if (readdraw == EGL_READ)
{
thread->setError(NoError());
return thread->getReadSurface();
return thread->getCurrentReadSurface();
}
else if (readdraw == EGL_DRAW)
{
thread->setError(NoError());
return thread->getDrawSurface();
return thread->getCurrentDrawSurface();
}
else
{
......@@ -641,10 +641,12 @@ EGLDisplay EGLAPIENTRY GetCurrentDisplay(void)
EVENT("()");
Thread *thread = GetCurrentThread();
EGLDisplay dpy = thread->getDisplay();
thread->setError(NoError());
return dpy;
if (thread->getContext() != nullptr)
{
return thread->getContext()->getCurrentDisplay();
}
return EGL_NO_DISPLAY;
}
EGLBoolean EGLAPIENTRY QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
......@@ -693,7 +695,7 @@ EGLBoolean EGLAPIENTRY WaitGL(void)
EVENT("()");
Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay();
Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
......@@ -720,7 +722,7 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
EVENT("(EGLint engine = %d)", engine);
Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay();
Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
......@@ -734,7 +736,8 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
thread->setError(EglBadParameter() << "the 'engine' parameter has an unrecognized value");
}
error = display->waitNative(engine, thread->getDrawSurface(), thread->getReadSurface());
error = display->waitNative(engine, thread->getCurrentDrawSurface(),
thread->getCurrentReadSurface());
if (error.isError())
{
thread->setError(error);
......@@ -969,7 +972,7 @@ EGLBoolean EGLAPIENTRY SwapInterval(EGLDisplay dpy, EGLint interval)
return EGL_FALSE;
}
Surface *draw_surface = static_cast<Surface *>(thread->getDrawSurface());
Surface *draw_surface = static_cast<Surface *>(thread->getCurrentDrawSurface());
if (draw_surface == nullptr)
{
......@@ -1075,7 +1078,7 @@ EGLBoolean EGLAPIENTRY WaitClient(void)
EVENT("()");
Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay();
Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display);
if (error.isError())
......
......@@ -784,4 +784,4 @@ ANGLE_EXPORT EGLBoolean SwapBuffersWithDamageEXT(EGLDisplay dpy,
return EGL_TRUE;
}
}
} // namespace egl
......@@ -1023,13 +1023,11 @@ ANGLE_EXPORT void GL_APIENTRY EGLImageTargetTexture2DOES(GLenum target, GLeglIma
{
EVENT("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image);
egl::Thread *thread = egl::GetCurrentThread();
Context *context = thread->getValidContext();
Context *context = GetValidGlobalContext();
if (context)
{
egl::Display *display = thread->getDisplay();
egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
if (!ValidateEGLImageTargetTexture2DOES(context, display, target, imageObject))
if (!ValidateEGLImageTargetTexture2DOES(context, target, imageObject))
{
return;
}
......@@ -1049,13 +1047,11 @@ ANGLE_EXPORT void GL_APIENTRY EGLImageTargetRenderbufferStorageOES(GLenum target
{
EVENT("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image);
egl::Thread *thread = egl::GetCurrentThread();
Context *context = thread->getValidContext();
Context *context = GetValidGlobalContext();
if (context)
{
egl::Display *display = thread->getDisplay();
egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
if (!ValidateEGLImageTargetRenderbufferStorageOES(context, display, target, imageObject))
if (!ValidateEGLImageTargetRenderbufferStorageOES(context, target, imageObject))
{
return;
}
......
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