| 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..fe9f4d9330464731db791040dd27aff9bd874fbd
|
| --- /dev/null
|
| +++ b/blimp/client/core/compositor/delegated_output_surface.cc
|
| @@ -0,0 +1,154 @@
|
| +// 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 "cc/output/compositor_frame.h"
|
| +
|
| +namespace blimp {
|
| +namespace client {
|
| +
|
| +DelegatedOutputSurface::MainThreadOnly::MainThreadOnly(
|
| + DelegatedOutputSurface* output_surface,
|
| + BlimpOutputSurfaceClient* client)
|
| + : client(client), weak_ptr_factory(output_surface) {}
|
| +
|
| +DelegatedOutputSurface::MainThreadOnly::~MainThreadOnly() = default;
|
| +
|
| +DelegatedOutputSurface::CompositorThreadOnly::CompositorThreadOnly(
|
| + DelegatedOutputSurface* output_surface,
|
| + base::WeakPtr<DelegatedOutputSurface> output_surface_weak_ptr)
|
| + : bound_to_client(false),
|
| + output_surface_weak_ptr(output_surface_weak_ptr),
|
| + weak_ptr_factory(output_surface) {}
|
| +
|
| +DelegatedOutputSurface::CompositorThreadOnly::~CompositorThreadOnly() = default;
|
| +
|
| +DelegatedOutputSurface::DelegatedOutputSurface(
|
| + scoped_refptr<cc::ContextProvider> compositor_context_provider,
|
| + scoped_refptr<cc::ContextProvider> worker_context_provider,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
|
| + BlimpOutputSurfaceClient* client)
|
| + : cc::OutputSurface(std::move(compositor_context_provider),
|
| + std::move(worker_context_provider),
|
| + nullptr),
|
| + main_thread_only_(this, client),
|
| + compositor_thread_only_(this,
|
| + main_thread_only_.weak_ptr_factory.GetWeakPtr()),
|
| + main_task_runner_(std::move(main_task_runner)),
|
| + compositor_task_runner_(std::move(compositor_task_runner)) {
|
| + DCHECK(IsMainThread());
|
| + capabilities_.delegated_rendering = true;
|
| +}
|
| +
|
| +DelegatedOutputSurface::~DelegatedOutputSurface() = default;
|
| +
|
| +void DelegatedOutputSurface::ReclaimCompositorResources(
|
| + const cc::ReturnedResourceArray& resources) {
|
| + DCHECK(IsMainThread());
|
| + compositor_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DelegatedOutputSurface::ReclaimResourcesOnCompositorThread,
|
| + main().output_surface_weak_ptr, resources));
|
| +}
|
| +
|
| +void DelegatedOutputSurface::ReclaimResourcesOnCompositorThread(
|
| + const cc::ReturnedResourceArray& resources) {
|
| + DCHECK(IsCompositorThread());
|
| + cc::OutputSurface::ReclaimResources(resources);
|
| +}
|
| +
|
| +uint32_t DelegatedOutputSurface::GetFramebufferCopyTextureFormat() {
|
| + NOTREACHED() << "Should not be called on delegated output surface";
|
| + return 0;
|
| +}
|
| +
|
| +bool DelegatedOutputSurface::BindToClient(cc::OutputSurfaceClient* client) {
|
| + DCHECK(IsCompositorThread());
|
| + DCHECK(!compositor().bound_to_client);
|
| +
|
| + bool success = cc::OutputSurface::BindToClient(client);
|
| + if (success) {
|
| + compositor().bound_to_client = true;
|
| + main_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&DelegatedOutputSurface::BindOnMainThread,
|
| + compositor().output_surface_weak_ptr,
|
| + compositor().weak_ptr_factory.GetWeakPtr()));
|
| + }
|
| +
|
| + return success;
|
| +}
|
| +
|
| +void DelegatedOutputSurface::SwapBuffers(cc::CompositorFrame frame) {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + main_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&DelegatedOutputSurface::SwapBuffersOnMainThread,
|
| + compositor().output_surface_weak_ptr, base::Passed(&frame)));
|
| +}
|
| +
|
| +void DelegatedOutputSurface::DetachFromClient() {
|
| + DCHECK(IsCompositorThread());
|
| + cc::OutputSurface::DetachFromClient();
|
| +
|
| + if (compositor().bound_to_client == true) {
|
| + compositor().bound_to_client = false;
|
| + main_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&DelegatedOutputSurface::DetachOnMainThread,
|
| + compositor().output_surface_weak_ptr));
|
| + }
|
| +
|
| + compositor().weak_ptr_factory.InvalidateWeakPtrs();
|
| +}
|
| +
|
| +void DelegatedOutputSurface::BindOnMainThread(
|
| + base::WeakPtr<DelegatedOutputSurface> output_surface_weak_ptr) {
|
| + DCHECK(IsMainThread());
|
| + main().output_surface_weak_ptr = output_surface_weak_ptr;
|
| + main().client->BindToOutputSurface(this);
|
| +}
|
| +
|
| +void DelegatedOutputSurface::SwapBuffersOnMainThread(
|
| + cc::CompositorFrame frame) {
|
| + DCHECK(IsMainThread());
|
| + main().client->SwapCompositorFrame(std::move(frame));
|
| + compositor_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&cc::OutputSurface::OnSwapBuffersComplete,
|
| + main().output_surface_weak_ptr));
|
| +}
|
| +
|
| +void DelegatedOutputSurface::DetachOnMainThread() {
|
| + DCHECK(IsMainThread());
|
| + main().client->UnbindOutputSurface(this);
|
| + main().weak_ptr_factory.InvalidateWeakPtrs();
|
| +}
|
| +
|
| +DelegatedOutputSurface::MainThreadOnly& DelegatedOutputSurface::main() {
|
| + DCHECK(IsMainThread());
|
| + return main_thread_only_;
|
| +}
|
| +
|
| +DelegatedOutputSurface::CompositorThreadOnly&
|
| +DelegatedOutputSurface::compositor() {
|
| + DCHECK(IsCompositorThread());
|
| + return compositor_thread_only_;
|
| +}
|
| +
|
| +bool DelegatedOutputSurface::IsMainThread() const {
|
| + return main_task_runner_->BelongsToCurrentThread();
|
| +}
|
| +
|
| +bool DelegatedOutputSurface::IsCompositorThread() const {
|
| + return compositor_task_runner_->BelongsToCurrentThread();
|
| +}
|
| +
|
| +} // namespace client
|
| +} // namespace blimp
|
|
|