OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SharedContextRateLimiter_h | 5 #ifndef SharedContextRateLimiter_h |
6 #define SharedContextRateLimiter_h | 6 #define SharedContextRateLimiter_h |
7 | 7 |
8 #include "public/platform/WebGraphicsContext3D.h" | 8 #include "public/platform/WebGraphicsContext3D.h" |
| 9 #include "wtf/Allocator.h" |
9 #include "wtf/Deque.h" | 10 #include "wtf/Deque.h" |
| 11 #include "wtf/Noncopyable.h" |
10 #include "wtf/OwnPtr.h" | 12 #include "wtf/OwnPtr.h" |
11 | 13 |
12 namespace blink { | 14 namespace blink { |
13 | 15 |
14 class WebGraphicsContext3DProvider; | 16 class WebGraphicsContext3DProvider; |
15 | 17 |
16 // Purpose: to limit the amount of worked queued for execution | 18 // Purpose: to limit the amount of worked queued for execution |
17 // (backlog) on the GPU by blocking the main thread to allow the GPU | 19 // (backlog) on the GPU by blocking the main thread to allow the GPU |
18 // to catch up. The Prevents unsynchronized tight animation loops | 20 // to catch up. The Prevents unsynchronized tight animation loops |
19 // from cause a GPU denial of service. | 21 // from cause a GPU denial of service. |
20 // | 22 // |
21 // How it works: The rate limiter uses GPU fences to mark each tick | 23 // How it works: The rate limiter uses GPU fences to mark each tick |
22 // and makes sure there are never more that 'maxPendingTicks' fences | 24 // and makes sure there are never more that 'maxPendingTicks' fences |
23 // that are awaiting completion. On platforms that do not support | 25 // that are awaiting completion. On platforms that do not support |
24 // fences, we use glFinish instead. glFinish will only be called in | 26 // fences, we use glFinish instead. glFinish will only be called in |
25 // unsynchronized cases that submit more than maxPendingTicks animation | 27 // unsynchronized cases that submit more than maxPendingTicks animation |
26 // tick per compositor frame, which should be quite rare. | 28 // tick per compositor frame, which should be quite rare. |
27 // | 29 // |
28 // How to use it: Each unit of work that constitutes a complete animation | 30 // How to use it: Each unit of work that constitutes a complete animation |
29 // frame must call tick(). reset() must be called when the animation | 31 // frame must call tick(). reset() must be called when the animation |
30 // is consumed by committing to the compositor. Several rate limiters can | 32 // is consumed by committing to the compositor. Several rate limiters can |
31 // be used concurrently: they will each use their own sequences of | 33 // be used concurrently: they will each use their own sequences of |
32 // fences which may be interleaved. When the graphics context is lost | 34 // fences which may be interleaved. When the graphics context is lost |
33 // and later restored, the existing rate limiter must be destroyed and | 35 // and later restored, the existing rate limiter must be destroyed and |
34 // a new one created. | 36 // a new one created. |
35 | 37 |
36 class SharedContextRateLimiter { | 38 class SharedContextRateLimiter final { |
| 39 USING_FAST_MALLOC(SharedContextRateLimiter); |
| 40 WTF_MAKE_NONCOPYABLE(SharedContextRateLimiter); |
37 public: | 41 public: |
38 static PassOwnPtr<SharedContextRateLimiter> create(unsigned maxPendingTicks)
; | 42 static PassOwnPtr<SharedContextRateLimiter> create(unsigned maxPendingTicks)
; |
39 void tick(); | 43 void tick(); |
40 void reset(); | 44 void reset(); |
41 private: | 45 private: |
42 SharedContextRateLimiter(unsigned maxPendingTicks); | 46 SharedContextRateLimiter(unsigned maxPendingTicks); |
43 | 47 |
44 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; | 48 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; |
45 Deque<WebGLId> m_queries; | 49 Deque<WebGLId> m_queries; |
46 unsigned m_maxPendingTicks; | 50 unsigned m_maxPendingTicks; |
47 bool m_canUseSyncQueries; | 51 bool m_canUseSyncQueries; |
48 }; | 52 }; |
49 | 53 |
50 } // blink | 54 } // blink |
51 | 55 |
52 #endif | 56 #endif |
OLD | NEW |