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