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

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: Code changed as per review comments. Created 6 years, 9 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 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { 616 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) {
617 RenderWidgetHostViewBase::SetBackground(background); 617 RenderWidgetHostViewBase::SetBackground(background);
618 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); 618 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
619 } 619 }
620 620
621 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 621 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
622 const gfx::Rect& src_subrect, 622 const gfx::Rect& src_subrect,
623 const gfx::Size& dst_size, 623 const gfx::Size& dst_size,
624 const base::Callback<void(bool, const SkBitmap&)>& callback, 624 const base::Callback<void(bool, const SkBitmap&)>& callback,
625 const SkBitmap::Config bitmap_config) { 625 const SkBitmap::Config bitmap_config) {
626 // Only ARGB888 and RGB565 supported as of now. 626 if (!IsReadbackConfigSupported(bitmap_config)) {
627 bool format_support = ((bitmap_config == SkBitmap::kRGB_565_Config) ||
628 (bitmap_config == SkBitmap::kARGB_8888_Config));
629 if (!format_support) {
630 DCHECK(format_support);
631 callback.Run(false, SkBitmap()); 627 callback.Run(false, SkBitmap());
632 return; 628 return;
633 } 629 }
634 base::TimeTicks start_time = base::TimeTicks::Now(); 630 base::TimeTicks start_time = base::TimeTicks::Now();
635 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { 631 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) {
636 callback.Run(false, SkBitmap()); 632 callback.Run(false, SkBitmap());
637 return; 633 return;
638 } 634 }
639 ImageTransportFactoryAndroid* factory =
640 ImageTransportFactoryAndroid::GetInstance();
641 GLHelper* gl_helper = factory->GetGLHelper();
642 if (!gl_helper)
643 return;
644 bool check_rgb565_support = gl_helper->CanUseRgb565Readback();
645 if ((bitmap_config == SkBitmap::kRGB_565_Config) &&
646 !check_rgb565_support) {
647 LOG(ERROR) << "Readbackformat rgb565 not supported";
648 callback.Run(false, SkBitmap());
649 return;
650 }
651 const gfx::Display& display = 635 const gfx::Display& display =
652 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 636 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
653 float device_scale_factor = display.device_scale_factor(); 637 float device_scale_factor = display.device_scale_factor();
654 gfx::Size dst_size_in_pixel = 638 gfx::Size dst_size_in_pixel =
655 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); 639 ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size();
656 gfx::Rect src_subrect_in_pixel = 640 gfx::Rect src_subrect_in_pixel =
657 ConvertRectToPixel(device_scale_factor, src_subrect); 641 ConvertRectToPixel(device_scale_factor, src_subrect);
658 642
659 if (using_synchronous_compositor_) { 643 if (using_synchronous_compositor_) {
660 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, 644 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback,
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 bitmap->setConfig(bitmap_config, 1332 bitmap->setConfig(bitmap_config,
1349 dst_size_in_pixel.width(), 1333 dst_size_in_pixel.width(),
1350 dst_size_in_pixel.height(), 1334 dst_size_in_pixel.height(),
1351 0, kOpaque_SkAlphaType); 1335 0, kOpaque_SkAlphaType);
1352 if (!bitmap->allocPixels()) 1336 if (!bitmap->allocPixels())
1353 return; 1337 return;
1354 1338
1355 ImageTransportFactoryAndroid* factory = 1339 ImageTransportFactoryAndroid* factory =
1356 ImageTransportFactoryAndroid::GetInstance(); 1340 ImageTransportFactoryAndroid::GetInstance();
1357 GLHelper* gl_helper = factory->GetGLHelper(); 1341 GLHelper* gl_helper = factory->GetGLHelper();
1342
1358 if (!gl_helper) 1343 if (!gl_helper)
1359 return; 1344 return;
1360 1345
1361 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( 1346 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock(
1362 new SkAutoLockPixels(*bitmap)); 1347 new SkAutoLockPixels(*bitmap));
1363 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); 1348 uint8* pixels = static_cast<uint8*>(bitmap->getPixels());
1364 1349
1365 cc::TextureMailbox texture_mailbox; 1350 cc::TextureMailbox texture_mailbox;
1366 scoped_ptr<cc::SingleReleaseCallback> release_callback; 1351 scoped_ptr<cc::SingleReleaseCallback> release_callback;
1367 result->TakeTexture(&texture_mailbox, &release_callback); 1352 result->TakeTexture(&texture_mailbox, &release_callback);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); 1399 DCHECK_EQ(source->width(), dst_size_in_pixel.width());
1415 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); 1400 DCHECK_EQ(source->height(), dst_size_in_pixel.height());
1416 1401
1417 ignore_result(scoped_callback_runner.Release()); 1402 ignore_result(scoped_callback_runner.Release());
1418 UMA_HISTOGRAM_TIMES(kAsyncReadBackString, 1403 UMA_HISTOGRAM_TIMES(kAsyncReadBackString,
1419 base::TimeTicks::Now() - start_time); 1404 base::TimeTicks::Now() - start_time);
1420 1405
1421 callback.Run(true, *source); 1406 callback.Run(true, *source);
1422 } 1407 }
1423 1408
1409 bool RenderWidgetHostViewAndroid::IsReadbackConfigSupported(
1410 SkBitmap::Config bitmap_config) {
1411 ImageTransportFactoryAndroid* factory =
1412 ImageTransportFactoryAndroid::GetInstance();
1413 GLHelper* gl_helper = factory->GetGLHelper();
1414 if (!gl_helper)
1415 return false;
1416 return gl_helper->IsReadbackConfigSupported(bitmap_config);
1417 }
1418
1424 // static 1419 // static
1425 void RenderWidgetHostViewPort::GetDefaultScreenInfo( 1420 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
1426 blink::WebScreenInfo* results) { 1421 blink::WebScreenInfo* results) {
1427 const gfx::Display& display = 1422 const gfx::Display& display =
1428 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 1423 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
1429 results->rect = display.bounds(); 1424 results->rect = display.bounds();
1430 // TODO(husky): Remove any system controls from availableRect. 1425 // TODO(husky): Remove any system controls from availableRect.
1431 results->availableRect = display.work_area(); 1426 results->availableRect = display.work_area();
1432 results->deviceScaleFactor = display.device_scale_factor(); 1427 results->deviceScaleFactor = display.device_scale_factor();
1433 gfx::DeviceDisplayInfo info; 1428 gfx::DeviceDisplayInfo info;
1434 results->depth = info.GetBitsPerPixel(); 1429 results->depth = info.GetBitsPerPixel();
1435 results->depthPerComponent = info.GetBitsPerComponent(); 1430 results->depthPerComponent = info.GetBitsPerComponent();
1436 results->isMonochrome = (results->depthPerComponent == 0); 1431 results->isMonochrome = (results->depthPerComponent == 0);
1437 } 1432 }
1438 1433
1439 //////////////////////////////////////////////////////////////////////////////// 1434 ////////////////////////////////////////////////////////////////////////////////
1440 // RenderWidgetHostView, public: 1435 // RenderWidgetHostView, public:
1441 1436
1442 // static 1437 // static
1443 RenderWidgetHostView* 1438 RenderWidgetHostView*
1444 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1439 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1445 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1440 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1446 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1441 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1447 } 1442 }
1448 1443
1449 } // namespace content 1444 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698