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 OutputSurface; 28 struct RendererCapabilities; 29 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; 37 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 46 47 virtual ~Proxy(); 48 49 virtual bool CompositeAndReadback(void* pixels, gfx::Rect rect) = 0; 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 // 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; 65 66 virtual const RendererCapabilities& GetRendererCapabilities() const = 0; 67 68 virtual void SetNeedsAnimate() = 0; 69 virtual void SetNeedsUpdateLayers() = 0; 70 virtual void SetNeedsCommit() = 0; 71 virtual void SetNeedsRedraw(gfx::Rect damage_rect) = 0; 72 virtual void SetNextCommitWaitsForActivation() = 0; 73 74 virtual void NotifyInputThrottledUntilCommit() = 0; 75 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; 80 81 virtual void MainThreadHasStoppedFlinging() = 0; 82 83 virtual bool CommitRequested() const = 0; 84 virtual bool BeginMainFrameRequested() const = 0; 85 86 // Must be called before using the proxy. 87 virtual void Start(scoped_ptr<OutputSurface> first_output_surface) = 0; 88 virtual void Stop() = 0; // Must be called before deleting the proxy. 89 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; 93 94 // Maximum number of sub-region texture updates supported for each commit. 95 virtual size_t MaxPartialTextureUpdates() const = 0; 96 97 virtual void AcquireLayerTextures() = 0; 98 99 virtual scoped_ptr<base::Value> AsValue() const = 0; 100 101 // Testing hooks 102 virtual bool CommitPendingForTesting() = 0; 103 virtual scoped_ptr<base::Value> SchedulerStateAsValueForTesting(); 104 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; 111 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 119 120 DISALLOW_COPY_AND_ASSIGN(Proxy); 121 }; 122 123 #ifndef NDEBUG 124 class DebugScopedSetMainThreadBlocked { 125 public: DebugScopedSetMainThreadBlocked(Proxy * proxy)126 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) : proxy_(proxy) { 127 DCHECK(!proxy_->IsMainThreadBlocked()); 128 proxy_->SetMainThreadBlocked(true); 129 } ~DebugScopedSetMainThreadBlocked()130 ~DebugScopedSetMainThreadBlocked() { 131 DCHECK(proxy_->IsMainThreadBlocked()); 132 proxy_->SetMainThreadBlocked(false); 133 } 134 private: 135 Proxy* proxy_; 136 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked); 137 }; 138 #else 139 class DebugScopedSetMainThreadBlocked { 140 public: DebugScopedSetMainThreadBlocked(Proxy * proxy)141 explicit DebugScopedSetMainThreadBlocked(Proxy* proxy) {} ~DebugScopedSetMainThreadBlocked()142 ~DebugScopedSetMainThreadBlocked() {} 143 private: 144 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThreadBlocked); 145 }; 146 #endif 147 148 } // namespace cc 149 150 #endif // CC_TREES_PROXY_H_ 151