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, ...@@ -266,7 +266,8 @@ Context::Context(rx::EGLImplFactory *implFactory,
mContextLostForced(false), mContextLostForced(false),
mResetStrategy(GetResetStrategy(attribs)), mResetStrategy(GetResetStrategy(attribs)),
mRobustAccess(GetRobustAccess(attribs)), mRobustAccess(GetRobustAccess(attribs)),
mCurrentSurface(nullptr), mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
mSurfacelessFramebuffer(nullptr), mSurfacelessFramebuffer(nullptr),
mWebGLContext(GetWebGLContext(attribs)), mWebGLContext(GetWebGLContext(attribs)),
mScratchBuffer(1000u) mScratchBuffer(1000u)
...@@ -460,6 +461,8 @@ Context::~Context() ...@@ -460,6 +461,8 @@ Context::~Context()
void Context::makeCurrent(egl::Display *display, egl::Surface *surface) void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
{ {
mCurrentDisplay = display;
if (!mHasBeenCurrent) if (!mHasBeenCurrent)
{ {
initRendererString(); initRendererString();
......
...@@ -800,6 +800,10 @@ class Context final : public ValidationContext ...@@ -800,6 +800,10 @@ class Context final : public ValidationContext
GLsizei height, GLsizei height,
GLsizei depth); GLsizei depth);
egl::Display *getCurrentDisplay() const { return mCurrentDisplay; }
egl::Surface *getCurrentDrawSurface() const { return mCurrentSurface; }
egl::Surface *getCurrentReadSurface() const { return mCurrentSurface; }
private: private:
void syncRendererState(); void syncRendererState();
void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask); void syncRendererState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask);
...@@ -879,6 +883,7 @@ class Context final : public ValidationContext ...@@ -879,6 +883,7 @@ class Context final : public ValidationContext
GLenum mResetStrategy; GLenum mResetStrategy;
bool mRobustAccess; bool mRobustAccess;
egl::Surface *mCurrentSurface; egl::Surface *mCurrentSurface;
egl::Display *mCurrentDisplay;
Framebuffer *mSurfacelessFramebuffer; Framebuffer *mSurfacelessFramebuffer;
bool mWebGLContext; bool mWebGLContext;
......
...@@ -16,9 +16,6 @@ namespace egl ...@@ -16,9 +16,6 @@ namespace egl
Thread::Thread() Thread::Thread()
: mError(EGL_SUCCESS), : mError(EGL_SUCCESS),
mAPI(EGL_OPENGL_ES_API), 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)) mContext(static_cast<gl::Context *>(EGL_NO_CONTEXT))
{ {
} }
...@@ -43,30 +40,27 @@ EGLenum Thread::getAPI() const ...@@ -43,30 +40,27 @@ EGLenum Thread::getAPI() const
return mAPI; return mAPI;
} }
void Thread::setCurrent(Display *display, void Thread::setCurrent(gl::Context *context)
Surface *drawSurface,
Surface *readSurface,
gl::Context *context)
{ {
mDisplay = display; mContext = context;
mDrawSurface = drawSurface;
mReadSurface = readSurface;
mContext = context;
} }
Display *Thread::getDisplay() const Surface *Thread::getCurrentDrawSurface() const
{ {
return mDisplay; if (mContext)
} {
return mContext->getCurrentDrawSurface();
Surface *Thread::getDrawSurface() const }
{ return nullptr;
return mDrawSurface;
} }
Surface *Thread::getReadSurface() const Surface *Thread::getCurrentReadSurface() const
{ {
return mReadSurface; if (mContext)
{
return mContext->getCurrentReadSurface();
}
return nullptr;
} }
gl::Context *Thread::getContext() const gl::Context *Thread::getContext() const
...@@ -85,4 +79,13 @@ gl::Context *Thread::getValidContext() const ...@@ -85,4 +79,13 @@ gl::Context *Thread::getValidContext() const
return mContext; return mContext;
} }
Display *Thread::getCurrentDisplay() const
{
if (mContext)
{
return mContext->getCurrentDisplay();
}
return nullptr;
}
} // namespace egl } // namespace egl
...@@ -33,22 +33,16 @@ class Thread ...@@ -33,22 +33,16 @@ class Thread
void setAPI(EGLenum api); void setAPI(EGLenum api);
EGLenum getAPI() const; EGLenum getAPI() const;
void setCurrent(Display *display, void setCurrent(gl::Context *context);
Surface *drawSurface, Surface *getCurrentDrawSurface() const;
Surface *readSurface, Surface *getCurrentReadSurface() const;
gl::Context *context);
Display *getDisplay() const;
Surface *getDrawSurface() const;
Surface *getReadSurface() const;
gl::Context *getContext() const; gl::Context *getContext() const;
gl::Context *getValidContext() const; gl::Context *getValidContext() const;
Display *getCurrentDisplay() const;
private: private:
EGLint mError; EGLint mError;
EGLenum mAPI; EGLenum mAPI;
egl::Display *mDisplay;
egl::Surface *mDrawSurface;
egl::Surface *mReadSurface;
gl::Context *mContext; gl::Context *mContext;
}; };
......
...@@ -3361,7 +3361,6 @@ bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *ma ...@@ -3361,7 +3361,6 @@ bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *ma
} }
bool ValidateEGLImageTargetTexture2DOES(Context *context, bool ValidateEGLImageTargetTexture2DOES(Context *context,
egl::Display *display,
GLenum target, GLenum target,
egl::Image *image) egl::Image *image)
{ {
...@@ -3394,7 +3393,8 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context, ...@@ -3394,7 +3393,8 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context,
return false; return false;
} }
if (!display->isValidImage(image)) ASSERT(context->getCurrentDisplay());
if (!context->getCurrentDisplay()->isValidImage(image))
{ {
context->handleError(InvalidValue() << "EGL image is not valid."); context->handleError(InvalidValue() << "EGL image is not valid.");
return false; return false;
...@@ -3420,7 +3420,6 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context, ...@@ -3420,7 +3420,6 @@ bool ValidateEGLImageTargetTexture2DOES(Context *context,
} }
bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
egl::Display *display,
GLenum target, GLenum target,
egl::Image *image) egl::Image *image)
{ {
...@@ -3440,7 +3439,8 @@ bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, ...@@ -3440,7 +3439,8 @@ bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
return false; return false;
} }
if (!display->isValidImage(image)) ASSERT(context->getCurrentDisplay());
if (!context->getCurrentDisplay()->isValidImage(image))
{ {
context->handleError(InvalidValue() << "EGL image is not valid."); context->handleError(InvalidValue() << "EGL image is not valid.");
return false; return false;
......
...@@ -342,11 +342,9 @@ bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char * ...@@ -342,11 +342,9 @@ bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *
bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker); bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker);
bool ValidateEGLImageTargetTexture2DOES(Context *context, bool ValidateEGLImageTargetTexture2DOES(Context *context,
egl::Display *display,
GLenum target, GLenum target,
egl::Image *image); egl::Image *image);
bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context,
egl::Display *display,
GLenum target, GLenum target,
egl::Image *image); egl::Image *image);
......
...@@ -115,7 +115,7 @@ EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy) ...@@ -115,7 +115,7 @@ EGLBoolean EGLAPIENTRY Terminate(EGLDisplay dpy)
if (display->isValidContext(thread->getContext())) if (display->isValidContext(thread->getContext()))
{ {
thread->setCurrent(nullptr, nullptr, nullptr, nullptr); thread->setCurrent(nullptr);
} }
display->terminate(); display->terminate();
...@@ -564,7 +564,7 @@ EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx) ...@@ -564,7 +564,7 @@ EGLBoolean EGLAPIENTRY DestroyContext(EGLDisplay dpy, EGLContext ctx)
if (context == thread->getContext()) if (context == thread->getContext())
{ {
thread->setCurrent(nullptr, thread->getDrawSurface(), thread->getReadSurface(), nullptr); thread->setCurrent(nullptr);
} }
display->destroyContext(context); display->destroyContext(context);
...@@ -601,7 +601,7 @@ EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface r ...@@ -601,7 +601,7 @@ EGLBoolean EGLAPIENTRY MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface r
} }
gl::Context *previousContext = thread->getContext(); gl::Context *previousContext = thread->getContext();
thread->setCurrent(display, drawSurface, readSurface, context); thread->setCurrent(context);
// Release the surface from the previously-current context, to allow // Release the surface from the previously-current context, to allow
// destroyed surfaces to delete themselves. // destroyed surfaces to delete themselves.
...@@ -622,12 +622,12 @@ EGLSurface EGLAPIENTRY GetCurrentSurface(EGLint readdraw) ...@@ -622,12 +622,12 @@ EGLSurface EGLAPIENTRY GetCurrentSurface(EGLint readdraw)
if (readdraw == EGL_READ) if (readdraw == EGL_READ)
{ {
thread->setError(NoError()); thread->setError(NoError());
return thread->getReadSurface(); return thread->getCurrentReadSurface();
} }
else if (readdraw == EGL_DRAW) else if (readdraw == EGL_DRAW)
{ {
thread->setError(NoError()); thread->setError(NoError());
return thread->getDrawSurface(); return thread->getCurrentDrawSurface();
} }
else else
{ {
...@@ -641,10 +641,12 @@ EGLDisplay EGLAPIENTRY GetCurrentDisplay(void) ...@@ -641,10 +641,12 @@ EGLDisplay EGLAPIENTRY GetCurrentDisplay(void)
EVENT("()"); EVENT("()");
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
EGLDisplay dpy = thread->getDisplay();
thread->setError(NoError()); 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) EGLBoolean EGLAPIENTRY QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
...@@ -693,7 +695,7 @@ EGLBoolean EGLAPIENTRY WaitGL(void) ...@@ -693,7 +695,7 @@ EGLBoolean EGLAPIENTRY WaitGL(void)
EVENT("()"); EVENT("()");
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay(); Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display); Error error = ValidateDisplay(display);
if (error.isError()) if (error.isError())
...@@ -720,7 +722,7 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine) ...@@ -720,7 +722,7 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
EVENT("(EGLint engine = %d)", engine); EVENT("(EGLint engine = %d)", engine);
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay(); Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display); Error error = ValidateDisplay(display);
if (error.isError()) if (error.isError())
...@@ -734,7 +736,8 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine) ...@@ -734,7 +736,8 @@ EGLBoolean EGLAPIENTRY WaitNative(EGLint engine)
thread->setError(EglBadParameter() << "the 'engine' parameter has an unrecognized value"); 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()) if (error.isError())
{ {
thread->setError(error); thread->setError(error);
...@@ -969,7 +972,7 @@ EGLBoolean EGLAPIENTRY SwapInterval(EGLDisplay dpy, EGLint interval) ...@@ -969,7 +972,7 @@ EGLBoolean EGLAPIENTRY SwapInterval(EGLDisplay dpy, EGLint interval)
return EGL_FALSE; return EGL_FALSE;
} }
Surface *draw_surface = static_cast<Surface *>(thread->getDrawSurface()); Surface *draw_surface = static_cast<Surface *>(thread->getCurrentDrawSurface());
if (draw_surface == nullptr) if (draw_surface == nullptr)
{ {
...@@ -1075,7 +1078,7 @@ EGLBoolean EGLAPIENTRY WaitClient(void) ...@@ -1075,7 +1078,7 @@ EGLBoolean EGLAPIENTRY WaitClient(void)
EVENT("()"); EVENT("()");
Thread *thread = GetCurrentThread(); Thread *thread = GetCurrentThread();
Display *display = thread->getDisplay(); Display *display = thread->getCurrentDisplay();
Error error = ValidateDisplay(display); Error error = ValidateDisplay(display);
if (error.isError()) if (error.isError())
......
...@@ -784,4 +784,4 @@ ANGLE_EXPORT EGLBoolean SwapBuffersWithDamageEXT(EGLDisplay dpy, ...@@ -784,4 +784,4 @@ ANGLE_EXPORT EGLBoolean SwapBuffersWithDamageEXT(EGLDisplay dpy,
return EGL_TRUE; return EGL_TRUE;
} }
} } // namespace egl
...@@ -1023,13 +1023,11 @@ ANGLE_EXPORT void GL_APIENTRY EGLImageTargetTexture2DOES(GLenum target, GLeglIma ...@@ -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); EVENT("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image);
egl::Thread *thread = egl::GetCurrentThread(); Context *context = GetValidGlobalContext();
Context *context = thread->getValidContext();
if (context) if (context)
{ {
egl::Display *display = thread->getDisplay();
egl::Image *imageObject = reinterpret_cast<egl::Image *>(image); egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
if (!ValidateEGLImageTargetTexture2DOES(context, display, target, imageObject)) if (!ValidateEGLImageTargetTexture2DOES(context, target, imageObject))
{ {
return; return;
} }
...@@ -1049,13 +1047,11 @@ ANGLE_EXPORT void GL_APIENTRY EGLImageTargetRenderbufferStorageOES(GLenum target ...@@ -1049,13 +1047,11 @@ ANGLE_EXPORT void GL_APIENTRY EGLImageTargetRenderbufferStorageOES(GLenum target
{ {
EVENT("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image); EVENT("(GLenum target = 0x%X, GLeglImageOES image = 0x%0.8p)", target, image);
egl::Thread *thread = egl::GetCurrentThread(); Context *context = GetValidGlobalContext();
Context *context = thread->getValidContext();
if (context) if (context)
{ {
egl::Display *display = thread->getDisplay();
egl::Image *imageObject = reinterpret_cast<egl::Image *>(image); egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
if (!ValidateEGLImageTargetRenderbufferStorageOES(context, display, target, imageObject)) if (!ValidateEGLImageTargetRenderbufferStorageOES(context, target, imageObject))
{ {
return; 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