| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "content/browser/compositor/image_transport_factory.h" |
| 9 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 10 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 10 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 11 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 11 #include "content/common/gpu/client/context_provider_command_buffer.h" | 12 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 12 #include "content/public/browser/gpu_data_manager.h" | 13 #include "content/public/browser/gpu_data_manager.h" |
| 13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkPaint.h" | 17 #include "third_party/skia/include/core/SkPaint.h" |
| 17 #include "third_party/skia/include/core/SkSurface.h" | 18 #include "third_party/skia/include/core/SkSurface.h" |
| 18 #include "third_party/skia/include/gpu/GrContext.h" | 19 #include "third_party/skia/include/gpu/GrContext.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 33 attributes.bind_generates_resource = false; | 34 attributes.bind_generates_resource = false; |
| 34 constexpr bool automatic_flushes = false; | 35 constexpr bool automatic_flushes = false; |
| 35 constexpr bool support_locking = false; | 36 constexpr bool support_locking = false; |
| 36 return make_scoped_refptr(new content::ContextProviderCommandBuffer( | 37 return make_scoped_refptr(new content::ContextProviderCommandBuffer( |
| 37 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, | 38 std::move(gpu_channel_host), gpu::GPU_STREAM_DEFAULT, |
| 38 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, GURL(), | 39 gpu::GpuStreamPriority::NORMAL, gpu::kNullSurfaceHandle, GURL(), |
| 39 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes, | 40 automatic_flushes, support_locking, gpu::SharedMemoryLimits(), attributes, |
| 40 nullptr, content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)); | 41 nullptr, content::command_buffer_metrics::OFFSCREEN_CONTEXT_FOR_TESTING)); |
| 41 } | 42 } |
| 42 | 43 |
| 43 class ContextTestBase : public content::ContentBrowserTest { | 44 void OnEstablishedGpuChannel( |
| 45 const base::Closure& quit_closure, |
| 46 scoped_refptr<gpu::GpuChannelHost>* retvalue, |
| 47 scoped_refptr<gpu::GpuChannelHost> established_host) { |
| 48 if (retvalue) |
| 49 *retvalue = std::move(established_host); |
| 50 quit_closure.Run(); |
| 51 } |
| 52 |
| 53 class EstablishGpuChannelHelper { |
| 44 public: | 54 public: |
| 45 void SetUpOnMainThread() override { | 55 EstablishGpuChannelHelper() {} |
| 46 // This may leave the provider_ null in some cases, so tests need to early | 56 ~EstablishGpuChannelHelper() {} |
| 47 // out. | |
| 48 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) | |
| 49 return; | |
| 50 | 57 |
| 58 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSyncRunLoop() { |
| 51 if (!content::BrowserGpuChannelHostFactory::instance()) | 59 if (!content::BrowserGpuChannelHostFactory::instance()) |
| 52 content::BrowserGpuChannelHostFactory::Initialize(true); | 60 content::BrowserGpuChannelHostFactory::Initialize(true); |
| 53 | 61 |
| 54 content::BrowserGpuChannelHostFactory* factory = | 62 content::BrowserGpuChannelHostFactory* factory = |
| 55 content::BrowserGpuChannelHostFactory::instance(); | 63 content::BrowserGpuChannelHostFactory::instance(); |
| 56 CHECK(factory); | 64 CHECK(factory); |
| 57 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
| 58 factory->EstablishGpuChannel(run_loop.QuitClosure()); | 66 factory->EstablishGpuChannel(base::Bind( |
| 67 &OnEstablishedGpuChannel, run_loop.QuitClosure(), &gpu_channel_host_)); |
| 59 run_loop.Run(); | 68 run_loop.Run(); |
| 60 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host( | 69 return std::move(gpu_channel_host_); |
| 61 factory->GetGpuChannel()); | 70 } |
| 71 |
| 72 private: |
| 73 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_; |
| 74 DISALLOW_COPY_AND_ASSIGN(EstablishGpuChannelHelper); |
| 75 }; |
| 76 |
| 77 class ContextTestBase : public content::ContentBrowserTest { |
| 78 public: |
| 79 void SetUpOnMainThread() override { |
| 80 // This may leave the provider_ null in some cases, so tests need to early |
| 81 // out. |
| 82 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) |
| 83 return; |
| 84 |
| 85 EstablishGpuChannelHelper helper; |
| 86 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = |
| 87 helper.EstablishGpuChannelSyncRunLoop(); |
| 62 CHECK(gpu_channel_host); | 88 CHECK(gpu_channel_host); |
| 63 | 89 |
| 64 provider_ = CreateContext(std::move(gpu_channel_host)); | 90 provider_ = CreateContext(std::move(gpu_channel_host)); |
| 65 bool bound = provider_->BindToCurrentThread(); | 91 bool bound = provider_->BindToCurrentThread(); |
| 66 CHECK(bound); | 92 CHECK(bound); |
| 67 gl_ = provider_->ContextGL(); | 93 gl_ = provider_->ContextGL(); |
| 68 context_support_ = provider_->ContextSupport(); | 94 context_support_ = provider_->ContextSupport(); |
| 69 | 95 |
| 70 ContentBrowserTest::SetUpOnMainThread(); | 96 ContentBrowserTest::SetUpOnMainThread(); |
| 71 } | 97 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest { | 121 class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest { |
| 96 public: | 122 public: |
| 97 void SetUpOnMainThread() override { | 123 void SetUpOnMainThread() override { |
| 98 if (!BrowserGpuChannelHostFactory::CanUseForTesting()) | 124 if (!BrowserGpuChannelHostFactory::CanUseForTesting()) |
| 99 return; | 125 return; |
| 100 | 126 |
| 101 // Start all tests without a gpu channel so that the tests exercise a | 127 // Start all tests without a gpu channel so that the tests exercise a |
| 102 // consistent codepath. | 128 // consistent codepath. |
| 103 if (!BrowserGpuChannelHostFactory::instance()) | 129 if (!BrowserGpuChannelHostFactory::instance()) |
| 104 BrowserGpuChannelHostFactory::Initialize(false); | 130 BrowserGpuChannelHostFactory::Initialize(false); |
| 105 | |
| 106 CHECK(GetFactory()); | 131 CHECK(GetFactory()); |
| 107 | 132 |
| 108 ContentBrowserTest::SetUpOnMainThread(); | 133 ContentBrowserTest::SetUpOnMainThread(); |
| 109 } | 134 } |
| 110 | 135 |
| 111 void SetUpCommandLine(base::CommandLine* command_line) override { | 136 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 112 // Start all tests without a gpu channel so that the tests exercise a | 137 // Start all tests without a gpu channel so that the tests exercise a |
| 113 // consistent codepath. | 138 // consistent codepath. |
| 114 command_line->AppendSwitch(switches::kDisableGpuEarlyInit); | 139 command_line->AppendSwitch(switches::kDisableGpuEarlyInit); |
| 115 } | 140 } |
| 116 | 141 |
| 117 void OnContextLost(const base::Closure callback, int* counter) { | 142 void OnContextLost(const base::Closure callback, int* counter) { |
| 118 (*counter)++; | 143 (*counter)++; |
| 119 callback.Run(); | 144 callback.Run(); |
| 120 } | 145 } |
| 121 | 146 |
| 147 void Signal(bool* event, |
| 148 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 149 CHECK_EQ(*event, false); |
| 150 *event = true; |
| 151 gpu_channel_host_ = std::move(gpu_channel_host); |
| 152 } |
| 153 |
| 122 protected: | 154 protected: |
| 123 BrowserGpuChannelHostFactory* GetFactory() { | 155 BrowserGpuChannelHostFactory* GetFactory() { |
| 124 return BrowserGpuChannelHostFactory::instance(); | 156 return BrowserGpuChannelHostFactory::instance(); |
| 125 } | 157 } |
| 126 | 158 |
| 127 bool IsChannelEstablished() { | 159 bool IsChannelEstablished() { |
| 128 return GetFactory()->GetGpuChannel() != NULL; | 160 return gpu_channel_host_ && !gpu_channel_host_->IsLost(); |
| 129 } | 161 } |
| 130 | 162 |
| 131 void EstablishAndWait() { | 163 void EstablishAndWait() { |
| 132 base::RunLoop run_loop; | 164 EstablishGpuChannelHelper helper; |
| 133 GetFactory()->EstablishGpuChannel(run_loop.QuitClosure()); | 165 gpu_channel_host_ = helper.EstablishGpuChannelSyncRunLoop(); |
| 134 run_loop.Run(); | |
| 135 } | 166 } |
| 136 | 167 |
| 137 gpu::GpuChannelHost* GetGpuChannel() { return GetFactory()->GetGpuChannel(); } | 168 gpu::GpuChannelHost* GetGpuChannel() { return gpu_channel_host_.get(); } |
| 138 | 169 |
| 139 static void Signal(bool *event) { | 170 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_; |
| 140 CHECK_EQ(*event, false); | |
| 141 *event = true; | |
| 142 } | |
| 143 }; | 171 }; |
| 144 | 172 |
| 145 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 173 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 146 // establishes a GPU channel. | 174 // establishes a GPU channel. |
| 147 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 175 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 148 #define MAYBE_Basic Basic | 176 #define MAYBE_Basic Basic |
| 149 #else | 177 #else |
| 150 #define MAYBE_Basic DISABLED_Basic | 178 #define MAYBE_Basic DISABLED_Basic |
| 151 #endif | 179 #endif |
| 152 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, MAYBE_Basic) { | 180 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, MAYBE_Basic) { |
| 153 DCHECK(!IsChannelEstablished()); | 181 DCHECK(!IsChannelEstablished()); |
| 154 EstablishAndWait(); | 182 EstablishAndWait(); |
| 155 EXPECT_TRUE(GetGpuChannel() != NULL); | 183 EXPECT_TRUE(GetGpuChannel() != NULL); |
| 156 } | 184 } |
| 157 | 185 |
| 158 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 186 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 159 // establishes a GPU channel. | 187 // establishes a GPU channel. |
| 160 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 188 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 161 #define MAYBE_EstablishAndTerminate EstablishAndTerminate | 189 #define MAYBE_EstablishAndTerminate EstablishAndTerminate |
| 162 #else | 190 #else |
| 163 #define MAYBE_EstablishAndTerminate DISABLED_EstablishAndTerminate | 191 #define MAYBE_EstablishAndTerminate DISABLED_EstablishAndTerminate |
| 164 #endif | 192 #endif |
| 165 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 193 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 166 MAYBE_EstablishAndTerminate) { | 194 MAYBE_EstablishAndTerminate) { |
| 167 DCHECK(!IsChannelEstablished()); | 195 DCHECK(!IsChannelEstablished()); |
| 168 base::RunLoop run_loop; | 196 base::RunLoop run_loop; |
| 169 GetFactory()->EstablishGpuChannel(run_loop.QuitClosure()); | 197 GetFactory()->EstablishGpuChannel( |
| 198 base::Bind(&OnEstablishedGpuChannel, run_loop.QuitClosure(), nullptr)); |
| 170 GetFactory()->Terminate(); | 199 GetFactory()->Terminate(); |
| 171 | 200 |
| 172 // The callback should still trigger. | 201 // The callback should still trigger. |
| 173 run_loop.Run(); | 202 run_loop.Run(); |
| 174 } | 203 } |
| 175 | 204 |
| 176 #if !defined(OS_ANDROID) | 205 #if !defined(OS_ANDROID) |
| 177 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 206 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 178 // establishes a GPU channel. | 207 // establishes a GPU channel. |
| 179 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 208 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 180 #define MAYBE_AlreadyEstablished AlreadyEstablished | 209 #define MAYBE_AlreadyEstablished AlreadyEstablished |
| 181 #else | 210 #else |
| 182 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished | 211 #define MAYBE_AlreadyEstablished DISABLED_AlreadyEstablished |
| 183 #endif | 212 #endif |
| 184 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 213 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 185 MAYBE_AlreadyEstablished) { | 214 MAYBE_AlreadyEstablished) { |
| 186 DCHECK(!IsChannelEstablished()); | 215 DCHECK(!IsChannelEstablished()); |
| 187 scoped_refptr<gpu::GpuChannelHost> gpu_channel = | 216 scoped_refptr<gpu::GpuChannelHost> gpu_channel = |
| 188 GetFactory()->EstablishGpuChannelSync(); | 217 GetFactory()->EstablishGpuChannelSync(); |
| 189 | 218 |
| 190 // Expect established callback immediately. | 219 // Expect established callback immediately. |
| 191 bool event = false; | 220 bool event = false; |
| 192 GetFactory()->EstablishGpuChannel( | 221 GetFactory()->EstablishGpuChannel( |
| 193 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, &event)); | 222 base::Bind(&BrowserGpuChannelHostFactoryTest::Signal, |
| 223 base::Unretained(this), &event)); |
| 194 EXPECT_TRUE(event); | 224 EXPECT_TRUE(event); |
| 195 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); | 225 EXPECT_EQ(gpu_channel.get(), GetGpuChannel()); |
| 196 } | 226 } |
| 197 #endif | 227 #endif |
| 198 | 228 |
| 199 // Test fails on Windows because GPU Channel set-up fails. | 229 // Test fails on Windows because GPU Channel set-up fails. |
| 200 #if !defined(OS_WIN) | 230 #if !defined(OS_WIN) |
| 201 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive | 231 #define MAYBE_GrContextKeepsGpuChannelAlive GrContextKeepsGpuChannelAlive |
| 202 #else | 232 #else |
| 203 #define MAYBE_GrContextKeepsGpuChannelAlive \ | 233 #define MAYBE_GrContextKeepsGpuChannelAlive \ |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 SkPaint greenFillPaint; | 276 SkPaint greenFillPaint; |
| 247 greenFillPaint.setColor(SK_ColorGREEN); | 277 greenFillPaint.setColor(SK_ColorGREEN); |
| 248 greenFillPaint.setStyle(SkPaint::kFill_Style); | 278 greenFillPaint.setStyle(SkPaint::kFill_Style); |
| 249 // Passes by not crashing | 279 // Passes by not crashing |
| 250 surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), greenFillPaint); | 280 surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), greenFillPaint); |
| 251 } | 281 } |
| 252 | 282 |
| 253 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor | 283 // Test fails on Chromeos + Mac, flaky on Windows because UI Compositor |
| 254 // establishes a GPU channel. | 284 // establishes a GPU channel. |
| 255 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 285 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 256 #define MAYBE_CrashAndRecover | 286 #define MAYBE_CrashAndRecover CrashAndRecover |
| 257 #else | 287 #else |
| 258 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover | 288 #define MAYBE_CrashAndRecover DISABLED_CrashAndRecover |
| 259 #endif | 289 #endif |
| 260 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, | 290 IN_PROC_BROWSER_TEST_F(BrowserGpuChannelHostFactoryTest, |
| 261 MAYBE_CrashAndRecover) { | 291 MAYBE_CrashAndRecover) { |
| 262 DCHECK(!IsChannelEstablished()); | 292 DCHECK(!IsChannelEstablished()); |
| 263 EstablishAndWait(); | 293 EstablishAndWait(); |
| 264 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); | 294 scoped_refptr<gpu::GpuChannelHost> host = GetGpuChannel(); |
| 265 | 295 |
| 266 scoped_refptr<ContextProviderCommandBuffer> provider = | 296 scoped_refptr<ContextProviderCommandBuffer> provider = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 277 shim->SimulateCrash(); | 307 shim->SimulateCrash(); |
| 278 run_loop.Run(); | 308 run_loop.Run(); |
| 279 | 309 |
| 280 EXPECT_EQ(1, counter); | 310 EXPECT_EQ(1, counter); |
| 281 EXPECT_FALSE(IsChannelEstablished()); | 311 EXPECT_FALSE(IsChannelEstablished()); |
| 282 EstablishAndWait(); | 312 EstablishAndWait(); |
| 283 EXPECT_TRUE(IsChannelEstablished()); | 313 EXPECT_TRUE(IsChannelEstablished()); |
| 284 } | 314 } |
| 285 | 315 |
| 286 } // namespace content | 316 } // namespace content |
| OLD | NEW |