sync_control_vsync_provider.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2013 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. #ifndef UI_GL_SYNC_CONTROL_VSYNC_PROVIDER_H_
  5. #define UI_GL_SYNC_CONTROL_VSYNC_PROVIDER_H_
  6. #include <stdint.h>
  7. #include "base/containers/queue.h"
  8. #include "base/time/time.h"
  9. #include "build/build_config.h"
  10. #include "ui/gfx/vsync_provider.h"
  11. namespace gl {
  12. // Base class for providers based on extensions like GLX_OML_sync_control and
  13. // EGL_CHROMIUM_sync_control.
  14. class SyncControlVSyncProvider : public gfx::VSyncProvider {
  15. public:
  16. SyncControlVSyncProvider();
  17. SyncControlVSyncProvider(const SyncControlVSyncProvider&) = delete;
  18. SyncControlVSyncProvider& operator=(const SyncControlVSyncProvider&) = delete;
  19. ~SyncControlVSyncProvider() override;
  20. void GetVSyncParameters(UpdateVSyncCallback callback) override;
  21. bool GetVSyncParametersIfAvailable(base::TimeTicks* timebase,
  22. base::TimeDelta* interval) override;
  23. bool SupportGetVSyncParametersIfAvailable() const override;
  24. static constexpr bool IsSupported() {
  25. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  26. return true;
  27. #else
  28. return false;
  29. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  30. }
  31. protected:
  32. virtual bool GetSyncValues(int64_t* system_time,
  33. int64_t* media_stream_counter,
  34. int64_t* swap_buffer_counter) = 0;
  35. virtual bool GetMscRate(int32_t* numerator, int32_t* denominator) = 0;
  36. private:
  37. #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  38. base::TimeTicks last_timebase_;
  39. uint64_t last_media_stream_counter_ = 0;
  40. base::TimeDelta last_good_interval_;
  41. bool invalid_msc_ = false;
  42. // A short history of the last few computed intervals.
  43. // We use this to filter out the noise in the computation resulting
  44. // from configuration change (monitor reconfiguration, moving windows
  45. // between monitors, suspend and resume, etc.).
  46. base::queue<base::TimeDelta> last_computed_intervals_;
  47. #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
  48. };
  49. } // namespace gl
  50. #endif // UI_GL_SYNC_CONTROL_VSYNC_PROVIDER_H_