| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "cc/base/switches.h" |
| 14 #include "cc/output/context_provider.h" | 15 #include "cc/output/context_provider.h" |
| 15 #include "cc/output/output_surface_client.h" | 16 #include "cc/output/output_surface_client.h" |
| 16 #include "cc/output/output_surface_frame.h" | 17 #include "cc/output/output_surface_frame.h" |
| 17 #include "cc/output/texture_mailbox_deleter.h" | 18 #include "cc/output/texture_mailbox_deleter.h" |
| 18 #include "cc/scheduler/begin_frame_source.h" | 19 #include "cc/scheduler/begin_frame_source.h" |
| 19 #include "cc/scheduler/delay_based_time_source.h" | 20 #include "cc/scheduler/delay_based_time_source.h" |
| 20 #include "cc/surfaces/direct_compositor_frame_sink.h" | 21 #include "cc/surfaces/direct_compositor_frame_sink.h" |
| 21 #include "cc/surfaces/display.h" | 22 #include "cc/surfaces/display.h" |
| 22 #include "cc/surfaces/display_scheduler.h" | 23 #include "cc/surfaces/display_scheduler.h" |
| 23 #include "cc/surfaces/local_surface_id_allocator.h" | 24 #include "cc/surfaces/local_surface_id_allocator.h" |
| 24 #include "cc/test/pixel_test_output_surface.h" | 25 #include "cc/test/pixel_test_output_surface.h" |
| 25 #include "gpu/command_buffer/client/context_support.h" | 26 #include "gpu/command_buffer/client/context_support.h" |
| 26 #include "gpu/command_buffer/client/gles2_interface.h" | 27 #include "gpu/command_buffer/client/gles2_interface.h" |
| 27 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 28 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 28 #include "ui/compositor/compositor_switches.h" | 29 #include "ui/compositor/compositor_switches.h" |
| 29 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 30 #include "ui/compositor/reflector.h" | 31 #include "ui/compositor/reflector.h" |
| 31 #include "ui/compositor/test/in_process_context_provider.h" | 32 #include "ui/compositor/test/in_process_context_provider.h" |
| 33 #include "ui/display/display_switches.h" |
| 34 #include "ui/gfx/switches.h" |
| 32 #include "ui/gl/gl_implementation.h" | 35 #include "ui/gl/gl_implementation.h" |
| 33 #include "ui/gl/test/gl_surface_test_support.h" | 36 #include "ui/gl/test/gl_surface_test_support.h" |
| 34 | 37 |
| 35 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) | 38 #if !defined(GPU_SURFACE_HANDLE_IS_ACCELERATED_WINDOW) |
| 36 #include "gpu/ipc/common/gpu_surface_tracker.h" | 39 #include "gpu/ipc/common/gpu_surface_tracker.h" |
| 37 #endif | 40 #endif |
| 38 | 41 |
| 39 namespace ui { | 42 namespace ui { |
| 40 namespace { | 43 namespace { |
| 41 // The client_id used here should not conflict with the client_id generated | 44 // The client_id used here should not conflict with the client_id generated |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 | 135 |
| 133 InProcessContextFactory::InProcessContextFactory( | 136 InProcessContextFactory::InProcessContextFactory( |
| 134 cc::SurfaceManager* surface_manager) | 137 cc::SurfaceManager* surface_manager) |
| 135 : frame_sink_id_allocator_(kDefaultClientId), | 138 : frame_sink_id_allocator_(kDefaultClientId), |
| 136 use_test_surface_(true), | 139 use_test_surface_(true), |
| 137 surface_manager_(surface_manager) { | 140 surface_manager_(surface_manager) { |
| 138 DCHECK(surface_manager); | 141 DCHECK(surface_manager); |
| 139 DCHECK_NE(gl::GetGLImplementation(), gl::kGLImplementationNone) | 142 DCHECK_NE(gl::GetGLImplementation(), gl::kGLImplementationNone) |
| 140 << "If running tests, ensure that main() is calling " | 143 << "If running tests, ensure that main() is calling " |
| 141 << "gl::GLSurfaceTestSupport::InitializeOneOff()"; | 144 << "gl::GLSurfaceTestSupport::InitializeOneOff()"; |
| 145 |
| 146 #if defined(OS_WIN) |
| 147 renderer_settings_.finish_rendering_on_resize = true; |
| 148 #elif defined(OS_MACOSX) |
| 149 renderer_settings_.release_overlay_resources_after_gpu_query = true; |
| 150 #endif |
| 151 // Populate buffer_to_texture_target_map for all buffer usage/formats. |
| 152 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); |
| 153 ++usage_idx) { |
| 154 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); |
| 155 for (int format_idx = 0; |
| 156 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); |
| 157 ++format_idx) { |
| 158 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); |
| 159 renderer_settings_ |
| 160 .buffer_to_texture_target_map[std::make_pair(usage, format)] = |
| 161 GL_TEXTURE_2D; |
| 162 } |
| 163 } |
| 142 } | 164 } |
| 143 | 165 |
| 144 InProcessContextFactory::~InProcessContextFactory() { | 166 InProcessContextFactory::~InProcessContextFactory() { |
| 145 DCHECK(per_compositor_data_.empty()); | 167 DCHECK(per_compositor_data_.empty()); |
| 146 } | 168 } |
| 147 | 169 |
| 148 void InProcessContextFactory::SendOnLostResources() { | 170 void InProcessContextFactory::SendOnLostResources() { |
| 149 for (auto& observer : observer_list_) | 171 for (auto& observer : observer_list_) |
| 150 observer.OnLostResources(); | 172 observer.OnLostResources(); |
| 151 } | 173 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 229 |
| 208 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( | 230 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( |
| 209 new cc::DelayBasedBeginFrameSource( | 231 new cc::DelayBasedBeginFrameSource( |
| 210 base::MakeUnique<cc::DelayBasedTimeSource>( | 232 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 211 compositor->task_runner().get()))); | 233 compositor->task_runner().get()))); |
| 212 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 234 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 213 compositor->task_runner().get(), | 235 compositor->task_runner().get(), |
| 214 display_output_surface->capabilities().max_frames_pending)); | 236 display_output_surface->capabilities().max_frames_pending)); |
| 215 | 237 |
| 216 data->display = base::MakeUnique<cc::Display>( | 238 data->display = base::MakeUnique<cc::Display>( |
| 217 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, | 239 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, renderer_settings_, |
| 218 compositor->GetRendererSettings(), compositor->frame_sink_id(), | 240 compositor->frame_sink_id(), begin_frame_source.get(), |
| 219 begin_frame_source.get(), std::move(display_output_surface), | 241 std::move(display_output_surface), std::move(scheduler), |
| 220 std::move(scheduler), base::MakeUnique<cc::TextureMailboxDeleter>( | 242 base::MakeUnique<cc::TextureMailboxDeleter>( |
| 221 compositor->task_runner().get())); | 243 compositor->task_runner().get())); |
| 222 // Note that we are careful not to destroy a prior |data->begin_frame_source| | 244 // Note that we are careful not to destroy a prior |data->begin_frame_source| |
| 223 // until we have reset |data->display|. | 245 // until we have reset |data->display|. |
| 224 data->begin_frame_source = std::move(begin_frame_source); | 246 data->begin_frame_source = std::move(begin_frame_source); |
| 225 | 247 |
| 226 auto* display = per_compositor_data_[compositor.get()]->display.get(); | 248 auto* display = per_compositor_data_[compositor.get()]->display.get(); |
| 227 auto compositor_frame_sink = base::MakeUnique<cc::DirectCompositorFrameSink>( | 249 auto compositor_frame_sink = base::MakeUnique<cc::DirectCompositorFrameSink>( |
| 228 compositor->frame_sink_id(), surface_manager_, display, context_provider, | 250 compositor->frame_sink_id(), surface_manager_, display, context_provider, |
| 229 shared_worker_context_provider_, &gpu_memory_buffer_manager_, | 251 shared_worker_context_provider_, &gpu_memory_buffer_manager_, |
| 230 &shared_bitmap_manager_); | 252 &shared_bitmap_manager_); |
| 231 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 253 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 if (data->surface_handle) | 290 if (data->surface_handle) |
| 269 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 291 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 270 #endif | 292 #endif |
| 271 per_compositor_data_.erase(it); | 293 per_compositor_data_.erase(it); |
| 272 } | 294 } |
| 273 | 295 |
| 274 double InProcessContextFactory::GetRefreshRate() const { | 296 double InProcessContextFactory::GetRefreshRate() const { |
| 275 return refresh_rate_; | 297 return refresh_rate_; |
| 276 } | 298 } |
| 277 | 299 |
| 278 uint32_t InProcessContextFactory::GetImageTextureTarget( | |
| 279 gfx::BufferFormat format, | |
| 280 gfx::BufferUsage usage) { | |
| 281 return GL_TEXTURE_2D; | |
| 282 } | |
| 283 | |
| 284 gpu::GpuMemoryBufferManager* | 300 gpu::GpuMemoryBufferManager* |
| 285 InProcessContextFactory::GetGpuMemoryBufferManager() { | 301 InProcessContextFactory::GetGpuMemoryBufferManager() { |
| 286 return &gpu_memory_buffer_manager_; | 302 return &gpu_memory_buffer_manager_; |
| 287 } | 303 } |
| 288 | 304 |
| 289 cc::TaskGraphRunner* InProcessContextFactory::GetTaskGraphRunner() { | 305 cc::TaskGraphRunner* InProcessContextFactory::GetTaskGraphRunner() { |
| 290 return &task_graph_runner_; | 306 return &task_graph_runner_; |
| 291 } | 307 } |
| 292 | 308 |
| 293 cc::FrameSinkId InProcessContextFactory::AllocateFrameSinkId() { | 309 cc::FrameSinkId InProcessContextFactory::AllocateFrameSinkId() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 305 per_compositor_data_[compositor]->display->SetVisible(visible); | 321 per_compositor_data_[compositor]->display->SetVisible(visible); |
| 306 } | 322 } |
| 307 | 323 |
| 308 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 324 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
| 309 const gfx::Size& size) { | 325 const gfx::Size& size) { |
| 310 if (!per_compositor_data_.count(compositor)) | 326 if (!per_compositor_data_.count(compositor)) |
| 311 return; | 327 return; |
| 312 per_compositor_data_[compositor]->display->Resize(size); | 328 per_compositor_data_[compositor]->display->Resize(size); |
| 313 } | 329 } |
| 314 | 330 |
| 331 const cc::RendererSettings& InProcessContextFactory::GetRendererSettings() |
| 332 const { |
| 333 return renderer_settings_; |
| 334 } |
| 335 |
| 315 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { | 336 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { |
| 316 observer_list_.AddObserver(observer); | 337 observer_list_.AddObserver(observer); |
| 317 } | 338 } |
| 318 | 339 |
| 319 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { | 340 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { |
| 320 observer_list_.RemoveObserver(observer); | 341 observer_list_.RemoveObserver(observer); |
| 321 } | 342 } |
| 322 | 343 |
| 323 InProcessContextFactory::PerCompositorData* | 344 InProcessContextFactory::PerCompositorData* |
| 324 InProcessContextFactory::CreatePerCompositorData(ui::Compositor* compositor) { | 345 InProcessContextFactory::CreatePerCompositorData(ui::Compositor* compositor) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 348 )); | 369 )); |
| 349 #endif | 370 #endif |
| 350 } | 371 } |
| 351 | 372 |
| 352 PerCompositorData* return_ptr = data.get(); | 373 PerCompositorData* return_ptr = data.get(); |
| 353 per_compositor_data_[compositor] = std::move(data); | 374 per_compositor_data_[compositor] = std::move(data); |
| 354 return return_ptr; | 375 return return_ptr; |
| 355 } | 376 } |
| 356 | 377 |
| 357 } // namespace ui | 378 } // namespace ui |
| OLD | NEW |