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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: cc/output/output_surface.cc
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc
index 3e1549701e9ba6fdcedc4ed401fb66fd2e699105..f6f3168d5bcdcf5954c3aa93095391c6c2ece71d 100644
--- a/cc/output/output_surface.cc
+++ b/cc/output/output_surface.cc
@@ -119,12 +119,12 @@ class SkiaGpuTraceMemoryDump : public SkTraceMemoryDump {
} // namespace
OutputSurface::OutputSurface(
- scoped_refptr<ContextProvider> context_provider,
+ std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
scoped_refptr<ContextProvider> worker_context_provider,
scoped_refptr<VulkanContextProvider> vulkan_context_provider,
std::unique_ptr<SoftwareOutputDevice> software_device)
: client_(NULL),
- context_provider_(std::move(context_provider)),
+ compositor_context_factory_(std::move(compositor_context_factory)),
worker_context_provider_(std::move(worker_context_provider)),
vulkan_context_provider_(vulkan_context_provider),
software_device_(std::move(software_device)),
@@ -135,21 +135,20 @@ OutputSurface::OutputSurface(
client_thread_checker_.DetachFromThread();
}
-OutputSurface::OutputSurface(scoped_refptr<ContextProvider> context_provider)
- : OutputSurface(std::move(context_provider),
+OutputSurface::OutputSurface(
+ std::unique_ptr<ContextProvider::Factory> compositor_context_factory)
+ : OutputSurface(std::move(compositor_context_factory),
nullptr,
nullptr,
- nullptr) {
-}
+ nullptr) {}
OutputSurface::OutputSurface(
- scoped_refptr<ContextProvider> context_provider,
+ std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
scoped_refptr<ContextProvider> worker_context_provider)
- : OutputSurface(std::move(context_provider),
+ : OutputSurface(std::move(compositor_context_factory),
std::move(worker_context_provider),
nullptr,
- nullptr) {
-}
+ nullptr) {}
OutputSurface::OutputSurface(
std::unique_ptr<SoftwareOutputDevice> software_device)
@@ -160,13 +159,12 @@ OutputSurface::OutputSurface(
}
OutputSurface::OutputSurface(
- scoped_refptr<ContextProvider> context_provider,
+ std::unique_ptr<ContextProvider::Factory> compositor_context_factory,
std::unique_ptr<SoftwareOutputDevice> software_device)
- : OutputSurface(std::move(context_provider),
+ : OutputSurface(std::move(compositor_context_factory),
nullptr,
nullptr,
- std::move(software_device)) {
-}
+ std::move(software_device)) {}
// Forwarded to OutputSurfaceClient
void OutputSurface::SetNeedsRedrawRect(const gfx::Rect& damage_rect) {
@@ -205,12 +203,15 @@ bool OutputSurface::BindToClient(OutputSurfaceClient* client) {
client_ = client;
bool success = true;
- if (context_provider_.get()) {
- success = context_provider_->BindToCurrentThread();
- if (success) {
- context_provider_->SetLostContextCallback(base::Bind(
+ if (compositor_context_factory_) {
+ compositor_context_provider_ = compositor_context_factory_->CreateContext();
+ if (compositor_context_provider_) {
+ compositor_context_provider_->SetLostContextCallback(base::Bind(
&OutputSurface::DidLoseOutputSurface, base::Unretained(this)));
}
+ success = !!compositor_context_provider_;
+ // Don't keep around the dead Factory.
+ compositor_context_factory_ = nullptr;
}
// In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
@@ -239,8 +240,8 @@ void OutputSurface::EnsureBackbuffer() {
}
void OutputSurface::DiscardBackbuffer() {
- if (context_provider_.get())
- context_provider_->ContextGL()->DiscardBackbufferCHROMIUM();
+ if (compositor_context_provider_)
+ compositor_context_provider_->ContextGL()->DiscardBackbufferCHROMIUM();
if (software_device_)
software_device_->DiscardBackbuffer();
}
@@ -255,17 +256,17 @@ void OutputSurface::Reshape(const gfx::Size& size,
surface_size_ = size;
device_scale_factor_ = scale_factor;
has_alpha_ = has_alpha;
- if (context_provider_.get()) {
- context_provider_->ContextGL()->ResizeCHROMIUM(size.width(), size.height(),
- scale_factor, has_alpha);
+ if (compositor_context_provider_) {
+ compositor_context_provider_->ContextGL()->ResizeCHROMIUM(
+ size.width(), size.height(), scale_factor, has_alpha);
}
if (software_device_)
software_device_->Resize(size, scale_factor);
}
void OutputSurface::BindFramebuffer() {
- DCHECK(context_provider_.get());
- context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0);
+ DCHECK(compositor_context_provider_);
+ compositor_context_provider_->ContextGL()->BindFramebuffer(GL_FRAMEBUFFER, 0);
}
void OutputSurface::PostSwapBuffersComplete() {
@@ -357,11 +358,11 @@ void OutputSurface::DetachFromClientInternal() {
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
- if (context_provider_.get()) {
- context_provider_->SetLostContextCallback(
+ if (compositor_context_provider_) {
+ compositor_context_provider_->SetLostContextCallback(
ContextProvider::LostContextCallback());
}
- context_provider_ = nullptr;
+ compositor_context_provider_ = nullptr;
client_ = nullptr;
weak_ptr_factory_.InvalidateWeakPtrs();
}

Powered by Google App Engine
This is Rietveld 408576698