OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/cancelable_callback.h" | 9 #include "base/cancelable_callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 // ----------------------------------------------------------------------------- | 41 // ----------------------------------------------------------------------------- |
42 class CONTENT_EXPORT CompositorImpl | 42 class CONTENT_EXPORT CompositorImpl |
43 : public Compositor, | 43 : public Compositor, |
44 public cc::LayerTreeHostClient, | 44 public cc::LayerTreeHostClient, |
45 public cc::LayerTreeHostSingleThreadClient, | 45 public cc::LayerTreeHostSingleThreadClient, |
46 public ui::UIResourceProvider, | 46 public ui::UIResourceProvider, |
47 public ui::WindowAndroidCompositor { | 47 public ui::WindowAndroidCompositor { |
48 public: | 48 public: |
49 class VSyncObserver { | 49 class VSyncObserver { |
50 public: | 50 public: |
51 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, | 51 virtual void OnVSync(base::TimeTicks timebase, |
52 base::TimeDelta interval) = 0; | 52 base::TimeDelta interval) = 0; |
53 }; | 53 }; |
54 | 54 |
55 CompositorImpl(CompositorClient* client, gfx::NativeWindow root_window); | 55 CompositorImpl(CompositorClient* client, gfx::NativeWindow root_window); |
56 ~CompositorImpl() override; | 56 ~CompositorImpl() override; |
57 | 57 |
58 static bool IsInitialized(); | 58 static bool IsInitialized(); |
59 | 59 |
60 static cc::SurfaceManager* GetSurfaceManager(); | 60 static cc::SurfaceManager* GetSurfaceManager(); |
61 static scoped_ptr<cc::SurfaceIdAllocator> CreateSurfaceIdAllocator(); | 61 static scoped_ptr<cc::SurfaceIdAllocator> CreateSurfaceIdAllocator(); |
62 | 62 |
63 void PopulateGpuCapabilities(gpu::Capabilities gpu_capabilities); | 63 void PopulateGpuCapabilities(gpu::Capabilities gpu_capabilities); |
64 | 64 |
65 void AddObserver(VSyncObserver* observer); | 65 void AddObserver(VSyncObserver* observer); |
66 void RemoveObserver(VSyncObserver* observer); | 66 void RemoveObserver(VSyncObserver* observer); |
| 67 void OnNeedsBeginFramesChange(bool needs_begin_frames); |
67 | 68 |
68 // ui::ResourceProvider implementation. | 69 // ui::ResourceProvider implementation. |
69 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; | 70 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; |
70 void DeleteUIResource(cc::UIResourceId resource_id) override; | 71 void DeleteUIResource(cc::UIResourceId resource_id) override; |
71 bool SupportsETC1NonPowerOfTwo() const override; | 72 bool SupportsETC1NonPowerOfTwo() const override; |
72 | 73 |
73 private: | 74 private: |
74 // Compositor implementation. | 75 // Compositor implementation. |
75 void SetRootLayer(scoped_refptr<cc::Layer> root) override; | 76 void SetRootLayer(scoped_refptr<cc::Layer> root) override; |
76 void SetSurface(jobject surface) override; | 77 void SetSurface(jobject surface) override; |
(...skipping 22 matching lines...) Expand all Loading... |
99 void DidCommit() override; | 100 void DidCommit() override; |
100 void DidCommitAndDrawFrame() override {} | 101 void DidCommitAndDrawFrame() override {} |
101 void DidCompleteSwapBuffers() override; | 102 void DidCompleteSwapBuffers() override; |
102 void DidCompletePageScaleAnimation() override {} | 103 void DidCompletePageScaleAnimation() override {} |
103 void RecordFrameTimingEvents( | 104 void RecordFrameTimingEvents( |
104 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 105 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
105 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 106 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
106 override {} | 107 override {} |
107 | 108 |
108 // LayerTreeHostSingleThreadClient implementation. | 109 // LayerTreeHostSingleThreadClient implementation. |
109 void ScheduleComposite() override; | |
110 void ScheduleAnimation() override; | |
111 void DidPostSwapBuffers() override; | 110 void DidPostSwapBuffers() override; |
112 void DidAbortSwapBuffers() override; | 111 void DidAbortSwapBuffers() override; |
113 | 112 |
114 // WindowAndroidCompositor implementation. | 113 // WindowAndroidCompositor implementation. |
115 void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) override; | 114 void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) override; |
116 void RequestCopyOfOutputOnRootLayer( | 115 void RequestCopyOfOutputOnRootLayer( |
117 scoped_ptr<cc::CopyOutputRequest> request) override; | 116 scoped_ptr<cc::CopyOutputRequest> request) override; |
118 void OnVSync(base::TimeTicks frame_time, | 117 void OnVSync(base::TimeTicks frame_time, |
119 base::TimeDelta vsync_period) override; | 118 base::TimeDelta vsync_period) override; |
120 void SetNeedsAnimate() override; | 119 void SetNeedsAnimate() override; |
121 | |
122 void SetVisible(bool visible); | 120 void SetVisible(bool visible); |
123 | |
124 enum CompositingTrigger { | |
125 DO_NOT_COMPOSITE, | |
126 COMPOSITE_IMMEDIATELY, | |
127 COMPOSITE_EVENTUALLY, | |
128 }; | |
129 void PostComposite(CompositingTrigger trigger); | |
130 void Composite(CompositingTrigger trigger); | |
131 void CreateOutputSurface(); | 121 void CreateOutputSurface(); |
132 | |
133 bool WillCompositeThisFrame() const { | |
134 return current_composite_task_ && | |
135 !current_composite_task_->callback().is_null(); | |
136 } | |
137 bool DidCompositeThisFrame() const { | |
138 return current_composite_task_ && | |
139 current_composite_task_->callback().is_null(); | |
140 } | |
141 bool WillComposite() const { | |
142 return WillCompositeThisFrame() || | |
143 composite_on_vsync_trigger_ != DO_NOT_COMPOSITE; | |
144 } | |
145 void CancelComposite() { | |
146 DCHECK(WillComposite()); | |
147 if (WillCompositeThisFrame()) | |
148 current_composite_task_->Cancel(); | |
149 current_composite_task_.reset(); | |
150 composite_on_vsync_trigger_ = DO_NOT_COMPOSITE; | |
151 will_composite_immediately_ = false; | |
152 } | |
153 void CreateLayerTreeHost(); | 122 void CreateLayerTreeHost(); |
154 | 123 |
155 void OnGpuChannelEstablished(); | 124 void OnGpuChannelEstablished(); |
156 void OnGpuChannelTimeout(); | 125 void OnGpuChannelTimeout(); |
157 | 126 |
158 // root_layer_ is the persistent internal root layer, while subroot_layer_ | 127 // root_layer_ is the persistent internal root layer, while subroot_layer_ |
159 // is the one attached by the compositor client. | 128 // is the one attached by the compositor client. |
160 scoped_refptr<cc::Layer> root_layer_; | 129 scoped_refptr<cc::Layer> root_layer_; |
161 scoped_refptr<cc::Layer> subroot_layer_; | 130 scoped_refptr<cc::Layer> subroot_layer_; |
162 | 131 |
163 scoped_ptr<cc::LayerTreeHost> host_; | 132 scoped_ptr<cc::LayerTreeHost> host_; |
164 ui::ResourceManagerImpl resource_manager_; | 133 ui::ResourceManagerImpl resource_manager_; |
165 | 134 |
166 scoped_ptr<cc::OnscreenDisplayClient> display_client_; | 135 scoped_ptr<cc::OnscreenDisplayClient> display_client_; |
167 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 136 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
168 | 137 |
169 gfx::Size size_; | 138 gfx::Size size_; |
170 bool has_transparent_background_; | 139 bool has_transparent_background_; |
171 float device_scale_factor_; | 140 float device_scale_factor_; |
172 | 141 |
173 ANativeWindow* window_; | 142 ANativeWindow* window_; |
174 int surface_id_; | 143 int surface_id_; |
175 | 144 |
176 CompositorClient* client_; | 145 CompositorClient* client_; |
177 | 146 |
178 gfx::NativeWindow root_window_; | 147 gfx::NativeWindow root_window_; |
179 | 148 |
180 // Used locally to track whether a call to LTH::Composite() did result in | |
181 // a posted SwapBuffers(). | |
182 bool did_post_swapbuffers_; | |
183 | |
184 // Used locally to inhibit ScheduleComposite() during | |
185 // UpdateLayerTreeHost(). | |
186 bool ignore_schedule_composite_; | |
187 | |
188 // Whether we need to composite in general because of any invalidation or | |
189 // explicit request. | |
190 bool needs_composite_; | |
191 | |
192 // Whether we need to update animations on the next composite. | 149 // Whether we need to update animations on the next composite. |
193 bool needs_animate_; | 150 bool needs_animate_; |
194 | 151 |
195 // Whether we posted a task and are about to composite. | |
196 bool will_composite_immediately_; | |
197 | |
198 // How we should schedule Composite during the next vsync. | |
199 CompositingTrigger composite_on_vsync_trigger_; | |
200 | |
201 // The Composite operation scheduled for the current vsync interval. | |
202 scoped_ptr<base::CancelableClosure> current_composite_task_; | |
203 | |
204 // The number of SwapBuffer calls that have not returned and ACK'd from | 152 // The number of SwapBuffer calls that have not returned and ACK'd from |
205 // the GPU thread. | 153 // the GPU thread. |
206 unsigned int pending_swapbuffers_; | 154 unsigned int pending_swapbuffers_; |
207 | 155 |
208 size_t num_successive_context_creation_failures_; | 156 size_t num_successive_context_creation_failures_; |
209 | 157 |
210 base::TimeDelta vsync_period_; | |
211 base::TimeTicks last_vsync_; | |
212 | |
213 base::OneShotTimer establish_gpu_channel_timeout_; | 158 base::OneShotTimer establish_gpu_channel_timeout_; |
214 | 159 |
215 // Whether there is an OutputSurface request pending from the current | 160 // Whether there is an OutputSurface request pending from the current |
216 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | 161 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| |
217 // if |host_| is deleted or we succeed in creating *and* initializing an | 162 // if |host_| is deleted or we succeed in creating *and* initializing an |
218 // OutputSurface (which is essentially the contract with cc). | 163 // OutputSurface (which is essentially the contract with cc). |
219 bool output_surface_request_pending_; | 164 bool output_surface_request_pending_; |
220 | 165 |
221 gpu::Capabilities gpu_capabilities_; | 166 gpu::Capabilities gpu_capabilities_; |
222 | 167 |
| 168 bool needs_begin_frames_; |
223 base::ObserverList<VSyncObserver, true> observer_list_; | 169 base::ObserverList<VSyncObserver, true> observer_list_; |
224 | 170 |
225 base::WeakPtrFactory<CompositorImpl> weak_factory_; | 171 base::WeakPtrFactory<CompositorImpl> weak_factory_; |
226 | 172 |
227 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); | 173 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); |
228 }; | 174 }; |
229 | 175 |
230 } // namespace content | 176 } // namespace content |
231 | 177 |
232 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 178 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
OLD | NEW |