OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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 "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 6 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" |
| 7 #include "content/browser/renderer_host/offscreen_canvas_compositor_frame_sink_m
anager.h" |
7 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" | 8 #include "content/browser/renderer_host/offscreen_canvas_surface_impl.h" |
8 #include "content/browser/renderer_host/offscreen_canvas_surface_manager.h" | |
9 #include "content/public/test/test_browser_thread.h" | 9 #include "content/public/test/test_browser_thread.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 #if defined(OS_ANDROID) | 13 #if defined(OS_ANDROID) |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" | 15 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" |
16 #include "content/test/mock_gpu_channel_establish_factory.h" | 16 #include "content/test/mock_gpu_channel_establish_factory.h" |
17 #else | 17 #else |
18 #include "content/browser/compositor/image_transport_factory.h" | 18 #include "content/browser/compositor/image_transport_factory.h" |
19 #endif | 19 #endif |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 class OffscreenCanvasSurfaceManagerTest : public testing::Test { | 23 class OffscreenCanvasCompositorFrameSinkManagerTest : public testing::Test { |
24 public: | 24 public: |
25 int getNumSurfaceImplInstances() { | 25 int getNumSurfaceImplInstances() { |
26 return OffscreenCanvasSurfaceManager::GetInstance() | 26 return OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
27 ->registered_surface_instances_.size(); | 27 ->registered_surface_instances_.size(); |
28 } | 28 } |
29 | 29 |
30 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { | 30 void OnSurfaceCreated(const cc::SurfaceId& surface_id) { |
31 OffscreenCanvasSurfaceManager::GetInstance()->OnSurfaceCreated( | 31 OffscreenCanvasCompositorFrameSinkManager::GetInstance()->OnSurfaceCreated( |
32 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); | 32 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(10, 10))); |
33 } | 33 } |
34 | 34 |
35 protected: | 35 protected: |
36 void SetUp() override; | 36 void SetUp() override; |
37 void TearDown() override; | 37 void TearDown() override; |
38 | 38 |
39 private: | 39 private: |
40 std::unique_ptr<TestBrowserThread> ui_thread_; | 40 std::unique_ptr<TestBrowserThread> ui_thread_; |
41 base::MessageLoopForUI message_loop_; | 41 base::MessageLoopForUI message_loop_; |
42 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
43 MockGpuChannelEstablishFactory gpu_channel_factory_; | 43 MockGpuChannelEstablishFactory gpu_channel_factory_; |
44 #endif | 44 #endif |
45 }; | 45 }; |
46 | 46 |
47 void OffscreenCanvasSurfaceManagerTest::SetUp() { | 47 void OffscreenCanvasCompositorFrameSinkManagerTest::SetUp() { |
48 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
49 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); | 49 ContextProviderFactoryImpl::Initialize(&gpu_channel_factory_); |
50 ui::ContextProviderFactory::SetInstance( | 50 ui::ContextProviderFactory::SetInstance( |
51 ContextProviderFactoryImpl::GetInstance()); | 51 ContextProviderFactoryImpl::GetInstance()); |
52 #else | 52 #else |
53 ImageTransportFactory::InitializeForUnitTests( | 53 ImageTransportFactory::InitializeForUnitTests( |
54 std::unique_ptr<ImageTransportFactory>( | 54 std::unique_ptr<ImageTransportFactory>( |
55 new NoTransportImageTransportFactory)); | 55 new NoTransportImageTransportFactory)); |
56 #endif | 56 #endif |
57 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); | 57 ui_thread_.reset(new TestBrowserThread(BrowserThread::UI, &message_loop_)); |
58 } | 58 } |
59 | 59 |
60 void OffscreenCanvasSurfaceManagerTest::TearDown() { | 60 void OffscreenCanvasCompositorFrameSinkManagerTest::TearDown() { |
61 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
62 ui::ContextProviderFactory::SetInstance(nullptr); | 62 ui::ContextProviderFactory::SetInstance(nullptr); |
63 ContextProviderFactoryImpl::Terminate(); | 63 ContextProviderFactoryImpl::Terminate(); |
64 #else | 64 #else |
65 ImageTransportFactory::Terminate(); | 65 ImageTransportFactory::Terminate(); |
66 #endif | 66 #endif |
67 } | 67 } |
68 | 68 |
69 // This test mimics the workflow of OffscreenCanvas.commit() on renderer | 69 // This test mimics the workflow of OffscreenCanvas.commit() on renderer |
70 // process. | 70 // process. |
71 TEST_F(OffscreenCanvasSurfaceManagerTest, | 71 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, |
72 SingleHTMLCanvasElementTransferToOffscreen) { | 72 SingleHTMLCanvasElementTransferToOffscreen) { |
73 cc::mojom::DisplayCompositorClientPtr client; | 73 cc::mojom::DisplayCompositorClientPtr client; |
74 cc::FrameSinkId frame_sink_id(3, 3); | 74 cc::FrameSinkId frame_sink_id(3, 3); |
75 cc::SurfaceIdAllocator surface_id_allocator; | 75 cc::SurfaceIdAllocator surface_id_allocator; |
76 cc::LocalSurfaceId current_local_surface_id( | 76 cc::LocalSurfaceId current_local_surface_id( |
77 surface_id_allocator.GenerateId()); | 77 surface_id_allocator.GenerateId()); |
78 | 78 |
79 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 79 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
80 cc::FrameSinkId(), frame_sink_id, std::move(client))); | 80 cc::FrameSinkId(), frame_sink_id, std::move(client))); |
81 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 81 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
82 EXPECT_EQ(surface_impl.get(), | 82 EXPECT_EQ(surface_impl.get(), |
83 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 83 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
84 frame_sink_id)); | 84 ->GetSurfaceInstance(frame_sink_id)); |
85 | 85 |
86 this->OnSurfaceCreated( | 86 this->OnSurfaceCreated( |
87 cc::SurfaceId(frame_sink_id, current_local_surface_id)); | 87 cc::SurfaceId(frame_sink_id, current_local_surface_id)); |
88 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); | 88 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); |
89 | 89 |
90 surface_impl = nullptr; | 90 surface_impl = nullptr; |
91 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 91 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
92 } | 92 } |
93 | 93 |
94 TEST_F(OffscreenCanvasSurfaceManagerTest, | 94 TEST_F(OffscreenCanvasCompositorFrameSinkManagerTest, |
95 MultiHTMLCanvasElementTransferToOffscreen) { | 95 MultiHTMLCanvasElementTransferToOffscreen) { |
96 cc::mojom::DisplayCompositorClientPtr client_a; | 96 cc::mojom::DisplayCompositorClientPtr client_a; |
97 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); | 97 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); |
98 cc::FrameSinkId frame_sink_id_a(3, 3); | 98 cc::FrameSinkId frame_sink_id_a(3, 3); |
99 cc::SurfaceIdAllocator surface_id_allocator; | 99 cc::SurfaceIdAllocator surface_id_allocator; |
100 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 100 auto surface_impl_a = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
101 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); | 101 dummy_parent_frame_sink_id, frame_sink_id_a, std::move(client_a))); |
102 | 102 |
103 cc::mojom::DisplayCompositorClientPtr client_b; | 103 cc::mojom::DisplayCompositorClientPtr client_b; |
104 cc::FrameSinkId frame_sink_id_b(4, 4); | 104 cc::FrameSinkId frame_sink_id_b(4, 4); |
105 | 105 |
106 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 106 auto surface_impl_b = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
107 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); | 107 dummy_parent_frame_sink_id, frame_sink_id_b, std::move(client_b))); |
108 | 108 |
109 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); | 109 EXPECT_EQ(2, this->getNumSurfaceImplInstances()); |
110 EXPECT_EQ(surface_impl_a.get(), | 110 EXPECT_EQ(surface_impl_a.get(), |
111 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 111 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
112 frame_sink_id_a)); | 112 ->GetSurfaceInstance(frame_sink_id_a)); |
113 EXPECT_EQ(surface_impl_b.get(), | 113 EXPECT_EQ(surface_impl_b.get(), |
114 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 114 OffscreenCanvasCompositorFrameSinkManager::GetInstance() |
115 frame_sink_id_b)); | 115 ->GetSurfaceInstance(frame_sink_id_b)); |
116 | 116 |
117 surface_impl_a = nullptr; | 117 surface_impl_a = nullptr; |
118 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 118 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
119 surface_impl_b = nullptr; | 119 surface_impl_b = nullptr; |
120 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 120 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
121 } | 121 } |
122 | 122 |
123 } // namespace content | 123 } // namespace content |
OLD | NEW |