cc: Disallow scroll offset animations when impl-scrolling isn't supported
[chromium-blink-merge.git] / cc / trees / proxy.h
blob838e44f855c2e109c3bf71676312ae8f086d156b
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_
8 #include <string>
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/threading/platform_thread.h"
15 #include "base/time/time.h"
16 #include "base/values.h"
17 #include "cc/base/cc_export.h"
19 namespace base { class SingleThreadTaskRunner; }
21 namespace gfx {
22 class Rect;
23 class Vector2d;
26 namespace cc {
28 class LayerTreeDebugState;
29 class OutputSurface;
30 struct RendererCapabilities;
32 // Abstract class responsible for proxying commands from the main-thread side of
33 // the compositor over to the compositor implementation.
34 class CC_EXPORT Proxy {
35 public:
36 base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
37 bool HasImplThread() const;
38 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
40 // Debug hooks.
41 bool IsMainThread() const;
42 bool IsImplThread() const;
43 bool IsMainThreadBlocked() const;
44 #if DCHECK_IS_ON
45 void SetMainThreadBlocked(bool is_main_thread_blocked);
46 void SetCurrentThreadIsImplThread(bool is_impl_thread);
47 #endif
49 virtual ~Proxy();
51 virtual void FinishAllRendering() = 0;
53 virtual bool IsStarted() const = 0;
55 // Indicates that the compositing surface associated with our context is
56 // ready to use.
57 virtual void SetLayerTreeHostClientReady() = 0;
59 virtual void SetVisible(bool visible) = 0;
61 virtual const RendererCapabilities& GetRendererCapabilities() const = 0;
63 virtual void SetNeedsAnimate() = 0;
64 virtual void SetNeedsUpdateLayers() = 0;
65 virtual void SetNeedsCommit() = 0;
66 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) = 0;
67 virtual void SetNextCommitWaitsForActivation() = 0;
69 virtual void NotifyInputThrottledUntilCommit() = 0;
71 // Defers commits until it is reset. It is only supported when in threaded
72 // mode. It's an error to make a sync call like CompositeAndReadback while
73 // commits are deferred.
74 virtual void SetDeferCommits(bool defer_commits) = 0;
76 virtual void MainThreadHasStoppedFlinging() = 0;
78 virtual bool CommitRequested() const = 0;
79 virtual bool BeginMainFrameRequested() const = 0;
81 // Must be called before using the proxy.
82 virtual void Start() = 0;
83 virtual void Stop() = 0; // Must be called before deleting the proxy.
85 // Forces 3D commands on all contexts to wait for all previous SwapBuffers
86 // to finish before executing in the GPU process.
87 virtual void ForceSerializeOnSwapBuffers() = 0;
89 // Maximum number of sub-region texture updates supported for each commit.
90 virtual size_t MaxPartialTextureUpdates() const = 0;
92 virtual bool SupportsImplScrolling() const = 0;
94 virtual scoped_ptr<base::Value> AsValue() const = 0;
96 virtual void SetDebugState(const LayerTreeDebugState& debug_state) = 0;
98 // Testing hooks
99 virtual bool CommitPendingForTesting() = 0;
100 virtual scoped_ptr<base::Value> SchedulerAsValueForTesting();
102 protected:
103 explicit Proxy(
104 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
105 friend class DebugScopedSetImplThread;
106 friend class DebugScopedSetMainThread;
107 friend class DebugScopedSetMainThreadBlocked;
109 private:
110 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
111 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
112 #if DCHECK_IS_ON
113 const base::PlatformThreadId main_thread_id_;
114 bool impl_thread_is_overridden_;
115 bool is_main_thread_blocked_;
116 #endif
118 DISALLOW_COPY_AND_ASSIGN(Proxy);
121 #if DCHECK_IS_ON
122 class DebugScopedSetMainThreadBlocked {
123 public:
124 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) {
125 DCHECK(!proxy_->IsMainThreadBlocked());
126 proxy_->SetMainThreadBlocked(true);
128 ~DebugScopedSetMainThreadBlocked() {
129 DCHECK(proxy_->IsMainThreadBlocked());
130 proxy_->SetMainThreadBlocked(false);
132 private:
133 Proxy* proxy_;
134 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
136 #else
137 class DebugScopedSetMainThreadBlocked {
138 public:
139 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {}
140 ~DebugScopedSetMainThreadBlocked() {}
141 private:
142 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
144 #endif
146 } // namespace cc
148 #endif // CC_TREES_PROXY_H_