Commit c30c424f by Jamie Madill

Make egl::Surface ref-counted.

This will let us store references to Surface in FBO attachments, even after the surface is destroyed. BUG=angleproject:963 Change-Id: I7e1cb161d1e08f78b1c4d730a32ad09ac7e61e30 Reviewed-on: https://chromium-review.googlesource.com/263482Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent d1f5ef2e
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
#include "RefCountObject.h" #include "RefCountObject.h"
RefCountObject::RefCountObject(GLuint id) RefCountObject::RefCountObject(GLuint id)
: mId(id),
mRefCount(0)
{ {
mId = id;
mRefCount = 0;
} }
RefCountObject::~RefCountObject() RefCountObject::~RefCountObject()
......
...@@ -20,7 +20,8 @@ namespace egl ...@@ -20,7 +20,8 @@ namespace egl
{ {
Surface::Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes) Surface::Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes)
: mImplementation(impl), : RefCountObject(0), // id unused
mImplementation(impl),
mType(surfaceType), mType(surfaceType),
mConfig(config), mConfig(config),
mPostSubBufferRequested(false), mPostSubBufferRequested(false),
...@@ -35,6 +36,8 @@ Surface::Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *c ...@@ -35,6 +36,8 @@ Surface::Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *c
mSwapBehavior(EGL_BUFFER_PRESERVED), mSwapBehavior(EGL_BUFFER_PRESERVED),
mTexture(NULL) mTexture(NULL)
{ {
addRef();
mPostSubBufferRequested = (attributes.get(EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_FALSE) == EGL_TRUE); mPostSubBufferRequested = (attributes.get(EGL_POST_SUB_BUFFER_SUPPORTED_NV, EGL_FALSE) == EGL_TRUE);
mFixedSize = (attributes.get(EGL_FIXED_SIZE_ANGLE, EGL_FALSE) == EGL_TRUE); mFixedSize = (attributes.get(EGL_FIXED_SIZE_ANGLE, EGL_FALSE) == EGL_TRUE);
......
...@@ -11,10 +11,11 @@ ...@@ -11,10 +11,11 @@
#ifndef LIBANGLE_SURFACE_H_ #ifndef LIBANGLE_SURFACE_H_
#define LIBANGLE_SURFACE_H_ #define LIBANGLE_SURFACE_H_
#include <EGL/egl.h>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "libANGLE/RefCountObject.h"
#include <EGL/egl.h>
namespace gl namespace gl
{ {
...@@ -32,11 +33,10 @@ class AttributeMap; ...@@ -32,11 +33,10 @@ class AttributeMap;
class Display; class Display;
struct Config; struct Config;
class Surface final : angle::NonCopyable class Surface final : public RefCountObject
{ {
public: public:
Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes); Surface(rx::SurfaceImpl *impl, EGLint surfaceType, const egl::Config *config, const AttributeMap &attributes);
~Surface();
rx::SurfaceImpl *getImplementation() { return mImplementation; } rx::SurfaceImpl *getImplementation() { return mImplementation; }
const rx::SurfaceImpl *getImplementation() const { return mImplementation; } const rx::SurfaceImpl *getImplementation() const { return mImplementation; }
...@@ -69,6 +69,8 @@ class Surface final : angle::NonCopyable ...@@ -69,6 +69,8 @@ class Surface final : angle::NonCopyable
EGLint isFixedSize() const; EGLint isFixedSize() const;
private: private:
virtual ~Surface();
rx::SurfaceImpl *mImplementation; rx::SurfaceImpl *mImplementation;
EGLint mType; EGLint mType;
......
...@@ -45,7 +45,7 @@ class SurfaceTest : public testing::Test ...@@ -45,7 +45,7 @@ class SurfaceTest : public testing::Test
virtual void TearDown() virtual void TearDown()
{ {
delete mSurface; mSurface->release();
} }
MockSurfaceImpl *mImpl; MockSurfaceImpl *mImpl;
...@@ -59,7 +59,7 @@ TEST_F(SurfaceTest, DestructionDeletesImpl) ...@@ -59,7 +59,7 @@ TEST_F(SurfaceTest, DestructionDeletesImpl)
EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation(); EXPECT_CALL(*impl, destroy()).Times(1).RetiresOnSaturation();
egl::Surface *surface = new egl::Surface(impl, EGL_WINDOW_BIT, &mConfig, egl::AttributeMap()); egl::Surface *surface = new egl::Surface(impl, EGL_WINDOW_BIT, &mConfig, egl::AttributeMap());
delete surface; surface->release();
// Only needed because the mock is leaked if bugs are present, // Only needed because the mock is leaked if bugs are present,
// which logs an error, but does not cause the test to fail. // which logs an error, but does not cause the test to fail.
......
...@@ -30,7 +30,7 @@ DisplayImpl::~DisplayImpl() ...@@ -30,7 +30,7 @@ DisplayImpl::~DisplayImpl()
void DisplayImpl::destroySurface(egl::Surface *surface) void DisplayImpl::destroySurface(egl::Surface *surface)
{ {
mSurfaceSet.erase(surface); mSurfaceSet.erase(surface);
SafeDelete(surface); surface->release();
} }
const egl::DisplayExtensions &DisplayImpl::getExtensions() const const egl::DisplayExtensions &DisplayImpl::getExtensions() const
......
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