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 "blimp/client/core/compositor/output_surface_proxy.h" | |
13 #include "cc/output/compositor_frame.h" | |
14 | |
15 namespace blimp { | |
16 namespace client { | |
17 | |
18 // A simple utility class to marshall the messages meant for the | |
19 // |output_surface_proxy_| to the |proxy_task_runner_|, and send the messages | |
20 // received on the compositor thread to the |output_surface_|. This class is | |
21 // created on and lives on the compositor thread. | |
22 class DelegatedOutputSurface::OutputSurfaceThreadPipe | |
23 : public OutputSurfaceProxyClient { | |
24 public: | |
25 OutputSurfaceThreadPipe( | |
26 DelegatedOutputSurface* output_surface, | |
27 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner, | |
28 base::WeakPtr<OutputSurfaceProxy> output_surface_proxy) | |
29 : output_surface_(output_surface), | |
30 proxy_task_runner_(proxy_task_runner), | |
31 output_surface_proxy_(output_surface_proxy), | |
32 weak_ptr_factory_(this) { | |
33 DCHECK(thread_checker_.CalledOnValidThread()); | |
34 DCHECK(output_surface_); | |
35 proxy_task_runner_->PostTask( | |
36 FROM_HERE, | |
37 base::Bind(&OutputSurfaceProxy::BindToClient, output_surface_proxy_, | |
38 weak_ptr_factory_.GetWeakPtr())); | |
39 } | |
40 | |
41 ~OutputSurfaceThreadPipe() override { | |
42 DCHECK(thread_checker_.CalledOnValidThread()); | |
43 proxy_task_runner_->PostTask( | |
44 FROM_HERE, base::Bind(&OutputSurfaceProxy::DetachFromClient, | |
45 output_surface_proxy_)); | |
46 } | |
47 | |
48 void SwapBuffers(cc::CompositorFrame frame) { | |
49 DCHECK(thread_checker_.CalledOnValidThread()); | |
50 proxy_task_runner_->PostTask( | |
51 FROM_HERE, base::Bind(&OutputSurfaceProxy::SwapCompositorFrame, | |
52 output_surface_proxy_, base::Passed(&frame))); | |
53 } | |
54 | |
55 private: | |
56 // OutputSurfaceProxyClient implementation. | |
57 void ReclaimCompositorResources( | |
58 const cc::ReturnedResourceArray& resources) override { | |
59 DCHECK(thread_checker_.CalledOnValidThread()); | |
60 output_surface_->ReclaimResources(resources); | |
61 } | |
62 | |
63 DelegatedOutputSurface* output_surface_; | |
64 | |
65 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner_; | |
66 base::WeakPtr<OutputSurfaceProxy> output_surface_proxy_; | |
67 | |
68 base::ThreadChecker thread_checker_; | |
69 base::WeakPtrFactory<OutputSurfaceThreadPipe> weak_ptr_factory_; | |
70 }; | |
71 | |
72 DelegatedOutputSurface::DelegatedOutputSurface( | |
73 scoped_refptr<cc::ContextProvider> compositor_context_provider, | |
74 scoped_refptr<cc::ContextProvider> worker_context_provider, | |
75 scoped_refptr<base::SingleThreadTaskRunner> proxy_task_runner, | |
76 base::WeakPtr<OutputSurfaceProxy> output_surface_proxy) | |
77 : cc::OutputSurface(std::move(compositor_context_provider), | |
78 std::move(worker_context_provider), | |
79 nullptr), | |
80 proxy_task_runner_(proxy_task_runner), | |
81 output_surface_proxy_(output_surface_proxy) { | |
82 capabilities_.delegated_rendering = true; | |
83 } | |
84 | |
85 DelegatedOutputSurface::~DelegatedOutputSurface() = default; | |
86 | |
87 uint32_t DelegatedOutputSurface::GetFramebufferCopyTextureFormat() { | |
88 NOTREACHED() << "Should not be called on delegated output surface"; | |
89 return 0; | |
90 } | |
91 | |
92 void DelegatedOutputSurface::SwapBuffers(cc::CompositorFrame frame) { | |
93 DCHECK(client_thread_checker_.CalledOnValidThread()); | |
94 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
| |
95 cc::OutputSurface::PostSwapBuffersComplete(); | |
96 } | |
97 | |
98 bool DelegatedOutputSurface::BindToClient(cc::OutputSurfaceClient* client) { | |
99 DCHECK(!output_surface_thread_pipe_); | |
100 | |
101 bool success = cc::OutputSurface::BindToClient(client); | |
102 // Create a thread pipe only if the bind was successful. If this fails, the | |
103 // output surface would detach itself from the client anyway. | |
104 if (success) { | |
105 output_surface_thread_pipe_ = base::MakeUnique<OutputSurfaceThreadPipe>( | |
106 this, std::move(proxy_task_runner_), output_surface_proxy_); | |
107 } | |
108 return success; | |
109 } | |
110 | |
111 void DelegatedOutputSurface::DetachFromClient() { | |
112 cc::OutputSurface::DetachFromClient(); | |
113 output_surface_thread_pipe_.reset(); | |
114 } | |
115 | |
116 } // namespace client | |
117 } // namespace blimp | |
OLD | NEW |