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.
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"
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
{
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;
38 bool isMainThread() const;
39 bool isImplThread() const;
40 bool isMainThreadBlocked() const;
42 void setMainThreadBlocked(bool);
43 void setCurrentThreadIsImplThread(bool);
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
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
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;
101 virtual void loseContext() = 0;
104 explicit Proxy(scoped_ptr
<Thread
> implThread
);
105 friend class DebugScopedSetImplThread
;
106 friend class DebugScopedSetMainThread
;
107 friend class DebugScopedSetMainThreadBlocked
;
110 DISALLOW_COPY_AND_ASSIGN(Proxy
);
112 scoped_ptr
<Thread
> m_mainThread
;
113 scoped_ptr
<Thread
> m_implThread
;
115 bool m_implThreadIsOverridden
;
116 bool m_isMainThreadBlocked
;
121 class DebugScopedSetMainThreadBlocked
{
123 explicit DebugScopedSetMainThreadBlocked(Proxy
* proxy
)
126 DCHECK(!m_proxy
->isMainThreadBlocked());
127 m_proxy
->setMainThreadBlocked(true);
129 ~DebugScopedSetMainThreadBlocked()
131 DCHECK(m_proxy
->isMainThreadBlocked());
132 m_proxy
->setMainThreadBlocked(false);
138 class DebugScopedSetMainThreadBlocked
{
140 explicit DebugScopedSetMainThreadBlocked(Proxy
*) { }
141 ~DebugScopedSetMainThreadBlocked() { }
147 #endif // CC_PROXY_H_