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