Chromium Code Reviews| 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/sky_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" | |
| 12 #include "base/location.h" | |
| 11 #include "jni/SkyView_jni.h" | 13 #include "jni/SkyView_jni.h" |
| 12 | 14 |
| 13 namespace sky { | 15 namespace sky { |
| 14 namespace shell { | 16 namespace shell { |
| 15 | 17 |
| 16 // static | 18 // static |
| 17 bool SkyView::Register(JNIEnv* env) { | 19 bool SkyView::Register(JNIEnv* env) { |
| 18 return RegisterNativesImpl(env); | 20 return RegisterNativesImpl(env); |
| 19 } | 21 } |
| 20 | 22 |
| 21 SkyView::Delegate::~Delegate() { | 23 SkyView::SkyView(const Config& config) : config_(config), window_(nullptr) { |
| 22 } | 24 JNIEnv* env = base::android::AttachCurrentThread(); |
| 23 | 25 Java_SkyView_createForActivity(env, base::android::GetApplicationContext(), |
| 24 SkyView::SkyView(Delegate* delegate) : delegate_(delegate), window_(NULL) { | 26 reinterpret_cast<jlong>(this)); |
|
eseidel
2015/02/05 05:57:28
Bleh. Really? Reinterpret-casting a pointer to a
abarth-chromium
2015/02/05 06:16:23
Yeah, that's how our JNI system works. It's super
eseidel
2015/02/05 07:06:44
And we don't have any helpers to hide the crazy?
| |
| 25 } | 27 } |
| 26 | 28 |
| 27 SkyView::~SkyView() { | 29 SkyView::~SkyView() { |
| 28 if (window_) | 30 if (window_) |
| 29 ReleaseWindow(); | 31 ReleaseWindow(); |
| 30 } | 32 } |
| 31 | 33 |
| 32 void SkyView::Init() { | |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 34 Java_SkyView_createForActivity(env, base::android::GetApplicationContext(), | |
| 35 reinterpret_cast<jlong>(this)); | |
| 36 } | |
| 37 | |
| 38 void SkyView::Destroy(JNIEnv* env, jobject obj) { | 34 void SkyView::Destroy(JNIEnv* env, jobject obj) { |
| 39 delegate_->OnDestroyed(); | |
| 40 } | 35 } |
| 41 | 36 |
| 42 void SkyView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { | 37 void SkyView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { |
| 43 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 38 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
| 44 // Note: This ensures that any local references used by | 39 // Note: This ensures that any local references used by |
| 45 // ANativeWindow_fromSurface are released immediately. This is needed as a | 40 // ANativeWindow_fromSurface are released immediately. This is needed as a |
| 46 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 41 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
| 47 { | 42 { |
| 48 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 43 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 49 window_ = ANativeWindow_fromSurface(env, jsurface); | 44 window_ = ANativeWindow_fromSurface(env, jsurface); |
| 50 } | 45 } |
| 51 delegate_->OnAcceleratedWidgetAvailable(window_); | 46 config_.gpu_task_runner->PostTask( |
| 47 FROM_HERE, base::Bind(&GPUDelegate::OnAcceleratedWidgetAvailable, | |
| 48 config_.gpu_delegate, window_)); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 void SkyView::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 51 void SkyView::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
| 55 DCHECK(window_); | 52 DCHECK(window_); |
| 53 config_.gpu_task_runner->PostTask( | |
| 54 FROM_HERE, base::Bind(&GPUDelegate::OnDestroyed, config_.gpu_delegate)); | |
| 56 ReleaseWindow(); | 55 ReleaseWindow(); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void SkyView::SurfaceSetSize(JNIEnv* env, | 58 void SkyView::SurfaceSetSize(JNIEnv* env, |
| 60 jobject obj, | 59 jobject obj, |
| 61 jint width, | 60 jint width, |
| 62 jint height, | 61 jint height, |
| 63 jfloat density) { | 62 jfloat density) { |
| 63 config_.ui_task_runner->PostTask( | |
| 64 FROM_HERE, | |
| 65 base::Bind(&UIDelegate::OnViewportMetricsChanged, config_.ui_delegate, | |
| 66 gfx::Size(width, height), density)); | |
| 64 } | 67 } |
| 65 | 68 |
| 66 void SkyView::ReleaseWindow() { | 69 void SkyView::ReleaseWindow() { |
| 67 ANativeWindow_release(window_); | 70 ANativeWindow_release(window_); |
| 68 window_ = NULL; | 71 window_ = nullptr; |
| 69 } | 72 } |
| 70 | 73 |
| 71 } // namespace shell | 74 } // namespace shell |
| 72 } // namespace sky | 75 } // namespace sky |
| OLD | NEW |