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