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 "services/surfaces/surfaces_impl.h" | 5 #include "services/surfaces/surfaces_impl.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "cc/output/compositor_frame.h" | 8 #include "cc/output/compositor_frame.h" |
9 #include "cc/resources/returned_resource.h" | 9 #include "cc/resources/returned_resource.h" |
10 #include "cc/surfaces/display.h" | 10 #include "cc/surfaces/display.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 : SurfacesImpl(manager, id_namespace, client) { | 40 : SurfacesImpl(manager, id_namespace, client) { |
41 binding_.Bind(surface); | 41 binding_.Bind(surface); |
42 binding_.client()->SetIdNamespace(id_namespace); | 42 binding_.client()->SetIdNamespace(id_namespace); |
43 } | 43 } |
44 | 44 |
45 SurfacesImpl::~SurfacesImpl() { | 45 SurfacesImpl::~SurfacesImpl() { |
46 client_->OnDisplayBeingDestroyed(display_.get()); | 46 client_->OnDisplayBeingDestroyed(display_.get()); |
47 factory_.DestroyAll(); | 47 factory_.DestroyAll(); |
48 } | 48 } |
49 | 49 |
50 void SurfacesImpl::CreateSurface(SurfaceIdPtr id) { | 50 void SurfacesImpl::CreateSurface(uint32_t local_id) { |
51 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); | 51 factory_.Create(QualifyIdentifier(local_id)); |
52 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { | |
53 // Bad message, do something bad to the caller? | |
54 NOTREACHED(); | |
55 return; | |
56 } | |
57 factory_.Create(id.To<cc::SurfaceId>()); | |
58 } | 52 } |
59 | 53 |
60 void SurfacesImpl::SubmitFrame(SurfaceIdPtr id, | 54 void SurfacesImpl::SubmitFrame(uint32_t local_id, |
61 mojo::FramePtr frame_ptr, | 55 mojo::FramePtr frame, |
62 const mojo::Closure& callback) { | 56 const mojo::Closure& callback) { |
63 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); | 57 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); |
64 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); | 58 factory_.SubmitFrame(QualifyIdentifier(local_id), |
65 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { | 59 frame.To<scoped_ptr<cc::CompositorFrame>>(), |
66 // Bad message, do something bad to the caller? | |
67 LOG(FATAL) << "Received frame for id " << cc_id.id << " namespace " | |
68 << cc::SurfaceIdAllocator::NamespaceForId(cc_id) | |
69 << " should be namespace " << id_namespace_; | |
70 return; | |
71 } | |
72 factory_.SubmitFrame(id.To<cc::SurfaceId>(), | |
73 frame_ptr.To<scoped_ptr<cc::CompositorFrame>>(), | |
74 base::Bind(&CallCallback, callback)); | 60 base::Bind(&CallCallback, callback)); |
75 client_->FrameSubmitted(); | 61 client_->FrameSubmitted(); |
76 } | 62 } |
77 | 63 |
78 void SurfacesImpl::DestroySurface(SurfaceIdPtr id) { | 64 void SurfacesImpl::DestroySurface(uint32_t local_id) { |
79 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); | 65 factory_.Destroy(QualifyIdentifier(local_id)); |
80 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { | |
81 // Bad message, do something bad to the caller? | |
82 NOTREACHED(); | |
83 return; | |
84 } | |
85 factory_.Destroy(id.To<cc::SurfaceId>()); | |
86 } | 66 } |
87 | 67 |
88 void SurfacesImpl::CreateGLES2BoundSurface( | 68 void SurfacesImpl::CreateGLES2BoundSurface( |
89 mojo::CommandBufferPtr gles2_client, | 69 mojo::CommandBufferPtr gles2_client, |
90 SurfaceIdPtr id, | 70 uint32_t local_id, |
91 mojo::SizePtr size, | 71 mojo::SizePtr size, |
92 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) { | 72 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) { |
93 command_buffer_handle_ = gles2_client.PassMessagePipe(); | 73 command_buffer_handle_ = gles2_client.PassMessagePipe(); |
94 | 74 |
95 cc::SurfaceId cc_id = id.To<cc::SurfaceId>(); | |
96 if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) { | |
97 // Bad message, do something bad to the caller? | |
98 LOG(FATAL) << "Received request for id " << cc_id.id << " namespace " | |
99 << cc::SurfaceIdAllocator::NamespaceForId(cc_id) | |
100 << " should be namespace " << id_namespace_; | |
101 return; | |
102 } | |
103 if (!display_) { | 75 if (!display_) { |
104 cc::RendererSettings settings; | 76 cc::RendererSettings settings; |
105 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); | 77 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); |
106 client_->SetDisplay(display_.get()); | 78 client_->SetDisplay(display_.get()); |
107 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface( | 79 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface( |
108 new mojo::ContextProviderMojo(command_buffer_handle_.Pass())))); | 80 new mojo::ContextProviderMojo(command_buffer_handle_.Pass())))); |
109 } | 81 } |
| 82 cc::SurfaceId cc_id = QualifyIdentifier(local_id); |
110 factory_.Create(cc_id); | 83 factory_.Create(cc_id); |
111 display_->SetSurfaceId(cc_id, 1.f); | 84 display_->SetSurfaceId(cc_id, 1.f); |
112 display_->Resize(size.To<gfx::Size>()); | 85 display_->Resize(size.To<gfx::Size>()); |
113 parameter_listeners_.AddBinding(this, listener_request.Pass()); | 86 parameter_listeners_.AddBinding(this, listener_request.Pass()); |
114 } | 87 } |
115 | 88 |
116 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { | 89 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { |
| 90 if (resources.empty()) |
| 91 return; |
117 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); | 92 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); |
118 for (size_t i = 0; i < resources.size(); ++i) { | 93 for (size_t i = 0; i < resources.size(); ++i) { |
119 ret[i] = mojo::ReturnedResource::From(resources[i]); | 94 ret[i] = mojo::ReturnedResource::From(resources[i]); |
120 } | 95 } |
121 binding_.client()->ReturnResources(ret.Pass()); | 96 binding_.client()->ReturnResources(ret.Pass()); |
122 } | 97 } |
123 | 98 |
124 void SurfacesImpl::DisplayDamaged() { | 99 void SurfacesImpl::DisplayDamaged() { |
125 } | 100 } |
126 | 101 |
(...skipping 23 matching lines...) Expand all Loading... |
150 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, | 125 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, |
151 uint32_t id_namespace, | 126 uint32_t id_namespace, |
152 Client* client) | 127 Client* client) |
153 : manager_(manager), | 128 : manager_(manager), |
154 factory_(manager, this), | 129 factory_(manager, this), |
155 id_namespace_(id_namespace), | 130 id_namespace_(id_namespace), |
156 client_(client), | 131 client_(client), |
157 binding_(this) { | 132 binding_(this) { |
158 } | 133 } |
159 | 134 |
| 135 cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { |
| 136 return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); |
| 137 } |
| 138 |
160 } // namespace mojo | 139 } // namespace mojo |
OLD | NEW |