Chromium Code Reviews| 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 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
|
danakj
2017/05/11 15:17:15
same here regarding tests
Alex Z.
2017/05/11 19:25:22
Done.
| |
| 147 renderer_settings_.partial_swap_enabled = | |
| 148 !command_line->HasSwitch(switches::kUIDisablePartialSwap); | |
| 149 #if defined(OS_WIN) | |
| 150 renderer_settings_.finish_rendering_on_resize = true; | |
| 151 #elif defined(OS_MACOSX) | |
| 152 renderer_settings_.release_overlay_resources_after_gpu_query = true; | |
| 153 #endif | |
| 154 renderer_settings_.gl_composited_texture_quad_border = | |
| 155 command_line->HasSwitch(cc::switches::kGlCompositedTextureQuadBorder); | |
| 156 renderer_settings_.show_overdraw_feedback = | |
| 157 command_line->HasSwitch(cc::switches::kShowOverdrawFeedback); | |
| 158 if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) | |
| 159 renderer_settings_.preferred_tile_format = cc::RGBA_4444; | |
| 160 renderer_settings_.enable_color_correct_rendering = | |
| 161 command_line->HasSwitch(switches::kEnableColorCorrectRendering) || | |
| 162 command_line->HasSwitch(switches::kEnableHDR); | |
| 163 // Populate buffer_to_texture_target_map for all buffer usage/formats. | |
| 164 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); | |
| 165 ++usage_idx) { | |
| 166 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); | |
| 167 for (int format_idx = 0; | |
| 168 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); | |
| 169 ++format_idx) { | |
| 170 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); | |
| 171 uint32_t target = GL_TEXTURE_2D; | |
| 172 renderer_settings_ | |
| 173 .buffer_to_texture_target_map[std::make_pair(usage, format)] = target; | |
| 174 } | |
| 175 } | |
| 176 renderer_settings_.disallow_non_exact_resource_reuse = | |
| 177 command_line->HasSwitch(cc::switches::kDisallowNonExactResourceReuse); | |
| 142 } | 178 } |
| 143 | 179 |
| 144 InProcessContextFactory::~InProcessContextFactory() { | 180 InProcessContextFactory::~InProcessContextFactory() { |
| 145 DCHECK(per_compositor_data_.empty()); | 181 DCHECK(per_compositor_data_.empty()); |
| 146 } | 182 } |
| 147 | 183 |
| 148 void InProcessContextFactory::SendOnLostResources() { | 184 void InProcessContextFactory::SendOnLostResources() { |
| 149 for (auto& observer : observer_list_) | 185 for (auto& observer : observer_list_) |
| 150 observer.OnLostResources(); | 186 observer.OnLostResources(); |
| 151 } | 187 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 | 243 |
| 208 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( | 244 std::unique_ptr<cc::DelayBasedBeginFrameSource> begin_frame_source( |
| 209 new cc::DelayBasedBeginFrameSource( | 245 new cc::DelayBasedBeginFrameSource( |
| 210 base::MakeUnique<cc::DelayBasedTimeSource>( | 246 base::MakeUnique<cc::DelayBasedTimeSource>( |
| 211 compositor->task_runner().get()))); | 247 compositor->task_runner().get()))); |
| 212 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( | 248 std::unique_ptr<cc::DisplayScheduler> scheduler(new cc::DisplayScheduler( |
| 213 compositor->task_runner().get(), | 249 compositor->task_runner().get(), |
| 214 display_output_surface->capabilities().max_frames_pending)); | 250 display_output_surface->capabilities().max_frames_pending)); |
| 215 | 251 |
| 216 data->display = base::MakeUnique<cc::Display>( | 252 data->display = base::MakeUnique<cc::Display>( |
| 217 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, | 253 &shared_bitmap_manager_, &gpu_memory_buffer_manager_, renderer_settings_, |
| 218 compositor->GetRendererSettings(), compositor->frame_sink_id(), | 254 compositor->frame_sink_id(), begin_frame_source.get(), |
| 219 begin_frame_source.get(), std::move(display_output_surface), | 255 std::move(display_output_surface), std::move(scheduler), |
| 220 std::move(scheduler), base::MakeUnique<cc::TextureMailboxDeleter>( | 256 base::MakeUnique<cc::TextureMailboxDeleter>( |
| 221 compositor->task_runner().get())); | 257 compositor->task_runner().get())); |
| 222 // Note that we are careful not to destroy a prior |data->begin_frame_source| | 258 // Note that we are careful not to destroy a prior |data->begin_frame_source| |
| 223 // until we have reset |data->display|. | 259 // until we have reset |data->display|. |
| 224 data->begin_frame_source = std::move(begin_frame_source); | 260 data->begin_frame_source = std::move(begin_frame_source); |
| 225 | 261 |
| 226 auto* display = per_compositor_data_[compositor.get()]->display.get(); | 262 auto* display = per_compositor_data_[compositor.get()]->display.get(); |
| 227 auto compositor_frame_sink = base::MakeUnique<cc::DirectCompositorFrameSink>( | 263 auto compositor_frame_sink = base::MakeUnique<cc::DirectCompositorFrameSink>( |
| 228 compositor->frame_sink_id(), surface_manager_, display, context_provider, | 264 compositor->frame_sink_id(), surface_manager_, display, context_provider, |
| 229 shared_worker_context_provider_, &gpu_memory_buffer_manager_, | 265 shared_worker_context_provider_, &gpu_memory_buffer_manager_, |
| 230 &shared_bitmap_manager_); | 266 &shared_bitmap_manager_); |
| 231 compositor->SetCompositorFrameSink(std::move(compositor_frame_sink)); | 267 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) | 304 if (data->surface_handle) |
| 269 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); | 305 gpu::GpuSurfaceTracker::Get()->RemoveSurface(data->surface_handle); |
| 270 #endif | 306 #endif |
| 271 per_compositor_data_.erase(it); | 307 per_compositor_data_.erase(it); |
| 272 } | 308 } |
| 273 | 309 |
| 274 double InProcessContextFactory::GetRefreshRate() const { | 310 double InProcessContextFactory::GetRefreshRate() const { |
| 275 return refresh_rate_; | 311 return refresh_rate_; |
| 276 } | 312 } |
| 277 | 313 |
| 278 uint32_t InProcessContextFactory::GetImageTextureTarget( | |
| 279 gfx::BufferFormat format, | |
| 280 gfx::BufferUsage usage) { | |
| 281 return GL_TEXTURE_2D; | |
| 282 } | |
| 283 | |
| 284 gpu::GpuMemoryBufferManager* | 314 gpu::GpuMemoryBufferManager* |
| 285 InProcessContextFactory::GetGpuMemoryBufferManager() { | 315 InProcessContextFactory::GetGpuMemoryBufferManager() { |
| 286 return &gpu_memory_buffer_manager_; | 316 return &gpu_memory_buffer_manager_; |
| 287 } | 317 } |
| 288 | 318 |
| 289 cc::TaskGraphRunner* InProcessContextFactory::GetTaskGraphRunner() { | 319 cc::TaskGraphRunner* InProcessContextFactory::GetTaskGraphRunner() { |
| 290 return &task_graph_runner_; | 320 return &task_graph_runner_; |
| 291 } | 321 } |
| 292 | 322 |
| 293 cc::FrameSinkId InProcessContextFactory::AllocateFrameSinkId() { | 323 cc::FrameSinkId InProcessContextFactory::AllocateFrameSinkId() { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 305 per_compositor_data_[compositor]->display->SetVisible(visible); | 335 per_compositor_data_[compositor]->display->SetVisible(visible); |
| 306 } | 336 } |
| 307 | 337 |
| 308 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, | 338 void InProcessContextFactory::ResizeDisplay(ui::Compositor* compositor, |
| 309 const gfx::Size& size) { | 339 const gfx::Size& size) { |
| 310 if (!per_compositor_data_.count(compositor)) | 340 if (!per_compositor_data_.count(compositor)) |
| 311 return; | 341 return; |
| 312 per_compositor_data_[compositor]->display->Resize(size); | 342 per_compositor_data_[compositor]->display->Resize(size); |
| 313 } | 343 } |
| 314 | 344 |
| 345 const cc::RendererSettings& InProcessContextFactory::GetRendererSettings() | |
| 346 const { | |
| 347 return renderer_settings_; | |
| 348 } | |
| 349 | |
| 315 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { | 350 void InProcessContextFactory::AddObserver(ContextFactoryObserver* observer) { |
| 316 observer_list_.AddObserver(observer); | 351 observer_list_.AddObserver(observer); |
| 317 } | 352 } |
| 318 | 353 |
| 319 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { | 354 void InProcessContextFactory::RemoveObserver(ContextFactoryObserver* observer) { |
| 320 observer_list_.RemoveObserver(observer); | 355 observer_list_.RemoveObserver(observer); |
| 321 } | 356 } |
| 322 | 357 |
| 323 InProcessContextFactory::PerCompositorData* | 358 InProcessContextFactory::PerCompositorData* |
| 324 InProcessContextFactory::CreatePerCompositorData(ui::Compositor* compositor) { | 359 InProcessContextFactory::CreatePerCompositorData(ui::Compositor* compositor) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 348 )); | 383 )); |
| 349 #endif | 384 #endif |
| 350 } | 385 } |
| 351 | 386 |
| 352 PerCompositorData* return_ptr = data.get(); | 387 PerCompositorData* return_ptr = data.get(); |
| 353 per_compositor_data_[compositor] = std::move(data); | 388 per_compositor_data_[compositor] = std::move(data); |
| 354 return return_ptr; | 389 return return_ptr; |
| 355 } | 390 } |
| 356 | 391 |
| 357 } // namespace ui | 392 } // namespace ui |
| OLD | NEW |