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 "ui/compositor/test/in_process_context_factory.h" | 5 #include "ui/compositor/test/in_process_context_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 attribs.stencil_size = 0; | 105 attribs.stencil_size = 0; |
106 attribs.samples = 0; | 106 attribs.samples = 0; |
107 attribs.sample_buffers = 0; | 107 attribs.sample_buffers = 0; |
108 attribs.fail_if_major_perf_caveat = false; | 108 attribs.fail_if_major_perf_caveat = false; |
109 attribs.bind_generates_resource = false; | 109 attribs.bind_generates_resource = false; |
110 | 110 |
111 scoped_refptr<InProcessContextProvider> context_provider = | 111 scoped_refptr<InProcessContextProvider> context_provider = |
112 InProcessContextProvider::Create(attribs, &gpu_memory_buffer_manager_, | 112 InProcessContextProvider::Create(attribs, &gpu_memory_buffer_manager_, |
113 &image_factory_, | 113 &image_factory_, |
114 compositor->widget(), "UICompositor"); | 114 compositor->widget(), "UICompositor"); |
115 scoped_refptr<InProcessContextProvider> worker_context_provider = | 115 |
116 InProcessContextProvider::CreateOffscreen(&gpu_memory_buffer_manager_, | 116 // Try to reuse existing shared worker context provider. |
117 &image_factory_); | 117 if (shared_worker_context_provider_) { |
| 118 base::AutoLock lock(*shared_worker_context_provider_->GetLock()); |
| 119 if (shared_worker_context_provider_->ContextGL() |
| 120 ->GetGraphicsResetStatusKHR() != GL_NO_ERROR) { |
| 121 shared_worker_context_provider_->Destroy(); |
| 122 shared_worker_context_provider_ = nullptr; |
| 123 } |
| 124 } |
| 125 if (!shared_worker_context_provider_) { |
| 126 shared_worker_context_provider_ = InProcessContextProvider::CreateOffscreen( |
| 127 &gpu_memory_buffer_manager_, &image_factory_); |
| 128 if (shared_worker_context_provider_ && |
| 129 !shared_worker_context_provider_->BindToCurrentThread()) |
| 130 shared_worker_context_provider_ = nullptr; |
| 131 if (shared_worker_context_provider_) |
| 132 shared_worker_context_provider_->SetupLock(); |
| 133 } |
118 | 134 |
119 scoped_ptr<cc::OutputSurface> real_output_surface; | 135 scoped_ptr<cc::OutputSurface> real_output_surface; |
120 | 136 |
121 if (use_test_surface_) { | 137 if (use_test_surface_) { |
122 bool flipped_output_surface = false; | 138 bool flipped_output_surface = false; |
123 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( | 139 real_output_surface = make_scoped_ptr(new cc::PixelTestOutputSurface( |
124 context_provider, worker_context_provider, flipped_output_surface)); | 140 context_provider, shared_worker_context_provider_, |
| 141 flipped_output_surface)); |
125 } else { | 142 } else { |
126 real_output_surface = make_scoped_ptr( | 143 real_output_surface = make_scoped_ptr(new DirectOutputSurface( |
127 new DirectOutputSurface(context_provider, worker_context_provider)); | 144 context_provider, shared_worker_context_provider_)); |
128 } | 145 } |
129 | 146 |
130 if (surface_manager_) { | 147 if (surface_manager_) { |
131 scoped_ptr<cc::OnscreenDisplayClient> display_client( | 148 scoped_ptr<cc::OnscreenDisplayClient> display_client( |
132 new cc::OnscreenDisplayClient( | 149 new cc::OnscreenDisplayClient( |
133 real_output_surface.Pass(), surface_manager_, | 150 real_output_surface.Pass(), surface_manager_, |
134 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), | 151 GetSharedBitmapManager(), GetGpuMemoryBufferManager(), |
135 compositor->GetRendererSettings(), compositor->task_runner())); | 152 compositor->GetRendererSettings(), compositor->task_runner())); |
136 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( | 153 scoped_ptr<cc::SurfaceDisplayOutputSurface> surface_output_surface( |
137 new cc::SurfaceDisplayOutputSurface( | 154 new cc::SurfaceDisplayOutputSurface( |
138 surface_manager_, compositor->surface_id_allocator(), | 155 surface_manager_, compositor->surface_id_allocator(), |
139 context_provider, worker_context_provider)); | 156 context_provider, shared_worker_context_provider_)); |
140 display_client->set_surface_output_surface(surface_output_surface.get()); | 157 display_client->set_surface_output_surface(surface_output_surface.get()); |
141 surface_output_surface->set_display_client(display_client.get()); | 158 surface_output_surface->set_display_client(display_client.get()); |
142 | 159 |
143 compositor->SetOutputSurface(surface_output_surface.Pass()); | 160 compositor->SetOutputSurface(surface_output_surface.Pass()); |
144 | 161 |
145 delete per_compositor_data_[compositor.get()]; | 162 delete per_compositor_data_[compositor.get()]; |
146 per_compositor_data_[compositor.get()] = display_client.release(); | 163 per_compositor_data_[compositor.get()] = display_client.release(); |
147 } else { | 164 } else { |
148 compositor->SetOutputSurface(real_output_surface.Pass()); | 165 compositor->SetOutputSurface(real_output_surface.Pass()); |
149 } | 166 } |
150 } | 167 } |
151 | 168 |
152 scoped_ptr<Reflector> InProcessContextFactory::CreateReflector( | 169 scoped_ptr<Reflector> InProcessContextFactory::CreateReflector( |
153 Compositor* mirrored_compositor, | 170 Compositor* mirrored_compositor, |
154 Layer* mirroring_layer) { | 171 Layer* mirroring_layer) { |
155 return make_scoped_ptr(new FakeReflector); | 172 return make_scoped_ptr(new FakeReflector); |
156 } | 173 } |
157 | 174 |
158 void InProcessContextFactory::RemoveReflector(Reflector* reflector) { | 175 void InProcessContextFactory::RemoveReflector(Reflector* reflector) { |
159 } | 176 } |
160 | 177 |
161 scoped_refptr<cc::ContextProvider> | 178 scoped_refptr<cc::ContextProvider> |
162 InProcessContextFactory::SharedMainThreadContextProvider() { | 179 InProcessContextFactory::SharedMainThreadContextProvider() { |
163 if (shared_main_thread_contexts_.get() && | 180 if (shared_main_thread_contexts_.get() && |
164 !shared_main_thread_contexts_->DestroyedOnMainThread()) | 181 !shared_main_thread_contexts_->HasBeenLostOnMainThread()) |
165 return shared_main_thread_contexts_; | 182 return shared_main_thread_contexts_; |
166 | 183 |
167 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen( | 184 shared_main_thread_contexts_ = InProcessContextProvider::CreateOffscreen( |
168 &gpu_memory_buffer_manager_, &image_factory_); | 185 &gpu_memory_buffer_manager_, &image_factory_); |
169 if (shared_main_thread_contexts_.get() && | 186 if (shared_main_thread_contexts_.get() && |
170 !shared_main_thread_contexts_->BindToCurrentThread()) | 187 !shared_main_thread_contexts_->BindToCurrentThread()) |
171 shared_main_thread_contexts_ = NULL; | 188 shared_main_thread_contexts_ = NULL; |
172 | 189 |
173 return shared_main_thread_contexts_; | 190 return shared_main_thread_contexts_; |
174 } | 191 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 } | 229 } |
213 | 230 |
214 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 231 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
215 const gfx::Size& size) { | 232 const gfx::Size& size) { |
216 if (!per_compositor_data_.count(compositor)) | 233 if (!per_compositor_data_.count(compositor)) |
217 return; | 234 return; |
218 per_compositor_data_[compositor]->display()->Resize(size); | 235 per_compositor_data_[compositor]->display()->Resize(size); |
219 } | 236 } |
220 | 237 |
221 } // namespace ui | 238 } // namespace ui |
OLD | NEW |