| 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/render_widget/blimp_document_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 namespace { | 20 namespace { |
| 21 const int kDummyBlimpContentsId = 0; | 21 const int kDummyBlimpContentsId = 0; |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 window_(gfx::kNullAcceleratedWidget), | 62 window_(gfx::kNullAcceleratedWidget), |
| 63 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
| 64 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | 64 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( |
| 65 base::MakeUnique<CompositorDependenciesImpl>()); | 65 base::MakeUnique<CompositorDependenciesImpl>()); |
| 66 | 66 |
| 67 compositor_ = base::MakeUnique<BrowserCompositor>( | 67 compositor_ = base::MakeUnique<BrowserCompositor>( |
| 68 compositor_dependencies_->GetEmbedderDependencies()); | 68 compositor_dependencies_->GetEmbedderDependencies()); |
| 69 compositor_->set_did_complete_swap_buffers_callback(base::Bind( | 69 compositor_->set_did_complete_swap_buffers_callback(base::Bind( |
| 70 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr())); | 70 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr())); |
| 71 | 71 |
| 72 compositor_manager_ = base::MakeUnique<BlimpCompositorManager>( | 72 document_manager_ = base::MakeUnique<BlimpDocumentManager>( |
| 73 kDummyBlimpContentsId, render_widget_feature, | 73 kDummyBlimpContentsId, render_widget_feature, |
| 74 compositor_dependencies_.get()); | 74 compositor_dependencies_.get()); |
| 75 compositor_->SetContentLayer(compositor_manager_->layer()); | 75 compositor_->SetContentLayer(document_manager_->layer()); |
| 76 | 76 |
| 77 java_obj_.Reset(env, jobj); | 77 java_obj_.Reset(env, jobj); |
| 78 } | 78 } |
| 79 | 79 |
| 80 BlimpView::~BlimpView() { | 80 BlimpView::~BlimpView() { |
| 81 SetSurface(nullptr); | 81 SetSurface(nullptr); |
| 82 | 82 |
| 83 // Destroy the BrowserCompositor and the BlimpCompositorManager before the | 83 // Destroy the BrowserCompositor and the BlimpCompositorManager before the |
| 84 // BlimpCompositorDependencies. | 84 // BlimpCompositorDependencies. |
| 85 compositor_.reset(); | 85 compositor_.reset(); |
| 86 compositor_manager_.reset(); | 86 document_manager_.reset(); |
| 87 compositor_dependencies_.reset(); | 87 compositor_dependencies_.reset(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void BlimpView::Destroy(JNIEnv* env, | 90 void BlimpView::Destroy(JNIEnv* env, |
| 91 const base::android::JavaParamRef<jobject>& jobj) { | 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, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 const base::android::JavaParamRef<jobject>& jobj) { | 129 const base::android::JavaParamRef<jobject>& jobj) { |
| 130 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 130 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
| 131 SetSurface(nullptr); | 131 SetSurface(nullptr); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void BlimpView::SetSurface(jobject surface) { | 134 void BlimpView::SetSurface(jobject surface) { |
| 135 JNIEnv* env = base::android::AttachCurrentThread(); | 135 JNIEnv* env = base::android::AttachCurrentThread(); |
| 136 // Release all references to the old surface. | 136 // Release all references to the old surface. |
| 137 if (window_ != gfx::kNullAcceleratedWidget) { | 137 if (window_ != gfx::kNullAcceleratedWidget) { |
| 138 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 138 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 139 compositor_manager_->SetVisible(false); | 139 document_manager_->SetVisible(false); |
| 140 ANativeWindow_release(window_); | 140 ANativeWindow_release(window_); |
| 141 window_ = gfx::kNullAcceleratedWidget; | 141 window_ = gfx::kNullAcceleratedWidget; |
| 142 } | 142 } |
| 143 | 143 |
| 144 if (surface) { | 144 if (surface) { |
| 145 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 145 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
| 146 window_ = ANativeWindow_fromSurface(env, surface); | 146 window_ = ANativeWindow_fromSurface(env, surface); |
| 147 compositor_->SetAcceleratedWidget(window_); | 147 compositor_->SetAcceleratedWidget(window_); |
| 148 compositor_manager_->SetVisible(true); | 148 document_manager_->SetVisible(true); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 jboolean BlimpView::OnTouchEvent( | 152 jboolean BlimpView::OnTouchEvent( |
| 153 JNIEnv* env, | 153 JNIEnv* env, |
| 154 const base::android::JavaParamRef<jobject>& obj, | 154 const base::android::JavaParamRef<jobject>& obj, |
| 155 const base::android::JavaParamRef<jobject>& motion_event, | 155 const base::android::JavaParamRef<jobject>& motion_event, |
| 156 jlong time_ms, | 156 jlong time_ms, |
| 157 jint android_action, | 157 jint android_action, |
| 158 jint pointer_count, | 158 jint pointer_count, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 pointer_count, | 202 pointer_count, |
| 203 history_size, | 203 history_size, |
| 204 action_index, | 204 action_index, |
| 205 android_button_state, | 205 android_button_state, |
| 206 android_meta_state, | 206 android_meta_state, |
| 207 raw_pos_x - pos_x_0, | 207 raw_pos_x - pos_x_0, |
| 208 raw_pos_y - pos_y_0, | 208 raw_pos_y - pos_y_0, |
| 209 pointer0, | 209 pointer0, |
| 210 pointer1); | 210 pointer1); |
| 211 | 211 |
| 212 return compositor_manager_->OnTouchEvent(event); | 212 return document_manager_->OnTouchEvent(event); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void BlimpView::OnSwapBuffersCompleted() { | 215 void BlimpView::OnSwapBuffersCompleted() { |
| 216 JNIEnv* env = base::android::AttachCurrentThread(); | 216 JNIEnv* env = base::android::AttachCurrentThread(); |
| 217 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); | 217 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); |
| 218 } | 218 } |
| 219 | 219 |
| 220 } // namespace app | 220 } // namespace app |
| 221 } // namespace client | 221 } // namespace client |
| 222 } // namespace blimp | 222 } // namespace blimp |
| OLD | NEW |