OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/android/blimp/chrome_compositor_dependencies.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "cc/output/context_provider.h" | |
10 #include "content/public/common/content_switches.h" | |
11 #include "gpu/command_buffer/client/gles2_interface.h" | |
12 #include "gpu/command_buffer/client/shared_memory_limits.h" | |
13 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | |
14 | |
15 namespace { | |
16 | |
17 bool IsValidWorkerContext(cc::ContextProvider* context_provider) { | |
18 cc::ContextProvider::ScopedContextLock lock(context_provider); | |
19 return context_provider->ContextGL()->GetGraphicsResetStatusKHR() == | |
20 GL_NO_ERROR; | |
21 } | |
22 | |
23 gpu::gles2::ContextCreationAttribHelper | |
24 GetOffscreenContextCreationAttributes() { | |
25 gpu::gles2::ContextCreationAttribHelper attributes; | |
26 attributes.alpha_size = -1; | |
27 attributes.depth_size = 0; | |
28 attributes.stencil_size = 0; | |
29 attributes.samples = 0; | |
30 attributes.sample_buffers = 0; | |
31 attributes.bind_generates_resource = false; | |
32 attributes.lose_context_when_out_of_memory = true; | |
33 return attributes; | |
34 } | |
35 | |
36 bool IsAsyncWorkerContextEnabled() { | |
37 const base::CommandLine& command_line = | |
38 *base::CommandLine::ForCurrentProcess(); | |
39 | |
40 if (command_line.HasSwitch(switches::kDisableGpuAsyncWorkerContext)) | |
41 return false; | |
42 else if (command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext)) | |
43 return true; | |
44 | |
45 return false; | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 ChromeCompositorDependencies::ChromeCompositorDependencies( | |
51 ui::ContextProviderFactory* context_provider_factory) | |
52 : context_provider_factory_(context_provider_factory), weak_factory_(this) { | |
53 DCHECK(context_provider_factory_); | |
54 } | |
55 | |
56 ChromeCompositorDependencies::~ChromeCompositorDependencies() = default; | |
57 | |
58 gpu::GpuMemoryBufferManager* | |
59 ChromeCompositorDependencies::GetGpuMemoryBufferManager() { | |
60 return context_provider_factory_->GetGpuMemoryBufferManager(); | |
61 } | |
62 | |
63 cc::SurfaceManager* ChromeCompositorDependencies::GetSurfaceManager() { | |
64 return context_provider_factory_->GetSurfaceManager(); | |
65 } | |
66 | |
67 uint32_t ChromeCompositorDependencies::AllocateSurfaceClientId() { | |
68 return context_provider_factory_->AllocateSurfaceClientId(); | |
69 } | |
70 | |
71 void ChromeCompositorDependencies::GetContextProviders( | |
72 const ContextProviderCallback& callback) { | |
73 pending_requests_.push_back(callback); | |
danakj
2016/09/01 23:35:18
It feels like you could just bind the callback int
Khushal
2016/09/02 00:24:33
Oh yes, didn't realize without the 2 async calls,
| |
74 context_provider_factory_->RequestGpuChannelHost( | |
75 base::Bind(&ChromeCompositorDependencies::OnGpuChannelEstablished, | |
76 weak_factory_.GetWeakPtr())); | |
77 } | |
78 | |
79 void ChromeCompositorDependencies::OnGpuChannelEstablished( | |
80 const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host, | |
danakj
2016/09/01 23:35:18
receive refptrs by value
Khushal
2016/09/02 00:24:32
Is there a reason why that is better? I thought it
danakj
2016/09/02 00:30:56
The caller should std::move if it doesnt need a co
Khushal
2016/09/02 01:13:35
Sorry if this is getting repetitive, I just want t
| |
81 ui::ContextProviderFactory::GpuChannelHostResult result) { | |
82 // We queue multiple requests, so early out in case the previous requests were | |
83 // already handled. | |
84 if (pending_requests_.empty()) | |
85 return; | |
86 | |
87 switch (result) { | |
88 case ui::ContextProviderFactory::GpuChannelHostResult:: | |
danakj
2016/09/01 23:35:18
if you "using ui::ContextProviderFactory::GpuChann
Khushal
2016/09/02 00:24:33
Done.
| |
89 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED: | |
90 // Pass the null result to the caller and let them try again. | |
91 break; | |
92 case ui::ContextProviderFactory::GpuChannelHostResult:: | |
93 FAILURE_FACTORY_SHUTDOWN: | |
94 // If the factory is shutting down, early out and drop the requests. | |
95 return; | |
96 case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS: | |
97 // Create the worker context first if necessary. | |
98 if (!shared_main_thread_worker_context_ || | |
99 !IsValidWorkerContext(shared_main_thread_worker_context_.get())) { | |
100 shared_main_thread_worker_context_ = | |
101 context_provider_factory_->CreateOffscreenContextProvider( | |
102 ui::ContextProviderFactory::ContextType:: | |
103 BLIMP_RENDER_WORKER_CONTEXT, | |
104 gpu::SharedMemoryLimits(), | |
105 GetOffscreenContextCreationAttributes(), | |
106 true /* support_locking */, false /* automatic_flushes */, | |
107 nullptr, gpu_channel_host.get()); | |
108 if (!shared_main_thread_worker_context_->BindToCurrentThread()) { | |
109 shared_main_thread_worker_context_ = nullptr; | |
110 } | |
111 } | |
112 break; | |
113 } | |
114 | |
115 // Copy the requests first since we can get more requests as we run these | |
116 // callbacks. | |
117 std::list<ContextProviderCallback> context_requests = pending_requests_; | |
118 pending_requests_.clear(); | |
119 | |
120 for (ContextProviderCallback& context_request : context_requests) { | |
121 scoped_refptr<cc::ContextProvider> compositor_context_provider; | |
122 | |
123 if (gpu_channel_host && shared_main_thread_worker_context_) { | |
124 // The compositor context shares resources with the worker context unless | |
125 // the worker is async. | |
126 cc::ContextProvider* shared_context = | |
127 IsAsyncWorkerContextEnabled() | |
danakj
2016/09/01 23:35:18
I'm not sure what the answer is, maybe talk with r
Khushal
2016/09/02 00:24:32
I think all of this is in compositor_util in conte
danakj
2016/09/02 00:30:56
That's content/browser though.
| |
128 ? nullptr | |
129 : shared_main_thread_worker_context_.get(); | |
130 | |
131 compositor_context_provider = | |
132 context_provider_factory_->CreateOffscreenContextProvider( | |
133 ui::ContextProviderFactory::ContextType:: | |
134 BLIMP_RENDER_COMPOSITOR_CONTEXT, | |
135 gpu::SharedMemoryLimits::ForMailboxContext(), | |
136 GetOffscreenContextCreationAttributes(), | |
137 false /* support_locking */, false /* automatic_flushes */, | |
138 shared_context, gpu_channel_host.get()); | |
danakj
2016/09/01 23:35:18
Why is this passing raw pointer to gpu_channel_hos
Khushal
2016/09/02 00:24:32
Done.
| |
139 } | |
140 | |
141 context_request.Run(compositor_context_provider, | |
142 shared_main_thread_worker_context_); | |
143 } | |
144 } | |
OLD | NEW |