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

Unified Diff: chrome/browser/android/blimp/chrome_compositor_dependencies.cc

Issue 2297933002: blimp: Set up the CompositorDependencies for blimp in Chrome. (Closed)
Patch Set: change to a Gpu Channel callback Created 4 years, 3 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: chrome/browser/android/blimp/chrome_compositor_dependencies.cc
diff --git a/chrome/browser/android/blimp/chrome_compositor_dependencies.cc b/chrome/browser/android/blimp/chrome_compositor_dependencies.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9bf229bb2bfd4a7a7ab4d7c395630a97823371e3
--- /dev/null
+++ b/chrome/browser/android/blimp/chrome_compositor_dependencies.cc
@@ -0,0 +1,144 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/blimp/chrome_compositor_dependencies.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "cc/output/context_provider.h"
+#include "content/public/common/content_switches.h"
+#include "gpu/command_buffer/client/gles2_interface.h"
+#include "gpu/command_buffer/client/shared_memory_limits.h"
+#include "gpu/command_buffer/common/gles2_cmd_utils.h"
+
+namespace {
+
+bool IsValidWorkerContext(cc::ContextProvider* context_provider) {
+ cc::ContextProvider::ScopedContextLock lock(context_provider);
+ return context_provider->ContextGL()->GetGraphicsResetStatusKHR() ==
+ GL_NO_ERROR;
+}
+
+gpu::gles2::ContextCreationAttribHelper
+GetOffscreenContextCreationAttributes() {
+ gpu::gles2::ContextCreationAttribHelper attributes;
+ attributes.alpha_size = -1;
+ attributes.depth_size = 0;
+ attributes.stencil_size = 0;
+ attributes.samples = 0;
+ attributes.sample_buffers = 0;
+ attributes.bind_generates_resource = false;
+ attributes.lose_context_when_out_of_memory = true;
+ return attributes;
+}
+
+bool IsAsyncWorkerContextEnabled() {
+ const base::CommandLine& command_line =
+ *base::CommandLine::ForCurrentProcess();
+
+ if (command_line.HasSwitch(switches::kDisableGpuAsyncWorkerContext))
+ return false;
+ else if (command_line.HasSwitch(switches::kEnableGpuAsyncWorkerContext))
+ return true;
+
+ return false;
+}
+
+} // namespace
+
+ChromeCompositorDependencies::ChromeCompositorDependencies(
+ ui::ContextProviderFactory* context_provider_factory)
+ : context_provider_factory_(context_provider_factory), weak_factory_(this) {
+ DCHECK(context_provider_factory_);
+}
+
+ChromeCompositorDependencies::~ChromeCompositorDependencies() = default;
+
+gpu::GpuMemoryBufferManager*
+ChromeCompositorDependencies::GetGpuMemoryBufferManager() {
+ return context_provider_factory_->GetGpuMemoryBufferManager();
+}
+
+cc::SurfaceManager* ChromeCompositorDependencies::GetSurfaceManager() {
+ return context_provider_factory_->GetSurfaceManager();
+}
+
+uint32_t ChromeCompositorDependencies::AllocateSurfaceClientId() {
+ return context_provider_factory_->AllocateSurfaceClientId();
+}
+
+void ChromeCompositorDependencies::GetContextProviders(
+ const ContextProviderCallback& callback) {
+ pending_requests_.push_back(callback);
danakj 2016/09/01 23:35:18 It feels like you could just bind the callback int
Khushal 2016/09/02 00:24:33 Oh yes, didn't realize without the 2 async calls,
+ context_provider_factory_->RequestGpuChannelHost(
+ base::Bind(&ChromeCompositorDependencies::OnGpuChannelEstablished,
+ weak_factory_.GetWeakPtr()));
+}
+
+void ChromeCompositorDependencies::OnGpuChannelEstablished(
+ const scoped_refptr<gpu::GpuChannelHost>& gpu_channel_host,
danakj 2016/09/01 23:35:18 receive refptrs by value
Khushal 2016/09/02 00:24:32 Is there a reason why that is better? I thought it
danakj 2016/09/02 00:30:56 The caller should std::move if it doesnt need a co
Khushal 2016/09/02 01:13:35 Sorry if this is getting repetitive, I just want t
+ ui::ContextProviderFactory::GpuChannelHostResult result) {
+ // We queue multiple requests, so early out in case the previous requests were
+ // already handled.
+ if (pending_requests_.empty())
+ return;
+
+ switch (result) {
+ case ui::ContextProviderFactory::GpuChannelHostResult::
danakj 2016/09/01 23:35:18 if you "using ui::ContextProviderFactory::GpuChann
Khushal 2016/09/02 00:24:33 Done.
+ FAILURE_GPU_PROCESS_INITIALIZATION_FAILED:
+ // Pass the null result to the caller and let them try again.
+ break;
+ case ui::ContextProviderFactory::GpuChannelHostResult::
+ FAILURE_FACTORY_SHUTDOWN:
+ // If the factory is shutting down, early out and drop the requests.
+ return;
+ case ui::ContextProviderFactory::GpuChannelHostResult::SUCCESS:
+ // Create the worker context first if necessary.
+ if (!shared_main_thread_worker_context_ ||
+ !IsValidWorkerContext(shared_main_thread_worker_context_.get())) {
+ shared_main_thread_worker_context_ =
+ context_provider_factory_->CreateOffscreenContextProvider(
+ ui::ContextProviderFactory::ContextType::
+ BLIMP_RENDER_WORKER_CONTEXT,
+ gpu::SharedMemoryLimits(),
+ GetOffscreenContextCreationAttributes(),
+ true /* support_locking */, false /* automatic_flushes */,
+ nullptr, gpu_channel_host.get());
+ if (!shared_main_thread_worker_context_->BindToCurrentThread()) {
+ shared_main_thread_worker_context_ = nullptr;
+ }
+ }
+ break;
+ }
+
+ // Copy the requests first since we can get more requests as we run these
+ // callbacks.
+ std::list<ContextProviderCallback> context_requests = pending_requests_;
+ pending_requests_.clear();
+
+ for (ContextProviderCallback& context_request : context_requests) {
+ scoped_refptr<cc::ContextProvider> compositor_context_provider;
+
+ if (gpu_channel_host && shared_main_thread_worker_context_) {
+ // The compositor context shares resources with the worker context unless
+ // the worker is async.
+ cc::ContextProvider* shared_context =
+ IsAsyncWorkerContextEnabled()
danakj 2016/09/01 23:35:18 I'm not sure what the answer is, maybe talk with r
Khushal 2016/09/02 00:24:32 I think all of this is in compositor_util in conte
danakj 2016/09/02 00:30:56 That's content/browser though.
+ ? nullptr
+ : shared_main_thread_worker_context_.get();
+
+ compositor_context_provider =
+ context_provider_factory_->CreateOffscreenContextProvider(
+ ui::ContextProviderFactory::ContextType::
+ BLIMP_RENDER_COMPOSITOR_CONTEXT,
+ gpu::SharedMemoryLimits::ForMailboxContext(),
+ GetOffscreenContextCreationAttributes(),
+ false /* support_locking */, false /* automatic_flushes */,
+ shared_context, gpu_channel_host.get());
danakj 2016/09/01 23:35:18 Why is this passing raw pointer to gpu_channel_hos
Khushal 2016/09/02 00:24:32 Done.
+ }
+
+ context_request.Run(compositor_context_provider,
+ shared_main_thread_worker_context_);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698