| 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 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 586 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
| 587 RenderWidgetHostViewBase::SetBackground(background); | 587 RenderWidgetHostViewBase::SetBackground(background); |
| 588 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 588 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
| 589 } | 589 } |
| 590 | 590 |
| 591 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 591 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 592 const gfx::Rect& src_subrect, | 592 const gfx::Rect& src_subrect, |
| 593 const gfx::Size& dst_size, | 593 const gfx::Size& dst_size, |
| 594 const base::Callback<void(bool, const SkBitmap&)>& callback, | 594 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 595 const SkBitmap::Config bitmap_config) { | 595 const SkBitmap::Config bitmap_config) { |
| 596 // Only ARGB888 and RGB565 supported as of now. | 596 if (!IsReadbackConfigSupported(bitmap_config)) { |
| 597 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) || | |
| 598 (bitmap_config == SkBitmap::kARGB_8888_Config)); | |
| 599 if (!format_support) { | |
| 600 DCHECK(format_support); | |
| 601 callback.Run(false, SkBitmap()); | 597 callback.Run(false, SkBitmap()); |
| 602 return; | 598 return; |
| 603 } | 599 } |
| 604 base::TimeTicks start_time = base::TimeTicks::Now(); | 600 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 605 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 601 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
| 606 callback.Run(false, SkBitmap()); | 602 callback.Run(false, SkBitmap()); |
| 607 return; | 603 return; |
| 608 } | 604 } |
| 609 ImageTransportFactoryAndroid* factory = | |
| 610 ImageTransportFactoryAndroid::GetInstance(); | |
| 611 GLHelper* gl_helper = factory->GetGLHelper(); | |
| 612 if (!gl_helper) | |
| 613 return; | |
| 614 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); | |
| 615 if ((bitmap_config == SkBitmap::kRGB_565_Config) && | |
| 616 !check_rgb565_support) { | |
| 617 LOG(ERROR) << "Readbackformat rgb565 not supported"; | |
| 618 callback.Run(false, SkBitmap()); | |
| 619 return; | |
| 620 } | |
| 621 const gfx::Display& display = | 605 const gfx::Display& display = |
| 622 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 606 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 623 float device_scale_factor = display.device_scale_factor(); | 607 float device_scale_factor = display.device_scale_factor(); |
| 624 gfx::Size dst_size_in_pixel = | 608 gfx::Size dst_size_in_pixel = |
| 625 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 609 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
| 626 gfx::Rect src_subrect_in_pixel = | 610 gfx::Rect src_subrect_in_pixel = |
| 627 ConvertRectToPixel(device_scale_factor, src_subrect); | 611 ConvertRectToPixel(device_scale_factor, src_subrect); |
| 628 | 612 |
| 629 if (using_synchronous_compositor_) { | 613 if (using_synchronous_compositor_) { |
| 630 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 614 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 bitmap->setConfig(bitmap_config, | 1302 bitmap->setConfig(bitmap_config, |
| 1319 dst_size_in_pixel.width(), | 1303 dst_size_in_pixel.width(), |
| 1320 dst_size_in_pixel.height(), | 1304 dst_size_in_pixel.height(), |
| 1321 0, kOpaque_SkAlphaType); | 1305 0, kOpaque_SkAlphaType); |
| 1322 if (!bitmap->allocPixels()) | 1306 if (!bitmap->allocPixels()) |
| 1323 return; | 1307 return; |
| 1324 | 1308 |
| 1325 ImageTransportFactoryAndroid* factory = | 1309 ImageTransportFactoryAndroid* factory = |
| 1326 ImageTransportFactoryAndroid::GetInstance(); | 1310 ImageTransportFactoryAndroid::GetInstance(); |
| 1327 GLHelper* gl_helper = factory->GetGLHelper(); | 1311 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1312 |
| 1328 if (!gl_helper) | 1313 if (!gl_helper) |
| 1329 return; | 1314 return; |
| 1330 | 1315 |
| 1331 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1316 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 1332 new SkAutoLockPixels(*bitmap)); | 1317 new SkAutoLockPixels(*bitmap)); |
| 1333 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1318 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 1334 | 1319 |
| 1335 cc::TextureMailbox texture_mailbox; | 1320 cc::TextureMailbox texture_mailbox; |
| 1336 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1321 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
| 1337 result->TakeTexture(&texture_mailbox, &release_callback); | 1322 result->TakeTexture(&texture_mailbox, &release_callback); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); | 1369 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); |
| 1385 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); | 1370 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); |
| 1386 | 1371 |
| 1387 ignore_result(scoped_callback_runner.Release()); | 1372 ignore_result(scoped_callback_runner.Release()); |
| 1388 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, | 1373 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, |
| 1389 base::TimeTicks::Now() - start_time); | 1374 base::TimeTicks::Now() - start_time); |
| 1390 | 1375 |
| 1391 callback.Run(true, *source); | 1376 callback.Run(true, *source); |
| 1392 } | 1377 } |
| 1393 | 1378 |
| 1379 bool RenderWidgetHostViewAndroid::IsReadbackConfigSupported( |
| 1380 SkBitmap::Config bitmap_config) { |
| 1381 ImageTransportFactoryAndroid* factory = |
| 1382 ImageTransportFactoryAndroid::GetInstance(); |
| 1383 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1384 if (!gl_helper) |
| 1385 return false; |
| 1386 return gl_helper->IsReadbackConfigSupported(bitmap_config); |
| 1387 } |
| 1388 |
| 1394 // static | 1389 // static |
| 1395 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1390 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
| 1396 blink::WebScreenInfo* results) { | 1391 blink::WebScreenInfo* results) { |
| 1397 const gfx::Display& display = | 1392 const gfx::Display& display = |
| 1398 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1393 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 1399 results->rect = display.bounds(); | 1394 results->rect = display.bounds(); |
| 1400 // TODO(husky): Remove any system controls from availableRect. | 1395 // TODO(husky): Remove any system controls from availableRect. |
| 1401 results->availableRect = display.work_area(); | 1396 results->availableRect = display.work_area(); |
| 1402 results->deviceScaleFactor = display.device_scale_factor(); | 1397 results->deviceScaleFactor = display.device_scale_factor(); |
| 1403 gfx::DeviceDisplayInfo info; | 1398 gfx::DeviceDisplayInfo info; |
| 1404 results->depth = info.GetBitsPerPixel(); | 1399 results->depth = info.GetBitsPerPixel(); |
| 1405 results->depthPerComponent = info.GetBitsPerComponent(); | 1400 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1406 results->isMonochrome = (results->depthPerComponent == 0); | 1401 results->isMonochrome = (results->depthPerComponent == 0); |
| 1407 } | 1402 } |
| 1408 | 1403 |
| 1409 //////////////////////////////////////////////////////////////////////////////// | 1404 //////////////////////////////////////////////////////////////////////////////// |
| 1410 // RenderWidgetHostView, public: | 1405 // RenderWidgetHostView, public: |
| 1411 | 1406 |
| 1412 // static | 1407 // static |
| 1413 RenderWidgetHostView* | 1408 RenderWidgetHostView* |
| 1414 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1409 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1415 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1410 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1416 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1411 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1417 } | 1412 } |
| 1418 | 1413 |
| 1419 } // namespace content | 1414 } // namespace content |
| OLD | NEW |