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