| 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 567 } |
| 568 | 568 |
| 569 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 569 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 570 const gfx::Rect& src_subrect, | 570 const gfx::Rect& src_subrect, |
| 571 const gfx::Size& dst_size, | 571 const gfx::Size& dst_size, |
| 572 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 572 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 573 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 573 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
| 574 callback.Run(false, SkBitmap()); | 574 callback.Run(false, SkBitmap()); |
| 575 return; | 575 return; |
| 576 } | 576 } |
| 577 | |
| 578 const gfx::Display& display = | 577 const gfx::Display& display = |
| 579 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 578 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 580 float device_scale_factor = display.device_scale_factor(); | 579 float device_scale_factor = display.device_scale_factor(); |
| 581 | 580 |
| 582 DCHECK_EQ(device_scale_factor, | 581 DCHECK_EQ(device_scale_factor, |
| 583 ui::GetImageScale(GetScaleFactorForView(this))); | 582 ui::GetImageScale(GetScaleFactorForView(this))); |
| 584 | 583 |
| 585 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 584 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
| 586 gfx::Rect src_subrect_in_pixel = | 585 gfx::Rect src_subrect_in_pixel = |
| 587 ConvertRectToPixel(device_scale_factor, src_subrect); | 586 ConvertRectToPixel(device_scale_factor, src_subrect); |
| 588 | 587 |
| 589 if (using_synchronous_compositor_) { | 588 if (using_synchronous_compositor_) { |
| 590 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 589 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
| 591 return; | 590 return; |
| 592 } | 591 } |
| 593 | 592 //Support format either for ARGB8888 and RGB565. |
| 593 bool readback_config_rgb565 = content_view_core_->IsReadBackConfig565(); |
| 594 scoped_ptr<cc::CopyOutputRequest> request; | 594 scoped_ptr<cc::CopyOutputRequest> request; |
| 595 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 595 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
| 596 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 596 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 597 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 597 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
| 598 dst_size_in_pixel, | 598 dst_size_in_pixel, |
| 599 callback)); | 599 callback)); |
| 600 } else { | 600 } else { |
| 601 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 601 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 602 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 602 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
| 603 dst_size_in_pixel, | 603 dst_size_in_pixel, |
| 604 readback_config_rgb565, |
| 604 callback)); | 605 callback)); |
| 605 } | 606 } |
| 606 request->set_area(src_subrect_in_pixel); | 607 request->set_area(src_subrect_in_pixel); |
| 607 layer_->RequestCopyOfOutput(request.Pass()); | 608 layer_->RequestCopyOfOutput(request.Pass()); |
| 608 } | 609 } |
| 609 | 610 |
| 610 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 611 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
| 611 const gfx::Rect& src_subrect, | 612 const gfx::Rect& src_subrect, |
| 612 const scoped_refptr<media::VideoFrame>& target, | 613 const scoped_refptr<media::VideoFrame>& target, |
| 613 const base::Callback<void(bool)>& callback) { | 614 const base::Callback<void(bool)>& callback) { |
| (...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 texture_layer_->SetIsDrawable(false); | 1289 texture_layer_->SetIsDrawable(false); |
| 1289 if (delegated_renderer_layer_.get()) | 1290 if (delegated_renderer_layer_.get()) |
| 1290 DestroyDelegatedContent(); | 1291 DestroyDelegatedContent(); |
| 1291 texture_id_in_layer_ = 0; | 1292 texture_id_in_layer_ = 0; |
| 1292 RunAckCallbacks(); | 1293 RunAckCallbacks(); |
| 1293 } | 1294 } |
| 1294 | 1295 |
| 1295 // static | 1296 // static |
| 1296 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1297 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| 1297 const gfx::Size& dst_size_in_pixel, | 1298 const gfx::Size& dst_size_in_pixel, |
| 1299 bool readback_config_rgb565, |
| 1298 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1300 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1299 scoped_ptr<cc::CopyOutputResult> result) { | 1301 scoped_ptr<cc::CopyOutputResult> result) { |
| 1300 DCHECK(result->HasTexture()); | 1302 DCHECK(result->HasTexture()); |
| 1301 base::ScopedClosureRunner scoped_callback_runner( | 1303 base::ScopedClosureRunner scoped_callback_runner( |
| 1302 base::Bind(callback, false, SkBitmap())); | 1304 base::Bind(callback, false, SkBitmap())); |
| 1303 | 1305 |
| 1304 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1306 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
| 1305 return; | 1307 return; |
| 1306 | 1308 |
| 1307 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1309 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| 1308 bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 1310 if(readback_config_rgb565){ |
| 1311 bitmap->setConfig(SkBitmap::kRGB_565_Config, |
| 1309 dst_size_in_pixel.width(), dst_size_in_pixel.height(), | 1312 dst_size_in_pixel.width(), dst_size_in_pixel.height(), |
| 1310 0, kOpaque_SkAlphaType); | 1313 0, kOpaque_SkAlphaType); |
| 1314 } |
| 1315 else{ |
| 1316 bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
| 1317 dst_size_in_pixel.width(), dst_size_in_pixel.height(), |
| 1318 0, kOpaque_SkAlphaType); |
| 1319 } |
| 1311 if (!bitmap->allocPixels()) | 1320 if (!bitmap->allocPixels()) |
| 1312 return; | 1321 return; |
| 1313 | 1322 |
| 1314 ImageTransportFactoryAndroid* factory = | 1323 ImageTransportFactoryAndroid* factory = |
| 1315 ImageTransportFactoryAndroid::GetInstance(); | 1324 ImageTransportFactoryAndroid::GetInstance(); |
| 1316 GLHelper* gl_helper = factory->GetGLHelper(); | 1325 GLHelper* gl_helper = factory->GetGLHelper(); |
| 1317 if (!gl_helper) | 1326 if (!gl_helper) |
| 1318 return; | 1327 return; |
| 1319 | 1328 |
| 1320 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( | 1329 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock( |
| 1321 new SkAutoLockPixels(*bitmap)); | 1330 new SkAutoLockPixels(*bitmap)); |
| 1322 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); | 1331 uint8* pixels = static_cast<uint8*>(bitmap->getPixels()); |
| 1323 | 1332 |
| 1324 cc::TextureMailbox texture_mailbox; | 1333 cc::TextureMailbox texture_mailbox; |
| 1325 scoped_ptr<cc::SingleReleaseCallback> release_callback; | 1334 scoped_ptr<cc::SingleReleaseCallback> release_callback; |
| 1326 result->TakeTexture(&texture_mailbox, &release_callback); | 1335 result->TakeTexture(&texture_mailbox, &release_callback); |
| 1327 DCHECK(texture_mailbox.IsTexture()); | 1336 DCHECK(texture_mailbox.IsTexture()); |
| 1328 if (!texture_mailbox.IsTexture()) | 1337 if (!texture_mailbox.IsTexture()) |
| 1329 return; | 1338 return; |
| 1330 | 1339 |
| 1331 ignore_result(scoped_callback_runner.Release()); | 1340 ignore_result(scoped_callback_runner.Release()); |
| 1332 | 1341 |
| 1333 gl_helper->CropScaleReadbackAndCleanMailbox( | 1342 gl_helper->CropScaleReadbackAndCleanMailbox( |
| 1334 texture_mailbox.name(), | 1343 texture_mailbox.name(), |
| 1335 texture_mailbox.sync_point(), | 1344 texture_mailbox.sync_point(), |
| 1336 result->size(), | 1345 result->size(), |
| 1337 gfx::Rect(result->size()), | 1346 gfx::Rect(result->size()), |
| 1338 dst_size_in_pixel, | 1347 dst_size_in_pixel, |
| 1339 pixels, | 1348 pixels, |
| 1349 readback_config_rgb565, |
| 1340 base::Bind(&CopyFromCompositingSurfaceFinished, | 1350 base::Bind(&CopyFromCompositingSurfaceFinished, |
| 1341 callback, | 1351 callback, |
| 1342 base::Passed(&release_callback), | 1352 base::Passed(&release_callback), |
| 1343 base::Passed(&bitmap), | 1353 base::Passed(&bitmap), |
| 1344 base::Passed(&bitmap_pixels_lock))); | 1354 base::Passed(&bitmap_pixels_lock))); |
| 1345 } | 1355 } |
| 1346 | 1356 |
| 1347 // static | 1357 // static |
| 1348 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1358 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
| 1349 const gfx::Size& dst_size_in_pixel, | 1359 const gfx::Size& dst_size_in_pixel, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1387 // RenderWidgetHostView, public: | 1397 // RenderWidgetHostView, public: |
| 1388 | 1398 |
| 1389 // static | 1399 // static |
| 1390 RenderWidgetHostView* | 1400 RenderWidgetHostView* |
| 1391 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1401 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1392 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1402 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1393 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1403 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1394 } | 1404 } |
| 1395 | 1405 |
| 1396 } // namespace content | 1406 } // namespace content |
| OLD | NEW |