| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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 "services/ui/ws/server_window_compositor_frame_sink.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/quads/shared_quad_state.h" |
| 11 #include "cc/quads/surface_draw_quad.h" |
| 12 #include "services/ui/surfaces/display_compositor.h" |
| 13 #include "services/ui/ws/server_window.h" |
| 14 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 15 #include "services/ui/ws/server_window_delegate.h" |
| 16 |
| 17 namespace ui { |
| 18 namespace ws { |
| 19 |
| 20 ServerWindowCompositorFrameSink::ServerWindowCompositorFrameSink( |
| 21 ServerWindowCompositorFrameSinkManager* manager, |
| 22 const cc::FrameSinkId& frame_sink_id, |
| 23 cc::mojom::MojoCompositorFrameSinkRequest request, |
| 24 cc::mojom::MojoCompositorFrameSinkClientPtr client) |
| 25 : frame_sink_id_(frame_sink_id), |
| 26 manager_(manager), |
| 27 surface_factory_(frame_sink_id_, |
| 28 manager_->GetCompositorFrameSinkManager(), |
| 29 this), |
| 30 client_(std::move(client)), |
| 31 binding_(this, std::move(request)) { |
| 32 cc::SurfaceManager* surface_manager = |
| 33 manager_->GetCompositorFrameSinkManager(); |
| 34 surface_manager->RegisterFrameSinkId(frame_sink_id_); |
| 35 surface_manager->RegisterSurfaceFactoryClient(frame_sink_id_, this); |
| 36 } |
| 37 |
| 38 ServerWindowCompositorFrameSink::~ServerWindowCompositorFrameSink() { |
| 39 // SurfaceFactory's destructor will attempt to return resources which will |
| 40 // call back into here and access |client_| so we should destroy |
| 41 // |surface_factory_|'s resources early on. |
| 42 surface_factory_.DestroyAll(); |
| 43 cc::SurfaceManager* surface_manager = |
| 44 manager_->GetCompositorFrameSinkManager(); |
| 45 surface_manager->UnregisterSurfaceFactoryClient(frame_sink_id_); |
| 46 surface_manager->InvalidateFrameSinkId(frame_sink_id_); |
| 47 } |
| 48 |
| 49 void ServerWindowCompositorFrameSink::SetNeedsBeginFrame( |
| 50 bool needs_begin_frame) { |
| 51 // TODO(fsamuel): Implement this. |
| 52 } |
| 53 |
| 54 void ServerWindowCompositorFrameSink::SubmitCompositorFrame( |
| 55 cc::CompositorFrame frame) { |
| 56 gfx::Size frame_size = |
| 57 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); |
| 58 // If the size of the CompostiorFrame has changed then destroy the existing |
| 59 // Surface and create a new one of the appropriate size. |
| 60 if (local_frame_id_.is_null() || frame_size != last_submitted_frame_size_) { |
| 61 if (!local_frame_id_.is_null()) |
| 62 surface_factory_.Destroy(local_frame_id_); |
| 63 local_frame_id_ = surface_id_allocator_.GenerateId(); |
| 64 surface_factory_.Create(local_frame_id_); |
| 65 } |
| 66 surface_factory_.SubmitCompositorFrame( |
| 67 local_frame_id_, std::move(frame), |
| 68 base::Bind(&ServerWindowCompositorFrameSink::DidReceiveCompositorFrameAck, |
| 69 base::Unretained(this))); |
| 70 last_submitted_frame_size_ = frame_size; |
| 71 ServerWindow* window = manager_->window_; |
| 72 window->delegate()->OnScheduleWindowPaint(window); |
| 73 } |
| 74 |
| 75 void ServerWindowCompositorFrameSink::DidReceiveCompositorFrameAck() { |
| 76 if (!client_ || !base::MessageLoop::current()) |
| 77 return; |
| 78 client_->DidReceiveCompositorFrameAck(); |
| 79 } |
| 80 |
| 81 void ServerWindowCompositorFrameSink::ReturnResources( |
| 82 const cc::ReturnedResourceArray& resources) { |
| 83 if (!client_ || !base::MessageLoop::current()) |
| 84 return; |
| 85 client_->ReclaimResources(resources); |
| 86 } |
| 87 |
| 88 void ServerWindowCompositorFrameSink::SetBeginFrameSource( |
| 89 cc::BeginFrameSource* begin_frame_source) { |
| 90 // TODO(tansell): Implement this. |
| 91 } |
| 92 |
| 93 } // namespace ws |
| 94 } // namespace ui |
| OLD | NEW |