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()); | |
sky
2017/05/08 22:36:43
Use MakeUnique.
Peng
2017/05/09 17:26:57
Done.
| |
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 void CompositorFrameSinkLocal::DidReceiveCompositorFrameAck( | |
82 const cc::ReturnedResourceArray& resources) { | |
83 DCHECK(thread_checker_); | |
84 DCHECK(thread_checker_->CalledOnValidThread()); | |
85 if (!client_) | |
86 return; | |
87 client_->ReclaimResources(resources); | |
88 client_->DidReceiveCompositorFrameAck(); | |
89 } | |
90 | |
91 void CompositorFrameSinkLocal::OnBeginFrame(const cc::BeginFrameArgs& args) { | |
92 DCHECK(thread_checker_); | |
93 DCHECK(thread_checker_->CalledOnValidThread()); | |
94 begin_frame_source_->OnBeginFrame(args); | |
95 } | |
96 | |
97 void CompositorFrameSinkLocal::ReclaimResources( | |
98 const cc::ReturnedResourceArray& resources) { | |
99 DCHECK(thread_checker_); | |
100 DCHECK(thread_checker_->CalledOnValidThread()); | |
101 if (!client_) | |
102 return; | |
103 client_->ReclaimResources(resources); | |
104 } | |
105 | |
106 void CompositorFrameSinkLocal::OnNeedsBeginFrames(bool needs_begin_frames) { | |
107 DCHECK(thread_checker_); | |
108 DCHECK(thread_checker_->CalledOnValidThread()); | |
109 support_->SetNeedsBeginFrame(needs_begin_frames); | |
110 } | |
111 | |
112 void CompositorFrameSinkLocal::OnDidFinishFrame(const cc::BeginFrameAck& ack) { | |
113 DCHECK(thread_checker_); | |
114 DCHECK(thread_checker_->CalledOnValidThread()); | |
115 // If there was damage, the submitted CompositorFrame includes the ack. | |
116 if (!ack.has_damage) | |
117 support_->BeginFrameDidNotSwap(ack); | |
118 } | |
119 | |
120 } // namespace aura | |
OLD | NEW |