OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/ui/public/cpp/compositor_frame_sink.h" | 5 #include "services/ui/public/cpp/compositor_frame_sink.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/output/compositor_frame_sink_client.h" | 9 #include "cc/output/compositor_frame_sink_client.h" |
10 #include "gpu/ipc/client/gpu_channel_host.h" | 10 #include "gpu/ipc/client/gpu_channel_host.h" |
11 #include "services/ui/public/cpp/context_provider.h" | |
12 #include "services/ui/public/cpp/gpu_service.h" | 11 #include "services/ui/public/cpp/gpu_service.h" |
13 #include "services/ui/public/cpp/window_surface.h" | 12 #include "services/ui/public/cpp/window_surface.h" |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
17 CompositorFrameSink::CompositorFrameSink( | 16 CompositorFrameSink::CompositorFrameSink( |
18 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host, | 17 scoped_refptr<cc::ContextProvider> context_provider, |
19 std::unique_ptr<ui::WindowSurface> surface) | 18 std::unique_ptr<ui::WindowSurface> surface) |
20 : cc::CompositorFrameSink( | 19 : cc::CompositorFrameSink(std::move(context_provider), nullptr), |
21 make_scoped_refptr(new ContextProvider(std::move(gpu_channel_host))), | 20 surface_(std::move(surface)) {} |
22 nullptr), | |
23 surface_(std::move(surface)) { | |
24 } | |
25 | 21 |
26 CompositorFrameSink::~CompositorFrameSink() {} | 22 CompositorFrameSink::~CompositorFrameSink() {} |
27 | 23 |
28 bool CompositorFrameSink::BindToClient(cc::CompositorFrameSinkClient* client) { | 24 bool CompositorFrameSink::BindToClient(cc::CompositorFrameSinkClient* client) { |
29 if (!cc::CompositorFrameSink::BindToClient(client)) | 25 if (!cc::CompositorFrameSink::BindToClient(client)) |
30 return false; | 26 return false; |
31 | 27 |
32 surface_->BindToThread(); | 28 surface_->BindToThread(); |
33 surface_->set_client(this); | 29 surface_->set_client(this); |
34 | 30 |
35 // TODO(enne): Get this from the WindowSurface via ServerWindowSurface. | 31 // TODO(enne): Get this from the WindowSurface via ServerWindowSurface. |
36 begin_frame_source_.reset(new cc::DelayBasedBeginFrameSource( | 32 begin_frame_source_.reset(new cc::DelayBasedBeginFrameSource( |
37 base::MakeUnique<cc::DelayBasedTimeSource>( | 33 base::MakeUnique<cc::DelayBasedTimeSource>( |
38 base::ThreadTaskRunnerHandle::Get().get()))); | 34 base::ThreadTaskRunnerHandle::Get().get()))); |
39 | 35 |
40 client->SetBeginFrameSource(begin_frame_source_.get()); | 36 client->SetBeginFrameSource(begin_frame_source_.get()); |
41 return true; | 37 return true; |
42 } | 38 } |
43 | 39 |
44 void CompositorFrameSink::DetachFromClient() { | 40 void CompositorFrameSink::DetachFromClient() { |
45 client_->SetBeginFrameSource(nullptr); | 41 client_->SetBeginFrameSource(nullptr); |
46 begin_frame_source_.reset(); | 42 begin_frame_source_.reset(); |
47 surface_.reset(); | 43 surface_.reset(); |
48 cc::CompositorFrameSink::DetachFromClient(); | 44 cc::CompositorFrameSink::DetachFromClient(); |
49 } | 45 } |
50 | 46 |
51 void CompositorFrameSink::SubmitCompositorFrame(cc::CompositorFrame frame) { | 47 void CompositorFrameSink::SubmitCompositorFrame(cc::CompositorFrame frame) { |
52 // CompositorFrameSink owns WindowSurface, and so if CompositorFrameSink is | 48 surface_->SubmitCompositorFrame(std::move(frame)); |
53 // destroyed then SubmitCompositorFrame's callback will never get called. | |
54 // Thus, base::Unretained is safe here as |client_| is valid as long as |this| | |
55 // is. | |
56 surface_->SubmitCompositorFrame( | |
57 std::move(frame), | |
58 base::Bind(&cc::CompositorFrameSinkClient::DidReceiveCompositorFrameAck, | |
59 base::Unretained(client_))); | |
60 } | 49 } |
61 | 50 |
62 void CompositorFrameSink::OnResourcesReturned( | 51 void CompositorFrameSink::DidReceiveCompositorFrameAck() { |
63 ui::WindowSurface* surface, | 52 client_->DidReceiveCompositorFrameAck(); |
| 53 } |
| 54 |
| 55 void CompositorFrameSink::ReclaimResources( |
64 const cc::ReturnedResourceArray& resources) { | 56 const cc::ReturnedResourceArray& resources) { |
65 client_->ReclaimResources(resources); | 57 client_->ReclaimResources(resources); |
66 } | 58 } |
67 | 59 |
68 } // namespace ui | 60 } // namespace ui |
OLD | NEW |