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