Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#ifndef mozilla_layers_SurfacePool_h
7
#define mozilla_layers_SurfacePool_h
8
9
#include "mozilla/Maybe.h"
10
#include "mozilla/ThreadSafeWeakPtr.h"
11
12
#include "GLTypes.h"
13
#include "nsISupportsImpl.h"
14
#include "nsRegion.h"
15
16
namespace mozilla {
17
18
namespace gl {
19
class GLContext;
20
} // namespace gl
21
22
namespace layers {
23
24
class SurfacePoolHandle;
25
26
// A pool of surfaces for NativeLayers. Manages GL resources. Since GLContexts
27
// are bound to their creator thread, a pool should not be shared across
28
// threads. Call Create() to create an instance. Call GetHandleForGL() to obtain
29
// a handle that can be passed to NativeLayerRoot::CreateLayer.
30
class SurfacePool {
31
public:
32
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool);
33
34
#ifdef XP_MACOSX
35
static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit);
36
#endif
37
38
// aGL can be nullptr.
39
virtual RefPtr<SurfacePoolHandle> GetHandleForGL(gl::GLContext* aGL) = 0;
40
virtual void DestroyGLResourcesForContext(gl::GLContext* aGL) = 0;
41
42
protected:
43
virtual ~SurfacePool() = default;
44
};
45
46
class SurfacePoolHandleCA;
47
48
// A handle to the process-wide surface pool. Users should create one handle per
49
// OS window, and call OnBeginFrame() and OnEndFrame() on the handle at
50
// appropriate times. OnBeginFrame() and OnEndFrame() should be called on the
51
// thread that the surface pool was created on.
52
// These handles are stored on NativeLayers that are created with them and keep
53
// the SurfacePool alive.
54
class SurfacePoolHandle {
55
public:
56
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePoolHandle);
57
virtual SurfacePoolHandleCA* AsSurfacePoolHandleCA() { return nullptr; }
58
59
virtual RefPtr<SurfacePool> Pool() = 0;
60
61
// Should be called every frame, in order to do rate-limited cleanup tasks.
62
virtual void OnBeginFrame() = 0;
63
virtual void OnEndFrame() = 0;
64
65
protected:
66
virtual ~SurfacePoolHandle() = default;
67
};
68
69
} // namespace layers
70
} // namespace mozilla
71
72
#endif // mozilla_layers_SurfacePool_h