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