Commit 5d9b4de5 by Nicolas Capens

Reference count the TLS objects.

Bug 20045861 Change-Id: I4881187cb45b6c818ceca2d950977b3af43443ab Reviewed-on: https://swiftshader-review.googlesource.com/2795Tested-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent e826ef02
#ifndef egl_Context_hpp
#define egl_Context_hpp
#include "common/Object.hpp"
#define EGLAPI
#include <EGL/egl.h>
#define GL_API
......@@ -11,16 +13,17 @@ namespace egl
class Surface;
class Image;
class Context
class Context : public gl::Object
{
public:
virtual ~Context() {};
virtual void destroy() = 0;
virtual void makeCurrent(Surface *surface) = 0;
virtual void bindTexImage(Surface *surface) = 0;
virtual EGLenum validateSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0;
virtual Image *createSharedImage(EGLenum target, GLuint name, GLuint textureLevel) = 0;
virtual int getClientVersion() = 0;
protected:
virtual ~Context() {};
};
}
......
......@@ -289,10 +289,11 @@ EGLSurface Display::createWindowSurface(EGLNativeWindowType window, EGLConfig co
if(!surface->initialize())
{
delete surface;
surface->release();
return EGL_NO_SURFACE;
}
surface->addRef();
mSurfaceSet.insert(surface);
return success(surface);
......@@ -391,10 +392,11 @@ EGLSurface Display::createOffscreenSurface(EGLConfig config, const EGLint *attri
if(!surface->initialize())
{
delete surface;
surface->release();
return EGL_NO_SURFACE;
}
surface->addRef();
mSurfaceSet.insert(surface);
return success(surface);
......@@ -430,14 +432,15 @@ EGLContext Display::createContext(EGLConfig configHandle, const egl::Context *sh
return error(EGL_BAD_ALLOC, EGL_NO_CONTEXT);
}
context->addRef();
mContextSet.insert(context);
return success(context);;
return success(context);
}
void Display::destroySurface(egl::Surface *surface)
{
delete surface;
surface->release();
mSurfaceSet.erase(surface);
if(surface == getCurrentDrawSurface())
......@@ -453,7 +456,7 @@ void Display::destroySurface(egl::Surface *surface)
void Display::destroyContext(egl::Context *context)
{
context->destroy();
context->release();
mContextSet.erase(context);
if(context == getCurrentContext())
......
......@@ -71,7 +71,7 @@ Surface::Surface(Display *display, const Config *config, EGLint width, EGLint he
Surface::~Surface()
{
release();
deleteResources();
}
bool Surface::initialize()
......@@ -81,7 +81,7 @@ bool Surface::initialize()
return reset();
}
void Surface::release()
void Surface::deleteResources()
{
if(mDepthStencil)
{
......@@ -130,7 +130,7 @@ bool Surface::reset()
bool Surface::reset(int backBufferWidth, int backBufferHeight)
{
release();
deleteResources();
if(mWindow)
{
......@@ -139,7 +139,7 @@ bool Surface::reset(int backBufferWidth, int backBufferHeight)
if(!frameBuffer)
{
ERR("Could not create frame buffer");
release();
deleteResources();
return error(EGL_BAD_ALLOC, false);
}
}
......@@ -149,7 +149,7 @@ bool Surface::reset(int backBufferWidth, int backBufferHeight)
if(!backBuffer)
{
ERR("Could not create back buffer");
release();
deleteResources();
return error(EGL_BAD_ALLOC, false);
}
......@@ -160,7 +160,7 @@ bool Surface::reset(int backBufferWidth, int backBufferHeight)
if(!mDepthStencil)
{
ERR("Could not create depth/stencil buffer for surface");
release();
deleteResources();
return error(EGL_BAD_ALLOC, false);
}
}
......
......@@ -17,6 +17,7 @@
#define INCLUDE_SURFACE_H_
#include "Main/FrameBuffer.hpp"
#include "common/Object.hpp"
#define EGLAPI
#include <EGL/egl.h>
......@@ -28,14 +29,12 @@ class Config;
class Texture;
class Image;
class Surface
class Surface : public gl::Object
{
public:
Surface(Display *display, const egl::Config *config, EGLNativeWindowType window);
Surface(Display *display, const egl::Config *config, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget);
virtual ~Surface();
bool initialize();
void swap();
......@@ -65,7 +64,9 @@ public:
bool checkForResize(); // Returns true if surface changed due to resize
private:
void release();
virtual ~Surface();
void deleteResources();
bool reset();
Display *const mDisplay;
......
......@@ -13,6 +13,9 @@
#include "main.h"
#include "Context.hpp"
#include "Surface.h"
#include "resource.h"
#include "Common/Thread.hpp"
#include "Common/SharedLibrary.hpp"
......@@ -259,6 +262,16 @@ void setCurrentContext(egl::Context *ctx)
{
Current *current = eglGetCurrent();
if(ctx)
{
ctx->addRef();
}
if(current->context)
{
current->context->release();
}
current->context = ctx;
}
......@@ -273,6 +286,16 @@ void setCurrentDrawSurface(egl::Surface *surface)
{
Current *current = eglGetCurrent();
if(surface)
{
surface->addRef();
}
if(current->drawSurface)
{
current->drawSurface->release();
}
current->drawSurface = surface;
}
......@@ -287,6 +310,16 @@ void setCurrentReadSurface(egl::Surface *surface)
{
Current *current = eglGetCurrent();
if(surface)
{
surface->addRef();
}
if(current->readSurface)
{
current->readSurface->release();
}
current->readSurface = surface;
}
......
......@@ -255,11 +255,6 @@ void Context::makeCurrent(egl::Surface *surface)
markAllStateDirty();
}
void Context::destroy()
{
delete this;
}
int Context::getClientVersion()
{
return 1;
......
......@@ -263,7 +263,6 @@ public:
Context(const egl::Config *config, const Context *shareContext);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy();
virtual int getClientVersion();
void markAllStateDirty();
......
......@@ -295,11 +295,6 @@ void Context::makeCurrent(egl::Surface *surface)
markAllStateDirty();
}
void Context::destroy()
{
delete this;
}
EGLint Context::getClientVersion()
{
return clientVersion;
......
......@@ -275,7 +275,6 @@ public:
Context(const egl::Config *config, const Context *shareContext, EGLint clientVersion);
virtual void makeCurrent(egl::Surface *surface);
virtual void destroy();
virtual EGLint getClientVersion();
void markAllStateDirty();
......
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