OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
6 | 6 |
7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
16 #include "cc/layers/delegated_renderer_layer.h" | 16 #include "cc/layers/delegated_renderer_layer.h" |
17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
18 #include "cc/layers/texture_layer.h" | 18 #include "cc/layers/texture_layer.h" |
19 #include "cc/output/compositor_frame.h" | 19 #include "cc/output/compositor_frame.h" |
20 #include "cc/output/compositor_frame_ack.h" | 20 #include "cc/output/compositor_frame_ack.h" |
21 #include "cc/output/copy_output_request.h" | |
22 #include "cc/output/copy_output_result.h" | |
21 #include "cc/trees/layer_tree_host.h" | 23 #include "cc/trees/layer_tree_host.h" |
22 #include "content/browser/accessibility/browser_accessibility_manager_android.h" | 24 #include "content/browser/accessibility/browser_accessibility_manager_android.h" |
23 #include "content/browser/android/content_view_core_impl.h" | 25 #include "content/browser/android/content_view_core_impl.h" |
24 #include "content/browser/android/in_process/synchronous_compositor_impl.h" | 26 #include "content/browser/android/in_process/synchronous_compositor_impl.h" |
25 #include "content/browser/android/overscroll_glow.h" | 27 #include "content/browser/android/overscroll_glow.h" |
26 #include "content/browser/gpu/gpu_surface_tracker.h" | 28 #include "content/browser/gpu/gpu_surface_tracker.h" |
27 #include "content/browser/renderer_host/compositor_impl_android.h" | 29 #include "content/browser/renderer_host/compositor_impl_android.h" |
30 #include "content/browser/renderer_host/dip_util.h" | |
28 #include "content/browser/renderer_host/image_transport_factory_android.h" | 31 #include "content/browser/renderer_host/image_transport_factory_android.h" |
29 #include "content/browser/renderer_host/render_widget_host_impl.h" | 32 #include "content/browser/renderer_host/render_widget_host_impl.h" |
30 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" | 33 #include "content/browser/renderer_host/surface_texture_transport_client_android .h" |
31 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_android.h" | 34 #include "content/browser/renderer_host/touch_smooth_scroll_gesture_android.h" |
32 #include "content/common/gpu/client/gl_helper.h" | 35 #include "content/common/gpu/client/gl_helper.h" |
33 #include "content/common/gpu/gpu_messages.h" | 36 #include "content/common/gpu/gpu_messages.h" |
34 #include "content/common/input_messages.h" | 37 #include "content/common/input_messages.h" |
35 #include "content/common/view_messages.h" | 38 #include "content/common/view_messages.h" |
36 #include "content/public/common/content_switches.h" | 39 #include "content/public/common/content_switches.h" |
40 #include "skia/ext/image_operations.h" | |
37 #include "third_party/khronos/GLES2/gl2.h" | 41 #include "third_party/khronos/GLES2/gl2.h" |
38 #include "third_party/khronos/GLES2/gl2ext.h" | 42 #include "third_party/khronos/GLES2/gl2ext.h" |
39 #include "ui/gfx/android/device_display_info.h" | 43 #include "ui/gfx/android/device_display_info.h" |
40 #include "ui/gfx/android/java_bitmap.h" | 44 #include "ui/gfx/android/java_bitmap.h" |
41 #include "ui/gfx/display.h" | 45 #include "ui/gfx/display.h" |
42 #include "ui/gfx/screen.h" | 46 #include "ui/gfx/screen.h" |
43 #include "ui/gfx/size_conversions.h" | 47 #include "ui/gfx/size_conversions.h" |
44 | 48 |
45 namespace content { | 49 namespace content { |
46 | 50 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 } | 326 } |
323 | 327 |
324 bool RenderWidgetHostViewAndroid::HasFocus() const { | 328 bool RenderWidgetHostViewAndroid::HasFocus() const { |
325 if (!content_view_core_) | 329 if (!content_view_core_) |
326 return false; // ContentViewCore not created yet. | 330 return false; // ContentViewCore not created yet. |
327 | 331 |
328 return content_view_core_->HasFocus(); | 332 return content_view_core_->HasFocus(); |
329 } | 333 } |
330 | 334 |
331 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 335 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
332 NOTIMPLEMENTED(); | 336 return HasValidFrame(); |
333 return false; | |
334 } | 337 } |
335 | 338 |
336 void RenderWidgetHostViewAndroid::Show() { | 339 void RenderWidgetHostViewAndroid::Show() { |
337 if (are_layers_attached_) | 340 if (are_layers_attached_) |
338 return; | 341 return; |
339 | 342 |
340 are_layers_attached_ = true; | 343 are_layers_attached_ = true; |
341 AttachLayers(); | 344 AttachLayers(); |
342 } | 345 } |
343 | 346 |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
533 | 536 |
534 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 537 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
535 RenderWidgetHostViewBase::SetBackground(background); | 538 RenderWidgetHostViewBase::SetBackground(background); |
536 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 539 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
537 } | 540 } |
538 | 541 |
539 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 542 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
540 const gfx::Rect& src_subrect, | 543 const gfx::Rect& src_subrect, |
541 const gfx::Size& dst_size, | 544 const gfx::Size& dst_size, |
542 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 545 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
543 NOTIMPLEMENTED(); | 546 if (!CanCopyToBitmap()) { |
Sami
2013/08/09 16:08:48
Seems like we could just call IsSurfaceAvailableFo
pfeldman
2013/08/09 16:19:59
Done.
| |
544 callback.Run(false, SkBitmap()); | 547 callback.Run(false, SkBitmap()); |
548 return; | |
549 } | |
550 | |
551 const gfx::Display& display = | |
552 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | |
553 float device_scale_factor = display.device_scale_factor(); | |
554 | |
555 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | |
556 gfx::Rect src_subrect_in_pixel = | |
557 ConvertRectToPixel(device_scale_factor, src_subrect); | |
558 | |
559 scoped_ptr<cc::CopyOutputRequest> request; | |
560 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | |
561 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | |
562 &RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceHasResult, | |
563 dst_size_in_pixel, | |
564 callback)); | |
565 } else { | |
566 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | |
567 &RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceHasResult, | |
568 dst_size_in_pixel, | |
569 callback)); | |
570 } | |
571 request->set_area(src_subrect_in_pixel); | |
572 layer_->RequestCopyOfOutput(request.Pass()); | |
545 } | 573 } |
546 | 574 |
547 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 575 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
548 const gfx::Rect& src_subrect, | 576 const gfx::Rect& src_subrect, |
549 const scoped_refptr<media::VideoFrame>& target, | 577 const scoped_refptr<media::VideoFrame>& target, |
550 const base::Callback<void(bool)>& callback) { | 578 const base::Callback<void(bool)>& callback) { |
551 NOTIMPLEMENTED(); | 579 NOTIMPLEMENTED(); |
552 callback.Run(false); | 580 callback.Run(false); |
553 } | 581 } |
554 | 582 |
583 bool RenderWidgetHostViewAndroid::CanCopyToBitmap() const { | |
584 return true; | |
Sami
2013/08/09 16:08:48
Do we need this method? Please add a TODO if somet
pfeldman
2013/08/09 16:19:59
Removed
| |
585 } | |
586 | |
555 bool RenderWidgetHostViewAndroid::CanCopyToVideoFrame() const { | 587 bool RenderWidgetHostViewAndroid::CanCopyToVideoFrame() const { |
556 return false; | 588 return false; |
557 } | 589 } |
558 | 590 |
559 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( | 591 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( |
560 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { | 592 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { |
561 if (!content_view_core_) | 593 if (!content_view_core_) |
562 return; | 594 return; |
563 | 595 |
564 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); | 596 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 } | 1178 } |
1147 | 1179 |
1148 void RenderWidgetHostViewAndroid::OnLostResources() { | 1180 void RenderWidgetHostViewAndroid::OnLostResources() { |
1149 if (texture_layer_) | 1181 if (texture_layer_) |
1150 texture_layer_->SetIsDrawable(false); | 1182 texture_layer_->SetIsDrawable(false); |
1151 texture_id_in_layer_ = 0; | 1183 texture_id_in_layer_ = 0; |
1152 RunAckCallbacks(); | 1184 RunAckCallbacks(); |
1153 } | 1185 } |
1154 | 1186 |
1155 // static | 1187 // static |
1188 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceHasResult( | |
1189 const gfx::Size& dst_size_in_pixel, | |
1190 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
1191 scoped_ptr<cc::CopyOutputResult> result) { | |
1192 if (result->IsEmpty() || result->size().IsEmpty()) { | |
1193 callback.Run(false, SkBitmap()); | |
1194 return; | |
1195 } | |
1196 | |
1197 if (result->HasTexture()) { | |
1198 PrepareTextureCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | |
1199 return; | |
1200 } | |
1201 | |
1202 DCHECK(result->HasBitmap()); | |
1203 PrepareBitmapCopyOutputResult(dst_size_in_pixel, callback, result.Pass()); | |
1204 } | |
1205 | |
1206 static void CopyFromCompositingSurfaceFinished( | |
1207 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
1208 const cc::TextureMailbox::ReleaseCallback& release_callback, | |
1209 scoped_ptr<SkBitmap> bitmap, | |
1210 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | |
1211 bool result) { | |
1212 bitmap_pixels_lock.reset(); | |
1213 release_callback.Run(0, false); | |
1214 callback.Run(result, *bitmap); | |
1215 } | |
1216 | |
1217 // static | |
1218 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | |
1219 const gfx::Size& dst_size_in_pixel, | |
1220 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
1221 scoped_ptr<cc::CopyOutputResult> result) { | |
1222 base::ScopedClosureRunner scoped_callback_runner( | |
1223 base::Bind(callback, false, SkBitmap())); | |
1224 | |
1225 DCHECK(result->HasTexture()); | |
1226 if (!result->HasTexture()) | |
1227 return; | |
1228 | |
1229 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | |
1230 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | |
1231 dst_size_in_pixel.width(), dst_size_in_pixel.height()); | |
1232 if (!bitmap->allocPixels()) | |
1233 return; | |
1234 bitmap->setIsOpaque(true); | |
1235 | |
1236 ImageTransportFactoryAndroid* factory = | |
1237 ImageTransportFactoryAndroid::GetInstance(); | |
1238 GLHelper* gl_helper = factory->GetGLHelper(); | |
1239 if (!gl_helper) | |
1240 return; | |
1241 | |
1242 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | |
1243 new SkAutoLockPixels(*bitmap)); | |
1244 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | |
1245 | |
1246 scoped_ptr<cc::TextureMailbox> texture_mailbox = result->TakeTexture(); | |
1247 DCHECK(texture_mailbox->IsTexture()); | |
1248 if (!texture_mailbox->IsTexture()) | |
1249 return; | |
1250 | |
1251 scoped_callback_runner.Release(); | |
1252 | |
1253 gl_helper->CropScaleReadbackAndCleanMailbox( | |
1254 texture_mailbox->name(), | |
1255 texture_mailbox->sync_point(), | |
1256 result->size(), | |
1257 gfx::Rect(result->size()), | |
1258 dst_size_in_pixel, | |
1259 pixels, | |
1260 base::Bind(&CopyFromCompositingSurfaceFinished, | |
1261 callback, | |
1262 texture_mailbox->callback(), | |
1263 base::Passed(&bitmap), | |
1264 base::Passed(&bitmap_pixels_lock))); | |
1265 } | |
1266 | |
1267 // static | |
1268 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | |
1269 const gfx::Size& dst_size_in_pixel, | |
1270 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
1271 scoped_ptr<cc::CopyOutputResult> result) { | |
1272 DCHECK(result->HasBitmap()); | |
1273 | |
1274 base::ScopedClosureRunner scoped_callback_runner( | |
1275 base::Bind(callback, false, SkBitmap())); | |
1276 if (!result->HasBitmap()) | |
1277 return; | |
1278 | |
1279 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | |
1280 DCHECK(source); | |
1281 if (!source) | |
1282 return; | |
1283 | |
1284 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); | |
1285 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); | |
1286 | |
1287 scoped_callback_runner.Release(); | |
1288 callback.Run(true, *source); | |
1289 } | |
1290 | |
1291 // static | |
1156 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1292 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1157 WebKit::WebScreenInfo* results) { | 1293 WebKit::WebScreenInfo* results) { |
1158 const gfx::Display& display = | 1294 const gfx::Display& display = |
1159 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1295 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
1160 results->rect = display.bounds(); | 1296 results->rect = display.bounds(); |
1161 // TODO(husky): Remove any system controls from availableRect. | 1297 // TODO(husky): Remove any system controls from availableRect. |
1162 results->availableRect = display.work_area(); | 1298 results->availableRect = display.work_area(); |
1163 results->deviceScaleFactor = display.device_scale_factor(); | 1299 results->deviceScaleFactor = display.device_scale_factor(); |
1164 gfx::DeviceDisplayInfo info; | 1300 gfx::DeviceDisplayInfo info; |
1165 results->depth = info.GetBitsPerPixel(); | 1301 results->depth = info.GetBitsPerPixel(); |
1166 results->depthPerComponent = info.GetBitsPerComponent(); | 1302 results->depthPerComponent = info.GetBitsPerComponent(); |
1167 results->isMonochrome = (results->depthPerComponent == 0); | 1303 results->isMonochrome = (results->depthPerComponent == 0); |
1168 } | 1304 } |
1169 | 1305 |
1170 //////////////////////////////////////////////////////////////////////////////// | 1306 //////////////////////////////////////////////////////////////////////////////// |
1171 // RenderWidgetHostView, public: | 1307 // RenderWidgetHostView, public: |
1172 | 1308 |
1173 // static | 1309 // static |
1174 RenderWidgetHostView* | 1310 RenderWidgetHostView* |
1175 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1311 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1176 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1312 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1177 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1313 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1178 } | 1314 } |
1179 | 1315 |
1180 } // namespace content | 1316 } // namespace content |
OLD | NEW |