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