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/net/blimp_stats.h" | 10 #include "blimp/client/app/compositor/browser_compositor.h" |
11 #include "jni/BlimpView_jni.h" | 11 #include "jni/BlimpView_jni.h" |
12 #include "ui/events/android/motion_event_android.h" | 12 #include "ui/events/android/motion_event_android.h" |
13 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
14 | 14 |
15 using base::android::JavaParamRef; | 15 using base::android::JavaParamRef; |
16 | 16 |
17 namespace blimp { | 17 namespace blimp { |
18 namespace client { | 18 namespace client { |
19 | 19 |
20 static jlong Init(JNIEnv* env, | 20 static jlong Init(JNIEnv* env, |
(...skipping 22 matching lines...) Expand all Loading... |
43 return RegisterNativesImpl(env); | 43 return RegisterNativesImpl(env); |
44 } | 44 } |
45 | 45 |
46 BlimpView::BlimpView(JNIEnv* env, | 46 BlimpView::BlimpView(JNIEnv* env, |
47 const JavaParamRef<jobject>& jobj, | 47 const JavaParamRef<jobject>& jobj, |
48 const gfx::Size& real_size, | 48 const gfx::Size& real_size, |
49 const gfx::Size& size, | 49 const gfx::Size& size, |
50 float dp_to_px, | 50 float dp_to_px, |
51 RenderWidgetFeature* render_widget_feature) | 51 RenderWidgetFeature* render_widget_feature) |
52 : device_scale_factor_(dp_to_px), | 52 : device_scale_factor_(dp_to_px), |
53 compositor_manager_( | 53 compositor_(base::MakeUnique<BrowserCompositor>()), |
54 BlimpCompositorManagerAndroid::Create(real_size, | |
55 size, | |
56 render_widget_feature, | |
57 this)), | |
58 current_surface_format_(0), | 54 current_surface_format_(0), |
59 window_(gfx::kNullAcceleratedWidget) { | 55 window_(gfx::kNullAcceleratedWidget), |
| 56 weak_ptr_factory_(this) { |
| 57 compositor_manager_ = BlimpCompositorManagerAndroid::Create( |
| 58 real_size, size, render_widget_feature, |
| 59 BrowserCompositor::GetSurfaceManager(), |
| 60 BrowserCompositor::GetGpuMemoryBufferManager(), |
| 61 base::Bind(&BrowserCompositor::AllocateSurfaceClientId)); |
| 62 compositor_->set_did_complete_swap_buffers_callback(base::Bind( |
| 63 &BlimpView::OnSwapBuffersCompleted, weak_ptr_factory_.GetWeakPtr())); |
| 64 compositor_->SetContentLayer(compositor_manager_->layer()); |
60 java_obj_.Reset(env, jobj); | 65 java_obj_.Reset(env, jobj); |
61 } | 66 } |
62 | 67 |
63 BlimpView::~BlimpView() { | 68 BlimpView::~BlimpView() { |
64 ReleaseAcceleratedWidget(); | 69 SetSurface(nullptr); |
65 } | 70 } |
66 | 71 |
67 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 72 void BlimpView::Destroy(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
68 delete this; | 73 delete this; |
69 } | 74 } |
70 | 75 |
71 void BlimpView::SetNeedsComposite(JNIEnv* env, | 76 void BlimpView::OnContentAreaSizeChanged( |
72 const JavaParamRef<jobject>& jobj) {} | 77 JNIEnv* env, |
| 78 const base::android::JavaParamRef<jobject>& jobj, |
| 79 jint width, |
| 80 jint height, |
| 81 jfloat dpToPx) { |
| 82 compositor_->SetSize(gfx::Size(width, height)); |
| 83 } |
73 | 84 |
74 void BlimpView::OnSurfaceChanged(JNIEnv* env, | 85 void BlimpView::OnSurfaceChanged(JNIEnv* env, |
75 const JavaParamRef<jobject>& jobj, | 86 const JavaParamRef<jobject>& jobj, |
76 jint format, | 87 jint format, |
77 jint width, | 88 jint width, |
78 jint height, | 89 jint height, |
79 const JavaParamRef<jobject>& jsurface) { | 90 const JavaParamRef<jobject>& jsurface) { |
80 if (current_surface_format_ != format) { | 91 if (current_surface_format_ != format) { |
81 current_surface_format_ = format; | 92 current_surface_format_ = format; |
82 ReleaseAcceleratedWidget(); | 93 SetSurface(nullptr); |
83 | 94 |
84 if (jsurface) { | 95 if (jsurface) { |
85 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); | 96 SetSurface(jsurface); |
86 window_ = ANativeWindow_fromSurface(env, jsurface); | |
87 compositor_manager_->SetAcceleratedWidget(window_); | |
88 compositor_manager_->SetVisible(true); | |
89 } | 97 } |
90 } | 98 } |
91 } | 99 } |
92 | 100 |
93 void BlimpView::OnSurfaceCreated(JNIEnv* env, | 101 void BlimpView::OnSurfaceCreated(JNIEnv* env, |
94 const JavaParamRef<jobject>& jobj) { | 102 const JavaParamRef<jobject>& jobj) { |
95 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 103 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
96 } | 104 } |
97 | 105 |
98 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, | 106 void BlimpView::OnSurfaceDestroyed(JNIEnv* env, |
99 const JavaParamRef<jobject>& jobj) { | 107 const JavaParamRef<jobject>& jobj) { |
100 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; | 108 current_surface_format_ = 0 /** PixelFormat.UNKNOWN */; |
101 ReleaseAcceleratedWidget(); | 109 SetSurface(nullptr); |
102 } | 110 } |
103 | 111 |
104 void BlimpView::SetVisibility(JNIEnv* env, | 112 void BlimpView::SetSurface(jobject surface) { |
105 const JavaParamRef<jobject>& jobj, | 113 JNIEnv* env = base::android::AttachCurrentThread(); |
106 jboolean visible) { | 114 // Release all references to the old surface. |
107 compositor_manager_->SetVisible(visible); | 115 if (window_ != gfx::kNullAcceleratedWidget) { |
108 } | 116 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); |
| 117 compositor_manager_->SetVisible(false); |
| 118 ANativeWindow_release(window_); |
| 119 window_ = gfx::kNullAcceleratedWidget; |
| 120 } |
109 | 121 |
110 void BlimpView::ReleaseAcceleratedWidget() { | 122 if (surface) { |
111 if (window_ == gfx::kNullAcceleratedWidget) | 123 base::android::ScopedJavaLocalFrame scoped_local_reference_frame(env); |
112 return; | 124 window_ = ANativeWindow_fromSurface(env, surface); |
113 | 125 compositor_->SetAcceleratedWidget(window_); |
114 compositor_manager_->ReleaseAcceleratedWidget(); | 126 compositor_manager_->SetVisible(true); |
115 ANativeWindow_release(window_); | 127 } |
116 window_ = gfx::kNullAcceleratedWidget; | |
117 } | 128 } |
118 | 129 |
119 jboolean BlimpView::OnTouchEvent(JNIEnv* env, | 130 jboolean BlimpView::OnTouchEvent(JNIEnv* env, |
120 const JavaParamRef<jobject>& obj, | 131 const JavaParamRef<jobject>& obj, |
121 const JavaParamRef<jobject>& motion_event, | 132 const JavaParamRef<jobject>& motion_event, |
122 jlong time_ms, | 133 jlong time_ms, |
123 jint android_action, | 134 jint android_action, |
124 jint pointer_count, | 135 jint pointer_count, |
125 jint history_size, | 136 jint history_size, |
126 jint action_index, | 137 jint action_index, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 pointer1); | 187 pointer1); |
177 | 188 |
178 return compositor_manager_->OnTouchEvent(event); | 189 return compositor_manager_->OnTouchEvent(event); |
179 } | 190 } |
180 | 191 |
181 void BlimpView::OnSwapBuffersCompleted() { | 192 void BlimpView::OnSwapBuffersCompleted() { |
182 JNIEnv* env = base::android::AttachCurrentThread(); | 193 JNIEnv* env = base::android::AttachCurrentThread(); |
183 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); | 194 Java_BlimpView_onSwapBuffersCompleted(env, java_obj_); |
184 } | 195 } |
185 | 196 |
186 void BlimpView::DidCommitAndDrawFrame() { | |
187 BlimpStats::GetInstance()->Add(BlimpStats::COMMIT, 1); | |
188 } | |
189 | |
190 } // namespace client | 197 } // namespace client |
191 } // namespace blimp | 198 } // namespace blimp |
OLD | NEW |