 Chromium Code Reviews
 Chromium Code Reviews Issue 2493223002:
  Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink  (Closed)
    
  
    Issue 2493223002:
  Change exo::SurfaceFactoryOwner to exo::ExoCompositorFrameSink  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/exo/compositor_frame_sink.h" | |
| 6 | |
| 7 #include "base/debug/stack_trace.h" | |
| 8 #include "cc/surfaces/surface_manager.h" | |
| 9 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 10 | |
| 11 namespace exo { | |
| 12 | |
| 13 //////////////////////////////////////////////////////////////////////////////// | |
| 14 // ExoComopositorFrameSink, public: | |
| 15 | |
| 16 // static | |
| 17 void CompositorFrameSink::Create( | |
| 18 const cc::FrameSinkId& frame_sink_id, | |
| 19 cc::SurfaceManager* surface_manager, | |
| 20 cc::mojom::MojoCompositorFrameSinkClientPtr client, | |
| 21 cc::mojom::MojoCompositorFrameSinkRequest request) { | |
| 22 auto* impl = new CompositorFrameSink(frame_sink_id, surface_manager, | |
| 
Fady Samuel
2016/12/01 20:38:46
base::MakeUnique<CompositorFrameSink>(frame_sink_i
 
Alex Z.
2016/12/06 20:10:41
Done.
 | |
| 23 std::move(client)); | |
| 24 auto binding = | |
| 25 mojo::MakeStrongBinding(base::WrapUnique(impl), std::move(request)); | |
| 
Fady Samuel
2016/12/01 20:38:46
use MakeUnique above instead of wrapunique.
 
Alex Z.
2016/12/06 20:10:41
Done.
 | |
| 26 impl->binding_ = binding; | |
| 27 } | |
| 28 | |
| 29 CompositorFrameSink::CompositorFrameSink( | |
| 30 const cc::FrameSinkId& frame_sink_id, | |
| 31 cc::SurfaceManager* surface_manager, | |
| 32 cc::mojom::MojoCompositorFrameSinkClientPtr client) | |
| 33 : frame_sink_id_(frame_sink_id), | |
| 
Fady Samuel
2016/12/03 07:14:09
Now that CompositorFrameSinkSupport has landed you
 
Alex Z.
2016/12/06 20:10:41
Done.
 | |
| 34 surface_manager_(surface_manager), | |
| 35 surface_factory_(frame_sink_id, surface_manager, this), | |
| 36 client_(std::move(client)) { | |
| 37 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | |
| 38 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | |
| 39 } | |
| 40 | |
| 41 CompositorFrameSink::~CompositorFrameSink() { | |
| 42 surface_factory_.EvictSurface(); | |
| 43 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | |
| 44 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | |
| 45 } | |
| 46 | |
| 47 //////////////////////////////////////////////////////////////////////////////// | |
| 48 // cc::SurfaceFactoryClient overrides: | |
| 49 | |
| 50 void CompositorFrameSink::ReturnResources( | |
| 51 const cc::ReturnedResourceArray& resources) { | |
| 52 if (resources.empty()) | |
| 53 return; | |
| 54 | |
| 55 if (!ack_pending_count_ && client_) { | |
| 56 client_->ReclaimResources(resources); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 std::copy(resources.begin(), resources.end(), | |
| 61 std::back_inserter(surface_returned_resources_)); | |
| 62 } | |
| 63 | |
| 64 void CompositorFrameSink::WillDrawSurface(const cc::LocalFrameId& id, | |
| 65 const gfx::Rect& damage_rect) { | |
| 66 if (client_) | |
| 67 client_->WillDrawSurface(); | |
| 68 } | |
| 69 | |
| 70 void CompositorFrameSink::SetBeginFrameSource( | |
| 71 cc::BeginFrameSource* begin_frame_source) { | |
| 72 if (begin_frame_source_ && added_frame_observer_) { | |
| 73 begin_frame_source_->RemoveObserver(this); | |
| 74 added_frame_observer_ = false; | |
| 75 } | |
| 76 begin_frame_source_ = begin_frame_source; | |
| 77 UpdateNeedsBeginFrameInternal(); | |
| 78 } | |
| 79 | |
| 80 //////////////////////////////////////////////////////////////////////////////// | |
| 81 // cc::mojom::MojoCompositorFrameSink overrides: | |
| 82 | |
| 83 void CompositorFrameSink::SetNeedsBeginFrame(bool needs_begin_frame) { | |
| 84 needs_begin_frame_ = needs_begin_frame; | |
| 85 UpdateNeedsBeginFrameInternal(); | |
| 86 } | |
| 87 | |
| 88 void CompositorFrameSink::SubmitCompositorFrame( | |
| 89 const cc::LocalFrameId& local_frame_id, | |
| 90 cc::CompositorFrame frame) { | |
| 91 ++ack_pending_count_; | |
| 92 surface_factory_.SubmitCompositorFrame( | |
| 93 local_frame_id, std::move(frame), | |
| 94 base::Bind(&CompositorFrameSink::DidReceiveCompositorFrameAck, | |
| 95 base::Unretained(this))); | |
| 96 } | |
| 97 | |
| 98 void CompositorFrameSink::EvictFrame() { | |
| 99 surface_factory_.EvictSurface(); | |
| 100 } | |
| 101 | |
| 102 //////////////////////////////////////////////////////////////////////////////// | |
| 103 // cc::BeginFrameObserver overrides: | |
| 104 | |
| 105 void CompositorFrameSink::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
| 106 UpdateNeedsBeginFrameInternal(); | |
| 107 last_begin_frame_args_ = args; | |
| 108 if (client_) | |
| 109 client_->OnBeginFrame(args); | |
| 110 } | |
| 111 | |
| 112 const cc::BeginFrameArgs& CompositorFrameSink::LastUsedBeginFrameArgs() const { | |
| 113 return last_begin_frame_args_; | |
| 114 } | |
| 115 | |
| 116 void CompositorFrameSink::OnBeginFrameSourcePausedChanged(bool paused) {} | |
| 117 | |
| 118 //////////////////////////////////////////////////////////////////////////////// | |
| 119 // ExoComopositorFrameSink, private: | |
| 120 | |
| 121 void CompositorFrameSink::UpdateNeedsBeginFrameInternal() { | |
| 122 if (!begin_frame_source_) | |
| 123 return; | |
| 124 | |
| 125 if (needs_begin_frame_ == added_frame_observer_) | |
| 126 return; | |
| 127 | |
| 128 added_frame_observer_ = needs_begin_frame_; | |
| 129 if (needs_begin_frame_) | |
| 130 begin_frame_source_->AddObserver(this); | |
| 131 else | |
| 132 begin_frame_source_->RemoveObserver(this); | |
| 133 } | |
| 134 | |
| 135 void CompositorFrameSink::DidReceiveCompositorFrameAck() { | |
| 136 if (!client_) | |
| 137 return; | |
| 138 | |
| 139 client_->DidReceiveCompositorFrameAck(); | |
| 140 DCHECK_GT(ack_pending_count_, 0); | |
| 141 if (!surface_returned_resources_.empty()) { | |
| 142 client_->ReclaimResources(surface_returned_resources_); | |
| 143 surface_returned_resources_.clear(); | |
| 144 } | |
| 145 ack_pending_count_--; | |
| 146 } | |
| 147 | |
| 148 } // namespace exo | |
| OLD | NEW |