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_contents_display.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/render_widget/blimp_document_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/BlimpContentsDisplay_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 |
24 namespace blimp { | 24 namespace blimp { |
25 namespace client { | 25 namespace client { |
26 namespace app { | 26 namespace app { |
27 | 27 |
28 static jlong Init( | 28 static jlong Init( |
29 JNIEnv* env, | 29 JNIEnv* env, |
30 const base::android::JavaParamRef<jobject>& jobj, | 30 const base::android::JavaParamRef<jobject>& jobj, |
31 const base::android::JavaParamRef<jobject>& blimp_client_session, | 31 const base::android::JavaParamRef<jobject>& blimp_client_session, |
32 jint real_width, | 32 jint real_width, |
33 jint real_height, | 33 jint real_height, |
34 jint width, | 34 jint width, |
35 jint height, | 35 jint height, |
36 jfloat dp_to_px) { | 36 jfloat dp_to_px) { |
37 BlimpClientSession* client_session = | 37 BlimpClientSession* client_session = |
38 BlimpClientSessionAndroid::FromJavaObject(env, blimp_client_session); | 38 BlimpClientSessionAndroid::FromJavaObject(env, blimp_client_session); |
39 | 39 |
40 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and | 40 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and |
41 // pass it through to the BlimpCompositor. | 41 // pass it through to the BlimpCompositor. |
42 ALLOW_UNUSED_LOCAL(client_session); | 42 ALLOW_UNUSED_LOCAL(client_session); |
43 | 43 |
44 return reinterpret_cast<intptr_t>(new BlimpView( | 44 return reinterpret_cast<intptr_t>(new BlimpContentsDisplay( |
45 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), |
46 dp_to_px, client_session->GetRenderWidgetFeature())); | 46 dp_to_px, client_session->GetRenderWidgetFeature())); |
47 } | 47 } |
48 | 48 |
49 // static | 49 // static |
50 bool BlimpView::RegisterJni(JNIEnv* env) { | 50 bool BlimpContentsDisplay::RegisterJni(JNIEnv* env) { |
51 return RegisterNativesImpl(env); | 51 return RegisterNativesImpl(env); |
52 } | 52 } |
53 | 53 |
54 BlimpView::BlimpView(JNIEnv* env, | 54 BlimpContentsDisplay::BlimpContentsDisplay( |
55 const base::android::JavaParamRef<jobject>& jobj, | 55 JNIEnv* env, |
56 const gfx::Size& real_size, | 56 const base::android::JavaParamRef<jobject>& jobj, |
57 const gfx::Size& size, | 57 const gfx::Size& real_size, |
58 float dp_to_px, | 58 const gfx::Size& size, |
59 blimp::client::RenderWidgetFeature* render_widget_feature) | 59 float dp_to_px, |
| 60 blimp::client::RenderWidgetFeature* render_widget_feature) |
60 : device_scale_factor_(dp_to_px), | 61 : device_scale_factor_(dp_to_px), |
61 current_surface_format_(0), | 62 current_surface_format_(0), |
62 window_(gfx::kNullAcceleratedWidget), | 63 window_(gfx::kNullAcceleratedWidget), |
63 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
64 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( | 65 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>( |
65 base::MakeUnique<CompositorDependenciesImpl>()); | 66 base::MakeUnique<CompositorDependenciesImpl>()); |
66 | 67 |
67 compositor_ = base::MakeUnique<BrowserCompositor>( | 68 compositor_ = base::MakeUnique<BrowserCompositor>( |
68 compositor_dependencies_->GetEmbedderDependencies()); | 69 compositor_dependencies_->GetEmbedderDependencies()); |
69 compositor_->set_did_complete_swap_buffers_callback(base::Bind( | 70 compositor_->set_did_complete_swap_buffers_callback( |
70 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr())); | 71 base::Bind(&BlimpContentsDisplay::OnSwapBuffersCompleted, |
| 72 weak_ptr_factory_.GetWeakPtr())); |
71 | 73 |
72 document_manager_ = base::MakeUnique<BlimpDocumentManager>( | 74 document_manager_ = base::MakeUnique<BlimpDocumentManager>( |
73 kDummyBlimpContentsId, render_widget_feature, | 75 kDummyBlimpContentsId, render_widget_feature, |
74 compositor_dependencies_.get()); | 76 compositor_dependencies_.get()); |
75 compositor_->SetContentLayer(document_manager_->layer()); | 77 compositor_->SetContentLayer(document_manager_->layer()); |
76 | 78 |
77 java_obj_.Reset(env, jobj); | 79 java_obj_.Reset(env, jobj); |
78 } | 80 } |
79 | 81 |
80 BlimpView::~BlimpView() { | 82 BlimpContentsDisplay::~BlimpContentsDisplay() { |
81 SetSurface(nullptr); | 83 SetSurface(nullptr); |
82 | 84 |
83 // Destroy the BrowserCompositor and the BlimpCompositorManager before the | 85 // Destroy the BrowserCompositor and the BlimpCompositorManager before the |
84 // BlimpCompositorDependencies. | 86 // BlimpCompositorDependencies. |
85 compositor_.reset(); | 87 compositor_.reset(); |
86 document_manager_.reset(); | 88 document_manager_.reset(); |
87 compositor_dependencies_.reset(); | 89 compositor_dependencies_.reset(); |
88 } | 90 } |
89 | 91 |
90 void BlimpView::Destroy(JNIEnv* env, | 92 void BlimpContentsDisplay::Destroy( |
91 const base::android::JavaParamRef<jobject>& jobj) { | 93 JNIEnv* env, |
| 94 const base::android::JavaParamRef<jobject>& jobj) { |
92 delete this; | 95 delete this; |
93 } | 96 } |
94 | 97 |
95 void BlimpView::OnContentAreaSizeChanged( | 98 void BlimpContentsDisplay::OnContentAreaSizeChanged( |
96 JNIEnv* env, | 99 JNIEnv* env, |
97 const base::android::JavaParamRef<jobject>& jobj, | 100 const base::android::JavaParamRef<jobject>& jobj, |
98 jint width, | 101 jint width, |
99 jint height, | 102 jint height, |
100 jfloat dpToPx) { | 103 jfloat dpToPx) { |
101 compositor_->SetSize(gfx::Size(width, height)); | 104 compositor_->SetSize(gfx::Size(width, height)); |
102 } | 105 } |
103 | 106 |
104 void BlimpView::OnSurfaceChanged( | 107 void BlimpContentsDisplay::OnSurfaceChanged( |
105 JNIEnv* env, | 108 JNIEnv* env, |
106 const base::android::JavaParamRef<jobject>& jobj, | 109 const base::android::JavaParamRef<jobject>& jobj, |
107 jint format, | 110 jint format, |
108 jint width, | 111 jint width, |
109 jint height, | 112 jint height, |
110 const base::android::JavaParamRef<jobject>& jsurface) { | 113 const base::android::JavaParamRef<jobject>& jsurface) { |
111 if (current_surface_format_ != format) { | 114 if (current_surface_format_ != format) { |
112 current_surface_format_ = format; | 115 current_surface_format_ = format; |
113 SetSurface(nullptr); | 116 SetSurface(nullptr); |
114 | 117 |
115 if (jsurface) { | 118 if (jsurface) { |
116 SetSurface(jsurface); | 119 SetSurface(jsurface); |
117 } | 120 } |
118 } | 121 } |
119 } | 122 } |
120 | 123 |
121 void BlimpView::OnSurfaceCreated( | 124 void BlimpContentsDisplay::OnSurfaceCreated( |
122 JNIEnv* env, | 125 JNIEnv* env, |
123 const base::android::JavaParamRef<jobject>& jobj) { | 126 const base::android::JavaParamRef<jobject>& jobj) { |
124 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 127 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
125 } | 128 } |
126 | 129 |
127 void BlimpView::OnSurfaceDestroyed( | 130 void BlimpContentsDisplay::OnSurfaceDestroyed( |
128 JNIEnv* env, | 131 JNIEnv* env, |
129 const base::android::JavaParamRef<jobject>& jobj) { | 132 const base::android::JavaParamRef<jobject>& jobj) { |
130 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 133 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
131 SetSurface(nullptr); | 134 SetSurface(nullptr); |
132 } | 135 } |
133 | 136 |
134 void BlimpView::SetSurface(jobject surface) { | 137 void BlimpContentsDisplay::SetSurface(jobject surface) { |
135 JNIEnv* env = base::android::AttachCurrentThread(); | 138 JNIEnv* env = base::android::AttachCurrentThread(); |
136 // Release all references to the old surface. | 139 // Release all references to the old surface. |
137 if (window_ != gfx::kNullAcceleratedWidget) { | 140 if (window_ != gfx::kNullAcceleratedWidget) { |
138 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | 141 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
139 document_manager_->SetVisible(false); | 142 document_manager_->SetVisible(false); |
140 ANativeWindow_release(window_); | 143 ANativeWindow_release(window_); |
141 window_ = gfx::kNullAcceleratedWidget; | 144 window_ = gfx::kNullAcceleratedWidget; |
142 } | 145 } |
143 | 146 |
144 if (surface) { | 147 if (surface) { |
145 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 148 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
146 window_ = ANativeWindow_fromSurface(env, surface); | 149 window_ = ANativeWindow_fromSurface(env, surface); |
147 compositor_->SetAcceleratedWidget(window_); | 150 compositor_->SetAcceleratedWidget(window_); |
148 document_manager_->SetVisible(true); | 151 document_manager_->SetVisible(true); |
149 } | 152 } |
150 } | 153 } |
151 | 154 |
152 jboolean BlimpView::OnTouchEvent( | 155 jboolean BlimpContentsDisplay::OnTouchEvent( |
153 JNIEnv* env, | 156 JNIEnv* env, |
154 const base::android::JavaParamRef<jobject>& obj, | 157 const base::android::JavaParamRef<jobject>& obj, |
155 const base::android::JavaParamRef<jobject>& motion_event, | 158 const base::android::JavaParamRef<jobject>& motion_event, |
156 jlong time_ms, | 159 jlong time_ms, |
157 jint android_action, | 160 jint android_action, |
158 jint pointer_count, | 161 jint pointer_count, |
159 jint history_size, | 162 jint history_size, |
160 jint action_index, | 163 jint action_index, |
161 jfloat pos_x_0, | 164 jfloat pos_x_0, |
162 jfloat pos_y_0, | 165 jfloat pos_y_0, |
163 jfloat pos_x_1, | 166 jfloat pos_x_1, |
164 jfloat pos_y_1, | 167 jfloat pos_y_1, |
165 jint pointer_id_0, | 168 jint pointer_id_0, |
166 jint pointer_id_1, | 169 jint pointer_id_1, |
167 jfloat touch_major_0, | 170 jfloat touch_major_0, |
168 jfloat touch_major_1, | 171 jfloat touch_major_1, |
169 jfloat touch_minor_0, | 172 jfloat touch_minor_0, |
170 jfloat touch_minor_1, | 173 jfloat touch_minor_1, |
171 jfloat orientation_0, | 174 jfloat orientation_0, |
172 jfloat orientation_1, | 175 jfloat orientation_1, |
173 jfloat tilt_0, | 176 jfloat tilt_0, |
174 jfloat tilt_1, | 177 jfloat tilt_1, |
175 jfloat raw_pos_x, | 178 jfloat raw_pos_x, |
176 jfloat raw_pos_y, | 179 jfloat raw_pos_y, |
177 jint android_tool_type_0, | 180 jint android_tool_type_0, |
178 jint android_tool_type_1, | 181 jint android_tool_type_1, |
179 jint android_button_state, | 182 jint android_button_state, |
180 jint android_meta_state) { | 183 jint android_meta_state) { |
181 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0, | 184 ui::MotionEventAndroid::Pointer pointer0( |
182 pos_x_0, | 185 pointer_id_0, pos_x_0, pos_y_0, touch_major_0, touch_minor_0, |
183 pos_y_0, | 186 orientation_0, tilt_0, android_tool_type_0); |
184 touch_major_0, | 187 ui::MotionEventAndroid::Pointer pointer1( |
185 touch_minor_0, | 188 pointer_id_1, pos_x_1, pos_y_1, touch_major_1, touch_minor_1, |
186 orientation_0, | 189 orientation_1, tilt_1, android_tool_type_1); |
187 tilt_0, | 190 ui::MotionEventAndroid event(1.f / device_scale_factor_, env, motion_event, |
188 android_tool_type_0); | 191 time_ms, android_action, pointer_count, |
189 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1, | 192 history_size, action_index, android_button_state, |
190 pos_x_1, | 193 android_meta_state, raw_pos_x - pos_x_0, |
191 pos_y_1, | 194 raw_pos_y - pos_y_0, &pointer0, &pointer1); |
192 touch_major_1, | |
193 touch_minor_1, | |
194 orientation_1, | |
195 tilt_1, | |
196 android_tool_type_1); | |
197 ui::MotionEventAndroid event(1.f / device_scale_factor_, | |
198 env, | |
199 motion_event, | |
200 time_ms, | |
201 android_action, | |
202 pointer_count, | |
203 history_size, | |
204 action_index, | |
205 android_button_state, | |
206 android_meta_state, | |
207 raw_pos_x - pos_x_0, | |
208 raw_pos_y - pos_y_0, | |
209 &pointer0, | |
210 &pointer1); | |
211 | 195 |
212 return document_manager_->OnTouchEvent(event); | 196 return document_manager_->OnTouchEvent(event); |
213 } | 197 } |
214 | 198 |
215 void BlimpView::OnSwapBuffersCompleted() { | 199 void BlimpContentsDisplay::OnSwapBuffersCompleted() { |
216 JNIEnv* env = base::android::AttachCurrentThread(); | 200 JNIEnv* env = base::android::AttachCurrentThread(); |
217 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); | 201 Java_BlimpContentsDisplay_onSwapBuffersCompleted(env, java_obj_); |
218 } | 202 } |
219 | 203 |
220 } // namespace app | 204 } // namespace app |
221 } // namespace client | 205 } // namespace client |
222 } // namespace blimp | 206 } // namespace blimp |
OLD | NEW |