| 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/view_manager/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/view_manager/surfaces/surfaces_delegate.h" | |
| 12 #include "components/view_manager/surfaces/surfaces_scheduler.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(SurfacesDelegate* surfaces_delegate, | |
| 27 const scoped_refptr<SurfacesState>& state, | |
| 28 mojo::InterfaceRequest<mojo::Surface> request) | |
| 29 : delegate_(surfaces_delegate), | |
| 30 state_(state), | |
| 31 id_namespace_(state->next_id_namespace()), | |
| 32 factory_(state->manager(), this), | |
| 33 binding_(this, request.Pass()) { | |
| 34 // Destroy this object if the connection is closed. | |
| 35 binding_.set_connection_error_handler( | |
| 36 base::Bind(&SurfacesImpl::CloseConnection, base::Unretained(this))); | |
| 37 } | |
| 38 | |
| 39 void SurfacesImpl::CloseConnection() { | |
| 40 if (connection_closed_) | |
| 41 return; | |
| 42 connection_closed_ = true; | |
| 43 delegate_->OnSurfaceConnectionClosed(this); | |
| 44 delete this; | |
| 45 } | |
| 46 | |
| 47 void SurfacesImpl::GetIdNamespace( | |
| 48 const Surface::GetIdNamespaceCallback& callback) { | |
| 49 callback.Run(id_namespace_); | |
| 50 } | |
| 51 | |
| 52 void SurfacesImpl::SetResourceReturner(mojo::ResourceReturnerPtr returner) { | |
| 53 returner_ = returner.Pass(); | |
| 54 } | |
| 55 | |
| 56 void SurfacesImpl::CreateSurface(uint32_t local_id) { | |
| 57 factory_.Create(QualifyIdentifier(local_id)); | |
| 58 } | |
| 59 | |
| 60 void SurfacesImpl::SubmitCompositorFrame(uint32_t local_id, | |
| 61 mojo::CompositorFramePtr frame, | |
| 62 const mojo::Closure& callback) { | |
| 63 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitCompositorFrame"); | |
| 64 factory_.SubmitCompositorFrame(QualifyIdentifier(local_id), | |
| 65 frame.To<scoped_ptr<cc::CompositorFrame>>(), | |
| 66 base::Bind(&CallCallback, callback)); | |
| 67 state_->scheduler()->SetNeedsDraw(); | |
| 68 } | |
| 69 | |
| 70 void SurfacesImpl::DestroySurface(uint32_t local_id) { | |
| 71 factory_.Destroy(QualifyIdentifier(local_id)); | |
| 72 } | |
| 73 | |
| 74 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { | |
| 75 if (resources.empty() || !returner_) | |
| 76 return; | |
| 77 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); | |
| 78 for (size_t i = 0; i < resources.size(); ++i) { | |
| 79 ret[i] = mojo::ReturnedResource::From(resources[i]); | |
| 80 } | |
| 81 returner_->ReturnResources(ret.Pass()); | |
| 82 } | |
| 83 | |
| 84 SurfacesImpl::~SurfacesImpl() { | |
| 85 // Only CloseConnection should be allowed to destroy this object. | |
| 86 DCHECK(connection_closed_); | |
| 87 factory_.DestroyAll(); | |
| 88 } | |
| 89 | |
| 90 cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { | |
| 91 return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); | |
| 92 } | |
| 93 | |
| 94 } // namespace mojo | |
| OLD | NEW |