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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 } | 597 } |
598 | 598 |
599 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 599 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
600 RenderWidgetHostViewBase::SetBackground(background); | 600 RenderWidgetHostViewBase::SetBackground(background); |
601 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 601 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
602 } | 602 } |
603 | 603 |
604 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 604 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
605 const gfx::Rect& src_subrect, | 605 const gfx::Rect& src_subrect, |
606 const gfx::Size& dst_size, | 606 const gfx::Size& dst_size, |
607 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 607 const base::Callback<void(bool, const SkBitmap&)>& callback, |
608 bool readback_config_rgb565) { | |
608 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 609 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
609 callback.Run(false, SkBitmap()); | 610 callback.Run(false, SkBitmap()); |
610 return; | 611 return; |
611 } | 612 } |
612 | 613 ImageTransportFactoryAndroid* factory = |
614 ImageTransportFactoryAndroid::GetInstance(); | |
615 GLHelper* gl_helper = factory->GetGLHelper(); | |
616 if (!gl_helper) | |
617 return; | |
618 static bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | |
piman
2014/01/09 18:12:15
Why static?
Maybe you want to cache this in the GL
sivag
2014/01/10 12:20:01
Done.
Cached the 565 support status using member v
| |
619 if(readback_config_rgb565 && !check_rgb565_support){ | |
piman
2014/01/09 18:12:15
nit: space before ( and after )
sivag
2014/01/10 12:20:01
Done
| |
620 LOG(ERROR) << "Readbackformat rgb565 not supported"; | |
621 callback.Run(false, SkBitmap()); | |
622 return; | |
623 } | |
613 const gfx::Display& display = | 624 const gfx::Display& display = |
614 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 625 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
615 float device_scale_factor = display.device_scale_factor(); | 626 float device_scale_factor = display.device_scale_factor(); |
616 | 627 |
617 DCHECK_EQ(device_scale_factor, | 628 DCHECK_EQ(device_scale_factor, |
618 ui::GetImageScale(GetScaleFactorForView(this))); | 629 ui::GetImageScale(GetScaleFactorForView(this))); |
619 | 630 |
620 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 631 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
621 gfx::Rect src_subrect_in_pixel = | 632 gfx::Rect src_subrect_in_pixel = |
622 ConvertRectToPixel(device_scale_factor, src_subrect); | 633 ConvertRectToPixel(device_scale_factor, src_subrect); |
623 | 634 |
624 if (using_synchronous_compositor_) { | 635 if (using_synchronous_compositor_) { |
625 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 636 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
626 return; | 637 return; |
627 } | 638 } |
628 | |
629 scoped_ptr<cc::CopyOutputRequest> request; | 639 scoped_ptr<cc::CopyOutputRequest> request; |
630 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 640 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
631 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 641 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
632 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 642 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
633 dst_size_in_pixel, | 643 dst_size_in_pixel, |
634 callback)); | 644 callback)); |
635 } else { | 645 } else { |
636 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 646 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
637 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 647 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
638 dst_size_in_pixel, | 648 dst_size_in_pixel, |
649 readback_config_rgb565, | |
639 callback)); | 650 callback)); |
640 } | 651 } |
641 request->set_area(src_subrect_in_pixel); | 652 request->set_area(src_subrect_in_pixel); |
642 layer_->RequestCopyOfOutput(request.Pass()); | 653 layer_->RequestCopyOfOutput(request.Pass()); |
643 } | 654 } |
644 | 655 |
645 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 656 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
646 const gfx::Rect& src_subrect, | 657 const gfx::Rect& src_subrect, |
647 const scoped_refptr<media::VideoFrame>& target, | 658 const scoped_refptr<media::VideoFrame>& target, |
648 const base::Callback<void(bool)>& callback) { | 659 const base::Callback<void(bool)>& callback) { |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1332 texture_layer_->SetIsDrawable(false); | 1343 texture_layer_->SetIsDrawable(false); |
1333 if (delegated_renderer_layer_.get()) | 1344 if (delegated_renderer_layer_.get()) |
1334 DestroyDelegatedContent(); | 1345 DestroyDelegatedContent(); |
1335 texture_id_in_layer_ = 0; | 1346 texture_id_in_layer_ = 0; |
1336 RunAckCallbacks(); | 1347 RunAckCallbacks(); |
1337 } | 1348 } |
1338 | 1349 |
1339 // static | 1350 // static |
1340 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1351 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1341 const gfx::Size& dst_size_in_pixel, | 1352 const gfx::Size& dst_size_in_pixel, |
1353 bool readback_config_rgb565, | |
1342 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1354 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1343 scoped_ptr<cc::CopyOutputResult> result) { | 1355 scoped_ptr<cc::CopyOutputResult> result) { |
1344 DCHECK(result->HasTexture()); | 1356 DCHECK(result->HasTexture()); |
1345 base::ScopedClosureRunner scoped_callback_runner( | 1357 base::ScopedClosureRunner scoped_callback_runner( |
1346 base::Bind(callback, false, SkBitmap())); | 1358 base::Bind(callback, false, SkBitmap())); |
1347 | 1359 |
1348 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1360 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1349 return; | 1361 return; |
1350 | 1362 |
1351 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1363 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1352 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1364 SkBitmap::Config bitmap_config = readback_config_rgb565 ? |
1353 dst_size_in_pixel.width(), dst_size_in_pixel.height(), | 1365 SkBitmap::kRGB_565_Config : |
1366 SkBitmap::kARGB_8888_Config; | |
1367 bitmap->setConfig(bitmap_config, | |
1368 dst_size_in_pixel.width(), | |
1369 dst_size_in_pixel.height(), | |
1354 0, kOpaque_SkAlphaType); | 1370 0, kOpaque_SkAlphaType); |
1355 if (!bitmap->allocPixels()) | 1371 if (!bitmap->allocPixels()) |
1356 return; | 1372 return; |
1357 | 1373 |
1358 ImageTransportFactoryAndroid* factory = | 1374 ImageTransportFactoryAndroid* factory = |
1359 ImageTransportFactoryAndroid::GetInstance(); | 1375 ImageTransportFactoryAndroid::GetInstance(); |
1360 GLHelper* gl_helper = factory->GetGLHelper(); | 1376 GLHelper* gl_helper = factory->GetGLHelper(); |
1361 if (!gl_helper) | 1377 if (!gl_helper) |
1362 return; | 1378 return; |
1363 | 1379 |
(...skipping 10 matching lines...) Expand all Loading... | |
1374 | 1390 |
1375 ignore_result(scoped_callback_runner.Release()); | 1391 ignore_result(scoped_callback_runner.Release()); |
1376 | 1392 |
1377 gl_helper->CropScaleReadbackAndCleanMailbox( | 1393 gl_helper->CropScaleReadbackAndCleanMailbox( |
1378 texture_mailbox.name(), | 1394 texture_mailbox.name(), |
1379 texture_mailbox.sync_point(), | 1395 texture_mailbox.sync_point(), |
1380 result->size(), | 1396 result->size(), |
1381 gfx::Rect(result->size()), | 1397 gfx::Rect(result->size()), |
1382 dst_size_in_pixel, | 1398 dst_size_in_pixel, |
1383 pixels, | 1399 pixels, |
1400 readback_config_rgb565, | |
1384 base::Bind(&CopyFromCompositingSurfaceFinished, | 1401 base::Bind(&CopyFromCompositingSurfaceFinished, |
1385 callback, | 1402 callback, |
1386 base::Passed(&release_callback), | 1403 base::Passed(&release_callback), |
1387 base::Passed(&bitmap), | 1404 base::Passed(&bitmap), |
1388 base::Passed(&bitmap_pixels_lock))); | 1405 base::Passed(&bitmap_pixels_lock))); |
1389 } | 1406 } |
1390 | 1407 |
1391 // static | 1408 // static |
1392 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1409 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1393 const gfx::Size& dst_size_in_pixel, | 1410 const gfx::Size& dst_size_in_pixel, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1431 // RenderWidgetHostView, public: | 1448 // RenderWidgetHostView, public: |
1432 | 1449 |
1433 // static | 1450 // static |
1434 RenderWidgetHostView* | 1451 RenderWidgetHostView* |
1435 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1452 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1436 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1453 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1437 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1454 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1438 } | 1455 } |
1439 | 1456 |
1440 } // namespace content | 1457 } // namespace content |
OLD | NEW |