| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "services/ui/ws/server_window_surface.h" | 5 #include "services/ui/ws/server_window_surface.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
| 10 #include "cc/quads/shared_quad_state.h" | 10 #include "cc/quads/shared_quad_state.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 void ServerWindowSurface::SubmitCompositorFrame( | 45 void ServerWindowSurface::SubmitCompositorFrame( |
| 46 cc::CompositorFrame frame, | 46 cc::CompositorFrame frame, |
| 47 const SubmitCompositorFrameCallback& callback) { | 47 const SubmitCompositorFrameCallback& callback) { |
| 48 gfx::Size frame_size = | 48 gfx::Size frame_size = |
| 49 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); | 49 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); |
| 50 // If the size of the CompostiorFrame has changed then destroy the existing | 50 // If the size of the CompostiorFrame has changed then destroy the existing |
| 51 // Surface and create a new one of the appropriate size. | 51 // Surface and create a new one of the appropriate size. |
| 52 if (local_frame_id_.is_null() || frame_size != last_submitted_frame_size_) { | 52 if (local_frame_id_.is_null() || frame_size != last_submitted_frame_size_) { |
| 53 // Rendering of the topmost frame happens in two phases. First the frame | 53 if (!local_frame_id_.is_null()) |
| 54 // is generated and submitted, and a later date it is actually drawn. | 54 surface_factory_.Destroy(local_frame_id_); |
| 55 // During the time the frame is generated and drawn we can't destroy the | |
| 56 // surface, otherwise when drawn you get an empty surface. To deal with | |
| 57 // this we schedule destruction via the delegate. The delegate will call | |
| 58 // us back when we're not waiting on a frame to be drawn (which may be | |
| 59 // synchronously). | |
| 60 if (!local_frame_id_.is_null()) { | |
| 61 surfaces_scheduled_for_destruction_.insert(local_frame_id_); | |
| 62 window()->delegate()->ScheduleSurfaceDestruction(window()); | |
| 63 } | |
| 64 local_frame_id_ = surface_id_allocator_.GenerateId(); | 55 local_frame_id_ = surface_id_allocator_.GenerateId(); |
| 65 surface_factory_.Create(local_frame_id_); | 56 surface_factory_.Create(local_frame_id_); |
| 66 } | 57 } |
| 67 may_contain_video_ = frame.metadata.may_contain_video; | 58 may_contain_video_ = frame.metadata.may_contain_video; |
| 68 surface_factory_.SubmitCompositorFrame(local_frame_id_, std::move(frame), | 59 surface_factory_.SubmitCompositorFrame(local_frame_id_, std::move(frame), |
| 69 callback); | 60 callback); |
| 70 last_submitted_frame_size_ = frame_size; | 61 last_submitted_frame_size_ = frame_size; |
| 71 window()->delegate()->OnScheduleWindowPaint(window()); | 62 window()->delegate()->OnScheduleWindowPaint(window()); |
| 72 } | 63 } |
| 73 | 64 |
| 74 cc::SurfaceId ServerWindowSurface::GetSurfaceId() const { | 65 cc::SurfaceId ServerWindowSurface::GetSurfaceId() const { |
| 66 if (local_frame_id_.is_null()) |
| 67 return cc::SurfaceId(); |
| 75 return cc::SurfaceId(frame_sink_id_, local_frame_id_); | 68 return cc::SurfaceId(frame_sink_id_, local_frame_id_); |
| 76 } | 69 } |
| 77 | 70 |
| 78 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { | |
| 79 std::set<cc::LocalFrameId> surfaces; | |
| 80 surfaces.swap(surfaces_scheduled_for_destruction_); | |
| 81 for (auto& id : surfaces) | |
| 82 surface_factory_.Destroy(id); | |
| 83 } | |
| 84 | |
| 85 ServerWindow* ServerWindowSurface::window() { | 71 ServerWindow* ServerWindowSurface::window() { |
| 86 return manager_->window(); | 72 return manager_->window(); |
| 87 } | 73 } |
| 88 | 74 |
| 89 void ServerWindowSurface::ReturnResources( | 75 void ServerWindowSurface::ReturnResources( |
| 90 const cc::ReturnedResourceArray& resources) { | 76 const cc::ReturnedResourceArray& resources) { |
| 91 if (!client_ || !base::MessageLoop::current()) | 77 if (!client_ || !base::MessageLoop::current()) |
| 92 return; | 78 return; |
| 93 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); | 79 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); |
| 94 } | 80 } |
| 95 | 81 |
| 96 void ServerWindowSurface::SetBeginFrameSource( | 82 void ServerWindowSurface::SetBeginFrameSource( |
| 97 cc::BeginFrameSource* begin_frame_source) { | 83 cc::BeginFrameSource* begin_frame_source) { |
| 98 // TODO(tansell): Implement this. | 84 // TODO(tansell): Implement this. |
| 99 } | 85 } |
| 100 | 86 |
| 101 } // namespace ws | 87 } // namespace ws |
| 102 } // namespace ui | 88 } // namespace ui |
| OLD | NEW |