Pass gfx::Rect and gfx::RectF by const ref.
[chromium-blink-merge.git] / cc / trees / proxy.h
blobe9876902dec08b59528391f822bbb28d983e5af0
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/time/time.h"
15 #include "base/values.h"
16 #include "cc/base/cc_export.h"
18 namespace base { class SingleThreadTaskRunner; }
20 namespace gfx {
21 class Rect;
22 class Vector2d;
25 namespace cc {
27 class OutputSurface;
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 {
33 public:
34 base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
35 bool HasImplThread() const;
36 base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
38 // Debug hooks.
39 bool IsMainThread() const;
40 bool IsImplThread() const;
41 bool IsMainThreadBlocked() const;
42 #ifndef NDEBUG
43 void SetMainThreadBlocked(bool is_main_thread_blocked);
44 void SetCurrentThreadIsImplThread(bool is_impl_thread);
45 #endif
47 virtual ~Proxy();
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
56 // ready to use.
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;
101 // Testing hooks
102 virtual bool CommitPendingForTesting() = 0;
103 virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting();
105 protected:
106 explicit Proxy(
107 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
108 friend class DebugScopedSetImplThread;
109 friend class DebugScopedSetMainThread;
110 friend class DebugScopedSetMainThreadBlocked;
112 private:
113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
114 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
115 #ifndef NDEBUG
116 bool impl_thread_is_overridden_;
117 bool is_main_thread_blocked_;
118 #endif
120 DISALLOW_COPY_AND_ASSIGN(Proxy);
123 #ifndef NDEBUG
124 class DebugScopedSetMainThreadBlocked {
125 public:
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);
134 private:
135 Proxy* proxy_;
136 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
138 #else
139 class DebugScopedSetMainThreadBlocked {
140 public:
141 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {}
142 ~DebugScopedSetMainThreadBlocked() {}
143 private:
144 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
146 #endif
148 } // namespace cc
150 #endif // CC_TREES_PROXY_H_