OSDN Git Service

Fix retrieving the current Display.
authorNicolas Capens <capn@google.com>
Mon, 10 Jul 2017 18:26:17 +0000 (14:26 -0400)
committerNicolas Capens <capn@google.com>
Tue, 11 Jul 2017 16:41:54 +0000 (16:41 +0000)
eglGetCurrentDisplay() returned a pointer to the concrete egl::Display
object, instead of the opaque identifier obtained from eglGetDisplay.
This was a regression caused by
https://swiftshader-review.googlesource.com/10188

Bug chromium:738298

Change-Id: Id3a87fc3978f8f4efdc77d6c5eaa85743fa3672c
Reviewed-on: https://swiftshader-review.googlesource.com/10508
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
src/OpenGL/libEGL/Display.cpp
src/OpenGL/libEGL/Display.h
src/OpenGL/libEGL/libEGL.cpp
tests/unittests/unittests.cpp

index a4aacfd..b08fa65 100644 (file)
@@ -46,7 +46,7 @@ namespace egl
 class DisplayImplementation : public Display
 {
 public:
-       DisplayImplementation(void *nativeDisplay) : Display(nativeDisplay) {}
+       DisplayImplementation(EGLDisplay dpy, void *nativeDisplay) : Display(dpy, nativeDisplay) {}
        ~DisplayImplementation() override {}
 
        Image *getSharedImage(EGLImageKHR name) override
@@ -72,12 +72,12 @@ Display *Display::get(EGLDisplay dpy)
                }
        #endif
 
-       static DisplayImplementation display(nativeDisplay);
+       static DisplayImplementation display(dpy, nativeDisplay);
 
        return &display;
 }
 
-Display::Display(void *nativeDisplay) : nativeDisplay(nativeDisplay)
+Display::Display(EGLDisplay eglDisplay, void *nativeDisplay) : eglDisplay(eglDisplay), nativeDisplay(nativeDisplay)
 {
        mMinSwapInterval = 1;
        mMaxSwapInterval = 1;
@@ -610,6 +610,11 @@ EGLint Display::getMaxSwapInterval() const
        return mMaxSwapInterval;
 }
 
+EGLDisplay Display::getEGLDisplay() const
+{
+       return eglDisplay;
+}
+
 void *Display::getNativeDisplay() const
 {
        return nativeDisplay;
index ba6b92c..5944d69 100644 (file)
@@ -38,7 +38,7 @@ namespace egl
        class [[clang::lto_visibility_public]] Display
        {
        protected:
-               explicit Display(void *nativeDisplay);
+               explicit Display(EGLDisplay eglDisplay, void *nativeDisplay);
                virtual ~Display() = 0;
 
        public:
@@ -70,6 +70,7 @@ namespace egl
                EGLint getMinSwapInterval() const;
                EGLint getMaxSwapInterval() const;
 
+               EGLDisplay getEGLDisplay() const;
                void *getNativeDisplay() const;
 
                EGLImageKHR createSharedImage(Image *image);
@@ -79,6 +80,7 @@ namespace egl
        private:
                sw::Format getDisplayFormat() const;
 
+               const EGLDisplay eglDisplay;
                void *const nativeDisplay;
 
                EGLint mMaxSwapInterval;
index c7a4127..3a62da0 100644 (file)
@@ -862,7 +862,14 @@ EGLDisplay GetCurrentDisplay(void)
                return success(EGL_NO_DISPLAY);
        }
 
-       return success(context->getDisplay());
+       egl::Display *display = context->getDisplay();
+
+       if(!display)
+       {
+               return error(EGL_BAD_ACCESS, EGL_NO_DISPLAY);
+       }
+
+       return success(display->getEGLDisplay());
 }
 
 EGLBoolean QueryContext(EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint *value)
index d93123b..8861424 100644 (file)
@@ -117,7 +117,7 @@ TEST_F(SwiftShaderTest, Initalization)
 
        EGLContext context = eglCreateContext(display, config, NULL, contextAttributes);
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
-       EXPECT_NE(EGL_NO_SURFACE, surface);
+       EXPECT_NE(EGL_NO_CONTEXT, context);
 
        success = eglMakeCurrent(display, surface, surface, context);
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
@@ -125,19 +125,19 @@ TEST_F(SwiftShaderTest, Initalization)
 
        EGLDisplay currentDisplay = eglGetCurrentDisplay();
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
-       EXPECT_NE(EGL_NO_DISPLAY, currentDisplay);
+       EXPECT_EQ(display, currentDisplay);
 
        EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW);
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
-       EXPECT_NE(EGL_NO_SURFACE, currentDrawSurface);
+       EXPECT_EQ(surface, currentDrawSurface);
 
        EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ);
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
-       EXPECT_NE(EGL_NO_SURFACE, currentReadSurface);
+       EXPECT_EQ(surface, currentReadSurface);
 
        EGLContext currentContext = eglGetCurrentContext();
        EXPECT_EQ(EGL_SUCCESS, eglGetError());
-       EXPECT_NE(EGL_NO_CONTEXT, currentContext);
+       EXPECT_EQ(context, currentContext);
 
        EXPECT_EQ((GLenum)GL_NO_ERROR, glGetError());