test_context_factories.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/compositor/test/test_context_factories.h"
  5. #include "base/command_line.h"
  6. #include "components/viz/common/features.h"
  7. #include "components/viz/host/host_frame_sink_manager.h"
  8. #include "components/viz/service/display_embedder/server_shared_bitmap_manager.h"
  9. #include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
  10. #include "ui/compositor/compositor_switches.h"
  11. #include "ui/compositor/test/in_process_context_factory.h"
  12. #include "ui/gl/gl_implementation.h"
  13. namespace ui {
  14. TestContextFactories::TestContextFactories(bool enable_pixel_output,
  15. bool output_to_window) {
  16. auto* command_line = base::CommandLine::ForCurrentProcess();
  17. if (command_line->HasSwitch(switches::kEnablePixelOutputInTests))
  18. enable_pixel_output = true;
  19. if (enable_pixel_output)
  20. disable_null_draw_ = std::make_unique<gl::DisableNullDrawGLBindings>();
  21. shared_bitmap_manager_ = std::make_unique<viz::ServerSharedBitmapManager>();
  22. frame_sink_manager_ = std::make_unique<viz::FrameSinkManagerImpl>(
  23. viz::FrameSinkManagerImpl::InitParams(shared_bitmap_manager_.get()));
  24. host_frame_sink_manager_ = std::make_unique<viz::HostFrameSinkManager>();
  25. implicit_factory_ = std::make_unique<InProcessContextFactory>(
  26. host_frame_sink_manager_.get(), frame_sink_manager_.get(),
  27. output_to_window);
  28. implicit_factory_->SetUseFastRefreshRateForTests();
  29. // Directly connect without using Mojo.
  30. frame_sink_manager_->SetLocalClient(host_frame_sink_manager_.get());
  31. host_frame_sink_manager_->SetLocalManager(frame_sink_manager_.get());
  32. }
  33. TestContextFactories::~TestContextFactories() = default;
  34. ContextFactory* TestContextFactories::GetContextFactory() const {
  35. return implicit_factory_.get();
  36. }
  37. } // namespace ui