OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/surfaces/display_compositor.h" | 5 #include "services/ui/surfaces/display_compositor.h" |
6 | 6 |
| 7 #include "cc/output/in_process_context_provider.h" |
7 #include "cc/surfaces/surface.h" | 8 #include "cc/surfaces/surface.h" |
| 9 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 10 #include "gpu/ipc/gpu_in_process_thread_service.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 #include "services/ui/surfaces/gpu_compositor_frame_sink.h" |
8 | 13 |
9 namespace ui { | 14 namespace ui { |
10 | 15 |
11 DisplayCompositor::DisplayCompositor( | 16 DisplayCompositor::DisplayCompositor( |
| 17 scoped_refptr<gpu::InProcessCommandBuffer::Service> gpu_service, |
| 18 std::unique_ptr<MusGpuMemoryBufferManager> gpu_memory_buffer_manager, |
| 19 gpu::ImageFactory* image_factory, |
12 cc::mojom::DisplayCompositorClientPtr client) | 20 cc::mojom::DisplayCompositorClientPtr client) |
13 : client_(std::move(client)) { | 21 : gpu_service_(std::move(gpu_service)), |
| 22 gpu_memory_buffer_manager_(std::move(gpu_memory_buffer_manager)), |
| 23 image_factory_(image_factory), |
| 24 client_(std::move(client)) { |
14 manager_.AddObserver(this); | 25 manager_.AddObserver(this); |
15 } | 26 } |
16 | 27 |
| 28 void DisplayCompositor::CreateCompositorFrameSink( |
| 29 const cc::FrameSinkId& frame_sink_id, |
| 30 gpu::SurfaceHandle surface_handle, |
| 31 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 32 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request, |
| 33 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 34 // We cannot create more than one CompositorFrameSink with a given |
| 35 // |frame_sink_id|. |
| 36 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id)); |
| 37 scoped_refptr<cc::InProcessContextProvider> context_provider; |
| 38 if (surface_handle != gpu::kNullSurfaceHandle) { |
| 39 context_provider = new cc::InProcessContextProvider( |
| 40 gpu_service_, surface_handle, gpu_memory_buffer_manager_.get(), |
| 41 image_factory_, gpu::SharedMemoryLimits(), |
| 42 nullptr /* shared_context */); |
| 43 } |
| 44 compositor_frame_sinks_[frame_sink_id] = |
| 45 base::MakeUnique<GpuCompositorFrameSink>( |
| 46 this, frame_sink_id, surface_handle, gpu_memory_buffer_manager_.get(), |
| 47 std::move(context_provider), std::move(request), |
| 48 std::move(private_request), std::move(client)); |
| 49 } |
| 50 |
17 void DisplayCompositor::AddSurfaceReference( | 51 void DisplayCompositor::AddSurfaceReference( |
18 const cc::SurfaceId& surface_id, | 52 const cc::SurfaceId& surface_id, |
19 const cc::SurfaceSequence& surface_sequence) { | 53 const cc::SurfaceSequence& surface_sequence) { |
20 cc::Surface* surface = manager_.GetSurfaceForId(surface_id); | 54 cc::Surface* surface = manager_.GetSurfaceForId(surface_id); |
21 if (!surface) { | 55 if (!surface) { |
22 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " | 56 LOG(ERROR) << "Attempting to add dependency to nonexistent surface " |
23 << surface_id.ToString(); | 57 << surface_id.ToString(); |
24 return; | 58 return; |
25 } | 59 } |
26 surface->AddDestructionDependency(surface_sequence); | 60 surface->AddDestructionDependency(surface_sequence); |
27 } | 61 } |
28 | 62 |
29 void DisplayCompositor::ReturnSurfaceReferences( | 63 void DisplayCompositor::ReturnSurfaceReferences( |
30 const cc::FrameSinkId& frame_sink_id, | 64 const cc::FrameSinkId& frame_sink_id, |
31 const std::vector<uint32_t>& sequences) { | 65 const std::vector<uint32_t>& sequences) { |
32 std::vector<uint32_t> sequences_copy(sequences); | 66 std::vector<uint32_t> sequences_copy(sequences); |
33 manager_.DidSatisfySequences(frame_sink_id, &sequences_copy); | 67 manager_.DidSatisfySequences(frame_sink_id, &sequences_copy); |
34 } | 68 } |
35 | 69 |
36 DisplayCompositor::~DisplayCompositor() { | 70 DisplayCompositor::~DisplayCompositor() { |
37 manager_.RemoveObserver(this); | 71 manager_.RemoveObserver(this); |
38 } | 72 } |
39 | 73 |
| 74 void DisplayCompositor::OnCompositorFrameSinkClientConnectionLost( |
| 75 const cc::FrameSinkId& frame_sink_id, |
| 76 bool destroy_compositor_frame_sink) { |
| 77 if (destroy_compositor_frame_sink) |
| 78 compositor_frame_sinks_.erase(frame_sink_id); |
| 79 // TODO(fsamuel): Tell the display compositor host that the client connection |
| 80 // has been lost so that it can drop its private connection and allow a new |
| 81 // client instance to create a new CompositorFrameSink. |
| 82 } |
| 83 |
| 84 void DisplayCompositor::OnCompositorFrameSinkPrivateConnectionLost( |
| 85 const cc::FrameSinkId& frame_sink_id, |
| 86 bool destroy_compositor_frame_sink) { |
| 87 if (destroy_compositor_frame_sink) |
| 88 compositor_frame_sinks_.erase(frame_sink_id); |
| 89 } |
| 90 |
40 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, | 91 void DisplayCompositor::OnSurfaceCreated(const cc::SurfaceId& surface_id, |
41 const gfx::Size& frame_size, | 92 const gfx::Size& frame_size, |
42 float device_scale_factor) { | 93 float device_scale_factor) { |
43 if (client_) | 94 if (client_) |
44 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); | 95 client_->OnSurfaceCreated(surface_id, frame_size, device_scale_factor); |
45 } | 96 } |
46 | 97 |
47 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, | 98 void DisplayCompositor::OnSurfaceDamaged(const cc::SurfaceId& surface_id, |
48 bool* changed) {} | 99 bool* changed) {} |
49 | 100 |
50 } // namespace ui | 101 } // namespace ui |
OLD | NEW |