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