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 "cc/cc_export.h"
22 struct RenderingStats
;
23 struct RendererCapabilities
;
25 // Abstract class responsible for proxying commands from the main-thread side of
26 // the compositor over to the compositor implementation.
27 class CC_EXPORT Proxy
{
29 Thread
* mainThread() const;
30 bool hasImplThread() const;
31 Thread
* implThread() const;
33 // Returns 0 if the current thread is neither the main thread nor the impl thread.
34 Thread
* currentThread() const;
37 bool isMainThread() const;
38 bool isImplThread() const;
39 bool isMainThreadBlocked() const;
41 void setMainThreadBlocked(bool);
42 void setCurrentThreadIsImplThread(bool);
47 virtual bool compositeAndReadback(void *pixels
, const gfx::Rect
&) = 0;
49 virtual void startPageScaleAnimation(gfx::Vector2d targetOffset
, bool useAnchor
, float scale
, base::TimeDelta duration
) = 0;
51 virtual void finishAllRendering() = 0;
53 virtual bool isStarted() const = 0;
55 // Attempts to initialize a context to use for rendering. Returns false if the context could not be created.
56 // The context will not be used and no frames may be produced until initializeRenderer() is called.
57 virtual bool initializeOutputSurface() = 0;
59 // Indicates that the compositing surface associated with our context is ready to use.
60 virtual void setSurfaceReady() = 0;
62 virtual void setVisible(bool) = 0;
64 // Attempts to initialize the layer renderer. Returns false if the context isn't usable for compositing.
65 virtual bool initializeRenderer() = 0;
67 // Attempts to recreate the context and layer renderer after a context lost. Returns false if the renderer couldn't be
69 virtual bool recreateOutputSurface() = 0;
71 virtual void renderingStats(RenderingStats
*) = 0;
73 virtual const RendererCapabilities
& rendererCapabilities() const = 0;
75 virtual void setNeedsAnimate() = 0;
76 virtual void setNeedsCommit() = 0;
77 virtual void setNeedsRedraw() = 0;
79 // Defers commits until it is reset. It is only supported when in threaded mode. It's an error to make a sync call
80 // like compositeAndReadback while commits are deferred.
81 virtual void setDeferCommits(bool) = 0;
83 virtual void didAddAnimation() = 0;
85 virtual bool commitRequested() const = 0;
87 virtual void start() = 0; // Must be called before using the proxy.
88 virtual void stop() = 0; // Must be called before deleting the proxy.
90 // Forces 3D commands on all contexts to wait for all previous SwapBuffers to finish before executing in the GPU
92 virtual void forceSerializeOnSwapBuffers() = 0;
94 // Maximum number of sub-region texture updates supported for each commit.
95 virtual size_t maxPartialTextureUpdates() const = 0;
97 virtual void acquireLayerTextures() = 0;
100 virtual void loseOutputSurface() = 0;
103 explicit Proxy(scoped_ptr
<Thread
> implThread
);
104 friend class DebugScopedSetImplThread
;
105 friend class DebugScopedSetMainThread
;
106 friend class DebugScopedSetMainThreadBlocked
;
109 DISALLOW_COPY_AND_ASSIGN(Proxy
);
111 scoped_ptr
<Thread
> m_mainThread
;
112 scoped_ptr
<Thread
> m_implThread
;
114 bool m_implThreadIsOverridden
;
115 bool m_isMainThreadBlocked
;
120 class DebugScopedSetMainThreadBlocked
{
122 explicit DebugScopedSetMainThreadBlocked(Proxy
* proxy
)
125 DCHECK(!m_proxy
->isMainThreadBlocked());
126 m_proxy
->setMainThreadBlocked(true);
128 ~DebugScopedSetMainThreadBlocked()
130 DCHECK(m_proxy
->isMainThreadBlocked());
131 m_proxy
->setMainThreadBlocked(false);
137 class DebugScopedSetMainThreadBlocked
{
139 explicit DebugScopedSetMainThreadBlocked(Proxy
*) { }
140 ~DebugScopedSetMainThreadBlocked() { }
146 #endif // CC_PROXY_H_