| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/cc/output_surface_mojo.h" | 5 #include "mojo/cc/output_surface_mojo.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/compositor_frame_ack.h" | 9 #include "cc/output/compositor_frame_ack.h" |
| 10 #include "cc/output/output_surface_client.h" | 10 #include "cc/output/output_surface_client.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" | 11 #include "components/view_manager/public/cpp/view_surface.h" |
| 12 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 12 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 | 15 |
| 16 OutputSurfaceMojo::OutputSurfaceMojo( | 16 OutputSurfaceMojo::OutputSurfaceMojo( |
| 17 OutputSurfaceMojoClient* client, | |
| 18 const scoped_refptr<cc::ContextProvider>& context_provider, | 17 const scoped_refptr<cc::ContextProvider>& context_provider, |
| 19 ScopedMessagePipeHandle surface_handle) | 18 scoped_ptr<mojo::ViewSurface> surface) |
| 20 : cc::OutputSurface(context_provider), | 19 : cc::OutputSurface(context_provider), |
| 21 output_surface_mojo_client_(client), | 20 surface_(surface.Pass()) { |
| 22 surface_handle_(surface_handle.Pass()), | |
| 23 id_namespace_(0u), | |
| 24 local_id_(0u), | |
| 25 binding_(this) { | |
| 26 capabilities_.delegated_rendering = true; | 21 capabilities_.delegated_rendering = true; |
| 27 capabilities_.max_frames_pending = 1; | 22 capabilities_.max_frames_pending = 1; |
| 28 } | 23 } |
| 29 | 24 |
| 30 OutputSurfaceMojo::~OutputSurfaceMojo() { | 25 OutputSurfaceMojo::~OutputSurfaceMojo() { |
| 31 } | 26 } |
| 32 | 27 |
| 33 void OutputSurfaceMojo::SetIdNamespace(uint32_t id_namespace) { | |
| 34 id_namespace_ = id_namespace; | |
| 35 if (local_id_) { | |
| 36 cc::SurfaceId qualified_id(static_cast<uint64_t>(id_namespace_) << 32 | | |
| 37 local_id_); | |
| 38 output_surface_mojo_client_->DidCreateSurface(qualified_id); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient* client) { | 28 bool OutputSurfaceMojo::BindToClient(cc::OutputSurfaceClient* client) { |
| 43 surface_.Bind(InterfacePtrInfo<Surface>(surface_handle_.Pass(), 0u)); | 29 surface_->BindToThread(); |
| 44 surface_->GetIdNamespace( | 30 surface_->set_client(this); |
| 45 base::Bind(&OutputSurfaceMojo::SetIdNamespace, base::Unretained(this))); | |
| 46 | |
| 47 // Wire up mojo binding. | |
| 48 mojo::ResourceReturnerPtr returner_ptr; | |
| 49 binding_.Bind(mojo::GetProxy(&returner_ptr).Pass()); | |
| 50 surface_->SetResourceReturner(returner_ptr.Pass()); | |
| 51 | |
| 52 return cc::OutputSurface::BindToClient(client); | 31 return cc::OutputSurface::BindToClient(client); |
| 53 } | 32 } |
| 54 | 33 |
| 55 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame* frame) { | 34 void OutputSurfaceMojo::SwapBuffers(cc::CompositorFrame* frame) { |
| 56 gfx::Size frame_size = | 35 // TODO(fsamuel, rjkroege): We should probably throttle compositor frames. |
| 57 frame->delegated_frame_data->render_pass_list.back()->output_rect.size(); | 36 surface_->SubmitCompositorFrame(mojo::CompositorFrame::From(*frame)); |
| 58 if (frame_size != surface_size_) { | |
| 59 if (local_id_ != 0u) { | |
| 60 surface_->DestroySurface(local_id_); | |
| 61 } | |
| 62 local_id_++; | |
| 63 surface_->CreateSurface(local_id_); | |
| 64 if (id_namespace_) { | |
| 65 cc::SurfaceId qualified_id(static_cast<uint64_t>(id_namespace_) << 32 | | |
| 66 local_id_); | |
| 67 output_surface_mojo_client_->DidCreateSurface(qualified_id); | |
| 68 } | |
| 69 surface_size_ = frame_size; | |
| 70 } | |
| 71 | |
| 72 surface_->SubmitCompositorFrame(local_id_, CompositorFrame::From(*frame), | |
| 73 mojo::Closure()); | |
| 74 | 37 |
| 75 client_->DidSwapBuffers(); | 38 client_->DidSwapBuffers(); |
| 76 client_->DidSwapBuffersComplete(); | 39 client_->DidSwapBuffersComplete(); |
| 77 } | 40 } |
| 78 | 41 |
| 79 void OutputSurfaceMojo::ReturnResources( | 42 void OutputSurfaceMojo::OnResourcesReturned( |
| 43 mojo::ViewSurface* surface, |
| 80 mojo::Array<mojo::ReturnedResourcePtr> resources) { | 44 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 81 cc::CompositorFrameAck cfa; | 45 cc::CompositorFrameAck cfa; |
| 82 cfa.resources = resources.To<cc::ReturnedResourceArray>(); | 46 cfa.resources = resources.To<cc::ReturnedResourceArray>(); |
| 83 ReclaimResources(&cfa); | 47 ReclaimResources(&cfa); |
| 84 } | 48 } |
| 85 | 49 |
| 86 } // namespace mojo | 50 } // namespace mojo |
| OLD | NEW |