| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 CC_OUTPUT_OUTPUT_SURFACE_H_ | 5 #ifndef CC_OUTPUT_OUTPUT_SURFACE_H_ |
| 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ | 6 #define CC_OUTPUT_OUTPUT_SURFACE_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
| 15 #include "cc/base/rolling_time_delta_history.h" | 15 #include "cc/base/rolling_time_delta_history.h" |
| 16 #include "cc/output/begin_frame_args.h" |
| 16 #include "cc/output/context_provider.h" | 17 #include "cc/output/context_provider.h" |
| 17 #include "cc/output/overlay_candidate_validator.h" | 18 #include "cc/output/overlay_candidate_validator.h" |
| 18 #include "cc/output/software_output_device.h" | 19 #include "cc/output/software_output_device.h" |
| 19 #include "cc/scheduler/frame_rate_controller.h" | |
| 20 | 20 |
| 21 namespace base { class SingleThreadTaskRunner; } | 21 namespace base { class SingleThreadTaskRunner; } |
| 22 | 22 |
| 23 namespace ui { struct LatencyInfo; } | 23 namespace ui { struct LatencyInfo; } |
| 24 | 24 |
| 25 namespace gfx { | 25 namespace gfx { |
| 26 class Rect; | 26 class Rect; |
| 27 class Size; | 27 class Size; |
| 28 class Transform; | 28 class Transform; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace cc { | 31 namespace cc { |
| 32 | 32 |
| 33 class CompositorFrame; | 33 class CompositorFrame; |
| 34 class CompositorFrameAck; | 34 class CompositorFrameAck; |
| 35 struct ManagedMemoryPolicy; | 35 struct ManagedMemoryPolicy; |
| 36 class OutputSurfaceClient; | 36 class OutputSurfaceClient; |
| 37 | 37 |
| 38 // Represents the output surface for a compositor. The compositor owns | 38 // Represents the output surface for a compositor. The compositor owns |
| 39 // and manages its destruction. Its lifetime is: | 39 // and manages its destruction. Its lifetime is: |
| 40 // 1. Created on the main thread by the LayerTreeHost through its client. | 40 // 1. Created on the main thread by the LayerTreeHost through its client. |
| 41 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 41 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
| 42 // From here on, it will only be used on the compositor thread. | 42 // From here on, it will only be used on the compositor thread. |
| 43 // 3. If the 3D context is lost, then the compositor will delete the output | 43 // 3. If the 3D context is lost, then the compositor will delete the output |
| 44 // surface (on the compositor thread) and go back to step 1. | 44 // surface (on the compositor thread) and go back to step 1. |
| 45 class CC_EXPORT OutputSurface : public FrameRateControllerClient { | 45 class CC_EXPORT OutputSurface { |
| 46 public: | 46 public: |
| 47 enum { | 47 enum { |
| 48 DEFAULT_MAX_FRAMES_PENDING = 2 | 48 DEFAULT_MAX_FRAMES_PENDING = 2 |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); | 51 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); |
| 52 | 52 |
| 53 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); | 53 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); |
| 54 | 54 |
| 55 OutputSurface(scoped_refptr<ContextProvider> context_provider, | 55 OutputSurface(scoped_refptr<ContextProvider> context_provider, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 // Called by the compositor on the compositor thread. This is a place where | 102 // Called by the compositor on the compositor thread. This is a place where |
| 103 // thread-specific data for the output surface can be initialized, since from | 103 // thread-specific data for the output surface can be initialized, since from |
| 104 // this point on the output surface will only be used on the compositor | 104 // this point on the output surface will only be used on the compositor |
| 105 // thread. | 105 // thread. |
| 106 virtual bool BindToClient(OutputSurfaceClient* client); | 106 virtual bool BindToClient(OutputSurfaceClient* client); |
| 107 | 107 |
| 108 // Enable or disable vsync. | 108 // Enable or disable vsync. |
| 109 void SetThrottleFrameProduction(bool enable); | 109 void SetThrottleFrameProduction(bool enable); |
| 110 | 110 |
| 111 void InitializeBeginFrameEmulation(base::SingleThreadTaskRunner* task_runner, | |
| 112 base::TimeDelta interval); | |
| 113 | |
| 114 virtual void EnsureBackbuffer(); | 111 virtual void EnsureBackbuffer(); |
| 115 virtual void DiscardBackbuffer(); | 112 virtual void DiscardBackbuffer(); |
| 116 | 113 |
| 117 virtual void Reshape(const gfx::Size& size, float scale_factor); | 114 virtual void Reshape(const gfx::Size& size, float scale_factor); |
| 118 virtual gfx::Size SurfaceSize() const; | 115 virtual gfx::Size SurfaceSize() const; |
| 119 | 116 |
| 120 virtual void BindFramebuffer(); | 117 virtual void BindFramebuffer(); |
| 121 | 118 |
| 122 // The implementation may destroy or steal the contents of the CompositorFrame | 119 // The implementation may destroy or steal the contents of the CompositorFrame |
| 123 // passed in (though it will not take ownership of the CompositorFrame | 120 // passed in (though it will not take ownership of the CompositorFrame |
| 124 // itself). | 121 // itself). |
| 125 virtual void SwapBuffers(CompositorFrame* frame); | 122 virtual void SwapBuffers(CompositorFrame* frame); |
| 126 | 123 |
| 127 // Notifies frame-rate smoothness preference. If true, all non-critical | 124 // Notifies frame-rate smoothness preference. If true, all non-critical |
| 128 // processing should be stopped, or lowered in priority. | 125 // processing should be stopped, or lowered in priority. |
| 129 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} | 126 virtual void UpdateSmoothnessTakesPriority(bool prefer_smoothness) {} |
| 130 | 127 |
| 131 // Requests a BeginFrame notification from the output surface. The | 128 // Requests a BeginFrame notification from the output surface. The |
| 132 // notification will be delivered by calling | 129 // notification will be delivered by calling |
| 133 // OutputSurfaceClient::BeginFrame until the callback is disabled. | 130 // OutputSurfaceClient::BeginFrame until the callback is disabled. |
| 134 virtual void SetNeedsBeginFrame(bool enable); | 131 virtual void SetNeedsBeginFrame(bool enable) {} |
| 135 | 132 |
| 136 bool HasClient() { return !!client_; } | 133 bool HasClient() { return !!client_; } |
| 137 | 134 |
| 138 // Returns an estimate of the current GPU latency. When only a software | 135 // Returns an estimate of the current GPU latency. When only a software |
| 139 // device is present, returns 0. | 136 // device is present, returns 0. |
| 140 base::TimeDelta GpuLatencyEstimate(); | 137 base::TimeDelta GpuLatencyEstimate(); |
| 141 | 138 |
| 142 // Get the class capable of informing cc of hardware overlay capability. | 139 // Get the class capable of informing cc of hardware overlay capability. |
| 143 OverlayCandidateValidator* overlay_candidate_validator() const { | 140 OverlayCandidateValidator* overlay_candidate_validator() const { |
| 144 return overlay_candidate_validator_.get(); | 141 return overlay_candidate_validator_.get(); |
| 145 } | 142 } |
| 146 | 143 |
| 147 protected: | 144 protected: |
| 145 OutputSurfaceClient* client_; |
| 146 bool is_lost_; |
| 147 |
| 148 // Synchronously initialize context3d and enter hardware mode. | 148 // Synchronously initialize context3d and enter hardware mode. |
| 149 // This can only supported in threaded compositing mode. | 149 // This can only supported in threaded compositing mode. |
| 150 // |offscreen_context_provider| should match what is returned by | 150 // |offscreen_context_provider| should match what is returned by |
| 151 // LayerTreeClient::OffscreenContextProvider(). | 151 // LayerTreeClient::OffscreenContextProvider(). |
| 152 bool InitializeAndSetContext3d( | 152 bool InitializeAndSetContext3d( |
| 153 scoped_refptr<ContextProvider> context_provider, | 153 scoped_refptr<ContextProvider> context_provider, |
| 154 scoped_refptr<ContextProvider> offscreen_context_provider); | 154 scoped_refptr<ContextProvider> offscreen_context_provider); |
| 155 void ReleaseGL(); | 155 void ReleaseGL(); |
| 156 | 156 |
| 157 void PostSwapBuffersComplete(); | 157 void PostSwapBuffersComplete(); |
| 158 | 158 |
| 159 struct OutputSurface::Capabilities capabilities_; | 159 struct OutputSurface::Capabilities capabilities_; |
| 160 scoped_refptr<ContextProvider> context_provider_; | 160 scoped_refptr<ContextProvider> context_provider_; |
| 161 scoped_ptr<SoftwareOutputDevice> software_device_; | 161 scoped_ptr<SoftwareOutputDevice> software_device_; |
| 162 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; | 162 scoped_ptr<OverlayCandidateValidator> overlay_candidate_validator_; |
| 163 gfx::Size surface_size_; | 163 gfx::Size surface_size_; |
| 164 float device_scale_factor_; | 164 float device_scale_factor_; |
| 165 base::TimeDelta begin_frame_interval_; | |
| 166 | 165 |
| 167 // The FrameRateController is deprecated. | |
| 168 // Platforms should move to native BeginFrames instead. | |
| 169 void CommitVSyncParameters(base::TimeTicks timebase, | 166 void CommitVSyncParameters(base::TimeTicks timebase, |
| 170 base::TimeDelta interval); | 167 base::TimeDelta interval); |
| 171 virtual void FrameRateControllerTick(const BeginFrameArgs& args) OVERRIDE; | |
| 172 scoped_ptr<FrameRateController> frame_rate_controller_; | |
| 173 | 168 |
| 174 bool throttle_frame_production_; | |
| 175 bool needs_begin_frame_; | |
| 176 bool client_ready_for_begin_frame_; | |
| 177 | |
| 178 // This stores a BeginFrame that we couldn't process immediately, | |
| 179 // but might process retroactively in the near future. | |
| 180 BeginFrameArgs skipped_begin_frame_args_; | |
| 181 | |
| 182 // Forwarded to OutputSurfaceClient but threaded through OutputSurface | |
| 183 // first so OutputSurface has a chance to update the FrameRateController | |
| 184 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | 169 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); |
| 185 void BeginFrame(const BeginFrameArgs& args); | |
| 186 void DidSwapBuffers(); | |
| 187 void OnSwapBuffersComplete(); | |
| 188 void ReclaimResources(const CompositorFrameAck* ack); | 170 void ReclaimResources(const CompositorFrameAck* ack); |
| 189 void DidLoseOutputSurface(); | 171 void DidLoseOutputSurface(); |
| 190 void SetExternalStencilTest(bool enabled); | 172 void SetExternalStencilTest(bool enabled); |
| 191 void SetExternalDrawConstraints(const gfx::Transform& transform, | 173 void SetExternalDrawConstraints(const gfx::Transform& transform, |
| 192 const gfx::Rect& viewport, | 174 const gfx::Rect& viewport, |
| 193 const gfx::Rect& clip, | 175 const gfx::Rect& clip, |
| 194 bool valid_for_tile_management); | 176 bool valid_for_tile_management); |
| 195 | 177 |
| 196 // virtual for testing. | |
| 197 virtual base::TimeTicks RetroactiveBeginFrameDeadline(); | |
| 198 virtual void PostCheckForRetroactiveBeginFrame(); | |
| 199 void CheckForRetroactiveBeginFrame(); | |
| 200 | |
| 201 private: | 178 private: |
| 202 OutputSurfaceClient* client_; | |
| 203 | |
| 204 void SetUpContext3d(); | 179 void SetUpContext3d(); |
| 205 void ResetContext3d(); | 180 void ResetContext3d(); |
| 206 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); | 181 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); |
| 207 void UpdateAndMeasureGpuLatency(); | 182 void UpdateAndMeasureGpuLatency(); |
| 208 | 183 void OnSwapBuffersComplete(); |
| 209 bool is_lost_; | |
| 210 | |
| 211 // check_for_retroactive_begin_frame_pending_ is used to avoid posting | |
| 212 // redundant checks for a retroactive BeginFrame. | |
| 213 bool check_for_retroactive_begin_frame_pending_; | |
| 214 | 184 |
| 215 bool external_stencil_test_enabled_; | 185 bool external_stencil_test_enabled_; |
| 216 | 186 |
| 217 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 187 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
| 218 | 188 |
| 219 std::deque<unsigned> available_gpu_latency_query_ids_; | 189 std::deque<unsigned> available_gpu_latency_query_ids_; |
| 220 std::deque<unsigned> pending_gpu_latency_query_ids_; | 190 std::deque<unsigned> pending_gpu_latency_query_ids_; |
| 221 RollingTimeDeltaHistory gpu_latency_history_; | 191 RollingTimeDeltaHistory gpu_latency_history_; |
| 222 | 192 |
| 223 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 193 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
| 224 }; | 194 }; |
| 225 | 195 |
| 226 } // namespace cc | 196 } // namespace cc |
| 227 | 197 |
| 228 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 198 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
| OLD | NEW |