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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 const SkBitmap::Config bitmap_config) { | 635 const SkBitmap::Config bitmap_config) { |
636 // Only ARGB888 and RGB565 supported as of now. | 636 |
637 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | 637 if (!IsReadBackConfigSupported(bitmap_config)) { |
638 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
639 if (!format_support) { | |
640 DCHECK(format_support); | |
641 callback.Run(false, SkBitmap()); | 638 callback.Run(false, SkBitmap()); |
642 return; | 639 return; |
643 } | 640 } |
644 base::TimeTicks start_time = base::TimeTicks::Now(); | 641 base::TimeTicks start_time = base::TimeTicks::Now(); |
645 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 642 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
646 callback.Run(false, SkBitmap()); | 643 callback.Run(false, SkBitmap()); |
647 return; | 644 return; |
648 } | 645 } |
649 ImageTransportFactoryAndroid* factory = | |
650 ImageTransportFactoryAndroid::GetInstance(); | |
651 GLHelper* gl_helper = factory->GetGLHelper(); | |
652 if (!gl_helper) | |
653 return; | |
654 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | |
655 if ((bitmap_config == SkBitmap::kRGB_565_Config) && | |
656 !check_rgb565_support) { | |
657 LOG(ERROR) << "Readbackformat rgb565 not supported"; | |
658 callback.Run(false, SkBitmap()); | |
659 return; | |
660 } | |
661 const gfx::Display& display = | 646 const gfx::Display& display = |
662 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 647 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
663 float device_scale_factor = display.device_scale_factor(); | 648 float device_scale_factor = display.device_scale_factor(); |
664 gfx::Size dst_size_in_pixel = | 649 gfx::Size dst_size_in_pixel = |
665 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 650 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
666 gfx::Rect src_subrect_in_pixel = | 651 gfx::Rect src_subrect_in_pixel = |
667 ConvertRectToPixel(device_scale_factor, src_subrect); | 652 ConvertRectToPixel(device_scale_factor, src_subrect); |
668 | 653 |
669 if (using_synchronous_compositor_) { | 654 if (using_synchronous_compositor_) { |
670 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 655 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1400 // static | 1385 // static |
1401 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1386 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1402 const gfx::Size& dst_size_in_pixel, | 1387 const gfx::Size& dst_size_in_pixel, |
1403 const SkBitmap::Config bitmap_config, | 1388 const SkBitmap::Config bitmap_config, |
1404 const base::TimeTicks& start_time, | 1389 const base::TimeTicks& start_time, |
1405 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1390 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1406 scoped_ptr<cc::CopyOutputResult> result) { | 1391 scoped_ptr<cc::CopyOutputResult> result) { |
1407 base::ScopedClosureRunner scoped_callback_runner( | 1392 base::ScopedClosureRunner scoped_callback_runner( |
1408 base::Bind(callback, false, SkBitmap())); | 1393 base::Bind(callback, false, SkBitmap())); |
1409 | 1394 |
1410 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1395 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) { |
1396 callback.Run(false, SkBitmap()); | |
no sievers
2014/02/18 19:35:44
You don't need to change all of these. That's what
sivag
2014/02/19 15:49:04
Done.
| |
1411 return; | 1397 return; |
1398 } | |
1412 | 1399 |
1413 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1400 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1414 bitmap->setConfig(bitmap_config, | 1401 bitmap->setConfig(bitmap_config, |
1415 dst_size_in_pixel.width(), | 1402 dst_size_in_pixel.width(), |
1416 dst_size_in_pixel.height(), | 1403 dst_size_in_pixel.height(), |
1417 0, kOpaque_SkAlphaType); | 1404 0, kOpaque_SkAlphaType); |
1418 if (!bitmap->allocPixels()) | 1405 if (!bitmap->allocPixels()) { |
1406 callback.Run(false, SkBitmap()); | |
1419 return; | 1407 return; |
1408 } | |
1420 | 1409 |
1421 ImageTransportFactoryAndroid* factory = | 1410 ImageTransportFactoryAndroid* factory = |
1422 ImageTransportFactoryAndroid::GetInstance(); | 1411 ImageTransportFactoryAndroid::GetInstance(); |
1423 GLHelper* gl_helper = factory->GetGLHelper(); | 1412 GLHelper* gl_helper = factory->GetGLHelper(); |
1424 if (!gl_helper) | 1413 |
1414 if (!gl_helper) { | |
1415 callback.Run(false, SkBitmap()); | |
1425 return; | 1416 return; |
1417 } | |
1426 | 1418 |
1427 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1419 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1428 new SkAutoLockPixels(*bitmap)); | 1420 new SkAutoLockPixels(*bitmap)); |
1429 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1421 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
1430 | 1422 |
1431 cc::TextureMailbox texture_mailbox; | 1423 cc::TextureMailbox texture_mailbox; |
1432 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1424 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
1433 result->TakeTexture(&texture_mailbox, &release_callback); | 1425 result->TakeTexture(&texture_mailbox, &release_callback); |
1434 DCHECK(texture_mailbox.IsTexture()); | 1426 DCHECK(texture_mailbox.IsTexture()); |
1435 if (!texture_mailbox.IsTexture()) | 1427 if (!texture_mailbox.IsTexture()) { |
1428 callback.Run(false, SkBitmap()); | |
1436 return; | 1429 return; |
1430 } | |
1437 | 1431 |
1438 ignore_result(scoped_callback_runner.Release()); | 1432 ignore_result(scoped_callback_runner.Release()); |
1439 | 1433 |
1440 gl_helper->CropScaleReadbackAndCleanMailbox( | 1434 gl_helper->CropScaleReadbackAndCleanMailbox( |
1441 texture_mailbox.mailbox(), | 1435 texture_mailbox.mailbox(), |
1442 texture_mailbox.sync_point(), | 1436 texture_mailbox.sync_point(), |
1443 result->size(), | 1437 result->size(), |
1444 gfx::Rect(result->size()), | 1438 gfx::Rect(result->size()), |
1445 dst_size_in_pixel, | 1439 dst_size_in_pixel, |
1446 pixels, | 1440 pixels, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); | 1474 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); |
1481 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); | 1475 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); |
1482 | 1476 |
1483 ignore_result(scoped_callback_runner.Release()); | 1477 ignore_result(scoped_callback_runner.Release()); |
1484 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 1478 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
1485 base::TimeTicks::Now() - start_time); | 1479 base::TimeTicks::Now() - start_time); |
1486 | 1480 |
1487 callback.Run(true, *source); | 1481 callback.Run(true, *source); |
1488 } | 1482 } |
1489 | 1483 |
1484 bool RenderWidgetHostViewAndroid::IsReadBackConfigSupported( | |
1485 const SkBitmap::Config& bitmap_config) { | |
1486 ImageTransportFactoryAndroid* factory = | |
1487 ImageTransportFactoryAndroid::GetInstance(); | |
1488 GLHelper* gl_helper = factory->GetGLHelper(); | |
1489 if (!gl_helper) | |
1490 return false; | |
1491 return gl_helper->IsReadBackConfigSupported(bitmap_config); | |
1492 } | |
1493 | |
1490 // static | 1494 // static |
1491 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1495 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1492 blink::WebScreenInfo* results) { | 1496 blink::WebScreenInfo* results) { |
1493 const gfx::Display& display = | 1497 const gfx::Display& display = |
1494 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1498 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
1495 results->rect = display.bounds(); | 1499 results->rect = display.bounds(); |
1496 // TODO(husky): Remove any system controls from availableRect. | 1500 // TODO(husky): Remove any system controls from availableRect. |
1497 results->availableRect = display.work_area(); | 1501 results->availableRect = display.work_area(); |
1498 results->deviceScaleFactor = display.device_scale_factor(); | 1502 results->deviceScaleFactor = display.device_scale_factor(); |
1499 gfx::DeviceDisplayInfo info; | 1503 gfx::DeviceDisplayInfo info; |
1500 results->depth = info.GetBitsPerPixel(); | 1504 results->depth = info.GetBitsPerPixel(); |
1501 results->depthPerComponent = info.GetBitsPerComponent(); | 1505 results->depthPerComponent = info.GetBitsPerComponent(); |
1502 results->isMonochrome = (results->depthPerComponent == 0); | 1506 results->isMonochrome = (results->depthPerComponent == 0); |
1503 } | 1507 } |
1504 | 1508 |
1505 //////////////////////////////////////////////////////////////////////////////// | 1509 //////////////////////////////////////////////////////////////////////////////// |
1506 // RenderWidgetHostView, public: | 1510 // RenderWidgetHostView, public: |
1507 | 1511 |
1508 // static | 1512 // static |
1509 RenderWidgetHostView* | 1513 RenderWidgetHostView* |
1510 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1514 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1511 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1515 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1512 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1516 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1513 } | 1517 } |
1514 | 1518 |
1515 } // namespace content | 1519 } // namespace content |
OLD | NEW |