Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/fake_context_factory.h" | 5 #include "ui/compositor/test/fake_context_factory.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "cc/base/switches.h" | |
| 8 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 9 #include "cc/output/compositor_frame_sink_client.h" | 11 #include "cc/output/compositor_frame_sink_client.h" |
| 10 #include "cc/scheduler/begin_frame_source.h" | 12 #include "cc/scheduler/begin_frame_source.h" |
| 11 #include "cc/scheduler/delay_based_time_source.h" | 13 #include "cc/scheduler/delay_based_time_source.h" |
| 12 #include "cc/test/fake_compositor_frame_sink.h" | 14 #include "cc/test/fake_compositor_frame_sink.h" |
| 15 #include "ui/compositor/compositor_switches.h" | |
| 16 #include "ui/display/display_switches.h" | |
| 17 #include "ui/gfx/switches.h" | |
| 13 | 18 |
| 14 namespace ui { | 19 namespace ui { |
| 15 | 20 |
| 21 FakeContextFactory::FakeContextFactory() { | |
| 22 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 23 renderer_settings_.partial_swap_enabled = | |
|
danakj
2017/05/11 15:17:15
Most of these are not needed for tests, I would ma
Alex Z.
2017/05/11 19:25:22
I set it to default values since nothing using eit
danakj
2017/05/11 20:10:16
I think test code not using switches sounds good.
| |
| 24 !command_line->HasSwitch(switches::kUIDisablePartialSwap); | |
| 25 #if defined(OS_WIN) | |
| 26 renderer_settings_.finish_rendering_on_resize = true; | |
| 27 #elif defined(OS_MACOSX) | |
| 28 renderer_settings_.release_overlay_resources_after_gpu_query = true; | |
| 29 #endif | |
| 30 renderer_settings_.gl_composited_texture_quad_border = | |
| 31 command_line->HasSwitch(cc::switches::kGlCompositedTextureQuadBorder); | |
| 32 renderer_settings_.show_overdraw_feedback = | |
| 33 command_line->HasSwitch(cc::switches::kShowOverdrawFeedback); | |
| 34 if (command_line->HasSwitch(switches::kUIEnableRGBA4444Textures)) | |
| 35 renderer_settings_.preferred_tile_format = cc::RGBA_4444; | |
| 36 renderer_settings_.enable_color_correct_rendering = | |
| 37 command_line->HasSwitch(switches::kEnableColorCorrectRendering) || | |
| 38 command_line->HasSwitch(switches::kEnableHDR); | |
| 39 // Populate buffer_to_texture_target_map for all buffer usage/formats. | |
| 40 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); | |
| 41 ++usage_idx) { | |
| 42 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); | |
| 43 for (int format_idx = 0; | |
| 44 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); | |
| 45 ++format_idx) { | |
| 46 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); | |
| 47 uint32_t target = GL_TEXTURE_2D; | |
| 48 renderer_settings_ | |
| 49 .buffer_to_texture_target_map[std::make_pair(usage, format)] = target; | |
| 50 } | |
| 51 } | |
| 52 renderer_settings_.disallow_non_exact_resource_reuse = | |
| 53 command_line->HasSwitch(cc::switches::kDisallowNonExactResourceReuse); | |
| 54 } | |
| 55 | |
| 56 FakeContextFactory::~FakeContextFactory() = default; | |
| 57 | |
| 16 const cc::CompositorFrame& FakeContextFactory::GetLastCompositorFrame() const { | 58 const cc::CompositorFrame& FakeContextFactory::GetLastCompositorFrame() const { |
| 17 return *frame_sink_->last_sent_frame(); | 59 return *frame_sink_->last_sent_frame(); |
| 18 } | 60 } |
| 19 | 61 |
| 20 void FakeContextFactory::CreateCompositorFrameSink( | 62 void FakeContextFactory::CreateCompositorFrameSink( |
| 21 base::WeakPtr<ui::Compositor> compositor) { | 63 base::WeakPtr<ui::Compositor> compositor) { |
| 22 auto frame_sink = cc::FakeCompositorFrameSink::Create3d(); | 64 auto frame_sink = cc::FakeCompositorFrameSink::Create3d(); |
| 23 frame_sink_ = frame_sink.get(); | 65 frame_sink_ = frame_sink.get(); |
| 24 compositor->SetCompositorFrameSink(std::move(frame_sink)); | 66 compositor->SetCompositorFrameSink(std::move(frame_sink)); |
| 25 } | 67 } |
| 26 | 68 |
| 27 scoped_refptr<cc::ContextProvider> | 69 scoped_refptr<cc::ContextProvider> |
| 28 FakeContextFactory::SharedMainThreadContextProvider() { | 70 FakeContextFactory::SharedMainThreadContextProvider() { |
| 29 return nullptr; | 71 return nullptr; |
| 30 } | 72 } |
| 31 | 73 |
| 32 void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) { | 74 void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 33 frame_sink_ = nullptr; | 75 frame_sink_ = nullptr; |
| 34 } | 76 } |
| 35 | 77 |
| 36 double FakeContextFactory::GetRefreshRate() const { | 78 double FakeContextFactory::GetRefreshRate() const { |
| 37 return 200.0; | 79 return 200.0; |
| 38 } | 80 } |
| 39 | 81 |
| 40 uint32_t FakeContextFactory::GetImageTextureTarget(gfx::BufferFormat format, | |
| 41 gfx::BufferUsage usage) { | |
| 42 return GL_TEXTURE_2D; | |
| 43 } | |
| 44 | |
| 45 gpu::GpuMemoryBufferManager* FakeContextFactory::GetGpuMemoryBufferManager() { | 82 gpu::GpuMemoryBufferManager* FakeContextFactory::GetGpuMemoryBufferManager() { |
| 46 return &gpu_memory_buffer_manager_; | 83 return &gpu_memory_buffer_manager_; |
| 47 } | 84 } |
| 48 | 85 |
| 49 cc::TaskGraphRunner* FakeContextFactory::GetTaskGraphRunner() { | 86 cc::TaskGraphRunner* FakeContextFactory::GetTaskGraphRunner() { |
| 50 return &task_graph_runner_; | 87 return &task_graph_runner_; |
| 51 } | 88 } |
| 52 | 89 |
| 90 const cc::RendererSettings& FakeContextFactory::GetRendererSettings() const { | |
| 91 return renderer_settings_; | |
| 92 } | |
| 93 | |
| 53 } // namespace ui | 94 } // namespace ui |
| OLD | NEW |