| OLD | NEW |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 resourceless_software_draw); | 100 resourceless_software_draw); |
| 101 } | 101 } |
| 102 | 102 |
| 103 OutputSurface::~OutputSurface() { | 103 OutputSurface::~OutputSurface() { |
| 104 if (context_provider_.get()) { | 104 if (context_provider_.get()) { |
| 105 context_provider_->SetLostContextCallback( | 105 context_provider_->SetLostContextCallback( |
| 106 ContextProvider::LostContextCallback()); | 106 ContextProvider::LostContextCallback()); |
| 107 context_provider_->SetMemoryPolicyChangedCallback( | 107 context_provider_->SetMemoryPolicyChangedCallback( |
| 108 ContextProvider::MemoryPolicyChangedCallback()); | 108 ContextProvider::MemoryPolicyChangedCallback()); |
| 109 } | 109 } |
| 110 if (worker_context_provider_.get()) { | |
| 111 worker_context_provider_->SetLostContextCallback( | |
| 112 ContextProvider::LostContextCallback()); | |
| 113 } | |
| 114 } | 110 } |
| 115 | 111 |
| 116 bool OutputSurface::HasExternalStencilTest() const { | 112 bool OutputSurface::HasExternalStencilTest() const { |
| 117 return external_stencil_test_enabled_; | 113 return external_stencil_test_enabled_; |
| 118 } | 114 } |
| 119 | 115 |
| 120 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { | 116 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { |
| 121 DCHECK(client); | 117 DCHECK(client); |
| 122 client_ = client; | 118 client_ = client; |
| 123 bool success = true; | 119 bool success = true; |
| 124 | 120 |
| 125 if (context_provider_.get()) { | 121 if (context_provider_.get()) { |
| 126 success = context_provider_->BindToCurrentThread(); | 122 success = context_provider_->BindToCurrentThread(); |
| 127 if (success) { | 123 if (success) { |
| 128 context_provider_->SetLostContextCallback(base::Bind( | 124 context_provider_->SetLostContextCallback(base::Bind( |
| 129 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); | 125 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); |
| 130 context_provider_->SetMemoryPolicyChangedCallback( | 126 context_provider_->SetMemoryPolicyChangedCallback( |
| 131 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); | 127 base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this))); |
| 132 } | 128 } |
| 133 } | 129 } |
| 134 | 130 |
| 135 if (success && worker_context_provider_.get()) { | 131 if (success && worker_context_provider_.get()) { |
| 136 success = worker_context_provider_->BindToCurrentThread(); | 132 success = worker_context_provider_->BindToCurrentThread(); |
| 137 if (success) { | 133 if (success) |
| 138 worker_context_provider_->SetupLock(); | 134 worker_context_provider_->SetupLock(); |
| 139 // The destructor resets the context lost callback, so base::Unretained | |
| 140 // is safe, as long as the worker threads stop using the context before | |
| 141 // the output surface is destroyed. | |
| 142 worker_context_provider_->SetLostContextCallback(base::Bind( | |
| 143 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); | |
| 144 } | |
| 145 } | 135 } |
| 146 | 136 |
| 147 if (!success) | 137 if (!success) |
| 148 client_ = NULL; | 138 client_ = NULL; |
| 149 | 139 |
| 150 return success; | 140 return success; |
| 151 } | 141 } |
| 152 | 142 |
| 153 void OutputSurface::EnsureBackbuffer() { | 143 void OutputSurface::EnsureBackbuffer() { |
| 154 if (software_device_) | 144 if (software_device_) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 OverlayCandidateValidator* OutputSurface::GetOverlayCandidateValidator() const { | 200 OverlayCandidateValidator* OutputSurface::GetOverlayCandidateValidator() const { |
| 211 return nullptr; | 201 return nullptr; |
| 212 } | 202 } |
| 213 | 203 |
| 214 void OutputSurface::SetWorkerContextShouldAggressivelyFreeResources( | 204 void OutputSurface::SetWorkerContextShouldAggressivelyFreeResources( |
| 215 bool aggressively_free_resources) { | 205 bool aggressively_free_resources) { |
| 216 TRACE_EVENT1("cc", | 206 TRACE_EVENT1("cc", |
| 217 "OutputSurface::SetWorkerContextShouldAggressivelyFreeResources", | 207 "OutputSurface::SetWorkerContextShouldAggressivelyFreeResources", |
| 218 "aggressively_free_resources", aggressively_free_resources); | 208 "aggressively_free_resources", aggressively_free_resources); |
| 219 if (auto* context_provider = worker_context_provider()) { | 209 if (auto* context_provider = worker_context_provider()) { |
| 220 // The context lock must be held while accessing the worker context. | 210 ContextProvider::ScopedContextLock scoped_context(context_provider); |
| 221 base::AutoLock context_lock(*context_provider->GetLock()); | |
| 222 | |
| 223 // Allow context to bind to current thread. | |
| 224 context_provider->DetachFromThread(); | |
| 225 | 211 |
| 226 if (aggressively_free_resources) { | 212 if (aggressively_free_resources) { |
| 227 context_provider->DeleteCachedResources(); | 213 context_provider->DeleteCachedResources(); |
| 228 } | 214 } |
| 229 | 215 |
| 230 if (auto* context_support = context_provider->ContextSupport()) { | 216 if (auto* context_support = context_provider->ContextSupport()) { |
| 231 context_support->SetAggressivelyFreeResources( | 217 context_support->SetAggressivelyFreeResources( |
| 232 aggressively_free_resources); | 218 aggressively_free_resources); |
| 233 } | 219 } |
| 234 | |
| 235 // Allow context to bind to other threads. | |
| 236 context_provider->DetachFromThread(); | |
| 237 } | 220 } |
| 238 } | 221 } |
| 239 | 222 |
| 240 bool OutputSurface::SurfaceIsSuspendForRecycle() const { | 223 bool OutputSurface::SurfaceIsSuspendForRecycle() const { |
| 241 return false; | 224 return false; |
| 242 } | 225 } |
| 243 | 226 |
| 244 } // namespace cc | 227 } // namespace cc |
| OLD | NEW |