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 5 #ifndef UI_BASE_ANDROID_WINDOW_ANDROID_H_ 6 #define UI_BASE_ANDROID_WINDOW_ANDROID_H_ 7 8 #include <jni.h> 9 #include <vector> 10 #include "base/android/jni_weak_ref.h" 11 #include "base/android/scoped_java_ref.h" 12 #include "base/observer_list.h" 13 #include "base/time/time.h" 14 #include "ui/base/ui_base_export.h" 15 #include "ui/gfx/vector2d_f.h" 16 17 namespace ui { 18 19 class WindowAndroidCompositor; 20 class WindowAndroidObserver; 21 22 // Android implementation of the activity window. 23 class UI_BASE_EXPORT WindowAndroid { 24 public: 25 WindowAndroid(JNIEnv* env, jobject obj, jlong vsync_period); 26 27 void Destroy(JNIEnv* env, jobject obj); 28 29 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); 30 31 static bool RegisterWindowAndroid(JNIEnv* env); 32 33 // The content offset is used to translate snapshots to the correct part of 34 // the window. set_content_offset(const gfx::Vector2dF & content_offset)35 void set_content_offset(const gfx::Vector2dF& content_offset) { 36 content_offset_ = content_offset; 37 } 38 content_offset()39 gfx::Vector2dF content_offset() const { 40 return content_offset_; 41 } 42 43 // Compositor callback relay. 44 void OnCompositingDidCommit(); 45 46 void AttachCompositor(WindowAndroidCompositor* compositor); 47 void DetachCompositor(); 48 49 void AddObserver(WindowAndroidObserver* observer); 50 void RemoveObserver(WindowAndroidObserver* observer); 51 GetCompositor()52 WindowAndroidCompositor* GetCompositor() { return compositor_; } 53 54 void RequestVSyncUpdate(); 55 void SetNeedsAnimate(); 56 void OnVSync(JNIEnv* env, jobject obj, jlong time_micros); 57 void Animate(base::TimeTicks begin_frame_time); 58 59 private: 60 ~WindowAndroid(); 61 62 JavaObjectWeakGlobalRef weak_java_window_; 63 gfx::Vector2dF content_offset_; 64 WindowAndroidCompositor* compositor_; 65 base::TimeDelta vsync_period_; 66 67 ObserverList<WindowAndroidObserver> observer_list_; 68 69 DISALLOW_COPY_AND_ASSIGN(WindowAndroid); 70 }; 71 72 } // namespace ui 73 74 #endif // UI_BASE_ANDROID_WINDOW_ANDROID_H_ 75