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 OnVSync(base::TimeTicks timebase, | 51 virtual void OnUpdateVSyncParameters(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); | |
68 | 67 |
69 // ui::ResourceProvider implementation. | 68 // ui::ResourceProvider implementation. |
70 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; | 69 cc::UIResourceId CreateUIResource(cc::UIResourceClient* client) override; |
71 void DeleteUIResource(cc::UIResourceId resource_id) override; | 70 void DeleteUIResource(cc::UIResourceId resource_id) override; |
72 bool SupportsETC1NonPowerOfTwo() const override; | 71 bool SupportsETC1NonPowerOfTwo() const override; |
73 | 72 |
74 private: | 73 private: |
75 // Compositor implementation. | 74 // Compositor implementation. |
76 void SetRootLayer(scoped_refptr<cc::Layer> root) override; | 75 void SetRootLayer(scoped_refptr<cc::Layer> root) override; |
77 void SetSurface(jobject surface) override; | 76 void SetSurface(jobject surface) override; |
(...skipping 22 matching lines...) Expand all Loading... |
100 void DidCommit() override; | 99 void DidCommit() override; |
101 void DidCommitAndDrawFrame() override {} | 100 void DidCommitAndDrawFrame() override {} |
102 void DidCompleteSwapBuffers() override; | 101 void DidCompleteSwapBuffers() override; |
103 void DidCompletePageScaleAnimation() override {} | 102 void DidCompletePageScaleAnimation() override {} |
104 void RecordFrameTimingEvents( | 103 void RecordFrameTimingEvents( |
105 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, | 104 scoped_ptr<cc::FrameTimingTracker::CompositeTimingSet> composite_events, |
106 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) | 105 scoped_ptr<cc::FrameTimingTracker::MainFrameTimingSet> main_frame_events) |
107 override {} | 106 override {} |
108 | 107 |
109 // LayerTreeHostSingleThreadClient implementation. | 108 // LayerTreeHostSingleThreadClient implementation. |
| 109 void ScheduleComposite() override; |
| 110 void ScheduleAnimation() override; |
110 void DidPostSwapBuffers() override; | 111 void DidPostSwapBuffers() override; |
111 void DidAbortSwapBuffers() override; | 112 void DidAbortSwapBuffers() override; |
112 | 113 |
113 // WindowAndroidCompositor implementation. | 114 // WindowAndroidCompositor implementation. |
114 void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) override; | 115 void AttachLayerForReadback(scoped_refptr<cc::Layer> layer) override; |
115 void RequestCopyOfOutputOnRootLayer( | 116 void RequestCopyOfOutputOnRootLayer( |
116 scoped_ptr<cc::CopyOutputRequest> request) override; | 117 scoped_ptr<cc::CopyOutputRequest> request) override; |
117 void OnVSync(base::TimeTicks frame_time, | 118 void OnVSync(base::TimeTicks frame_time, |
118 base::TimeDelta vsync_period) override; | 119 base::TimeDelta vsync_period) override; |
119 void SetNeedsAnimate() override; | 120 void SetNeedsAnimate() override; |
| 121 |
120 void SetVisible(bool visible); | 122 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); |
121 void CreateOutputSurface(); | 131 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 } |
122 void CreateLayerTreeHost(); | 153 void CreateLayerTreeHost(); |
123 | 154 |
124 void OnGpuChannelEstablished(); | 155 void OnGpuChannelEstablished(); |
125 void OnGpuChannelTimeout(); | 156 void OnGpuChannelTimeout(); |
126 | 157 |
127 // root_layer_ is the persistent internal root layer, while subroot_layer_ | 158 // root_layer_ is the persistent internal root layer, while subroot_layer_ |
128 // is the one attached by the compositor client. | 159 // is the one attached by the compositor client. |
129 scoped_refptr<cc::Layer> root_layer_; | 160 scoped_refptr<cc::Layer> root_layer_; |
130 scoped_refptr<cc::Layer> subroot_layer_; | 161 scoped_refptr<cc::Layer> subroot_layer_; |
131 | 162 |
132 scoped_ptr<cc::LayerTreeHost> host_; | 163 scoped_ptr<cc::LayerTreeHost> host_; |
133 ui::ResourceManagerImpl resource_manager_; | 164 ui::ResourceManagerImpl resource_manager_; |
134 | 165 |
135 scoped_ptr<cc::OnscreenDisplayClient> display_client_; | 166 scoped_ptr<cc::OnscreenDisplayClient> display_client_; |
136 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; | 167 scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_; |
137 | 168 |
138 gfx::Size size_; | 169 gfx::Size size_; |
139 bool has_transparent_background_; | 170 bool has_transparent_background_; |
140 float device_scale_factor_; | 171 float device_scale_factor_; |
141 | 172 |
142 ANativeWindow* window_; | 173 ANativeWindow* window_; |
143 int surface_id_; | 174 int surface_id_; |
144 | 175 |
145 CompositorClient* client_; | 176 CompositorClient* client_; |
146 | 177 |
147 gfx::NativeWindow root_window_; | 178 gfx::NativeWindow root_window_; |
148 | 179 |
| 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 |
149 // Whether we need to update animations on the next composite. | 192 // Whether we need to update animations on the next composite. |
150 bool needs_animate_; | 193 bool needs_animate_; |
151 | 194 |
| 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 |
152 // The number of SwapBuffer calls that have not returned and ACK'd from | 204 // The number of SwapBuffer calls that have not returned and ACK'd from |
153 // the GPU thread. | 205 // the GPU thread. |
154 unsigned int pending_swapbuffers_; | 206 unsigned int pending_swapbuffers_; |
155 | 207 |
156 size_t num_successive_context_creation_failures_; | 208 size_t num_successive_context_creation_failures_; |
157 | 209 |
| 210 base::TimeDelta vsync_period_; |
| 211 base::TimeTicks last_vsync_; |
| 212 |
158 base::OneShotTimer establish_gpu_channel_timeout_; | 213 base::OneShotTimer establish_gpu_channel_timeout_; |
159 | 214 |
160 // Whether there is an OutputSurface request pending from the current | 215 // Whether there is an OutputSurface request pending from the current |
161 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| | 216 // |host_|. Becomes |true| if RequestNewOutputSurface is called, and |false| |
162 // if |host_| is deleted or we succeed in creating *and* initializing an | 217 // if |host_| is deleted or we succeed in creating *and* initializing an |
163 // OutputSurface (which is essentially the contract with cc). | 218 // OutputSurface (which is essentially the contract with cc). |
164 bool output_surface_request_pending_; | 219 bool output_surface_request_pending_; |
165 | 220 |
166 gpu::Capabilities gpu_capabilities_; | 221 gpu::Capabilities gpu_capabilities_; |
167 | 222 |
168 bool needs_begin_frames_; | |
169 base::ObserverList<VSyncObserver, true> observer_list_; | 223 base::ObserverList<VSyncObserver, true> observer_list_; |
170 | 224 |
171 base::WeakPtrFactory<CompositorImpl> weak_factory_; | 225 base::WeakPtrFactory<CompositorImpl> weak_factory_; |
172 | 226 |
173 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); | 227 DISALLOW_COPY_AND_ASSIGN(CompositorImpl); |
174 }; | 228 }; |
175 | 229 |
176 } // namespace content | 230 } // namespace content |
177 | 231 |
178 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ | 232 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITOR_IMPL_ANDROID_H_ |
OLD | NEW |