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

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

Issue 2147873003: cc: Dedup IPCs to return resources to client (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added three unit tests Created 4 years, 5 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_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 private: 222 private:
223 // Window that we're observing, or NULL if it's been destroyed. 223 // Window that we're observing, or NULL if it's been destroyed.
224 aura::Window* window_; 224 aura::Window* window_;
225 225
226 // Was |window_| destroyed? 226 // Was |window_| destroyed?
227 bool destroyed_; 227 bool destroyed_;
228 228
229 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver); 229 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
230 }; 230 };
231 231
232 class FakeSurfaceDamageObserver : public cc::SurfaceDamageObserver {
233 public:
234 void OnSurfaceDamaged(const cc::SurfaceId& id, bool* changed) override {
235 *changed = true;
236 }
237 };
238
232 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber { 239 class FakeFrameSubscriber : public RenderWidgetHostViewFrameSubscriber {
233 public: 240 public:
234 FakeFrameSubscriber(gfx::Size size, base::Callback<void(bool)> callback) 241 FakeFrameSubscriber(gfx::Size size, base::Callback<void(bool)> callback)
235 : size_(size), callback_(callback), should_capture_(true) {} 242 : size_(size), callback_(callback), should_capture_(true) {}
236 243
237 bool ShouldCaptureFrame(const gfx::Rect& damage_rect, 244 bool ShouldCaptureFrame(const gfx::Rect& damage_rect,
238 base::TimeTicks present_time, 245 base::TimeTicks present_time,
239 scoped_refptr<media::VideoFrame>* storage, 246 scoped_refptr<media::VideoFrame>* storage,
240 DeliverFrameCallback* callback) override { 247 DeliverFrameCallback* callback) override {
241 if (!should_capture_) 248 if (!should_capture_)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 348 }
342 349
343 bool HasFrameData() const { 350 bool HasFrameData() const {
344 return !surface_id().is_null(); 351 return !surface_id().is_null();
345 } 352 }
346 353
347 bool released_front_lock_active() const { 354 bool released_front_lock_active() const {
348 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting(); 355 return GetDelegatedFrameHost()->ReleasedFrontLockActiveForTesting();
349 } 356 }
350 357
358 void ReturnResources(const cc::ReturnedResourceArray& resources) {
359 GetDelegatedFrameHost()->ReturnResources(resources);
360 }
361
362 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); }
363
351 // A lock that doesn't actually do anything to the compositor, and does not 364 // A lock that doesn't actually do anything to the compositor, and does not
352 // time out. 365 // time out.
353 class FakeResizeLock : public ResizeLock { 366 class FakeResizeLock : public ResizeLock {
354 public: 367 public:
355 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 368 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
356 : ResizeLock(new_size, defer_compositor_lock) {} 369 : ResizeLock(new_size, defer_compositor_lock) {}
357 }; 370 };
358 371
359 const ui::MotionEventAura& pointer_state_for_test() { 372 const ui::MotionEventAura& pointer_state_for_test() {
360 return pointer_state(); 373 return pointer_state();
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 gfx::Size size, 1605 gfx::Size size,
1593 gfx::Rect damage) { 1606 gfx::Rect damage) {
1594 cc::CompositorFrame frame; 1607 cc::CompositorFrame frame;
1595 frame.metadata.device_scale_factor = scale_factor; 1608 frame.metadata.device_scale_factor = scale_factor;
1596 frame.delegated_frame_data.reset(new cc::DelegatedFrameData); 1609 frame.delegated_frame_data.reset(new cc::DelegatedFrameData);
1597 1610
1598 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create(); 1611 std::unique_ptr<cc::RenderPass> pass = cc::RenderPass::Create();
1599 pass->SetNew( 1612 pass->SetNew(
1600 cc::RenderPassId(1, 1), gfx::Rect(size), damage, gfx::Transform()); 1613 cc::RenderPassId(1, 1), gfx::Rect(size), damage, gfx::Transform());
1601 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass)); 1614 frame.delegated_frame_data->render_pass_list.push_back(std::move(pass));
1615 cc::TransferableResource resource;
1616 resource.id = 1;
1617 frame.delegated_frame_data->resource_list.push_back(std::move(resource));
1602 return frame; 1618 return frame;
1603 } 1619 }
1604 1620
1621 // If the ui::Compositor has been reset then resources are returned back to the
1622 // client in response to the swap. This test verifies that the returned
1623 // resources are indeed reported as being in response to a swap.
1624 TEST_F(RenderWidgetHostViewAuraTest, ResettingCompositorReturnsResources) {
1625 FakeSurfaceDamageObserver damage_observer;
1626 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1627 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1628 manager->AddObserver(&damage_observer);
1629
1630 gfx::Size view_size(100, 100);
1631 gfx::Rect view_rect(view_size);
1632
1633 view_->InitAsChild(NULL);
danakj 2016/07/14 19:55:44 nullptr
Fady Samuel 2016/07/14 23:17:04 Done. I just did a s/NULL/nullptr
1634 aura::client::ParentWindowWithContext(
1635 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
1636 gfx::Rect());
1637 view_->SetSize(view_size);
1638 view_->Show();
1639 sink_->ClearMessages();
1640
1641 view_->ResetCompositor();
1642
1643 // Swappinga frame should trigger a swap ACK IPC because we have reset the
danakj 2016/07/14 19:55:44 Swapping a frame
Fady Samuel 2016/07/14 23:17:04 Done.
1644 // compositor.
1645 view_->OnSwapCompositorFrame(0,
1646 MakeDelegatedFrame(1.f, view_size, view_rect));
1647 EXPECT_EQ(1u, sink_->message_count());
1648 {
1649 const IPC::Message* msg = sink_->GetMessageAt(0);
1650 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1651 ViewMsg_ReclaimCompositorResources::Param params;
1652 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1653 EXPECT_EQ(0u, std::get<0>(params)); // output_surface_id
1654 EXPECT_EQ(true, std::get<1>(params)); // is_swap_ack
danakj 2016/07/14 19:55:44 EXPECT_TRUE (i've seen EQ(true/false) fail to comp
Fady Samuel 2016/07/14 23:17:04 Done.
1655 }
1656 manager->RemoveObserver(&damage_observer);
1657 }
1658
1659 // This test verifies that returned resources do not require a pending ack.
1660 TEST_F(RenderWidgetHostViewAuraTest, ReturnedResources) {
1661 gfx::Size view_size(100, 100);
1662 gfx::Rect view_rect(view_size);
1663
1664 view_->InitAsChild(NULL);
1665 aura::client::ParentWindowWithContext(
1666 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
1667 gfx::Rect());
1668 view_->SetSize(view_size);
1669 view_->Show();
1670 sink_->ClearMessages();
1671
1672 // Accumulate some returned resources. This should not trigger an IPC.
1673 cc::ReturnedResourceArray resources;
1674 cc::ReturnedResource resource;
1675 resource.id = 1;
1676 resources.push_back(resource);
1677 view_->ReturnResources(resources);
1678 EXPECT_EQ(1u, sink_->message_count());
1679 {
1680 const IPC::Message* msg = sink_->GetMessageAt(0);
1681 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1682 ViewMsg_ReclaimCompositorResources::Param params;
1683 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1684 EXPECT_EQ(0u, std::get<0>(params)); // output_surface_id
1685 EXPECT_EQ(false, std::get<1>(params)); // is_swap_ack
danakj 2016/07/14 19:55:44 EXPECT_FALSE
Fady Samuel 2016/07/14 23:17:04 Done.
1686 }
1687 }
1688
1689 // This test verifies that when the output_surface_id changes, then
1690 // DelegateFrameHost
danakj 2016/07/14 19:55:44 weird line wrapping
Fady Samuel 2016/07/14 23:17:04 Done.
1691 // returns compositor resources without a swap ack.
1692 TEST_F(RenderWidgetHostViewAuraTest, TwoOutputSurfaces) {
1693 FakeSurfaceDamageObserver damage_observer;
1694 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
1695 cc::SurfaceManager* manager = factory->GetSurfaceManager();
1696 manager->AddObserver(&damage_observer);
1697
1698 gfx::Size view_size(100, 100);
1699 gfx::Rect view_rect(view_size);
1700
1701 view_->InitAsChild(NULL);
1702 aura::client::ParentWindowWithContext(
1703 view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
1704 gfx::Rect());
1705 view_->SetSize(view_size);
1706 view_->Show();
1707 sink_->ClearMessages();
1708
1709 view_->OnSwapCompositorFrame(0,
1710 MakeDelegatedFrame(1.f, view_size, view_rect));
1711
1712 // Accumulate some returned resources. This should not trigger an IPC.
1713 cc::ReturnedResourceArray resources;
1714 cc::ReturnedResource resource;
1715 resource.id = 1;
1716 resources.push_back(resource);
1717 view_->ReturnResources(resources);
1718 EXPECT_EQ(0u, sink_->message_count());
1719
1720 // Swap another CompositorFrame but this time from another output_surface_id.
1721 // This should trigger a non-ACK ReclaimCompositorResources IPC.
1722 view_->OnSwapCompositorFrame(1,
1723 MakeDelegatedFrame(1.f, view_size, view_rect));
1724 EXPECT_EQ(1u, sink_->message_count());
1725 {
1726 const IPC::Message* msg = sink_->GetMessageAt(0);
1727 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1728 ViewMsg_ReclaimCompositorResources::Param params;
1729 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1730 EXPECT_EQ(0u, std::get<0>(params)); // output_surface_id
1731 EXPECT_EQ(false, std::get<1>(params)); // is_swap_ack
1732 }
1733 sink_->ClearMessages();
1734
1735 // Report that the surface is drawn to trigger an ACK.
1736 cc::Surface* surface = manager->GetSurfaceForId(view_->surface_id());
1737 EXPECT_TRUE(surface);
1738 surface->RunDrawCallbacks(cc::SurfaceDrawStatus::DRAWN);
1739 EXPECT_EQ(1u, sink_->message_count());
1740 {
1741 const IPC::Message* msg = sink_->GetMessageAt(0);
1742 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID, msg->type());
1743 ViewMsg_ReclaimCompositorResources::Param params;
1744 ViewMsg_ReclaimCompositorResources::Read(msg, &params);
1745 EXPECT_EQ(1u, std::get<0>(params)); // output_surface_id
1746 EXPECT_EQ(true, std::get<1>(params)); // is_swap_ack
1747 }
1748
1749 manager->RemoveObserver(&damage_observer);
1750 }
1751
1605 // Resizing in fullscreen mode should send the up-to-date screen info. 1752 // Resizing in fullscreen mode should send the up-to-date screen info.
1606 // http://crbug.com/324350 1753 // http://crbug.com/324350
1607 TEST_F(RenderWidgetHostViewAuraTest, DISABLED_FullscreenResize) { 1754 TEST_F(RenderWidgetHostViewAuraTest, DISABLED_FullscreenResize) {
1608 aura::Window* root_window = aura_test_helper_->root_window(); 1755 aura::Window* root_window = aura_test_helper_->root_window();
1609 root_window->SetLayoutManager(new FullscreenLayoutManager(root_window)); 1756 root_window->SetLayoutManager(new FullscreenLayoutManager(root_window));
1610 view_->InitAsFullscreen(parent_view_); 1757 view_->InitAsFullscreen(parent_view_);
1611 view_->Show(); 1758 view_->Show();
1612 widget_host_->ResetSizeAndRepaintPendingFlags(); 1759 widget_host_->ResetSizeAndRepaintPendingFlags();
1613 sink_->ClearMessages(); 1760 sink_->ClearMessages();
1614 1761
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 view_->SetSize(size3); 1962 view_->SetSize(size3);
1816 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); 1963 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1817 EXPECT_EQ(0u, sink_->message_count()); 1964 EXPECT_EQ(0u, sink_->message_count());
1818 1965
1819 // Receive a frame of the new size, should be skipped and not produce a Resize 1966 // Receive a frame of the new size, should be skipped and not produce a Resize
1820 // message. 1967 // message.
1821 view_->OnSwapCompositorFrame( 1968 view_->OnSwapCompositorFrame(
1822 0, MakeDelegatedFrame(1.f, size3, gfx::Rect(size3))); 1969 0, MakeDelegatedFrame(1.f, size3, gfx::Rect(size3)));
1823 // Expect the frame ack; 1970 // Expect the frame ack;
1824 EXPECT_EQ(1u, sink_->message_count()); 1971 EXPECT_EQ(1u, sink_->message_count());
1825 EXPECT_EQ(ViewMsg_SwapCompositorFrameAck::ID, sink_->GetMessageAt(0)->type()); 1972 EXPECT_EQ(ViewMsg_ReclaimCompositorResources::ID,
1973 sink_->GetMessageAt(0)->type());
1826 sink_->ClearMessages(); 1974 sink_->ClearMessages();
1827 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString()); 1975 EXPECT_EQ(size2.ToString(), view_->GetRequestedRendererSize().ToString());
1828 1976
1829 // Receive a frame of the correct size, should not be skipped and, and should 1977 // Receive a frame of the correct size, should not be skipped and, and should
1830 // produce a Resize message after the commit. 1978 // produce a Resize message after the commit.
1831 view_->OnSwapCompositorFrame( 1979 view_->OnSwapCompositorFrame(
1832 0, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2))); 1980 0, MakeDelegatedFrame(1.f, size2, gfx::Rect(size2)));
1833 cc::SurfaceId surface_id = view_->surface_id(); 1981 cc::SurfaceId surface_id = view_->surface_id();
1834 if (surface_id.is_null()) { 1982 if (surface_id.is_null()) {
1835 // No frame ack yet. 1983 // No frame ack yet.
(...skipping 18 matching lines...) Expand all
1854 // call 2002 // call
1855 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow, 2003 // ui::WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow,
1856 // which the above WaitForCommit may cause to be picked up. Be robust 2004 // which the above WaitForCommit may cause to be picked up. Be robust
1857 // to this extra IPC coming in. 2005 // to this extra IPC coming in.
1858 InputMsg_HandleInputEvent::Param params; 2006 InputMsg_HandleInputEvent::Param params;
1859 InputMsg_HandleInputEvent::Read(msg, &params); 2007 InputMsg_HandleInputEvent::Read(msg, &params);
1860 const blink::WebInputEvent* event = std::get<0>(params); 2008 const blink::WebInputEvent* event = std::get<0>(params);
1861 EXPECT_EQ(blink::WebInputEvent::MouseMove, event->type); 2009 EXPECT_EQ(blink::WebInputEvent::MouseMove, event->type);
1862 break; 2010 break;
1863 } 2011 }
1864 case ViewMsg_SwapCompositorFrameAck::ID: 2012 case ViewMsg_ReclaimCompositorResources::ID:
1865 break; 2013 break;
1866 case ViewMsg_Resize::ID: { 2014 case ViewMsg_Resize::ID: {
1867 EXPECT_FALSE(has_resize); 2015 EXPECT_FALSE(has_resize);
1868 ViewMsg_Resize::Param params; 2016 ViewMsg_Resize::Param params;
1869 ViewMsg_Resize::Read(msg, &params); 2017 ViewMsg_Resize::Read(msg, &params);
1870 EXPECT_EQ(size3.ToString(), std::get<0>(params).new_size.ToString()); 2018 EXPECT_EQ(size3.ToString(), std::get<0>(params).new_size.ToString());
1871 has_resize = true; 2019 has_resize = true;
1872 break; 2020 break;
1873 } 2021 }
1874 default: 2022 default:
(...skipping 2441 matching lines...) Expand 10 before | Expand all | Expand 10 after
4316 // No bounds at index 1. 4464 // No bounds at index 1.
4317 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound)); 4465 EXPECT_FALSE(text_input_client()->GetCompositionCharacterBounds(1, &bound));
4318 4466
4319 // Valid bound at index 0. 4467 // Valid bound at index 0.
4320 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound)); 4468 EXPECT_TRUE(text_input_client()->GetCompositionCharacterBounds(0, &bound));
4321 EXPECT_EQ(4 + (int)index, bound.height()); 4469 EXPECT_EQ(4 + (int)index, bound.height());
4322 } 4470 }
4323 } 4471 }
4324 4472
4325 } // namespace content 4473 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698