| 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 "cc/surfaces/local_surface_id_allocator.h" |
| 6 #include "content/browser/compositor/test/no_transport_image_transport_factory.h
" | 7 #include "content/browser/compositor/test/no_transport_image_transport_factory.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/browser/renderer_host/offscreen_canvas_surface_manager.h" |
| 9 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 11 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 #if defined(OS_ANDROID) | 14 #if defined(OS_ANDROID) |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" | 16 #include "content/browser/renderer_host/context_provider_factory_impl_android.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 ImageTransportFactory::Terminate(); | 66 ImageTransportFactory::Terminate(); |
| 66 #endif | 67 #endif |
| 67 } | 68 } |
| 68 | 69 |
| 69 // This test mimics the workflow of OffscreenCanvas.commit() on renderer | 70 // This test mimics the workflow of OffscreenCanvas.commit() on renderer |
| 70 // process. | 71 // process. |
| 71 TEST_F(OffscreenCanvasSurfaceManagerTest, | 72 TEST_F(OffscreenCanvasSurfaceManagerTest, |
| 72 SingleHTMLCanvasElementTransferToOffscreen) { | 73 SingleHTMLCanvasElementTransferToOffscreen) { |
| 73 cc::mojom::DisplayCompositorClientPtr client; | 74 cc::mojom::DisplayCompositorClientPtr client; |
| 74 cc::FrameSinkId frame_sink_id(3, 3); | 75 cc::FrameSinkId frame_sink_id(3, 3); |
| 75 cc::SurfaceIdAllocator surface_id_allocator; | 76 cc::LocalSurfaceIdAllocator local_surface_id_allocator; |
| 76 cc::LocalSurfaceId current_local_surface_id( | 77 cc::LocalSurfaceId current_local_surface_id( |
| 77 surface_id_allocator.GenerateId()); | 78 local_surface_id_allocator.GenerateId()); |
| 78 | 79 |
| 79 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( | 80 auto surface_impl = base::WrapUnique(new OffscreenCanvasSurfaceImpl( |
| 80 cc::FrameSinkId(), frame_sink_id, std::move(client))); | 81 cc::FrameSinkId(), frame_sink_id, std::move(client))); |
| 81 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); | 82 EXPECT_EQ(1, this->getNumSurfaceImplInstances()); |
| 82 EXPECT_EQ(surface_impl.get(), | 83 EXPECT_EQ(surface_impl.get(), |
| 83 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 84 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( |
| 84 frame_sink_id)); | 85 frame_sink_id)); |
| 85 | 86 |
| 86 this->OnSurfaceCreated( | 87 this->OnSurfaceCreated( |
| 87 cc::SurfaceId(frame_sink_id, current_local_surface_id)); | 88 cc::SurfaceId(frame_sink_id, current_local_surface_id)); |
| 88 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); | 89 EXPECT_EQ(current_local_surface_id, surface_impl->current_local_surface_id()); |
| 89 | 90 |
| 90 surface_impl = nullptr; | 91 surface_impl = nullptr; |
| 91 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); | 92 EXPECT_EQ(0, this->getNumSurfaceImplInstances()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 TEST_F(OffscreenCanvasSurfaceManagerTest, | 95 TEST_F(OffscreenCanvasSurfaceManagerTest, |
| 95 MultiHTMLCanvasElementTransferToOffscreen) { | 96 MultiHTMLCanvasElementTransferToOffscreen) { |
| 96 cc::mojom::DisplayCompositorClientPtr client_a; | 97 cc::mojom::DisplayCompositorClientPtr client_a; |
| 97 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); | 98 cc::FrameSinkId dummy_parent_frame_sink_id(0, 0); |
| 98 cc::FrameSinkId frame_sink_id_a(3, 3); | 99 cc::FrameSinkId frame_sink_id_a(3, 3); |
| 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 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( |
| 112 frame_sink_id_a)); | 112 frame_sink_id_a)); |
| 113 EXPECT_EQ(surface_impl_b.get(), | 113 EXPECT_EQ(surface_impl_b.get(), |
| 114 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( | 114 OffscreenCanvasSurfaceManager::GetInstance()->GetSurfaceInstance( |
| 115 frame_sink_id_b)); | 115 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 |