Commit 9d3ae5fe by Geoff Lang

Use the Surface type for validation and fix incorrect window validation.

The window passed to surface creation should not be used by any surface owned by any display, not just the current one. Store a global window surface list for validation. BUG=angleproject:795 Change-Id: I2314979f2f27848b21fcb00676194d7671d1db68 Reviewed-on: https://chromium-review.googlesource.com/260942Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 4b91262a
...@@ -79,6 +79,15 @@ void DeinitDefaultPlatformImpl() ...@@ -79,6 +79,15 @@ void DeinitDefaultPlatformImpl()
} }
} }
typedef std::map<EGLNativeWindowType, Surface*> WindowSurfaceMap;
// Get a map of all EGL window surfaces to validate that no window has more than one EGL surface
// associated with it.
static WindowSurfaceMap *GetWindowSurfaces()
{
static WindowSurfaceMap windowSurfaces;
return &windowSurfaces;
}
typedef std::map<EGLNativeDisplayType, Display*> DisplayMap; typedef std::map<EGLNativeDisplayType, Display*> DisplayMap;
static DisplayMap *GetDisplayMap() static DisplayMap *GetDisplayMap()
{ {
...@@ -330,6 +339,10 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT ...@@ -330,6 +339,10 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT
Surface *surface = new Surface(surfaceImpl, EGL_WINDOW_BIT, configuration, attribs); Surface *surface = new Surface(surfaceImpl, EGL_WINDOW_BIT, configuration, attribs);
mImplementation->getSurfaceSet().insert(surface); mImplementation->getSurfaceSet().insert(surface);
WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
ASSERT(windowSurfaces && windowSurfaces->find(window) == windowSurfaces->end());
windowSurfaces->insert(std::make_pair(window, surface));
ASSERT(outSurface != nullptr); ASSERT(outSurface != nullptr);
*outSurface = surface; *outSurface = surface;
return Error(EGL_SUCCESS); return Error(EGL_SUCCESS);
...@@ -455,6 +468,25 @@ Error Display::restoreLostDevice() ...@@ -455,6 +468,25 @@ Error Display::restoreLostDevice()
void Display::destroySurface(Surface *surface) void Display::destroySurface(Surface *surface)
{ {
if (surface->getType() == EGL_WINDOW_BIT)
{
WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
ASSERT(windowSurfaces);
bool surfaceRemoved = false;
for (WindowSurfaceMap::iterator iter = windowSurfaces->begin(); iter != windowSurfaces->end(); iter++)
{
if (iter->second == surface)
{
windowSurfaces->erase(iter);
surfaceRemoved = true;
break;
}
}
ASSERT(surfaceRemoved);
}
mImplementation->destroySurface(surface); mImplementation->destroySurface(surface);
} }
...@@ -509,17 +541,12 @@ bool Display::isValidSurface(Surface *surface) const ...@@ -509,17 +541,12 @@ bool Display::isValidSurface(Surface *surface) const
return mImplementation->getSurfaceSet().find(surface) != mImplementation->getSurfaceSet().end(); return mImplementation->getSurfaceSet().find(surface) != mImplementation->getSurfaceSet().end();
} }
bool Display::hasExistingWindowSurface(EGLNativeWindowType window) const bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{ {
for (const auto &surfaceIt : mImplementation->getSurfaceSet()) WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
{ ASSERT(windowSurfaces);
if (surfaceIt->getWindowHandle() == window)
{
return true;
}
}
return false; return windowSurfaces->find(window) != windowSurfaces->end();
} }
static ClientExtensions GenerateClientExtensions() static ClientExtensions GenerateClientExtensions()
......
...@@ -67,10 +67,10 @@ class Display final ...@@ -67,10 +67,10 @@ class Display final
bool isValidConfig(const Config *config) const; bool isValidConfig(const Config *config) const;
bool isValidContext(gl::Context *context) const; bool isValidContext(gl::Context *context) const;
bool isValidSurface(egl::Surface *surface) const; bool isValidSurface(egl::Surface *surface) const;
bool hasExistingWindowSurface(EGLNativeWindowType window) const;
bool isValidNativeWindow(EGLNativeWindowType window) const; bool isValidNativeWindow(EGLNativeWindowType window) const;
static bool isValidNativeDisplay(EGLNativeDisplayType display); static bool isValidNativeDisplay(EGLNativeDisplayType display);
static bool hasExistingWindowSurface(EGLNativeWindowType window);
bool isDeviceLost() const; bool isDeviceLost() const;
bool testDeviceLost(); bool testDeviceLost();
......
...@@ -49,11 +49,6 @@ EGLint Surface::getType() const ...@@ -49,11 +49,6 @@ EGLint Surface::getType() const
return mType; return mType;
} }
EGLNativeWindowType Surface::getWindowHandle() const
{
return mImplementation->getWindowHandle();
}
Error Surface::swap() Error Surface::swap()
{ {
return mImplementation->swap(); return mImplementation->swap();
......
...@@ -49,8 +49,6 @@ class Surface final ...@@ -49,8 +49,6 @@ class Surface final
Error bindTexImage(gl::Texture *texture, EGLint buffer); Error bindTexImage(gl::Texture *texture, EGLint buffer);
Error releaseTexImage(EGLint buffer); Error releaseTexImage(EGLint buffer);
EGLNativeWindowType getWindowHandle() const;
EGLint isPostSubBufferSupported() const; EGLint isPostSubBufferSupported() const;
void setSwapInterval(EGLint interval); void setSwapInterval(EGLint interval);
......
...@@ -37,9 +37,6 @@ class SurfaceImpl ...@@ -37,9 +37,6 @@ class SurfaceImpl
virtual egl::Error releaseTexImage(EGLint buffer) = 0; virtual egl::Error releaseTexImage(EGLint buffer) = 0;
virtual void setSwapInterval(EGLint interval) = 0; virtual void setSwapInterval(EGLint interval) = 0;
//TODO(jmadill): Possibly should be redesigned
virtual EGLNativeWindowType getWindowHandle() const = 0;
// width and height can change with client window resizing // width and height can change with client window resizing
virtual EGLint getWidth() const = 0; virtual EGLint getWidth() const = 0;
virtual EGLint getHeight() const = 0; virtual EGLint getHeight() const = 0;
......
...@@ -222,11 +222,6 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height) ...@@ -222,11 +222,6 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
return egl::Error(EGL_SUCCESS); return egl::Error(EGL_SUCCESS);
} }
EGLNativeWindowType SurfaceD3D::getWindowHandle() const
{
return mNativeWindow.getNativeWindow();
}
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
#define kSurfaceProperty _TEXT("Egl::SurfaceOwner") #define kSurfaceProperty _TEXT("Egl::SurfaceOwner")
#define kParentWndProc _TEXT("Egl::SurfaceParentWndProc") #define kParentWndProc _TEXT("Egl::SurfaceParentWndProc")
......
...@@ -54,8 +54,6 @@ class SurfaceD3D : public SurfaceImpl ...@@ -54,8 +54,6 @@ class SurfaceD3D : public SurfaceImpl
// Returns true if swapchain changed due to resize or interval update // Returns true if swapchain changed due to resize or interval update
bool checkForOutOfDateSwapChain(); bool checkForOutOfDateSwapChain();
EGLNativeWindowType getWindowHandle() const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(SurfaceD3D); DISALLOW_COPY_AND_ASSIGN(SurfaceD3D);
......
...@@ -179,9 +179,4 @@ EGLint SurfaceWGL::getHeight() const ...@@ -179,9 +179,4 @@ EGLint SurfaceWGL::getHeight() const
return rect.bottom - rect.top; return rect.bottom - rect.top;
} }
EGLNativeWindowType SurfaceWGL::getWindowHandle() const
{
return mChildWindow;
}
} }
...@@ -42,8 +42,6 @@ class SurfaceWGL : public SurfaceGL ...@@ -42,8 +42,6 @@ class SurfaceWGL : public SurfaceGL
EGLint getWidth() const override; EGLint getWidth() const override;
EGLint getHeight() const override; EGLint getHeight() const override;
EGLNativeWindowType getWindowHandle() const override;
private: private:
DISALLOW_COPY_AND_ASSIGN(SurfaceWGL); DISALLOW_COPY_AND_ASSIGN(SurfaceWGL);
......
...@@ -278,7 +278,7 @@ Error ValidateCreateWindowSurface(Display *display, Config *config, EGLNativeWin ...@@ -278,7 +278,7 @@ Error ValidateCreateWindowSurface(Display *display, Config *config, EGLNativeWin
} }
} }
if (display->hasExistingWindowSurface(window)) if (Display::hasExistingWindowSurface(window))
{ {
return Error(EGL_BAD_ALLOC); return Error(EGL_BAD_ALLOC);
} }
......
...@@ -751,7 +751,7 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b ...@@ -751,7 +751,7 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b
return EGL_FALSE; return EGL_FALSE;
} }
if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle()) if (surface == EGL_NO_SURFACE || eglSurface->getType() == EGL_WINDOW_BIT)
{ {
SetGlobalError(Error(EGL_BAD_SURFACE)); SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE; return EGL_FALSE;
...@@ -829,7 +829,7 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin ...@@ -829,7 +829,7 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin
return EGL_FALSE; return EGL_FALSE;
} }
if (surface == EGL_NO_SURFACE || eglSurface->getWindowHandle()) if (surface == EGL_NO_SURFACE || eglSurface->getType() == EGL_WINDOW_BIT)
{ {
SetGlobalError(Error(EGL_BAD_SURFACE)); SetGlobalError(Error(EGL_BAD_SURFACE));
return EGL_FALSE; return EGL_FALSE;
......
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