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 "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/quads/shared_quad_state.h" | 9 #include "cc/quads/shared_quad_state.h" |
10 #include "cc/quads/surface_draw_quad.h" | 10 #include "cc/quads/surface_draw_quad.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 ServerWindowSurface::ServerWindowSurface( | 26 ServerWindowSurface::ServerWindowSurface( |
27 ServerWindowSurfaceManager* manager, | 27 ServerWindowSurfaceManager* manager, |
28 mojo::InterfaceRequest<Surface> request, | 28 mojo::InterfaceRequest<Surface> request, |
29 mojom::SurfaceClientPtr client) | 29 mojom::SurfaceClientPtr client) |
30 : manager_(manager), | 30 : manager_(manager), |
31 surface_id_(manager->GenerateId()), | 31 surface_id_(manager->GenerateId()), |
32 surface_factory_(manager_->GetSurfaceManager(), this), | |
33 client_(std::move(client)), | 32 client_(std::move(client)), |
34 binding_(this, std::move(request)), | 33 binding_(this, std::move(request)) { |
35 registered_surface_factory_client_(false) { | 34 surface_factory_.reset(new cc::SurfaceFactory( |
36 surface_factory_.Create(surface_id_); | 35 manager_->client_id(), manager_->GetSurfaceManager(), this)); |
| 36 // TODO(fsamuel): We shouldn't do this. |
| 37 surface_factory_->Create(surface_id_); |
37 } | 38 } |
38 | 39 |
39 ServerWindowSurface::~ServerWindowSurface() { | 40 ServerWindowSurface::~ServerWindowSurface() { |
40 // SurfaceFactory's destructor will attempt to return resources which will | 41 // SurfaceFactory's destructor will attempt to return resources which will |
41 // call back into here and access |client_| so we should destroy | 42 // call back into here and access |client_| so we should destroy |
42 // |surface_factory_|'s resources early on. | 43 // |surface_factory_|'s resources early on. |
43 surface_factory_.DestroyAll(); | 44 surface_factory_.reset(); |
44 | |
45 if (registered_surface_factory_client_) { | |
46 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | |
47 surface_manager->UnregisterSurfaceFactoryClient(manager_->client_id()); | |
48 } | |
49 } | 45 } |
50 | 46 |
51 void ServerWindowSurface::SubmitCompositorFrame( | 47 void ServerWindowSurface::SubmitCompositorFrame( |
52 cc::CompositorFrame frame, | 48 cc::CompositorFrame frame, |
53 const SubmitCompositorFrameCallback& callback) { | 49 const SubmitCompositorFrameCallback& callback) { |
54 gfx::Size frame_size = | 50 gfx::Size frame_size = |
55 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); | 51 frame.delegated_frame_data->render_pass_list[0]->output_rect.size(); |
56 if (!surface_id_.is_null()) { | 52 if (!surface_id_.is_null()) { |
57 // If the size of the CompostiorFrame has changed then destroy the existing | 53 // If the size of the CompostiorFrame has changed then destroy the existing |
58 // Surface and create a new one of the appropriate size. | 54 // Surface and create a new one of the appropriate size. |
59 if (frame_size != last_submitted_frame_size_) { | 55 if (frame_size != last_submitted_frame_size_) { |
60 // Rendering of the topmost frame happens in two phases. First the frame | 56 // Rendering of the topmost frame happens in two phases. First the frame |
61 // is generated and submitted, and a later date it is actually drawn. | 57 // is generated and submitted, and a later date it is actually drawn. |
62 // During the time the frame is generated and drawn we can't destroy the | 58 // During the time the frame is generated and drawn we can't destroy the |
63 // surface, otherwise when drawn you get an empty surface. To deal with | 59 // surface, otherwise when drawn you get an empty surface. To deal with |
64 // this we schedule destruction via the delegate. The delegate will call | 60 // this we schedule destruction via the delegate. The delegate will call |
65 // us back when we're not waiting on a frame to be drawn (which may be | 61 // us back when we're not waiting on a frame to be drawn (which may be |
66 // synchronously). | 62 // synchronously). |
67 surfaces_scheduled_for_destruction_.insert(surface_id_); | 63 surfaces_scheduled_for_destruction_.insert(surface_id_); |
68 window()->delegate()->ScheduleSurfaceDestruction(window()); | 64 window()->delegate()->ScheduleSurfaceDestruction(window()); |
69 surface_id_ = manager_->GenerateId(); | 65 surface_id_ = manager_->GenerateId(); |
70 surface_factory_.Create(surface_id_); | 66 surface_factory_->Create(surface_id_); |
71 } | 67 } |
72 } | 68 } |
73 surface_factory_.SubmitCompositorFrame(surface_id_, std::move(frame), | 69 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
74 base::Bind(&CallCallback, callback)); | 70 base::Bind(&CallCallback, callback)); |
75 last_submitted_frame_size_ = frame_size; | 71 last_submitted_frame_size_ = frame_size; |
76 window()->delegate()->OnScheduleWindowPaint(window()); | 72 window()->delegate()->OnScheduleWindowPaint(window()); |
77 } | 73 } |
78 | 74 |
79 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { | 75 void ServerWindowSurface::DestroySurfacesScheduledForDestruction() { |
80 std::set<cc::SurfaceId> surfaces; | 76 std::set<cc::SurfaceId> surfaces; |
81 surfaces.swap(surfaces_scheduled_for_destruction_); | 77 surfaces.swap(surfaces_scheduled_for_destruction_); |
82 for (auto& id : surfaces) | 78 for (auto& id : surfaces) |
83 surface_factory_.Destroy(id); | 79 surface_factory_->Destroy(id); |
84 } | |
85 | |
86 void ServerWindowSurface::RegisterForBeginFrames() { | |
87 DCHECK(!registered_surface_factory_client_); | |
88 registered_surface_factory_client_ = true; | |
89 cc::SurfaceManager* surface_manager = manager_->GetSurfaceManager(); | |
90 surface_manager->RegisterSurfaceFactoryClient(manager_->client_id(), this); | |
91 } | 80 } |
92 | 81 |
93 ServerWindow* ServerWindowSurface::window() { | 82 ServerWindow* ServerWindowSurface::window() { |
94 return manager_->window(); | 83 return manager_->window(); |
95 } | 84 } |
96 | 85 |
97 void ServerWindowSurface::ReturnResources( | 86 void ServerWindowSurface::ReturnResources( |
98 const cc::ReturnedResourceArray& resources) { | 87 const cc::ReturnedResourceArray& resources) { |
99 if (!client_ || !base::MessageLoop::current()) | 88 if (!client_ || !base::MessageLoop::current()) |
100 return; | 89 return; |
101 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); | 90 client_->ReturnResources(mojo::Array<cc::ReturnedResource>::From(resources)); |
102 } | 91 } |
103 | 92 |
104 void ServerWindowSurface::SetBeginFrameSource( | 93 void ServerWindowSurface::SetBeginFrameSource( |
105 cc::BeginFrameSource* begin_frame_source) { | 94 cc::BeginFrameSource* begin_frame_source) { |
106 // TODO(tansell): Implement this. | 95 // TODO(tansell): Implement this. |
107 } | 96 } |
108 | 97 |
109 } // namespace ws | 98 } // namespace ws |
110 } // namespace ui | 99 } // namespace ui |
OLD | NEW |