gfx/layers/client/TextureClientPool.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f54ab4771e5f
1 /* -*- Mode: C++; tab-width: 20; 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_GFX_TEXTURECLIENTPOOL_H
7 #define MOZILLA_GFX_TEXTURECLIENTPOOL_H
8
9 #include "mozilla/gfx/Types.h"
10 #include "mozilla/gfx/Point.h"
11 #include "mozilla/RefPtr.h"
12 #include "TextureClient.h"
13 #include "nsITimer.h"
14 #include <stack>
15
16 namespace mozilla {
17 namespace layers {
18
19 class ISurfaceAllocator;
20
21 class TextureClientPool MOZ_FINAL
22 {
23 ~TextureClientPool();
24
25 public:
26 NS_INLINE_DECL_REFCOUNTING(TextureClientPool)
27
28 TextureClientPool(gfx::SurfaceFormat aFormat, gfx::IntSize aSize,
29 ISurfaceAllocator *aAllocator);
30
31 /**
32 * Gets an allocated TextureClient of size and format that are determined
33 * by the initialisation parameters given to the pool. This will either be
34 * a cached client that was returned to the pool, or a newly allocated
35 * client if one isn't available.
36 *
37 * All clients retrieved by this method should be returned using the return
38 * functions, or reported lost so that the pool can manage its size correctly.
39 */
40 TemporaryRef<TextureClient> GetTextureClient();
41
42 /**
43 * Return a TextureClient that is no longer being used and is ready for
44 * immediate re-use or destruction.
45 */
46 void ReturnTextureClient(TextureClient *aClient);
47
48 /**
49 * Return a TextureClient that is not yet ready to be reused, but will be
50 * imminently.
51 */
52 void ReturnTextureClientDeferred(TextureClient *aClient);
53
54 /**
55 * Attempt to shrink the pool so that there are no more than
56 * sMaxTextureClients clients outstanding.
57 */
58 void ShrinkToMaximumSize();
59
60 /**
61 * Attempt to shrink the pool so that there are no more than sMinCacheSize
62 * unused clients.
63 */
64 void ShrinkToMinimumSize();
65
66 /**
67 * Return any clients to the pool that were previously returned in
68 * ReturnTextureClientDeferred.
69 */
70 void ReturnDeferredClients();
71
72 /**
73 * Report that a client retrieved via GetTextureClient() has become
74 * unusable, so that it will no longer be tracked.
75 */
76 void ReportClientLost() { mOutstandingClients--; }
77
78 /**
79 * Calling this will cause the pool to attempt to relinquish any unused
80 * clients.
81 */
82 void Clear();
83
84 gfx::SurfaceFormat GetFormat() { return mFormat; }
85
86 private:
87 // The time in milliseconds before the pool will be shrunk to the minimum
88 // size after returning a client.
89 static const uint32_t sShrinkTimeout = 1000;
90
91 // The minimum size of the pool (the number of tiles that will be kept after
92 // shrinking).
93 static const uint32_t sMinCacheSize = 0;
94
95 // The maximum number of texture clients managed by this pool that we want
96 // to remain active.
97 static const uint32_t sMaxTextureClients = 50;
98
99 gfx::SurfaceFormat mFormat;
100 gfx::IntSize mSize;
101
102 uint32_t mOutstandingClients;
103
104 // On b2g gonk, std::queue might be a better choice.
105 // On ICS, fence wait happens implicitly before drawing.
106 // Since JB, fence wait happens explicitly when fetching a client from the pool.
107 std::stack<RefPtr<TextureClient> > mTextureClients;
108 std::stack<RefPtr<TextureClient> > mTextureClientsDeferred;
109 nsRefPtr<nsITimer> mTimer;
110 RefPtr<ISurfaceAllocator> mSurfaceAllocator;
111 };
112
113 }
114 }
115 #endif /* MOZILLA_GFX_TEXTURECLIENTPOOL_H */

mercurial