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 "gpu/command_buffer/client/gles2_interface.h" | 8 #include "gpu/command_buffer/client/gles2_interface.h" |
9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
10 #include "wtf/Deque.h" | 10 #include "wtf/Deque.h" |
11 #include "wtf/Noncopyable.h" | 11 #include "wtf/Noncopyable.h" |
12 #include "wtf/OwnPtr.h" | 12 #include <memory> |
13 #include "wtf/PassOwnPtr.h" | |
14 | 13 |
15 namespace blink { | 14 namespace blink { |
16 | 15 |
17 class WebGraphicsContext3DProvider; | 16 class WebGraphicsContext3DProvider; |
18 | 17 |
19 // Purpose: to limit the amount of worked queued for execution | 18 // Purpose: to limit the amount of worked queued for execution |
20 // (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 |
21 // to catch up. The Prevents unsynchronized tight animation loops | 20 // to catch up. The Prevents unsynchronized tight animation loops |
22 // from cause a GPU denial of service. | 21 // from cause a GPU denial of service. |
23 // | 22 // |
24 // 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 |
25 // and makes sure there are never more that 'maxPendingTicks' fences | 24 // and makes sure there are never more that 'maxPendingTicks' fences |
26 // that are awaiting completion. On platforms that do not support | 25 // that are awaiting completion. On platforms that do not support |
27 // fences, we use glFinish instead. glFinish will only be called in | 26 // fences, we use glFinish instead. glFinish will only be called in |
28 // unsynchronized cases that submit more than maxPendingTicks animation | 27 // unsynchronized cases that submit more than maxPendingTicks animation |
29 // tick per compositor frame, which should be quite rare. | 28 // tick per compositor frame, which should be quite rare. |
30 // | 29 // |
31 // 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 |
32 // frame must call tick(). reset() must be called when the animation | 31 // frame must call tick(). reset() must be called when the animation |
33 // is consumed by committing to the compositor. Several rate limiters can | 32 // is consumed by committing to the compositor. Several rate limiters can |
34 // be used concurrently: they will each use their own sequences of | 33 // be used concurrently: they will each use their own sequences of |
35 // fences which may be interleaved. When the graphics context is lost | 34 // fences which may be interleaved. When the graphics context is lost |
36 // and later restored, the existing rate limiter must be destroyed and | 35 // and later restored, the existing rate limiter must be destroyed and |
37 // a new one created. | 36 // a new one created. |
38 | 37 |
39 class SharedContextRateLimiter final { | 38 class SharedContextRateLimiter final { |
40 USING_FAST_MALLOC(SharedContextRateLimiter); | 39 USING_FAST_MALLOC(SharedContextRateLimiter); |
41 WTF_MAKE_NONCOPYABLE(SharedContextRateLimiter); | 40 WTF_MAKE_NONCOPYABLE(SharedContextRateLimiter); |
42 public: | 41 public: |
43 static PassOwnPtr<SharedContextRateLimiter> create(unsigned maxPendingTicks)
; | 42 static std::unique_ptr<SharedContextRateLimiter> create(unsigned maxPendingT
icks); |
44 void tick(); | 43 void tick(); |
45 void reset(); | 44 void reset(); |
46 private: | 45 private: |
47 SharedContextRateLimiter(unsigned maxPendingTicks); | 46 SharedContextRateLimiter(unsigned maxPendingTicks); |
48 | 47 |
49 OwnPtr<WebGraphicsContext3DProvider> m_contextProvider; | 48 std::unique_ptr<WebGraphicsContext3DProvider> m_contextProvider; |
50 Deque<GLuint> m_queries; | 49 Deque<GLuint> m_queries; |
51 unsigned m_maxPendingTicks; | 50 unsigned m_maxPendingTicks; |
52 bool m_canUseSyncQueries; | 51 bool m_canUseSyncQueries; |
53 }; | 52 }; |
54 | 53 |
55 } // namespace blink | 54 } // namespace blink |
56 | 55 |
57 #endif | 56 #endif |
OLD | NEW |