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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 texture_id_in_layer_, | 299 texture_id_in_layer_, |
300 texture_size_in_layer_, | 300 texture_size_in_layer_, |
301 bitmap.size(), | 301 bitmap.size(), |
302 true, | 302 true, |
303 GLHelper::SCALER_QUALITY_FAST); | 303 GLHelper::SCALER_QUALITY_FAST); |
304 if (texture == 0u) | 304 if (texture == 0u) |
305 return false; | 305 return false; |
306 | 306 |
307 helper->ReadbackTextureSync(texture, | 307 helper->ReadbackTextureSync(texture, |
308 gfx::Rect(bitmap.size()), | 308 gfx::Rect(bitmap.size()), |
309 static_cast<unsigned char*> (bitmap.pixels())); | 309 static_cast<unsigned char*> (bitmap.pixels()), |
| 310 SkBitmap::kARGB_8888_Config); |
310 | 311 |
311 gpu::gles2::GLES2Interface* gl = | 312 gpu::gles2::GLES2Interface* gl = |
312 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); | 313 ImageTransportFactoryAndroid::GetInstance()->GetContextGL(); |
313 gl->DeleteTextures(1, &texture); | 314 gl->DeleteTextures(1, &texture); |
314 | 315 |
315 return true; | 316 return true; |
316 } | 317 } |
317 | 318 |
318 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 319 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
319 if (!content_view_core_) | 320 if (!content_view_core_) |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 } | 620 } |
620 | 621 |
621 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 622 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
622 RenderWidgetHostViewBase::SetBackground(background); | 623 RenderWidgetHostViewBase::SetBackground(background); |
623 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 624 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
624 } | 625 } |
625 | 626 |
626 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 627 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
627 const gfx::Rect& src_subrect, | 628 const gfx::Rect& src_subrect, |
628 const gfx::Size& dst_size, | 629 const gfx::Size& dst_size, |
629 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 630 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 631 bool readback_config_rgb565) { |
630 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 632 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
631 callback.Run(false, SkBitmap()); | 633 callback.Run(false, SkBitmap()); |
632 return; | 634 return; |
633 } | 635 } |
634 | 636 ImageTransportFactoryAndroid* factory = |
| 637 ImageTransportFactoryAndroid::GetInstance(); |
| 638 GLHelper* gl_helper = factory->GetGLHelper(); |
| 639 if (!gl_helper) |
| 640 return; |
| 641 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); |
| 642 if (readback_config_rgb565 && !check_rgb565_support) { |
| 643 LOG(ERROR) << "Readbackformat rgb565 not supported"; |
| 644 callback.Run(false, SkBitmap()); |
| 645 return; |
| 646 } |
635 const gfx::Display& display = | 647 const gfx::Display& display = |
636 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 648 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
637 float device_scale_factor = display.device_scale_factor(); | 649 float device_scale_factor = display.device_scale_factor(); |
638 | 650 |
639 DCHECK_EQ(device_scale_factor, | 651 DCHECK_EQ(device_scale_factor, |
640 ui::GetImageScale(GetScaleFactorForView(this))); | 652 ui::GetImageScale(GetScaleFactorForView(this))); |
641 | 653 |
642 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 654 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
643 gfx::Rect src_subrect_in_pixel = | 655 gfx::Rect src_subrect_in_pixel = |
644 ConvertRectToPixel(device_scale_factor, src_subrect); | 656 ConvertRectToPixel(device_scale_factor, src_subrect); |
645 | 657 |
646 if (using_synchronous_compositor_) { | 658 if (using_synchronous_compositor_) { |
647 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 659 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
648 return; | 660 return; |
649 } | 661 } |
650 | |
651 scoped_ptr<cc::CopyOutputRequest> request; | 662 scoped_ptr<cc::CopyOutputRequest> request; |
652 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 663 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
653 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 664 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
654 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 665 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
655 dst_size_in_pixel, | 666 dst_size_in_pixel, |
656 callback)); | 667 callback)); |
657 } else { | 668 } else { |
658 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 669 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
659 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 670 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
660 dst_size_in_pixel, | 671 dst_size_in_pixel, |
| 672 readback_config_rgb565, |
661 callback)); | 673 callback)); |
662 } | 674 } |
663 request->set_area(src_subrect_in_pixel); | 675 request->set_area(src_subrect_in_pixel); |
664 layer_->RequestCopyOfOutput(request.Pass()); | 676 layer_->RequestCopyOfOutput(request.Pass()); |
665 } | 677 } |
666 | 678 |
667 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 679 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
668 const gfx::Rect& src_subrect, | 680 const gfx::Rect& src_subrect, |
669 const scoped_refptr<media::VideoFrame>& target, | 681 const scoped_refptr<media::VideoFrame>& target, |
670 const base::Callback<void(bool)>& callback) { | 682 const base::Callback<void(bool)>& callback) { |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 texture_layer_->SetIsDrawable(false); | 1375 texture_layer_->SetIsDrawable(false); |
1364 if (delegated_renderer_layer_.get()) | 1376 if (delegated_renderer_layer_.get()) |
1365 DestroyDelegatedContent(); | 1377 DestroyDelegatedContent(); |
1366 texture_id_in_layer_ = 0; | 1378 texture_id_in_layer_ = 0; |
1367 RunAckCallbacks(); | 1379 RunAckCallbacks(); |
1368 } | 1380 } |
1369 | 1381 |
1370 // static | 1382 // static |
1371 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1383 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1372 const gfx::Size& dst_size_in_pixel, | 1384 const gfx::Size& dst_size_in_pixel, |
| 1385 bool readback_config_rgb565, |
1373 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1386 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1374 scoped_ptr<cc::CopyOutputResult> result) { | 1387 scoped_ptr<cc::CopyOutputResult> result) { |
1375 DCHECK(result->HasTexture()); | 1388 DCHECK(result->HasTexture()); |
1376 base::ScopedClosureRunner scoped_callback_runner( | 1389 base::ScopedClosureRunner scoped_callback_runner( |
1377 base::Bind(callback, false, SkBitmap())); | 1390 base::Bind(callback, false, SkBitmap())); |
1378 | 1391 |
1379 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1392 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1380 return; | 1393 return; |
1381 | 1394 |
1382 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1395 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1383 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1396 SkBitmap::Config bitmap_config = readback_config_rgb565 ? |
1384 dst_size_in_pixel.width(), dst_size_in_pixel.height(), | 1397 SkBitmap::kRGB_565_Config : |
| 1398 SkBitmap::kARGB_8888_Config; |
| 1399 bitmap->setConfig(bitmap_config, |
| 1400 dst_size_in_pixel.width(), |
| 1401 dst_size_in_pixel.height(), |
1385 0, kOpaque_SkAlphaType); | 1402 0, kOpaque_SkAlphaType); |
1386 if (!bitmap->allocPixels()) | 1403 if (!bitmap->allocPixels()) |
1387 return; | 1404 return; |
1388 | 1405 |
1389 ImageTransportFactoryAndroid* factory = | 1406 ImageTransportFactoryAndroid* factory = |
1390 ImageTransportFactoryAndroid::GetInstance(); | 1407 ImageTransportFactoryAndroid::GetInstance(); |
1391 GLHelper* gl_helper = factory->GetGLHelper(); | 1408 GLHelper* gl_helper = factory->GetGLHelper(); |
1392 if (!gl_helper) | 1409 if (!gl_helper) |
1393 return; | 1410 return; |
1394 | 1411 |
(...skipping 10 matching lines...) Expand all Loading... |
1405 | 1422 |
1406 ignore_result(scoped_callback_runner.Release()); | 1423 ignore_result(scoped_callback_runner.Release()); |
1407 | 1424 |
1408 gl_helper->CropScaleReadbackAndCleanMailbox( | 1425 gl_helper->CropScaleReadbackAndCleanMailbox( |
1409 texture_mailbox.mailbox(), | 1426 texture_mailbox.mailbox(), |
1410 texture_mailbox.sync_point(), | 1427 texture_mailbox.sync_point(), |
1411 result->size(), | 1428 result->size(), |
1412 gfx::Rect(result->size()), | 1429 gfx::Rect(result->size()), |
1413 dst_size_in_pixel, | 1430 dst_size_in_pixel, |
1414 pixels, | 1431 pixels, |
| 1432 readback_config_rgb565, |
1415 base::Bind(&CopyFromCompositingSurfaceFinished, | 1433 base::Bind(&CopyFromCompositingSurfaceFinished, |
1416 callback, | 1434 callback, |
1417 base::Passed(&release_callback), | 1435 base::Passed(&release_callback), |
1418 base::Passed(&bitmap), | 1436 base::Passed(&bitmap), |
1419 base::Passed(&bitmap_pixels_lock))); | 1437 base::Passed(&bitmap_pixels_lock))); |
1420 } | 1438 } |
1421 | 1439 |
1422 // static | 1440 // static |
1423 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1441 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1424 const gfx::Size& dst_size_in_pixel, | 1442 const gfx::Size& dst_size_in_pixel, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 // RenderWidgetHostView, public: | 1480 // RenderWidgetHostView, public: |
1463 | 1481 |
1464 // static | 1482 // static |
1465 RenderWidgetHostView* | 1483 RenderWidgetHostView* |
1466 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1484 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1467 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1485 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1468 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1486 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1469 } | 1487 } |
1470 | 1488 |
1471 } // namespace content | 1489 } // namespace content |
OLD | NEW |