Commit 3311d474 by Jamie Madill Committed by Commit Bot

Display: Add a shared state object.

This will allow us to manage the SurfaceSet in the GL layer. BUG=angleproject:1684 Change-Id: Iab8243157710beab2667ef10275571078ce9ae8e Reviewed-on: https://chromium-review.googlesource.com/424228Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 1754ba0d
......@@ -139,7 +139,7 @@ static DevicePlatformDisplayMap *GetDevicePlatformDisplayMap()
return &displays;
}
rx::DisplayImpl *CreateDisplayFromDevice(Device *eglDevice)
rx::DisplayImpl *CreateDisplayFromDevice(Device *eglDevice, const DisplayState &state)
{
rx::DisplayImpl *impl = nullptr;
......@@ -147,7 +147,7 @@ rx::DisplayImpl *CreateDisplayFromDevice(Device *eglDevice)
{
#if defined(ANGLE_ENABLE_D3D11)
case EGL_D3D11_DEVICE_ANGLE:
impl = new rx::DisplayD3D();
impl = new rx::DisplayD3D(state);
break;
#endif
#if defined(ANGLE_ENABLE_D3D9)
......@@ -170,7 +170,7 @@ rx::DisplayImpl *CreateDisplayFromDevice(Device *eglDevice)
return impl;
}
rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap, const DisplayState &state)
{
rx::DisplayImpl *impl = nullptr;
EGLAttrib displayType =
......@@ -180,15 +180,15 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE:
#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
// Default to D3D displays
impl = new rx::DisplayD3D();
impl = new rx::DisplayD3D(state);
#elif defined(ANGLE_USE_X11)
impl = new rx::DisplayGLX();
impl = new rx::DisplayGLX(state);
#elif defined(ANGLE_PLATFORM_APPLE)
impl = new rx::DisplayCGL();
impl = new rx::DisplayCGL(state);
#elif defined(ANGLE_USE_OZONE)
impl = new rx::DisplayOzone();
impl = new rx::DisplayOzone(state);
#elif defined(ANGLE_PLATFORM_ANDROID)
impl = new rx::DisplayAndroid();
impl = new rx::DisplayAndroid(state);
#else
// No display available
UNREACHABLE();
......@@ -198,7 +198,7 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE:
case EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE:
#if defined(ANGLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
impl = new rx::DisplayD3D();
impl = new rx::DisplayD3D(state);
#else
// A D3D display was requested on a platform that doesn't support it
UNREACHABLE();
......@@ -208,11 +208,11 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE:
#if defined(ANGLE_ENABLE_OPENGL)
#if defined(ANGLE_PLATFORM_WINDOWS)
impl = new rx::DisplayWGL();
impl = new rx::DisplayWGL(state);
#elif defined(ANGLE_USE_X11)
impl = new rx::DisplayGLX();
impl = new rx::DisplayGLX(state);
#elif defined(ANGLE_PLATFORM_APPLE)
impl = new rx::DisplayCGL();
impl = new rx::DisplayCGL(state);
#elif defined(ANGLE_USE_OZONE)
// This might work but has never been tried, so disallow for now.
impl = nullptr;
......@@ -231,13 +231,13 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE:
#if defined(ANGLE_ENABLE_OPENGL)
#if defined(ANGLE_PLATFORM_WINDOWS)
impl = new rx::DisplayWGL();
impl = new rx::DisplayWGL(state);
#elif defined(ANGLE_USE_X11)
impl = new rx::DisplayGLX();
impl = new rx::DisplayGLX(state);
#elif defined(ANGLE_USE_OZONE)
impl = new rx::DisplayOzone();
impl = new rx::DisplayOzone(state);
#elif defined(ANGLE_PLATFORM_ANDROID)
impl = new rx::DisplayAndroid();
impl = new rx::DisplayAndroid(state);
#else
// No GLES support on this platform, fail display creation.
impl = nullptr;
......@@ -247,7 +247,7 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE:
#if defined(ANGLE_ENABLE_VULKAN)
impl = new rx::DisplayVk();
impl = new rx::DisplayVk(state);
#else
// No display available
UNREACHABLE();
......@@ -256,7 +256,7 @@ rx::DisplayImpl *CreateDisplayFromAttribs(const AttributeMap &attribMap)
case EGL_PLATFORM_ANGLE_TYPE_NULL_ANGLE:
#if defined(ANGLE_ENABLE_NULL)
impl = new rx::DisplayNULL();
impl = new rx::DisplayNULL(state);
#else
// No display available
UNREACHABLE();
......@@ -304,7 +304,7 @@ Display *Display::GetDisplayFromAttribs(void *native_display, const AttributeMap
// Apply new attributes if the display is not initialized yet.
if (!display->isInitialized())
{
rx::DisplayImpl *impl = CreateDisplayFromAttribs(attribMap);
rx::DisplayImpl *impl = CreateDisplayFromAttribs(attribMap, display->getState());
if (impl == nullptr)
{
// No valid display implementation for these attributes
......@@ -360,7 +360,7 @@ Display *Display::GetDisplayFromDevice(void *native_display)
// Apply new attributes if the display is not initialized yet.
if (!display->isInitialized())
{
rx::DisplayImpl *impl = CreateDisplayFromDevice(eglDevice);
rx::DisplayImpl *impl = CreateDisplayFromDevice(eglDevice, display->getState());
display->setAttributes(impl, egl::AttributeMap());
}
......@@ -510,9 +510,9 @@ void Display::terminate()
destroyStream(*mStreamSet.begin());
}
while (!mImplementation->getSurfaceSet().empty())
while (!mState.surfaceSet.empty())
{
destroySurface(*mImplementation->getSurfaceSet().begin());
destroySurface(*mState.surfaceSet.begin());
}
mConfigSet.clear();
......@@ -605,7 +605,7 @@ Error Display::createWindowSurface(const Config *configuration, EGLNativeWindowT
ASSERT(outSurface != nullptr);
*outSurface = surface.release();
mImplementation->getSurfaceSet().insert(*outSurface);
mState.surfaceSet.insert(*outSurface);
WindowSurfaceMap *windowSurfaces = GetWindowSurfaces();
ASSERT(windowSurfaces && windowSurfaces->find(window) == windowSurfaces->end());
......@@ -628,7 +628,7 @@ Error Display::createPbufferSurface(const Config *configuration, const Attribute
ASSERT(outSurface != nullptr);
*outSurface = surface.release();
mImplementation->getSurfaceSet().insert(*outSurface);
mState.surfaceSet.insert(*outSurface);
return egl::Error(EGL_SUCCESS);
}
......@@ -652,7 +652,7 @@ Error Display::createPbufferFromClientBuffer(const Config *configuration,
ASSERT(outSurface != nullptr);
*outSurface = surface.release();
mImplementation->getSurfaceSet().insert(*outSurface);
mState.surfaceSet.insert(*outSurface);
return egl::Error(EGL_SUCCESS);
}
......@@ -673,7 +673,7 @@ Error Display::createPixmapSurface(const Config *configuration, NativePixmapType
ASSERT(outSurface != nullptr);
*outSurface = surface.release();
mImplementation->getSurfaceSet().insert(*outSurface);
mState.surfaceSet.insert(*outSurface);
return egl::Error(EGL_SUCCESS);
}
......@@ -806,7 +806,8 @@ void Display::destroySurface(Surface *surface)
ASSERT(surfaceRemoved);
}
mImplementation->destroySurface(surface);
mState.surfaceSet.erase(surface);
surface->onDestroy();
}
void Display::destroyImage(egl::Image *image)
......@@ -894,8 +895,7 @@ bool Display::isValidContext(const gl::Context *context) const
bool Display::isValidSurface(const Surface *surface) const
{
return mImplementation->getSurfaceSet().find(const_cast<Surface *>(surface)) !=
mImplementation->getSurfaceSet().end();
return mState.surfaceSet.find(const_cast<Surface *>(surface)) != mState.surfaceSet.end();
}
bool Display::isValidImage(const Image *image) const
......
......@@ -37,6 +37,13 @@ class Image;
class Surface;
class Stream;
using SurfaceSet = std::set<Surface *>;
struct DisplayState final : angle::NonCopyable
{
SurfaceSet surfaceSet;
};
class Display final : angle::NonCopyable
{
public:
......@@ -122,6 +129,8 @@ class Display final : angle::NonCopyable
gl::Version getMaxSupportedESVersion() const;
const DisplayState &getState() const { return mState; }
private:
Display(EGLenum platform, EGLNativeDisplayType displayId, Device *eglDevice);
......@@ -132,6 +141,7 @@ class Display final : angle::NonCopyable
void initDisplayExtensions();
void initVendorString();
DisplayState mState;
rx::DisplayImpl *mImplementation;
EGLNativeDisplayType mDisplayId;
......
......@@ -8,26 +8,20 @@
#include "libANGLE/renderer/DisplayImpl.h"
#include "libANGLE/Display.h"
#include "libANGLE/Surface.h"
namespace rx
{
DisplayImpl::DisplayImpl()
: mExtensionsInitialized(false),
mCapsInitialized(false)
DisplayImpl::DisplayImpl(const egl::DisplayState &state)
: mState(state), mExtensionsInitialized(false), mCapsInitialized(false)
{
}
DisplayImpl::~DisplayImpl()
{
ASSERT(mSurfaceSet.empty());
}
void DisplayImpl::destroySurface(egl::Surface *surface)
{
mSurfaceSet.erase(surface);
surface->onDestroy();
ASSERT(mState.surfaceSet.empty());
}
const egl::DisplayExtensions &DisplayImpl::getExtensions() const
......
......@@ -24,6 +24,7 @@ namespace egl
{
class AttributeMap;
class Display;
struct DisplayState;
struct Config;
class Surface;
class ImageSibling;
......@@ -45,7 +46,7 @@ class StreamProducerImpl;
class DisplayImpl : public EGLImplFactory
{
public:
DisplayImpl();
DisplayImpl(const egl::DisplayState &state);
virtual ~DisplayImpl();
virtual egl::Error initialize(egl::Display *display) = 0;
......@@ -75,18 +76,10 @@ class DisplayImpl : public EGLImplFactory
virtual gl::Version getMaxSupportedESVersion() const = 0;
const egl::Caps &getCaps() const;
typedef std::set<egl::Surface*> SurfaceSet;
const SurfaceSet &getSurfaceSet() const { return mSurfaceSet; }
SurfaceSet &getSurfaceSet() { return mSurfaceSet; }
void destroySurface(egl::Surface *surface);
const egl::DisplayExtensions &getExtensions() const;
protected:
// Place the surface set here so it can be accessible for handling
// context loss events. (It is shared between the Display and Impl.)
SurfaceSet mSurfaceSet;
const egl::DisplayState &mState;
private:
virtual void generateExtensions(egl::DisplayExtensions *outExtensions) const = 0;
......
......@@ -154,7 +154,7 @@ egl::Error CreateRendererD3D(egl::Display *display, RendererD3D **outRenderer)
return result;
}
DisplayD3D::DisplayD3D() : mRenderer(nullptr)
DisplayD3D::DisplayD3D(const egl::DisplayState &state) : DisplayImpl(state), mRenderer(nullptr)
{
}
......@@ -249,7 +249,7 @@ bool DisplayD3D::testDeviceLost()
egl::Error DisplayD3D::restoreLostDevice()
{
// Release surface resources to make the Reset() succeed
for (auto &surface : mSurfaceSet)
for (auto &surface : mState.surfaceSet)
{
if (surface->getBoundTexture())
{
......@@ -265,7 +265,7 @@ egl::Error DisplayD3D::restoreLostDevice()
}
// Restore any surfaces that may have been lost
for (const auto &surface : mSurfaceSet)
for (const auto &surface : mState.surfaceSet)
{
SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface);
......@@ -330,7 +330,7 @@ void DisplayD3D::generateCaps(egl::Caps *outCaps) const
egl::Error DisplayD3D::waitClient() const
{
for (auto &surface : getSurfaceSet())
for (auto &surface : mState.surfaceSet)
{
SurfaceD3D *surfaceD3D = GetImplAs<SurfaceD3D>(surface);
surfaceD3D->checkForOutOfDateSwapChain();
......
......@@ -19,7 +19,7 @@ class RendererD3D;
class DisplayD3D : public DisplayImpl
{
public:
DisplayD3D();
DisplayD3D(const egl::DisplayState &state);
egl::Error initialize(egl::Display *display) override;
virtual void terminate() override;
......
......@@ -22,7 +22,8 @@
namespace rx
{
DisplayGL::DisplayGL() : mRenderer(nullptr), mCurrentDrawSurface(nullptr)
DisplayGL::DisplayGL(const egl::DisplayState &state)
: DisplayImpl(state), mRenderer(nullptr), mCurrentDrawSurface(nullptr)
{
}
......@@ -73,7 +74,8 @@ StreamProducerImpl *DisplayGL::createStreamProducerD3DTextureNV12(
egl::Error DisplayGL::makeCurrent(egl::Surface *drawSurface, egl::Surface *readSurface, gl::Context *context)
{
// Notify the previous surface (if it still exists) that it is no longer current
if (mCurrentDrawSurface && mSurfaceSet.find(mCurrentDrawSurface) != mSurfaceSet.end())
if (mCurrentDrawSurface &&
mState.surfaceSet.find(mCurrentDrawSurface) != mState.surfaceSet.end())
{
ANGLE_TRY(GetImplAs<SurfaceGL>(mCurrentDrawSurface)->unMakeCurrent());
}
......
......@@ -25,7 +25,7 @@ class RendererGL;
class DisplayGL : public DisplayImpl
{
public:
DisplayGL();
DisplayGL(const egl::DisplayState &state);
~DisplayGL() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -20,7 +20,7 @@ namespace rx
class DisplayCGL : public DisplayGL
{
public:
DisplayCGL();
DisplayCGL(const egl::DisplayState &state);
~DisplayCGL() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -44,7 +44,8 @@ class FunctionsGLCGL : public FunctionsGL
void *mDylibHandle;
};
DisplayCGL::DisplayCGL() : DisplayGL(), mEGLDisplay(nullptr), mFunctions(nullptr), mContext(nullptr)
DisplayCGL::DisplayCGL(const egl::DisplayState &state)
: DisplayGL(state), mEGLDisplay(nullptr), mFunctions(nullptr), mContext(nullptr)
{
}
......
......@@ -13,8 +13,8 @@ namespace rx
#define EGL_NO_CONFIG ((EGLConfig)0)
DisplayEGL::DisplayEGL()
: DisplayGL(),
DisplayEGL::DisplayEGL(const egl::DisplayState &state)
: DisplayGL(state),
mEGL(nullptr),
mConfig(EGL_NO_CONFIG),
mContext(EGL_NO_CONTEXT),
......
......@@ -18,7 +18,7 @@ namespace rx
class DisplayEGL : public DisplayGL
{
public:
DisplayEGL();
DisplayEGL(const egl::DisplayState &state);
~DisplayEGL() override;
std::string getVendorString() const override;
......
......@@ -32,7 +32,8 @@ const char *GetEGLPath()
namespace rx
{
DisplayAndroid::DisplayAndroid() : DisplayEGL(), mDummyPbuffer(EGL_NO_SURFACE)
DisplayAndroid::DisplayAndroid(const egl::DisplayState &state)
: DisplayEGL(state), mDummyPbuffer(EGL_NO_SURFACE)
{
}
......
......@@ -21,7 +21,7 @@ namespace rx
class DisplayAndroid : public DisplayEGL
{
public:
DisplayAndroid();
DisplayAndroid(const egl::DisplayState &state);
~DisplayAndroid() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -325,8 +325,8 @@ void DisplayOzone::Buffer::present()
}
}
DisplayOzone::DisplayOzone()
: DisplayEGL(),
DisplayOzone::DisplayOzone(const egl::DisplayState &state)
: DisplayEGL(state),
mSwapControl(SwapControl::ABSENT),
mMinSwapInterval(0),
mMaxSwapInterval(0),
......
......@@ -107,7 +107,7 @@ class DisplayOzone final : public DisplayEGL
GLuint mTexture;
};
DisplayOzone();
DisplayOzone(const egl::DisplayState &state);
~DisplayOzone() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -106,8 +106,8 @@ class FunctionsGLGLX : public FunctionsGL
PFNGETPROCPROC mGetProc;
};
DisplayGLX::DisplayGLX()
: DisplayGL(),
DisplayGLX::DisplayGLX(const egl::DisplayState &state)
: DisplayGL(state),
mFunctionsGL(nullptr),
mRequestedVisual(-1),
mContextConfig(nullptr),
......
......@@ -38,7 +38,7 @@ struct SwapControlData
class DisplayGLX : public DisplayGL
{
public:
DisplayGLX();
DisplayGLX(const egl::DisplayState &state);
~DisplayGLX() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -58,8 +58,8 @@ class FunctionsGLWindows : public FunctionsGL
PFNWGLGETPROCADDRESSPROC mGetProcAddressWGL;
};
DisplayWGL::DisplayWGL()
: DisplayGL(),
DisplayWGL::DisplayWGL(const egl::DisplayState &state)
: DisplayGL(state),
mOpenGLModule(nullptr),
mFunctionsWGL(nullptr),
mFunctionsGL(nullptr),
......
......@@ -21,7 +21,7 @@ class FunctionsWGL;
class DisplayWGL : public DisplayGL
{
public:
DisplayWGL();
DisplayWGL(const egl::DisplayState &state);
~DisplayWGL() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -19,7 +19,7 @@
namespace rx
{
DisplayNULL::DisplayNULL() : DisplayImpl(), mDevice(nullptr)
DisplayNULL::DisplayNULL(const egl::DisplayState &state) : DisplayImpl(state), mDevice(nullptr)
{
}
......
......@@ -18,7 +18,7 @@ namespace rx
class DisplayNULL : public DisplayImpl
{
public:
DisplayNULL();
DisplayNULL(const egl::DisplayState &state);
~DisplayNULL() override;
egl::Error initialize(egl::Display *display) override;
......
......@@ -19,7 +19,7 @@
namespace rx
{
DisplayVk::DisplayVk() : DisplayImpl(), mRenderer(nullptr)
DisplayVk::DisplayVk(const egl::DisplayState &state) : DisplayImpl(state), mRenderer(nullptr)
{
}
......
......@@ -19,7 +19,7 @@ class RendererVk;
class DisplayVk : public DisplayImpl
{
public:
DisplayVk();
DisplayVk(const egl::DisplayState &state);
~DisplayVk() override;
egl::Error initialize(egl::Display *display) override;
......
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