Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: services/ui/surfaces/mojo_frame_sink_manager.cc

Issue 2795823003: Create //components/viz/frame_sinks and move code. (Closed)
Patch Set: Fix DEPS. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/ui/surfaces/mojo_frame_sink_manager.h"
6
7 #include <utility>
8
9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h"
11 #include "cc/base/switches.h"
12 #include "cc/scheduler/begin_frame_source.h"
13 #include "cc/surfaces/display.h"
14 #include "cc/surfaces/surface_dependency_tracker.h"
15 #include "components/display_compositor/gpu_compositor_frame_sink.h"
16 #include "components/display_compositor/gpu_root_compositor_frame_sink.h"
17 #include "services/ui/surfaces/display_provider.h"
18
19 namespace ui {
20
21 MojoFrameSinkManager::MojoFrameSinkManager(
22 DisplayProvider* display_provider,
23 cc::mojom::FrameSinkManagerRequest request,
24 cc::mojom::FrameSinkManagerClientPtr client)
25 : manager_(cc::SurfaceManager::LifetimeType::REFERENCES),
26 display_provider_(display_provider),
27 client_(std::move(client)),
28 binding_(this, std::move(request)) {
29 manager_.AddObserver(this);
30 }
31
32 MojoFrameSinkManager::~MojoFrameSinkManager() {
33 DCHECK(thread_checker_.CalledOnValidThread());
34 manager_.RemoveObserver(this);
35 }
36
37 void MojoFrameSinkManager::CreateRootCompositorFrameSink(
38 const cc::FrameSinkId& frame_sink_id,
39 gpu::SurfaceHandle surface_handle,
40 cc::mojom::MojoCompositorFrameSinkAssociatedRequest request,
41 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
42 cc::mojom::MojoCompositorFrameSinkClientPtr client,
43 cc::mojom::DisplayPrivateAssociatedRequest display_private_request) {
44 DCHECK(thread_checker_.CalledOnValidThread());
45 DCHECK_NE(surface_handle, gpu::kNullSurfaceHandle);
46 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
47 DCHECK(display_provider_);
48
49 std::unique_ptr<cc::BeginFrameSource> begin_frame_source;
50 std::unique_ptr<cc::Display> display = display_provider_->CreateDisplay(
51 frame_sink_id, surface_handle, &begin_frame_source);
52
53 // Lazily inject a SurfaceDependencyTracker into SurfaceManager if surface
54 // synchronization is enabled.
55 if (!manager_.dependency_tracker() &&
56 base::CommandLine::ForCurrentProcess()->HasSwitch(
57 cc::switches::kEnableSurfaceSynchronization)) {
58 std::unique_ptr<cc::SurfaceDependencyTracker> dependency_tracker(
59 new cc::SurfaceDependencyTracker(&manager_, begin_frame_source.get()));
60 manager_.SetDependencyTracker(std::move(dependency_tracker));
61 }
62
63 compositor_frame_sinks_[frame_sink_id] =
64 base::MakeUnique<display_compositor::GpuRootCompositorFrameSink>(
65 this, &manager_, frame_sink_id, std::move(display),
66 std::move(begin_frame_source), std::move(request),
67 std::move(private_request), std::move(client),
68 std::move(display_private_request));
69 }
70
71 void MojoFrameSinkManager::CreateCompositorFrameSink(
72 const cc::FrameSinkId& frame_sink_id,
73 cc::mojom::MojoCompositorFrameSinkRequest request,
74 cc::mojom::MojoCompositorFrameSinkPrivateRequest private_request,
75 cc::mojom::MojoCompositorFrameSinkClientPtr client) {
76 DCHECK(thread_checker_.CalledOnValidThread());
77 DCHECK_EQ(0u, compositor_frame_sinks_.count(frame_sink_id));
78
79 compositor_frame_sinks_[frame_sink_id] =
80 base::MakeUnique<display_compositor::GpuCompositorFrameSink>(
81 this, &manager_, frame_sink_id, std::move(request),
82 std::move(private_request), std::move(client));
83 }
84
85 void MojoFrameSinkManager::RegisterFrameSinkHierarchy(
86 const cc::FrameSinkId& parent_frame_sink_id,
87 const cc::FrameSinkId& child_frame_sink_id) {
88 manager_.RegisterFrameSinkHierarchy(parent_frame_sink_id,
89 child_frame_sink_id);
90 }
91
92 void MojoFrameSinkManager::UnregisterFrameSinkHierarchy(
93 const cc::FrameSinkId& parent_frame_sink_id,
94 const cc::FrameSinkId& child_frame_sink_id) {
95 manager_.UnregisterFrameSinkHierarchy(parent_frame_sink_id,
96 child_frame_sink_id);
97 }
98
99 void MojoFrameSinkManager::DropTemporaryReference(
100 const cc::SurfaceId& surface_id) {
101 manager_.DropTemporaryReference(surface_id);
102 }
103
104 void MojoFrameSinkManager::DestroyCompositorFrameSink(cc::FrameSinkId sink_id) {
105 compositor_frame_sinks_.erase(sink_id);
106 }
107
108 void MojoFrameSinkManager::OnSurfaceCreated(
109 const cc::SurfaceInfo& surface_info) {
110 DCHECK(thread_checker_.CalledOnValidThread());
111 DCHECK_GT(surface_info.device_scale_factor(), 0.0f);
112
113 // TODO(kylechar): |client_| will try to find an owner for the temporary
114 // reference to the new surface. With surface synchronization this might not
115 // be necessary, because a surface reference might already exist and no
116 // temporary reference was created. It could be useful to let |client_| know
117 // if it should find an owner.
118 if (client_)
119 client_->OnSurfaceCreated(surface_info);
120 }
121
122 void MojoFrameSinkManager::OnSurfaceDamaged(const cc::SurfaceId& surface_id,
123 bool* changed) {}
124
125 void MojoFrameSinkManager::OnClientConnectionLost(
126 const cc::FrameSinkId& frame_sink_id,
127 bool destroy_compositor_frame_sink) {
128 DCHECK(thread_checker_.CalledOnValidThread());
129 if (destroy_compositor_frame_sink)
130 DestroyCompositorFrameSink(frame_sink_id);
131 // TODO(fsamuel): Tell the frame sink manager host that the client connection
132 // has been lost so that it can drop its private connection and allow a new
133 // client instance to create a new CompositorFrameSink.
134 }
135
136 void MojoFrameSinkManager::OnPrivateConnectionLost(
137 const cc::FrameSinkId& frame_sink_id,
138 bool destroy_compositor_frame_sink) {
139 DCHECK(thread_checker_.CalledOnValidThread());
140 if (destroy_compositor_frame_sink)
141 DestroyCompositorFrameSink(frame_sink_id);
142 }
143
144 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/surfaces/mojo_frame_sink_manager.h ('k') | services/ui/surfaces/mus_display_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698