| 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/software_output_device.h" | 18 #include "cc/output/software_output_device.h" |
| 18 #include "cc/scheduler/frame_rate_controller.h" | |
| 19 | 19 |
| 20 namespace base { class SingleThreadTaskRunner; } | 20 namespace base { class SingleThreadTaskRunner; } |
| 21 | 21 |
| 22 namespace ui { struct LatencyInfo; } | 22 namespace ui { struct LatencyInfo; } |
| 23 | 23 |
| 24 namespace gfx { | 24 namespace gfx { |
| 25 class Rect; | 25 class Rect; |
| 26 class Size; | 26 class Size; |
| 27 class Transform; | 27 class Transform; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace cc { | 30 namespace cc { |
| 31 | 31 |
| 32 class CompositorFrame; | 32 class CompositorFrame; |
| 33 class CompositorFrameAck; | 33 class CompositorFrameAck; |
| 34 struct ManagedMemoryPolicy; | 34 struct ManagedMemoryPolicy; |
| 35 class OutputSurfaceClient; | 35 class OutputSurfaceClient; |
| 36 | 36 |
| 37 // Represents the output surface for a compositor. The compositor owns | 37 // Represents the output surface for a compositor. The compositor owns |
| 38 // and manages its destruction. Its lifetime is: | 38 // and manages its destruction. Its lifetime is: |
| 39 // 1. Created on the main thread by the LayerTreeHost through its client. | 39 // 1. Created on the main thread by the LayerTreeHost through its client. |
| 40 // 2. Passed to the compositor thread and bound to a client via BindToClient. | 40 // 2. Passed to the compositor thread and bound to a client via BindToClient. |
| 41 // From here on, it will only be used on the compositor thread. | 41 // From here on, it will only be used on the compositor thread. |
| 42 // 3. If the 3D context is lost, then the compositor will delete the output | 42 // 3. If the 3D context is lost, then the compositor will delete the output |
| 43 // surface (on the compositor thread) and go back to step 1. | 43 // surface (on the compositor thread) and go back to step 1. |
| 44 class CC_EXPORT OutputSurface : public FrameRateControllerClient { | 44 class CC_EXPORT OutputSurface { |
| 45 public: | 45 public: |
| 46 enum { | 46 enum { |
| 47 DEFAULT_MAX_FRAMES_PENDING = 2 | 47 DEFAULT_MAX_FRAMES_PENDING = 2 |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); | 50 explicit OutputSurface(scoped_refptr<ContextProvider> context_provider); |
| 51 | 51 |
| 52 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); | 52 explicit OutputSurface(scoped_ptr<SoftwareOutputDevice> software_device); |
| 53 | 53 |
| 54 OutputSurface(scoped_refptr<ContextProvider> context_provider, | 54 OutputSurface(scoped_refptr<ContextProvider> context_provider, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // (namely Android WebView), this is called to determine whether the software | 97 // (namely Android WebView), this is called to determine whether the software |
| 98 // device should be used on the current frame. | 98 // device should be used on the current frame. |
| 99 virtual bool ForcedDrawToSoftwareDevice() const; | 99 virtual bool ForcedDrawToSoftwareDevice() const; |
| 100 | 100 |
| 101 // Called by the compositor on the compositor thread. This is a place where | 101 // Called by the compositor on the compositor thread. This is a place where |
| 102 // thread-specific data for the output surface can be initialized, since from | 102 // thread-specific data for the output surface can be initialized, since from |
| 103 // this point on the output surface will only be used on the compositor | 103 // this point on the output surface will only be used on the compositor |
| 104 // thread. | 104 // thread. |
| 105 virtual bool BindToClient(OutputSurfaceClient* client); | 105 virtual bool BindToClient(OutputSurfaceClient* client); |
| 106 | 106 |
| 107 void InitializeBeginImplFrameEmulation( | 107 // Enable or disable vsync. |
| 108 base::SingleThreadTaskRunner* task_runner, | 108 void SetThrottleFrameProduction(bool enable); |
| 109 bool throttle_frame_production, | |
| 110 base::TimeDelta interval); | |
| 111 | |
| 112 void SetMaxFramesPending(int max_frames_pending); | |
| 113 | 109 |
| 114 virtual void EnsureBackbuffer(); | 110 virtual void EnsureBackbuffer(); |
| 115 virtual void DiscardBackbuffer(); | 111 virtual void DiscardBackbuffer(); |
| 116 | 112 |
| 117 virtual void Reshape(const gfx::Size& size, float scale_factor); | 113 virtual void Reshape(const gfx::Size& size, float scale_factor); |
| 118 virtual gfx::Size SurfaceSize() const; | 114 virtual gfx::Size SurfaceSize() const; |
| 119 | 115 |
| 120 virtual void BindFramebuffer(); | 116 virtual void BindFramebuffer(); |
| 121 | 117 |
| 122 // The implementation may destroy or steal the contents of the CompositorFrame | 118 // The implementation may destroy or steal the contents of the CompositorFrame |
| (...skipping 26 matching lines...) Expand all Loading... |
| 149 scoped_refptr<ContextProvider> offscreen_context_provider); | 145 scoped_refptr<ContextProvider> offscreen_context_provider); |
| 150 void ReleaseGL(); | 146 void ReleaseGL(); |
| 151 | 147 |
| 152 void PostSwapBuffersComplete(); | 148 void PostSwapBuffersComplete(); |
| 153 | 149 |
| 154 struct OutputSurface::Capabilities capabilities_; | 150 struct OutputSurface::Capabilities capabilities_; |
| 155 scoped_refptr<ContextProvider> context_provider_; | 151 scoped_refptr<ContextProvider> context_provider_; |
| 156 scoped_ptr<SoftwareOutputDevice> software_device_; | 152 scoped_ptr<SoftwareOutputDevice> software_device_; |
| 157 gfx::Size surface_size_; | 153 gfx::Size surface_size_; |
| 158 float device_scale_factor_; | 154 float device_scale_factor_; |
| 155 base::TimeDelta begin_impl_frame_interval_; |
| 159 | 156 |
| 160 // The FrameRateController is deprecated. | |
| 161 // Platforms should move to native BeginImplFrames instead. | |
| 162 void CommitVSyncParameters(base::TimeTicks timebase, | 157 void CommitVSyncParameters(base::TimeTicks timebase, |
| 163 base::TimeDelta interval); | 158 base::TimeDelta interval); |
| 164 virtual void FrameRateControllerTick(bool throttled, | 159 bool throttle_frame_production_; |
| 165 const BeginFrameArgs& args) OVERRIDE; | |
| 166 scoped_ptr<FrameRateController> frame_rate_controller_; | |
| 167 int max_frames_pending_; | |
| 168 int pending_swap_buffers_; | |
| 169 bool needs_begin_impl_frame_; | 160 bool needs_begin_impl_frame_; |
| 170 bool client_ready_for_begin_impl_frame_; | 161 bool client_ready_for_begin_impl_frame_; |
| 171 | 162 |
| 172 // This stores a BeginImplFrame that we couldn't process immediately, | 163 // This stores a BeginImplFrame that we couldn't process immediately, |
| 173 // but might process retroactively in the near future. | 164 // but might process retroactively in the near future. |
| 174 BeginFrameArgs skipped_begin_impl_frame_args_; | 165 BeginFrameArgs skipped_begin_impl_frame_args_; |
| 175 | 166 |
| 176 // Forwarded to OutputSurfaceClient but threaded through OutputSurface | 167 // Forwarded to OutputSurfaceClient but threaded through OutputSurface |
| 177 // first so OutputSurface has a chance to update the FrameRateController | 168 // first so OutputSurface has a chance to update the BeginFrameSource |
| 178 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); | 169 void SetNeedsRedrawRect(const gfx::Rect& damage_rect); |
| 179 void BeginImplFrame(const BeginFrameArgs& args); | 170 void BeginImplFrame(const BeginFrameArgs& args); |
| 180 void DidSwapBuffers(); | 171 void DidSwapBuffers(); |
| 181 void OnSwapBuffersComplete(); | 172 void OnSwapBuffersComplete(); |
| 182 void ReclaimResources(const CompositorFrameAck* ack); | 173 void ReclaimResources(const CompositorFrameAck* ack); |
| 183 void DidLoseOutputSurface(); | 174 void DidLoseOutputSurface(); |
| 184 void SetExternalStencilTest(bool enabled); | 175 void SetExternalStencilTest(bool enabled); |
| 185 void SetExternalDrawConstraints(const gfx::Transform& transform, | 176 void SetExternalDrawConstraints(const gfx::Transform& transform, |
| 186 const gfx::Rect& viewport, | 177 const gfx::Rect& viewport, |
| 187 const gfx::Rect& clip, | 178 const gfx::Rect& clip, |
| 188 bool valid_for_tile_management); | 179 bool valid_for_tile_management); |
| 189 | 180 |
| 190 // virtual for testing. | 181 // virtual for testing. |
| 191 virtual base::TimeTicks RetroactiveBeginImplFrameDeadline(); | 182 virtual base::TimeTicks RetroactiveBeginImplFrameDeadline(); |
| 192 virtual void PostCheckForRetroactiveBeginImplFrame(); | 183 virtual void PostCheckForRetroactiveBeginImplFrame(); |
| 193 void CheckForRetroactiveBeginImplFrame(); | 184 void CheckForRetroactiveBeginImplFrame(); |
| 194 | 185 |
| 195 private: | 186 private: |
| 196 OutputSurfaceClient* client_; | 187 OutputSurfaceClient* client_; |
| 197 | 188 |
| 198 void SetUpContext3d(); | 189 void SetUpContext3d(); |
| 199 void ResetContext3d(); | 190 void ResetContext3d(); |
| 200 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); | 191 void SetMemoryPolicy(const ManagedMemoryPolicy& policy); |
| 201 void UpdateAndMeasureGpuLatency(); | 192 void UpdateAndMeasureGpuLatency(); |
| 202 | 193 |
| 194 bool is_lost_; |
| 195 |
| 203 // check_for_retroactive_begin_impl_frame_pending_ is used to avoid posting | 196 // check_for_retroactive_begin_impl_frame_pending_ is used to avoid posting |
| 204 // redundant checks for a retroactive BeginImplFrame. | 197 // redundant checks for a retroactive BeginImplFrame. |
| 205 bool check_for_retroactive_begin_impl_frame_pending_; | 198 bool check_for_retroactive_begin_impl_frame_pending_; |
| 206 | 199 |
| 207 bool external_stencil_test_enabled_; | 200 bool external_stencil_test_enabled_; |
| 208 | 201 |
| 209 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; | 202 base::WeakPtrFactory<OutputSurface> weak_ptr_factory_; |
| 210 | 203 |
| 211 std::deque<unsigned> available_gpu_latency_query_ids_; | 204 std::deque<unsigned> available_gpu_latency_query_ids_; |
| 212 std::deque<unsigned> pending_gpu_latency_query_ids_; | 205 std::deque<unsigned> pending_gpu_latency_query_ids_; |
| 213 RollingTimeDeltaHistory gpu_latency_history_; | 206 RollingTimeDeltaHistory gpu_latency_history_; |
| 214 | 207 |
| 215 DISALLOW_COPY_AND_ASSIGN(OutputSurface); | 208 DISALLOW_COPY_AND_ASSIGN(OutputSurface); |
| 216 }; | 209 }; |
| 217 | 210 |
| 218 } // namespace cc | 211 } // namespace cc |
| 219 | 212 |
| 220 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ | 213 #endif // CC_OUTPUT_OUTPUT_SURFACE_H_ |
| OLD | NEW |