| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/platform_window/android/platform_window_android.h" | 5 #include "ui/platform_window/android/platform_window_android.h" |
| 6 | 6 |
| 7 #include <android/input.h> | 7 #include <android/input.h> |
| 8 #include <android/native_window_jni.h> | 8 #include <android/native_window_jni.h> |
| 9 | 9 |
| 10 #include "base/android/context_utils.h" | 10 #include "base/android/context_utils.h" |
| 11 #include "base/android/jni_android.h" | 11 #include "base/android/jni_android.h" |
| 12 #include "base/bind.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "gpu/ipc/common/gpu_surface_tracker.h" |
| 12 #include "jni/PlatformWindowAndroid_jni.h" | 15 #include "jni/PlatformWindowAndroid_jni.h" |
| 13 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
| 14 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 17 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
| 15 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/platform_window/platform_window_delegate.h" | 19 #include "ui/platform_window/platform_window_delegate.h" |
| 17 | 20 |
| 18 using base::android::JavaParamRef; | 21 using base::android::JavaParamRef; |
| 19 using base::android::ScopedJavaLocalRef; | 22 using base::android::ScopedJavaLocalRef; |
| 20 | 23 |
| 21 namespace ui { | 24 namespace ui { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 const JavaParamRef<jobject>& obj, | 86 const JavaParamRef<jobject>& obj, |
| 84 const JavaParamRef<jobject>& jsurface, | 87 const JavaParamRef<jobject>& jsurface, |
| 85 float device_pixel_ratio) { | 88 float device_pixel_ratio) { |
| 86 // Note: This ensures that any local references used by | 89 // Note: This ensures that any local references used by |
| 87 // ANativeWindow_fromSurface are released immediately. This is needed as a | 90 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 88 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 91 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 89 { | 92 { |
| 90 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 93 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 91 window_ = ANativeWindow_fromSurface(env, jsurface); | 94 window_ = ANativeWindow_fromSurface(env, jsurface); |
| 92 } | 95 } |
| 93 delegate_->OnAcceleratedWidgetAvailable(window_, device_pixel_ratio); | 96 |
| 97 gpu::SurfaceHandle surface_handle = |
| 98 gpu::GpuSurfaceTracker::GetInstance()->AddSurfaceForNativeWidget(window_); |
| 99 |
| 100 // Post the notification to the delegate to ensure pending initializations |
| 101 // for the surface have a chance to run. |
| 102 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 103 FROM_HERE, |
| 104 base::Bind(&PlatformWindowAndroid::NotifyDelegateSurfaceCreated, |
| 105 weak_factory_.GetWeakPtr(), surface_handle, |
| 106 device_pixel_ratio)); |
| 94 } | 107 } |
| 95 | 108 |
| 96 void PlatformWindowAndroid::SurfaceDestroyed(JNIEnv* env, | 109 void PlatformWindowAndroid::SurfaceDestroyed(JNIEnv* env, |
| 97 const JavaParamRef<jobject>& obj) { | 110 const JavaParamRef<jobject>& obj) { |
| 98 DCHECK(window_); | 111 DCHECK(window_); |
| 99 delegate_->OnAcceleratedWidgetDestroyed(); | 112 delegate_->OnAcceleratedWidgetDestroyed(); |
| 100 ReleaseWindow(); | 113 ReleaseWindow(); |
| 101 } | 114 } |
| 102 | 115 |
| 103 void PlatformWindowAndroid::SurfaceSetSize(JNIEnv* env, | 116 void PlatformWindowAndroid::SurfaceSetSize(JNIEnv* env, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 delegate_->DispatchEvent(&char_event); | 162 delegate_->DispatchEvent(&char_event); |
| 150 } | 163 } |
| 151 return true; | 164 return true; |
| 152 } | 165 } |
| 153 | 166 |
| 154 void PlatformWindowAndroid::ReleaseWindow() { | 167 void PlatformWindowAndroid::ReleaseWindow() { |
| 155 ANativeWindow_release(window_); | 168 ANativeWindow_release(window_); |
| 156 window_ = NULL; | 169 window_ = NULL; |
| 157 } | 170 } |
| 158 | 171 |
| 172 void PlatformWindowAndroid::NotifyDelegateSurfaceCreated( |
| 173 gpu::SurfaceHandle surface_handle, |
| 174 float device_pixel_ratio) { |
| 175 delegate_->OnAcceleratedWidgetAvailable(surface_handle, device_pixel_ratio); |
| 176 } |
| 177 |
| 159 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
| 160 // PlatformWindowAndroid, PlatformWindow implementation: | 179 // PlatformWindowAndroid, PlatformWindow implementation: |
| 161 | 180 |
| 162 void PlatformWindowAndroid::Show() { | 181 void PlatformWindowAndroid::Show() { |
| 163 if (!java_platform_window_android_.is_empty()) | 182 if (!java_platform_window_android_.is_empty()) |
| 164 return; | 183 return; |
| 184 |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | 185 JNIEnv* env = base::android::AttachCurrentThread(); |
| 166 java_platform_window_android_ = JavaObjectWeakGlobalRef( | 186 java_platform_window_android_ = JavaObjectWeakGlobalRef( |
| 167 env, Java_PlatformWindowAndroid_createForActivity( | 187 env, Java_PlatformWindowAndroid_createForCurrentActivity( |
| 168 env, base::android::GetApplicationContext(), | 188 env, |
| 169 reinterpret_cast<jlong>(this), | 189 reinterpret_cast<jlong>(this), |
| 170 reinterpret_cast<jlong>(&platform_ime_controller_)).obj()); | 190 reinterpret_cast<jlong>(&platform_ime_controller_)) |
| 191 .obj()); |
| 171 } | 192 } |
| 172 | 193 |
| 173 void PlatformWindowAndroid::Hide() { | 194 void PlatformWindowAndroid::Hide() { |
| 174 // Nothing to do. View is always visible. | 195 // Nothing to do. View is always visible. |
| 175 } | 196 } |
| 176 | 197 |
| 177 void PlatformWindowAndroid::Close() { | 198 void PlatformWindowAndroid::Close() { |
| 178 delegate_->OnCloseRequest(); | 199 delegate_->OnCloseRequest(); |
| 179 } | 200 } |
| 180 | 201 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 245 |
| 225 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { | 246 void PlatformWindowAndroid::ConfineCursorToBounds(const gfx::Rect& bounds) { |
| 226 NOTIMPLEMENTED(); | 247 NOTIMPLEMENTED(); |
| 227 } | 248 } |
| 228 | 249 |
| 229 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { | 250 PlatformImeController* PlatformWindowAndroid::GetPlatformImeController() { |
| 230 return &platform_ime_controller_; | 251 return &platform_ime_controller_; |
| 231 } | 252 } |
| 232 | 253 |
| 233 } // namespace ui | 254 } // namespace ui |
| OLD | NEW |