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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 | 621 |
622 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 622 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
623 RenderWidgetHostViewBase::SetBackground(background); | 623 RenderWidgetHostViewBase::SetBackground(background); |
624 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 624 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
625 } | 625 } |
626 | 626 |
627 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 627 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
628 const gfx::Rect& src_subrect, | 628 const gfx::Rect& src_subrect, |
629 const gfx::Size& dst_size, | 629 const gfx::Size& dst_size, |
630 const base::Callback<void(bool, const SkBitmap&)>& callback, | 630 const base::Callback<void(bool, const SkBitmap&)>& callback, |
631 bool readback_config_rgb565) { | 631 const SkBitmap::Config bitmap_config) { |
| 632 // Only ARGB888 and RGB565 supported as of now. |
| 633 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) || |
| 634 (bitmap_config == SkBitmap::kARGB_8888_Config)); |
| 635 |
632 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 636 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
633 callback.Run(false, SkBitmap()); | 637 callback.Run(false, SkBitmap()); |
634 return; | 638 return; |
635 } | 639 } |
636 ImageTransportFactoryAndroid* factory = | 640 ImageTransportFactoryAndroid* factory = |
637 ImageTransportFactoryAndroid::GetInstance(); | 641 ImageTransportFactoryAndroid::GetInstance(); |
638 GLHelper* gl_helper = factory->GetGLHelper(); | 642 GLHelper* gl_helper = factory->GetGLHelper(); |
639 if (!gl_helper) | 643 if (!gl_helper) |
640 return; | 644 return; |
641 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | 645 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); |
642 if (readback_config_rgb565 && !check_rgb565_support) { | 646 if ((bitmap_config == SkBitmap::kRGB_565_Config) && |
| 647 !check_rgb565_support) { |
643 LOG(ERROR) << "Readbackformat rgb565 not supported"; | 648 LOG(ERROR) << "Readbackformat rgb565 not supported"; |
644 callback.Run(false, SkBitmap()); | 649 callback.Run(false, SkBitmap()); |
645 return; | 650 return; |
646 } | 651 } |
647 const gfx::Display& display = | 652 const gfx::Display& display = |
648 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 653 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
649 float device_scale_factor = display.device_scale_factor(); | 654 float device_scale_factor = display.device_scale_factor(); |
650 | 655 |
651 DCHECK_EQ(device_scale_factor, | 656 DCHECK_EQ(device_scale_factor, |
652 ui::GetImageScale(GetScaleFactorForView(this))); | 657 ui::GetImageScale(GetScaleFactorForView(this))); |
653 | 658 |
654 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 659 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
655 gfx::Rect src_subrect_in_pixel = | 660 gfx::Rect src_subrect_in_pixel = |
656 ConvertRectToPixel(device_scale_factor, src_subrect); | 661 ConvertRectToPixel(device_scale_factor, src_subrect); |
657 | 662 |
658 if (using_synchronous_compositor_) { | 663 if (using_synchronous_compositor_) { |
659 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 664 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
660 return; | 665 return; |
661 } | 666 } |
662 scoped_ptr<cc::CopyOutputRequest> request; | 667 scoped_ptr<cc::CopyOutputRequest> request; |
663 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 668 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
664 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 669 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
665 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 670 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
666 dst_size_in_pixel, | 671 dst_size_in_pixel, |
667 callback)); | 672 callback)); |
668 } else { | 673 } else { |
669 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 674 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
670 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 675 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
671 dst_size_in_pixel, | 676 dst_size_in_pixel, |
672 readback_config_rgb565, | 677 bitmap_config, |
673 callback)); | 678 callback)); |
674 } | 679 } |
675 request->set_area(src_subrect_in_pixel); | 680 request->set_area(src_subrect_in_pixel); |
676 layer_->RequestCopyOfOutput(request.Pass()); | 681 layer_->RequestCopyOfOutput(request.Pass()); |
677 } | 682 } |
678 | 683 |
679 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 684 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
680 const gfx::Rect& src_subrect, | 685 const gfx::Rect& src_subrect, |
681 const scoped_refptr<media::VideoFrame>& target, | 686 const scoped_refptr<media::VideoFrame>& target, |
682 const base::Callback<void(bool)>& callback) { | 687 const base::Callback<void(bool)>& callback) { |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 texture_layer_->SetIsDrawable(false); | 1380 texture_layer_->SetIsDrawable(false); |
1376 if (delegated_renderer_layer_.get()) | 1381 if (delegated_renderer_layer_.get()) |
1377 DestroyDelegatedContent(); | 1382 DestroyDelegatedContent(); |
1378 texture_id_in_layer_ = 0; | 1383 texture_id_in_layer_ = 0; |
1379 RunAckCallbacks(); | 1384 RunAckCallbacks(); |
1380 } | 1385 } |
1381 | 1386 |
1382 // static | 1387 // static |
1383 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1388 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1384 const gfx::Size& dst_size_in_pixel, | 1389 const gfx::Size& dst_size_in_pixel, |
1385 bool readback_config_rgb565, | 1390 const SkBitmap::Config bitmap_config, |
1386 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1391 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1387 scoped_ptr<cc::CopyOutputResult> result) { | 1392 scoped_ptr<cc::CopyOutputResult> result) { |
1388 DCHECK(result->HasTexture()); | 1393 DCHECK(result->HasTexture()); |
1389 base::ScopedClosureRunner scoped_callback_runner( | 1394 base::ScopedClosureRunner scoped_callback_runner( |
1390 base::Bind(callback, false, SkBitmap())); | 1395 base::Bind(callback, false, SkBitmap())); |
1391 | 1396 |
1392 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1397 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1393 return; | 1398 return; |
1394 | 1399 |
1395 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1400 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1396 SkBitmap::Config bitmap_config = readback_config_rgb565 ? | |
1397 SkBitmap::kRGB_565_Config : | |
1398 SkBitmap::kARGB_8888_Config; | |
1399 bitmap->setConfig(bitmap_config, | 1401 bitmap->setConfig(bitmap_config, |
1400 dst_size_in_pixel.width(), | 1402 dst_size_in_pixel.width(), |
1401 dst_size_in_pixel.height(), | 1403 dst_size_in_pixel.height(), |
1402 0, kOpaque_SkAlphaType); | 1404 0, kOpaque_SkAlphaType); |
1403 if (!bitmap->allocPixels()) | 1405 if (!bitmap->allocPixels()) |
1404 return; | 1406 return; |
1405 | 1407 |
1406 ImageTransportFactoryAndroid* factory = | 1408 ImageTransportFactoryAndroid* factory = |
1407 ImageTransportFactoryAndroid::GetInstance(); | 1409 ImageTransportFactoryAndroid::GetInstance(); |
1408 GLHelper* gl_helper = factory->GetGLHelper(); | 1410 GLHelper* gl_helper = factory->GetGLHelper(); |
(...skipping 13 matching lines...) Expand all Loading... |
1422 | 1424 |
1423 ignore_result(scoped_callback_runner.Release()); | 1425 ignore_result(scoped_callback_runner.Release()); |
1424 | 1426 |
1425 gl_helper->CropScaleReadbackAndCleanMailbox( | 1427 gl_helper->CropScaleReadbackAndCleanMailbox( |
1426 texture_mailbox.name(), | 1428 texture_mailbox.name(), |
1427 texture_mailbox.sync_point(), | 1429 texture_mailbox.sync_point(), |
1428 result->size(), | 1430 result->size(), |
1429 gfx::Rect(result->size()), | 1431 gfx::Rect(result->size()), |
1430 dst_size_in_pixel, | 1432 dst_size_in_pixel, |
1431 pixels, | 1433 pixels, |
1432 readback_config_rgb565, | 1434 bitmap_config, |
1433 base::Bind(&CopyFromCompositingSurfaceFinished, | 1435 base::Bind(&CopyFromCompositingSurfaceFinished, |
1434 callback, | 1436 callback, |
1435 base::Passed(&release_callback), | 1437 base::Passed(&release_callback), |
1436 base::Passed(&bitmap), | 1438 base::Passed(&bitmap), |
1437 base::Passed(&bitmap_pixels_lock))); | 1439 base::Passed(&bitmap_pixels_lock))); |
1438 } | 1440 } |
1439 | 1441 |
1440 // static | 1442 // static |
1441 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1443 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1442 const gfx::Size& dst_size_in_pixel, | 1444 const gfx::Size& dst_size_in_pixel, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 // RenderWidgetHostView, public: | 1482 // RenderWidgetHostView, public: |
1481 | 1483 |
1482 // static | 1484 // static |
1483 RenderWidgetHostView* | 1485 RenderWidgetHostView* |
1484 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1486 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1485 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1487 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1486 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1488 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1487 } | 1489 } |
1488 | 1490 |
1489 } // namespace content | 1491 } // namespace content |
OLD | NEW |