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

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

Issue 1985973002: Defer compositor context creation to the thread. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: contextfactory: . Created 4 years, 7 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 base::trace_event::ProcessMemoryDump* pmd_; 113 base::trace_event::ProcessMemoryDump* pmd_;
114 uint64_t share_group_tracing_guid_; 114 uint64_t share_group_tracing_guid_;
115 115
116 DISALLOW_COPY_AND_ASSIGN(SkiaGpuTraceMemoryDump); 116 DISALLOW_COPY_AND_ASSIGN(SkiaGpuTraceMemoryDump);
117 }; 117 };
118 118
119 } // namespace 119 } // namespace
120 120
121 OutputSurface::OutputSurface( 121 OutputSurface::OutputSurface(
122 scoped_refptr<ContextProvider> context_provider, 122 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
123 scoped_refptr<ContextProvider> worker_context_provider, 123 scoped_refptr<ContextProvider> worker_context_provider,
124 scoped_refptr<VulkanContextProvider> vulkan_context_provider, 124 scoped_refptr<VulkanContextProvider> vulkan_context_provider,
125 std::unique_ptr<SoftwareOutputDevice> software_device) 125 std::unique_ptr<SoftwareOutputDevice> software_device)
126 : client_(NULL), 126 : client_(NULL),
127 context_provider_(std::move(context_provider)), 127 compositor_context_factory_(std::move(compositor_context_factory)),
128 worker_context_provider_(std::move(worker_context_provider)), 128 worker_context_provider_(std::move(worker_context_provider)),
129 vulkan_context_provider_(vulkan_context_provider), 129 vulkan_context_provider_(vulkan_context_provider),
130 software_device_(std::move(software_device)), 130 software_device_(std::move(software_device)),
131 device_scale_factor_(-1), 131 device_scale_factor_(-1),
132 has_alpha_(true), 132 has_alpha_(true),
133 external_stencil_test_enabled_(false), 133 external_stencil_test_enabled_(false),
134 weak_ptr_factory_(this) { 134 weak_ptr_factory_(this) {
135 client_thread_checker_.DetachFromThread(); 135 client_thread_checker_.DetachFromThread();
136 } 136 }
137 137
138 OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider) 138 OutputSurface::OutputSurface(
139 : OutputSurface(std::move(context_provider), 139 std::unique_ptr<ContextProvider::Factory> compositor_context_factory)
140 : OutputSurface(std::move(compositor_context_factory),
140 nullptr, 141 nullptr,
141 nullptr, 142 nullptr,
142 nullptr) { 143 nullptr) {}
143 }
144 144
145 OutputSurface::OutputSurface( 145 OutputSurface::OutputSurface(
146 scoped_refptr<ContextProvider> context_provider, 146 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
147 scoped_refptr<ContextProvider> worker_context_provider) 147 scoped_refptr<ContextProvider> worker_context_provider)
148 : OutputSurface(std::move(context_provider), 148 : OutputSurface(std::move(compositor_context_factory),
149 std::move(worker_context_provider), 149 std::move(worker_context_provider),
150 nullptr, 150 nullptr,
151 nullptr) { 151 nullptr) {}
152 }
153 152
154 OutputSurface::OutputSurface( 153 OutputSurface::OutputSurface(
155 std::unique_ptr<SoftwareOutputDevice> software_device) 154 std::unique_ptr<SoftwareOutputDevice> software_device)
156 : OutputSurface(nullptr, 155 : OutputSurface(nullptr,
157 nullptr, 156 nullptr,
158 nullptr, 157 nullptr,
159 std::move(software_device)) { 158 std::move(software_device)) {
160 } 159 }
161 160
162 OutputSurface::OutputSurface( 161 OutputSurface::OutputSurface(
163 scoped_refptr<ContextProvider> context_provider, 162 std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
164 std::unique_ptr<SoftwareOutputDevice> software_device) 163 std::unique_ptr<SoftwareOutputDevice> software_device)
165 : OutputSurface(std::move(context_provider), 164 : OutputSurface(std::move(compositor_context_factory),
166 nullptr, 165 nullptr,
167 nullptr, 166 nullptr,
168 std::move(software_device)) { 167 std::move(software_device)) {}
169 }
170 168
171 // Forwarded to OutputSurfaceClient 169 // Forwarded to OutputSurfaceClient
172 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { 170 void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
173 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect"); 171 TRACE_EVENT0("cc", "OutputSurface::SetNeedsRedrawRect");
174 client_->SetNeedsRedrawRect(damage_rect); 172 client_->SetNeedsRedrawRect(damage_rect);
175 } 173 }
176 174
177 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) { 175 void OutputSurface::ReclaimResources(const CompositorFrameAck* ack) {
178 client_->ReclaimResources(ack); 176 client_->ReclaimResources(ack);
179 } 177 }
(...skipping 18 matching lines...) Expand all
198 196
199 void OutputSurface::ApplyExternalStencil() {} 197 void OutputSurface::ApplyExternalStencil() {}
200 198
201 bool OutputSurface::BindToClient(OutputSurfaceClient* client) { 199 bool OutputSurface::BindToClient(OutputSurfaceClient* client) {
202 DCHECK(client_thread_checker_.CalledOnValidThread()); 200 DCHECK(client_thread_checker_.CalledOnValidThread());
203 DCHECK(client); 201 DCHECK(client);
204 DCHECK(!client_); 202 DCHECK(!client_);
205 client_ = client; 203 client_ = client;
206 bool success = true; 204 bool success = true;
207 205
208 if (context_provider_.get()) { 206 if (compositor_context_factory_) {
209 success = context_provider_->BindToCurrentThread(); 207 compositor_context_provider_ = compositor_context_factory_->CreateContext();
210 if (success) { 208 if (compositor_context_provider_) {
211 context_provider_->SetLostContextCallback(base::Bind( 209 compositor_context_provider_->SetLostContextCallback(base::Bind(
212 &OutputSurface::DidLoseOutputSurface, base::Unretained(this))); 210 &OutputSurface::DidLoseOutputSurface, base::Unretained(this)));
213 } 211 }
212 success = !!compositor_context_provider_;
213 // Don't keep around the dead Factory.
214 compositor_context_factory_ = nullptr;
214 } 215 }
215 216
216 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 217 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
217 // Don't register a dump provider in these cases. 218 // Don't register a dump provider in these cases.
218 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 219 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
219 if (base::ThreadTaskRunnerHandle::IsSet()) { 220 if (base::ThreadTaskRunnerHandle::IsSet()) {
220 // Now that we are on the context thread, register a dump provider with this 221 // Now that we are on the context thread, register a dump provider with this
221 // thread's task runner. This will overwrite any previous dump provider 222 // thread's task runner. This will overwrite any previous dump provider
222 // registered. 223 // registered.
223 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 224 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
224 this, "OutputSurface", base::ThreadTaskRunnerHandle::Get()); 225 this, "OutputSurface", base::ThreadTaskRunnerHandle::Get());
225 } 226 }
226 227
227 if (!success) 228 if (!success)
228 DetachFromClient(); 229 DetachFromClient();
229 return success; 230 return success;
230 } 231 }
231 232
232 void OutputSurface::DetachFromClient() { 233 void OutputSurface::DetachFromClient() {
233 DetachFromClientInternal(); 234 DetachFromClientInternal();
234 } 235 }
235 236
236 void OutputSurface::EnsureBackbuffer() { 237 void OutputSurface::EnsureBackbuffer() {
237 if (software_device_) 238 if (software_device_)
238 software_device_->EnsureBackbuffer(); 239 software_device_->EnsureBackbuffer();
239 } 240 }
240 241
241 void OutputSurface::DiscardBackbuffer() { 242 void OutputSurface::DiscardBackbuffer() {
242 if (context_provider_.get()) 243 if (compositor_context_provider_)
243 context_provider_->ContextGL()->DiscardBackbufferCHROMIUM(); 244 compositor_context_provider_->ContextGL()->DiscardBackbufferCHROMIUM();
244 if (software_device_) 245 if (software_device_)
245 software_device_->DiscardBackbuffer(); 246 software_device_->DiscardBackbuffer();
246 } 247 }
247 248
248 void OutputSurface::Reshape(const gfx::Size& size, 249 void OutputSurface::Reshape(const gfx::Size& size,
249 float scale_factor, 250 float scale_factor,
250 bool has_alpha) { 251 bool has_alpha) {
251 if (size == surface_size_ && scale_factor == device_scale_factor_ && 252 if (size == surface_size_ && scale_factor == device_scale_factor_ &&
252 has_alpha == has_alpha_) 253 has_alpha == has_alpha_)
253 return; 254 return;
254 255
255 surface_size_ = size; 256 surface_size_ = size;
256 device_scale_factor_ = scale_factor; 257 device_scale_factor_ = scale_factor;
257 has_alpha_ = has_alpha; 258 has_alpha_ = has_alpha;
258 if (context_provider_.get()) { 259 if (compositor_context_provider_) {
259 context_provider_->ContextGL()->ResizeCHROMIUM(size.width(), size.height(), 260 compositor_context_provider_->ContextGL()->ResizeCHROMIUM(
260 scale_factor, has_alpha); 261 size.width(), size.height(), scale_factor, has_alpha);
261 } 262 }
262 if (software_device_) 263 if (software_device_)
263 software_device_->Resize(size, scale_factor); 264 software_device_->Resize(size, scale_factor);
264 } 265 }
265 266
266 void OutputSurface::BindFramebuffer() { 267 void OutputSurface::BindFramebuffer() {
267 DCHECK(context_provider_.get()); 268 DCHECK(compositor_context_provider_);
268 context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0); 269 compositor_context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0);
269 } 270 }
270 271
271 void OutputSurface::PostSwapBuffersComplete() { 272 void OutputSurface::PostSwapBuffersComplete() {
272 base::ThreadTaskRunnerHandle::Get()->PostTask( 273 base::ThreadTaskRunnerHandle::Get()->PostTask(
273 FROM_HERE, base::Bind(&OutputSurface::OnSwapBuffersComplete, 274 FROM_HERE, base::Bind(&OutputSurface::OnSwapBuffersComplete,
274 weak_ptr_factory_.GetWeakPtr())); 275 weak_ptr_factory_.GetWeakPtr()));
275 } 276 }
276 277
277 // We don't post tasks bound to the client directly since they might run 278 // We don't post tasks bound to the client directly since they might run
278 // after the OutputSurface has been destroyed. 279 // after the OutputSurface has been destroyed.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 351
351 void OutputSurface::DetachFromClientInternal() { 352 void OutputSurface::DetachFromClientInternal() {
352 DCHECK(client_thread_checker_.CalledOnValidThread()); 353 DCHECK(client_thread_checker_.CalledOnValidThread());
353 DCHECK(client_); 354 DCHECK(client_);
354 355
355 // Unregister any dump provider. Safe to call (no-op) if we have not yet 356 // Unregister any dump provider. Safe to call (no-op) if we have not yet
356 // registered. 357 // registered.
357 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 358 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
358 this); 359 this);
359 360
360 if (context_provider_.get()) { 361 if (compositor_context_provider_) {
361 context_provider_->SetLostContextCallback( 362 compositor_context_provider_->SetLostContextCallback(
362 ContextProvider::LostContextCallback()); 363 ContextProvider::LostContextCallback());
363 } 364 }
364 context_provider_ = nullptr; 365 compositor_context_provider_ = nullptr;
365 client_ = nullptr; 366 client_ = nullptr;
366 weak_ptr_factory_.InvalidateWeakPtrs(); 367 weak_ptr_factory_.InvalidateWeakPtrs();
367 } 368 }
368 369
369 } // namespace cc 370 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698