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