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