OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/surfaces/surfaces_impl.h" |
| 6 |
| 7 #include "base/trace_event/trace_event.h" |
| 8 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/resources/returned_resource.h" |
| 10 #include "cc/surfaces/surface_id_allocator.h" |
| 11 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 12 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 13 #include "mojo/services/surfaces/surfaces_scheduler.h" |
| 14 |
| 15 using mojo::SurfaceIdPtr; |
| 16 |
| 17 namespace surfaces { |
| 18 |
| 19 namespace { |
| 20 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { |
| 21 callback.Run(); |
| 22 } |
| 23 } |
| 24 |
| 25 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, |
| 26 uint32_t id_namespace, |
| 27 SurfacesScheduler* scheduler, |
| 28 mojo::InterfaceRequest<mojo::Surface> request) |
| 29 : manager_(manager), |
| 30 factory_(manager, this), |
| 31 id_namespace_(id_namespace), |
| 32 scheduler_(scheduler), |
| 33 binding_(this, request.Pass()) { |
| 34 } |
| 35 |
| 36 SurfacesImpl::~SurfacesImpl() { |
| 37 factory_.DestroyAll(); |
| 38 } |
| 39 |
| 40 void SurfacesImpl::GetIdNamespace( |
| 41 const Surface::GetIdNamespaceCallback& callback) { |
| 42 callback.Run(id_namespace_); |
| 43 } |
| 44 |
| 45 void SurfacesImpl::SetResourceReturner(mojo::ResourceReturnerPtr returner) { |
| 46 returner_ = returner.Pass(); |
| 47 } |
| 48 |
| 49 void SurfacesImpl::CreateSurface(uint32_t local_id) { |
| 50 factory_.Create(QualifyIdentifier(local_id)); |
| 51 } |
| 52 |
| 53 void SurfacesImpl::SubmitFrame(uint32_t local_id, |
| 54 mojo::FramePtr frame, |
| 55 const mojo::Closure& callback) { |
| 56 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); |
| 57 factory_.SubmitFrame(QualifyIdentifier(local_id), |
| 58 frame.To<scoped_ptr<cc::CompositorFrame>>(), |
| 59 base::Bind(&CallCallback, callback)); |
| 60 scheduler_->SetNeedsDraw(); |
| 61 } |
| 62 |
| 63 void SurfacesImpl::DestroySurface(uint32_t local_id) { |
| 64 factory_.Destroy(QualifyIdentifier(local_id)); |
| 65 } |
| 66 |
| 67 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { |
| 68 if (resources.empty() || !returner_) |
| 69 return; |
| 70 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); |
| 71 for (size_t i = 0; i < resources.size(); ++i) { |
| 72 ret[i] = mojo::ReturnedResource::From(resources[i]); |
| 73 } |
| 74 returner_->ReturnResources(ret.Pass()); |
| 75 } |
| 76 |
| 77 cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { |
| 78 return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); |
| 79 } |
| 80 |
| 81 } // namespace mojo |
OLD | NEW |