Chromium Code Reviews| 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" |
| 11 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 17 #include "cc/base/latency_info_swap_promise.h" | 18 #include "cc/base/latency_info_swap_promise.h" |
| 18 #include "cc/layers/delegated_frame_provider.h" | 19 #include "cc/layers/delegated_frame_provider.h" |
| 19 #include "cc/layers/delegated_renderer_layer.h" | 20 #include "cc/layers/delegated_renderer_layer.h" |
| 20 #include "cc/layers/layer.h" | 21 #include "cc/layers/layer.h" |
| 21 #include "cc/layers/texture_layer.h" | 22 #include "cc/layers/texture_layer.h" |
| 22 #include "cc/output/compositor_frame.h" | 23 #include "cc/output/compositor_frame.h" |
| 23 #include "cc/output/compositor_frame_ack.h" | 24 #include "cc/output/compositor_frame_ack.h" |
| 24 #include "cc/output/copy_output_request.h" | 25 #include "cc/output/copy_output_request.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 | 84 |
| 84 // Sends an acknowledgement to the renderer of a processed IME event. | 85 // Sends an acknowledgement to the renderer of a processed IME event. |
| 85 void SendImeEventAck(RenderWidgetHostImpl* host) { | 86 void SendImeEventAck(RenderWidgetHostImpl* host) { |
| 86 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); | 87 host->Send(new ViewMsg_ImeEventAck(host->GetRoutingID())); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void CopyFromCompositingSurfaceFinished( | 90 void CopyFromCompositingSurfaceFinished( |
| 90 const base::Callback<void(bool, const SkBitmap&)>& callback, | 91 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 91 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 92 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
| 92 scoped_ptr<SkBitmap> bitmap, | 93 scoped_ptr<SkBitmap> bitmap, |
| 94 const base::TimeTicks& start_time, | |
| 93 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, | 95 scoped_ptr<SkAutoLockPixels> bitmap_pixels_lock, |
| 94 bool result) { | 96 bool result) { |
| 95 bitmap_pixels_lock.reset(); | 97 bitmap_pixels_lock.reset(); |
| 96 release_callback->Run(0, false); | 98 release_callback->Run(0, false); |
| 99 UMA_HISTOGRAM_TIMES("RWHVA.CopyFromCompositingSurface asyncreadback time", | |
|
jar (doing other things)
2014/01/11 03:41:39
nit: Did you intend to add data to the same histog
sivag
2014/01/14 13:38:22
Done.
| |
| 100 base::TimeTicks::Now() - start_time); | |
| 97 callback.Run(result, *bitmap); | 101 callback.Run(result, *bitmap); |
| 98 } | 102 } |
| 99 | 103 |
| 100 bool UsingDelegatedRenderer() { | 104 bool UsingDelegatedRenderer() { |
| 101 return CommandLine::ForCurrentProcess()->HasSwitch( | 105 return CommandLine::ForCurrentProcess()->HasSwitch( |
| 102 switches::kEnableDelegatedRenderer); | 106 switches::kEnableDelegatedRenderer); |
| 103 } | 107 } |
| 104 | 108 |
| 105 } // anonymous namespace | 109 } // anonymous namespace |
| 106 | 110 |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 | 582 |
| 579 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { | 583 void RenderWidgetHostViewAndroid::SetBackground(const SkBitmap& background) { |
| 580 RenderWidgetHostViewBase::SetBackground(background); | 584 RenderWidgetHostViewBase::SetBackground(background); |
| 581 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); | 585 host_->Send(new ViewMsg_SetBackground(host_->GetRoutingID(), background)); |
| 582 } | 586 } |
| 583 | 587 |
| 584 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 588 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 585 const gfx::Rect& src_subrect, | 589 const gfx::Rect& src_subrect, |
| 586 const gfx::Size& dst_size, | 590 const gfx::Size& dst_size, |
| 587 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 591 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 592 base::TimeTicks start_time = base::TimeTicks::Now(); | |
| 588 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { | 593 if (!using_synchronous_compositor_ && !IsSurfaceAvailableForCopy()) { |
| 589 callback.Run(false, SkBitmap()); | 594 callback.Run(false, SkBitmap()); |
| 590 return; | 595 return; |
| 591 } | 596 } |
| 592 | 597 |
| 593 const gfx::Display& display = | 598 const gfx::Display& display = |
| 594 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 599 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 595 float device_scale_factor = display.device_scale_factor(); | 600 float device_scale_factor = display.device_scale_factor(); |
| 596 | 601 |
| 597 DCHECK_EQ(device_scale_factor, | 602 DCHECK_EQ(device_scale_factor, |
| 598 ui::GetImageScale(GetScaleFactorForView(this))); | 603 ui::GetImageScale(GetScaleFactorForView(this))); |
| 599 | 604 |
| 600 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 605 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
| 601 gfx::Rect src_subrect_in_pixel = | 606 gfx::Rect src_subrect_in_pixel = |
| 602 ConvertRectToPixel(device_scale_factor, src_subrect); | 607 ConvertRectToPixel(device_scale_factor, src_subrect); |
| 603 | 608 |
| 604 if (using_synchronous_compositor_) { | 609 if (using_synchronous_compositor_) { |
| 605 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); | 610 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback); |
| 611 UMA_HISTOGRAM_TIMES("RWHVA.SynchronousCopyContents", | |
| 612 base::TimeTicks::Now() - start_time); | |
| 606 return; | 613 return; |
| 607 } | 614 } |
| 608 | 615 |
| 609 scoped_ptr<cc::CopyOutputRequest> request; | 616 scoped_ptr<cc::CopyOutputRequest> request; |
| 610 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { | 617 if (src_subrect_in_pixel.size() == dst_size_in_pixel) { |
| 611 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | 618 request = cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
| 612 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, | 619 &RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult, |
| 613 dst_size_in_pixel, | 620 dst_size_in_pixel, |
| 621 start_time, | |
| 614 callback)); | 622 callback)); |
| 615 } else { | 623 } else { |
| 616 request = cc::CopyOutputRequest::CreateRequest(base::Bind( | 624 request = cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 617 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, | 625 &RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult, |
| 618 dst_size_in_pixel, | 626 dst_size_in_pixel, |
| 627 start_time, | |
| 619 callback)); | 628 callback)); |
| 620 } | 629 } |
| 621 request->set_area(src_subrect_in_pixel); | 630 request->set_area(src_subrect_in_pixel); |
| 622 layer_->RequestCopyOfOutput(request.Pass()); | 631 layer_->RequestCopyOfOutput(request.Pass()); |
| 632 | |
|
jar (doing other things)
2014/01/11 03:41:39
nit: no need for blank line
sivag
2014/01/14 13:38:22
Done.
| |
| 623 } | 633 } |
| 624 | 634 |
| 625 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( | 635 void RenderWidgetHostViewAndroid::CopyFromCompositingSurfaceToVideoFrame( |
| 626 const gfx::Rect& src_subrect, | 636 const gfx::Rect& src_subrect, |
| 627 const scoped_refptr<media::VideoFrame>& target, | 637 const scoped_refptr<media::VideoFrame>& target, |
| 628 const base::Callback<void(bool)>& callback) { | 638 const base::Callback<void(bool)>& callback) { |
| 629 NOTIMPLEMENTED(); | 639 NOTIMPLEMENTED(); |
| 630 callback.Run(false); | 640 callback.Run(false); |
| 631 } | 641 } |
| 632 | 642 |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1308 texture_layer_->SetIsDrawable(false); | 1318 texture_layer_->SetIsDrawable(false); |
| 1309 if (delegated_renderer_layer_.get()) | 1319 if (delegated_renderer_layer_.get()) |
| 1310 DestroyDelegatedContent(); | 1320 DestroyDelegatedContent(); |
| 1311 texture_id_in_layer_ = 0; | 1321 texture_id_in_layer_ = 0; |
| 1312 RunAckCallbacks(); | 1322 RunAckCallbacks(); |
| 1313 } | 1323 } |
| 1314 | 1324 |
| 1315 // static | 1325 // static |
| 1316 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1326 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| 1317 const gfx::Size& dst_size_in_pixel, | 1327 const gfx::Size& dst_size_in_pixel, |
| 1328 const base::TimeTicks& start_time, | |
| 1318 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1329 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1319 scoped_ptr<cc::CopyOutputResult> result) { | 1330 scoped_ptr<cc::CopyOutputResult> result) { |
| 1320 DCHECK(result->HasTexture()); | 1331 DCHECK(result->HasTexture()); |
| 1321 base::ScopedClosureRunner scoped_callback_runner( | 1332 base::ScopedClosureRunner scoped_callback_runner( |
| 1322 base::Bind(callback, false, SkBitmap())); | 1333 base::Bind(callback, false, SkBitmap())); |
| 1323 | 1334 |
| 1324 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) | 1335 if (!result->HasTexture() || result->IsEmpty() || result->size().IsEmpty()) |
| 1325 return; | 1336 return; |
| 1326 | 1337 |
| 1327 scoped_ptr<SkBitmap> bitmap(new SkBitmap); | 1338 scoped_ptr<SkBitmap> bitmap(new SkBitmap); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1354 texture_mailbox.name(), | 1365 texture_mailbox.name(), |
| 1355 texture_mailbox.sync_point(), | 1366 texture_mailbox.sync_point(), |
| 1356 result->size(), | 1367 result->size(), |
| 1357 gfx::Rect(result->size()), | 1368 gfx::Rect(result->size()), |
| 1358 dst_size_in_pixel, | 1369 dst_size_in_pixel, |
| 1359 pixels, | 1370 pixels, |
| 1360 base::Bind(&CopyFromCompositingSurfaceFinished, | 1371 base::Bind(&CopyFromCompositingSurfaceFinished, |
| 1361 callback, | 1372 callback, |
| 1362 base::Passed(&release_callback), | 1373 base::Passed(&release_callback), |
| 1363 base::Passed(&bitmap), | 1374 base::Passed(&bitmap), |
| 1375 start_time, | |
| 1364 base::Passed(&bitmap_pixels_lock))); | 1376 base::Passed(&bitmap_pixels_lock))); |
| 1365 } | 1377 } |
| 1366 | 1378 |
| 1367 // static | 1379 // static |
| 1368 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( | 1380 void RenderWidgetHostViewAndroid::PrepareBitmapCopyOutputResult( |
| 1369 const gfx::Size& dst_size_in_pixel, | 1381 const gfx::Size& dst_size_in_pixel, |
| 1382 const base::TimeTicks& start_time, | |
| 1370 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1383 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1371 scoped_ptr<cc::CopyOutputResult> result) { | 1384 scoped_ptr<cc::CopyOutputResult> result) { |
| 1372 DCHECK(result->HasBitmap()); | 1385 DCHECK(result->HasBitmap()); |
| 1373 base::ScopedClosureRunner scoped_callback_runner( | 1386 base::ScopedClosureRunner scoped_callback_runner( |
| 1374 base::Bind(callback, false, SkBitmap())); | 1387 base::Bind(callback, false, SkBitmap())); |
| 1375 | 1388 |
| 1376 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) | 1389 if (!result->HasBitmap() || result->IsEmpty() || result->size().IsEmpty()) |
| 1377 return; | 1390 return; |
| 1378 | 1391 |
| 1379 scoped_ptr<SkBitmap> source = result->TakeBitmap(); | 1392 scoped_ptr<SkBitmap> source = result->TakeBitmap(); |
| 1380 DCHECK(source); | 1393 DCHECK(source); |
| 1381 if (!source) | 1394 if (!source) |
| 1382 return; | 1395 return; |
| 1383 | 1396 |
| 1384 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); | 1397 DCHECK_EQ(source->width(), dst_size_in_pixel.width()); |
| 1385 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); | 1398 DCHECK_EQ(source->height(), dst_size_in_pixel.height()); |
| 1386 | 1399 |
| 1387 ignore_result(scoped_callback_runner.Release()); | 1400 ignore_result(scoped_callback_runner.Release()); |
| 1401 UMA_HISTOGRAM_TIMES("RWHVA.CopyFromCompositingSurface asyncreadback time", | |
| 1402 base::TimeTicks::Now() - start_time); | |
| 1403 | |
| 1388 callback.Run(true, *source); | 1404 callback.Run(true, *source); |
| 1389 } | 1405 } |
| 1390 | 1406 |
| 1391 // static | 1407 // static |
| 1392 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | 1408 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
| 1393 blink::WebScreenInfo* results) { | 1409 blink::WebScreenInfo* results) { |
| 1394 const gfx::Display& display = | 1410 const gfx::Display& display = |
| 1395 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 1411 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 1396 results->rect = display.bounds(); | 1412 results->rect = display.bounds(); |
| 1397 // TODO(husky): Remove any system controls from availableRect. | 1413 // TODO(husky): Remove any system controls from availableRect. |
| 1398 results->availableRect = display.work_area(); | 1414 results->availableRect = display.work_area(); |
| 1399 results->deviceScaleFactor = display.device_scale_factor(); | 1415 results->deviceScaleFactor = display.device_scale_factor(); |
| 1400 gfx::DeviceDisplayInfo info; | 1416 gfx::DeviceDisplayInfo info; |
| 1401 results->depth = info.GetBitsPerPixel(); | 1417 results->depth = info.GetBitsPerPixel(); |
| 1402 results->depthPerComponent = info.GetBitsPerComponent(); | 1418 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1403 results->isMonochrome = (results->depthPerComponent == 0); | 1419 results->isMonochrome = (results->depthPerComponent == 0); |
| 1404 } | 1420 } |
| 1405 | 1421 |
| 1406 //////////////////////////////////////////////////////////////////////////////// | 1422 //////////////////////////////////////////////////////////////////////////////// |
| 1407 // RenderWidgetHostView, public: | 1423 // RenderWidgetHostView, public: |
| 1408 | 1424 |
| 1409 // static | 1425 // static |
| 1410 RenderWidgetHostView* | 1426 RenderWidgetHostView* |
| 1411 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1427 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1412 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1428 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1413 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1429 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1414 } | 1430 } |
| 1415 | 1431 |
| 1416 } // namespace content | 1432 } // namespace content |
| OLD | NEW |