Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: blimp/client/app/android/blimp_view.cc

Issue 2493333002: Move Java Blimp shell code to app subpackage (Closed)
Patch Set: Merge branch 'refs/heads/master' into blimp-shell-integration Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/app/android/blimp_view.h"
6
7 #include <android/native_window_jni.h>
8
9 #include "base/memory/ptr_util.h"
10 #include "blimp/client/app/android/blimp_client_session_android.h"
11 #include "blimp/client/app/compositor/browser_compositor.h"
12 #include "blimp/client/core/compositor/blimp_compositor_dependencies.h"
13 #include "blimp/client/core/render_widget/blimp_document_manager.h"
14 #include "blimp/client/core/render_widget/render_widget_feature.h"
15 #include "blimp/client/support/compositor/compositor_dependencies_impl.h"
16 #include "jni/BlimpView_jni.h"
17 #include "ui/events/android/motion_event_android.h"
18 #include "ui/gfx/geometry/size.h"
19
20 namespace {
21 const int kDummyBlimpContentsId = 0;
22 } // namespace
23
24 namespace blimp {
25 namespace client {
26 namespace app {
27
28 static jlong Init(
29 JNIEnv* env,
30 const base::android::JavaParamRef<jobject>& jobj,
31 const base::android::JavaParamRef<jobject>& blimp_client_session,
32 jint real_width,
33 jint real_height,
34 jint width,
35 jint height,
36 jfloat dp_to_px) {
37 BlimpClientSession* client_session =
38 BlimpClientSessionAndroid::FromJavaObject(env, blimp_client_session);
39
40 // TODO(dtrainor): Pull the feature object from the BlimpClientSession and
41 // pass it through to the BlimpCompositor.
42 ALLOW_UNUSED_LOCAL(client_session);
43
44 return reinterpret_cast<intptr_t>(new BlimpView(
45 env, jobj, gfx::Size(real_width, real_height), gfx::Size(width, height),
46 dp_to_px, client_session->GetRenderWidgetFeature()));
47 }
48
49 // static
50 bool BlimpView::RegisterJni(JNIEnv* env) {
51 return RegisterNativesImpl(env);
52 }
53
54 BlimpView::BlimpView(JNIEnv* env,
55 const base::android::JavaParamRef<jobject>& jobj,
56 const gfx::Size& real_size,
57 const gfx::Size& size,
58 float dp_to_px,
59 blimp::client::RenderWidgetFeature* render_widget_feature)
60 : device_scale_factor_(dp_to_px),
61 current_surface_format_(0),
62 window_(gfx::kNullAcceleratedWidget),
63 weak_ptr_factory_(this) {
64 compositor_dependencies_ = base::MakeUnique<BlimpCompositorDependencies>(
65 base::MakeUnique<CompositorDependenciesImpl>());
66
67 compositor_ = base::MakeUnique<BrowserCompositor>(
68 compositor_dependencies_->GetEmbedderDependencies());
69 compositor_->set_did_complete_swap_buffers_callback(base::Bind(
70 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr()));
71
72 document_manager_ = base::MakeUnique<BlimpDocumentManager>(
73 kDummyBlimpContentsId, render_widget_feature,
74 compositor_dependencies_.get());
75 compositor_->SetContentLayer(document_manager_->layer());
76
77 java_obj_.Reset(env, jobj);
78 }
79
80 BlimpView::~BlimpView() {
81 SetSurface(nullptr);
82
83 // Destroy the BrowserCompositor and the BlimpCompositorManager before the
84 // BlimpCompositorDependencies.
85 compositor_.reset();
86 document_manager_.reset();
87 compositor_dependencies_.reset();
88 }
89
90 void BlimpView::Destroy(JNIEnv* env,
91 const base::android::JavaParamRef<jobject>& jobj) {
92 delete this;
93 }
94
95 void BlimpView::OnContentAreaSizeChanged(
96 JNIEnv* env,
97 const base::android::JavaParamRef<jobject>& jobj,
98 jint width,
99 jint height,
100 jfloat dpToPx) {
101 compositor_->SetSize(gfx::Size(width, height));
102 }
103
104 void BlimpView::OnSurfaceChanged(
105 JNIEnv* env,
106 const base::android::JavaParamRef<jobject>& jobj,
107 jint format,
108 jint width,
109 jint height,
110 const base::android::JavaParamRef<jobject>& jsurface) {
111 if (current_surface_format_ != format) {
112 current_surface_format_ = format;
113 SetSurface(nullptr);
114
115 if (jsurface) {
116 SetSurface(jsurface);
117 }
118 }
119 }
120
121 void BlimpView::OnSurfaceCreated(
122 JNIEnv* env,
123 const base::android::JavaParamRef<jobject>& jobj) {
124 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
125 }
126
127 void BlimpView::OnSurfaceDestroyed(
128 JNIEnv* env,
129 const base::android::JavaParamRef<jobject>& jobj) {
130 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */;
131 SetSurface(nullptr);
132 }
133
134 void BlimpView::SetSurface(jobject surface) {
135 JNIEnv* env = base::android::AttachCurrentThread();
136 // Release all references to the old surface.
137 if (window_ != gfx::kNullAcceleratedWidget) {
138 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
139 document_manager_->SetVisible(false);
140 ANativeWindow_release(window_);
141 window_ = gfx::kNullAcceleratedWidget;
142 }
143
144 if (surface) {
145 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env);
146 window_ = ANativeWindow_fromSurface(env, surface);
147 compositor_->SetAcceleratedWidget(window_);
148 document_manager_->SetVisible(true);
149 }
150 }
151
152 jboolean BlimpView::OnTouchEvent(
153 JNIEnv* env,
154 const base::android::JavaParamRef<jobject>& obj,
155 const base::android::JavaParamRef<jobject>& motion_event,
156 jlong time_ms,
157 jint android_action,
158 jint pointer_count,
159 jint history_size,
160 jint action_index,
161 jfloat pos_x_0,
162 jfloat pos_y_0,
163 jfloat pos_x_1,
164 jfloat pos_y_1,
165 jint pointer_id_0,
166 jint pointer_id_1,
167 jfloat touch_major_0,
168 jfloat touch_major_1,
169 jfloat touch_minor_0,
170 jfloat touch_minor_1,
171 jfloat orientation_0,
172 jfloat orientation_1,
173 jfloat tilt_0,
174 jfloat tilt_1,
175 jfloat raw_pos_x,
176 jfloat raw_pos_y,
177 jint android_tool_type_0,
178 jint android_tool_type_1,
179 jint android_button_state,
180 jint android_meta_state) {
181 ui::MotionEventAndroid::Pointer pointer0(pointer_id_0,
182 pos_x_0,
183 pos_y_0,
184 touch_major_0,
185 touch_minor_0,
186 orientation_0,
187 tilt_0,
188 android_tool_type_0);
189 ui::MotionEventAndroid::Pointer pointer1(pointer_id_1,
190 pos_x_1,
191 pos_y_1,
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
212 return document_manager_->OnTouchEvent(event);
213 }
214
215 void BlimpView::OnSwapBuffersCompleted() {
216 JNIEnv* env = base::android::AttachCurrentThread();
217 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_);
218 }
219
220 } // namespace app
221 } // namespace client
222 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/client/app/android/blimp_view.h ('k') | blimp/client/app/android/java/res/layout/blimp_main.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698