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