| 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_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 #endif | 1438 #endif |
| 1439 | 1439 |
| 1440 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( | 1440 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( |
| 1441 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, | 1441 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel, |
| 1442 int gpu_host_id) { | 1442 int gpu_host_id) { |
| 1443 BufferPresentedCallback ack_callback = base::Bind( | 1443 BufferPresentedCallback ack_callback = base::Bind( |
| 1444 &AcknowledgeBufferForGpu, | 1444 &AcknowledgeBufferForGpu, |
| 1445 params_in_pixel.route_id, | 1445 params_in_pixel.route_id, |
| 1446 gpu_host_id, | 1446 gpu_host_id, |
| 1447 params_in_pixel.mailbox_name); | 1447 params_in_pixel.mailbox_name); |
| 1448 BuffersSwapped( | 1448 BuffersSwapped(params_in_pixel.size, |
| 1449 params_in_pixel.size, params_in_pixel.scale_factor, | 1449 params_in_pixel.scale_factor, |
| 1450 params_in_pixel.mailbox_name, ack_callback); | 1450 params_in_pixel.mailbox_name, |
| 1451 params_in_pixel.latency_info, |
| 1452 ack_callback); |
| 1451 } | 1453 } |
| 1452 | 1454 |
| 1453 void RenderWidgetHostViewAura::SwapDelegatedFrame( | 1455 void RenderWidgetHostViewAura::SwapDelegatedFrame( |
| 1454 scoped_ptr<cc::DelegatedFrameData> frame_data, | 1456 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 1455 float frame_device_scale_factor) { | 1457 float frame_device_scale_factor, |
| 1458 const ui::LatencyInfo& latency_info) { |
| 1456 gfx::Size frame_size_in_dip; | 1459 gfx::Size frame_size_in_dip; |
| 1457 if (!frame_data->render_pass_list.empty()) { | 1460 if (!frame_data->render_pass_list.empty()) { |
| 1458 frame_size_in_dip = gfx::ToFlooredSize(gfx::ScaleSize( | 1461 frame_size_in_dip = gfx::ToFlooredSize(gfx::ScaleSize( |
| 1459 frame_data->render_pass_list.back()->output_rect.size(), | 1462 frame_data->render_pass_list.back()->output_rect.size(), |
| 1460 1.f/frame_device_scale_factor)); | 1463 1.f/frame_device_scale_factor)); |
| 1461 } | 1464 } |
| 1462 if (ShouldSkipFrame(frame_size_in_dip)) { | 1465 if (ShouldSkipFrame(frame_size_in_dip)) { |
| 1463 cc::CompositorFrameAck ack; | 1466 cc::CompositorFrameAck ack; |
| 1464 ack.resources.swap(frame_data->resource_list); | 1467 ack.resources.swap(frame_data->resource_list); |
| 1465 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1468 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1466 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1469 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
| 1467 return; | 1470 return; |
| 1468 } | 1471 } |
| 1469 window_->layer()->SetDelegatedFrame(frame_data.Pass(), frame_size_in_dip); | 1472 window_->layer()->SetDelegatedFrame(frame_data.Pass(), frame_size_in_dip); |
| 1470 released_front_lock_ = NULL; | 1473 released_front_lock_ = NULL; |
| 1471 current_frame_size_ = frame_size_in_dip; | 1474 current_frame_size_ = frame_size_in_dip; |
| 1472 CheckResizeLock(); | 1475 CheckResizeLock(); |
| 1473 | 1476 |
| 1474 if (paint_observer_) | 1477 if (paint_observer_) |
| 1475 paint_observer_->OnUpdateCompositorContent(); | 1478 paint_observer_->OnUpdateCompositorContent(); |
| 1476 | 1479 |
| 1477 ui::Compositor* compositor = GetCompositor(); | 1480 ui::Compositor* compositor = GetCompositor(); |
| 1478 if (!compositor) { | 1481 if (!compositor) { |
| 1479 SendDelegatedFrameAck(); | 1482 SendDelegatedFrameAck(); |
| 1480 } else { | 1483 } else { |
| 1484 compositor->SetLatencyInfo(latency_info); |
| 1481 AddOnCommitCallbackAndDisableLocks( | 1485 AddOnCommitCallbackAndDisableLocks( |
| 1482 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, | 1486 base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, |
| 1483 AsWeakPtr())); | 1487 AsWeakPtr())); |
| 1484 } | 1488 } |
| 1485 } | 1489 } |
| 1486 | 1490 |
| 1487 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { | 1491 void RenderWidgetHostViewAura::SendDelegatedFrameAck() { |
| 1488 cc::CompositorFrameAck ack; | 1492 cc::CompositorFrameAck ack; |
| 1489 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); | 1493 window_->layer()->TakeUnusedResourcesForChildCompositor(&ack.resources); |
| 1490 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1494 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1491 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1495 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
| 1492 } | 1496 } |
| 1493 | 1497 |
| 1494 void RenderWidgetHostViewAura::SwapSoftwareFrame( | 1498 void RenderWidgetHostViewAura::SwapSoftwareFrame( |
| 1495 scoped_ptr<cc::SoftwareFrameData> frame_data, | 1499 scoped_ptr<cc::SoftwareFrameData> frame_data, |
| 1496 float frame_device_scale_factor) { | 1500 float frame_device_scale_factor, |
| 1501 const ui::LatencyInfo& latency_info) { |
| 1497 const gfx::Size& frame_size = frame_data->size; | 1502 const gfx::Size& frame_size = frame_data->size; |
| 1498 const gfx::Rect& damage_rect = frame_data->damage_rect; | 1503 const gfx::Rect& damage_rect = frame_data->damage_rect; |
| 1499 const TransportDIB::Id& dib_id = frame_data->dib_id; | 1504 const TransportDIB::Id& dib_id = frame_data->dib_id; |
| 1500 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); | 1505 scoped_ptr<TransportDIB> dib(host_->GetProcess()->MapTransportDIB(dib_id)); |
| 1501 | 1506 |
| 1502 // Validate the received DIB. | 1507 // Validate the received DIB. |
| 1503 size_t expected_size = 4 * frame_size.GetArea(); | 1508 size_t expected_size = 4 * frame_size.GetArea(); |
| 1504 if (!dib || dib->size() < expected_size) { | 1509 if (!dib || dib->size() < expected_size) { |
| 1505 host_->GetProcess()->ReceivedBadMessage(); | 1510 host_->GetProcess()->ReceivedBadMessage(); |
| 1506 return; | 1511 return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1533 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, | 1538 base::Bind(&RenderWidgetHostViewAura::SendSoftwareFrameAck, |
| 1534 AsWeakPtr(), last_dib_id)); | 1539 AsWeakPtr(), last_dib_id)); |
| 1535 } | 1540 } |
| 1536 | 1541 |
| 1537 current_frame_size_ = frame_size_in_dip; | 1542 current_frame_size_ = frame_size_in_dip; |
| 1538 CheckResizeLock(); | 1543 CheckResizeLock(); |
| 1539 released_front_lock_ = NULL; | 1544 released_front_lock_ = NULL; |
| 1540 window_->SetExternalTexture(NULL); | 1545 window_->SetExternalTexture(NULL); |
| 1541 window_->SchedulePaintInRect( | 1546 window_->SchedulePaintInRect( |
| 1542 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); | 1547 ConvertRectToDIP(frame_device_scale_factor, damage_rect)); |
| 1548 compositor->SetLatencyInfo(latency_info); |
| 1543 | 1549 |
| 1544 if (paint_observer_) | 1550 if (paint_observer_) |
| 1545 paint_observer_->OnUpdateCompositorContent(); | 1551 paint_observer_->OnUpdateCompositorContent(); |
| 1546 } | 1552 } |
| 1547 | 1553 |
| 1548 void RenderWidgetHostViewAura::SendSoftwareFrameAck( | 1554 void RenderWidgetHostViewAura::SendSoftwareFrameAck( |
| 1549 const TransportDIB::Id& id) { | 1555 const TransportDIB::Id& id) { |
| 1550 cc::CompositorFrameAck ack; | 1556 cc::CompositorFrameAck ack; |
| 1551 ack.last_dib_id = id; | 1557 ack.last_dib_id = id; |
| 1552 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | 1558 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1553 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); | 1559 host_->GetRoutingID(), host_->GetProcess()->GetID(), ack); |
| 1554 } | 1560 } |
| 1555 | 1561 |
| 1556 void RenderWidgetHostViewAura::OnSwapCompositorFrame( | 1562 void RenderWidgetHostViewAura::OnSwapCompositorFrame( |
| 1557 scoped_ptr<cc::CompositorFrame> frame) { | 1563 scoped_ptr<cc::CompositorFrame> frame) { |
| 1558 if (frame->delegated_frame_data) { | 1564 if (frame->delegated_frame_data) { |
| 1559 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), | 1565 SwapDelegatedFrame(frame->delegated_frame_data.Pass(), |
| 1560 frame->metadata.device_scale_factor); | 1566 frame->metadata.device_scale_factor, |
| 1567 frame->metadata.latency_info); |
| 1561 return; | 1568 return; |
| 1562 } | 1569 } |
| 1563 | 1570 |
| 1564 if (frame->software_frame_data) { | 1571 if (frame->software_frame_data) { |
| 1565 SwapSoftwareFrame(frame->software_frame_data.Pass(), | 1572 SwapSoftwareFrame(frame->software_frame_data.Pass(), |
| 1566 frame->metadata.device_scale_factor); | 1573 frame->metadata.device_scale_factor, |
| 1574 frame->metadata.latency_info); |
| 1567 return; | 1575 return; |
| 1568 } | 1576 } |
| 1569 | 1577 |
| 1570 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) | 1578 if (!frame->gl_frame_data || frame->gl_frame_data->mailbox.IsZero()) |
| 1571 return; | 1579 return; |
| 1572 | 1580 |
| 1573 BufferPresentedCallback ack_callback = base::Bind( | 1581 BufferPresentedCallback ack_callback = base::Bind( |
| 1574 &SendCompositorFrameAck, | 1582 &SendCompositorFrameAck, |
| 1575 host_->GetRoutingID(), host_->GetProcess()->GetID(), | 1583 host_->GetRoutingID(), host_->GetProcess()->GetID(), |
| 1576 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); | 1584 frame->gl_frame_data->mailbox, frame->gl_frame_data->size); |
| 1577 | 1585 |
| 1578 if (!frame->gl_frame_data->sync_point) { | 1586 if (!frame->gl_frame_data->sync_point) { |
| 1579 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; | 1587 LOG(ERROR) << "CompositorFrame without sync point. Skipping frame..."; |
| 1580 ack_callback.Run(true, scoped_refptr<ui::Texture>()); | 1588 ack_callback.Run(true, scoped_refptr<ui::Texture>()); |
| 1581 return; | 1589 return; |
| 1582 } | 1590 } |
| 1583 | 1591 |
| 1584 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 1592 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); |
| 1585 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); | 1593 factory->WaitSyncPoint(frame->gl_frame_data->sync_point); |
| 1586 | 1594 |
| 1587 std::string mailbox_name( | 1595 std::string mailbox_name( |
| 1588 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), | 1596 reinterpret_cast<const char*>(frame->gl_frame_data->mailbox.name), |
| 1589 sizeof(frame->gl_frame_data->mailbox.name)); | 1597 sizeof(frame->gl_frame_data->mailbox.name)); |
| 1590 BuffersSwapped( | 1598 BuffersSwapped(frame->gl_frame_data->size, |
| 1591 frame->gl_frame_data->size, frame->metadata.device_scale_factor, | 1599 frame->metadata.device_scale_factor, |
| 1592 mailbox_name, ack_callback); | 1600 mailbox_name, |
| 1601 frame->metadata.latency_info, |
| 1602 ack_callback); |
| 1593 } | 1603 } |
| 1594 | 1604 |
| 1595 #if defined(OS_WIN) | 1605 #if defined(OS_WIN) |
| 1596 void RenderWidgetHostViewAura::SetParentNativeViewAccessible( | 1606 void RenderWidgetHostViewAura::SetParentNativeViewAccessible( |
| 1597 gfx::NativeViewAccessible accessible_parent) { | 1607 gfx::NativeViewAccessible accessible_parent) { |
| 1598 if (GetBrowserAccessibilityManager()) { | 1608 if (GetBrowserAccessibilityManager()) { |
| 1599 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerWin() | 1609 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerWin() |
| 1600 ->set_parent_iaccessible(accessible_parent); | 1610 ->set_parent_iaccessible(accessible_parent); |
| 1601 } | 1611 } |
| 1602 } | 1612 } |
| 1603 #endif | 1613 #endif |
| 1604 | 1614 |
| 1605 void RenderWidgetHostViewAura::BuffersSwapped( | 1615 void RenderWidgetHostViewAura::BuffersSwapped( |
| 1606 const gfx::Size& size, | 1616 const gfx::Size& size, |
| 1607 float surface_scale_factor, | 1617 float surface_scale_factor, |
| 1608 const std::string& mailbox_name, | 1618 const std::string& mailbox_name, |
| 1619 const ui::LatencyInfo& latency_info, |
| 1609 const BufferPresentedCallback& ack_callback) { | 1620 const BufferPresentedCallback& ack_callback) { |
| 1610 scoped_refptr<ui::Texture> texture_to_return(current_surface_); | 1621 scoped_refptr<ui::Texture> texture_to_return(current_surface_); |
| 1611 const gfx::Rect surface_rect = gfx::Rect(size); | 1622 const gfx::Rect surface_rect = gfx::Rect(size); |
| 1612 if (!SwapBuffersPrepare(surface_rect, surface_scale_factor, surface_rect, | 1623 if (!SwapBuffersPrepare(surface_rect, surface_scale_factor, surface_rect, |
| 1613 mailbox_name, ack_callback)) { | 1624 mailbox_name, ack_callback)) { |
| 1614 return; | 1625 return; |
| 1615 } | 1626 } |
| 1616 | 1627 |
| 1617 previous_damage_.setRect(RectToSkIRect(surface_rect)); | 1628 previous_damage_.setRect(RectToSkIRect(surface_rect)); |
| 1618 skipped_damage_.setEmpty(); | 1629 skipped_damage_.setEmpty(); |
| 1619 | 1630 |
| 1620 ui::Compositor* compositor = GetCompositor(); | 1631 ui::Compositor* compositor = GetCompositor(); |
| 1621 if (compositor) { | 1632 if (compositor) { |
| 1622 gfx::Size surface_size = ConvertSizeToDIP(surface_scale_factor, size); | 1633 gfx::Size surface_size = ConvertSizeToDIP(surface_scale_factor, size); |
| 1623 window_->SchedulePaintInRect(gfx::Rect(surface_size)); | 1634 window_->SchedulePaintInRect(gfx::Rect(surface_size)); |
| 1635 compositor->SetLatencyInfo(latency_info); |
| 1624 } | 1636 } |
| 1625 | 1637 |
| 1626 if (paint_observer_) | 1638 if (paint_observer_) |
| 1627 paint_observer_->OnUpdateCompositorContent(); | 1639 paint_observer_->OnUpdateCompositorContent(); |
| 1628 | 1640 |
| 1629 SwapBuffersCompleted(ack_callback, texture_to_return); | 1641 SwapBuffersCompleted(ack_callback, texture_to_return); |
| 1630 } | 1642 } |
| 1631 | 1643 |
| 1632 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( | 1644 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( |
| 1633 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, | 1645 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 params_in_pixel.height)); | 1700 params_in_pixel.height)); |
| 1689 | 1701 |
| 1690 // Damage may not have been DIP aligned, so inflate damage to compensate | 1702 // Damage may not have been DIP aligned, so inflate damage to compensate |
| 1691 // for any round-off error. | 1703 // for any round-off error. |
| 1692 rect_to_paint.Inset(-1, -1); | 1704 rect_to_paint.Inset(-1, -1); |
| 1693 rect_to_paint.Intersect(window_->bounds()); | 1705 rect_to_paint.Intersect(window_->bounds()); |
| 1694 | 1706 |
| 1695 if (paint_observer_) | 1707 if (paint_observer_) |
| 1696 paint_observer_->OnUpdateCompositorContent(); | 1708 paint_observer_->OnUpdateCompositorContent(); |
| 1697 window_->SchedulePaintInRect(rect_to_paint); | 1709 window_->SchedulePaintInRect(rect_to_paint); |
| 1710 compositor->SetLatencyInfo(params_in_pixel.latency_info); |
| 1698 } | 1711 } |
| 1699 | 1712 |
| 1700 SwapBuffersCompleted(ack_callback, previous_texture); | 1713 SwapBuffersCompleted(ack_callback, previous_texture); |
| 1701 } | 1714 } |
| 1702 | 1715 |
| 1703 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { | 1716 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() { |
| 1704 } | 1717 } |
| 1705 | 1718 |
| 1706 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { | 1719 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() { |
| 1707 // This really tells us to release the frontbuffer. | 1720 // This really tells us to release the frontbuffer. |
| (...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2991 RenderWidgetHost* widget) { | 3004 RenderWidgetHost* widget) { |
| 2992 return new RenderWidgetHostViewAura(widget); | 3005 return new RenderWidgetHostViewAura(widget); |
| 2993 } | 3006 } |
| 2994 | 3007 |
| 2995 // static | 3008 // static |
| 2996 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3009 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2997 GetScreenInfoForWindow(results, NULL); | 3010 GetScreenInfoForWindow(results, NULL); |
| 2998 } | 3011 } |
| 2999 | 3012 |
| 3000 } // namespace content | 3013 } // namespace content |
| OLD | NEW |