Commit 9fe2370a authored by Klaus Weidner's avatar Klaus Weidner Committed by Commit Bot

Avoid WebXR resource leak on destruction

The DrawingBuffer code that WebXRDrawingBuffer is based on requires
a BeginDestruction method to be called to break a reference loop.
Both DrawingBuffer and its ColorBuffer subclass are refcounted and
store references to each other.

Add the BeginDestruction method to WebXRDrawingBuffer which was mentioned
in a copied comment but not implemented.

BUG=857547

Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I3bef8e975c26ca432eafe7eb4ba8c4daae715796
Reviewed-on: https://chromium-review.googlesource.com/1120645Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571693}
parent e5df4ad6
......@@ -121,10 +121,10 @@ XRWebGLLayer::XRWebGLLayer(XRSession* session,
double framebuffer_scale)
: XRLayer(session, kXRWebGLLayerType),
webgl_context_(webgl_context),
drawing_buffer_(drawing_buffer),
drawing_buffer_(std::move(drawing_buffer)),
framebuffer_(framebuffer),
framebuffer_scale_(framebuffer_scale) {
DCHECK(drawing_buffer);
DCHECK(drawing_buffer_);
// If the contents need mirroring, indicate that to the drawing buffer.
if (session->exclusive() && session->outputContext() &&
session->device()->external()) {
......@@ -137,6 +137,7 @@ XRWebGLLayer::XRWebGLLayer(XRSession* session,
XRWebGLLayer::~XRWebGLLayer() {
if (mirroring_)
drawing_buffer_->SetMirrorClient(nullptr);
drawing_buffer_->BeginDestruction();
}
void XRWebGLLayer::getXRWebGLRenderingContext(
......
......@@ -114,6 +114,12 @@ XRWebGLDrawingBuffer::XRWebGLDrawingBuffer(DrawingBuffer* drawing_buffer,
alpha_(want_alpha_channel),
multiview_(false) {}
void XRWebGLDrawingBuffer::BeginDestruction() {
back_color_buffer_ = nullptr;
front_color_buffer_ = nullptr;
recycled_color_buffer_queue_.clear();
}
// TODO(bajones): The GL resources allocated in this function are leaking. Add
// a way to clean up the buffers when the layer is GCed or the session ends.
bool XRWebGLDrawingBuffer::Initialize(const IntSize& size,
......
......@@ -63,13 +63,18 @@ class PLATFORM_EXPORT XRWebGLDrawingBuffer
void UseSharedBuffer(const gpu::MailboxHolder&);
void DoneWithSharedBuffer();
// Prepare for destruction by breaking reference loops. This must be called to
// avoid memory leaks, drawing buffer and color buffers are refcounted and
// store references to each other.
void BeginDestruction();
private:
struct ColorBuffer : public RefCounted<ColorBuffer> {
ColorBuffer(XRWebGLDrawingBuffer*, const IntSize&, GLuint texture_id);
~ColorBuffer();
// The owning XRWebGLDrawingBuffer. Note that DrawingBuffer is explicitly
// destroyed by the beginDestruction method, which will eventually drain all
// destroyed by the BeginDestruction method, which will eventually drain all
// of its ColorBuffers.
scoped_refptr<XRWebGLDrawingBuffer> drawing_buffer;
const IntSize size;
......
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