WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCSingleThreadProxy.h
bloba38aa7fd0ea755abf4ca5794e154e432174e011d
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
3 // found in the LICENSE file.
5 #ifndef CCSingleThreadProxy_h
6 #define CCSingleThreadProxy_h
8 #include "CCAnimationEvents.h"
9 #include "CCLayerTreeHostImpl.h"
10 #include "CCProxy.h"
11 #include <limits>
12 #include <wtf/OwnPtr.h>
14 namespace cc {
16 class CCLayerTreeHost;
18 class CCSingleThreadProxy : public CCProxy, CCLayerTreeHostImplClient {
19 public:
20 static PassOwnPtr<CCProxy> create(CCLayerTreeHost*);
21 virtual ~CCSingleThreadProxy();
23 // CCProxy implementation
24 virtual bool compositeAndReadback(void *pixels, const IntRect&) OVERRIDE;
25 virtual void startPageScaleAnimation(const IntSize& targetPosition, bool useAnchor, float scale, double duration) OVERRIDE;
26 virtual void finishAllRendering() OVERRIDE;
27 virtual bool isStarted() const OVERRIDE;
28 virtual bool initializeContext() OVERRIDE;
29 virtual void setSurfaceReady() OVERRIDE;
30 virtual void setVisible(bool) OVERRIDE;
31 virtual bool initializeRenderer() OVERRIDE;
32 virtual bool recreateContext() OVERRIDE;
33 virtual void implSideRenderingStats(CCRenderingStats&) OVERRIDE;
34 virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE;
35 virtual void loseContext() OVERRIDE;
36 virtual void setNeedsAnimate() OVERRIDE;
37 virtual void setNeedsCommit() OVERRIDE;
38 virtual void setNeedsRedraw() OVERRIDE;
39 virtual bool commitRequested() const OVERRIDE;
40 virtual void didAddAnimation() OVERRIDE;
41 virtual void start() OVERRIDE;
42 virtual void stop() OVERRIDE;
43 virtual size_t maxPartialTextureUpdates() const OVERRIDE { return std::numeric_limits<size_t>::max(); }
44 virtual void acquireLayerTextures() OVERRIDE { }
45 virtual void forceSerializeOnSwapBuffers() OVERRIDE;
47 // CCLayerTreeHostImplClient implementation
48 virtual void didLoseContextOnImplThread() OVERRIDE { }
49 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE { ASSERT_NOT_REACHED(); }
50 virtual void onVSyncParametersChanged(double monotonicTimebase, double intervalInSeconds) OVERRIDE { }
51 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { }
52 virtual void setNeedsRedrawOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
53 virtual void setNeedsCommitOnImplThread() OVERRIDE { m_layerTreeHost->scheduleComposite(); }
54 virtual void postAnimationEventsToMainThreadOnImplThread(PassOwnPtr<CCAnimationEventsVector>, double wallClockTime) OVERRIDE;
55 virtual void releaseContentsTexturesOnImplThread() OVERRIDE;
57 // Called by the legacy path where RenderWidget does the scheduling.
58 void compositeImmediately();
60 private:
61 explicit CCSingleThreadProxy(CCLayerTreeHost*);
63 bool commitAndComposite();
64 void doCommit(CCTextureUpdateQueue&);
65 bool doComposite();
66 void didSwapFrame();
68 // Accessed on main thread only.
69 CCLayerTreeHost* m_layerTreeHost;
70 bool m_contextLost;
72 // Holds on to the context between initializeContext() and initializeRenderer() calls. Shouldn't
73 // be used for anything else.
74 OwnPtr<CCGraphicsContext> m_contextBeforeInitialization;
76 // Used on the CCThread, but checked on main thread during initialization/shutdown.
77 OwnPtr<CCLayerTreeHostImpl> m_layerTreeHostImpl;
78 bool m_rendererInitialized;
79 RendererCapabilities m_RendererCapabilitiesForMainThread;
81 bool m_nextFrameIsNewlyCommittedFrame;
84 // For use in the single-threaded case. In debug builds, it pretends that the
85 // code is running on the impl thread to satisfy assertion checks.
86 class DebugScopedSetImplThread {
87 public:
88 DebugScopedSetImplThread()
90 #if !ASSERT_DISABLED
91 CCProxy::setCurrentThreadIsImplThread(true);
92 #endif
94 ~DebugScopedSetImplThread()
96 #if !ASSERT_DISABLED
97 CCProxy::setCurrentThreadIsImplThread(false);
98 #endif
102 // For use in the single-threaded case. In debug builds, it pretends that the
103 // code is running on the main thread to satisfy assertion checks.
104 class DebugScopedSetMainThread {
105 public:
106 DebugScopedSetMainThread()
108 #if !ASSERT_DISABLED
109 CCProxy::setCurrentThreadIsImplThread(false);
110 #endif
112 ~DebugScopedSetMainThread()
114 #if !ASSERT_DISABLED
115 CCProxy::setCurrentThreadIsImplThread(true);
116 #endif
120 // For use in the single-threaded case. In debug builds, it pretends that the
121 // code is running on the impl thread and that the main thread is blocked to
122 // satisfy assertion checks
123 class DebugScopedSetImplThreadAndMainThreadBlocked {
124 private:
125 DebugScopedSetImplThread m_implThread;
126 DebugScopedSetMainThreadBlocked m_mainThreadBlocked;
129 } // namespace cc
131 #endif