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

Side by Side Diff: cc/surfaces/direct_compositor_frame_sink.cc

Issue 2337913003: Fork cc::OutputSurface into cc::CompositorFrameSink. (Closed)
Patch Set: cfsfork: rebase Created 4 years, 3 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
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 "cc/surfaces/surface_display_output_surface.h" 5 #include "cc/surfaces/direct_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/surfaces/display.h" 10 #include "cc/surfaces/display.h"
10 #include "cc/surfaces/surface.h" 11 #include "cc/surfaces/surface.h"
11 #include "cc/surfaces/surface_id_allocator.h" 12 #include "cc/surfaces/surface_id_allocator.h"
12 #include "cc/surfaces/surface_manager.h" 13 #include "cc/surfaces/surface_manager.h"
13 14
14 namespace cc { 15 namespace cc {
15 16
16 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( 17 DirectCompositorFrameSink::DirectCompositorFrameSink(
17 SurfaceManager* surface_manager, 18 SurfaceManager* surface_manager,
18 SurfaceIdAllocator* surface_id_allocator, 19 SurfaceIdAllocator* surface_id_allocator,
19 Display* display, 20 Display* display,
20 scoped_refptr<ContextProvider> context_provider, 21 scoped_refptr<ContextProvider> context_provider,
21 scoped_refptr<ContextProvider> worker_context_provider) 22 scoped_refptr<ContextProvider> worker_context_provider)
22 : OutputSurface(std::move(context_provider), 23 : CompositorFrameSink(std::move(context_provider),
23 std::move(worker_context_provider), 24 std::move(worker_context_provider),
24 nullptr), 25 nullptr),
25 surface_manager_(surface_manager), 26 surface_manager_(surface_manager),
26 surface_id_allocator_(surface_id_allocator), 27 surface_id_allocator_(surface_id_allocator),
27 display_(display), 28 display_(display),
28 factory_(surface_manager, this) { 29 factory_(surface_manager, this) {
29 DCHECK(thread_checker_.CalledOnValidThread()); 30 DCHECK(thread_checker_.CalledOnValidThread());
30 capabilities_.delegated_rendering = true; 31 capabilities_.delegated_rendering = true;
31 capabilities_.adjust_deadline_for_parent = true; 32 capabilities_.adjust_deadline_for_parent = true;
32 capabilities_.can_force_reclaim_resources = true; 33 capabilities_.can_force_reclaim_resources = true;
33 34
34 // Display and SurfaceDisplayOutputSurface share a GL context, so sync 35 // Display and DirectCompositorFrameSink share a GL context, so sync
35 // points aren't needed when passing resources between them. 36 // points aren't needed when passing resources between them.
36 capabilities_.delegated_sync_points_required = false; 37 capabilities_.delegated_sync_points_required = false;
37 factory_.set_needs_sync_points(false); 38 factory_.set_needs_sync_points(false);
38 } 39 }
39 40
40 SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( 41 DirectCompositorFrameSink::DirectCompositorFrameSink(
41 SurfaceManager* surface_manager, 42 SurfaceManager* surface_manager,
42 SurfaceIdAllocator* surface_id_allocator, 43 SurfaceIdAllocator* surface_id_allocator,
43 Display* display, 44 Display* display,
44 scoped_refptr<VulkanContextProvider> vulkan_context_provider) 45 scoped_refptr<VulkanContextProvider> vulkan_context_provider)
45 : OutputSurface(std::move(vulkan_context_provider)), 46 : CompositorFrameSink(std::move(vulkan_context_provider)),
46 surface_manager_(surface_manager), 47 surface_manager_(surface_manager),
47 surface_id_allocator_(surface_id_allocator), 48 surface_id_allocator_(surface_id_allocator),
48 display_(display), 49 display_(display),
49 factory_(surface_manager, this) { 50 factory_(surface_manager, this) {
50 DCHECK(thread_checker_.CalledOnValidThread()); 51 DCHECK(thread_checker_.CalledOnValidThread());
51 capabilities_.delegated_rendering = true; 52 capabilities_.delegated_rendering = true;
52 capabilities_.adjust_deadline_for_parent = true; 53 capabilities_.adjust_deadline_for_parent = true;
53 capabilities_.can_force_reclaim_resources = true; 54 capabilities_.can_force_reclaim_resources = true;
54 } 55 }
55 56
56 SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { 57 DirectCompositorFrameSink::~DirectCompositorFrameSink() {
57 DCHECK(thread_checker_.CalledOnValidThread()); 58 DCHECK(thread_checker_.CalledOnValidThread());
58 if (HasClient()) 59 if (HasClient())
59 DetachFromClient(); 60 DetachFromClient();
60 } 61 }
61 62
62 void SurfaceDisplayOutputSurface::SwapBuffers(CompositorFrame frame) { 63 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) {
63 gfx::Size frame_size = 64 gfx::Size frame_size =
64 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); 65 frame.delegated_frame_data->render_pass_list.back()->output_rect.size();
65 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { 66 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) {
66 if (!delegated_surface_id_.is_null()) { 67 if (!delegated_surface_id_.is_null()) {
67 factory_.Destroy(delegated_surface_id_); 68 factory_.Destroy(delegated_surface_id_);
68 } 69 }
69 delegated_surface_id_ = surface_id_allocator_->GenerateId(); 70 delegated_surface_id_ = surface_id_allocator_->GenerateId();
70 factory_.Create(delegated_surface_id_); 71 factory_.Create(delegated_surface_id_);
71 last_swap_frame_size_ = frame_size; 72 last_swap_frame_size_ = frame_size;
72 } 73 }
73 display_->SetSurfaceId(delegated_surface_id_, 74 display_->SetSurfaceId(delegated_surface_id_,
74 frame.metadata.device_scale_factor); 75 frame.metadata.device_scale_factor);
75 76
76 factory_.SubmitCompositorFrame( 77 factory_.SubmitCompositorFrame(
77 delegated_surface_id_, std::move(frame), 78 delegated_surface_id_, std::move(frame),
78 base::Bind(&SurfaceDisplayOutputSurface::DidDrawCallback, 79 base::Bind(&DirectCompositorFrameSink::DidDrawCallback,
79 base::Unretained(this))); 80 base::Unretained(this)));
80 } 81 }
81 82
82 bool SurfaceDisplayOutputSurface::BindToClient(OutputSurfaceClient* client) { 83 bool DirectCompositorFrameSink::BindToClient(
84 CompositorFrameSinkClient* client) {
83 DCHECK(thread_checker_.CalledOnValidThread()); 85 DCHECK(thread_checker_.CalledOnValidThread());
84 86
85 surface_manager_->RegisterSurfaceFactoryClient( 87 surface_manager_->RegisterSurfaceFactoryClient(
86 surface_id_allocator_->client_id(), this); 88 surface_id_allocator_->client_id(), this);
87 89
88 if (!OutputSurface::BindToClient(client)) 90 if (!CompositorFrameSink::BindToClient(client))
89 return false; 91 return false;
90 92
91 // We want the Display's output surface to hear about lost context, and since 93 // We want the Display's output surface to hear about lost context, and since
92 // this shares a context with it, we should not be listening for lost context 94 // this shares a context with it, we should not be listening for lost context
93 // callbacks on the context here. 95 // callbacks on the context here.
94 if (context_provider()) 96 if (context_provider())
95 context_provider()->SetLostContextCallback(base::Closure()); 97 context_provider()->SetLostContextCallback(base::Closure());
96 98
97 // Avoid initializing GL context here, as this should be sharing the 99 // Avoid initializing GL context here, as this should be sharing the
98 // Display's context. 100 // Display's context.
99 display_->Initialize(this, surface_manager_, 101 display_->Initialize(this, surface_manager_,
100 surface_id_allocator_->client_id()); 102 surface_id_allocator_->client_id());
101 return true; 103 return true;
102 } 104 }
103 105
104 void SurfaceDisplayOutputSurface::ForceReclaimResources() { 106 void DirectCompositorFrameSink::ForceReclaimResources() {
105 if (!delegated_surface_id_.is_null()) { 107 if (!delegated_surface_id_.is_null()) {
106 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(), 108 factory_.SubmitCompositorFrame(delegated_surface_id_, CompositorFrame(),
107 SurfaceFactory::DrawCallback()); 109 SurfaceFactory::DrawCallback());
108 } 110 }
109 } 111 }
110 112
111 void SurfaceDisplayOutputSurface::DetachFromClient() { 113 void DirectCompositorFrameSink::DetachFromClient() {
112 DCHECK(HasClient()); 114 DCHECK(HasClient());
113 // Unregister the SurfaceFactoryClient here instead of the dtor so that only 115 // Unregister the SurfaceFactoryClient here instead of the dtor so that only
114 // one client is alive for this namespace at any given time. 116 // one client is alive for this namespace at any given time.
115 surface_manager_->UnregisterSurfaceFactoryClient( 117 surface_manager_->UnregisterSurfaceFactoryClient(
116 surface_id_allocator_->client_id()); 118 surface_id_allocator_->client_id());
117 if (!delegated_surface_id_.is_null()) 119 if (!delegated_surface_id_.is_null())
118 factory_.Destroy(delegated_surface_id_); 120 factory_.Destroy(delegated_surface_id_);
119 121
120 OutputSurface::DetachFromClient(); 122 CompositorFrameSink::DetachFromClient();
121 } 123 }
122 124
123 void SurfaceDisplayOutputSurface::BindFramebuffer() { 125 void DirectCompositorFrameSink::BindFramebuffer() {
124 // This is a delegating output surface, no framebuffer/direct drawing support. 126 // This is a delegating output surface, no framebuffer/direct drawing support.
enne (OOO) 2016/09/14 00:35:44 I guess this function will go away soon, but here'
125 NOTREACHED(); 127 NOTREACHED();
126 } 128 }
127 129
128 uint32_t SurfaceDisplayOutputSurface::GetFramebufferCopyTextureFormat() { 130 uint32_t DirectCompositorFrameSink::GetFramebufferCopyTextureFormat() {
129 // This is a delegating output surface, no framebuffer/direct drawing support. 131 // This is a delegating output surface, no framebuffer/direct drawing support.
130 NOTREACHED(); 132 NOTREACHED();
131 return 0; 133 return 0;
132 } 134 }
133 135
134 void SurfaceDisplayOutputSurface::ReturnResources( 136 void DirectCompositorFrameSink::ReturnResources(
135 const ReturnedResourceArray& resources) { 137 const ReturnedResourceArray& resources) {
136 if (client_) 138 if (client_)
137 client_->ReclaimResources(resources); 139 client_->ReclaimResources(resources);
138 } 140 }
139 141
140 void SurfaceDisplayOutputSurface::SetBeginFrameSource( 142 void DirectCompositorFrameSink::SetBeginFrameSource(
141 BeginFrameSource* begin_frame_source) { 143 BeginFrameSource* begin_frame_source) {
142 DCHECK(client_); 144 DCHECK(client_);
143 client_->SetBeginFrameSource(begin_frame_source); 145 client_->SetBeginFrameSource(begin_frame_source);
144 } 146 }
145 147
146 void SurfaceDisplayOutputSurface::DisplayOutputSurfaceLost() { 148 void DirectCompositorFrameSink::DisplayOutputSurfaceLost() {
147 output_surface_lost_ = true; 149 is_lost_ = true;
148 client_->DidLoseOutputSurface(); 150 client_->DidLoseCompositorFrameSink();
149 } 151 }
150 152
151 void SurfaceDisplayOutputSurface::DisplayWillDrawAndSwap( 153 void DirectCompositorFrameSink::DisplayWillDrawAndSwap(
152 bool will_draw_and_swap, 154 bool will_draw_and_swap,
153 const RenderPassList& render_passes) { 155 const RenderPassList& render_passes) {
154 // This notification is not relevant to our client outside of tests. 156 // This notification is not relevant to our client outside of tests.
155 } 157 }
156 158
157 void SurfaceDisplayOutputSurface::DisplayDidDrawAndSwap() { 159 void DirectCompositorFrameSink::DisplayDidDrawAndSwap() {
158 // This notification is not relevant to our client outside of tests. We 160 // This notification is not relevant to our client outside of tests. We
159 // unblock the client from DidDrawCallback() when the surface is going to 161 // unblock the client from DidDrawCallback() when the surface is going to
160 // be drawn. 162 // be drawn.
161 } 163 }
162 164
163 void SurfaceDisplayOutputSurface::DidDrawCallback() { 165 void DirectCompositorFrameSink::DidDrawCallback() {
164 // TODO(danakj): Why the lost check? 166 // TODO(danakj): Why the lost check?
165 if (!output_surface_lost_) 167 if (!is_lost_)
166 client_->DidSwapBuffersComplete(); 168 client_->DidSwapBuffersComplete();
167 } 169 }
168 170
169 } // namespace cc 171 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698