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 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 } | 582 } |
583 | 583 |
584 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 584 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
585 const gfx::Rect& src_subrect, | 585 const gfx::Rect& src_subrect, |
586 const gfx::Size& dst_size, | 586 const gfx::Size& dst_size, |
587 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 587 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
588 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 588 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
589 callback.Run(false, SkBitmap()); | 589 callback.Run(false, SkBitmap()); |
590 return; | 590 return; |
591 } | 591 } |
592 | 592 // Support format either for ARGB8888 and RGB565. |
593 bool readback_config_rgb565 = content_view_core_->IsReadBackConfig565(); | |
594 ImageTransportFactoryAndroid* factory = | |
595 ImageTransportFactoryAndroid::GetInstance(); | |
596 GLHelper* gl_helper = factory->GetGLHelper(); | |
597 if (!gl_helper) | |
598 return; | |
599 if(readback_config_rgb565 && !gl_helper->CanUseRgb565Readback()){ | |
no sievers
2014/01/07 16:26:02
Can we check CanUseRgb565Readback() only once? It'
sivag
2014/01/09 14:51:50
Done.
| |
600 LOG(ERROR) << "Readbackformat rgb565 not supported"; | |
601 callback.Run(false, SkBitmap()); | |
602 return; | |
603 } | |
593 const gfx::Display& display = | 604 const gfx::Display& display = |
594 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 605 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
595 float device_scale_factor = display.device_scale_factor(); | 606 float device_scale_factor = display.device_scale_factor(); |
596 | 607 |
597 DCHECK_EQ(device_scale_factor, | 608 DCHECK_EQ(device_scale_factor, |
598 ui::GetImageScale(GetScaleFactorForView(this))); | 609 ui::GetImageScale(GetScaleFactorForView(this))); |
599 | 610 |
600 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 611 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
601 gfx::Rect src_subrect_in_pixel = | 612 gfx::Rect src_subrect_in_pixel = |
602 ConvertRectToPixel(device_scale_factor, src_subrect); | 613 ConvertRectToPixel(device_scale_factor, src_subrect); |
603 | 614 |
604 if (using_synchronous_compositor_) { | 615 if (using_synchronous_compositor_) { |
605 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 616 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
606 return; | 617 return; |
607 } | 618 } |
608 | |
609 scoped_ptr<cc::CopyOutputRequest> request; | 619 scoped_ptr<cc::CopyOutputRequest> request; |
610 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 620 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
611 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 621 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
612 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 622 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
613 dst_size_in_pixel, | 623 dst_size_in_pixel, |
614 callback)); | 624 callback)); |
615 } else { | 625 } else { |
616 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 626 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
617 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 627 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
618 dst_size_in_pixel, | 628 dst_size_in_pixel, |
629 readback_config_rgb565, | |
619 callback)); | 630 callback)); |
620 } | 631 } |
621 request->set_area(src_subrect_in_pixel); | 632 request->set_area(src_subrect_in_pixel); |
622 layer_->RequestCopyOfOutput(request.Pass()); | 633 layer_->RequestCopyOfOutput(request.Pass()); |
623 } | 634 } |
624 | 635 |
625 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 636 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
626 const gfx::Rect& src_subrect, | 637 const gfx::Rect& src_subrect, |
627 const scoped_refptr<media::VideoFrame>& target, | 638 const scoped_refptr<media::VideoFrame>& target, |
628 const base::Callback<void(bool)>& callback) { | 639 const base::Callback<void(bool)>& callback) { |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1308 texture_layer_->SetIsDrawable(false); | 1319 texture_layer_->SetIsDrawable(false); |
1309 if (delegated_renderer_layer_.get()) | 1320 if (delegated_renderer_layer_.get()) |
1310 DestroyDelegatedContent(); | 1321 DestroyDelegatedContent(); |
1311 texture_id_in_layer_ = 0; | 1322 texture_id_in_layer_ = 0; |
1312 RunAckCallbacks(); | 1323 RunAckCallbacks(); |
1313 } | 1324 } |
1314 | 1325 |
1315 // static | 1326 // static |
1316 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1327 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
1317 const gfx::Size& dst_size_in_pixel, | 1328 const gfx::Size& dst_size_in_pixel, |
1329 bool readback_config_rgb565, | |
1318 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1330 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1319 scoped_ptr<cc::CopyOutputResult> result) { | 1331 scoped_ptr<cc::CopyOutputResult> result) { |
1320 DCHECK(result->HasTexture()); | 1332 DCHECK(result->HasTexture()); |
1321 base::ScopedClosureRunner scoped_callback_runner( | 1333 base::ScopedClosureRunner scoped_callback_runner( |
1322 base::Bind(callback, false, SkBitmap())); | 1334 base::Bind(callback, false, SkBitmap())); |
1323 | 1335 |
1324 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1336 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
1325 return; | 1337 return; |
1326 | 1338 |
1327 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1339 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
1328 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1340 if(readback_config_rgb565){ |
1341 bitmap->setConfig(SkBitmap::kRGB_565_Config, | |
no sievers
2014/01/07 16:26:02
nit: no need for if-else, can do 'readback_config_
sivag
2014/01/09 14:51:50
Done.
| |
1329 dst_size_in_pixel.width(), dst_size_in_pixel.height(), | 1342 dst_size_in_pixel.width(), dst_size_in_pixel.height(), |
1330 0, kOpaque_SkAlphaType); | 1343 0, kOpaque_SkAlphaType); |
1344 } | |
1345 else{ | |
1346 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | |
1347 dst_size_in_pixel.width(), dst_size_in_pixel.height(), | |
no sievers
2014/01/07 16:26:02
nit: indent here and above
sivag
2014/01/09 14:51:50
Done.
| |
1348 0, kOpaque_SkAlphaType); | |
1349 } | |
1331 if (!bitmap->allocPixels()) | 1350 if (!bitmap->allocPixels()) |
1332 return; | 1351 return; |
1333 | 1352 |
1334 ImageTransportFactoryAndroid* factory = | 1353 ImageTransportFactoryAndroid* factory = |
1335 ImageTransportFactoryAndroid::GetInstance(); | 1354 ImageTransportFactoryAndroid::GetInstance(); |
1336 GLHelper* gl_helper = factory->GetGLHelper(); | 1355 GLHelper* gl_helper = factory->GetGLHelper(); |
1337 if (!gl_helper) | 1356 if (!gl_helper) |
1338 return; | 1357 return; |
1339 | 1358 |
1340 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1359 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
1341 new SkAutoLockPixels(*bitmap)); | 1360 new SkAutoLockPixels(*bitmap)); |
1342 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1361 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
1343 | 1362 |
1344 cc::TextureMailbox texture_mailbox; | 1363 cc::TextureMailbox texture_mailbox; |
1345 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1364 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
1346 result->TakeTexture(&texture_mailbox, &release_callback); | 1365 result->TakeTexture(&texture_mailbox, &release_callback); |
1347 DCHECK(texture_mailbox.IsTexture()); | 1366 DCHECK(texture_mailbox.IsTexture()); |
1348 if (!texture_mailbox.IsTexture()) | 1367 if (!texture_mailbox.IsTexture()) |
1349 return; | 1368 return; |
1350 | 1369 |
1351 ignore_result(scoped_callback_runner.Release()); | 1370 ignore_result(scoped_callback_runner.Release()); |
1352 | 1371 |
1353 gl_helper->CropScaleReadbackAndCleanMailbox( | 1372 gl_helper->CropScaleReadbackAndCleanMailbox( |
1354 texture_mailbox.name(), | 1373 texture_mailbox.name(), |
1355 texture_mailbox.sync_point(), | 1374 texture_mailbox.sync_point(), |
1356 result->size(), | 1375 result->size(), |
1357 gfx::Rect(result->size()), | 1376 gfx::Rect(result->size()), |
1358 dst_size_in_pixel, | 1377 dst_size_in_pixel, |
1359 pixels, | 1378 pixels, |
1379 readback_config_rgb565, | |
1360 base::Bind(&CopyFromCompositingSurfaceFinished, | 1380 base::Bind(&CopyFromCompositingSurfaceFinished, |
1361 callback, | 1381 callback, |
1362 base::Passed(&release_callback), | 1382 base::Passed(&release_callback), |
1363 base::Passed(&bitmap), | 1383 base::Passed(&bitmap), |
1364 base::Passed(&bitmap_pixels_lock))); | 1384 base::Passed(&bitmap_pixels_lock))); |
1365 } | 1385 } |
1366 | 1386 |
1367 // static | 1387 // static |
1368 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1388 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
1369 const gfx::Size& dst_size_in_pixel, | 1389 const gfx::Size& dst_size_in_pixel, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1407 // RenderWidgetHostView, public: | 1427 // RenderWidgetHostView, public: |
1408 | 1428 |
1409 // static | 1429 // static |
1410 RenderWidgetHostView* | 1430 RenderWidgetHostView* |
1411 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1431 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1412 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1432 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1413 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1433 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1414 } | 1434 } |
1415 | 1435 |
1416 } // namespace content | 1436 } // namespace content |
OLD | NEW |