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; }
27 class LayerTreeDebugState;
29 struct RendererCapabilities;
31 // Abstract class responsible for proxying commands from the main-thread side of
32 // the compositor over to the compositor implementation.
33 class CC_EXPORT Proxy {
35 base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
36 bool HasImplThread() const;
37 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
40 bool IsMainThread() const;
41 bool IsImplThread() const;
42 bool IsMainThreadBlocked() const;
44 void SetMainThreadBlocked(bool is_main_thread_blocked);
45 void SetCurrentThreadIsImplThread(bool is_impl_thread);
50 virtual bool CompositeAndReadback(void* pixels, const gfx::Rect& rect) = 0;
52 virtual void FinishAllRendering() = 0;
54 virtual bool IsStarted() const = 0;
56 // Indicates that the compositing surface associated with our context is
58 virtual void SetLayerTreeHostClientReady() = 0;
60 virtual void SetVisible(bool visible) = 0;
62 // Attempts to recreate the context and renderer synchronously after the
63 // output surface is lost. Calls
64 // LayerTreeHost::OnCreateAndInitializeOutputSurfaceAttempted with the result.
65 virtual void CreateAndInitializeOutputSurface() = 0;
67 virtual const RendererCapabilities& GetRendererCapabilities() const = 0;
69 virtual void SetNeedsAnimate() = 0;
70 virtual void SetNeedsUpdateLayers() = 0;
71 virtual void SetNeedsCommit() = 0;
72 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) = 0;
73 virtual void SetNextCommitWaitsForActivation() = 0;
75 virtual void NotifyInputThrottledUntilCommit() = 0;
77 // Defers commits until it is reset. It is only supported when in threaded
78 // mode. It's an error to make a sync call like CompositeAndReadback while
79 // commits are deferred.
80 virtual void SetDeferCommits(bool defer_commits) = 0;
82 virtual void MainThreadHasStoppedFlinging() = 0;
84 virtual bool CommitRequested() const = 0;
85 virtual bool BeginMainFrameRequested() const = 0;
87 // Must be called before using the proxy.
88 virtual void Start() = 0;
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
92 // to finish before executing in the GPU 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 scoped_ptr<base::Value> AsValue() const = 0;
100 virtual void SetDebugState(const LayerTreeDebugState& debug_state) = 0;
103 virtual bool CommitPendingForTesting() = 0;
104 virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting();
108 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
109 friend class DebugScopedSetImplThread;
110 friend class DebugScopedSetMainThread;
111 friend class DebugScopedSetMainThreadBlocked;
114 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
115 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
117 bool impl_thread_is_overridden_;
118 bool is_main_thread_blocked_;
121 DISALLOW_COPY_AND_ASSIGN(Proxy);
125 class DebugScopedSetMainThreadBlocked {
127 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) {
128 DCHECK(!proxy_->IsMainThreadBlocked());
129 proxy_->SetMainThreadBlocked(true);
131 ~DebugScopedSetMainThreadBlocked() {
132 DCHECK(proxy_->IsMainThreadBlocked());
133 proxy_->SetMainThreadBlocked(false);
137 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
140 class DebugScopedSetMainThreadBlocked {
142 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {}
143 ~DebugScopedSetMainThreadBlocked() {}
145 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
151 #endif // CC_TREES_PROXY_H_