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