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

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: Fix LayerTreeHostClientTakeAwayOutputSurface test. Content provider is always destroyed on the clie… Created 5 years, 2 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 | « cc/output/output_surface.h ('k') | cc/raster/tile_task_worker_pool_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const scoped_refptr<ContextProvider>& context_provider, 113 const scoped_refptr<ContextProvider>& context_provider,
114 const scoped_refptr<ContextProvider>& worker_context_provider, 114 const scoped_refptr<ContextProvider>& worker_context_provider,
115 scoped_ptr<SoftwareOutputDevice> software_device) 115 scoped_ptr<SoftwareOutputDevice> software_device)
116 : client_(NULL), 116 : client_(NULL),
117 context_provider_(context_provider), 117 context_provider_(context_provider),
118 worker_context_provider_(worker_context_provider), 118 worker_context_provider_(worker_context_provider),
119 software_device_(software_device.Pass()), 119 software_device_(software_device.Pass()),
120 device_scale_factor_(-1), 120 device_scale_factor_(-1),
121 external_stencil_test_enabled_(false), 121 external_stencil_test_enabled_(false),
122 weak_ptr_factory_(this) { 122 weak_ptr_factory_(this) {
123 client_thread_checker_.DetachFromThread();
123 } 124 }
124 125
125 OutputSurface::OutputSurface( 126 OutputSurface::OutputSurface(
126 const scoped_refptr<ContextProvider>& context_provider) 127 const scoped_refptr<ContextProvider>& context_provider)
127 : OutputSurface(context_provider, nullptr, nullptr) { 128 : OutputSurface(context_provider, nullptr, nullptr) {
128 } 129 }
129 130
130 OutputSurface::OutputSurface( 131 OutputSurface::OutputSurface(
131 const scoped_refptr<ContextProvider>& context_provider, 132 const scoped_refptr<ContextProvider>& context_provider,
132 const scoped_refptr<ContextProvider>& worker_context_provider) 133 const scoped_refptr<ContextProvider>& worker_context_provider)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 transform_for_tile_priority, 188 transform_for_tile_priority,
188 resourceless_software_draw); 189 resourceless_software_draw);
189 } 190 }
190 191
191 OutputSurface::~OutputSurface() { 192 OutputSurface::~OutputSurface() {
192 // Unregister any dump provider. Safe to call (no-op) if we have not yet 193 // Unregister any dump provider. Safe to call (no-op) if we have not yet
193 // registered. 194 // registered.
194 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 195 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
195 this); 196 this);
196 197
197 if (context_provider_.get()) { 198 if (client_)
198 context_provider_->SetLostContextCallback( 199 DetachFromClient();
199 ContextProvider::LostContextCallback());
200 context_provider_->SetMemoryPolicyChangedCallback(
201 ContextProvider::MemoryPolicyChangedCallback());
202 }
203 } 200 }
204 201
205 bool OutputSurface::HasExternalStencilTest() const { 202 bool OutputSurface::HasExternalStencilTest() const {
206 return external_stencil_test_enabled_; 203 return external_stencil_test_enabled_;
207 } 204 }
208 205
209 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { 206 bool OutputSurface::BindToClient(OutputSurfaceClient* client) {
207 DCHECK(client_thread_checker_.CalledOnValidThread());
210 DCHECK(client); 208 DCHECK(client);
209 DCHECK(!client_);
211 client_ = client; 210 client_ = client;
212 bool success = true; 211 bool success = true;
213 212
214 if (context_provider_.get()) { 213 if (context_provider_.get()) {
215 success = context_provider_->BindToCurrentThread(); 214 success = context_provider_->BindToCurrentThread();
216 if (success) { 215 if (success) {
217 context_provider_->SetLostContextCallback(base::Bind( 216 context_provider_->SetLostContextCallback(base::Bind(
218 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); 217 &OutputSurface::DidLoseOutputSurface, base::Unretained(this)));
219 context_provider_->SetMemoryPolicyChangedCallback( 218 context_provider_->SetMemoryPolicyChangedCallback(
220 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); 219 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this)));
221 } 220 }
222 } 221 }
223 222
224 if (success && worker_context_provider_.get()) {
225 success = worker_context_provider_->BindToCurrentThread();
226 if (success)
227 worker_context_provider_->SetupLock();
228 }
229
230 if (!success) 223 if (!success)
231 client_ = NULL; 224 client_ = NULL;
232 225
233 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 226 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
234 // Don't register a dump provider in these cases. 227 // Don't register a dump provider in these cases.
235 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 228 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
236 if (base::ThreadTaskRunnerHandle::IsSet()) { 229 if (base::ThreadTaskRunnerHandle::IsSet()) {
237 // Now that we are on the context thread, register a dump provider with this 230 // Now that we are on the context thread, register a dump provider with this
238 // thread's task runner. This will overwrite any previous dump provider 231 // thread's task runner. This will overwrite any previous dump provider
239 // registered. 232 // registered.
240 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 233 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
241 this, base::ThreadTaskRunnerHandle::Get()); 234 this, base::ThreadTaskRunnerHandle::Get());
242 } 235 }
243 236
244 return success; 237 return success;
245 } 238 }
246 239
240 void OutputSurface::DetachFromClient() {
241 DCHECK(client_thread_checker_.CalledOnValidThread());
242 DCHECK(client_);
243 if (context_provider_.get()) {
244 context_provider_->SetLostContextCallback(
245 ContextProvider::LostContextCallback());
246 context_provider_->SetMemoryPolicyChangedCallback(
247 ContextProvider::MemoryPolicyChangedCallback());
248 }
249 context_provider_ = nullptr;
250 client_ = nullptr;
251 weak_ptr_factory_.InvalidateWeakPtrs();
252 }
253
247 void OutputSurface::EnsureBackbuffer() { 254 void OutputSurface::EnsureBackbuffer() {
248 if (software_device_) 255 if (software_device_)
249 software_device_->EnsureBackbuffer(); 256 software_device_->EnsureBackbuffer();
250 } 257 }
251 258
252 void OutputSurface::DiscardBackbuffer() { 259 void OutputSurface::DiscardBackbuffer() {
253 if (context_provider_.get()) 260 if (context_provider_.get())
254 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); 261 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM();
255 if (software_device_) 262 if (software_device_)
256 software_device_->DiscardBackbuffer(); 263 software_device_->DiscardBackbuffer();
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 SkiaGpuTraceMemoryDump trace_memory_dump( 352 SkiaGpuTraceMemoryDump trace_memory_dump(
346 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID()); 353 pmd, context_provider->ContextSupport()->ShareGroupTracingGUID());
347 gr_context->dumpMemoryStatistics(&trace_memory_dump); 354 gr_context->dumpMemoryStatistics(&trace_memory_dump);
348 } 355 }
349 } 356 }
350 357
351 return true; 358 return true;
352 } 359 }
353 360
354 } // namespace cc 361 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/output_surface.h ('k') | cc/raster/tile_task_worker_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698