| 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 "sky/shell/sky_view.h" | 5 #include "sky/shell/platform_view.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/jni_android.h" | 10 #include "base/android/jni_android.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "jni/SkyView_jni.h" | 13 #include "jni/PlatformView_jni.h" |
| 14 #include "sky/shell/shell.h" |
| 14 | 15 |
| 15 namespace sky { | 16 namespace sky { |
| 16 namespace shell { | 17 namespace shell { |
| 17 | 18 |
| 19 static jlong Attach(JNIEnv* env, jclass clazz) { |
| 20 return reinterpret_cast<jlong>(Shell::Shared().view()); |
| 21 } |
| 22 |
| 18 // static | 23 // static |
| 19 bool SkyView::Register(JNIEnv* env) { | 24 bool PlatformView::Register(JNIEnv* env) { |
| 20 return RegisterNativesImpl(env); | 25 return RegisterNativesImpl(env); |
| 21 } | 26 } |
| 22 | 27 |
| 23 SkyView::SkyView(const Config& config) : config_(config), window_(nullptr) { | 28 PlatformView::PlatformView(const Config& config) |
| 24 JNIEnv* env = base::android::AttachCurrentThread(); | 29 : config_(config), window_(nullptr) { |
| 25 Java_SkyView_createForActivity(env, base::android::GetApplicationContext(), | |
| 26 reinterpret_cast<jlong>(this)); | |
| 27 } | 30 } |
| 28 | 31 |
| 29 SkyView::~SkyView() { | 32 PlatformView::~PlatformView() { |
| 30 if (window_) | 33 if (window_) |
| 31 ReleaseWindow(); | 34 ReleaseWindow(); |
| 32 } | 35 } |
| 33 | 36 |
| 34 void SkyView::Destroy(JNIEnv* env, jobject obj) { | 37 void PlatformView::Detach(JNIEnv* env, jobject obj) { |
| 38 DCHECK(!window_); |
| 35 } | 39 } |
| 36 | 40 |
| 37 void SkyView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { | 41 void PlatformView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { |
| 38 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 42 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
| 39 // Note: This ensures that any local references used by | 43 // Note: This ensures that any local references used by |
| 40 // ANativeWindow_fromSurface are released immediately. This is needed as a | 44 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 41 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 45 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 42 { | 46 { |
| 43 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 47 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 44 window_ = ANativeWindow_fromSurface(env, jsurface); | 48 window_ = ANativeWindow_fromSurface(env, jsurface); |
| 45 } | 49 } |
| 46 config_.gpu_task_runner->PostTask( | 50 config_.gpu_task_runner->PostTask( |
| 47 FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, | 51 FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, |
| 48 config_.gpu_delegate, window_)); | 52 config_.gpu_delegate, window_)); |
| 49 } | 53 } |
| 50 | 54 |
| 51 void SkyView::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 55 void PlatformView::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
| 52 DCHECK(window_); | 56 DCHECK(window_); |
| 53 config_.gpu_task_runner->PostTask( | 57 config_.gpu_task_runner->PostTask( |
| 54 FROM_HERE, | 58 FROM_HERE, |
| 55 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); | 59 base::Bind(&GPUDelegate::OnOutputSurfaceDestroyed, config_.gpu_delegate)); |
| 56 ReleaseWindow(); | 60 ReleaseWindow(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 void SkyView::SurfaceSetSize(JNIEnv* env, | 63 void PlatformView::SurfaceSetSize(JNIEnv* env, |
| 60 jobject obj, | 64 jobject obj, |
| 61 jint width, | 65 jint width, |
| 62 jint height, | 66 jint height, |
| 63 jfloat density) { | 67 jfloat density) { |
| 64 config_.ui_task_runner->PostTask( | 68 config_.ui_task_runner->PostTask( |
| 65 FROM_HERE, | 69 FROM_HERE, |
| 66 base::Bind(&UIDelegate::OnViewportMetricsChanged, config_.ui_delegate, | 70 base::Bind(&UIDelegate::OnViewportMetricsChanged, config_.ui_delegate, |
| 67 gfx::Size(width, height), density)); | 71 gfx::Size(width, height), density)); |
| 68 } | 72 } |
| 69 | 73 |
| 70 void SkyView::ReleaseWindow() { | 74 void PlatformView::ReleaseWindow() { |
| 71 ANativeWindow_release(window_); | 75 ANativeWindow_release(window_); |
| 72 window_ = nullptr; | 76 window_ = nullptr; |
| 73 } | 77 } |
| 74 | 78 |
| 75 } // namespace shell | 79 } // namespace shell |
| 76 } // namespace sky | 80 } // namespace sky |
| OLD | NEW |