OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "blimp/client/android/blimp_view.h" | |
6 | |
7 #include <android/native_window_jni.h> | |
8 | |
9 #include "blimp/client/compositor/blimp_compositor_android.h" | |
10 #include "blimp/client/session/blimp_client_session_android.h" | |
11 #include "jni/BlimpView_jni.h" | |
12 #include "ui/events/android/motion_event_android.h" | |
13 #include "ui/gfx/geometry/size.h" | |
14 | |
15 namespace blimp { | |
16 namespace client { | |
17 | |
18 static jlong Init(JNIEnv* env, | |
19 const JavaParamRef<jobject>& jobj, | |
20 const JavaParamRef<jobject>& blimp_client_session, | |
21 jint real_width, | |
22 jint real_height, | |
23 jint width, | |
24 jint height, | |
25 jfloat dp_to_px) { | |
26 BlimpClientSession* client_session = | |
27 BlimpClientSessionAndroid::FromJavaObject(env, | |
28 blimp_client_session.obj()); | |
29 | |
30 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and | |
31 // pass it through to the BlimpCompositor. | |
32 ALLOW_UNUSED_LOCAL(client_session); | |
33 | |
34 return reinterpret_cast<intptr_t>(new BlimpView( | |
35 env, jobj, gfx::Size(real_width, real_height), gfx::Size(width, height), | |
36 dp_to_px, client_session->GetRenderWidgetFeature())); | |
37 } | |
38 | |
39 // static | |
40 bool BlimpView::RegisterJni(JNIEnv* env) { | |
41 return RegisterNativesImpl(env); | |
42 } | |
43 | |
44 BlimpView::BlimpView(JNIEnv* env, | |
45 const JavaParamRef<jobject>& jobj, | |
46 const gfx::Size& real_size, | |
47 const gfx::Size& size, | |
48 float dp_to_px, | |
49 RenderWidgetFeature* render_widget_feature) | |
50 : device_scale_factor_(dp_to_px), | |
51 compositor_(BlimpCompositorAndroid::Create(real_size, | |
52 size, | |
53 dp_to_px, | |
54 render_widget_feature)), | |
55 current_surface_format_(0), | |
56 window_(gfx::kNullAcceleratedWidget) { | |
57 java_obj_.Reset(env, jobj); | |
58 } | |
59 | |
60 BlimpView::~BlimpView() { | |
61 ReleaseAcceleratedWidget(); | |
62 } | |
63 | |
64 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | |
65 delete this; | |
66 } | |
67 | |
68 void BlimpView::SetNeedsComposite(JNIEnv* env, | |
69 const JavaParamRef<jobject>& jobj) {} | |
70 | |
71 void BlimpView::OnSurfaceChanged(JNIEnv* env, | |
72 const JavaParamRef<jobject>& jobj, | |
73 jint format, | |
74 jint width, | |
75 jint height, | |
76 const JavaParamRef<jobject>& jsurface) { | |
77 if (current_surface_format_ != format) { | |
78 current_surface_format_ = format; | |
79 ReleaseAcceleratedWidget(); | |
80 | |
81 if (jsurface) { | |
82 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | |
83 window_ = ANativeWindow_fromSurface(env, jsurface); | |
84 compositor_->SetAcceleratedWidget(window_); | |
85 compositor_->SetVisible(true); | |
86 } | |
87 } | |
88 | |
89 compositor_->SetSize(gfx::Size(width, height)); | |
90 } | |
91 | |
92 void BlimpView::OnSurfaceCreated(JNIEnv* env, | |
93 const JavaParamRef<jobject>& jobj) { | |
94 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | |
95 } | |
96 | |
97 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, | |
98 const JavaParamRef<jobject>& jobj) { | |
99 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | |
100 ReleaseAcceleratedWidget(); | |
101 } | |
102 | |
103 void BlimpView::SetVisibility(JNIEnv* env, | |
104 const JavaParamRef<jobject>& jobj, | |
105 jboolean visible) { | |
106 compositor_->SetVisible(visible); | |
107 } | |
108 | |
109 void BlimpView::ReleaseAcceleratedWidget() { | |
110 if (window_ == gfx::kNullAcceleratedWidget) | |
111 return; | |
112 | |
113 compositor_->ReleaseAcceleratedWidget(); | |
114 ANativeWindow_release(window_); | |
115 window_ = gfx::kNullAcceleratedWidget; | |
116 } | |
117 | |
118 jboolean BlimpView::OnTouchEvent(JNIEnv* env, | |
119 const JavaParamRef<jobject>& obj, | |
120 const JavaParamRef<jobject>& motion_event, | |
121 jlong time_ms, | |
122 jint android_action, | |
123 jint pointer_count, | |
124 jint history_size, | |
125 jint action_index, | |
126 jfloat pos_x_0, | |
127 jfloat pos_y_0, | |
128 jfloat pos_x_1, | |
129 jfloat pos_y_1, | |
130 jint pointer_id_0, | |
131 jint pointer_id_1, | |
132 jfloat touch_major_0, | |
133 jfloat touch_major_1, | |
134 jfloat touch_minor_0, | |
135 jfloat touch_minor_1, | |
136 jfloat orientation_0, | |
137 jfloat orientation_1, | |
138 jfloat tilt_0, | |
139 jfloat tilt_1, | |
140 jfloat raw_pos_x, | |
141 jfloat raw_pos_y, | |
142 jint android_tool_type_0, | |
143 jint android_tool_type_1, | |
144 jint android_button_state, | |
145 jint android_meta_state) { | |
146 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0, | |
147 pos_x_0, | |
148 pos_y_0, | |
149 touch_major_0, | |
150 touch_minor_0, | |
151 orientation_0, | |
152 tilt_0, | |
153 android_tool_type_0); | |
154 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1, | |
155 pos_x_1, | |
156 pos_y_1, | |
157 touch_major_1, | |
158 touch_minor_1, | |
159 orientation_1, | |
160 tilt_1, | |
161 android_tool_type_1); | |
162 ui::MotionEventAndroid event(1.f / device_scale_factor_, | |
163 env, | |
164 motion_event, | |
165 time_ms, | |
166 android_action, | |
167 pointer_count, | |
168 history_size, | |
169 action_index, | |
170 android_button_state, | |
171 android_meta_state, | |
172 raw_pos_x - pos_x_0, | |
173 raw_pos_y - pos_y_0, | |
174 pointer0, | |
175 pointer1); | |
176 | |
177 return compositor_->OnTouchEvent(event); | |
178 } | |
179 | |
180 } // namespace client | |
181 } // namespace blimp | |
OLD | NEW |