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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 618 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
619 RenderWidgetHostViewBase::SetBackground(background); | 619 RenderWidgetHostViewBase::SetBackground(background); |
620 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 620 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
621 } | 621 } |
622 | 622 |
623 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 623 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
624 const gfx::Rect& src_subrect, | 624 const gfx::Rect& src_subrect, |
625 const gfx::Size& dst_size, | 625 const gfx::Size& dst_size, |
626 const base::Callback<void(bool, const SkBitmap&)>& callback, | 626 const base::Callback<void(bool, const SkBitmap&)>& callback, |
627 const SkBitmap::Config bitmap_config) { | 627 const SkBitmap::Config bitmap_config) { |
628 // Only ARGB888 and RGB565 supported as of now. | 628 |
629 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | 629 if (!IsReadBackConfigSupported(bitmap_config)) { |
630 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
631 if (!format_support) { | |
632 DCHECK(format_support); | |
633 callback.Run(false, SkBitmap()); | 630 callback.Run(false, SkBitmap()); |
634 return; | 631 return; |
635 } | 632 } |
636 base::TimeTicks start_time = base::TimeTicks::Now(); | 633 base::TimeTicks start_time = base::TimeTicks::Now(); |
637 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 634 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
638 callback.Run(false, SkBitmap()); | 635 callback.Run(false, SkBitmap()); |
639 return; | 636 return; |
640 } | 637 } |
641 ImageTransportFactoryAndroid* factory = | |
642 ImageTransportFactoryAndroid::GetInstance(); | |
643 GLHelper* gl_helper = factory->GetGLHelper(); | |
644 if (!gl_helper) | |
645 return; | |
646 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | |
647 if ((bitmap_config == SkBitmap::kRGB_565_Config) && | |
648 !check_rgb565_support) { | |
649 LOG(ERROR) << "Readbackformat rgb565 not supported"; | |
650 callback.Run(false, SkBitmap()); | |
651 return; | |
652 } | |
653 const gfx::Display& display = | 638 const gfx::Display& display = |
654 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 639 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
655 float device_scale_factor = display.device_scale_factor(); | 640 float device_scale_factor = display.device_scale_factor(); |
656 gfx::Size dst_size_in_pixel = | 641 gfx::Size dst_size_in_pixel = |
657 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 642 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
658 gfx::Rect src_subrect_in_pixel = | 643 gfx::Rect src_subrect_in_pixel = |
659 ConvertRectToPixel(device_scale_factor, src_subrect); | 644 ConvertRectToPixel(device_scale_factor, src_subrect); |
660 | 645 |
661 if (using_synchronous_compositor_) { | 646 if (using_synchronous_compositor_) { |
662 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 647 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 bitmap->setConfig(bitmap_config, | 1391 bitmap->setConfig(bitmap_config, |
1407 dst_size_in_pixel.width(), | 1392 dst_size_in_pixel.width(), |
1408 dst_size_in_pixel.height(), | 1393 dst_size_in_pixel.height(), |
1409 0, kOpaque_SkAlphaType); | 1394 0, kOpaque_SkAlphaType); |
1410 if (!bitmap->allocPixels()) | 1395 if (!bitmap->allocPixels()) |
1411 return; | 1396 return; |
1412 | 1397 |
1413 ImageTransportFactoryAndroid* factory = | 1398 ImageTransportFactoryAndroid* factory = |
1414 ImageTransportFactoryAndroid::GetInstance(); | 1399 ImageTransportFactoryAndroid::GetInstance(); |
1415 GLHelper* gl_helper = factory->GetGLHelper(); | 1400 GLHelper* gl_helper = factory->GetGLHelper(); |
1401 | |
1416 if (!gl_helper) | 1402 if (!gl_helper) |
1417 return; | 1403 return; |
1418 | 1404 |
1419 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1405 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1420 new SkAutoLockPixels(*bitmap)); | 1406 new SkAutoLockPixels(*bitmap)); |
1421 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1407 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
1422 | 1408 |
1423 cc::TextureMailbox texture_mailbox; | 1409 cc::TextureMailbox texture_mailbox; |
1424 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1410 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
1425 result->TakeTexture(&texture_mailbox, &release_callback); | 1411 result->TakeTexture(&texture_mailbox, &release_callback); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); | 1458 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); |
1473 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); | 1459 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); |
1474 | 1460 |
1475 ignore_result(scoped_callback_runner.Release()); | 1461 ignore_result(scoped_callback_runner.Release()); |
1476 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 1462 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
1477 base::TimeTicks::Now() - start_time); | 1463 base::TimeTicks::Now() - start_time); |
1478 | 1464 |
1479 callback.Run(true, *source); | 1465 callback.Run(true, *source); |
1480 } | 1466 } |
1481 | 1467 |
1468 bool RenderWidgetHostViewAndroid::IsReadBackConfigSupported( | |
1469 const SkBitmap::Config& bitmap_config) { | |
vivekg
2014/02/20 00:53:31
nit: As SkBitmap::Config is an enum, pass it by va
sivag
2014/02/21 11:40:51
Done.
| |
1470 ImageTransportFactoryAndroid* factory = | |
1471 ImageTransportFactoryAndroid::GetInstance(); | |
1472 GLHelper* gl_helper = factory->GetGLHelper(); | |
1473 if (!gl_helper) | |
1474 return false; | |
1475 return gl_helper->IsReadBackConfigSupported(bitmap_config); | |
1476 } | |
1477 | |
1482 // static | 1478 // static |
1483 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1479 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
1484 blink::WebScreenInfo* results) { | 1480 blink::WebScreenInfo* results) { |
1485 const gfx::Display& display = | 1481 const gfx::Display& display = |
1486 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1482 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
1487 results->rect = display.bounds(); | 1483 results->rect = display.bounds(); |
1488 // TODO(husky): Remove any system controls from availableRect. | 1484 // TODO(husky): Remove any system controls from availableRect. |
1489 results->availableRect = display.work_area(); | 1485 results->availableRect = display.work_area(); |
1490 results->deviceScaleFactor = display.device_scale_factor(); | 1486 results->deviceScaleFactor = display.device_scale_factor(); |
1491 gfx::DeviceDisplayInfo info; | 1487 gfx::DeviceDisplayInfo info; |
1492 results->depth = info.GetBitsPerPixel(); | 1488 results->depth = info.GetBitsPerPixel(); |
1493 results->depthPerComponent = info.GetBitsPerComponent(); | 1489 results->depthPerComponent = info.GetBitsPerComponent(); |
1494 results->isMonochrome = (results->depthPerComponent == 0); | 1490 results->isMonochrome = (results->depthPerComponent == 0); |
1495 } | 1491 } |
1496 | 1492 |
1497 //////////////////////////////////////////////////////////////////////////////// | 1493 //////////////////////////////////////////////////////////////////////////////// |
1498 // RenderWidgetHostView, public: | 1494 // RenderWidgetHostView, public: |
1499 | 1495 |
1500 // static | 1496 // static |
1501 RenderWidgetHostView* | 1497 RenderWidgetHostView* |
1502 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1498 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1503 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1499 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1504 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1500 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1505 } | 1501 } |
1506 | 1502 |
1507 } // namespace content | 1503 } // namespace content |
OLD | NEW |