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 "blimp/client/app/android/blimp_client_session_android.h" | 9 #include "blimp/client/app/android/blimp_client_session_android.h" |
| 10 #include "blimp/client/core/contents/blimp_contents_impl.h" |
| 11 #include "blimp/client/core/render_widget/blimp_render_widget.h" |
10 #include "blimp/net/blimp_stats.h" | 12 #include "blimp/net/blimp_stats.h" |
11 #include "jni/BlimpView_jni.h" | 13 #include "jni/BlimpView_jni.h" |
12 #include "ui/events/android/motion_event_android.h" | 14 #include "ui/events/android/motion_event_android.h" |
13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
14 | 16 |
15 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
16 | 18 |
17 namespace blimp { | 19 namespace blimp { |
18 namespace client { | 20 namespace client { |
19 | 21 |
(...skipping 23 matching lines...) Expand all Loading... |
43 return RegisterNativesImpl(env); | 45 return RegisterNativesImpl(env); |
44 } | 46 } |
45 | 47 |
46 BlimpView::BlimpView(JNIEnv* env, | 48 BlimpView::BlimpView(JNIEnv* env, |
47 const JavaParamRef<jobject>& jobj, | 49 const JavaParamRef<jobject>& jobj, |
48 const gfx::Size& real_size, | 50 const gfx::Size& real_size, |
49 const gfx::Size& size, | 51 const gfx::Size& size, |
50 float dp_to_px, | 52 float dp_to_px, |
51 RenderWidgetFeature* render_widget_feature) | 53 RenderWidgetFeature* render_widget_feature) |
52 : device_scale_factor_(dp_to_px), | 54 : device_scale_factor_(dp_to_px), |
53 compositor_manager_( | 55 blimp_contents_manager_(render_widget_feature), |
54 BlimpCompositorManagerAndroid::Create(real_size, | |
55 size, | |
56 render_widget_feature, | |
57 this)), | |
58 current_surface_format_(0), | 56 current_surface_format_(0), |
59 window_(gfx::kNullAcceleratedWidget) { | 57 window_(gfx::kNullAcceleratedWidget), |
| 58 weak_ptr_factory_(this) { |
60 java_obj_.Reset(env, jobj); | 59 java_obj_.Reset(env, jobj); |
| 60 |
| 61 blimp_contents_ = blimp_contents_manager_.CreateBlimpContents(); |
| 62 |
| 63 blimp_contents_->set_did_complete_swap_buffers_callback(base::Bind( |
| 64 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr())); |
61 } | 65 } |
62 | 66 |
63 BlimpView::~BlimpView() { | 67 BlimpView::~BlimpView() { |
64 ReleaseAcceleratedWidget(); | 68 ReleaseAcceleratedWidget(); |
65 } | 69 } |
66 | 70 |
67 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 71 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
68 delete this; | 72 delete this; |
69 } | 73 } |
70 | 74 |
71 void BlimpView::SetNeedsComposite(JNIEnv* env, | 75 void BlimpView::SetNeedsComposite(JNIEnv* env, |
72 const JavaParamRef<jobject>& jobj) {} | 76 const JavaParamRef<jobject>& jobj) {} |
73 | 77 |
74 void BlimpView::OnSurfaceChanged(JNIEnv* env, | 78 void BlimpView::OnSurfaceChanged(JNIEnv* env, |
75 const JavaParamRef<jobject>& jobj, | 79 const JavaParamRef<jobject>& jobj, |
76 jint format, | 80 jint format, |
77 jint width, | 81 jint width, |
78 jint height, | 82 jint height, |
79 const JavaParamRef<jobject>& jsurface) { | 83 const JavaParamRef<jobject>& jsurface) { |
80 if (current_surface_format_ != format) { | 84 if (current_surface_format_ != format) { |
81 current_surface_format_ = format; | 85 current_surface_format_ = format; |
82 ReleaseAcceleratedWidget(); | 86 ReleaseAcceleratedWidget(); |
83 | 87 |
84 if (jsurface) { | 88 if (jsurface) { |
85 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 89 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
86 window_ = ANativeWindow_fromSurface(env, jsurface); | 90 window_ = ANativeWindow_fromSurface(env, jsurface); |
87 compositor_manager_->SetAcceleratedWidget(window_); | 91 blimp_contents_->SetAcceleratedWidget(window_); |
88 compositor_manager_->SetVisible(true); | 92 blimp_contents_->SetVisible(true); |
89 } | 93 } |
90 } | 94 } |
91 } | 95 } |
92 | 96 |
93 void BlimpView::OnSurfaceCreated(JNIEnv* env, | 97 void BlimpView::OnSurfaceCreated(JNIEnv* env, |
94 const JavaParamRef<jobject>& jobj) { | 98 const JavaParamRef<jobject>& jobj) { |
95 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 99 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
96 } | 100 } |
97 | 101 |
98 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, | 102 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, |
99 const JavaParamRef<jobject>& jobj) { | 103 const JavaParamRef<jobject>& jobj) { |
100 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 104 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
101 ReleaseAcceleratedWidget(); | 105 ReleaseAcceleratedWidget(); |
102 } | 106 } |
103 | 107 |
104 void BlimpView::SetVisibility(JNIEnv* env, | 108 void BlimpView::SetVisibility(JNIEnv* env, |
105 const JavaParamRef<jobject>& jobj, | 109 const JavaParamRef<jobject>& jobj, |
106 jboolean visible) { | 110 jboolean visible) { |
107 compositor_manager_->SetVisible(visible); | 111 blimp_contents_->SetVisible(visible); |
108 } | 112 } |
109 | 113 |
110 void BlimpView::ReleaseAcceleratedWidget() { | 114 void BlimpView::ReleaseAcceleratedWidget() { |
111 if (window_ == gfx::kNullAcceleratedWidget) | 115 if (window_ == gfx::kNullAcceleratedWidget) |
112 return; | 116 return; |
113 | 117 |
114 compositor_manager_->ReleaseAcceleratedWidget(); | 118 blimp_contents_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
115 ANativeWindow_release(window_); | 119 ANativeWindow_release(window_); |
116 window_ = gfx::kNullAcceleratedWidget; | 120 window_ = gfx::kNullAcceleratedWidget; |
117 } | 121 } |
118 | 122 |
119 jboolean BlimpView::OnTouchEvent(JNIEnv* env, | 123 jboolean BlimpView::OnTouchEvent(JNIEnv* env, |
120 const JavaParamRef<jobject>& obj, | 124 const JavaParamRef<jobject>& obj, |
121 const JavaParamRef<jobject>& motion_event, | 125 const JavaParamRef<jobject>& motion_event, |
122 jlong time_ms, | 126 jlong time_ms, |
123 jint android_action, | 127 jint android_action, |
124 jint pointer_count, | 128 jint pointer_count, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 pointer_count, | 172 pointer_count, |
169 history_size, | 173 history_size, |
170 action_index, | 174 action_index, |
171 android_button_state, | 175 android_button_state, |
172 android_meta_state, | 176 android_meta_state, |
173 raw_pos_x - pos_x_0, | 177 raw_pos_x - pos_x_0, |
174 raw_pos_y - pos_y_0, | 178 raw_pos_y - pos_y_0, |
175 pointer0, | 179 pointer0, |
176 pointer1); | 180 pointer1); |
177 | 181 |
178 return compositor_manager_->OnTouchEvent(event); | 182 if (blimp_contents_->GetActiveWidget()) { |
| 183 return blimp_contents_->GetActiveWidget()->OnTouchEvent(event); |
| 184 } |
| 185 |
| 186 return false; |
179 } | 187 } |
180 | 188 |
181 void BlimpView::OnSwapBuffersCompleted() { | 189 void BlimpView::OnSwapBuffersCompleted() { |
182 JNIEnv* env = base::android::AttachCurrentThread(); | 190 JNIEnv* env = base::android::AttachCurrentThread(); |
183 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); | 191 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); |
184 } | 192 } |
185 | 193 |
186 void BlimpView::DidCommitAndDrawFrame() { | |
187 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | |
188 } | |
189 | |
190 } // namespace client | 194 } // namespace client |
191 } // namespace blimp | 195 } // namespace blimp |
OLD | NEW |