| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/compositor_frame_sink_support.h" | 5 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 // SurfaceFactory's destructor will attempt to return resources which will | 52 // SurfaceFactory's destructor will attempt to return resources which will |
| 53 // call back into here and access |client_| so we should destroy | 53 // call back into here and access |client_| so we should destroy |
| 54 // |surface_factory_|'s resources early on. | 54 // |surface_factory_|'s resources early on. |
| 55 surface_factory_.EvictSurface(); | 55 surface_factory_.EvictSurface(); |
| 56 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 56 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 57 if (handles_frame_sink_id_invalidation_) | 57 if (handles_frame_sink_id_invalidation_) |
| 58 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 58 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( |
| 62 const LocalSurfaceId& local_surface_id, |
| 63 const std::vector<SurfaceId>* active_referenced_surfaces, |
| 64 const std::vector<SurfaceId>* pending_referenced_surfaces) { |
| 65 if (!surface_manager_->using_surface_references()) |
| 66 return; |
| 67 |
| 68 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); |
| 69 |
| 70 // Populate list of surface references to add and remove based on reference |
| 71 // surfaces in current frame compared with the last frame. The list of |
| 72 // surface references includes references from both the pending and active |
| 73 // frame if any. |
| 74 reference_tracker_.UpdateReferences(local_surface_id, |
| 75 active_referenced_surfaces, |
| 76 pending_referenced_surfaces); |
| 77 |
| 78 UpdateSurfaceReferences(last_surface_id, local_surface_id); |
| 79 } |
| 80 |
| 81 void CompositorFrameSinkSupport::ReturnResources( |
| 82 const ReturnedResourceArray& resources) { |
| 83 if (resources.empty()) |
| 84 return; |
| 85 |
| 86 if (!ack_pending_count_ && client_) { |
| 87 client_->ReclaimResources(resources); |
| 88 return; |
| 89 } |
| 90 |
| 91 std::copy(resources.begin(), resources.end(), |
| 92 std::back_inserter(surface_returned_resources_)); |
| 93 } |
| 94 |
| 95 void CompositorFrameSinkSupport::SetBeginFrameSource( |
| 96 BeginFrameSource* begin_frame_source) { |
| 97 if (begin_frame_source_ && added_frame_observer_) { |
| 98 begin_frame_source_->RemoveObserver(this); |
| 99 added_frame_observer_ = false; |
| 100 } |
| 101 begin_frame_source_ = begin_frame_source; |
| 102 UpdateNeedsBeginFramesInternal(); |
| 103 } |
| 104 |
| 105 void CompositorFrameSinkSupport::WillDrawSurface( |
| 106 const LocalSurfaceId& local_surface_id, |
| 107 const gfx::Rect& damage_rect) { |
| 108 if (client_) |
| 109 client_->WillDrawSurface(local_surface_id, damage_rect); |
| 110 } |
| 111 |
| 61 void CompositorFrameSinkSupport::EvictFrame() { | 112 void CompositorFrameSinkSupport::EvictFrame() { |
| 62 surface_factory_.EvictSurface(); | 113 surface_factory_.EvictSurface(); |
| 63 } | 114 } |
| 64 | 115 |
| 65 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { | 116 void CompositorFrameSinkSupport::SetNeedsBeginFrame(bool needs_begin_frame) { |
| 66 needs_begin_frame_ = needs_begin_frame; | 117 needs_begin_frame_ = needs_begin_frame; |
| 67 UpdateNeedsBeginFramesInternal(); | 118 UpdateNeedsBeginFramesInternal(); |
| 68 } | 119 } |
| 69 | 120 |
| 70 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( | 121 void CompositorFrameSinkSupport::BeginFrameDidNotSwap( |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 227 |
| 177 void CompositorFrameSinkSupport::ForceReclaimResources() { | 228 void CompositorFrameSinkSupport::ForceReclaimResources() { |
| 178 surface_factory_.ClearSurface(); | 229 surface_factory_.ClearSurface(); |
| 179 } | 230 } |
| 180 | 231 |
| 181 void CompositorFrameSinkSupport::ClaimTemporaryReference( | 232 void CompositorFrameSinkSupport::ClaimTemporaryReference( |
| 182 const SurfaceId& surface_id) { | 233 const SurfaceId& surface_id) { |
| 183 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); | 234 surface_manager_->AssignTemporaryReference(surface_id, frame_sink_id_); |
| 184 } | 235 } |
| 185 | 236 |
| 186 void CompositorFrameSinkSupport::ReferencedSurfacesChanged( | |
| 187 const LocalSurfaceId& local_surface_id, | |
| 188 const std::vector<SurfaceId>* active_referenced_surfaces, | |
| 189 const std::vector<SurfaceId>* pending_referenced_surfaces) { | |
| 190 if (!surface_manager_->using_surface_references()) | |
| 191 return; | |
| 192 | |
| 193 SurfaceId last_surface_id = reference_tracker_.current_surface_id(); | |
| 194 | |
| 195 // Populate list of surface references to add and remove based on reference | |
| 196 // surfaces in current frame compared with the last frame. The list of | |
| 197 // surface references includes references from both the pending and active | |
| 198 // frame if any. | |
| 199 reference_tracker_.UpdateReferences(local_surface_id, | |
| 200 active_referenced_surfaces, | |
| 201 pending_referenced_surfaces); | |
| 202 | |
| 203 UpdateSurfaceReferences(last_surface_id, local_surface_id); | |
| 204 } | |
| 205 | |
| 206 void CompositorFrameSinkSupport::ReturnResources( | |
| 207 const ReturnedResourceArray& resources) { | |
| 208 if (resources.empty()) | |
| 209 return; | |
| 210 | |
| 211 if (!ack_pending_count_ && client_) { | |
| 212 client_->ReclaimResources(resources); | |
| 213 return; | |
| 214 } | |
| 215 | |
| 216 std::copy(resources.begin(), resources.end(), | |
| 217 std::back_inserter(surface_returned_resources_)); | |
| 218 } | |
| 219 | |
| 220 void CompositorFrameSinkSupport::SetBeginFrameSource( | |
| 221 BeginFrameSource* begin_frame_source) { | |
| 222 if (begin_frame_source_ && added_frame_observer_) { | |
| 223 begin_frame_source_->RemoveObserver(this); | |
| 224 added_frame_observer_ = false; | |
| 225 } | |
| 226 begin_frame_source_ = begin_frame_source; | |
| 227 UpdateNeedsBeginFramesInternal(); | |
| 228 } | |
| 229 | |
| 230 void CompositorFrameSinkSupport::WillDrawSurface( | |
| 231 const LocalSurfaceId& local_surface_id, | |
| 232 const gfx::Rect& damage_rect) { | |
| 233 if (client_) | |
| 234 client_->WillDrawSurface(local_surface_id, damage_rect); | |
| 235 } | |
| 236 | |
| 237 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { | 237 void CompositorFrameSinkSupport::OnBeginFrame(const BeginFrameArgs& args) { |
| 238 UpdateNeedsBeginFramesInternal(); | 238 UpdateNeedsBeginFramesInternal(); |
| 239 last_begin_frame_args_ = args; | 239 last_begin_frame_args_ = args; |
| 240 if (client_) | 240 if (client_) |
| 241 client_->OnBeginFrame(args); | 241 client_->OnBeginFrame(args); |
| 242 } | 242 } |
| 243 | 243 |
| 244 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() | 244 const BeginFrameArgs& CompositorFrameSinkSupport::LastUsedBeginFrameArgs() |
| 245 const { | 245 const { |
| 246 return last_begin_frame_args_; | 246 return last_begin_frame_args_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 261 else | 261 else |
| 262 begin_frame_source_->RemoveObserver(this); | 262 begin_frame_source_->RemoveObserver(this); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void CompositorFrameSinkSupport::RequestCopyOfSurface( | 265 void CompositorFrameSinkSupport::RequestCopyOfSurface( |
| 266 std::unique_ptr<CopyOutputRequest> request) { | 266 std::unique_ptr<CopyOutputRequest> request) { |
| 267 surface_factory_.RequestCopyOfSurface(std::move(request)); | 267 surface_factory_.RequestCopyOfSurface(std::move(request)); |
| 268 } | 268 } |
| 269 | 269 |
| 270 } // namespace cc | 270 } // namespace cc |
| OLD | NEW |