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 "cc/surfaces/direct_compositor_frame_sink.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/output/compositor_frame_sink_client.h" |
10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 frame_sink_id_(frame_sink_id), | 44 frame_sink_id_(frame_sink_id), |
45 surface_manager_(surface_manager), | 45 surface_manager_(surface_manager), |
46 display_(display), | 46 display_(display), |
47 factory_(frame_sink_id_, surface_manager, this) { | 47 factory_(frame_sink_id_, surface_manager, this) { |
48 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
49 capabilities_.can_force_reclaim_resources = true; | 49 capabilities_.can_force_reclaim_resources = true; |
50 } | 50 } |
51 | 51 |
52 DirectCompositorFrameSink::~DirectCompositorFrameSink() { | 52 DirectCompositorFrameSink::~DirectCompositorFrameSink() { |
53 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
54 if (HasClient()) | |
55 DetachFromClient(); | |
56 } | 54 } |
57 | 55 |
58 bool DirectCompositorFrameSink::BindToClient( | 56 bool DirectCompositorFrameSink::BindToClient( |
59 CompositorFrameSinkClient* client) { | 57 CompositorFrameSinkClient* client) { |
60 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
61 | 59 |
62 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | |
63 | |
64 if (!CompositorFrameSink::BindToClient(client)) | 60 if (!CompositorFrameSink::BindToClient(client)) |
65 return false; | 61 return false; |
66 | 62 |
| 63 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 64 |
67 // We want the Display's output surface to hear about lost context, and since | 65 // We want the Display's output surface to hear about lost context, and since |
68 // this shares a context with it, we should not be listening for lost context | 66 // this shares a context with it, we should not be listening for lost context |
69 // callbacks on the context here. | 67 // callbacks on the context here. |
70 if (context_provider()) | 68 if (auto* cp = context_provider()) |
71 context_provider()->SetLostContextCallback(base::Closure()); | 69 cp->SetLostContextCallback(base::Closure()); |
72 | 70 |
73 // Avoid initializing GL context here, as this should be sharing the | 71 // Avoid initializing GL context here, as this should be sharing the |
74 // Display's context. | 72 // Display's context. |
75 display_->Initialize(this, surface_manager_, frame_sink_id_); | 73 display_->Initialize(this, surface_manager_, frame_sink_id_); |
76 return true; | 74 return true; |
77 } | 75 } |
78 | 76 |
79 void DirectCompositorFrameSink::DetachFromClient() { | 77 void DirectCompositorFrameSink::DetachFromClient() { |
80 DCHECK(HasClient()); | |
81 | |
82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 78 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
83 // one client is alive for this namespace at any given time. | 79 // one client is alive for this namespace at any given time. |
84 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 80 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
85 if (!delegated_local_frame_id_.is_null()) | 81 if (!delegated_local_frame_id_.is_null()) |
86 factory_.Destroy(delegated_local_frame_id_); | 82 factory_.Destroy(delegated_local_frame_id_); |
87 | 83 |
88 CompositorFrameSink::DetachFromClient(); | 84 CompositorFrameSink::DetachFromClient(); |
89 } | 85 } |
90 | 86 |
91 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { | 87 void DirectCompositorFrameSink::SwapBuffers(CompositorFrame frame) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // This notification is not relevant to our client outside of tests. We | 138 // This notification is not relevant to our client outside of tests. We |
143 // unblock the client from DidDrawCallback() when the surface is going to | 139 // unblock the client from DidDrawCallback() when the surface is going to |
144 // be drawn. | 140 // be drawn. |
145 } | 141 } |
146 | 142 |
147 void DirectCompositorFrameSink::DidDrawCallback() { | 143 void DirectCompositorFrameSink::DidDrawCallback() { |
148 client_->DidSwapBuffersComplete(); | 144 client_->DidSwapBuffersComplete(); |
149 } | 145 } |
150 | 146 |
151 } // namespace cc | 147 } // namespace cc |
OLD | NEW |