| 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 "blimp/client/app/android/blimp_view.h" | 5 #include "blimp/client/app/android/blimp_view.h" |
| 6 | 6 |
| 7 #include <android/native_window_jni.h> | 7 #include <android/native_window_jni.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "blimp/client/app/android/blimp_client_session_android.h" | 10 #include "blimp/client/app/android/blimp_client_session_android.h" |
| 11 #include "blimp/client/app/compositor/browser_compositor.h" | 11 #include "blimp/client/app/compositor/browser_compositor.h" |
| 12 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" | 12 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h" |
| 13 #include "blimp/client/core/compositor/blimp_compositor_manager.h" | 13 #include "blimp/client/core/compositor/blimp_compositor_manager.h" |
| 14 #include "blimp/client/core/render_widget/render_widget_feature.h" | 14 #include "blimp/client/core/render_widget/render_widget_feature.h" |
| 15 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" | 15 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" |
| 16 #include "jni/BlimpView_jni.h" | 16 #include "jni/BlimpView_jni.h" |
| 17 #include "ui/events/android/motion_event_android.h" | 17 #include "ui/events/android/motion_event_android.h" |
| 18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 19 | 19 |
| 20 using base::android::JavaParamRef; | |
| 21 | |
| 22 namespace { | 20 namespace { |
| 23 const int kDummyBlimpContentsId = 0; | 21 const int kDummyBlimpContentsId = 0; |
| 24 } // namespace | 22 } // namespace |
| 25 | 23 |
| 26 namespace blimp { | 24 namespace blimp { |
| 27 namespace client { | 25 namespace client { |
| 28 namespace app { | 26 namespace app { |
| 29 | 27 |
| 30 static jlong Init(JNIEnv* env, | 28 static jlong Init( |
| 31 const JavaParamRef<jobject>& jobj, | 29 JNIEnv* env, |
| 32 const JavaParamRef<jobject>& blimp_client_session, | 30 const base::android::JavaParamRef<jobject>& jobj, |
| 33 jint real_width, | 31 const base::android::JavaParamRef<jobject>& blimp_client_session, |
| 34 jint real_height, | 32 jint real_width, |
| 35 jint width, | 33 jint real_height, |
| 36 jint height, | 34 jint width, |
| 37 jfloat dp_to_px) { | 35 jint height, |
| 36 jfloat dp_to_px) { |
| 38 BlimpClientSession* client_session = | 37 BlimpClientSession* client_session = |
| 39 BlimpClientSessionAndroid::FromJavaObject(env, blimp_client_session); | 38 BlimpClientSessionAndroid::FromJavaObject(env, blimp_client_session); |
| 40 | 39 |
| 41 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and | 40 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and |
| 42 // pass it through to the BlimpCompositor. | 41 // pass it through to the BlimpCompositor. |
| 43 ALLOW_UNUSED_LOCAL(client_session); | 42 ALLOW_UNUSED_LOCAL(client_session); |
| 44 | 43 |
| 45 return reinterpret_cast<intptr_t>(new BlimpView( | 44 return reinterpret_cast<intptr_t>(new BlimpView( |
| 46 env, jobj, gfx::Size(real_width, real_height), gfx::Size(width, height), | 45 env, jobj, gfx::Size(real_width, real_height), gfx::Size(width, height), |
| 47 dp_to_px, client_session->GetRenderWidgetFeature())); | 46 dp_to_px, client_session->GetRenderWidgetFeature())); |
| 48 } | 47 } |
| 49 | 48 |
| 50 // static | 49 // static |
| 51 bool BlimpView::RegisterJni(JNIEnv* env) { | 50 bool BlimpView::RegisterJni(JNIEnv* env) { |
| 52 return RegisterNativesImpl(env); | 51 return RegisterNativesImpl(env); |
| 53 } | 52 } |
| 54 | 53 |
| 55 BlimpView::BlimpView(JNIEnv* env, | 54 BlimpView::BlimpView(JNIEnv* env, |
| 56 const JavaParamRef<jobject>& jobj, | 55 const base::android::JavaParamRef<jobject>& jobj, |
| 57 const gfx::Size& real_size, | 56 const gfx::Size& real_size, |
| 58 const gfx::Size& size, | 57 const gfx::Size& size, |
| 59 float dp_to_px, | 58 float dp_to_px, |
| 60 blimp::client::RenderWidgetFeature* render_widget_feature) | 59 blimp::client::RenderWidgetFeature* render_widget_feature) |
| 61 : device_scale_factor_(dp_to_px), | 60 : device_scale_factor_(dp_to_px), |
| 62 current_surface_format_(0), | 61 current_surface_format_(0), |
| 63 window_(gfx::kNullAcceleratedWidget), | 62 window_(gfx::kNullAcceleratedWidget), |
| 64 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
| 65 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | 64 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( |
| 66 base::MakeUnique<CompositorDependenciesImpl>()); | 65 base::MakeUnique<CompositorDependenciesImpl>()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 81 BlimpView::~BlimpView() { | 80 BlimpView::~BlimpView() { |
| 82 SetSurface(nullptr); | 81 SetSurface(nullptr); |
| 83 | 82 |
| 84 // Destroy the BrowserCompositor and the BlimpCompositorManager before the | 83 // Destroy the BrowserCompositor and the BlimpCompositorManager before the |
| 85 // BlimpCompositorDependencies. | 84 // BlimpCompositorDependencies. |
| 86 compositor_.reset(); | 85 compositor_.reset(); |
| 87 compositor_manager_.reset(); | 86 compositor_manager_.reset(); |
| 88 compositor_dependencies_.reset(); | 87 compositor_dependencies_.reset(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 90 void BlimpView::Destroy(JNIEnv* env, |
| 91 const base::android::JavaParamRef<jobject>& jobj) { |
| 92 delete this; | 92 delete this; |
| 93 } | 93 } |
| 94 | 94 |
| 95 void BlimpView::OnContentAreaSizeChanged( | 95 void BlimpView::OnContentAreaSizeChanged( |
| 96 JNIEnv* env, | 96 JNIEnv* env, |
| 97 const base::android::JavaParamRef<jobject>& jobj, | 97 const base::android::JavaParamRef<jobject>& jobj, |
| 98 jint width, | 98 jint width, |
| 99 jint height, | 99 jint height, |
| 100 jfloat dpToPx) { | 100 jfloat dpToPx) { |
| 101 compositor_->SetSize(gfx::Size(width, height)); | 101 compositor_->SetSize(gfx::Size(width, height)); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void BlimpView::OnSurfaceChanged(JNIEnv* env, | 104 void BlimpView::OnSurfaceChanged( |
| 105 const JavaParamRef<jobject>& jobj, | 105 JNIEnv* env, |
| 106 jint format, | 106 const base::android::JavaParamRef<jobject>& jobj, |
| 107 jint width, | 107 jint format, |
| 108 jint height, | 108 jint width, |
| 109 const JavaParamRef<jobject>& jsurface) { | 109 jint height, |
| 110 const base::android::JavaParamRef<jobject>& jsurface) { |
| 110 if (current_surface_format_ != format) { | 111 if (current_surface_format_ != format) { |
| 111 current_surface_format_ = format; | 112 current_surface_format_ = format; |
| 112 SetSurface(nullptr); | 113 SetSurface(nullptr); |
| 113 | 114 |
| 114 if (jsurface) { | 115 if (jsurface) { |
| 115 SetSurface(jsurface); | 116 SetSurface(jsurface); |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 void BlimpView::OnSurfaceCreated(JNIEnv* env, | 121 void BlimpView::OnSurfaceCreated( |
| 121 const JavaParamRef<jobject>& jobj) { | 122 JNIEnv* env, |
| 123 const base::android::JavaParamRef<jobject>& jobj) { |
| 122 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 124 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
| 123 } | 125 } |
| 124 | 126 |
| 125 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, | 127 void BlimpView::OnSurfaceDestroyed( |
| 126 const JavaParamRef<jobject>& jobj) { | 128 JNIEnv* env, |
| 129 const base::android::JavaParamRef<jobject>& jobj) { |
| 127 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 130 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
| 128 SetSurface(nullptr); | 131 SetSurface(nullptr); |
| 129 } | 132 } |
| 130 | 133 |
| 131 void BlimpView::SetSurface(jobject surface) { | 134 void BlimpView::SetSurface(jobject surface) { |
| 132 JNIEnv* env = base::android::AttachCurrentThread(); | 135 JNIEnv* env = base::android::AttachCurrentThread(); |
| 133 // Release all references to the old surface. | 136 // Release all references to the old surface. |
| 134 if (window_ != gfx::kNullAcceleratedWidget) { | 137 if (window_ != gfx::kNullAcceleratedWidget) { |
| 135 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 138 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 136 compositor_manager_->SetVisible(false); | 139 compositor_manager_->SetVisible(false); |
| 137 ANativeWindow_release(window_); | 140 ANativeWindow_release(window_); |
| 138 window_ = gfx::kNullAcceleratedWidget; | 141 window_ = gfx::kNullAcceleratedWidget; |
| 139 } | 142 } |
| 140 | 143 |
| 141 if (surface) { | 144 if (surface) { |
| 142 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 145 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 143 window_ = ANativeWindow_fromSurface(env, surface); | 146 window_ = ANativeWindow_fromSurface(env, surface); |
| 144 compositor_->SetAcceleratedWidget(window_); | 147 compositor_->SetAcceleratedWidget(window_); |
| 145 compositor_manager_->SetVisible(true); | 148 compositor_manager_->SetVisible(true); |
| 146 } | 149 } |
| 147 } | 150 } |
| 148 | 151 |
| 149 jboolean BlimpView::OnTouchEvent(JNIEnv* env, | 152 jboolean BlimpView::OnTouchEvent( |
| 150 const JavaParamRef<jobject>& obj, | 153 JNIEnv* env, |
| 151 const JavaParamRef<jobject>& motion_event, | 154 const base::android::JavaParamRef<jobject>& obj, |
| 152 jlong time_ms, | 155 const base::android::JavaParamRef<jobject>& motion_event, |
| 153 jint android_action, | 156 jlong time_ms, |
| 154 jint pointer_count, | 157 jint android_action, |
| 155 jint history_size, | 158 jint pointer_count, |
| 156 jint action_index, | 159 jint history_size, |
| 157 jfloat pos_x_0, | 160 jint action_index, |
| 158 jfloat pos_y_0, | 161 jfloat pos_x_0, |
| 159 jfloat pos_x_1, | 162 jfloat pos_y_0, |
| 160 jfloat pos_y_1, | 163 jfloat pos_x_1, |
| 161 jint pointer_id_0, | 164 jfloat pos_y_1, |
| 162 jint pointer_id_1, | 165 jint pointer_id_0, |
| 163 jfloat touch_major_0, | 166 jint pointer_id_1, |
| 164 jfloat touch_major_1, | 167 jfloat touch_major_0, |
| 165 jfloat touch_minor_0, | 168 jfloat touch_major_1, |
| 166 jfloat touch_minor_1, | 169 jfloat touch_minor_0, |
| 167 jfloat orientation_0, | 170 jfloat touch_minor_1, |
| 168 jfloat orientation_1, | 171 jfloat orientation_0, |
| 169 jfloat tilt_0, | 172 jfloat orientation_1, |
| 170 jfloat tilt_1, | 173 jfloat tilt_0, |
| 171 jfloat raw_pos_x, | 174 jfloat tilt_1, |
| 172 jfloat raw_pos_y, | 175 jfloat raw_pos_x, |
| 173 jint android_tool_type_0, | 176 jfloat raw_pos_y, |
| 174 jint android_tool_type_1, | 177 jint android_tool_type_0, |
| 175 jint android_button_state, | 178 jint android_tool_type_1, |
| 176 jint android_meta_state) { | 179 jint android_button_state, |
| 180 jint android_meta_state) { |
| 177 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0, | 181 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0, |
| 178 pos_x_0, | 182 pos_x_0, |
| 179 pos_y_0, | 183 pos_y_0, |
| 180 touch_major_0, | 184 touch_major_0, |
| 181 touch_minor_0, | 185 touch_minor_0, |
| 182 orientation_0, | 186 orientation_0, |
| 183 tilt_0, | 187 tilt_0, |
| 184 android_tool_type_0); | 188 android_tool_type_0); |
| 185 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1, | 189 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1, |
| 186 pos_x_1, | 190 pos_x_1, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 209 } | 213 } |
| 210 | 214 |
| 211 void BlimpView::OnSwapBuffersCompleted() { | 215 void BlimpView::OnSwapBuffersCompleted() { |
| 212 JNIEnv* env = base::android::AttachCurrentThread(); | 216 JNIEnv* env = base::android::AttachCurrentThread(); |
| 213 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); | 217 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); |
| 214 } | 218 } |
| 215 | 219 |
| 216 } // namespace app | 220 } // namespace app |
| 217 } // namespace client | 221 } // namespace client |
| 218 } // namespace blimp | 222 } // namespace blimp |
| OLD | NEW |