| 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 "components/mus/ws/server_view_surface.h" | 5 #include "components/mus/ws/server_view_surface.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/quads/shared_quad_state.h" | 8 #include "cc/quads/shared_quad_state.h" |
| 9 #include "cc/quads/surface_draw_quad.h" | 9 #include "cc/quads/surface_draw_quad.h" |
| 10 #include "components/mus/surfaces/surfaces_state.h" | 10 #include "components/mus/surfaces/surfaces_state.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 ServerViewSurface::~ServerViewSurface() { | 35 ServerViewSurface::~ServerViewSurface() { |
| 36 // SurfaceFactory's destructor will attempt to return resources which will | 36 // SurfaceFactory's destructor will attempt to return resources which will |
| 37 // call back into here and access |client_| so we should destroy | 37 // call back into here and access |client_| so we should destroy |
| 38 // |surface_factory_|'s resources early on. | 38 // |surface_factory_|'s resources early on. |
| 39 surface_factory_.DestroyAll(); | 39 surface_factory_.DestroyAll(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ServerViewSurface::Bind(mojo::InterfaceRequest<Surface> request, | 42 void ServerViewSurface::Bind(mojo::InterfaceRequest<Surface> request, |
| 43 mojo::SurfaceClientPtr client) { | 43 mojom::SurfaceClientPtr client) { |
| 44 if (binding_.is_bound()) { | 44 if (binding_.is_bound()) { |
| 45 // Destroy frame surfaces submitted by the old client before replacing | 45 // Destroy frame surfaces submitted by the old client before replacing |
| 46 // client_, so those surfaces will be returned to the old client. | 46 // client_, so those surfaces will be returned to the old client. |
| 47 surface_factory_.DestroyAll(); | 47 surface_factory_.DestroyAll(); |
| 48 binding_.Close(); | 48 binding_.Close(); |
| 49 } | 49 } |
| 50 binding_.Bind(request.Pass()); | 50 binding_.Bind(request.Pass()); |
| 51 client_ = client.Pass(); | 51 client_ = client.Pass(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ServerViewSurface::SubmitCompositorFrame( | 54 void ServerViewSurface::SubmitCompositorFrame( |
| 55 mojo::CompositorFramePtr frame, | 55 mojom::CompositorFramePtr frame, |
| 56 const SubmitCompositorFrameCallback& callback) { | 56 const SubmitCompositorFrameCallback& callback) { |
| 57 gfx::Size frame_size = frame->passes[0]->output_rect.To<gfx::Rect>().size(); | 57 gfx::Size frame_size = frame->passes[0]->output_rect.To<gfx::Rect>().size(); |
| 58 if (!surface_id_.is_null()) { | 58 if (!surface_id_.is_null()) { |
| 59 // If the size of the CompostiorFrame has changed then destroy the existing | 59 // If the size of the CompostiorFrame has changed then destroy the existing |
| 60 // Surface and create a new one of the appropriate size. | 60 // Surface and create a new one of the appropriate size. |
| 61 if (frame_size != last_submitted_frame_size_) { | 61 if (frame_size != last_submitted_frame_size_) { |
| 62 surface_factory_.Destroy(surface_id_); | 62 surface_factory_.Destroy(surface_id_); |
| 63 surface_id_ = surface_id_allocator_.GenerateId(); | 63 surface_id_ = surface_id_allocator_.GenerateId(); |
| 64 surface_factory_.Create(surface_id_); | 64 surface_factory_.Create(surface_id_); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 surface_factory_.SubmitCompositorFrame(surface_id_, | 67 surface_factory_.SubmitCompositorFrame(surface_id_, |
| 68 ConvertCompositorFrame(frame), | 68 ConvertCompositorFrame(frame), |
| 69 base::Bind(&CallCallback, callback)); | 69 base::Bind(&CallCallback, callback)); |
| 70 view_->delegate()->GetSurfacesState()->scheduler()->SetNeedsDraw(); | 70 view_->delegate()->GetSurfacesState()->scheduler()->SetNeedsDraw(); |
| 71 view_->delegate()->OnScheduleViewPaint(view_); | 71 view_->delegate()->OnScheduleViewPaint(view_); |
| 72 last_submitted_frame_size_ = frame_size; | 72 last_submitted_frame_size_ = frame_size; |
| 73 } | 73 } |
| 74 | 74 |
| 75 scoped_ptr<cc::CompositorFrame> ServerViewSurface::ConvertCompositorFrame( | 75 scoped_ptr<cc::CompositorFrame> ServerViewSurface::ConvertCompositorFrame( |
| 76 const mojo::CompositorFramePtr& input) { | 76 const mojom::CompositorFramePtr& input) { |
| 77 referenced_view_ids_.clear(); | 77 referenced_view_ids_.clear(); |
| 78 return ConvertToCompositorFrame(input, this); | 78 return ConvertToCompositorFrame(input, this); |
| 79 } | 79 } |
| 80 | 80 |
| 81 bool ServerViewSurface::ConvertSurfaceDrawQuad( | 81 bool ServerViewSurface::ConvertSurfaceDrawQuad( |
| 82 const mojo::QuadPtr& input, | 82 const mojom::QuadPtr& input, |
| 83 const mojo::CompositorFrameMetadataPtr& metadata, | 83 const mojom::CompositorFrameMetadataPtr& metadata, |
| 84 cc::SharedQuadState* sqs, | 84 cc::SharedQuadState* sqs, |
| 85 cc::RenderPass* render_pass) { | 85 cc::RenderPass* render_pass) { |
| 86 Id id = static_cast<Id>( | 86 Id id = static_cast<Id>( |
| 87 input->surface_quad_state->surface.To<cc::SurfaceId>().id); | 87 input->surface_quad_state->surface.To<cc::SurfaceId>().id); |
| 88 ViewId view_id = ViewIdFromTransportId(id); | 88 ViewId view_id = ViewIdFromTransportId(id); |
| 89 ServerView* view = view_->GetChildView(view_id); | 89 ServerView* view = view_->GetChildView(view_id); |
| 90 if (!view) | 90 if (!view) |
| 91 return false; | 91 return false; |
| 92 | 92 |
| 93 referenced_view_ids_.insert(view_id); | 93 referenced_view_ids_.insert(view_id); |
| 94 cc::SurfaceDrawQuad* surface_quad = | 94 cc::SurfaceDrawQuad* surface_quad = |
| 95 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); | 95 render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); |
| 96 surface_quad->SetAll(sqs, input->rect.To<gfx::Rect>(), | 96 surface_quad->SetAll(sqs, input->rect.To<gfx::Rect>(), |
| 97 input->opaque_rect.To<gfx::Rect>(), | 97 input->opaque_rect.To<gfx::Rect>(), |
| 98 input->visible_rect.To<gfx::Rect>(), | 98 input->visible_rect.To<gfx::Rect>(), |
| 99 input->needs_blending, view->GetOrCreateSurface()->id()); | 99 input->needs_blending, view->GetOrCreateSurface()->id()); |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void ServerViewSurface::ReturnResources( | 103 void ServerViewSurface::ReturnResources( |
| 104 const cc::ReturnedResourceArray& resources) { | 104 const cc::ReturnedResourceArray& resources) { |
| 105 if (!client_) | 105 if (!client_) |
| 106 return; | 106 return; |
| 107 client_->ReturnResources( | 107 client_->ReturnResources( |
| 108 mojo::Array<mojo::ReturnedResourcePtr>::From(resources)); | 108 mojo::Array<mojom::ReturnedResourcePtr>::From(resources)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 } // namespace mus | 111 } // namespace mus |
| OLD | NEW |