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_TREES_PROXY_H_
6 #define CC_TREES_PROXY_H_
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time/time.h"
15 #include "base/values.h"
16 #include "cc/base/cc_export.h"
18 namespace base
{ class SingleThreadTaskRunner
; }
28 struct RendererCapabilities
;
30 // Abstract class responsible for proxying commands from the main-thread side of
31 // the compositor over to the compositor implementation.
32 class CC_EXPORT Proxy
{
34 base::SingleThreadTaskRunner
* MainThreadTaskRunner() const;
35 bool HasImplThread() const;
36 base::SingleThreadTaskRunner
* ImplThreadTaskRunner() const;
39 bool IsMainThread() const;
40 bool IsImplThread() const;
41 bool IsMainThreadBlocked() const;
43 void SetMainThreadBlocked(bool is_main_thread_blocked
);
44 void SetCurrentThreadIsImplThread(bool is_impl_thread
);
49 virtual bool CompositeAndReadback(void* pixels
, const gfx::Rect
& rect
) = 0;
51 virtual void FinishAllRendering() = 0;
53 virtual bool IsStarted() const = 0;
55 // Indicates that the compositing surface associated with our context is
57 virtual void SetLayerTreeHostClientReady() = 0;
59 virtual void SetVisible(bool visible
) = 0;
61 // Attempts to recreate the context and renderer synchronously after the
62 // output surface is lost. Calls
63 // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result.
64 virtual void CreateAndInitializeOutputSurface() = 0;
66 virtual const RendererCapabilities
& GetRendererCapabilities() const = 0;
68 virtual void SetNeedsAnimate() = 0;
69 virtual void SetNeedsUpdateLayers() = 0;
70 virtual void SetNeedsCommit() = 0;
71 virtual void SetNeedsRedraw(const gfx::Rect
& damage_rect
) = 0;
72 virtual void SetNextCommitWaitsForActivation() = 0;
74 virtual void NotifyInputThrottledUntilCommit() = 0;
76 // Defers commits until it is reset. It is only supported when in threaded
77 // mode. It's an error to make a sync call like CompositeAndReadback while
78 // commits are deferred.
79 virtual void SetDeferCommits(bool defer_commits
) = 0;
81 virtual void MainThreadHasStoppedFlinging() = 0;
83 virtual bool CommitRequested() const = 0;
84 virtual bool BeginMainFrameRequested() const = 0;
86 // Must be called before using the proxy.
87 virtual void Start() = 0;
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
91 // to finish before executing in the GPU process.
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;
99 virtual scoped_ptr
<base::Value
> AsValue() const = 0;
102 virtual bool CommitPendingForTesting() = 0;
103 virtual scoped_ptr
<base::Value
> SchedulerStateAsValueForTesting();
107 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner
);
108 friend class DebugScopedSetImplThread
;
109 friend class DebugScopedSetMainThread
;
110 friend class DebugScopedSetMainThreadBlocked
;
113 scoped_refptr
<base::SingleThreadTaskRunner
> main_task_runner_
;
114 scoped_refptr
<base::SingleThreadTaskRunner
> impl_task_runner_
;
116 bool impl_thread_is_overridden_
;
117 bool is_main_thread_blocked_
;
120 DISALLOW_COPY_AND_ASSIGN(Proxy
);
124 class DebugScopedSetMainThreadBlocked
{
126 explicit DebugScopedSetMainThreadBlocked(Proxy
* proxy
) : proxy_(proxy
) {
127 DCHECK(!proxy_
->IsMainThreadBlocked());
128 proxy_
->SetMainThreadBlocked(true);
130 ~DebugScopedSetMainThreadBlocked() {
131 DCHECK(proxy_
->IsMainThreadBlocked());
132 proxy_
->SetMainThreadBlocked(false);
136 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked
);
139 class DebugScopedSetMainThreadBlocked
{
141 explicit DebugScopedSetMainThreadBlocked(Proxy
* proxy
) {}
142 ~DebugScopedSetMainThreadBlocked() {}
144 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked
);
150 #endif // CC_TREES_PROXY_H_