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

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

Issue 2297933002: blimp: Set up the CompositorDependencies for blimp in Chrome. (Closed)
Patch Set: Created 4 years, 4 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..5e05d07a8780bdc7b54c8fdb17cb6293743fbba1
--- /dev/null
+++ b/chrome/browser/android/blimp/chrome_compositor_dependencies.cc
@@ -0,0 +1,166 @@
+// 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"
+#include "ui/android/context_provider_factory.h"
+
+namespace {
+
+void OnCompositorContextCreated(
+ const blimp::client::CompositorDependencies::ContextProviderCallback&
+ callback,
+ const scoped_refptr<cc::ContextProvider>& worker_context,
+ const scoped_refptr<cc::ContextProvider>& compositor_context) {
+ blimp::client::CompositorDependencies::ContextProviders context_providers;
+ context_providers.compositor_context_provider = std::move(compositor_context);
+ context_providers.worker_context_provider = std::move(worker_context);
+ callback.Run(context_providers);
+}
+
+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),
+ worker_context_request_pending_(false),
+ weak_factory_(this) {
+ DCHECK(context_provider_factory_);
+}
+
+ChromeCompositorDependencies::~ChromeCompositorDependencies() = default;
+
+cc::LayerTreeSettings* ChromeCompositorDependencies::GetLayerTreeSettings() {
+ // MAKE THE SETTINGS!!!!!
David Trainor- moved to gerrit 2016/08/31 00:28:58 yes plz! In another patch maybe pull out the Comp
Khushal 2016/08/31 21:22:51 Done. I just moved it to internal for now, when Ch
+ return nullptr;
+}
+
+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) {
+ bool worker_context_is_valid = false;
+ if (shared_main_thread_worker_context_) {
+ // Note: If context is lost, delete reference after releasing the lock.
+ cc::ContextProvider::ScopedContextLock lock(
+ shared_main_thread_worker_context_.get());
+ if (shared_main_thread_worker_context_->ContextGL()
+ ->GetGraphicsResetStatusKHR() == GL_NO_ERROR)
+ worker_context_is_valid = true;
+ }
+ if (!worker_context_is_valid)
+ shared_main_thread_worker_context_ = nullptr;
David Trainor- moved to gerrit 2016/08/31 00:28:58 What happens to any outstanding requests if this d
Khushal 2016/08/31 21:22:50 Good call. I think the compositor expects the work
+
+ // Request a compositor context if the worker context is still valid.
+ if (shared_main_thread_worker_context_) {
+ HandleCompositorContextRequest(callback);
+ return;
+ }
+
+ // Add the request to the list of pending requests first, if the result
+ // comes back synchronously, the callback should get triggered.
+ pending_requests_.push_back(callback);
+
+ // If the request for a worker context is already pending, don't make
+ // another one. We'll handle all the pending requests together once the
+ // worker context is available.
+ if (worker_context_request_pending_)
+ return;
+
+ worker_context_request_pending_ = true;
+ context_provider_factory_->CreateOffscreenContextProvider(
+ ui::ContextProviderFactory::ContextType::BLIMP_RENDER_WORKER_CONTEXT,
+ gpu::SharedMemoryLimits(), GetOffscreenContextCreationAttributes(),
+ true /* support_locking */, false /* automatic_flushes */, nullptr,
+ base::Bind(&ChromeCompositorDependencies::OnWorkerContextCreated,
+ weak_factory_.GetWeakPtr()));
+}
+
+void ChromeCompositorDependencies::OnWorkerContextCreated(
+ const scoped_refptr<cc::ContextProvider>& worker_context) {
+ DCHECK(worker_context_request_pending_);
+ DCHECK(!shared_main_thread_worker_context_);
+
+ worker_context_request_pending_ = false;
+ if (worker_context->BindToCurrentThread()) {
+ shared_main_thread_worker_context_ = worker_context;
+ }
David Trainor- moved to gerrit 2016/08/31 00:28:58 What if this returns false?
Khushal 2016/08/31 21:22:50 If the bind fails, then we just report the failure
+
+ // 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) {
+ HandleCompositorContextRequest(context_request);
+ }
+}
+
+void ChromeCompositorDependencies::HandleCompositorContextRequest(
+ const ContextProviderCallback& callback) {
+ // Respond with null contexts if the worker context could not be created.
+ if (!shared_main_thread_worker_context_) {
+ callback.Run(ContextProviders());
+ return;
+ }
+
+ ui::ContextProviderFactory::ContextProviderCallback result_callback =
+ base::Bind(&OnCompositorContextCreated, callback,
+ shared_main_thread_worker_context_);
+
+ // The compositor context shares resources with the worker context unless
+ // the worker is async.
+ cc::ContextProvider* shared_context =
+ IsAsyncWorkerContextEnabled() ? nullptr
+ : shared_main_thread_worker_context_.get();
+
+ context_provider_factory_->CreateOffscreenContextProvider(
+ ui::ContextProviderFactory::ContextType::BLIMP_RENDER_COMPOSITOR_CONTEXT,
+ gpu::SharedMemoryLimits::ForMailboxContext(),
+ GetOffscreenContextCreationAttributes(), false /* support_locking */,
+ false /* automatic_flushes */, shared_context, result_callback);
+}

Powered by Google App Engine
This is Rietveld 408576698