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/android/platform_view.h" | 5 #include "sky/shell/android/platform_view_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/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/PlatformView_jni.h" | 13 #include "jni/PlatformViewAndroid_jni.h" |
14 #include "sky/shell/shell.h" | 14 #include "sky/shell/shell.h" |
15 | 15 |
16 namespace sky { | 16 namespace sky { |
17 namespace shell { | 17 namespace shell { |
18 | 18 |
19 static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) { | 19 static jlong Attach(JNIEnv* env, jclass clazz, jint viewportObserverHandle) { |
20 PlatformView* view = Shell::Shared().view(); | 20 PlatformView* view = Shell::Shared().view(); |
21 view->ConnectToViewportObserver( | 21 view->ConnectToViewportObserver( |
22 mojo::MakeRequest<ViewportObserver>(mojo::ScopedMessagePipeHandle( | 22 mojo::MakeRequest<ViewportObserver>(mojo::ScopedMessagePipeHandle( |
23 mojo::MessagePipeHandle(viewportObserverHandle)))); | 23 mojo::MessagePipeHandle(viewportObserverHandle)))); |
24 return reinterpret_cast<jlong>(view); | 24 return reinterpret_cast<jlong>(view); |
25 } | 25 } |
26 | 26 |
27 // static | 27 // static |
28 bool PlatformView::Register(JNIEnv* env) { | 28 bool PlatformViewAndroid::Register(JNIEnv* env) { |
29 return RegisterNativesImpl(env); | 29 return RegisterNativesImpl(env); |
30 } | 30 } |
31 | 31 |
32 PlatformView::PlatformView(const Config& config) | 32 PlatformViewAndroid::~PlatformViewAndroid() { |
33 : config_(config), window_(nullptr) { | |
34 } | |
35 | |
36 PlatformView::~PlatformView() { | |
37 if (window_) | 33 if (window_) |
38 ReleaseWindow(); | 34 ReleaseWindow(); |
39 } | 35 } |
40 | 36 |
41 void PlatformView::ConnectToViewportObserver( | 37 void PlatformViewAndroid::Detach(JNIEnv* env, jobject obj) { |
42 mojo::InterfaceRequest<ViewportObserver> request) { | |
43 config_.ui_task_runner->PostTask( | |
44 FROM_HERE, | |
45 base::Bind(&UIDelegate::ConnectToViewportObserver, config_.ui_delegate, | |
46 base::Passed(&request))); | |
47 } | |
48 | |
49 void PlatformView::Detach(JNIEnv* env, jobject obj) { | |
50 DCHECK(!window_); | 38 DCHECK(!window_); |
51 } | 39 } |
52 | 40 |
53 void PlatformView::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurface) { | 41 void PlatformViewAndroid::SurfaceCreated(JNIEnv* env, jobject obj, jobject jsurf
ace) { |
54 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 42 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
55 // Note: This ensures that any local references used by | 43 // Note: This ensures that any local references used by |
56 // ANativeWindow_fromSurface are released immediately. This is needed as a | 44 // ANativeWindow_fromSurface are released immediately. This is needed as a |
57 // 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 |
58 { | 46 { |
59 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 47 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
60 window_ = ANativeWindow_fromSurface(env, jsurface); | 48 window_ = ANativeWindow_fromSurface(env, jsurface); |
61 } | 49 } |
62 config_.ui_task_runner->PostTask( | 50 SurfaceWasCreated(); |
63 FROM_HERE, base::Bind(&UIDelegate::OnAcceleratedWidgetAvailable, | |
64 config_.ui_delegate, window_)); | |
65 } | 51 } |
66 | 52 |
67 void PlatformView::SurfaceDestroyed(JNIEnv* env, jobject obj) { | 53 void PlatformViewAndroid::SurfaceDestroyed(JNIEnv* env, jobject obj) { |
68 DCHECK(window_); | 54 DCHECK(window_); |
69 config_.ui_task_runner->PostTask( | 55 SurfaceWasDestroyed(); |
70 FROM_HERE, | |
71 base::Bind(&UIDelegate::OnOutputSurfaceDestroyed, config_.ui_delegate)); | |
72 ReleaseWindow(); | 56 ReleaseWindow(); |
73 } | 57 } |
74 | 58 |
75 void PlatformView::ReleaseWindow() { | 59 void PlatformViewAndroid::ReleaseWindow() { |
76 ANativeWindow_release(window_); | 60 ANativeWindow_release(window_); |
77 window_ = nullptr; | 61 window_ = nullptr; |
78 } | 62 } |
79 | 63 |
80 } // namespace shell | 64 } // namespace shell |
81 } // namespace sky | 65 } // namespace sky |
OLD | NEW |