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/threading/platform_thread.h" 15 #include "base/time/time.h" 16 #include "base/values.h" 17 #include "cc/base/cc_export.h" 18 19 namespace base { class SingleThreadTaskRunner; } 20 21 namespace gfx { 22 class Rect; 23 class Vector2d; 24 } 25 26 namespace cc { 27 28 class LayerTreeDebugState; 29 class OutputSurface; 30 struct RendererCapabilities; 31 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; 39 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 48 49 virtual ~Proxy(); 50 51 virtual void FinishAllRendering() = 0; 52 53 virtual bool IsStarted() const = 0; 54 55 // Indicates that the compositing surface associated with our context is 56 // ready to use. 57 virtual void SetLayerTreeHostClientReady() = 0; 58 59 virtual void SetVisible(bool visible) = 0; 60 61 virtual const RendererCapabilities& GetRendererCapabilities() const = 0; 62 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; 68 69 virtual void NotifyInputThrottledUntilCommit() = 0; 70 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; 75 76 virtual void MainThreadHasStoppedFlinging() = 0; 77 78 virtual bool CommitRequested() const = 0; 79 virtual bool BeginMainFrameRequested() const = 0; 80 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. 84 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; 88 89 // Maximum number of sub-region texture updates supported for each commit. 90 virtual size_t MaxPartialTextureUpdates() const = 0; 91 92 virtual scoped_ptr<base::Value> AsValue() const = 0; 93 94 virtual void SetDebugState(const LayerTreeDebugState& debug_state) = 0; 95 96 // Testing hooks 97 virtual bool CommitPendingForTesting() = 0; 98 virtual scoped_ptr<base::Value> SchedulerAsValueForTesting(); 99 100 protected: 101 explicit Proxy( 102 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner); 103 friend class DebugScopedSetImplThread; 104 friend class DebugScopedSetMainThread; 105 friend class DebugScopedSetMainThreadBlocked; 106 107 private: 108 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; 109 scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_; 110 #if DCHECK_IS_ON 111 const base::PlatformThreadId main_thread_id_; 112 bool impl_thread_is_overridden_; 113 bool is_main_thread_blocked_; 114 #endif 115 116 DISALLOW_COPY_AND_ASSIGN(Proxy); 117 }; 118 119 #if DCHECK_IS_ON 120 class DebugScopedSetMainThreadBlocked { 121 public: 122 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) { 123 DCHECK(!proxy_->IsMainThreadBlocked()); 124 proxy_->SetMainThreadBlocked(true); 125 } 126 ~DebugScopedSetMainThreadBlocked() { 127 DCHECK(proxy_->IsMainThreadBlocked()); 128 proxy_->SetMainThreadBlocked(false); 129 } 130 private: 131 Proxy* proxy_; 132 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked); 133 }; 134 #else 135 class DebugScopedSetMainThreadBlocked { 136 public: 137 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {} 138 ~DebugScopedSetMainThreadBlocked() {} 139 private: 140 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked); 141 }; 142 #endif 143 144 } // namespace cc 145 146 #endif // CC_TREES_PROXY_H_ 147