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/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 625 |
626 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 626 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
627 RenderWidgetHostViewBase::SetBackground(background); | 627 RenderWidgetHostViewBase::SetBackground(background); |
628 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 628 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
629 } | 629 } |
630 | 630 |
631 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 631 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
632 const gfx::Rect& src_subrect, | 632 const gfx::Rect& src_subrect, |
633 const gfx::Size& dst_size, | 633 const gfx::Size& dst_size, |
634 const base::Callback<void(bool, const SkBitmap&)>& callback, | 634 const base::Callback<void(bool, const SkBitmap&)>& callback, |
635 bool readback_config_rgb565) { | 635 const SkBitmap::Config bitmap_config) { |
| 636 // Only ARGB888 and RGB565 supported as of now. |
| 637 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || |
| 638 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
| 639 if (!format_support) { |
| 640 DCHECK(format_support); |
| 641 callback.Run(false, SkBitmap()); |
| 642 return; |
| 643 } |
636 base::TimeTicks start_time = base::TimeTicks::Now(); | 644 base::TimeTicks start_time = base::TimeTicks::Now(); |
637 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 645 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
638 callback.Run(false, SkBitmap()); | 646 callback.Run(false, SkBitmap()); |
639 return; | 647 return; |
640 } | 648 } |
641 ImageTransportFactoryAndroid* factory = | 649 ImageTransportFactoryAndroid* factory = |
642 ImageTransportFactoryAndroid::GetInstance(); | 650 ImageTransportFactoryAndroid::GetInstance(); |
643 GLHelper* gl_helper = factory->GetGLHelper(); | 651 GLHelper* gl_helper = factory->GetGLHelper(); |
644 if (!gl_helper) | 652 if (!gl_helper) |
645 return; | 653 return; |
646 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | 654 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); |
647 if (readback_config_rgb565 && !check_rgb565_support) { | 655 if ((bitmap_config == SkBitmap::kRGB_565_Config) && |
| 656 !check_rgb565_support) { |
648 LOG(ERROR) << "Readbackformat rgb565 not supported"; | 657 LOG(ERROR) << "Readbackformat rgb565 not supported"; |
649 callback.Run(false, SkBitmap()); | 658 callback.Run(false, SkBitmap()); |
650 return; | 659 return; |
651 } | 660 } |
652 const gfx::Display& display = | 661 const gfx::Display& display = |
653 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 662 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
654 float device_scale_factor = display.device_scale_factor(); | 663 float device_scale_factor = display.device_scale_factor(); |
655 | 664 |
656 DCHECK_EQ(device_scale_factor, | 665 DCHECK_EQ(device_scale_factor, |
657 ui::GetImageScale(GetScaleFactorForView(this))); | 666 ui::GetImageScale(GetScaleFactorForView(this))); |
(...skipping 12 matching lines...) Expand all Loading... |
670 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 679 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
671 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 680 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
672 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 681 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
673 dst_size_in_pixel, | 682 dst_size_in_pixel, |
674 start_time, | 683 start_time, |
675 callback)); | 684 callback)); |
676 } else { | 685 } else { |
677 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 686 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
678 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 687 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
679 dst_size_in_pixel, | 688 dst_size_in_pixel, |
680 readback_config_rgb565, | 689 bitmap_config, |
681 start_time, | 690 start_time, |
682 callback)); | 691 callback)); |
683 } | 692 } |
684 request->set_area(src_subrect_in_pixel); | 693 request->set_area(src_subrect_in_pixel); |
685 layer_->RequestCopyOfOutput(request.Pass()); | 694 layer_->RequestCopyOfOutput(request.Pass()); |
686 } | 695 } |
687 | 696 |
688 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 697 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
689 const gfx::Rect& src_subrect, | 698 const gfx::Rect& src_subrect, |
690 const scoped_refptr<media::VideoFrame>& target, | 699 const scoped_refptr<media::VideoFrame>& target, |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 texture_layer_->SetIsDrawable(false); | 1402 texture_layer_->SetIsDrawable(false); |
1394 if (delegated_renderer_layer_.get()) | 1403 if (delegated_renderer_layer_.get()) |
1395 DestroyDelegatedContent(); | 1404 DestroyDelegatedContent(); |
1396 texture_id_in_layer_ = 0; | 1405 texture_id_in_layer_ = 0; |
1397 RunAckCallbacks(); | 1406 RunAckCallbacks(); |
1398 } | 1407 } |
1399 | 1408 |
1400 // static | 1409 // static |
1401 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1410 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1402 const gfx::Size& dst_size_in_pixel, | 1411 const gfx::Size& dst_size_in_pixel, |
1403 bool readback_config_rgb565, | 1412 const SkBitmap::Config bitmap_config, |
1404 const base::TimeTicks& start_time, | 1413 const base::TimeTicks& start_time, |
1405 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1414 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1406 scoped_ptr<cc::CopyOutputResult> result) { | 1415 scoped_ptr<cc::CopyOutputResult> result) { |
1407 DCHECK(result->HasTexture()); | 1416 DCHECK(result->HasTexture()); |
1408 base::ScopedClosureRunner scoped_callback_runner( | 1417 base::ScopedClosureRunner scoped_callback_runner( |
1409 base::Bind(callback, false, SkBitmap())); | 1418 base::Bind(callback, false, SkBitmap())); |
1410 | 1419 |
1411 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1420 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1412 return; | 1421 return; |
1413 | 1422 |
1414 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1423 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1415 SkBitmap::Config bitmap_config = readback_config_rgb565 ? | |
1416 SkBitmap::kRGB_565_Config : | |
1417 SkBitmap::kARGB_8888_Config; | |
1418 bitmap->setConfig(bitmap_config, | 1424 bitmap->setConfig(bitmap_config, |
1419 dst_size_in_pixel.width(), | 1425 dst_size_in_pixel.width(), |
1420 dst_size_in_pixel.height(), | 1426 dst_size_in_pixel.height(), |
1421 0, kOpaque_SkAlphaType); | 1427 0, kOpaque_SkAlphaType); |
1422 if (!bitmap->allocPixels()) | 1428 if (!bitmap->allocPixels()) |
1423 return; | 1429 return; |
1424 | 1430 |
1425 ImageTransportFactoryAndroid* factory = | 1431 ImageTransportFactoryAndroid* factory = |
1426 ImageTransportFactoryAndroid::GetInstance(); | 1432 ImageTransportFactoryAndroid::GetInstance(); |
1427 GLHelper* gl_helper = factory->GetGLHelper(); | 1433 GLHelper* gl_helper = factory->GetGLHelper(); |
(...skipping 13 matching lines...) Expand all Loading... |
1441 | 1447 |
1442 ignore_result(scoped_callback_runner.Release()); | 1448 ignore_result(scoped_callback_runner.Release()); |
1443 | 1449 |
1444 gl_helper->CropScaleReadbackAndCleanMailbox( | 1450 gl_helper->CropScaleReadbackAndCleanMailbox( |
1445 texture_mailbox.name(), | 1451 texture_mailbox.name(), |
1446 texture_mailbox.sync_point(), | 1452 texture_mailbox.sync_point(), |
1447 result->size(), | 1453 result->size(), |
1448 gfx::Rect(result->size()), | 1454 gfx::Rect(result->size()), |
1449 dst_size_in_pixel, | 1455 dst_size_in_pixel, |
1450 pixels, | 1456 pixels, |
1451 readback_config_rgb565, | 1457 bitmap_config, |
1452 base::Bind(&CopyFromCompositingSurfaceFinished, | 1458 base::Bind(&CopyFromCompositingSurfaceFinished, |
1453 callback, | 1459 callback, |
1454 base::Passed(&release_callback), | 1460 base::Passed(&release_callback), |
1455 base::Passed(&bitmap), | 1461 base::Passed(&bitmap), |
1456 start_time, | 1462 start_time, |
1457 base::Passed(&bitmap_pixels_lock))); | 1463 base::Passed(&bitmap_pixels_lock))); |
1458 } | 1464 } |
1459 | 1465 |
1460 // static | 1466 // static |
1461 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1467 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 // RenderWidgetHostView, public: | 1510 // RenderWidgetHostView, public: |
1505 | 1511 |
1506 // static | 1512 // static |
1507 RenderWidgetHostView* | 1513 RenderWidgetHostView* |
1508 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1514 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1509 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1515 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1510 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1516 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1511 } | 1517 } |
1512 | 1518 |
1513 } // namespace content | 1519 } // namespace content |
OLD | NEW |