| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | 67 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 68 | 68 |
| 69 // We want the Display's output surface to hear about lost context, and since | 69 // We want the Display's output surface to hear about lost context, and since |
| 70 // this shares a context with it, we should not be listening for lost context | 70 // this shares a context with it, we should not be listening for lost context |
| 71 // callbacks on the context here. | 71 // callbacks on the context here. |
| 72 if (auto* cp = context_provider()) | 72 if (auto* cp = context_provider()) |
| 73 cp->SetLostContextCallback(base::Closure()); | 73 cp->SetLostContextCallback(base::Closure()); |
| 74 | 74 |
| 75 // Avoid initializing GL context here, as this should be sharing the | 75 // Avoid initializing GL context here, as this should be sharing the |
| 76 // Display's context. | 76 // Display's context. |
| 77 display_->Initialize(this, surface_manager_, frame_sink_id_); | 77 display_->Initialize(this, surface_manager_); |
| 78 return true; | 78 return true; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void DirectCompositorFrameSink::DetachFromClient() { | 81 void DirectCompositorFrameSink::DetachFromClient() { |
| 82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only | 82 // Unregister the SurfaceFactoryClient here instead of the dtor so that only |
| 83 // one client is alive for this namespace at any given time. | 83 // one client is alive for this namespace at any given time. |
| 84 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 84 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 85 if (delegated_local_frame_id_.is_valid()) | 85 if (delegated_local_frame_id_.is_valid()) |
| 86 factory_.Destroy(delegated_local_frame_id_); | 86 factory_.Destroy(delegated_local_frame_id_); |
| 87 | 87 |
| 88 CompositorFrameSink::DetachFromClient(); | 88 CompositorFrameSink::DetachFromClient(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { | 91 void DirectCompositorFrameSink::SubmitCompositorFrame(CompositorFrame frame) { |
| 92 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); | 92 gfx::Size frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 93 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { | 93 if (frame_size.IsEmpty() || frame_size != last_swap_frame_size_) { |
| 94 if (delegated_local_frame_id_.is_valid()) { | 94 if (delegated_local_frame_id_.is_valid()) { |
| 95 factory_.Destroy(delegated_local_frame_id_); | 95 factory_.Destroy(delegated_local_frame_id_); |
| 96 } | 96 } |
| 97 delegated_local_frame_id_ = surface_id_allocator_.GenerateId(); | 97 delegated_local_frame_id_ = surface_id_allocator_.GenerateId(); |
| 98 factory_.Create(delegated_local_frame_id_); | 98 factory_.Create(delegated_local_frame_id_); |
| 99 last_swap_frame_size_ = frame_size; | 99 last_swap_frame_size_ = frame_size; |
| 100 } | 100 } |
| 101 display_->SetSurfaceId(SurfaceId(frame_sink_id_, delegated_local_frame_id_), | 101 display_->SetLocalFrameId(delegated_local_frame_id_, |
| 102 frame.metadata.device_scale_factor); | 102 frame.metadata.device_scale_factor); |
| 103 | 103 |
| 104 factory_.SubmitCompositorFrame( | 104 factory_.SubmitCompositorFrame( |
| 105 delegated_local_frame_id_, std::move(frame), | 105 delegated_local_frame_id_, std::move(frame), |
| 106 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, | 106 base::Bind(&DirectCompositorFrameSink::DidDrawCallback, |
| 107 base::Unretained(this))); | 107 base::Unretained(this))); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void DirectCompositorFrameSink::ForceReclaimResources() { | 110 void DirectCompositorFrameSink::ForceReclaimResources() { |
| 111 if (delegated_local_frame_id_.is_valid()) { | 111 if (delegated_local_frame_id_.is_valid()) { |
| 112 factory_.SubmitCompositorFrame(delegated_local_frame_id_, CompositorFrame(), | 112 factory_.SubmitCompositorFrame(delegated_local_frame_id_, CompositorFrame(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 141 // This notification is not relevant to our client outside of tests. We | 141 // This notification is not relevant to our client outside of tests. We |
| 142 // unblock the client from DidDrawCallback() when the surface is going to | 142 // unblock the client from DidDrawCallback() when the surface is going to |
| 143 // be drawn. | 143 // be drawn. |
| 144 } | 144 } |
| 145 | 145 |
| 146 void DirectCompositorFrameSink::DidDrawCallback() { | 146 void DirectCompositorFrameSink::DidDrawCallback() { |
| 147 client_->DidReceiveCompositorFrameAck(); | 147 client_->DidReceiveCompositorFrameAck(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace cc | 150 } // namespace cc |
| OLD | NEW |