| 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 #if defined(OS_WIN) |
| 23 renderer_settings_.finish_rendering_on_resize = true; |
| 24 #elif defined(OS_MACOSX) |
| 25 renderer_settings_.release_overlay_resources_after_gpu_query = true; |
| 26 #endif |
| 27 // Populate buffer_to_texture_target_map for all buffer usage/formats. |
| 28 for (int usage_idx = 0; usage_idx <= static_cast<int>(gfx::BufferUsage::LAST); |
| 29 ++usage_idx) { |
| 30 gfx::BufferUsage usage = static_cast<gfx::BufferUsage>(usage_idx); |
| 31 for (int format_idx = 0; |
| 32 format_idx <= static_cast<int>(gfx::BufferFormat::LAST); |
| 33 ++format_idx) { |
| 34 gfx::BufferFormat format = static_cast<gfx::BufferFormat>(format_idx); |
| 35 renderer_settings_ |
| 36 .buffer_to_texture_target_map[std::make_pair(usage, format)] = |
| 37 GL_TEXTURE_2D; |
| 38 } |
| 39 } |
| 40 } |
| 41 |
| 42 FakeContextFactory::~FakeContextFactory() = default; |
| 43 |
| 16 const cc::CompositorFrame& FakeContextFactory::GetLastCompositorFrame() const { | 44 const cc::CompositorFrame& FakeContextFactory::GetLastCompositorFrame() const { |
| 17 return *frame_sink_->last_sent_frame(); | 45 return *frame_sink_->last_sent_frame(); |
| 18 } | 46 } |
| 19 | 47 |
| 20 void FakeContextFactory::CreateCompositorFrameSink( | 48 void FakeContextFactory::CreateCompositorFrameSink( |
| 21 base::WeakPtr<ui::Compositor> compositor) { | 49 base::WeakPtr<ui::Compositor> compositor) { |
| 22 auto frame_sink = cc::FakeCompositorFrameSink::Create3d(); | 50 auto frame_sink = cc::FakeCompositorFrameSink::Create3d(); |
| 23 frame_sink_ = frame_sink.get(); | 51 frame_sink_ = frame_sink.get(); |
| 24 compositor->SetCompositorFrameSink(std::move(frame_sink)); | 52 compositor->SetCompositorFrameSink(std::move(frame_sink)); |
| 25 } | 53 } |
| 26 | 54 |
| 27 scoped_refptr<cc::ContextProvider> | 55 scoped_refptr<cc::ContextProvider> |
| 28 FakeContextFactory::SharedMainThreadContextProvider() { | 56 FakeContextFactory::SharedMainThreadContextProvider() { |
| 29 return nullptr; | 57 return nullptr; |
| 30 } | 58 } |
| 31 | 59 |
| 32 void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) { | 60 void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) { |
| 33 frame_sink_ = nullptr; | 61 frame_sink_ = nullptr; |
| 34 } | 62 } |
| 35 | 63 |
| 36 double FakeContextFactory::GetRefreshRate() const { | 64 double FakeContextFactory::GetRefreshRate() const { |
| 37 return 200.0; | 65 return 200.0; |
| 38 } | 66 } |
| 39 | 67 |
| 40 uint32_t FakeContextFactory::GetImageTextureTarget(gfx::BufferFormat format, | |
| 41 gfx::BufferUsage usage) { | |
| 42 return GL_TEXTURE_2D; | |
| 43 } | |
| 44 | |
| 45 gpu::GpuMemoryBufferManager* FakeContextFactory::GetGpuMemoryBufferManager() { | 68 gpu::GpuMemoryBufferManager* FakeContextFactory::GetGpuMemoryBufferManager() { |
| 46 return &gpu_memory_buffer_manager_; | 69 return &gpu_memory_buffer_manager_; |
| 47 } | 70 } |
| 48 | 71 |
| 49 cc::TaskGraphRunner* FakeContextFactory::GetTaskGraphRunner() { | 72 cc::TaskGraphRunner* FakeContextFactory::GetTaskGraphRunner() { |
| 50 return &task_graph_runner_; | 73 return &task_graph_runner_; |
| 51 } | 74 } |
| 52 | 75 |
| 76 const cc::RendererSettings& FakeContextFactory::GetRendererSettings() const { |
| 77 return renderer_settings_; |
| 78 } |
| 79 |
| 53 } // namespace ui | 80 } // namespace ui |
| OLD | NEW |