1 // Copyright 2018 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_EXTERNAL_BEGIN_FRAME_SOURCE_ANDROID_H_ 6 #define COMPONENTS_VIZ_SERVICE_FRAME_SINKS_EXTERNAL_BEGIN_FRAME_SOURCE_ANDROID_H_ 7 8 #include <jni.h> 9 10 #include "base/android/jni_weak_ref.h" 11 #include "base/macros.h" 12 #include "components/viz/common/frame_sinks/begin_frame_source.h" 13 #include "components/viz/service/viz_service_export.h" 14 15 namespace viz { 16 17 // An implementation of ExternalBeginFrameSource which is driven by VSync 18 // signals coming from org.chromium.ui.VSyncMonitor. 19 class VIZ_SERVICE_EXPORT ExternalBeginFrameSourceAndroid 20 : public ExternalBeginFrameSource, 21 public ExternalBeginFrameSourceClient { 22 public: 23 ExternalBeginFrameSourceAndroid(uint32_t restart_id, float refresh_rate); 24 ~ExternalBeginFrameSourceAndroid() override; 25 26 void OnVSync(JNIEnv* env, 27 const base::android::JavaParamRef<jobject>& obj, 28 jlong time_micros, 29 jlong period_micros); 30 void UpdateRefreshRate(float refresh_rate) override; 31 32 private: 33 // ExternalBeginFrameSourceClient implementation. 34 void OnNeedsBeginFrames(bool needs_begin_frames) override; 35 36 void SetEnabled(bool enabled); 37 38 base::android::ScopedJavaGlobalRef<jobject> j_object_; 39 BeginFrameArgsGenerator begin_frame_args_generator_; 40 41 DISALLOW_COPY_AND_ASSIGN(ExternalBeginFrameSourceAndroid); 42 }; 43 44 } // namespace viz 45 46 #endif // COMPONENTS_VIZ_SERVICE_FRAME_SINKS_EXTERNAL_BEGIN_FRAME_SOURCE_ANDROID_H_ 47