Modify transform_to_target of RenderPasses in Surfaces.
[chromium-blink-merge.git] / ui / android / window_android.cc
blob172a7ae2f37f51600e7dcb5c32f5c875cbdca96b
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.
5 #include "ui/android/window_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_weak_ref.h"
10 #include "base/android/scoped_java_ref.h"
11 #include "jni/WindowAndroid_jni.h"
12 #include "ui/android/window_android_compositor.h"
13 #include "ui/android/window_android_observer.h"
15 namespace ui {
17 using base::android::AttachCurrentThread;
18 using base::android::ScopedJavaLocalRef;
20 WindowAndroid::WindowAndroid(JNIEnv* env, jobject obj)
21 : weak_java_window_(env, obj), compositor_(NULL) {
24 void WindowAndroid::Destroy(JNIEnv* env, jobject obj) {
25 delete this;
28 ScopedJavaLocalRef<jobject> WindowAndroid::GetJavaObject() {
29 return weak_java_window_.get(AttachCurrentThread());
32 bool WindowAndroid::RegisterWindowAndroid(JNIEnv* env) {
33 return RegisterNativesImpl(env);
36 WindowAndroid::~WindowAndroid() {
37 DCHECK(!compositor_);
40 void WindowAndroid::OnCompositingDidCommit() {
41 FOR_EACH_OBSERVER(WindowAndroidObserver,
42 observer_list_,
43 OnCompositingDidCommit());
46 void WindowAndroid::AddObserver(WindowAndroidObserver* observer) {
47 if (!observer_list_.HasObserver(observer))
48 observer_list_.AddObserver(observer);
51 void WindowAndroid::RemoveObserver(WindowAndroidObserver* observer) {
52 observer_list_.RemoveObserver(observer);
55 void WindowAndroid::AttachCompositor(WindowAndroidCompositor* compositor) {
56 if (compositor_ && compositor != compositor_)
57 DetachCompositor();
59 compositor_ = compositor;
60 FOR_EACH_OBSERVER(WindowAndroidObserver,
61 observer_list_,
62 OnAttachCompositor());
65 void WindowAndroid::DetachCompositor() {
66 compositor_ = NULL;
67 FOR_EACH_OBSERVER(WindowAndroidObserver,
68 observer_list_,
69 OnDetachCompositor());
70 observer_list_.Clear();
73 void WindowAndroid::RequestVSyncUpdate() {
74 JNIEnv* env = AttachCurrentThread();
75 Java_WindowAndroid_requestVSyncUpdate(env, GetJavaObject().obj());
78 void WindowAndroid::SetNeedsAnimate() {
79 if (compositor_)
80 compositor_->SetNeedsAnimate();
83 void WindowAndroid::Animate(base::TimeTicks begin_frame_time) {
84 FOR_EACH_OBSERVER(
85 WindowAndroidObserver, observer_list_, OnAnimate(begin_frame_time));
88 void WindowAndroid::OnVSync(JNIEnv* env,
89 jobject obj,
90 jlong time_micros,
91 jlong period_micros) {
92 base::TimeTicks frame_time(base::TimeTicks::FromInternalValue(time_micros));
93 base::TimeDelta vsync_period(
94 base::TimeDelta::FromMicroseconds(period_micros));
95 FOR_EACH_OBSERVER(
96 WindowAndroidObserver,
97 observer_list_,
98 OnVSync(frame_time, vsync_period));
99 if (compositor_)
100 compositor_->OnVSync(frame_time, vsync_period);
103 // ----------------------------------------------------------------------------
104 // Native JNI methods
105 // ----------------------------------------------------------------------------
107 jlong Init(JNIEnv* env, jobject obj) {
108 WindowAndroid* window = new WindowAndroid(env, obj);
109 return reinterpret_cast<intptr_t>(window);
112 } // namespace ui