OLD | NEW |
1 // Copyright 2012 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 |
| 5 #ifndef CCThreadProxy_h |
| 6 #define CCThreadProxy_h |
| 7 |
| 8 #include "CCAnimationEvents.h" |
| 9 #include "CCCompletionEvent.h" |
| 10 #include "CCLayerTreeHostImpl.h" |
| 11 #include "CCProxy.h" |
| 12 #include "CCScheduler.h" |
| 13 #include "CCTextureUpdateController.h" |
| 14 #include <base/time.h> |
| 15 #include <wtf/OwnPtr.h> |
| 16 |
| 17 namespace cc { |
| 18 |
| 19 class CCInputHandler; |
| 20 class CCLayerTreeHost; |
| 21 class CCScheduler; |
| 22 class CCScopedThreadProxy; |
| 23 class CCTextureUpdateQueue; |
| 24 class CCThread; |
| 25 class CCThreadProxyContextRecreationTimer; |
| 26 |
| 27 class CCThreadProxy : public CCProxy, CCLayerTreeHostImplClient, CCSchedulerClie
nt, CCTextureUpdateControllerClient { |
| 28 public: |
| 29 static scoped_ptr<CCProxy> create(CCLayerTreeHost*); |
| 30 |
| 31 virtual ~CCThreadProxy(); |
| 32 |
| 33 // CCProxy implementation |
| 34 virtual bool compositeAndReadback(void *pixels, const IntRect&) OVERRIDE; |
| 35 virtual void startPageScaleAnimation(const IntSize& targetPosition, bool use
Anchor, float scale, double duration) OVERRIDE; |
| 36 virtual void finishAllRendering() OVERRIDE; |
| 37 virtual bool isStarted() const OVERRIDE; |
| 38 virtual bool initializeContext() OVERRIDE; |
| 39 virtual void setSurfaceReady() OVERRIDE; |
| 40 virtual void setVisible(bool) OVERRIDE; |
| 41 virtual bool initializeRenderer() OVERRIDE; |
| 42 virtual bool recreateContext() OVERRIDE; |
| 43 virtual void renderingStats(CCRenderingStats*) OVERRIDE; |
| 44 virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE; |
| 45 virtual void loseContext() OVERRIDE; |
| 46 virtual void setNeedsAnimate() OVERRIDE; |
| 47 virtual void setNeedsCommit() OVERRIDE; |
| 48 virtual void setNeedsRedraw() OVERRIDE; |
| 49 virtual bool commitRequested() const OVERRIDE; |
| 50 virtual void didAddAnimation() OVERRIDE { } |
| 51 virtual void start() OVERRIDE; |
| 52 virtual void stop() OVERRIDE; |
| 53 virtual size_t maxPartialTextureUpdates() const OVERRIDE; |
| 54 virtual void acquireLayerTextures() OVERRIDE; |
| 55 virtual void forceSerializeOnSwapBuffers() OVERRIDE; |
| 56 |
| 57 // CCLayerTreeHostImplClient implementation |
| 58 virtual void didLoseContextOnImplThread() OVERRIDE; |
| 59 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE; |
| 60 virtual void onVSyncParametersChanged(double monotonicTimebase, double inter
valInSeconds) OVERRIDE; |
| 61 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE; |
| 62 virtual void setNeedsRedrawOnImplThread() OVERRIDE; |
| 63 virtual void setNeedsCommitOnImplThread() OVERRIDE; |
| 64 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<CCAnimat
ionEventsVector>, double wallClockTime) OVERRIDE; |
| 65 virtual void releaseContentsTexturesOnImplThread() OVERRIDE; |
| 66 |
| 67 // CCSchedulerClient implementation |
| 68 virtual void scheduledActionBeginFrame() OVERRIDE; |
| 69 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapIfPossi
ble() OVERRIDE; |
| 70 virtual CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapForced(
) OVERRIDE; |
| 71 virtual void scheduledActionCommit() OVERRIDE; |
| 72 virtual void scheduledActionBeginContextRecreation() OVERRIDE; |
| 73 virtual void scheduledActionAcquireLayerTexturesForMainThread() OVERRIDE; |
| 74 virtual void didAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE; |
| 75 |
| 76 // CCTextureUpdateControllerClient implementation |
| 77 virtual void readyToFinalizeTextureUpdates() OVERRIDE; |
| 78 |
| 79 private: |
| 80 explicit CCThreadProxy(CCLayerTreeHost*); |
| 81 friend class CCThreadProxyContextRecreationTimer; |
| 82 |
| 83 // Set on impl thread, read on main thread. |
| 84 struct BeginFrameAndCommitState { |
| 85 BeginFrameAndCommitState(); |
| 86 ~BeginFrameAndCommitState(); |
| 87 |
| 88 double monotonicFrameBeginTime; |
| 89 scoped_ptr<CCScrollAndScaleSet> scrollInfo; |
| 90 WebKit::WebTransformationMatrix implTransform; |
| 91 CCPrioritizedTextureManager::BackingVector evictedContentsTexturesBackin
gs; |
| 92 size_t memoryAllocationLimitBytes; |
| 93 }; |
| 94 OwnPtr<BeginFrameAndCommitState> m_pendingBeginFrameRequest; |
| 95 |
| 96 // Called on main thread |
| 97 void beginFrame(); |
| 98 void didCommitAndDrawFrame(); |
| 99 void didCompleteSwapBuffers(); |
| 100 void setAnimationEvents(CCAnimationEventsVector*, double wallClockTime); |
| 101 void beginContextRecreation(); |
| 102 void tryToRecreateContext(); |
| 103 |
| 104 // Called on impl thread |
| 105 struct ReadbackRequest { |
| 106 CCCompletionEvent completion; |
| 107 bool success; |
| 108 void* pixels; |
| 109 IntRect rect; |
| 110 }; |
| 111 void forceBeginFrameOnImplThread(CCCompletionEvent*); |
| 112 void beginFrameCompleteOnImplThread(CCCompletionEvent*, PassOwnPtr<CCTexture
UpdateQueue>); |
| 113 void beginFrameAbortedOnImplThread(); |
| 114 void requestReadbackOnImplThread(ReadbackRequest*); |
| 115 void requestStartPageScaleAnimationOnImplThread(IntSize targetPosition, bool
useAnchor, float scale, double durationSec); |
| 116 void finishAllRenderingOnImplThread(CCCompletionEvent*); |
| 117 void initializeImplOnImplThread(CCCompletionEvent*, CCInputHandler*); |
| 118 void setSurfaceReadyOnImplThread(); |
| 119 void setVisibleOnImplThread(CCCompletionEvent*, bool); |
| 120 void initializeContextOnImplThread(CCGraphicsContext*); |
| 121 void initializeRendererOnImplThread(CCCompletionEvent*, bool* initializeSucc
eeded, RendererCapabilities*); |
| 122 void layerTreeHostClosedOnImplThread(CCCompletionEvent*); |
| 123 void setFullRootLayerDamageOnImplThread(); |
| 124 void acquireLayerTexturesForMainThreadOnImplThread(CCCompletionEvent*); |
| 125 void recreateContextOnImplThread(CCCompletionEvent*, CCGraphicsContext*, boo
l* recreateSucceeded, RendererCapabilities*); |
| 126 void renderingStatsOnImplThread(CCCompletionEvent*, CCRenderingStats*); |
| 127 CCScheduledActionDrawAndSwapResult scheduledActionDrawAndSwapInternal(bool f
orcedDraw); |
| 128 void forceSerializeOnSwapBuffersOnImplThread(CCCompletionEvent*); |
| 129 void setNeedsForcedCommitOnImplThread(); |
| 130 |
| 131 // Accessed on main thread only. |
| 132 bool m_animateRequested; // Set only when setNeedsAnimate is called. |
| 133 bool m_commitRequested; // Set only when setNeedsCommit is called. |
| 134 bool m_commitRequestSentToImplThread; // Set by setNeedsCommit and setNeedsA
nimate. |
| 135 bool m_forcedCommitRequested; |
| 136 OwnPtr<CCThreadProxyContextRecreationTimer> m_contextRecreationTimer; |
| 137 CCLayerTreeHost* m_layerTreeHost; |
| 138 bool m_rendererInitialized; |
| 139 RendererCapabilities m_RendererCapabilitiesMainThreadCopy; |
| 140 bool m_started; |
| 141 bool m_texturesAcquired; |
| 142 bool m_inCompositeAndReadback; |
| 143 |
| 144 scoped_ptr<CCLayerTreeHostImpl> m_layerTreeHostImpl; |
| 145 |
| 146 scoped_ptr<CCInputHandler> m_inputHandlerOnImplThread; |
| 147 |
| 148 OwnPtr<CCScheduler> m_schedulerOnImplThread; |
| 149 |
| 150 RefPtr<CCScopedThreadProxy> m_mainThreadProxy; |
| 151 |
| 152 // Holds on to the context we might use for compositing in between initializ
eContext() |
| 153 // and initializeRenderer() calls. |
| 154 scoped_ptr<CCGraphicsContext> m_contextBeforeInitializationOnImplThread; |
| 155 |
| 156 // Set when the main thread is waiting on a scheduledActionBeginFrame to be
issued. |
| 157 CCCompletionEvent* m_beginFrameCompletionEventOnImplThread; |
| 158 |
| 159 // Set when the main thread is waiting on a readback. |
| 160 ReadbackRequest* m_readbackRequestOnImplThread; |
| 161 |
| 162 // Set when the main thread is waiting on a commit to complete. |
| 163 CCCompletionEvent* m_commitCompletionEventOnImplThread; |
| 164 |
| 165 // Set when the main thread is waiting on layers to be drawn. |
| 166 CCCompletionEvent* m_textureAcquisitionCompletionEventOnImplThread; |
| 167 |
| 168 OwnPtr<CCTextureUpdateController> m_currentTextureUpdateControllerOnImplThre
ad; |
| 169 |
| 170 // Set when we need to reset the contentsTexturesPurged flag after the |
| 171 // commit. |
| 172 bool m_resetContentsTexturesPurgedAfterCommitOnImplThread; |
| 173 |
| 174 // Set when the next draw should post didCommitAndDrawFrame to the main thre
ad. |
| 175 bool m_nextFrameIsNewlyCommittedFrameOnImplThread; |
| 176 |
| 177 bool m_renderVSyncEnabled; |
| 178 |
| 179 base::TimeDelta m_totalCommitTime; |
| 180 size_t m_totalCommitCount; |
| 181 }; |
| 182 |
| 183 } |
| 184 |
| 185 #endif |
OLD | NEW |