OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "services/native_viewport/platform_viewport_android.h" | 5 #include "services/native_viewport/platform_viewport_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 "jni/PlatformViewportAndroid_jni.h" | 11 #include "jni/PlatformViewportAndroid_jni.h" |
12 #include "mojo/converters/geometry/geometry_type_converters.h" | 12 #include "mojo/converters/geometry/geometry_type_converters.h" |
13 #include "mojo/converters/input_events/input_events_type_converters.h" | 13 #include "mojo/converters/input_events/input_events_type_converters.h" |
14 #include "mojo/public/cpp/application/application_impl.h" | |
15 #include "services/native_viewport/native_viewport_internal.mojom.h" | |
14 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
15 #include "ui/events/keycodes/keyboard_code_conversion_android.h" | 17 #include "ui/events/keycodes/keyboard_code_conversion_android.h" |
16 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
17 | 19 |
18 namespace native_viewport { | 20 namespace native_viewport { |
19 namespace { | 21 namespace { |
20 | 22 |
21 mojo::EventType MotionEventActionToEventType(jint action) { | 23 mojo::EventType MotionEventActionToEventType(jint action) { |
22 switch (action) { | 24 switch (action) { |
23 case AMOTION_EVENT_ACTION_DOWN: | 25 case AMOTION_EVENT_ACTION_DOWN: |
(...skipping 20 matching lines...) Expand all Loading... | |
44 } // namespace | 46 } // namespace |
45 | 47 |
46 //////////////////////////////////////////////////////////////////////////////// | 48 //////////////////////////////////////////////////////////////////////////////// |
47 // PlatformViewportAndroid, public: | 49 // PlatformViewportAndroid, public: |
48 | 50 |
49 // static | 51 // static |
50 bool PlatformViewportAndroid::Register(JNIEnv* env) { | 52 bool PlatformViewportAndroid::Register(JNIEnv* env) { |
51 return RegisterNativesImpl(env); | 53 return RegisterNativesImpl(env); |
52 } | 54 } |
53 | 55 |
54 PlatformViewportAndroid::PlatformViewportAndroid(Delegate* delegate) | 56 PlatformViewportAndroid::PlatformViewportAndroid( |
55 : delegate_(delegate), | 57 mojo::ApplicationImpl* application, |
58 Delegate* delegate) | |
59 : application_(application), | |
60 delegate_(delegate), | |
56 window_(NULL), | 61 window_(NULL), |
57 id_generator_(0), | 62 id_generator_(0), |
58 weak_factory_(this) { | 63 weak_factory_(this) {} |
59 } | |
60 | 64 |
61 PlatformViewportAndroid::~PlatformViewportAndroid() { | 65 PlatformViewportAndroid::~PlatformViewportAndroid() { |
62 if (window_) | 66 if (window_) |
63 ReleaseWindow(); | 67 ReleaseWindow(); |
68 JNIEnv* env = base::android::AttachCurrentThread(); | |
64 if (!java_platform_viewport_android_.is_empty()) { | 69 if (!java_platform_viewport_android_.is_empty()) { |
65 JNIEnv* env = base::android::AttachCurrentThread(); | |
66 Java_PlatformViewportAndroid_detach( | 70 Java_PlatformViewportAndroid_detach( |
67 env, java_platform_viewport_android_.get(env).obj()); | 71 env, java_platform_viewport_android_.get(env).obj()); |
72 } else { | |
73 Java_PlatformViewportAndroid_withdrawRequest(env, | |
74 reinterpret_cast<jlong>(this)); | |
qsr
2015/08/07 14:09:39
reinterpret_cast should be to intptr_t, here and e
etiennej
2015/08/07 14:15:40
Done.
| |
68 } | 75 } |
69 } | 76 } |
70 | 77 |
71 void PlatformViewportAndroid::Destroy(JNIEnv* env, jobject obj) { | 78 void PlatformViewportAndroid::Destroy(JNIEnv* env, jobject obj) { |
72 delegate_->OnDestroyed(); | 79 delegate_->OnDestroyed(); |
73 } | 80 } |
74 | 81 |
82 void PlatformViewportAndroid::SurfaceAttached(JNIEnv* env, | |
83 jobject obj, | |
84 jobject platform_viewport) { | |
85 java_platform_viewport_android_ = | |
86 JavaObjectWeakGlobalRef(env, platform_viewport); | |
87 } | |
88 | |
75 void PlatformViewportAndroid::SurfaceCreated(JNIEnv* env, | 89 void PlatformViewportAndroid::SurfaceCreated(JNIEnv* env, |
76 jobject obj, | 90 jobject obj, |
77 jobject jsurface) { | 91 jobject jsurface) { |
78 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); | 92 base::android::ScopedJavaLocalRef<jobject> protector(env, jsurface); |
79 // Note: This ensures that any local references used by | 93 // Note: This ensures that any local references used by |
80 // ANativeWindow_fromSurface are released immediately. This is needed as a | 94 // ANativeWindow_fromSurface are released immediately. This is needed as a |
81 // workaround for https://code.google.com/p/android/issues/detail?id=68174 | 95 // workaround for https://code.google.com/p/android/issues/detail?id=68174 |
82 { | 96 { |
83 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 97 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
84 window_ = ANativeWindow_fromSurface(env, jsurface); | 98 window_ = ANativeWindow_fromSurface(env, jsurface); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 delegate_->OnEvent(event.Pass()); | 155 delegate_->OnEvent(event.Pass()); |
142 | 156 |
143 return true; | 157 return true; |
144 } | 158 } |
145 | 159 |
146 //////////////////////////////////////////////////////////////////////////////// | 160 //////////////////////////////////////////////////////////////////////////////// |
147 // PlatformViewportAndroid, PlatformViewport implementation: | 161 // PlatformViewportAndroid, PlatformViewport implementation: |
148 | 162 |
149 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { | 163 void PlatformViewportAndroid::Init(const gfx::Rect& bounds) { |
150 JNIEnv* env = base::android::AttachCurrentThread(); | 164 JNIEnv* env = base::android::AttachCurrentThread(); |
151 java_platform_viewport_android_ = JavaObjectWeakGlobalRef( | 165 Java_PlatformViewportAndroid_createRequest(env, |
152 env, | 166 reinterpret_cast<jlong>(this)); |
153 Java_PlatformViewportAndroid_create(env, reinterpret_cast<jlong>(this)) | 167 |
154 .obj()); | 168 NativeViewportShellServicePtr shell_service; |
169 application_->ConnectToService("mojo:native_viewport_support", | |
170 &shell_service); | |
171 shell_service->CreateNewNativeWindow(); | |
155 } | 172 } |
156 | 173 |
157 void PlatformViewportAndroid::Show() { | 174 void PlatformViewportAndroid::Show() { |
158 // Nothing to do. View is created visible. | 175 // Nothing to do. View is created visible. |
159 } | 176 } |
160 | 177 |
161 void PlatformViewportAndroid::Hide() { | 178 void PlatformViewportAndroid::Hide() { |
162 // Nothing to do. View is always visible. | 179 // Nothing to do. View is always visible. |
163 } | 180 } |
164 | 181 |
(...skipping 17 matching lines...) Expand all Loading... | |
182 | 199 |
183 void PlatformViewportAndroid::ReleaseWindow() { | 200 void PlatformViewportAndroid::ReleaseWindow() { |
184 ANativeWindow_release(window_); | 201 ANativeWindow_release(window_); |
185 window_ = NULL; | 202 window_ = NULL; |
186 } | 203 } |
187 | 204 |
188 //////////////////////////////////////////////////////////////////////////////// | 205 //////////////////////////////////////////////////////////////////////////////// |
189 // PlatformViewport, public: | 206 // PlatformViewport, public: |
190 | 207 |
191 // static | 208 // static |
192 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 209 scoped_ptr<PlatformViewport> PlatformViewport::Create( |
210 mojo::ApplicationImpl* application_, | |
211 Delegate* delegate) { | |
193 return scoped_ptr<PlatformViewport>( | 212 return scoped_ptr<PlatformViewport>( |
194 new PlatformViewportAndroid(delegate)).Pass(); | 213 new PlatformViewportAndroid(application_, delegate)) |
214 .Pass(); | |
195 } | 215 } |
196 | 216 |
197 } // namespace native_viewport | 217 } // namespace native_viewport |
OLD | NEW |