OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 "ui/aura/local/compositor_frame_sink_local.h" |
| 6 |
| 7 #include "cc/output/compositor_frame_sink_client.h" |
| 8 #include "cc/surfaces/compositor_frame_sink_support.h" |
| 9 #include "ui/aura/client/cursor_client.h" |
| 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/window.h" |
| 12 #include "ui/aura/window_delegate.h" |
| 13 #include "ui/display/display.h" |
| 14 #include "ui/display/screen.h" |
| 15 |
| 16 namespace aura { |
| 17 |
| 18 CompositorFrameSinkLocal::CompositorFrameSinkLocal( |
| 19 const cc::FrameSinkId& frame_sink_id, |
| 20 cc::SurfaceManager* surface_manager) |
| 21 : cc::CompositorFrameSink(nullptr, nullptr, nullptr, nullptr), |
| 22 frame_sink_id_(frame_sink_id), |
| 23 surface_manager_(surface_manager) {} |
| 24 |
| 25 CompositorFrameSinkLocal::~CompositorFrameSinkLocal() {} |
| 26 |
| 27 bool CompositorFrameSinkLocal::BindToClient( |
| 28 cc::CompositorFrameSinkClient* client) { |
| 29 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 30 return false; |
| 31 DCHECK(!thread_checker_); |
| 32 thread_checker_ = base::MakeUnique<base::ThreadChecker>(); |
| 33 |
| 34 support_ = cc::CompositorFrameSinkSupport::Create( |
| 35 this, surface_manager_, frame_sink_id_, false /* is_root */, |
| 36 true /* handles_frame_sink_id_invalidation */, |
| 37 true /* needs_sync_points */); |
| 38 begin_frame_source_ = base::MakeUnique<cc::ExternalBeginFrameSource>(this); |
| 39 client->SetBeginFrameSource(begin_frame_source_.get()); |
| 40 return true; |
| 41 } |
| 42 |
| 43 void CompositorFrameSinkLocal::SetSurfaceChangedCallback( |
| 44 const SurfaceChangedCallback& callback) { |
| 45 DCHECK(!surface_changed_callback_); |
| 46 surface_changed_callback_ = callback; |
| 47 } |
| 48 |
| 49 void CompositorFrameSinkLocal::DetachFromClient() { |
| 50 DCHECK(thread_checker_); |
| 51 DCHECK(thread_checker_->CalledOnValidThread()); |
| 52 client_->SetBeginFrameSource(nullptr); |
| 53 begin_frame_source_.reset(); |
| 54 support_->EvictFrame(); |
| 55 support_.reset(); |
| 56 thread_checker_.reset(); |
| 57 cc::CompositorFrameSink::DetachFromClient(); |
| 58 } |
| 59 |
| 60 void CompositorFrameSinkLocal::SubmitCompositorFrame( |
| 61 cc::CompositorFrame frame) { |
| 62 DCHECK(thread_checker_); |
| 63 DCHECK(thread_checker_->CalledOnValidThread()); |
| 64 |
| 65 cc::LocalSurfaceId old_local_surface_id = local_surface_id_; |
| 66 if (!frame.render_pass_list.empty()) { |
| 67 const auto& frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 68 if (frame_size != last_submitted_frame_size_ || |
| 69 !local_surface_id_.is_valid()) { |
| 70 last_submitted_frame_size_ = frame_size; |
| 71 local_surface_id_ = id_allocator_.GenerateId(); |
| 72 } |
| 73 } |
| 74 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 75 |
| 76 if (local_surface_id_ != old_local_surface_id) { |
| 77 surface_changed_callback_.Run( |
| 78 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 79 last_submitted_frame_size_); |
| 80 } |
| 81 } |
| 82 |
| 83 void CompositorFrameSinkLocal::DidReceiveCompositorFrameAck( |
| 84 const cc::ReturnedResourceArray& resources) { |
| 85 DCHECK(thread_checker_); |
| 86 DCHECK(thread_checker_->CalledOnValidThread()); |
| 87 if (!client_) |
| 88 return; |
| 89 client_->ReclaimResources(resources); |
| 90 client_->DidReceiveCompositorFrameAck(); |
| 91 } |
| 92 |
| 93 void CompositorFrameSinkLocal::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 94 DCHECK(thread_checker_); |
| 95 DCHECK(thread_checker_->CalledOnValidThread()); |
| 96 begin_frame_source_->OnBeginFrame(args); |
| 97 } |
| 98 |
| 99 void CompositorFrameSinkLocal::ReclaimResources( |
| 100 const cc::ReturnedResourceArray& resources) { |
| 101 DCHECK(thread_checker_); |
| 102 DCHECK(thread_checker_->CalledOnValidThread()); |
| 103 if (!client_) |
| 104 return; |
| 105 client_->ReclaimResources(resources); |
| 106 } |
| 107 |
| 108 void CompositorFrameSinkLocal::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 109 DCHECK(thread_checker_); |
| 110 DCHECK(thread_checker_->CalledOnValidThread()); |
| 111 support_->SetNeedsBeginFrame(needs_begin_frames); |
| 112 } |
| 113 |
| 114 void CompositorFrameSinkLocal::OnDidFinishFrame(const cc::BeginFrameAck& ack) { |
| 115 DCHECK(thread_checker_); |
| 116 DCHECK(thread_checker_->CalledOnValidThread()); |
| 117 // If there was damage, the submitted CompositorFrame includes the ack. |
| 118 if (!ack.has_damage) |
| 119 support_->BeginFrameDidNotSwap(ack); |
| 120 } |
| 121 |
| 122 } // namespace aura |
OLD | NEW |