| 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 support_ = cc::CompositorFrameSinkSupport::Create( |
| 24 this, surface_manager, frame_sink_id, false /* is_root */, |
| 25 true /* handles_frame_sink_id_invalidation */, |
| 26 true /* needs_sync_points */); |
| 27 } |
| 28 |
| 29 CompositorFrameSinkLocal::~CompositorFrameSinkLocal() {} |
| 30 |
| 31 bool CompositorFrameSinkLocal::BindToClient( |
| 32 cc::CompositorFrameSinkClient* client) { |
| 33 if (!cc::CompositorFrameSink::BindToClient(client)) |
| 34 return false; |
| 35 DCHECK(!thread_checker_); |
| 36 thread_checker_.reset(new base::ThreadChecker()); |
| 37 |
| 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 thread_checker_.reset(); |
| 51 cc::CompositorFrameSink::DetachFromClient(); |
| 52 } |
| 53 |
| 54 void CompositorFrameSinkLocal::SubmitCompositorFrame( |
| 55 cc::CompositorFrame frame) { |
| 56 DCHECK(thread_checker_); |
| 57 DCHECK(thread_checker_->CalledOnValidThread()); |
| 58 |
| 59 cc::LocalSurfaceId old_local_surface_id = local_surface_id_; |
| 60 if (!frame.render_pass_list.empty()) { |
| 61 const auto& frame_size = frame.render_pass_list.back()->output_rect.size(); |
| 62 if (frame_size != last_submitted_frame_size_ || |
| 63 !local_surface_id_.is_valid()) { |
| 64 last_submitted_frame_size_ = frame_size; |
| 65 local_surface_id_ = id_allocator_.GenerateId(); |
| 66 } |
| 67 } |
| 68 support_->SubmitCompositorFrame(local_surface_id_, std::move(frame)); |
| 69 |
| 70 if (local_surface_id_ != old_local_surface_id) { |
| 71 surface_changed_callback_.Run( |
| 72 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 73 last_submitted_frame_size_); |
| 74 } |
| 75 } |
| 76 |
| 77 void CompositorFrameSinkLocal::EvictFrame() { |
| 78 support_->EvictFrame(); |
| 79 } |
| 80 |
| 81 cc::SurfaceId CompositorFrameSinkLocal::GetSurfaceId() const { |
| 82 return cc::SurfaceId(frame_sink_id_, local_surface_id_); |
| 83 } |
| 84 |
| 85 void CompositorFrameSinkLocal::DidReceiveCompositorFrameAck( |
| 86 const cc::ReturnedResourceArray& resources) { |
| 87 DCHECK(thread_checker_); |
| 88 DCHECK(thread_checker_->CalledOnValidThread()); |
| 89 if (!client_) |
| 90 return; |
| 91 client_->ReclaimResources(resources); |
| 92 client_->DidReceiveCompositorFrameAck(); |
| 93 } |
| 94 |
| 95 void CompositorFrameSinkLocal::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 96 DCHECK(thread_checker_); |
| 97 DCHECK(thread_checker_->CalledOnValidThread()); |
| 98 begin_frame_source_->OnBeginFrame(args); |
| 99 } |
| 100 |
| 101 void CompositorFrameSinkLocal::ReclaimResources( |
| 102 const cc::ReturnedResourceArray& resources) { |
| 103 DCHECK(thread_checker_); |
| 104 DCHECK(thread_checker_->CalledOnValidThread()); |
| 105 if (!client_) |
| 106 return; |
| 107 client_->ReclaimResources(resources); |
| 108 } |
| 109 |
| 110 void CompositorFrameSinkLocal::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 111 DCHECK(thread_checker_); |
| 112 DCHECK(thread_checker_->CalledOnValidThread()); |
| 113 support_->SetNeedsBeginFrame(needs_begin_frames); |
| 114 } |
| 115 |
| 116 void CompositorFrameSinkLocal::OnDidFinishFrame(const cc::BeginFrameAck& ack) { |
| 117 DCHECK(thread_checker_); |
| 118 DCHECK(thread_checker_->CalledOnValidThread()); |
| 119 // If there was damage, the submitted CompositorFrame includes the ack. |
| 120 if (!ack.has_damage) |
| 121 support_->BeginFrameDidNotSwap(ack); |
| 122 } |
| 123 |
| 124 } // namespace aura |
| OLD | NEW |