Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 149123008: Implement GLHelperReadbackSupport for GLHelper usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid using SupportsFormat in between gl operations. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 if (!IsReadbackConfigSupported(bitmap_config)) {
629 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) ||
630 (bitmap_config == SkBitmap::kARGB_8888_Config));
631 if (!format_support) {
632 DCHECK(format_support);
633 callback.Run(false, SkBitmap()); 629 callback.Run(false, SkBitmap());
634 return; 630 return;
635 } 631 }
636 base::TimeTicks start_time = base::TimeTicks::Now(); 632 base::TimeTicks start_time = base::TimeTicks::Now();
637 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { 633 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) {
638 callback.Run(false, SkBitmap()); 634 callback.Run(false, SkBitmap());
639 return; 635 return;
640 } 636 }
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 = 637 const gfx::Display& display =
654 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 638 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
655 float device_scale_factor = display.device_scale_factor(); 639 float device_scale_factor = display.device_scale_factor();
656 gfx::Size dst_size_in_pixel = 640 gfx::Size dst_size_in_pixel =
657 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 641 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
658 gfx::Rect src_subrect_in_pixel = 642 gfx::Rect src_subrect_in_pixel =
659 ConvertRectToPixel(device_scale_factor, src_subrect); 643 ConvertRectToPixel(device_scale_factor, src_subrect);
660 644
661 if (using_synchronous_compositor_) { 645 if (using_synchronous_compositor_) {
662 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 646 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 bitmap->setConfig(bitmap_config, 1390 bitmap->setConfig(bitmap_config,
1407 dst_size_in_pixel.width(), 1391 dst_size_in_pixel.width(),
1408 dst_size_in_pixel.height(), 1392 dst_size_in_pixel.height(),
1409 0, kOpaque_SkAlphaType); 1393 0, kOpaque_SkAlphaType);
1410 if (!bitmap->allocPixels()) 1394 if (!bitmap->allocPixels())
1411 return; 1395 return;
1412 1396
1413 ImageTransportFactoryAndroid* factory = 1397 ImageTransportFactoryAndroid* factory =
1414 ImageTransportFactoryAndroid::GetInstance(); 1398 ImageTransportFactoryAndroid::GetInstance();
1415 GLHelper* gl_helper = factory->GetGLHelper(); 1399 GLHelper* gl_helper = factory->GetGLHelper();
1400
1416 if (!gl_helper) 1401 if (!gl_helper)
1417 return; 1402 return;
1418 1403
1419 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( 1404 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock(
1420 new SkAutoLockPixels(*bitmap)); 1405 new SkAutoLockPixels(*bitmap));
1421 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); 1406 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
1422 1407
1423 cc::TextureMailbox texture_mailbox; 1408 cc::TextureMailbox texture_mailbox;
1424 scoped_ptr<cc::SingleReleaseCallback> release_callback; 1409 scoped_ptr<cc::SingleReleaseCallback> release_callback;
1425 result->TakeTexture(&texture_mailbox, &release_callback); 1410 result->TakeTexture(&texture_mailbox, &release_callback);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); 1457 DCHECK_EQ(source->width(), dst_size_in_pixel.width());
1473 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); 1458 DCHECK_EQ(source->height(), dst_size_in_pixel.height());
1474 1459
1475 ignore_result(scoped_callback_runner.Release()); 1460 ignore_result(scoped_callback_runner.Release());
1476 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, 1461 UMA_HISTOGRAM_TIMES(kAsyncReadBackString,
1477 base::TimeTicks::Now() - start_time); 1462 base::TimeTicks::Now() - start_time);
1478 1463
1479 callback.Run(true, *source); 1464 callback.Run(true, *source);
1480 } 1465 }
1481 1466
1467 bool RenderWidgetHostViewAndroid::IsReadbackConfigSupported(
1468 SkBitmap::Config bitmap_config) {
1469 ImageTransportFactoryAndroid* factory =
1470 ImageTransportFactoryAndroid::GetInstance();
1471 GLHelper* gl_helper = factory->GetGLHelper();
1472 if (!gl_helper)
1473 return false;
1474 return gl_helper->IsReadbackConfigSupported(bitmap_config);
1475 }
1476
1482 // static 1477 // static
1483 void RenderWidgetHostViewPort::GetDefaultScreenInfo( 1478 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
1484 blink::WebScreenInfo* results) { 1479 blink::WebScreenInfo* results) {
1485 const gfx::Display& display = 1480 const gfx::Display& display =
1486 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 1481 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
1487 results->rect = display.bounds(); 1482 results->rect = display.bounds();
1488 // TODO(husky): Remove any system controls from availableRect. 1483 // TODO(husky): Remove any system controls from availableRect.
1489 results->availableRect = display.work_area(); 1484 results->availableRect = display.work_area();
1490 results->deviceScaleFactor = display.device_scale_factor(); 1485 results->deviceScaleFactor = display.device_scale_factor();
1491 gfx::DeviceDisplayInfo info; 1486 gfx::DeviceDisplayInfo info;
1492 results->depth = info.GetBitsPerPixel(); 1487 results->depth = info.GetBitsPerPixel();
1493 results->depthPerComponent = info.GetBitsPerComponent(); 1488 results->depthPerComponent = info.GetBitsPerComponent();
1494 results->isMonochrome = (results->depthPerComponent == 0); 1489 results->isMonochrome = (results->depthPerComponent == 0);
1495 } 1490 }
1496 1491
1497 //////////////////////////////////////////////////////////////////////////////// 1492 ////////////////////////////////////////////////////////////////////////////////
1498 // RenderWidgetHostView, public: 1493 // RenderWidgetHostView, public:
1499 1494
1500 // static 1495 // static
1501 RenderWidgetHostView* 1496 RenderWidgetHostView*
1502 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1497 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1503 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1498 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1504 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1499 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1505 } 1500 }
1506 1501
1507 } // namespace content 1502 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698