Commit c1abf917 by Jamie Madill Committed by Commit Bot

Fix leaking objects with UniqueObjectPointer.

BUG=angleproject:2170 Change-Id: Ie0473022c153c4b70f350cab0c208dd3a0670c40 Reviewed-on: https://chromium-review.googlesource.com/691374Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 6276b922
......@@ -458,4 +458,19 @@ PixmapSurface::~PixmapSurface()
{
}
// SurfaceDeleter implementation.
SurfaceDeleter::SurfaceDeleter(const Display *display) : mDisplay(display)
{
}
SurfaceDeleter::~SurfaceDeleter()
{
}
void SurfaceDeleter::operator()(Surface *surface)
{
ANGLE_SWALLOW_ERR(surface->onDestroy(mDisplay));
}
} // namespace egl
......@@ -215,7 +215,18 @@ class PixmapSurface final : public Surface
~PixmapSurface() override;
};
using SurfacePointer = angle::UniqueObjectPointer<Surface, Display>;
class SurfaceDeleter final
{
public:
SurfaceDeleter(const Display *display);
~SurfaceDeleter();
void operator()(Surface *surface);
private:
const Display *mDisplay;
};
using SurfacePointer = angle::UniqueObjectPointerBase<Surface, SurfaceDeleter>;
} // namespace egl
......
......@@ -426,18 +426,42 @@ inline GLenum FramebufferBindingToEnum(FramebufferBinding binding)
}
}
// Helper class for wrapping an onDestroy function.
template <typename ObjT, typename ContextT>
class UniqueObjectPointer : angle::NonCopyable
class DestroyThenDelete
{
public:
DestroyThenDelete(const ContextT *context) : mContext(context) {}
void operator()(ObjT *obj)
{
ANGLE_SWALLOW_ERR(obj->onDestroy(mContext));
delete obj;
}
private:
const ContextT *mContext;
};
// Helper class for wrapping an onDestroy function.
template <typename ObjT, typename DeleterT>
class UniqueObjectPointerBase : angle::NonCopyable
{
public:
UniqueObjectPointer(const ContextT *context) : mObject(nullptr), mContext(context) {}
UniqueObjectPointer(ObjT *obj, const ContextT *context) : mObject(obj), mContext(context) {}
~UniqueObjectPointer()
template <typename ContextT>
UniqueObjectPointerBase(const ContextT *context) : mObject(nullptr), mDeleter(context)
{
}
template <typename ContextT>
UniqueObjectPointerBase(ObjT *obj, const ContextT *context) : mObject(obj), mDeleter(context)
{
}
~UniqueObjectPointerBase()
{
if (mObject)
{
ANGLE_SWALLOW_ERR(mObject->onDestroy(mContext));
mDeleter(mObject);
}
}
......@@ -456,15 +480,19 @@ class UniqueObjectPointer : angle::NonCopyable
{
if (mObject)
{
ANGLE_SWALLOW_ERR(mObject->onDestroy(mContext));
mDeleter(mObject);
}
mObject = obj;
}
private:
ObjT *mObject;
const ContextT *mContext;
DeleterT mDeleter;
};
template <typename ObjT, typename ContextT>
using UniqueObjectPointer = UniqueObjectPointerBase<ObjT, DestroyThenDelete<ObjT, ContextT>>;
} // namespace angle
namespace gl
......
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