1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_VIZ_SERVICE_FRAME_SINKS_GPU_VSYNC_BEGIN_FRAME_SOURCE_H_ 6 #define COMPONENTS_VIZ_SERVICE_FRAME_SINKS_GPU_VSYNC_BEGIN_FRAME_SOURCE_H_ 7 8 #include "base/macros.h" 9 #include "components/viz/common/display/update_vsync_parameters_callback.h" 10 #include "components/viz/common/frame_sinks/begin_frame_source.h" 11 #include "components/viz/service/display/frame_rate_decider.h" 12 #include "components/viz/service/viz_service_export.h" 13 14 namespace viz { 15 16 class OutputSurface; 17 18 // Receives begin frames via OutputSurface::SetGpuVSyncCallback(). Output 19 // surface must have |supports_gpu_vsync| capability. This class is not thread 20 // safe so the callbacks must be received on the original thread. The BFS is 21 // guaranteed to outlive the OutputSurface. 22 class VIZ_SERVICE_EXPORT GpuVSyncBeginFrameSource 23 : public ExternalBeginFrameSource, 24 public ExternalBeginFrameSourceClient { 25 public: 26 GpuVSyncBeginFrameSource(uint32_t restart_id, OutputSurface* output_surface); 27 ~GpuVSyncBeginFrameSource() override; 28 29 // ExternalBeginFrameSource overrides. 30 BeginFrameArgs GetMissedBeginFrameArgs(BeginFrameObserver* obs) override; 31 void SetPreferredInterval(base::TimeDelta interval) override; 32 33 // ExternalBeginFrameSourceClient implementation. 34 void OnNeedsBeginFrames(bool needs_begin_frames) override; 35 36 private: 37 void OnGpuVSync(base::TimeTicks vsync_time, base::TimeDelta vsync_interval); 38 39 OutputSurface* const output_surface_; 40 BeginFrameArgsGenerator begin_frame_args_generator_; 41 42 bool run_at_half_refresh_rate_ = false; 43 bool skip_next_vsync_ = false; 44 base::TimeDelta vsync_interval_ = BeginFrameArgs::DefaultInterval(); 45 46 DISALLOW_COPY_AND_ASSIGN(GpuVSyncBeginFrameSource); 47 }; 48 49 } // namespace viz 50 51 #endif // COMPONENTS_VIZ_SERVICE_FRAME_SINKS_GPU_VSYNC_BEGIN_FRAME_SOURCE_H_ 52