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

Side by Side Diff: content/browser/gpu/gpu_ipc_browsertests.cc

Issue 2967963002: gpu: Reduce of BrowserGpuChannelHostFactory. (Closed)
Patch Set: . Created 3 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 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/browser_main_loop.h"
9 #include "content/browser/compositor/image_transport_factory.h" 10 #include "content/browser/compositor/image_transport_factory.h"
10 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
11 #include "content/browser/gpu/gpu_process_host.h" 11 #include "content/browser/gpu/gpu_process_host.h"
12 #include "content/common/gpu_stream_constants.h" 12 #include "content/common/gpu_stream_constants.h"
13 #include "content/public/browser/gpu_data_manager.h" 13 #include "content/public/browser/gpu_data_manager.h"
14 #include "content/public/browser/gpu_utils.h" 14 #include "content/public/browser/gpu_utils.h"
15 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
16 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
17 #include "gpu/ipc/client/gpu_channel_host.h"
17 #include "services/ui/gpu/interfaces/gpu_service.mojom.h" 18 #include "services/ui/gpu/interfaces/gpu_service.mojom.h"
18 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h" 19 #include "services/ui/public/cpp/gpu/context_provider_command_buffer.h"
19 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "third_party/skia/include/core/SkPaint.h" 21 #include "third_party/skia/include/core/SkPaint.h"
21 #include "third_party/skia/include/core/SkSurface.h" 22 #include "third_party/skia/include/core/SkSurface.h"
22 #include "third_party/skia/include/gpu/GrContext.h" 23 #include "third_party/skia/include/gpu/GrContext.h"
23 #include "ui/gl/gl_switches.h" 24 #include "ui/gl/gl_switches.h"
24 25
25 namespace { 26 namespace {
26 27
(...skipping 25 matching lines...) Expand all
52 *retvalue = std::move(established_host); 53 *retvalue = std::move(established_host);
53 quit_closure.Run(); 54 quit_closure.Run();
54 } 55 }
55 56
56 class EstablishGpuChannelHelper { 57 class EstablishGpuChannelHelper {
57 public: 58 public:
58 EstablishGpuChannelHelper() {} 59 EstablishGpuChannelHelper() {}
59 ~EstablishGpuChannelHelper() {} 60 ~EstablishGpuChannelHelper() {}
60 61
61 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSyncRunLoop() { 62 scoped_refptr<gpu::GpuChannelHost> EstablishGpuChannelSyncRunLoop() {
62 if (!content::BrowserGpuChannelHostFactory::instance()) 63 gpu::GpuChannelEstablishFactory* factory =
63 content::BrowserGpuChannelHostFactory::Initialize(true); 64 content::BrowserMainLoop::GetInstance()
64 65 ->gpu_channel_establish_factory();
65 content::BrowserGpuChannelHostFactory* factory =
66 content::BrowserGpuChannelHostFactory::instance();
67 CHECK(factory); 66 CHECK(factory);
68 base::RunLoop run_loop; 67 base::RunLoop run_loop;
69 factory->EstablishGpuChannel(base::Bind( 68 factory->EstablishGpuChannel(base::Bind(
70 &OnEstablishedGpuChannel, run_loop.QuitClosure(), &gpu_channel_host_)); 69 &OnEstablishedGpuChannel, run_loop.QuitClosure(), &gpu_channel_host_));
71 run_loop.Run(); 70 run_loop.Run();
72 return std::move(gpu_channel_host_); 71 return std::move(gpu_channel_host_);
73 } 72 }
74 73
75 private: 74 private:
76 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_; 75 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host_;
77 DISALLOW_COPY_AND_ASSIGN(EstablishGpuChannelHelper); 76 DISALLOW_COPY_AND_ASSIGN(EstablishGpuChannelHelper);
78 }; 77 };
79 78
80 class ContextTestBase : public content::ContentBrowserTest { 79 class ContextTestBase : public content::ContentBrowserTest {
81 public: 80 public:
82 void SetUpOnMainThread() override { 81 void SetUpOnMainThread() override {
83 // This may leave the provider_ null in some cases, so tests need to early 82 // This may leave the provider_ null in some cases, so tests need to early
84 // out. 83 // out.
85 if (!content::BrowserGpuChannelHostFactory::CanUseForTesting()) 84 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(nullptr))
86 return; 85 return;
87 86
88 EstablishGpuChannelHelper helper; 87 EstablishGpuChannelHelper helper;
89 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host = 88 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host =
90 helper.EstablishGpuChannelSyncRunLoop(); 89 helper.EstablishGpuChannelSyncRunLoop();
91 CHECK(gpu_channel_host); 90 CHECK(gpu_channel_host);
92 91
93 provider_ = CreateContext(std::move(gpu_channel_host)); 92 provider_ = CreateContext(std::move(gpu_channel_host));
94 bool bound = provider_->BindToCurrentThread(); 93 bool bound = provider_->BindToCurrentThread();
95 CHECK(bound); 94 CHECK(bound);
(...skipping 21 matching lines...) Expand all
117 116
118 // Include the shared tests. 117 // Include the shared tests.
119 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F 118 #define CONTEXT_TEST_F IN_PROC_BROWSER_TEST_F
120 #include "gpu/ipc/client/gpu_context_tests.h" 119 #include "gpu/ipc/client/gpu_context_tests.h"
121 120
122 namespace content { 121 namespace content {
123 122
124 class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest { 123 class BrowserGpuChannelHostFactoryTest : public ContentBrowserTest {
125 public: 124 public:
126 void SetUpOnMainThread() override { 125 void SetUpOnMainThread() override {
127 if (!BrowserGpuChannelHostFactory::CanUseForTesting()) 126 if (!GpuDataManager::GetInstance()->GpuAccessAllowed(nullptr))
128 return; 127 return;
129
130 // Start all tests without a gpu channel so that the tests exercise a
131 // consistent codepath.
132 if (!BrowserGpuChannelHostFactory::instance())
133 BrowserGpuChannelHostFactory::Initialize(false);
piman 2017/07/05 17:48:15 What is the replacement for this? Without this I'm
sadrul 2017/07/05 18:39:51 The initialization in BrowserMainLoop [1] should a
piman 2017/07/05 18:58:36 Ok, thanks. That probably explains some of the fla
134 CHECK(GetFactory()); 128 CHECK(GetFactory());
135
136 ContentBrowserTest::SetUpOnMainThread(); 129 ContentBrowserTest::SetUpOnMainThread();
137 } 130 }
138 131
139 void SetUpCommandLine(base::CommandLine* command_line) override { 132 void SetUpCommandLine(base::CommandLine* command_line) override {
140 // Start all tests without a gpu channel so that the tests exercise a 133 // Start all tests without a gpu channel so that the tests exercise a
141 // consistent codepath. 134 // consistent codepath.
142 command_line->AppendSwitch(switches::kDisableGpuEarlyInit); 135 command_line->AppendSwitch(switches::kDisableGpuEarlyInit);
143 } 136 }
144 137
145 void OnContextLost(const base::Closure callback, int* counter) { 138 void OnContextLost(const base::Closure callback, int* counter) {
146 (*counter)++; 139 (*counter)++;
147 callback.Run(); 140 callback.Run();
148 } 141 }
149 142
150 void Signal(bool* event, 143 void Signal(bool* event,
151 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { 144 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
152 CHECK_EQ(*event, false); 145 CHECK_EQ(*event, false);
153 *event = true; 146 *event = true;
154 gpu_channel_host_ = std::move(gpu_channel_host); 147 gpu_channel_host_ = std::move(gpu_channel_host);
155 } 148 }
156 149
157 protected: 150 protected:
158 BrowserGpuChannelHostFactory* GetFactory() { 151 gpu::GpuChannelEstablishFactory* GetFactory() {
159 return BrowserGpuChannelHostFactory::instance(); 152 return BrowserMainLoop::GetInstance()->gpu_channel_establish_factory();
160 } 153 }
161 154
162 bool IsChannelEstablished() { 155 bool IsChannelEstablished() {
163 return gpu_channel_host_ && !gpu_channel_host_->IsLost(); 156 return gpu_channel_host_ && !gpu_channel_host_->IsLost();
164 } 157 }
165 158
166 void EstablishAndWait() { 159 void EstablishAndWait() {
167 EstablishGpuChannelHelper helper; 160 EstablishGpuChannelHelper helper;
168 gpu_channel_host_ = helper.EstablishGpuChannelSyncRunLoop(); 161 gpu_channel_host_ = helper.EstablishGpuChannelSyncRunLoop();
169 } 162 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 297
305 IN_PROC_BROWSER_TEST_F(GpuProcessHostBrowserTest, Shutdown) { 298 IN_PROC_BROWSER_TEST_F(GpuProcessHostBrowserTest, Shutdown) {
306 DCHECK(!IsChannelEstablished()); 299 DCHECK(!IsChannelEstablished());
307 EstablishAndWait(); 300 EstablishAndWait();
308 base::RunLoop run_loop; 301 base::RunLoop run_loop;
309 StopGpuProcess(run_loop.QuitClosure()); 302 StopGpuProcess(run_loop.QuitClosure());
310 run_loop.Run(); 303 run_loop.Run();
311 } 304 }
312 305
313 } // namespace content 306 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/browser_gpu_channel_host_factory.cc ('k') | content/browser/renderer_host/compositor_impl_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698