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

Side by Side Diff: cc/output/output_surface.cc

Issue 1336733002: Re-land: cc: Implement shared worker contexts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android build fix Created 5 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "cc/output/output_surface.h" 5 #include "cc/output/output_surface.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h" 10 #include "base/thread_task_runner_handle.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const scoped_refptr<ContextProvider>& context_provider, 110 const scoped_refptr<ContextProvider>& context_provider,
111 const scoped_refptr<ContextProvider>& worker_context_provider, 111 const scoped_refptr<ContextProvider>& worker_context_provider,
112 scoped_ptr<SoftwareOutputDevice> software_device) 112 scoped_ptr<SoftwareOutputDevice> software_device)
113 : client_(NULL), 113 : client_(NULL),
114 context_provider_(context_provider), 114 context_provider_(context_provider),
115 worker_context_provider_(worker_context_provider), 115 worker_context_provider_(worker_context_provider),
116 software_device_(software_device.Pass()), 116 software_device_(software_device.Pass()),
117 device_scale_factor_(-1), 117 device_scale_factor_(-1),
118 external_stencil_test_enabled_(false), 118 external_stencil_test_enabled_(false),
119 weak_ptr_factory_(this) { 119 weak_ptr_factory_(this) {
120 client_thread_checker_.DetachFromThread();
120 } 121 }
121 122
122 OutputSurface::OutputSurface( 123 OutputSurface::OutputSurface(
123 const scoped_refptr<ContextProvider>& context_provider) 124 const scoped_refptr<ContextProvider>& context_provider)
124 : OutputSurface(context_provider, nullptr, nullptr) { 125 : OutputSurface(context_provider, nullptr, nullptr) {
125 } 126 }
126 127
127 OutputSurface::OutputSurface( 128 OutputSurface::OutputSurface(
128 const scoped_refptr<ContextProvider>& context_provider, 129 const scoped_refptr<ContextProvider>& context_provider,
129 const scoped_refptr<ContextProvider>& worker_context_provider) 130 const scoped_refptr<ContextProvider>& worker_context_provider)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 transform_for_tile_priority, 185 transform_for_tile_priority,
185 resourceless_software_draw); 186 resourceless_software_draw);
186 } 187 }
187 188
188 OutputSurface::~OutputSurface() { 189 OutputSurface::~OutputSurface() {
189 // Unregister any dump provider. Safe to call (no-op) if we have not yet 190 // Unregister any dump provider. Safe to call (no-op) if we have not yet
190 // registered. 191 // registered.
191 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 192 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
192 this); 193 this);
193 194
194 if (context_provider_.get()) { 195 if (client_)
195 context_provider_->SetLostContextCallback( 196 DetachFromClient();
196 ContextProvider::LostContextCallback());
197 context_provider_->SetMemoryPolicyChangedCallback(
198 ContextProvider::MemoryPolicyChangedCallback());
199 }
200 } 197 }
201 198
202 bool OutputSurface::HasExternalStencilTest() const { 199 bool OutputSurface::HasExternalStencilTest() const {
203 return external_stencil_test_enabled_; 200 return external_stencil_test_enabled_;
204 } 201 }
205 202
206 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { 203 bool OutputSurface::BindToClient(OutputSurfaceClient* client) {
204 DCHECK(client_thread_checker_.CalledOnValidThread());
207 DCHECK(client); 205 DCHECK(client);
206 DCHECK(!client_);
208 client_ = client; 207 client_ = client;
209 bool success = true; 208 bool success = true;
210 209
211 if (context_provider_.get()) { 210 if (context_provider_.get()) {
212 success = context_provider_->BindToCurrentThread(); 211 success = context_provider_->BindToCurrentThread();
213 if (success) { 212 if (success) {
214 context_provider_->SetLostContextCallback(base::Bind( 213 context_provider_->SetLostContextCallback(base::Bind(
215 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); 214 &OutputSurface::DidLoseOutputSurface, base::Unretained(this)));
216 context_provider_->SetMemoryPolicyChangedCallback( 215 context_provider_->SetMemoryPolicyChangedCallback(
217 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); 216 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this)));
218 } 217 }
219 } 218 }
220 219
221 if (success && worker_context_provider_.get()) {
222 success = worker_context_provider_->BindToCurrentThread();
223 if (success)
224 worker_context_provider_->SetupLock();
225 }
226
227 if (!success) 220 if (!success)
228 client_ = NULL; 221 client_ = NULL;
229 222
230 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 223 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
231 // Don't register a dump provider in these cases. 224 // Don't register a dump provider in these cases.
232 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 225 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
233 if (base::ThreadTaskRunnerHandle::IsSet()) { 226 if (base::ThreadTaskRunnerHandle::IsSet()) {
234 // Now that we are on the context thread, register a dump provider with this 227 // Now that we are on the context thread, register a dump provider with this
235 // thread's task runner. This will overwrite any previous dump provider 228 // thread's task runner. This will overwrite any previous dump provider
236 // registered. 229 // registered.
237 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 230 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
238 this, base::ThreadTaskRunnerHandle::Get()); 231 this, base::ThreadTaskRunnerHandle::Get());
239 } 232 }
240 233
241 return success; 234 return success;
242 } 235 }
243 236
237 void OutputSurface::DetachFromClient() {
238 DCHECK(client_thread_checker_.CalledOnValidThread());
239 DCHECK(client_);
240 if (context_provider_.get()) {
241 context_provider_->SetLostContextCallback(
242 ContextProvider::LostContextCallback());
243 context_provider_->SetMemoryPolicyChangedCallback(
244 ContextProvider::MemoryPolicyChangedCallback());
245 }
246 context_provider_ = nullptr;
247 client_ = nullptr;
248 weak_ptr_factory_.InvalidateWeakPtrs();
249 }
250
244 void OutputSurface::EnsureBackbuffer() { 251 void OutputSurface::EnsureBackbuffer() {
245 if (software_device_) 252 if (software_device_)
246 software_device_->EnsureBackbuffer(); 253 software_device_->EnsureBackbuffer();
247 } 254 }
248 255
249 void OutputSurface::DiscardBackbuffer() { 256 void OutputSurface::DiscardBackbuffer() {
250 if (context_provider_.get()) 257 if (context_provider_.get())
251 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); 258 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM();
252 if (software_device_) 259 if (software_device_)
253 software_device_->DiscardBackbuffer(); 260 software_device_->DiscardBackbuffer();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (auto* gr_context = context_provider->GrContext()) { 347 if (auto* gr_context = context_provider->GrContext()) {
341 SkiaGpuTraceMemoryDump trace_memory_dump(pmd); 348 SkiaGpuTraceMemoryDump trace_memory_dump(pmd);
342 gr_context->dumpMemoryStatistics(&trace_memory_dump); 349 gr_context->dumpMemoryStatistics(&trace_memory_dump);
343 } 350 }
344 } 351 }
345 352
346 return true; 353 return true;
347 } 354 }
348 355
349 } // namespace cc 356 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698