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, | |
23 nullptr), | 22 nullptr), |
24 surface_(std::move(surface)) { | 23 surface_(std::move(surface)) { |
25 capabilities_.delegated_rendering = true; | |
26 } | 24 } |
27 | 25 |
28 CompositorFrameSink::~CompositorFrameSink() {} | 26 CompositorFrameSink::~CompositorFrameSink() {} |
29 | 27 |
30 bool CompositorFrameSink::BindToClient(cc::CompositorFrameSinkClient* client) { | 28 bool CompositorFrameSink::BindToClient(cc::CompositorFrameSinkClient* client) { |
31 surface_->BindToThread(); | 29 surface_->BindToThread(); |
32 surface_->set_client(this); | 30 surface_->set_client(this); |
33 | 31 |
34 // TODO(enne): Get this from the WindowSurface via ServerWindowSurface. | 32 // TODO(enne): Get this from the WindowSurface via ServerWindowSurface. |
35 begin_frame_source_.reset(new cc::DelayBasedBeginFrameSource( | 33 begin_frame_source_.reset(new cc::DelayBasedBeginFrameSource( |
36 base::MakeUnique<cc::DelayBasedTimeSource>( | 34 base::MakeUnique<cc::DelayBasedTimeSource>( |
37 base::ThreadTaskRunnerHandle::Get().get()))); | 35 base::ThreadTaskRunnerHandle::Get().get()))); |
38 | 36 |
39 client->SetBeginFrameSource(begin_frame_source_.get()); | 37 client->SetBeginFrameSource(begin_frame_source_.get()); |
40 return cc::CompositorFrameSink::BindToClient(client); | 38 return cc::CompositorFrameSink::BindToClient(client); |
41 } | 39 } |
42 | 40 |
43 void CompositorFrameSink::DetachFromClient() { | 41 void CompositorFrameSink::DetachFromClient() { |
44 client_->SetBeginFrameSource(nullptr); | 42 client_->SetBeginFrameSource(nullptr); |
45 begin_frame_source_.reset(); | 43 begin_frame_source_.reset(); |
46 surface_.reset(); | 44 surface_.reset(); |
47 cc::CompositorFrameSink::DetachFromClient(); | 45 cc::CompositorFrameSink::DetachFromClient(); |
48 } | 46 } |
49 | 47 |
50 void CompositorFrameSink::BindFramebuffer() { | |
51 // This is a delegating output surface, no framebuffer/direct drawing support. | |
52 NOTREACHED(); | |
53 } | |
54 | |
55 uint32_t CompositorFrameSink::GetFramebufferCopyTextureFormat() { | |
56 // This is a delegating output surface, no framebuffer/direct drawing support. | |
57 NOTREACHED(); | |
58 return 0; | |
59 } | |
60 | |
61 void CompositorFrameSink::SwapBuffers(cc::CompositorFrame frame) { | 48 void CompositorFrameSink::SwapBuffers(cc::CompositorFrame frame) { |
62 // CompositorFrameSink owns WindowSurface, and so if CompositorFrameSink is | 49 // CompositorFrameSink owns WindowSurface, and so if CompositorFrameSink is |
63 // destroyed then SubmitCompositorFrame's callback will never get called. | 50 // destroyed then SubmitCompositorFrame's callback will never get called. |
64 // Thus, base::Unretained is safe here. | 51 // Thus, base::Unretained is safe here. |
65 surface_->SubmitCompositorFrame( | 52 surface_->SubmitCompositorFrame( |
66 std::move(frame), base::Bind(&CompositorFrameSink::SwapBuffersComplete, | 53 std::move(frame), base::Bind(&CompositorFrameSink::SwapBuffersComplete, |
67 base::Unretained(this))); | 54 base::Unretained(this))); |
68 } | 55 } |
69 | 56 |
70 void CompositorFrameSink::OnResourcesReturned( | 57 void CompositorFrameSink::OnResourcesReturned( |
71 ui::WindowSurface* surface, | 58 ui::WindowSurface* surface, |
72 mojo::Array<cc::ReturnedResource> resources) { | 59 mojo::Array<cc::ReturnedResource> resources) { |
73 client_->ReclaimResources(resources.To<cc::ReturnedResourceArray>()); | 60 client_->ReclaimResources(resources.To<cc::ReturnedResourceArray>()); |
74 } | 61 } |
75 | 62 |
76 void CompositorFrameSink::SwapBuffersComplete() { | 63 void CompositorFrameSink::SwapBuffersComplete() { |
77 client_->DidSwapBuffersComplete(); | 64 client_->DidSwapBuffersComplete(); |
78 } | 65 } |
79 | 66 |
80 } // namespace ui | 67 } // namespace ui |
OLD | NEW |