| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/surfaces/display_impl.h" | 5 #include "components/surfaces/display_impl.h" |
| 6 | 6 |
| 7 #include "cc/output/compositor_frame.h" | 7 #include "cc/output/compositor_frame.h" |
| 8 #include "cc/surfaces/display.h" | 8 #include "cc/surfaces/display.h" |
| 9 #include "components/surfaces/surfaces_context_provider.h" | 9 #include "components/surfaces/surfaces_context_provider.h" |
| 10 #include "components/surfaces/surfaces_output_surface.h" | 10 #include "components/surfaces/surfaces_output_surface.h" |
| 11 #include "components/surfaces/surfaces_scheduler.h" | 11 #include "components/surfaces/surfaces_scheduler.h" |
| 12 #include "components/surfaces/surfaces_service_application.h" |
| 12 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 13 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 14 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 14 | 15 |
| 15 namespace surfaces { | 16 namespace surfaces { |
| 16 namespace { | 17 namespace { |
| 17 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { | 18 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { |
| 18 callback.Run(); | 19 callback.Run(); |
| 19 } | 20 } |
| 20 } | 21 } |
| 21 | 22 |
| 22 DisplayImpl::DisplayImpl(cc::SurfaceManager* manager, | 23 DisplayImpl::DisplayImpl(SurfacesServiceApplication* application, |
| 24 cc::SurfaceManager* manager, |
| 23 cc::SurfaceId cc_id, | 25 cc::SurfaceId cc_id, |
| 24 SurfacesScheduler* scheduler, | 26 SurfacesScheduler* scheduler, |
| 25 mojo::ContextProviderPtr context_provider, | 27 mojo::ContextProviderPtr context_provider, |
| 26 mojo::ResourceReturnerPtr returner, | 28 mojo::ResourceReturnerPtr returner, |
| 27 mojo::InterfaceRequest<mojo::Display> display_request) | 29 mojo::InterfaceRequest<mojo::Display> display_request) |
| 28 : manager_(manager), | 30 : application_(application), |
| 31 manager_(manager), |
| 29 factory_(manager, this), | 32 factory_(manager, this), |
| 30 cc_id_(cc_id), | 33 cc_id_(cc_id), |
| 31 scheduler_(scheduler), | 34 scheduler_(scheduler), |
| 32 context_provider_(context_provider.Pass()), | 35 context_provider_(context_provider.Pass()), |
| 33 returner_(returner.Pass()), | 36 returner_(returner.Pass()), |
| 34 viewport_param_binding_(this), | 37 viewport_param_binding_(this), |
| 35 display_binding_(this, display_request.Pass()) { | 38 display_binding_(this, display_request.Pass()) { |
| 39 application_->DisplayCreated(this); |
| 36 mojo::ViewportParameterListenerPtr viewport_parameter_listener; | 40 mojo::ViewportParameterListenerPtr viewport_parameter_listener; |
| 37 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener)); | 41 viewport_param_binding_.Bind(GetProxy(&viewport_parameter_listener)); |
| 38 context_provider_->Create( | 42 context_provider_->Create( |
| 39 viewport_parameter_listener.Pass(), | 43 viewport_parameter_listener.Pass(), |
| 40 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this))); | 44 base::Bind(&DisplayImpl::OnContextCreated, base::Unretained(this))); |
| 41 } | 45 } |
| 42 | 46 |
| 43 void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) { | 47 void DisplayImpl::OnContextCreated(mojo::CommandBufferPtr gles2_client) { |
| 44 DCHECK(!display_); | 48 DCHECK(!display_); |
| 45 | 49 |
| 46 cc::RendererSettings settings; | 50 cc::RendererSettings settings; |
| 47 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); | 51 display_.reset(new cc::Display(this, manager_, nullptr, nullptr, settings)); |
| 48 scheduler_->AddDisplay(display_.get()); | 52 scheduler_->AddDisplay(display_.get()); |
| 49 display_->Initialize(make_scoped_ptr( | 53 display_->Initialize(make_scoped_ptr( |
| 50 new surfaces::DirectOutputSurface(new surfaces::SurfacesContextProvider( | 54 new surfaces::DirectOutputSurface(new surfaces::SurfacesContextProvider( |
| 51 gles2_client.PassInterface().PassHandle())))); | 55 gles2_client.PassInterface().PassHandle())))); |
| 52 | 56 |
| 53 factory_.Create(cc_id_); | 57 factory_.Create(cc_id_); |
| 54 display_->SetSurfaceId(cc_id_, 1.f); | 58 display_->SetSurfaceId(cc_id_, 1.f); |
| 55 if (pending_frame_) | 59 if (pending_frame_) |
| 56 Draw(); | 60 Draw(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 DisplayImpl::~DisplayImpl() { | 63 DisplayImpl::~DisplayImpl() { |
| 60 if (display_) { | 64 if (display_) { |
| 61 factory_.Destroy(cc_id_); | 65 factory_.Destroy(cc_id_); |
| 62 scheduler_->RemoveDisplay(display_.get()); | 66 scheduler_->RemoveDisplay(display_.get()); |
| 67 // By deleting the object after display_ is reset, OutputSurfaceLost can |
| 68 // know not to do anything (which would result in double delete). |
| 69 delete display_.release(); |
| 63 } | 70 } |
| 71 application_->DisplayDestroyed(this); |
| 64 } | 72 } |
| 65 | 73 |
| 66 void DisplayImpl::SubmitFrame(mojo::FramePtr frame, | 74 void DisplayImpl::SubmitFrame(mojo::FramePtr frame, |
| 67 const SubmitFrameCallback& callback) { | 75 const SubmitFrameCallback& callback) { |
| 68 DCHECK(pending_callback_.is_null()); | 76 DCHECK(pending_callback_.is_null()); |
| 69 pending_frame_ = frame.Pass(); | 77 pending_frame_ = frame.Pass(); |
| 70 pending_callback_ = callback; | 78 pending_callback_ = callback; |
| 71 if (display_) | 79 if (display_) |
| 72 Draw(); | 80 Draw(); |
| 73 } | 81 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 90 } | 98 } |
| 91 | 99 |
| 92 void DisplayImpl::DidSwapBuffersComplete() { | 100 void DisplayImpl::DidSwapBuffersComplete() { |
| 93 } | 101 } |
| 94 | 102 |
| 95 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase, | 103 void DisplayImpl::CommitVSyncParameters(base::TimeTicks timebase, |
| 96 base::TimeDelta interval) { | 104 base::TimeDelta interval) { |
| 97 } | 105 } |
| 98 | 106 |
| 99 void DisplayImpl::OutputSurfaceLost() { | 107 void DisplayImpl::OutputSurfaceLost() { |
| 108 if (!display_) // Shutdown case |
| 109 return; |
| 110 |
| 100 // If our OutputSurface is lost we can't draw until we get a new one. For now, | 111 // If our OutputSurface is lost we can't draw until we get a new one. For now, |
| 101 // destroy the display and create a new one when our ContextProvider provides | 112 // destroy the display and create a new one when our ContextProvider provides |
| 102 // a new one. | 113 // a new one. |
| 103 // TODO: This is more violent than necessary - we could simply remove this | 114 // TODO: This is more violent than necessary - we could simply remove this |
| 104 // display from the scheduler's set and pass a new context in to the | 115 // display from the scheduler's set and pass a new context in to the |
| 105 // OutputSurface. It should be able to reinitialize properly. | 116 // OutputSurface. It should be able to reinitialize properly. |
| 106 scheduler_->RemoveDisplay(display_.get()); | 117 scheduler_->RemoveDisplay(display_.get()); |
| 107 display_.reset(); | 118 display_.reset(); |
| 108 factory_.Destroy(cc_id_); | 119 factory_.Destroy(cc_id_); |
| 109 viewport_param_binding_.Close(); | 120 viewport_param_binding_.Close(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 129 DCHECK(returner_); | 140 DCHECK(returner_); |
| 130 | 141 |
| 131 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); | 142 mojo::Array<mojo::ReturnedResourcePtr> ret(resources.size()); |
| 132 for (size_t i = 0; i < resources.size(); ++i) { | 143 for (size_t i = 0; i < resources.size(); ++i) { |
| 133 ret[i] = mojo::ReturnedResource::From(resources[i]); | 144 ret[i] = mojo::ReturnedResource::From(resources[i]); |
| 134 } | 145 } |
| 135 returner_->ReturnResources(ret.Pass()); | 146 returner_->ReturnResources(ret.Pass()); |
| 136 } | 147 } |
| 137 | 148 |
| 138 } // namespace surfaces | 149 } // namespace surfaces |
| OLD | NEW |