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()
}
}
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;
static DisplayMap *GetDisplayMap()
{
......@@ -330,6 +339,10 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT
Surface *surface = new Surface(surfaceImpl, EGL_WINDOW_BIT, configuration, attribs);
mImplementation->getSurfaceSet().insert(surface);
WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
ASSERT(windowSurfaces && windowSurfaces->find(window) == windowSurfaces->end());
windowSurfaces->insert(std::make_pair(window, surface));
ASSERT(outSurface != nullptr);
*outSurface = surface;
return Error(EGL_SUCCESS);
......@@ -455,6 +468,25 @@ Error Display::restoreLostDevice()
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);
}
......@@ -509,17 +541,12 @@ bool Display::isValidSurface(Surface *surface) const
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())
{
if (surfaceIt->getWindowHandle() == window)
{
return true;
}
}
WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
ASSERT(windowSurfaces);
return false;
return windowSurfaces->find(window) != windowSurfaces->end();
}
static ClientExtensions GenerateClientExtensions()
......
......@@ -67,10 +67,10 @@ class Display final
bool isValidConfig(const Config *config) const;
bool isValidContext(gl::Context *context) const;
bool isValidSurface(egl::Surface *surface) const;
bool hasExistingWindowSurface(EGLNativeWindowType window) const;
bool isValidNativeWindow(EGLNativeWindowType window) const;
static bool isValidNativeDisplay(EGLNativeDisplayType display);
static bool hasExistingWindowSurface(EGLNativeWindowType window);
bool isDeviceLost() const;
bool testDeviceLost();
......
......@@ -49,11 +49,6 @@ EGLint Surface::getType() const
return mType;
}
EGLNativeWindowType Surface::getWindowHandle() const
{
return mImplementation->getWindowHandle();
}
Error Surface::swap()
{
return mImplementation->swap();
......
......@@ -49,8 +49,6 @@ class Surface final
Error bindTexImage(gl::Texture *texture, EGLint buffer);
Error releaseTexImage(EGLint buffer);
EGLNativeWindowType getWindowHandle() const;
EGLint isPostSubBufferSupported() const;
void setSwapInterval(EGLint interval);
......
......@@ -37,9 +37,6 @@ class SurfaceImpl
virtual egl::Error releaseTexImage(EGLint buffer) = 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
virtual EGLint getWidth() const = 0;
virtual EGLint getHeight() const = 0;
......
......@@ -222,11 +222,6 @@ egl::Error SurfaceD3D::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
return egl::Error(EGL_SUCCESS);
}
EGLNativeWindowType SurfaceD3D::getWindowHandle() const
{
return mNativeWindow.getNativeWindow();
}
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
#define kSurfaceProperty _TEXT("Egl::SurfaceOwner")
#define kParentWndProc _TEXT("Egl::SurfaceParentWndProc")
......
......@@ -54,8 +54,6 @@ class SurfaceD3D : public SurfaceImpl
// Returns true if swapchain changed due to resize or interval update
bool checkForOutOfDateSwapChain();
EGLNativeWindowType getWindowHandle() const override;
private:
DISALLOW_COPY_AND_ASSIGN(SurfaceD3D);
......
......@@ -179,9 +179,4 @@ EGLint SurfaceWGL::getHeight() const
return rect.bottom - rect.top;
}
EGLNativeWindowType SurfaceWGL::getWindowHandle() const
{
return mChildWindow;
}
}
......@@ -42,8 +42,6 @@ class SurfaceWGL : public SurfaceGL
EGLint getWidth() const override;
EGLint getHeight() const override;
EGLNativeWindowType getWindowHandle() const override;
private:
DISALLOW_COPY_AND_ASSIGN(SurfaceWGL);
......
......@@ -278,7 +278,7 @@ Error ValidateCreateWindowSurface(Display *display, Config *config, EGLNativeWin
}
}
if (display->hasExistingWindowSurface(window))
if (Display::hasExistingWindowSurface(window))
{
return Error(EGL_BAD_ALLOC);
}
......
......@@ -751,7 +751,7 @@ EGLBoolean EGLAPIENTRY BindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint b
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));
return EGL_FALSE;
......@@ -829,7 +829,7 @@ EGLBoolean EGLAPIENTRY ReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLin
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));
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