gecko-dev/gfx/layers/SurfacePool.h
Markus Stange 0f70058b6f Bug 1592044 - Reduce the frequency of IOSurface and framebuffer creation and destruction with the help of a surface pool. r=jgilbert
There are multiple SurfacePools: Main thread painting and the non-WebRender compositors create a new pool per window, and WebRender creates one shared pool across all windows. The non-WebRender users set the pool size limit to zero, i.e. no recycling across paints. This preserves the pre-existing behavior.
WebRender's pool size is configurable with the gfx.webrender.compositor.surface-pool-size pref.
Every window holds on to a SurfacePoolHandle. A SurfacePoolHandle has an owning reference to the pool, via a surface pool wrapper. Once all handles are gone, the surface pool goes away, too.
The SurfacePool holds on to IOSurfaces and MozFramebuffers. Both are created on demand, independently, but are associated with each other.
A given NativeLayer uses only one surface pool handle during its lifetime. The native layer no longer influences which GLContext its framebuffers are created for; the GL context is now managed by the surface pool handle.
As a result, a NativeLayer can no longer change which GLContext its framebuffers are created by.
So in the future, if we ever need to migrate a window frome one GLContext to another, we will need to recreate the NativeLayers inside it. I think that's ok.

Differential Revision: https://phabricator.services.mozilla.com/D54859

--HG--
extra : moz-landing-system : lando
2019-12-18 21:01:51 +00:00

73 lines
2.2 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_layers_SurfacePool_h
#define mozilla_layers_SurfacePool_h
#include "mozilla/Maybe.h"
#include "mozilla/ThreadSafeWeakPtr.h"
#include "GLTypes.h"
#include "nsISupportsImpl.h"
#include "nsRegion.h"
namespace mozilla {
namespace gl {
class GLContext;
} // namespace gl
namespace layers {
class SurfacePoolHandle;
// A pool of surfaces for NativeLayers. Manages GL resources. Since GLContexts
// are bound to their creator thread, a pool should not be shared across
// threads. Call Create() to create an instance. Call GetHandleForGL() to obtain
// a handle that can be passed to NativeLayerRoot::CreateLayer.
class SurfacePool {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool);
#ifdef XP_MACOSX
static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit);
#endif
// aGL can be nullptr.
virtual RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) = 0;
virtual void DestroyGLResourcesForContext(gl::GLContext* aGL) = 0;
protected:
virtual ~SurfacePool() {}
};
class SurfacePoolHandleCA;
// A handle to the process-wide surface pool. Users should create one handle per
// OS window, and call OnBeginFrame() and OnEndFrame() on the handle at
// appropriate times. OnBeginFrame() and OnEndFrame() should be called on the
// thread that the surface pool was created on.
// These handles are stored on NativeLayers that are created with them and keep
// the SurfacePool alive.
class SurfacePoolHandle {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle);
virtual SurfacePoolHandleCA* AsSurfacePoolHandleCA() { return nullptr; }
virtual RefPtr<SurfacePool> Pool() = 0;
// Should be called every frame, in order to do rate-limited cleanup tasks.
virtual void OnBeginFrame() = 0;
virtual void OnEndFrame() = 0;
protected:
virtual ~SurfacePoolHandle() {}
};
} // namespace layers
} // namespace mozilla
#endif // mozilla_layers_SurfacePool_h