Commit 870352a1 by Jamie Madill

MANGLE egl::Display.

BUG=angle:794 Change-Id: Id131f3119100030d6ee630e357a8d28396a6a813 Reviewed-on: https://chromium-review.googlesource.com/231852Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7dd2e10d
......@@ -10,20 +10,17 @@
#include "libANGLE/Display.h"
#include <algorithm>
#include <map>
#include <vector>
#include <sstream>
#include <iterator>
#include "common/debug.h"
#include "common/mathutil.h"
#include "libANGLE/Context.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/DisplayImpl.h"
//TODO(jmadill): remove these
#include "libANGLE/renderer/SwapChain.h"
#include "libANGLE/renderer/d3d/SurfaceD3D.h"
#include <algorithm>
#include <map>
#include <vector>
#include <sstream>
#include <iterator>
#include <EGL/eglext.h>
......@@ -125,7 +122,7 @@ static DisplayMap *GetDisplayMap()
return &displays;
}
egl::Display *Display::getDisplay(EGLNativeDisplayType displayId, const AttributeMap &attribMap)
Display *Display::getDisplay(EGLNativeDisplayType displayId, const AttributeMap &attribMap)
{
Display *display = NULL;
......@@ -137,7 +134,7 @@ egl::Display *Display::getDisplay(EGLNativeDisplayType displayId, const Attribut
}
else
{
display = new egl::Display(displayId);
display = new Display(displayId);
displays->insert(std::make_pair(displayId, display));
}
......@@ -151,7 +148,8 @@ egl::Display *Display::getDisplay(EGLNativeDisplayType displayId, const Attribut
}
Display::Display(EGLNativeDisplayType displayId)
: mDisplayId(displayId),
: mImplementation(NULL),
mDisplayId(displayId),
mAttributeMap(),
mRenderer(NULL)
{
......@@ -189,6 +187,9 @@ Error Display::initialize()
return Error(EGL_NOT_INITIALIZED);
}
mImplementation = mRenderer->createDisplay();
ASSERT(mImplementation);
//TODO(jmadill): should be part of caps?
EGLint minSwapInterval = mRenderer->getMinSwapInterval();
EGLint maxSwapInterval = mRenderer->getMaxSwapInterval();
......@@ -231,11 +232,6 @@ Error Display::initialize()
void Display::terminate()
{
while (!mSurfaceSet.empty())
{
destroySurface(*mSurfaceSet.begin());
}
while (!mContextSet.empty())
{
destroyContext(*mContextSet.begin());
......@@ -373,11 +369,11 @@ Error Display::createWindowSurface(EGLNativeWindowType window, EGLConfig config,
}
}
//TODO(jmadill): MANGLE refactor
rx::SurfaceD3D *surfaceD3D = rx::SurfaceD3D::createFromWindow(this, configuration, window, fixedSize,
width, height, postSubBufferSupported);
rx::SurfaceImpl *surfaceImpl = mImplementation->createWindowSurface(this, configuration, window,
fixedSize, width, height,
postSubBufferSupported);
Surface *surface = new Surface(surfaceD3D);
Surface *surface = new Surface(surfaceImpl);
Error error = surface->initialize();
if (error.isError())
{
......@@ -385,7 +381,7 @@ Error Display::createWindowSurface(EGLNativeWindowType window, EGLConfig config,
return error;
}
mSurfaceSet.insert(surface);
mImplementation->getSurfaceSet().insert(surface);
*outSurface = surface;
return Error(EGL_SUCCESS);
......@@ -495,11 +491,10 @@ Error Display::createOffscreenSurface(EGLConfig config, EGLClientBuffer shareHan
}
}
//TODO(jmadill): MANGLE refactor
rx::SurfaceD3D *surfaceD3D = rx::SurfaceD3D::createOffscreen(this, configuration, shareHandle,
width, height, textureFormat, textureTarget);
rx::SurfaceImpl *surfaceImpl = mImplementation->createOffscreenSurface(this, configuration, shareHandle,
width, height, textureFormat, textureTarget);
Surface *surface = new Surface(surfaceD3D);
Surface *surface = new Surface(surfaceImpl);
Error error = surface->initialize();
if (error.isError())
{
......@@ -507,7 +502,7 @@ Error Display::createOffscreenSurface(EGLConfig config, EGLClientBuffer shareHan
return error;
}
mSurfaceSet.insert(surface);
mImplementation->getSurfaceSet().insert(surface);
*outSurface = surface;
return Error(EGL_SUCCESS);
......@@ -555,45 +550,12 @@ Error Display::restoreLostDevice()
}
}
// Release surface resources to make the Reset() succeed
for (const auto &surface : mSurfaceSet)
{
//TODO(jmadill): MANGLE refactor
rx::SurfaceD3D *surfaceD3D = rx::SurfaceD3D::makeSurfaceD3D(surface);
if (surface->getBoundTexture())
{
surface->releaseTexImage(EGL_BACK_BUFFER);
}
surfaceD3D->releaseSwapChain();
}
if (!mRenderer->resetDevice())
{
return Error(EGL_BAD_ALLOC);
}
// Restore any surfaces that may have been lost
for (const auto &surface : mSurfaceSet)
{
//TODO(jmadill): MANGLE refactor
rx::SurfaceD3D *surfaceD3D = rx::SurfaceD3D::makeSurfaceD3D(surface);
Error error = surfaceD3D->resetSwapChain();
if (error.isError())
{
return error;
}
}
return Error(EGL_SUCCESS);
return mImplementation->restoreLostDevice();
}
void Display::destroySurface(egl::Surface *surface)
void Display::destroySurface(Surface *surface)
{
mSurfaceSet.erase(surface);
SafeDelete(surface);
mImplementation->destroySurface(surface);
}
void Display::destroyContext(gl::Context *context)
......@@ -625,16 +587,16 @@ bool Display::isValidContext(gl::Context *context)
return mContextSet.find(context) != mContextSet.end();
}
bool Display::isValidSurface(egl::Surface *surface)
bool Display::isValidSurface(Surface *surface)
{
return mSurfaceSet.find(surface) != mSurfaceSet.end();
return mImplementation->getSurfaceSet().find(surface) != mImplementation->getSurfaceSet().end();
}
bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{
for (SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
for (const auto &surfaceIt : mImplementation->getSurfaceSet())
{
if ((*surface)->getWindowHandle() == window)
if (surfaceIt->getWindowHandle() == window)
{
return true;
}
......
......@@ -24,6 +24,11 @@ namespace gl
class Context;
}
namespace rx
{
class DisplayImpl;
}
namespace egl
{
class Surface;
......@@ -77,12 +82,16 @@ class ANGLE_EXPORT Display
Error restoreLostDevice();
static std::string generateClientExtensionString();
void initDisplayExtensionString();
void initVendorString();
rx::DisplayImpl *mImplementation;
EGLNativeDisplayType mDisplayId;
AttributeMap mAttributeMap;
typedef std::set<Surface*> SurfaceSet;
SurfaceSet mSurfaceSet;
ConfigSet mConfigSet;
typedef std::set<gl::Context*> ContextSet;
......@@ -90,14 +99,11 @@ class ANGLE_EXPORT Display
rx::Renderer *mRenderer;
static std::string generateClientExtensionString();
void initDisplayExtensionString();
std::string mDisplayExtensionString;
void initVendorString();
std::string mVendorString;
};
}
#endif // LIBANGLE_DISPLAY_H_
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayImpl.cpp: Implementation methods of egl::Display
#include "libANGLE/renderer/DisplayImpl.h"
#include "libANGLE/Surface.h"
namespace rx
{
DisplayImpl::~DisplayImpl()
{
while (!mSurfaceSet.empty())
{
destroySurface(*mSurfaceSet.begin());
}
}
void DisplayImpl::destroySurface(egl::Surface *surface)
{
mSurfaceSet.erase(surface);
SafeDelete(surface);
}
}
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayImpl.h: Implementation methods of egl::Display
#ifndef LIBANGLE_RENDERER_DISPLAYIMPL_H_
#define LIBANGLE_RENDERER_DISPLAYIMPL_H_
#include "common/angleutils.h"
#include "libANGLE/Error.h"
#include <set>
namespace egl
{
class Display;
class Config;
class Surface;
}
namespace rx
{
class SurfaceImpl;
class DisplayImpl
{
public:
DisplayImpl() {}
virtual ~DisplayImpl();
virtual SurfaceImpl *createWindowSurface(egl::Display *display, const egl::Config *config,
EGLNativeWindowType window, EGLint fixedSize,
EGLint width, EGLint height, EGLint postSubBufferSupported) = 0;
virtual SurfaceImpl *createOffscreenSurface(egl::Display *display, const egl::Config *config,
EGLClientBuffer shareHandle, EGLint width, EGLint height,
EGLenum textureFormat, EGLenum textureTarget) = 0;
virtual egl::Error restoreLostDevice() = 0;
typedef std::set<egl::Surface*> SurfaceSet;
const SurfaceSet &getSurfaceSet() const { return mSurfaceSet; }
SurfaceSet &getSurfaceSet() { return mSurfaceSet; }
void destroySurface(egl::Surface *surface);
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;
private:
DISALLOW_COPY_AND_ASSIGN(DisplayImpl);
};
}
#endif // LIBANGLE_RENDERER_DISPLAYIMPL_H_
......@@ -58,6 +58,7 @@ class FramebufferImpl;
struct TranslatedIndexData;
struct Workarounds;
class SwapChain;
class DisplayImpl;
struct ConfigDesc
{
......@@ -76,7 +77,6 @@ class Renderer
virtual ~Renderer();
virtual EGLint initialize() = 0;
virtual bool resetDevice() = 0;
virtual int generateConfigs(ConfigDesc **configDescList) = 0;
virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
......@@ -161,6 +161,8 @@ class Renderer
virtual int getMinSwapInterval() const = 0;
virtual int getMaxSwapInterval() const = 0;
virtual DisplayImpl *createDisplay() = 0;
private:
DISALLOW_COPY_AND_ASSIGN(Renderer);
......
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayD3D.cpp: D3D implementation of egl::Display
#include "libANGLE/renderer/d3d/DisplayD3D.h"
#include "libANGLE/Surface.h"
#include "libANGLE/renderer/SwapChain.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include "libANGLE/renderer/d3d/SurfaceD3D.h"
namespace rx
{
SurfaceImpl *DisplayD3D::createWindowSurface(egl::Display *display, const egl::Config *config,
EGLNativeWindowType window, EGLint fixedSize,
EGLint width, EGLint height, EGLint postSubBufferSupported)
{
return SurfaceD3D::createFromWindow(display, config, window, fixedSize,
width, height, postSubBufferSupported);
}
SurfaceImpl *DisplayD3D::createOffscreenSurface(egl::Display *display, const egl::Config *config,
EGLClientBuffer shareHandle, EGLint width, EGLint height,
EGLenum textureFormat, EGLenum textureTarget)
{
return SurfaceD3D::createOffscreen(display, config, shareHandle,
width, height, textureFormat, textureTarget);
}
egl::Error DisplayD3D::restoreLostDevice()
{
// Release surface resources to make the Reset() succeed
for (auto &surface : mSurfaceSet)
{
if (surface->getBoundTexture())
{
surface->releaseTexImage(EGL_BACK_BUFFER);
}
SurfaceD3D *surfaceD3D = SurfaceD3D::makeSurfaceD3D(surface);
surfaceD3D->releaseSwapChain();
}
if (!mRenderer->resetDevice())
{
return egl::Error(EGL_BAD_ALLOC);
}
// Restore any surfaces that may have been lost
for (const auto &surface : mSurfaceSet)
{
SurfaceD3D *surfaceD3D = SurfaceD3D::makeSurfaceD3D(surface);
egl::Error error = surfaceD3D->resetSwapChain();
if (error.isError())
{
return error;
}
}
return egl::Error(EGL_SUCCESS);
}
}
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// DisplayD3D.h: D3D implementation of egl::Display
#ifndef LIBANGLE_RENDERER_D3D_DISPLAYD3D_H_
#define LIBANGLE_RENDERER_D3D_DISPLAYD3D_H_
#include "libANGLE/renderer/DisplayImpl.h"
namespace rx
{
class RendererD3D;
class DisplayD3D : public DisplayImpl
{
public:
DisplayD3D(rx::RendererD3D *renderer) {}
SurfaceImpl *createWindowSurface(egl::Display *display, const egl::Config *config,
EGLNativeWindowType window, EGLint fixedSize,
EGLint width, EGLint height, EGLint postSubBufferSupported) override;
SurfaceImpl *createOffscreenSurface(egl::Display *display, const egl::Config *config,
EGLClientBuffer shareHandle, EGLint width, EGLint height,
EGLenum textureFormat, EGLenum textureTarget) override;
egl::Error restoreLostDevice() override;
private:
DISALLOW_COPY_AND_ASSIGN(DisplayD3D);
rx::RendererD3D *mRenderer;
};
}
#endif // LIBANGLE_RENDERER_D3D_DISPLAYD3D_H_
......@@ -16,6 +16,7 @@
#include "libANGLE/State.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/DisplayD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h"
namespace rx
......@@ -824,4 +825,9 @@ std::string RendererD3D::getVendorString() const
return std::string("");
}
DisplayImpl *RendererD3D::createDisplay()
{
return new DisplayD3D(this);
}
}
......@@ -69,6 +69,8 @@ class RendererD3D : public Renderer
bool isDeviceLost() const override;
std::string getVendorString() const override;
DisplayImpl *createDisplay() override;
// Direct3D Specific methods
virtual GUID getAdapterIdentifier() const = 0;
......@@ -155,7 +157,9 @@ class RendererD3D : public Renderer
virtual VertexBuffer *createVertexBuffer() = 0;
virtual IndexBuffer *createIndexBuffer() = 0;
// Device lost
void notifyDeviceLost() override;
virtual bool resetDevice() = 0;
protected:
virtual gl::Error drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
......
......@@ -109,6 +109,8 @@
'libANGLE/queryconversions.cpp',
'libANGLE/queryconversions.h',
'libANGLE/renderer/BufferImpl.h',
'libANGLE/renderer/DisplayImpl.cpp',
'libANGLE/renderer/DisplayImpl.h',
'libANGLE/renderer/FenceImpl.h',
'libANGLE/renderer/FramebufferImpl.h',
'libANGLE/renderer/Image.cpp',
......@@ -161,6 +163,8 @@
[
'libANGLE/renderer/d3d/BufferD3D.cpp',
'libANGLE/renderer/d3d/BufferD3D.h',
'libANGLE/renderer/d3d/DisplayD3D.cpp',
'libANGLE/renderer/d3d/DisplayD3D.h',
'libANGLE/renderer/d3d/DynamicHLSL.cpp',
'libANGLE/renderer/d3d/DynamicHLSL.h',
'libANGLE/renderer/d3d/FramebufferD3D.cpp',
......
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