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

Side by Side Diff: chrome/browser/android/blimp/chrome_compositor_dependencies.cc

Issue 2297933002: blimp: Set up the CompositorDependencies for blimp in Chrome. (Closed)
Patch Set: Rebase Created 4 years, 3 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
« no previous file with comments | « chrome/browser/android/blimp/chrome_compositor_dependencies.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 if (!context_provider)
danakj 2016/09/01 19:26:06 Why would it not just be a failure |result| in thi
Khushal 2016/09/01 19:39:57 Oh, I'm calling it from GetContextProviders also,
19 return false;
20
21 cc::ContextProvider::ScopedContextLock lock(context_provider);
22 return context_provider->ContextGL()->GetGraphicsResetStatusKHR() ==
danakj 2016/09/01 19:26:06 Why do you check this when the context is created?
Khushal 2016/09/01 19:39:57 So I only do this after the worker context is boun
danakj 2016/09/01 19:55:20 I think it does it when checking if it should reus
Khushal 2016/09/01 20:10:23 This one also checks it only during the re-use poi
23 GL_NO_ERROR;
24 }
25
26 void OnCompositorContextCreated(
27 const blimp::client::CompositorDependencies::ContextProviderCallback&
28 callback,
29 const scoped_refptr<cc::ContextProvider>& worker_context,
30 const scoped_refptr<cc::ContextProvider>& compositor_context,
31 ui::ContextProviderFactory::ContextCreationResult result) {
32 blimp::client::CompositorDependencies::ContextProviders context_providers;
33
34 switch (result) {
35 case ui::ContextProviderFactory::ContextCreationResult::
36 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED:
37 // Pass the null result to the caller and let them try again.
38 break;
39 case ui::ContextProviderFactory::ContextCreationResult::
40 FAILURE_FACTORY_SHUTDOWN:
41 // If the factory is shutting down, early out and drop the request.
42 return;
43 case ui::ContextProviderFactory::ContextCreationResult::
44 FAILURE_GPU_SURFACE_HANDLE_LOST:
45 NOTREACHED() << "We only ask for offscreen contexts";
46 break;
47 case ui::ContextProviderFactory::ContextCreationResult::SUCCESS:
48 // Return null if the worker context was invalidated while we were waiting
49 // for the compositor context.
50 if (IsValidWorkerContext(worker_context.get())) {
51 context_providers.compositor_context_provider =
52 std::move(compositor_context);
53 context_providers.worker_context_provider = std::move(worker_context);
54 }
55 break;
56 }
57
58 callback.Run(context_providers);
59 }
60
61 gpu::gles2::ContextCreationAttribHelper
62 GetOffscreenContextCreationAttributes() {
63 gpu::gles2::ContextCreationAttribHelper attributes;
64 attributes.alpha_size = -1;
65 attributes.depth_size = 0;
66 attributes.stencil_size = 0;
67 attributes.samples = 0;
68 attributes.sample_buffers = 0;
69 attributes.bind_generates_resource = false;
70 attributes.lose_context_when_out_of_memory = true;
71 return attributes;
72 }
73
74 bool IsAsyncWorkerContextEnabled() {
75 const base::CommandLine& command_line =
76 *base::CommandLine::ForCurrentProcess();
77
78 if (command_line.HasSwitch(switches::kDisableGpuAsyncWorkerContext))
79 return false;
80 else if (command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext))
81 return true;
82
83 return false;
84 }
85
86 } // namespace
87
88 ChromeCompositorDependencies::ChromeCompositorDependencies(
89 ui::ContextProviderFactory* context_provider_factory)
90 : context_provider_factory_(context_provider_factory),
91 worker_context_request_pending_(false),
92 weak_factory_(this) {
93 DCHECK(context_provider_factory_);
94 }
95
96 ChromeCompositorDependencies::~ChromeCompositorDependencies() = default;
97
98 gpu::GpuMemoryBufferManager*
99 ChromeCompositorDependencies::GetGpuMemoryBufferManager() {
100 return context_provider_factory_->GetGpuMemoryBufferManager();
101 }
102
103 cc::SurfaceManager* ChromeCompositorDependencies::GetSurfaceManager() {
104 return context_provider_factory_->GetSurfaceManager();
105 }
106
107 uint32_t ChromeCompositorDependencies::AllocateSurfaceClientId() {
108 return context_provider_factory_->AllocateSurfaceClientId();
109 }
110
111 void ChromeCompositorDependencies::GetContextProviders(
112 const ContextProviderCallback& callback) {
113 if (!IsValidWorkerContext(shared_main_thread_worker_context_.get()))
114 shared_main_thread_worker_context_ = nullptr;
115
116 // Request a compositor context if the worker context is still valid.
117 if (shared_main_thread_worker_context_) {
118 HandleCompositorContextRequest(callback);
119 return;
120 }
121
122 // Add the request to the list of pending requests first, if the result
123 // comes back synchronously, the callback should get triggered.
124 pending_requests_.push_back(callback);
125
126 // If the request for a worker context is already pending, don't make
127 // another one. We'll handle all the pending requests together once the
128 // worker context is available.
129 if (worker_context_request_pending_)
130 return;
131
132 worker_context_request_pending_ = true;
133 context_provider_factory_->CreateOffscreenContextProvider(
danakj 2016/09/01 19:26:06 This code here is significantly more complicated t
Khushal 2016/09/01 19:39:57 I had to do it this way because we needed to creat
danakj 2016/09/01 19:55:20 What if you just made a sync method to make contex
Khushal 2016/09/01 20:10:23 I could just hide it all in the ContextProviderFac
danakj 2016/09/01 20:14:01 They have LTHI on diff threads right, so no they s
Khushal 2016/09/01 20:47:37 So there are 3 ways I could think of doing this.
134 ui::ContextProviderFactory::ContextType::BLIMP_RENDER_WORKER_CONTEXT,
135 gpu::SharedMemoryLimits(), GetOffscreenContextCreationAttributes(),
136 true /* support_locking */, false /* automatic_flushes */, nullptr,
137 base::Bind(&ChromeCompositorDependencies::OnWorkerContextCreated,
138 weak_factory_.GetWeakPtr()));
139 }
140
141 void ChromeCompositorDependencies::OnWorkerContextCreated(
142 const scoped_refptr<cc::ContextProvider>& worker_context,
143 ui::ContextProviderFactory::ContextCreationResult result) {
144 DCHECK(worker_context_request_pending_);
145 DCHECK(!shared_main_thread_worker_context_);
146
147 worker_context_request_pending_ = false;
148
149 switch (result) {
150 case ui::ContextProviderFactory::ContextCreationResult::
151 FAILURE_GPU_PROCESS_INITIALIZATION_FAILED:
152 // Pass the null result to the caller and let them try again.
153 break;
154 case ui::ContextProviderFactory::ContextCreationResult::
155 FAILURE_FACTORY_SHUTDOWN:
156 // If the factory is shutting down, early out and drop the requests.
157 return;
158 case ui::ContextProviderFactory::ContextCreationResult::
159 FAILURE_GPU_SURFACE_HANDLE_LOST:
160 NOTREACHED() << "We only ask for offscreen contexts";
161 break;
162 case ui::ContextProviderFactory::ContextCreationResult::SUCCESS:
163 if (worker_context->BindToCurrentThread()) {
164 shared_main_thread_worker_context_ = worker_context;
165 }
166 break;
167 }
168
169 // Copy the requests first since we can get more requests as we run these
170 // callbacks.
171 std::list<ContextProviderCallback> context_requests = pending_requests_;
172 pending_requests_.clear();
173
174 for (ContextProviderCallback& context_request : context_requests) {
175 HandleCompositorContextRequest(context_request);
176 }
177 }
178
179 void ChromeCompositorDependencies::HandleCompositorContextRequest(
180 const ContextProviderCallback& callback) {
181 // Respond with null contexts if the worker context could not be created.
182 if (!shared_main_thread_worker_context_) {
183 callback.Run(ContextProviders());
184 return;
185 }
186
187 ui::ContextProviderFactory::ContextProviderCallback result_callback =
188 base::Bind(&OnCompositorContextCreated, callback,
189 shared_main_thread_worker_context_);
190
191 // The compositor context shares resources with the worker context unless
192 // the worker is async.
193 cc::ContextProvider* shared_context =
194 IsAsyncWorkerContextEnabled() ? nullptr
195 : shared_main_thread_worker_context_.get();
196
197 context_provider_factory_->CreateOffscreenContextProvider(
198 ui::ContextProviderFactory::ContextType::BLIMP_RENDER_COMPOSITOR_CONTEXT,
199 gpu::SharedMemoryLimits::ForMailboxContext(),
200 GetOffscreenContextCreationAttributes(), false /* support_locking */,
201 false /* automatic_flushes */, shared_context, result_callback);
202 }
OLDNEW
« no previous file with comments | « chrome/browser/android/blimp/chrome_compositor_dependencies.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698