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 "sky/compositor/surface_holder.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 9 #include "mojo/public/cpp/application/connect.h" |
| 10 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 11 #include "sky/compositor/surface_allocator.h" |
| 12 |
| 13 namespace sky { |
| 14 |
| 15 SurfaceHolder::Client::~Client() { |
| 16 } |
| 17 |
| 18 SurfaceHolder::SurfaceHolder(Client* client, mojo::Shell* shell) |
| 19 : client_(client), weak_factory_(this) { |
| 20 mojo::ServiceProviderPtr service_provider; |
| 21 shell->ConnectToApplication("mojo:surfaces_service", |
| 22 mojo::GetProxy(&service_provider)); |
| 23 mojo::ConnectToService(service_provider.get(), &surfaces_service_); |
| 24 |
| 25 surfaces_service_->CreateSurfaceConnection(base::Bind( |
| 26 &SurfaceHolder::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr())); |
| 27 } |
| 28 |
| 29 SurfaceHolder::~SurfaceHolder() { |
| 30 if (surface_id_) |
| 31 surface_->DestroySurface(surface_id_.Clone()); |
| 32 } |
| 33 |
| 34 void SurfaceHolder::SubmitFrame(mojo::FramePtr frame) { |
| 35 surface_->SubmitFrame(surface_id_.Clone(), frame.Pass()); |
| 36 } |
| 37 |
| 38 void SurfaceHolder::SetSize(const gfx::Size& size) { |
| 39 if (surface_id_ && size_ == size) |
| 40 return; |
| 41 |
| 42 if (surface_id_) { |
| 43 surface_->DestroySurface(surface_id_.Clone()); |
| 44 } else { |
| 45 surface_id_ = mojo::SurfaceId::New(); |
| 46 } |
| 47 |
| 48 surface_id_->id = surface_allocator_->CreateSurfaceId(); |
| 49 surface_->CreateSurface(surface_id_.Clone(), mojo::Size::From(size)); |
| 50 size_ = size; |
| 51 |
| 52 client_->OnSurfaceIdAvailable(surface_id_.Clone()); |
| 53 } |
| 54 |
| 55 void SurfaceHolder::ReturnResources( |
| 56 mojo::Array<mojo::ReturnedResourcePtr> resources) { |
| 57 // TODO(abarth): The surface service shouldn't spam us with empty calls. |
| 58 if (!resources.size()) |
| 59 return; |
| 60 client_->ReturnResources(resources.Pass()); |
| 61 client_->OnReadyForNextFrame(); |
| 62 } |
| 63 |
| 64 void SurfaceHolder::OnSurfaceConnectionCreated(mojo::SurfacePtr surface, |
| 65 uint32_t id_namespace) { |
| 66 surface_ = surface.Pass(); |
| 67 surface_.set_client(this); |
| 68 surface_allocator_.reset(new SurfaceAllocator(id_namespace)); |
| 69 |
| 70 client_->OnReadyForNextFrame(); |
| 71 } |
| 72 |
| 73 } // namespace sky |
OLD | NEW |