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