| 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 "ui/views/mus/surface_binding.h" | 5 #include "ui/views/mus/surface_binding.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 (*window_map)[connection] = new PerConnectionState(connector, connection); | 91 (*window_map)[connection] = new PerConnectionState(connector, connection); |
| 92 (*window_map)[connection]->Init(); | 92 (*window_map)[connection]->Init(); |
| 93 } | 93 } |
| 94 return (*window_map)[connection]; | 94 return (*window_map)[connection]; |
| 95 } | 95 } |
| 96 | 96 |
| 97 std::unique_ptr<cc::OutputSurface> | 97 std::unique_ptr<cc::OutputSurface> |
| 98 SurfaceBinding::PerConnectionState::CreateOutputSurface( | 98 SurfaceBinding::PerConnectionState::CreateOutputSurface( |
| 99 mus::Window* window, | 99 mus::Window* window, |
| 100 mus::mojom::SurfaceType surface_type) { | 100 mus::mojom::SurfaceType surface_type) { |
| 101 if (gpu_.encountered_error()) |
| 102 return nullptr; |
| 101 // TODO(sky): figure out lifetime here. Do I need to worry about the return | 103 // TODO(sky): figure out lifetime here. Do I need to worry about the return |
| 102 // value outliving this? | 104 // value outliving this? |
| 103 mus::mojom::CommandBufferPtr cb; | 105 mus::mojom::CommandBufferPtr cb; |
| 104 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); | 106 gpu_->CreateOffscreenGLES2Context(GetProxy(&cb)); |
| 105 | 107 |
| 106 scoped_refptr<cc::ContextProvider> context_provider( | 108 scoped_refptr<cc::ContextProvider> context_provider( |
| 107 new mus::ContextProvider(cb.PassInterface().PassHandle())); | 109 new mus::ContextProvider(cb.PassInterface().PassHandle())); |
| 108 return base::WrapUnique(new mus::OutputSurface( | 110 return base::WrapUnique(new mus::OutputSurface( |
| 109 context_provider, window->RequestSurface(surface_type))); | 111 context_provider, window->RequestSurface(surface_type))); |
| 110 } | 112 } |
| 111 | 113 |
| 112 SurfaceBinding::PerConnectionState::PerConnectionState( | 114 SurfaceBinding::PerConnectionState::PerConnectionState( |
| 113 shell::Connector* connector, | 115 shell::Connector* connector, |
| 114 mus::WindowTreeConnection* connection) | 116 mus::WindowTreeConnection* connection) |
| 115 : connector_(connector), connection_(connection) {} | 117 : connector_(connector), connection_(connection) {} |
| 116 | 118 |
| 117 SurfaceBinding::PerConnectionState::~PerConnectionState() { | 119 SurfaceBinding::PerConnectionState::~PerConnectionState() { |
| 118 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); | 120 ConnectionToStateMap* window_map = window_states.Pointer()->Get(); |
| 119 DCHECK(window_map); | 121 DCHECK(window_map); |
| 120 DCHECK_EQ(this, (*window_map)[connection_]); | 122 DCHECK_EQ(this, (*window_map)[connection_]); |
| 121 window_map->erase(connection_); | 123 window_map->erase(connection_); |
| 122 if (window_map->empty()) { | 124 if (window_map->empty()) { |
| 123 delete window_map; | 125 delete window_map; |
| 124 window_states.Pointer()->Set(nullptr); | 126 window_states.Pointer()->Set(nullptr); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 | 129 |
| 128 void SurfaceBinding::PerConnectionState::Init() { | 130 void SurfaceBinding::PerConnectionState::Init() { |
| 129 connector_->ConnectToInterface("mojo:mus", &gpu_); | 131 connector_->ConnectToInterface("mojo:mus", &gpu_); |
| 132 |
| 133 // TODO(sad): If connection is lost (e.g. if gpu crashes), then the |
| 134 // connections need to be restored. https://crbug.com/613366 |
| 135 // TODO(rockot|yzshen): It is necessary to install a connection-error handler, |
| 136 // even if the handler doesn't actually do anything. https://crbug.com/613371 |
| 137 gpu_.set_connection_error_handler([]{}); |
| 130 } | 138 } |
| 131 | 139 |
| 132 // SurfaceBinding -------------------------------------------------------------- | 140 // SurfaceBinding -------------------------------------------------------------- |
| 133 | 141 |
| 134 SurfaceBinding::SurfaceBinding(shell::Connector* connector, | 142 SurfaceBinding::SurfaceBinding(shell::Connector* connector, |
| 135 mus::Window* window, | 143 mus::Window* window, |
| 136 mus::mojom::SurfaceType surface_type) | 144 mus::mojom::SurfaceType surface_type) |
| 137 : window_(window), | 145 : window_(window), |
| 138 surface_type_(surface_type), | 146 surface_type_(surface_type), |
| 139 state_(PerConnectionState::Get(connector, window->connection())) {} | 147 state_(PerConnectionState::Get(connector, window->connection())) {} |
| 140 | 148 |
| 141 SurfaceBinding::~SurfaceBinding() {} | 149 SurfaceBinding::~SurfaceBinding() {} |
| 142 | 150 |
| 143 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { | 151 std::unique_ptr<cc::OutputSurface> SurfaceBinding::CreateOutputSurface() { |
| 144 return state_->CreateOutputSurface(window_, surface_type_); | 152 return state_->CreateOutputSurface(window_, surface_type_); |
| 145 } | 153 } |
| 146 | 154 |
| 147 } // namespace views | 155 } // namespace views |
| OLD | NEW |