blob: e26e031345617c1443c5aa57b2db2be4ab7a09f2 [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]0fb25002012-10-12 07:20:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]cd57cc5a2012-10-12 22:43:414
[email protected]556fd292013-03-18 08:03:045#ifndef CC_TREES_SINGLE_THREAD_PROXY_H_
6#define CC_TREES_SINGLE_THREAD_PROXY_H_
[email protected]cd57cc5a2012-10-12 22:43:417
[email protected]cd57cc5a2012-10-12 22:43:418#include <limits>
9
[email protected]1b0df502013-06-27 23:39:5810#include "base/time/time.h"
[email protected]95e4e1a02013-03-18 07:09:0911#include "cc/animation/animation_events.h"
[email protected]df3c24c92013-06-19 03:54:3512#include "cc/output/begin_frame_args.h"
[email protected]556fd292013-03-18 08:03:0413#include "cc/trees/layer_tree_host_impl.h"
14#include "cc/trees/proxy.h"
[email protected]55a124d02012-10-22 03:07:1315
[email protected]cd57cc5a2012-10-12 22:43:4116namespace cc {
17
[email protected]0a451722013-02-22 20:32:0518class ContextProvider;
[email protected]96baf3e2012-10-22 23:09:5519class LayerTreeHost;
[email protected]943528e2013-11-07 05:01:3220class LayerTreeHostSingleThreadClient;
[email protected]cd57cc5a2012-10-12 22:43:4121
[email protected]96baf3e2012-10-22 23:09:5522class SingleThreadProxy : public Proxy, LayerTreeHostImplClient {
[email protected]a8a049c2013-03-11 23:27:0623 public:
[email protected]943528e2013-11-07 05:01:3224 static scoped_ptr<Proxy> Create(
25 LayerTreeHost* layer_tree_host,
26 LayerTreeHostSingleThreadClient* client);
[email protected]a8a049c2013-03-11 23:27:0627 virtual ~SingleThreadProxy();
[email protected]cd57cc5a2012-10-12 22:43:4128
[email protected]a8a049c2013-03-11 23:27:0629 // Proxy implementation
[email protected]0023fc72014-01-10 20:05:0630 virtual bool CompositeAndReadback(void* pixels,
31 const gfx::Rect& rect) OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0632 virtual void FinishAllRendering() OVERRIDE;
33 virtual bool IsStarted() const OVERRIDE;
[email protected]14bd5542013-05-08 21:51:3034 virtual void SetLayerTreeHostClientReady() OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0635 virtual void SetVisible(bool visible) OVERRIDE;
[email protected]04049fc2013-05-01 03:13:2036 virtual void CreateAndInitializeOutputSurface() OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0637 virtual const RendererCapabilities& GetRendererCapabilities() const OVERRIDE;
[email protected]8b9e52b2014-01-17 16:35:3138 virtual void SetNeedsAnimate() OVERRIDE;
[email protected]3519b872013-07-30 07:17:5039 virtual void SetNeedsUpdateLayers() OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0640 virtual void SetNeedsCommit() OVERRIDE;
[email protected]0023fc72014-01-10 20:05:0641 virtual void SetNeedsRedraw(const gfx::Rect& damage_rect) OVERRIDE;
[email protected]74b43cc2013-08-30 06:29:2742 virtual void SetNextCommitWaitsForActivation() OVERRIDE;
[email protected]df09e052013-07-31 18:59:5043 virtual void NotifyInputThrottledUntilCommit() OVERRIDE {}
[email protected]a8a049c2013-03-11 23:27:0644 virtual void SetDeferCommits(bool defer_commits) OVERRIDE;
45 virtual bool CommitRequested() const OVERRIDE;
[email protected]971728d2013-10-26 10:39:3146 virtual bool BeginMainFrameRequested() const OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0647 virtual void MainThreadHasStoppedFlinging() OVERRIDE {}
[email protected]e96e3432013-12-19 18:56:0748 virtual void Start() OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0649 virtual void Stop() OVERRIDE;
50 virtual size_t MaxPartialTextureUpdates() const OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0651 virtual void ForceSerializeOnSwapBuffers() OVERRIDE;
[email protected]a8a049c2013-03-11 23:27:0652 virtual scoped_ptr<base::Value> AsValue() const OVERRIDE;
53 virtual bool CommitPendingForTesting() OVERRIDE;
[email protected]cd57cc5a2012-10-12 22:43:4154
[email protected]a8a049c2013-03-11 23:27:0655 // LayerTreeHostImplClient implementation
[email protected]fa339032014-02-18 22:11:5956 virtual void UpdateRendererCapabilitiesOnImplThread() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2757 virtual void DidLoseOutputSurfaceOnImplThread() OVERRIDE;
[email protected]3dc0c772014-04-26 10:06:0558 virtual void CommitVSyncParameters(base::TimeTicks timebase,
59 base::TimeDelta interval) OVERRIDE {}
60 virtual void SetEstimatedParentDrawTime(base::TimeDelta draw_time) OVERRIDE {}
[email protected]c14902662014-04-18 05:06:1161 virtual void SetMaxSwapsPendingOnImplThread(int max) OVERRIDE {}
[email protected]4d7e46a2013-11-08 05:33:4062 virtual void DidSwapBuffersOnImplThread() OVERRIDE;
[email protected]c14902662014-04-18 05:06:1163 virtual void DidSwapBuffersCompleteOnImplThread() OVERRIDE;
[email protected]97e9ccd62014-04-12 01:07:1564 virtual void BeginFrame(const BeginFrameArgs& args) OVERRIDE {}
[email protected]3d9f7432013-04-06 00:35:1865 virtual void OnCanDrawStateChanged(bool can_draw) OVERRIDE;
[email protected]4f48f6e2013-08-27 06:33:3866 virtual void NotifyReadyToActivate() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2767 virtual void SetNeedsRedrawOnImplThread() OVERRIDE;
[email protected]0023fc72014-01-10 20:05:0668 virtual void SetNeedsRedrawRectOnImplThread(
69 const gfx::Rect& dirty_rect) OVERRIDE;
[email protected]c48536a52013-09-14 00:02:0870 virtual void SetNeedsManageTilesOnImplThread() OVERRIDE;
[email protected]86126792013-03-16 20:07:5471 virtual void DidInitializeVisibleTileOnImplThread() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2772 virtual void SetNeedsCommitOnImplThread() OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2773 virtual void PostAnimationEventsToMainThreadOnImplThread(
[email protected]85b57502014-03-11 15:37:4874 scoped_ptr<AnimationEventsVector> events) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2775 virtual bool ReduceContentsTextureMemoryOnImplThread(
[email protected]a8a049c2013-03-11 23:27:0676 size_t limit_bytes,
77 int priority_cutoff) OVERRIDE;
[email protected]c1bb5af2013-03-13 19:06:2778 virtual void SendManagedMemoryStats() OVERRIDE;
79 virtual bool IsInsideDraw() OVERRIDE;
80 virtual void RenewTreePriority() OVERRIDE {}
[email protected]0fc818e2013-03-18 06:45:2081 virtual void RequestScrollbarAnimationOnImplThread(base::TimeDelta delay)
82 OVERRIDE {}
[email protected]2a61ad52013-05-13 14:01:2983 virtual void DidActivatePendingTree() OVERRIDE {}
[email protected]bac0e552013-11-05 22:38:5184 virtual void DidManageTiles() OVERRIDE {}
[email protected]2c6998c2014-04-03 11:33:5785 virtual void SetDebugState(const LayerTreeDebugState& debug_state) OVERRIDE {}
[email protected]cd57cc5a2012-10-12 22:43:4186
[email protected]a8a049c2013-03-11 23:27:0687 // Called by the legacy path where RenderWidget does the scheduling.
[email protected]f0c2a242013-03-15 19:34:5288 void CompositeImmediately(base::TimeTicks frame_begin_time);
[email protected]cd57cc5a2012-10-12 22:43:4189
[email protected]a8a049c2013-03-11 23:27:0690 private:
[email protected]943528e2013-11-07 05:01:3291 SingleThreadProxy(LayerTreeHost* layer_tree_host,
92 LayerTreeHostSingleThreadClient* client);
[email protected]cd57cc5a2012-10-12 22:43:4193
[email protected]e0341352013-04-06 05:01:2094 bool CommitAndComposite(base::TimeTicks frame_begin_time,
[email protected]0023fc72014-01-10 20:05:0695 const gfx::Rect& device_viewport_damage_rect,
[email protected]2921d042013-05-10 05:01:3996 bool for_readback,
[email protected]e0341352013-04-06 05:01:2097 LayerTreeHostImpl::FrameData* frame);
[email protected]a8a049c2013-03-11 23:27:0698 void DoCommit(scoped_ptr<ResourceUpdateQueue> queue);
[email protected]3b2eb882014-04-24 19:48:5699 bool DoComposite(base::TimeTicks frame_begin_time,
[email protected]0023fc72014-01-10 20:05:06100 const gfx::Rect& device_viewport_damage_rect,
[email protected]e51444a2013-12-10 23:05:01101 bool for_readback,
102 LayerTreeHostImpl::FrameData* frame);
[email protected]a8a049c2013-03-11 23:27:06103 void DidSwapFrame();
[email protected]cd57cc5a2012-10-12 22:43:41104
[email protected]3d9f7432013-04-06 00:35:18105 bool ShouldComposite() const;
[email protected]d9fce6722013-08-30 01:10:01106 void UpdateBackgroundAnimateTicking();
[email protected]3d9f7432013-04-06 00:35:18107
[email protected]a8a049c2013-03-11 23:27:06108 // Accessed on main thread only.
109 LayerTreeHost* layer_tree_host_;
[email protected]943528e2013-11-07 05:01:32110 LayerTreeHostSingleThreadClient* client_;
[email protected]cd57cc5a2012-10-12 22:43:41111
[email protected]a8a049c2013-03-11 23:27:06112 // Used on the Thread, but checked on main thread during
113 // initialization/shutdown.
114 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl_;
[email protected]a8a049c2013-03-11 23:27:06115 RendererCapabilities renderer_capabilities_for_main_thread_;
[email protected]cd57cc5a2012-10-12 22:43:41116
[email protected]a8a049c2013-03-11 23:27:06117 bool next_frame_is_newly_committed_frame_;
[email protected]cd57cc5a2012-10-12 22:43:41118
[email protected]a8a049c2013-03-11 23:27:06119 bool inside_draw_;
[email protected]74d9063c2013-01-18 03:14:47120
[email protected]a8a049c2013-03-11 23:27:06121 DISALLOW_COPY_AND_ASSIGN(SingleThreadProxy);
[email protected]cd57cc5a2012-10-12 22:43:41122};
123
124// For use in the single-threaded case. In debug builds, it pretends that the
125// code is running on the impl thread to satisfy assertion checks.
126class DebugScopedSetImplThread {
[email protected]a8a049c2013-03-11 23:27:06127 public:
128 explicit DebugScopedSetImplThread(Proxy* proxy) : proxy_(proxy) {
[email protected]767f38d72014-03-18 21:26:41129#if DCHECK_IS_ON
[email protected]a8a049c2013-03-11 23:27:06130 previous_value_ = proxy_->impl_thread_is_overridden_;
131 proxy_->SetCurrentThreadIsImplThread(true);
[email protected]cd57cc5a2012-10-12 22:43:41132#endif
[email protected]a8a049c2013-03-11 23:27:06133 }
134 ~DebugScopedSetImplThread() {
[email protected]767f38d72014-03-18 21:26:41135#if DCHECK_IS_ON
[email protected]a8a049c2013-03-11 23:27:06136 proxy_->SetCurrentThreadIsImplThread(previous_value_);
[email protected]cd57cc5a2012-10-12 22:43:41137#endif
[email protected]a8a049c2013-03-11 23:27:06138 }
139
140 private:
141 bool previous_value_;
142 Proxy* proxy_;
143
144 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThread);
[email protected]cd57cc5a2012-10-12 22:43:41145};
146
147// For use in the single-threaded case. In debug builds, it pretends that the
148// code is running on the main thread to satisfy assertion checks.
149class DebugScopedSetMainThread {
[email protected]a8a049c2013-03-11 23:27:06150 public:
151 explicit DebugScopedSetMainThread(Proxy* proxy) : proxy_(proxy) {
[email protected]767f38d72014-03-18 21:26:41152#if DCHECK_IS_ON
[email protected]a8a049c2013-03-11 23:27:06153 previous_value_ = proxy_->impl_thread_is_overridden_;
154 proxy_->SetCurrentThreadIsImplThread(false);
[email protected]cd57cc5a2012-10-12 22:43:41155#endif
[email protected]a8a049c2013-03-11 23:27:06156 }
157 ~DebugScopedSetMainThread() {
[email protected]767f38d72014-03-18 21:26:41158#if DCHECK_IS_ON
[email protected]a8a049c2013-03-11 23:27:06159 proxy_->SetCurrentThreadIsImplThread(previous_value_);
[email protected]cd57cc5a2012-10-12 22:43:41160#endif
[email protected]a8a049c2013-03-11 23:27:06161 }
162
163 private:
164 bool previous_value_;
165 Proxy* proxy_;
166
167 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetMainThread);
[email protected]cd57cc5a2012-10-12 22:43:41168};
169
170// For use in the single-threaded case. In debug builds, it pretends that the
171// code is running on the impl thread and that the main thread is blocked to
172// satisfy assertion checks
173class DebugScopedSetImplThreadAndMainThreadBlocked {
[email protected]a8a049c2013-03-11 23:27:06174 public:
175 explicit DebugScopedSetImplThreadAndMainThreadBlocked(Proxy* proxy)
176 : impl_thread_(proxy), main_thread_blocked_(proxy) {}
177
178 private:
179 DebugScopedSetImplThread impl_thread_;
180 DebugScopedSetMainThreadBlocked main_thread_blocked_;
181
182 DISALLOW_COPY_AND_ASSIGN(DebugScopedSetImplThreadAndMainThreadBlocked);
[email protected]cd57cc5a2012-10-12 22:43:41183};
184
[email protected]a8a049c2013-03-11 23:27:06185} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41186
[email protected]556fd292013-03-18 08:03:04187#endif // CC_TREES_SINGLE_THREAD_PROXY_H_