| 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/trace_event/trace_event.h" | 7 #include "base/trace_event/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" | |
| 11 #include "cc/surfaces/surface_id_allocator.h" | 10 #include "cc/surfaces/surface_id_allocator.h" |
| 12 #include "mojo/cc/context_provider_mojo.h" | |
| 13 #include "mojo/cc/direct_output_surface.h" | |
| 14 #include "mojo/converters/geometry/geometry_type_converters.h" | 11 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 15 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 12 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 13 #include "services/surfaces/surfaces_scheduler.h" |
| 16 | 14 |
| 17 using mojo::SurfaceIdPtr; | 15 using mojo::SurfaceIdPtr; |
| 18 | 16 |
| 19 namespace surfaces { | 17 namespace surfaces { |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { | 20 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { |
| 23 callback.Run(); | 21 callback.Run(); |
| 24 } | 22 } |
| 25 } | 23 } |
| 26 | 24 |
| 27 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, | 25 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, |
| 28 uint32_t id_namespace, | 26 uint32_t id_namespace, |
| 29 Client* client, | 27 SurfacesScheduler* scheduler, |
| 30 mojo::InterfaceRequest<mojo::Surface> request) | 28 mojo::InterfaceRequest<mojo::Surface> request) |
| 31 : SurfacesImpl(manager, id_namespace, client) { | 29 : manager_(manager), |
| 32 binding_.Bind(request.Pass()); | 30 factory_(manager, this), |
| 33 } | 31 id_namespace_(id_namespace), |
| 34 | 32 scheduler_(scheduler), |
| 35 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, | 33 binding_(this, request.Pass()) { |
| 36 uint32_t id_namespace, | |
| 37 Client* client, | |
| 38 mojo::SurfacePtr* surface) | |
| 39 : SurfacesImpl(manager, id_namespace, client) { | |
| 40 binding_.Bind(surface); | |
| 41 } | 34 } |
| 42 | 35 |
| 43 SurfacesImpl::~SurfacesImpl() { | 36 SurfacesImpl::~SurfacesImpl() { |
| 44 client_->OnDisplayBeingDestroyed(display_.get()); | |
| 45 factory_.DestroyAll(); | 37 factory_.DestroyAll(); |
| 46 } | 38 } |
| 47 | 39 |
| 48 void SurfacesImpl::GetIdNamespace( | 40 void SurfacesImpl::GetIdNamespace( |
| 49 const Surface::GetIdNamespaceCallback& callback) { | 41 const Surface::GetIdNamespaceCallback& callback) { |
| 50 callback.Run(id_namespace_); | 42 callback.Run(id_namespace_); |
| 51 } | 43 } |
| 52 | 44 |
| 53 void SurfacesImpl::SetResourceReturner(mojo::ResourceReturnerPtr returner) { | 45 void SurfacesImpl::SetResourceReturner(mojo::ResourceReturnerPtr returner) { |
| 54 returner_ = returner.Pass(); | 46 returner_ = returner.Pass(); |
| 55 } | 47 } |
| 56 | 48 |
| 57 void SurfacesImpl::CreateSurface(uint32_t local_id) { | 49 void SurfacesImpl::CreateSurface(uint32_t local_id) { |
| 58 factory_.Create(QualifyIdentifier(local_id)); | 50 factory_.Create(QualifyIdentifier(local_id)); |
| 59 } | 51 } |
| 60 | 52 |
| 61 void SurfacesImpl::SubmitFrame(uint32_t local_id, | 53 void SurfacesImpl::SubmitFrame(uint32_t local_id, |
| 62 mojo::FramePtr frame, | 54 mojo::FramePtr frame, |
| 63 const mojo::Closure& callback) { | 55 const mojo::Closure& callback) { |
| 64 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); | 56 TRACE_EVENT0("mojo", "SurfacesImpl::SubmitFrame"); |
| 65 factory_.SubmitFrame(QualifyIdentifier(local_id), | 57 factory_.SubmitFrame(QualifyIdentifier(local_id), |
| 66 frame.To<scoped_ptr<cc::CompositorFrame>>(), | 58 frame.To<scoped_ptr<cc::CompositorFrame>>(), |
| 67 base::Bind(&CallCallback, callback)); | 59 base::Bind(&CallCallback, callback)); |
| 68 client_->FrameSubmitted(); | 60 scheduler_->SetNeedsDraw(); |
| 69 } | 61 } |
| 70 | 62 |
| 71 void SurfacesImpl::DestroySurface(uint32_t local_id) { | 63 void SurfacesImpl::DestroySurface(uint32_t local_id) { |
| 72 factory_.Destroy(QualifyIdentifier(local_id)); | 64 factory_.Destroy(QualifyIdentifier(local_id)); |
| 73 if (local_id == displayed_surface_) { | |
| 74 displayed_surface_ = 0; | |
| 75 client_->OnDisplayBeingDestroyed(display_.get()); | |
| 76 display_.reset(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void SurfacesImpl::CreateGLES2BoundSurface( | |
| 81 mojo::CommandBufferPtr gles2_client, | |
| 82 uint32_t local_id, | |
| 83 mojo::SizePtr size, | |
| 84 mojo::InterfaceRequest<mojo::ViewportParameterListener> listener_request) { | |
| 85 command_buffer_handle_ = gles2_client.PassMessagePipe(); | |
| 86 | |
| 87 if (!display_) { | |
| 88 cc::RendererSettings settings; | |
| 89 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); | |
| 90 client_->SetDisplay(display_.get()); | |
| 91 display_->Initialize(make_scoped_ptr(new mojo::DirectOutputSurface( | |
| 92 new mojo::ContextProviderMojo(command_buffer_handle_.Pass())))); | |
| 93 } | |
| 94 displayed_surface_ = local_id; | |
| 95 cc::SurfaceId cc_id = QualifyIdentifier(local_id); | |
| 96 factory_.Create(cc_id); | |
| 97 display_->SetSurfaceId(cc_id, 1.f); | |
| 98 display_->Resize(size.To<gfx::Size>()); | |
| 99 parameter_listeners_.AddBinding(this, listener_request.Pass()); | |
| 100 } | 65 } |
| 101 | 66 |
| 102 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { | 67 void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { |
| 103 if (resources.empty() || !returner_) | 68 if (resources.empty() || !returner_) |
| 104 return; | 69 return; |
| 105 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); | 70 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); |
| 106 for (size_t i = 0; i < resources.size(); ++i) { | 71 for (size_t i = 0; i < resources.size(); ++i) { |
| 107 ret[i] = mojo::ReturnedResource::From(resources[i]); | 72 ret[i] = mojo::ReturnedResource::From(resources[i]); |
| 108 } | 73 } |
| 109 returner_->ReturnResources(ret.Pass()); | 74 returner_->ReturnResources(ret.Pass()); |
| 110 } | 75 } |
| 111 | 76 |
| 112 void SurfacesImpl::DisplayDamaged() { | |
| 113 } | |
| 114 | |
| 115 void SurfacesImpl::DidSwapBuffers() { | |
| 116 } | |
| 117 | |
| 118 void SurfacesImpl::DidSwapBuffersComplete() { | |
| 119 } | |
| 120 | |
| 121 void SurfacesImpl::CommitVSyncParameters(base::TimeTicks timebase, | |
| 122 base::TimeDelta interval) { | |
| 123 } | |
| 124 | |
| 125 void SurfacesImpl::OutputSurfaceLost() { | |
| 126 } | |
| 127 | |
| 128 void SurfacesImpl::SetMemoryPolicy(const cc::ManagedMemoryPolicy& policy) { | |
| 129 } | |
| 130 | |
| 131 void SurfacesImpl::OnVSyncParametersUpdated(int64_t timebase, | |
| 132 int64_t interval) { | |
| 133 client_->OnVSyncParametersUpdated( | |
| 134 base::TimeTicks::FromInternalValue(timebase), | |
| 135 base::TimeDelta::FromInternalValue(interval)); | |
| 136 } | |
| 137 | |
| 138 SurfacesImpl::SurfacesImpl(cc::SurfaceManager* manager, | |
| 139 uint32_t id_namespace, | |
| 140 Client* client) | |
| 141 : manager_(manager), | |
| 142 factory_(manager, this), | |
| 143 id_namespace_(id_namespace), | |
| 144 client_(client), | |
| 145 displayed_surface_(0), | |
| 146 binding_(this) { | |
| 147 } | |
| 148 | |
| 149 cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { | 77 cc::SurfaceId SurfacesImpl::QualifyIdentifier(uint32_t local_id) { |
| 150 return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); | 78 return cc::SurfaceId(static_cast<uint64_t>(id_namespace_) << 32 | local_id); |
| 151 } | 79 } |
| 152 | 80 |
| 153 } // namespace mojo | 81 } // namespace mojo |
| OLD | NEW |