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

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

Issue 143683003: Support format using enum argument for Async readback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code changed as per review comments. Created 6 years, 11 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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 621
622 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { 622 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) {
623 RenderWidgetHostViewBase::SetBackground(background); 623 RenderWidgetHostViewBase::SetBackground(background);
624 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); 624 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background));
625 } 625 }
626 626
627 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( 627 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface(
628 const gfx::Rect& src_subrect, 628 const gfx::Rect& src_subrect,
629 const gfx::Size& dst_size, 629 const gfx::Size& dst_size,
630 const base::Callback<void(bool, const SkBitmap&)>& callback, 630 const base::Callback<void(bool, const SkBitmap&)>& callback,
631 bool readback_config_rgb565) { 631 const SkBitmap::Config bitmap_config) {
632 // Only ARGB888 and RGB565 supported as of now.
633 DCHECK((bitmap_config == SkBitmap::kRGB_565_Config) ||
634 (bitmap_config == SkBitmap::kARGB_8888_Config));
635
632 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { 636 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) {
633 callback.Run(false, SkBitmap()); 637 callback.Run(false, SkBitmap());
634 return; 638 return;
635 } 639 }
636 ImageTransportFactoryAndroid* factory = 640 ImageTransportFactoryAndroid* factory =
637 ImageTransportFactoryAndroid::GetInstance(); 641 ImageTransportFactoryAndroid::GetInstance();
638 GLHelper* gl_helper = factory->GetGLHelper(); 642 GLHelper* gl_helper = factory->GetGLHelper();
639 if (!gl_helper) 643 if (!gl_helper)
640 return; 644 return;
641 bool check_rgb565_support = gl_helper->CanUseRgb565Readback(); 645 bool check_rgb565_support = gl_helper->CanUseRgb565Readback();
642 if (readback_config_rgb565 && !check_rgb565_support) { 646 if ((bitmap_config == SkBitmap::kRGB_565_Config) &&
647 !check_rgb565_support) {
643 LOG(ERROR) << "Readbackformat rgb565 not supported"; 648 LOG(ERROR) << "Readbackformat rgb565 not supported";
644 callback.Run(false, SkBitmap()); 649 callback.Run(false, SkBitmap());
645 return; 650 return;
646 } 651 }
647 const gfx::Display& display = 652 const gfx::Display& display =
648 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 653 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
649 float device_scale_factor = display.device_scale_factor(); 654 float device_scale_factor = display.device_scale_factor();
650 655
651 DCHECK_EQ(device_scale_factor, 656 DCHECK_EQ(device_scale_factor,
652 ui::GetImageScale(GetScaleFactorForView(this))); 657 ui::GetImageScale(GetScaleFactorForView(this)));
653 658
654 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); 659 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size);
655 gfx::Rect src_subrect_in_pixel = 660 gfx::Rect src_subrect_in_pixel =
656 ConvertRectToPixel(device_scale_factor, src_subrect); 661 ConvertRectToPixel(device_scale_factor, src_subrect);
657 662
658 if (using_synchronous_compositor_) { 663 if (using_synchronous_compositor_) {
659 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); 664 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback);
660 return; 665 return;
661 } 666 }
662 scoped_ptr<cc::CopyOutputRequest> request; 667 scoped_ptr<cc::CopyOutputRequest> request;
663 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { 668 if (src_subrect_in_pixel.size() == dst_size_in_pixel) {
664 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( 669 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind(
665 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, 670 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult,
666 dst_size_in_pixel, 671 dst_size_in_pixel,
667 callback)); 672 callback));
668 } else { 673 } else {
669 request = cc::CopyOutputRequest::CreateRequest(base::Bind( 674 request = cc::CopyOutputRequest::CreateRequest(base::Bind(
670 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, 675 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult,
671 dst_size_in_pixel, 676 dst_size_in_pixel,
672 readback_config_rgb565, 677 bitmap_config,
673 callback)); 678 callback));
674 } 679 }
675 request->set_area(src_subrect_in_pixel); 680 request->set_area(src_subrect_in_pixel);
676 layer_->RequestCopyOfOutput(request.Pass()); 681 layer_->RequestCopyOfOutput(request.Pass());
677 } 682 }
678 683
679 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( 684 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame(
680 const gfx::Rect& src_subrect, 685 const gfx::Rect& src_subrect,
681 const scoped_refptr<media::VideoFrame>& target, 686 const scoped_refptr<media::VideoFrame>& target,
682 const base::Callback<void(bool)>& callback) { 687 const base::Callback<void(bool)>& callback) {
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 texture_layer_->SetIsDrawable(false); 1389 texture_layer_->SetIsDrawable(false);
1385 if (delegated_renderer_layer_.get()) 1390 if (delegated_renderer_layer_.get())
1386 DestroyDelegatedContent(); 1391 DestroyDelegatedContent();
1387 texture_id_in_layer_ = 0; 1392 texture_id_in_layer_ = 0;
1388 RunAckCallbacks(); 1393 RunAckCallbacks();
1389 } 1394 }
1390 1395
1391 // static 1396 // static
1392 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( 1397 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult(
1393 const gfx::Size& dst_size_in_pixel, 1398 const gfx::Size& dst_size_in_pixel,
1394 bool readback_config_rgb565, 1399 const SkBitmap::Config bitmap_config,
1395 const base::Callback<void(bool, const SkBitmap&)>& callback, 1400 const base::Callback<void(bool, const SkBitmap&)>& callback,
1396 scoped_ptr<cc::CopyOutputResult> result) { 1401 scoped_ptr<cc::CopyOutputResult> result) {
1397 DCHECK(result->HasTexture()); 1402 DCHECK(result->HasTexture());
1398 base::ScopedClosureRunner scoped_callback_runner( 1403 base::ScopedClosureRunner scoped_callback_runner(
1399 base::Bind(callback, false, SkBitmap())); 1404 base::Bind(callback, false, SkBitmap()));
1400 1405
1401 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) 1406 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty())
1402 return; 1407 return;
1403 1408
1404 scoped_ptr<SkBitmap> bitmap(new SkBitmap); 1409 scoped_ptr<SkBitmap> bitmap(new SkBitmap);
1405 SkBitmap::Config bitmap_config = readback_config_rgb565 ?
1406 SkBitmap::kRGB_565_Config :
1407 SkBitmap::kARGB_8888_Config;
1408 bitmap->setConfig(bitmap_config, 1410 bitmap->setConfig(bitmap_config,
1409 dst_size_in_pixel.width(), 1411 dst_size_in_pixel.width(),
1410 dst_size_in_pixel.height(), 1412 dst_size_in_pixel.height(),
1411 0, kOpaque_SkAlphaType); 1413 0, kOpaque_SkAlphaType);
1412 if (!bitmap->allocPixels()) 1414 if (!bitmap->allocPixels())
1413 return; 1415 return;
1414 1416
1415 ImageTransportFactoryAndroid* factory = 1417 ImageTransportFactoryAndroid* factory =
1416 ImageTransportFactoryAndroid::GetInstance(); 1418 ImageTransportFactoryAndroid::GetInstance();
1417 GLHelper* gl_helper = factory->GetGLHelper(); 1419 GLHelper* gl_helper = factory->GetGLHelper();
(...skipping 13 matching lines...) Expand all
1431 1433
1432 ignore_result(scoped_callback_runner.Release()); 1434 ignore_result(scoped_callback_runner.Release());
1433 1435
1434 gl_helper->CropScaleReadbackAndCleanMailbox( 1436 gl_helper->CropScaleReadbackAndCleanMailbox(
1435 texture_mailbox.name(), 1437 texture_mailbox.name(),
1436 texture_mailbox.sync_point(), 1438 texture_mailbox.sync_point(),
1437 result->size(), 1439 result->size(),
1438 gfx::Rect(result->size()), 1440 gfx::Rect(result->size()),
1439 dst_size_in_pixel, 1441 dst_size_in_pixel,
1440 pixels, 1442 pixels,
1441 readback_config_rgb565, 1443 bitmap_config,
1442 base::Bind(&CopyFromCompositingSurfaceFinished, 1444 base::Bind(&CopyFromCompositingSurfaceFinished,
1443 callback, 1445 callback,
1444 base::Passed(&release_callback), 1446 base::Passed(&release_callback),
1445 base::Passed(&bitmap), 1447 base::Passed(&bitmap),
1446 base::Passed(&bitmap_pixels_lock))); 1448 base::Passed(&bitmap_pixels_lock)));
1447 } 1449 }
1448 1450
1449 // static 1451 // static
1450 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( 1452 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult(
1451 const gfx::Size& dst_size_in_pixel, 1453 const gfx::Size& dst_size_in_pixel,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 // RenderWidgetHostView, public: 1491 // RenderWidgetHostView, public:
1490 1492
1491 // static 1493 // static
1492 RenderWidgetHostView* 1494 RenderWidgetHostView*
1493 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { 1495 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) {
1494 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); 1496 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget);
1495 return new RenderWidgetHostViewAndroid(rwhi, NULL); 1497 return new RenderWidgetHostViewAndroid(rwhi, NULL);
1496 } 1498 }
1497 1499
1498 } // namespace content 1500 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698