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

Unified Diff: blimp/client/core/compositor/delegated_output_surface.cc

Issue 2266863003: blimp: Move BlimpCompositor to use delegated rendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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: blimp/client/core/compositor/delegated_output_surface.cc
diff --git a/blimp/client/core/compositor/delegated_output_surface.cc b/blimp/client/core/compositor/delegated_output_surface.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d2ff78418139bb83253b63eaac41575844921fac
--- /dev/null
+++ b/blimp/client/core/compositor/delegated_output_surface.cc
@@ -0,0 +1,117 @@
+// 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 "blimp/client/core/compositor/delegated_output_surface.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/memory/ptr_util.h"
+#include "base/single_thread_task_runner.h"
+#include "base/threading/thread_checker.h"
+#include "blimp/client/core/compositor/output_surface_proxy.h"
+#include "cc/output/compositor_frame.h"
+
+namespace blimp {
+namespace client {
+
+// A simple utility class to marshall the messages meant for the
+// |output_surface_proxy_| to the |proxy_task_runner_|, and send the messages
+// received on the compositor thread to the |output_surface_|. This class is
+// created on and lives on the compositor thread.
+class DelegatedOutputSurface::OutputSurfaceThreadPipe
+ : public OutputSurfaceProxyClient {
+ public:
+ OutputSurfaceThreadPipe(
+ DelegatedOutputSurface* output_surface,
+ scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner,
+ base::WeakPtr<OutputSurfaceProxy> output_surface_proxy)
+ : output_surface_(output_surface),
+ proxy_task_runner_(proxy_task_runner),
+ output_surface_proxy_(output_surface_proxy),
+ weak_ptr_factory_(this) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK(output_surface_);
+ proxy_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&OutputSurfaceProxy::BindToClient, output_surface_proxy_,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
+
+ ~OutputSurfaceThreadPipe() override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ proxy_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&OutputSurfaceProxy::DetachFromClient,
+ output_surface_proxy_));
+ }
+
+ void SwapBuffers(cc::CompositorFrame frame) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ proxy_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&OutputSurfaceProxy::SwapCompositorFrame,
+ output_surface_proxy_, base::Passed(&frame)));
+ }
+
+ private:
+ // OutputSurfaceProxyClient implementation.
+ void ReclaimCompositorResources(
+ const cc::ReturnedResourceArray& resources) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ output_surface_->ReclaimResources(resources);
+ }
+
+ DelegatedOutputSurface* output_surface_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_;
+ base::WeakPtr<OutputSurfaceProxy> output_surface_proxy_;
+
+ base::ThreadChecker thread_checker_;
+ base::WeakPtrFactory<OutputSurfaceThreadPipe> weak_ptr_factory_;
+};
+
+DelegatedOutputSurface::DelegatedOutputSurface(
+ scoped_refptr<cc::ContextProvider> compositor_context_provider,
+ scoped_refptr<cc::ContextProvider> worker_context_provider,
+ scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner,
+ base::WeakPtr<OutputSurfaceProxy> output_surface_proxy)
+ : cc::OutputSurface(std::move(compositor_context_provider),
+ std::move(worker_context_provider),
+ nullptr),
+ proxy_task_runner_(proxy_task_runner),
+ output_surface_proxy_(output_surface_proxy) {
+ capabilities_.delegated_rendering = true;
+}
+
+DelegatedOutputSurface::~DelegatedOutputSurface() = default;
+
+uint32_t DelegatedOutputSurface::GetFramebufferCopyTextureFormat() {
+ NOTREACHED() << "Should not be called on delegated output surface";
+ return 0;
+}
+
+void DelegatedOutputSurface::SwapBuffers(cc::CompositorFrame frame) {
+ DCHECK(client_thread_checker_.CalledOnValidThread());
+ output_surface_thread_pipe_->SwapBuffers(std::move(frame));
David Trainor- moved to gerrit 2016/08/22 23:58:10 DCHECK(output_surface_thread_pipe_)?
Khushal 2016/08/23 02:53:11 If we are derefencing it in the next line, it will
+ cc::OutputSurface::PostSwapBuffersComplete();
+}
+
+bool DelegatedOutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
+ DCHECK(!output_surface_thread_pipe_);
+
+ bool success = cc::OutputSurface::BindToClient(client);
+ // Create a thread pipe only if the bind was successful. If this fails, the
+ // output surface would detach itself from the client anyway.
+ if (success) {
+ output_surface_thread_pipe_ = base::MakeUnique<OutputSurfaceThreadPipe>(
+ this, std::move(proxy_task_runner_), output_surface_proxy_);
+ }
+ return success;
+}
+
+void DelegatedOutputSurface::DetachFromClient() {
+ cc::OutputSurface::DetachFromClient();
+ output_surface_thread_pipe_.reset();
+}
+
+} // namespace client
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698