Depend on stored sync session GUID for Android.
[chromium-blink-merge.git] / cc / proxy.h
blob65680e321e196d9187d44917eb69d5d137181a84
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_PROXY_H_
6 #define CC_PROXY_H_
8 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/time.h"
11 #include "base/memory/scoped_ptr.h"
12 #include <public/WebCompositorOutputSurface.h>
13 #include "cc/cc_export.h"
15 namespace gfx {
16 class Rect;
17 class Vector2d;
20 namespace cc {
22 class Thread;
23 struct RenderingStats;
24 struct RendererCapabilities;
26 // Abstract class responsible for proxying commands from the main-thread side of
27 // the compositor over to the compositor implementation.
28 class CC_EXPORT Proxy {
29 public:
30 Thread* mainThread() const;
31 bool hasImplThread() const;
32 Thread* implThread() const;
34 // Returns 0 if the current thread is neither the main thread nor the impl thread.
35 Thread* currentThread() const;
37 // Debug hooks
38 bool isMainThread() const;
39 bool isImplThread() const;
40 bool isMainThreadBlocked() const;
41 #ifndef NDEBUG
42 void setMainThreadBlocked(bool);
43 void setCurrentThreadIsImplThread(bool);
44 #endif
46 virtual ~Proxy();
48 virtual bool compositeAndReadback(void *pixels, const gfx::Rect&) = 0;
50 virtual void startPageScaleAnimation(gfx::Vector2d targetOffset, bool useAnchor, float scale, base::TimeDelta duration) = 0;
52 virtual void finishAllRendering() = 0;
54 virtual bool isStarted() const = 0;
56 // Attempts to initialize a context to use for rendering. Returns false if the context could not be created.
57 // The context will not be used and no frames may be produced until initializeRenderer() is called.
58 virtual bool initializeContext() = 0;
60 // Indicates that the compositing surface associated with our context is ready to use.
61 virtual void setSurfaceReady() = 0;
63 virtual void setVisible(bool) = 0;
65 // Attempts to initialize the layer renderer. Returns false if the context isn't usable for compositing.
66 virtual bool initializeRenderer() = 0;
68 // Attempts to recreate the context and layer renderer after a context lost. Returns false if the renderer couldn't be
69 // reinitialized.
70 virtual bool recreateContext() = 0;
72 virtual void renderingStats(RenderingStats*) = 0;
74 virtual const RendererCapabilities& rendererCapabilities() const = 0;
76 virtual void setNeedsAnimate() = 0;
77 virtual void setNeedsCommit() = 0;
78 virtual void setNeedsRedraw() = 0;
80 // Defers commits until it is reset. It is only supported when in threaded mode. It's an error to make a sync call
81 // like compositeAndReadback while commits are deferred.
82 virtual void setDeferCommits(bool) = 0;
84 virtual void didAddAnimation() = 0;
86 virtual bool commitRequested() const = 0;
88 virtual void start() = 0; // Must be called before using the proxy.
89 virtual void stop() = 0; // Must be called before deleting the proxy.
91 // Forces 3D commands on all contexts to wait for all previous SwapBuffers to finish before executing in the GPU
92 // process.
93 virtual void forceSerializeOnSwapBuffers() = 0;
95 // Maximum number of sub-region texture updates supported for each commit.
96 virtual size_t maxPartialTextureUpdates() const = 0;
98 virtual void acquireLayerTextures() = 0;
100 // Testing hooks
101 virtual void loseContext() = 0;
103 protected:
104 explicit Proxy(scoped_ptr<Thread> implThread);
105 friend class DebugScopedSetImplThread;
106 friend class DebugScopedSetMainThread;
107 friend class DebugScopedSetMainThreadBlocked;
109 private:
110 DISALLOW_COPY_AND_ASSIGN(Proxy);
112 scoped_ptr<Thread> m_mainThread;
113 scoped_ptr<Thread> m_implThread;
114 #ifndef NDEBUG
115 bool m_implThreadIsOverridden;
116 bool m_isMainThreadBlocked;
117 #endif
120 #ifndef NDEBUG
121 class DebugScopedSetMainThreadBlocked {
122 public:
123 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy)
124 : m_proxy(proxy)
126 DCHECK(!m_proxy->isMainThreadBlocked());
127 m_proxy->setMainThreadBlocked(true);
129 ~DebugScopedSetMainThreadBlocked()
131 DCHECK(m_proxy->isMainThreadBlocked());
132 m_proxy->setMainThreadBlocked(false);
134 private:
135 Proxy* m_proxy;
137 #else
138 class DebugScopedSetMainThreadBlocked {
139 public:
140 explicit DebugScopedSetMainThreadBlocked(Proxy*) { }
141 ~DebugScopedSetMainThreadBlocked() { }
143 #endif
147 #endif // CC_PROXY_H_