WebKit Roll 139512:139548
[chromium-blink-merge.git] / cc / single_thread_proxy.h
blobb4e1ad9d567750f249f85d8904ee7f4ff3ddd1da
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 CC_SINGLE_THREAD_PROXY_H_
6 #define CC_SINGLE_THREAD_PROXY_H_
8 #include <limits>
10 #include "base/time.h"
11 #include "cc/animation_events.h"
12 #include "cc/layer_tree_host_impl.h"
13 #include "cc/proxy.h"
15 namespace cc {
17 class LayerTreeHost;
19 class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
20 public:
21 static scoped_ptr<Proxy> create(LayerTreeHost*);
22 virtual ~SingleThreadProxy();
24 // Proxy implementation
25 virtual bool compositeAndReadback(void *pixels, const gfx::Rect&) OVERRIDE;
26 virtual void startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration) OVERRIDE;
27 virtual void finishAllRendering() OVERRIDE;
28 virtual bool isStarted() const OVERRIDE;
29 virtual bool initializeOutputSurface() OVERRIDE;
30 virtual void setSurfaceReady() OVERRIDE;
31 virtual void setVisible(bool) OVERRIDE;
32 virtual bool initializeRenderer() OVERRIDE;
33 virtual bool recreateOutputSurface() OVERRIDE;
34 virtual void renderingStats(RenderingStats*) OVERRIDE;
35 virtual const RendererCapabilities& rendererCapabilities() const OVERRIDE;
36 virtual void setNeedsAnimate() OVERRIDE;
37 virtual void setNeedsCommit() OVERRIDE;
38 virtual void setNeedsRedraw() OVERRIDE;
39 virtual void setDeferCommits(bool) OVERRIDE;
40 virtual bool commitRequested() const OVERRIDE;
41 virtual void mainThreadHasStoppedFlinging() OVERRIDE { }
42 virtual void start() OVERRIDE;
43 virtual void stop() OVERRIDE;
44 virtual size_t maxPartialTextureUpdates() const OVERRIDE;
45 virtual void acquireLayerTextures() OVERRIDE { }
46 virtual void forceSerializeOnSwapBuffers() OVERRIDE;
47 virtual bool commitPendingForTesting() OVERRIDE;
48 virtual skia::RefPtr<SkPicture> capturePicture() OVERRIDE;
50 // LayerTreeHostImplClient implementation
51 virtual void didLoseOutputSurfaceOnImplThread() OVERRIDE { }
52 virtual void onSwapBuffersCompleteOnImplThread() OVERRIDE;
53 virtual void onVSyncParametersChanged(base::TimeTicks timebase, base::TimeDelta interval) OVERRIDE { }
54 virtual void onCanDrawStateChanged(bool canDraw) OVERRIDE { }
55 virtual void onHasPendingTreeStateChanged(bool havePendingTree) OVERRIDE;
56 virtual void setNeedsRedrawOnImplThread() OVERRIDE;
57 virtual void setNeedsCommitOnImplThread() OVERRIDE;
58 virtual void setNeedsManageTilesOnImplThread() OVERRIDE;
59 virtual void postAnimationEventsToMainThreadOnImplThread(scoped_ptr<AnimationEventsVector>, base::Time wallClockTime) OVERRIDE;
60 virtual bool reduceContentsTextureMemoryOnImplThread(size_t limitBytes, int priorityCutoff) OVERRIDE;
61 virtual void sendManagedMemoryStats() OVERRIDE;
63 // Called by the legacy path where RenderWidget does the scheduling.
64 void compositeImmediately();
66 private:
67 explicit SingleThreadProxy(LayerTreeHost*);
69 bool commitAndComposite();
70 void doCommit(scoped_ptr<ResourceUpdateQueue>);
71 bool doComposite();
72 void didSwapFrame();
74 // Accessed on main thread only.
75 LayerTreeHost* m_layerTreeHost;
76 bool m_outputSurfaceLost;
78 // Holds on to the context between initializeContext() and initializeRenderer() calls. Shouldn't
79 // be used for anything else.
80 scoped_ptr<OutputSurface> m_outputSurfaceBeforeInitialization;
82 // Used on the Thread, but checked on main thread during initialization/shutdown.
83 scoped_ptr<LayerTreeHostImpl> m_layerTreeHostImpl;
84 bool m_rendererInitialized;
85 RendererCapabilities m_RendererCapabilitiesForMainThread;
87 bool m_nextFrameIsNewlyCommittedFrame;
89 base::TimeDelta m_totalCommitTime;
90 size_t m_totalCommitCount;
93 // For use in the single-threaded case. In debug builds, it pretends that the
94 // code is running on the impl thread to satisfy assertion checks.
95 class DebugScopedSetImplThread {
96 public:
97 explicit DebugScopedSetImplThread(Proxy* proxy)
98 : m_proxy(proxy)
100 #ifndef NDEBUG
101 m_previousValue = m_proxy->m_implThreadIsOverridden;
102 m_proxy->setCurrentThreadIsImplThread(true);
103 #endif
105 ~DebugScopedSetImplThread()
107 #ifndef NDEBUG
108 m_proxy->setCurrentThreadIsImplThread(m_previousValue);
109 #endif
111 private:
112 bool m_previousValue;
113 Proxy* m_proxy;
116 // For use in the single-threaded case. In debug builds, it pretends that the
117 // code is running on the main thread to satisfy assertion checks.
118 class DebugScopedSetMainThread {
119 public:
120 explicit DebugScopedSetMainThread(Proxy* proxy)
121 : m_proxy(proxy)
123 #ifndef NDEBUG
124 m_previousValue = m_proxy->m_implThreadIsOverridden;
125 m_proxy->setCurrentThreadIsImplThread(false);
126 #endif
128 ~DebugScopedSetMainThread()
130 #ifndef NDEBUG
131 m_proxy->setCurrentThreadIsImplThread(m_previousValue);
132 #endif
134 private:
135 bool m_previousValue;
136 Proxy* m_proxy;
139 // For use in the single-threaded case. In debug builds, it pretends that the
140 // code is running on the impl thread and that the main thread is blocked to
141 // satisfy assertion checks
142 class DebugScopedSetImplThreadAndMainThreadBlocked {
143 public:
144 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
145 : m_implThread(proxy)
146 , m_mainThreadBlocked(proxy)
149 private:
150 DebugScopedSetImplThread m_implThread;
151 DebugScopedSetMainThreadBlocked m_mainThreadBlocked;
154 } // namespace cc
156 #endif // CC_SINGLE_THREAD_PROXY_H_