OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "blimp/client/core/compositor/delegated_output_surface.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/threading/thread_checker.h" |
| 12 #include "cc/output/compositor_frame.h" |
| 13 |
| 14 namespace blimp { |
| 15 namespace client { |
| 16 |
| 17 DelegatedOutputSurface::DelegatedOutputSurface( |
| 18 scoped_refptr<cc::ContextProvider> compositor_context_provider, |
| 19 scoped_refptr<cc::ContextProvider> worker_context_provider, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 21 base::WeakPtr<BlimpOutputSurfaceClient> client) |
| 22 : cc::OutputSurface(std::move(compositor_context_provider), |
| 23 std::move(worker_context_provider), |
| 24 nullptr), |
| 25 main_task_runner_(std::move(main_task_runner)), |
| 26 client_(client), |
| 27 bound_to_client_(false), |
| 28 weak_factory_(this) { |
| 29 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 30 capabilities_.delegated_rendering = true; |
| 31 } |
| 32 |
| 33 DelegatedOutputSurface::~DelegatedOutputSurface() = default; |
| 34 |
| 35 void DelegatedOutputSurface::ReclaimCompositorResources( |
| 36 const cc::ReturnedResourceArray& resources) { |
| 37 DCHECK(client_thread_checker_.CalledOnValidThread()); |
| 38 cc::OutputSurface::ReclaimResources(resources); |
| 39 } |
| 40 |
| 41 uint32_t DelegatedOutputSurface::GetFramebufferCopyTextureFormat() { |
| 42 NOTREACHED() << "Should not be called on delegated output surface"; |
| 43 return 0; |
| 44 } |
| 45 |
| 46 bool DelegatedOutputSurface::BindToClient(cc::OutputSurfaceClient* client) { |
| 47 bool success = cc::OutputSurface::BindToClient(client); |
| 48 if (success) { |
| 49 main_task_runner_->PostTask( |
| 50 FROM_HERE, base::Bind(&BlimpOutputSurfaceClient::BindToOutputSurface, |
| 51 client_, weak_factory_.GetWeakPtr())); |
| 52 } |
| 53 return success; |
| 54 } |
| 55 |
| 56 void DelegatedOutputSurface::SwapBuffers(cc::CompositorFrame frame) { |
| 57 DCHECK(client_thread_checker_.CalledOnValidThread()); |
| 58 |
| 59 main_task_runner_->PostTask( |
| 60 FROM_HERE, base::Bind(&BlimpOutputSurfaceClient::SwapCompositorFrame, |
| 61 client_, base::Passed(&frame))); |
| 62 cc::OutputSurface::PostSwapBuffersComplete(); |
| 63 } |
| 64 |
| 65 void DelegatedOutputSurface::DetachFromClient() { |
| 66 cc::OutputSurface::DetachFromClient(); |
| 67 |
| 68 if (bound_to_client_ == true) { |
| 69 bound_to_client_ = false; |
| 70 main_task_runner_->PostTask( |
| 71 FROM_HERE, |
| 72 base::Bind(&BlimpOutputSurfaceClient::UnbindOutputSurface, client_)); |
| 73 } |
| 74 |
| 75 weak_factory_.InvalidateWeakPtrs(); |
| 76 } |
| 77 |
| 78 } // namespace client |
| 79 } // namespace blimp |
OLD | NEW |