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 "cc/output/compositor_frame.h" |
| 8 #include "cc/resources/returned_resource.h" |
| 9 #include "cc/surfaces/display.h" |
| 10 #include "cc/surfaces/surface_id_allocator.h" |
| 11 #include "mojo/cc/context_provider_mojo.h" |
| 12 #include "mojo/public/cpp/gles2/gles2.h" |
| 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 14 #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" |
| 15 |
| 16 namespace mojo { |
| 17 namespace surfaces { |
| 18 |
| 19 SurfacesImpl::SurfacesImpl(ApplicationConnection* app, Context* context) |
| 20 : context_(context), |
| 21 factory_(context_->Manager(), this), |
| 22 id_namespace_(context->IdNamespace()) { |
| 23 } |
| 24 |
| 25 SurfacesImpl::~SurfacesImpl() { |
| 26 } |
| 27 |
| 28 void SurfacesImpl::OnConnectionEstablished() { |
| 29 client()->SetIdNamespace(id_namespace_); |
| 30 } |
| 31 |
| 32 void SurfacesImpl::CreateSurface(SurfaceIdPtr id, mojo::SizePtr size) { |
| 33 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); |
| 34 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { |
| 35 // Bad message, do something bad to the caller? |
| 36 NOTREACHED(); |
| 37 return; |
| 38 } |
| 39 factory_.Create(id.To<cc::SurfaceId>(), size.To<gfx::Size>()); |
| 40 } |
| 41 |
| 42 void SurfacesImpl::SubmitFrame(SurfaceIdPtr id, FramePtr frame_ptr) { |
| 43 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); |
| 44 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { |
| 45 // Bad message, do something bad to the caller? |
| 46 NOTREACHED(); |
| 47 return; |
| 48 } |
| 49 factory_.SubmitFrame(id.To<cc::SurfaceId>(), mojo::ConvertTo(frame_ptr)); |
| 50 context_->FrameSubmitted(); |
| 51 } |
| 52 |
| 53 void SurfacesImpl::DestroySurface(SurfaceIdPtr id) { |
| 54 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); |
| 55 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { |
| 56 // Bad message, do something bad to the caller? |
| 57 NOTREACHED(); |
| 58 return; |
| 59 } |
| 60 factory_.Destroy(id.To<cc::SurfaceId>()); |
| 61 } |
| 62 |
| 63 void SurfacesImpl::CreateGLES2BoundSurface(CommandBufferPtr gles2_client, |
| 64 SurfaceIdPtr id, |
| 65 mojo::SizePtr size) { |
| 66 command_buffer_handle_ = gles2_client.PassMessagePipe(); |
| 67 |
| 68 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); |
| 69 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { |
| 70 // Bad message, do something bad to the caller? |
| 71 NOTREACHED(); |
| 72 return; |
| 73 } |
| 74 if (!display_) { |
| 75 display_.reset(new cc::Display(this, context_->Manager(), NULL)); |
| 76 context_->SetDisplay(display_.get()); |
| 77 } |
| 78 factory_.Create(cc_id, size.To<gfx::Size>()); |
| 79 display_->Resize(cc_id, size.To<gfx::Size>()); |
| 80 } |
| 81 |
| 82 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { |
| 83 Array<ReturnedResourcePtr> ret(resources.size()); |
| 84 for (size_t i = 0; i < resources.size(); ++i) { |
| 85 ret[i] = ReturnedResource::From(resources[i]); |
| 86 } |
| 87 client()->ReturnResources(ret.Pass()); |
| 88 } |
| 89 |
| 90 scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() { |
| 91 static GLES2Initializer* gles2 = new GLES2Initializer; |
| 92 DCHECK(gles2); |
| 93 return make_scoped_ptr(new cc::OutputSurface( |
| 94 new ContextProviderMojo(command_buffer_handle_.Pass()))); |
| 95 } |
| 96 |
| 97 } // namespace surfaces |
| 98 } // namespace mojo |
OLD | NEW |