Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / trees / proxy.h
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.
4
5 #ifndef CC_TREES_PROXY_H_
6 #define CC_TREES_PROXY_H_
7
8 #include <string>
9
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"
17
18 namespace base { class SingleThreadTaskRunner; }
19
20 namespace gfx {
21 class Rect;
22 class Vector2d;
23 }
24
25 namespace cc {
26
27 class LayerTreeDebugState;
28 class OutputSurface;
29 struct RendererCapabilities;
30
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 {
34  public:
35   base::SingleThreadTaskRunner* MainThreadTaskRunner() const;
36   bool HasImplThread() const;
37   base::SingleThreadTaskRunner* ImplThreadTaskRunner() const;
38
39   // Debug hooks.
40   bool IsMainThread() const;
41   bool IsImplThread() const;
42   bool IsMainThreadBlocked() const;
43 #if DCHECK_IS_ON
44   void SetMainThreadBlocked(bool is_main_thread_blocked);
45   void SetCurrentThreadIsImplThread(bool is_impl_thread);
46 #endif
47
48   virtual ~Proxy();
49
50   virtual bool CompositeAndReadback(void* pixels, const gfx::Rect& rect) = 0;
51
52   virtual void FinishAllRendering() = 0;
53
54   virtual bool IsStarted() const = 0;
55
56   // Indicates that the compositing surface associated with our context is
57   // ready to use.
58   virtual void SetLayerTreeHostClientReady() = 0;
59
60   virtual void SetVisible(bool visible) = 0;
61
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;
66
67   virtual const RendererCapabilities& GetRendererCapabilities() const = 0;
68
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;
74
75   virtual void NotifyInputThrottledUntilCommit() = 0;
76
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;
81
82   virtual void MainThreadHasStoppedFlinging() = 0;
83
84   virtual bool CommitRequested() const = 0;
85   virtual bool BeginMainFrameRequested() const = 0;
86
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.
90
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;
94
95   // Maximum number of sub-region texture updates supported for each commit.
96   virtual size_t MaxPartialTextureUpdates() const = 0;
97
98   virtual scoped_ptr<base::Value> AsValue() const = 0;
99
100   virtual void SetDebugState(const LayerTreeDebugState& debug_state) = 0;
101
102   // Testing hooks
103   virtual bool CommitPendingForTesting() = 0;
104   virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting();
105
106  protected:
107   explicit Proxy(
108       scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner);
109   friend class DebugScopedSetImplThread;
110   friend class DebugScopedSetMainThread;
111   friend class DebugScopedSetMainThreadBlocked;
112
113  private:
114   scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
115   scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
116 #if DCHECK_IS_ON
117   bool impl_thread_is_overridden_;
118   bool is_main_thread_blocked_;
119 #endif
120
121   DISALLOW_COPY_AND_ASSIGN(Proxy);
122 };
123
124 #if DCHECK_IS_ON
125 class DebugScopedSetMainThreadBlocked {
126  public:
127   explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) {
128     DCHECK(!proxy_->IsMainThreadBlocked());
129     proxy_->SetMainThreadBlocked(true);
130   }
131   ~DebugScopedSetMainThreadBlocked() {
132     DCHECK(proxy_->IsMainThreadBlocked());
133     proxy_->SetMainThreadBlocked(false);
134   }
135  private:
136   Proxy* proxy_;
137   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
138 };
139 #else
140 class DebugScopedSetMainThreadBlocked {
141  public:
142   explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {}
143   ~DebugScopedSetMainThreadBlocked() {}
144  private:
145   DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked);
146 };
147 #endif
148
149 }  // namespace cc
150
151 #endif  // CC_TREES_PROXY_H_