OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 CCSingleThreadProxy_h | 5 #ifndef CCSingleThreadProxy_h |
6 #define CCSingleThreadProxy_h | 6 #define CCSingleThreadProxy_h |
7 | 7 |
8 #include "CCAnimationEvents.h" | 8 #include "CCAnimationEvents.h" |
9 #include "CCLayerTreeHostImpl.h" | 9 #include "CCLayerTreeHostImpl.h" |
10 #include "CCProxy.h" | 10 #include "CCProxy.h" |
11 #include <base/time.h> | 11 #include <base/time.h> |
12 #include <limits> | 12 #include <limits> |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 class CCLayerTreeHost; | 16 class LayerTreeHost; |
17 | 17 |
18 class CCSingleThreadProxy : public CCProxy, CCLayerTreeHostImplClient { | 18 class SingleThreadProxy : public Proxy, LayerTreeHostImplClient { |
19 public: | 19 public: |
20 static scoped_ptr<CCProxy> create(CCLayerTreeHost*); | 20 static scoped_ptr<Proxy> create(LayerTreeHost*); |
21 virtual ~CCSingleThreadProxy(); | 21 virtual ~SingleThreadProxy(); |
22 | 22 |
23 // CCProxy implementation | 23 // Proxy implementation |
24 virtual bool compositeAndReadback(void *pixels, const IntRect&) OVERRIDE; | 24 virtual bool compositeAndReadback(void *pixels, const IntRect&) OVERRIDE; |
25 virtual void startPageScaleAnimation(const IntSize& targetPosition, bool use
Anchor, float scale, double duration) OVERRIDE; | 25 virtual void startPageScaleAnimation(const IntSize& targetPosition, bool use
Anchor, float scale, double duration) OVERRIDE; |
26 virtual void finishAllRendering() OVERRIDE; | 26 virtual void finishAllRendering() OVERRIDE; |
27 virtual bool isStarted() const OVERRIDE; | 27 virtual bool isStarted() const OVERRIDE; |
28 virtual bool initializeContext() OVERRIDE; | 28 virtual bool initializeContext() OVERRIDE; |
29 virtual void setSurfaceReady() OVERRIDE; | 29 virtual void setSurfaceReady() OVERRIDE; |
30 virtual void setVisible(bool) OVERRIDE; | 30 virtual void setVisible(bool) OVERRIDE; |
31 virtual bool initializeRenderer() OVERRIDE; | 31 virtual bool initializeRenderer() OVERRIDE; |
32 virtual bool recreateContext() OVERRIDE; | 32 virtual bool recreateContext() OVERRIDE; |
33 virtual void renderingStats(CCRenderingStats*) OVERRIDE; | 33 virtual void renderingStats(RenderingStats*) OVERRIDE; |
34 virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE; | 34 virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE; |
35 virtual void loseContext() OVERRIDE; | 35 virtual void loseContext() OVERRIDE; |
36 virtual void setNeedsAnimate() OVERRIDE; | 36 virtual void setNeedsAnimate() OVERRIDE; |
37 virtual void setNeedsCommit() OVERRIDE; | 37 virtual void setNeedsCommit() OVERRIDE; |
38 virtual void setNeedsRedraw() OVERRIDE; | 38 virtual void setNeedsRedraw() OVERRIDE; |
39 virtual bool commitRequested() const OVERRIDE; | 39 virtual bool commitRequested() const OVERRIDE; |
40 virtual void didAddAnimation() OVERRIDE; | 40 virtual void didAddAnimation() OVERRIDE; |
41 virtual void start() OVERRIDE; | 41 virtual void start() OVERRIDE; |
42 virtual void stop() OVERRIDE; | 42 virtual void stop() OVERRIDE; |
43 virtual size_t maxPartialTextureUpdates() const OVERRIDE; | 43 virtual size_t maxPartialTextureUpdates() const OVERRIDE; |
44 virtual void acquireLayerTextures() OVERRIDE { } | 44 virtual void acquireLayerTextures() OVERRIDE { } |
45 virtual void forceSerializeOnSwapBuffers() OVERRIDE; | 45 virtual void forceSerializeOnSwapBuffers() OVERRIDE; |
46 | 46 |
47 // CCLayerTreeHostImplClient implementation | 47 // LayerTreeHostImplClient implementation |
48 virtual void didLoseContextOnImplThread() OVERRIDE { } | 48 virtual void didLoseContextOnImplThread() OVERRIDE { } |
49 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE; | 49 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE; |
50 virtual void onVSyncParametersChanged(double monotonicTimebase, double inter
valInSeconds) OVERRIDE { } | 50 virtual void onVSyncParametersChanged(double monotonicTimebase, double inter
valInSeconds) OVERRIDE { } |
51 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { } | 51 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { } |
52 virtual void setNeedsRedrawOnImplThread() OVERRIDE; | 52 virtual void setNeedsRedrawOnImplThread() OVERRIDE; |
53 virtual void setNeedsCommitOnImplThread() OVERRIDE; | 53 virtual void setNeedsCommitOnImplThread() OVERRIDE; |
54 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<CCAnimat
ionEventsVector>, double wallClockTime) OVERRIDE; | 54 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<Animatio
nEventsVector>, double wallClockTime) OVERRIDE; |
55 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes) OVER
RIDE; | 55 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes) OVER
RIDE; |
56 | 56 |
57 // Called by the legacy path where RenderWidget does the scheduling. | 57 // Called by the legacy path where RenderWidget does the scheduling. |
58 void compositeImmediately(); | 58 void compositeImmediately(); |
59 | 59 |
60 private: | 60 private: |
61 explicit CCSingleThreadProxy(CCLayerTreeHost*); | 61 explicit SingleThreadProxy(LayerTreeHost*); |
62 | 62 |
63 bool commitAndComposite(); | 63 bool commitAndComposite(); |
64 void doCommit(scoped_ptr<CCTextureUpdateQueue>); | 64 void doCommit(scoped_ptr<TextureUpdateQueue>); |
65 bool doComposite(); | 65 bool doComposite(); |
66 void didSwapFrame(); | 66 void didSwapFrame(); |
67 | 67 |
68 // Accessed on main thread only. | 68 // Accessed on main thread only. |
69 CCLayerTreeHost* m_layerTreeHost; | 69 LayerTreeHost* m_layerTreeHost; |
70 bool m_contextLost; | 70 bool m_contextLost; |
71 | 71 |
72 // Holds on to the context between initializeContext() and initializeRendere
r() calls. Shouldn't | 72 // Holds on to the context between initializeContext() and initializeRendere
r() calls. Shouldn't |
73 // be used for anything else. | 73 // be used for anything else. |
74 scoped_ptr<CCGraphicsContext> m_contextBeforeInitialization; | 74 scoped_ptr<GraphicsContext> m_contextBeforeInitialization; |
75 | 75 |
76 // Used on the CCThread, but checked on main thread during initialization/sh
utdown. | 76 // Used on the Thread, but checked on main thread during initialization/shut
down. |
77 scoped_ptr<CCLayerTreeHostImpl> m_layerTreeHostImpl; | 77 scoped_ptr<LayerTreeHostImpl> m_layerTreeHostImpl; |
78 bool m_rendererInitialized; | 78 bool m_rendererInitialized; |
79 RendererCapabilities m_RendererCapabilitiesForMainThread; | 79 RendererCapabilities m_RendererCapabilitiesForMainThread; |
80 | 80 |
81 bool m_nextFrameIsNewlyCommittedFrame; | 81 bool m_nextFrameIsNewlyCommittedFrame; |
82 | 82 |
83 base::TimeDelta m_totalCommitTime; | 83 base::TimeDelta m_totalCommitTime; |
84 size_t m_totalCommitCount; | 84 size_t m_totalCommitCount; |
85 }; | 85 }; |
86 | 86 |
87 // For use in the single-threaded case. In debug builds, it pretends that the | 87 // For use in the single-threaded case. In debug builds, it pretends that the |
88 // code is running on the impl thread to satisfy assertion checks. | 88 // code is running on the impl thread to satisfy assertion checks. |
89 class DebugScopedSetImplThread { | 89 class DebugScopedSetImplThread { |
90 public: | 90 public: |
91 DebugScopedSetImplThread() | 91 DebugScopedSetImplThread() |
92 { | 92 { |
93 #if !ASSERT_DISABLED | 93 #if !ASSERT_DISABLED |
94 CCProxy::setCurrentThreadIsImplThread(true); | 94 Proxy::setCurrentThreadIsImplThread(true); |
95 #endif | 95 #endif |
96 } | 96 } |
97 ~DebugScopedSetImplThread() | 97 ~DebugScopedSetImplThread() |
98 { | 98 { |
99 #if !ASSERT_DISABLED | 99 #if !ASSERT_DISABLED |
100 CCProxy::setCurrentThreadIsImplThread(false); | 100 Proxy::setCurrentThreadIsImplThread(false); |
101 #endif | 101 #endif |
102 } | 102 } |
103 }; | 103 }; |
104 | 104 |
105 // For use in the single-threaded case. In debug builds, it pretends that the | 105 // For use in the single-threaded case. In debug builds, it pretends that the |
106 // code is running on the main thread to satisfy assertion checks. | 106 // code is running on the main thread to satisfy assertion checks. |
107 class DebugScopedSetMainThread { | 107 class DebugScopedSetMainThread { |
108 public: | 108 public: |
109 DebugScopedSetMainThread() | 109 DebugScopedSetMainThread() |
110 { | 110 { |
111 #if !ASSERT_DISABLED | 111 #if !ASSERT_DISABLED |
112 CCProxy::setCurrentThreadIsImplThread(false); | 112 Proxy::setCurrentThreadIsImplThread(false); |
113 #endif | 113 #endif |
114 } | 114 } |
115 ~DebugScopedSetMainThread() | 115 ~DebugScopedSetMainThread() |
116 { | 116 { |
117 #if !ASSERT_DISABLED | 117 #if !ASSERT_DISABLED |
118 CCProxy::setCurrentThreadIsImplThread(true); | 118 Proxy::setCurrentThreadIsImplThread(true); |
119 #endif | 119 #endif |
120 } | 120 } |
121 }; | 121 }; |
122 | 122 |
123 // For use in the single-threaded case. In debug builds, it pretends that the | 123 // For use in the single-threaded case. In debug builds, it pretends that the |
124 // code is running on the impl thread and that the main thread is blocked to | 124 // code is running on the impl thread and that the main thread is blocked to |
125 // satisfy assertion checks | 125 // satisfy assertion checks |
126 class DebugScopedSetImplThreadAndMainThreadBlocked { | 126 class DebugScopedSetImplThreadAndMainThreadBlocked { |
127 private: | 127 private: |
128 DebugScopedSetImplThread m_implThread; | 128 DebugScopedSetImplThread m_implThread; |
129 DebugScopedSetMainThreadBlocked m_mainThreadBlocked; | 129 DebugScopedSetMainThreadBlocked m_mainThreadBlocked; |
130 }; | 130 }; |
131 | 131 |
132 } // namespace cc | 132 } // namespace cc |
133 | 133 |
134 #endif | 134 #endif |
OLD | NEW |