test_in_process_context_provider.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2013 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. #ifndef COMPONENTS_VIZ_TEST_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_
  5. #define COMPONENTS_VIZ_TEST_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/synchronization/lock.h"
  10. #include "base/task/single_thread_task_runner.h"
  11. #include "components/viz/common/gpu/context_provider.h"
  12. #include "components/viz/common/gpu/raster_context_provider.h"
  13. #include "components/viz/test/test_gpu_memory_buffer_manager.h"
  14. #include "components/viz/test/test_image_factory.h"
  15. #include "gpu/config/gpu_feature_info.h"
  16. class GrDirectContext;
  17. namespace gpu {
  18. class GLInProcessContext;
  19. class GpuProcessActivityFlags;
  20. class RasterInProcessContext;
  21. namespace raster {
  22. class GrShaderCache;
  23. }
  24. } // namespace gpu
  25. namespace skia_bindings {
  26. class GrContextForGLES2Interface;
  27. }
  28. namespace viz {
  29. std::unique_ptr<gpu::GLInProcessContext> CreateTestInProcessContext();
  30. enum TestContextType {
  31. kGLES2, // Provides GLES2Interface.
  32. kSoftwareRaster, // Provides RasterInterface for software raster.
  33. kGpuRaster // Provides RasterInterface for GPU raster.
  34. };
  35. class TestInProcessContextProvider
  36. : public base::RefCountedThreadSafe<TestInProcessContextProvider>,
  37. public ContextProvider,
  38. public RasterContextProvider {
  39. public:
  40. explicit TestInProcessContextProvider(
  41. TestContextType type,
  42. bool support_locking,
  43. gpu::raster::GrShaderCache* gr_shader_cache = nullptr,
  44. gpu::GpuProcessActivityFlags* activity_flags = nullptr);
  45. // ContextProvider / RasterContextProvider implementation.
  46. void AddRef() const override;
  47. void Release() const override;
  48. gpu::ContextResult BindToCurrentThread() override;
  49. gpu::gles2::GLES2Interface* ContextGL() override;
  50. gpu::raster::RasterInterface* RasterInterface() override;
  51. gpu::ContextSupport* ContextSupport() override;
  52. class GrDirectContext* GrContext() override;
  53. gpu::SharedImageInterface* SharedImageInterface() override;
  54. ContextCacheController* CacheController() override;
  55. base::Lock* GetLock() override;
  56. const gpu::Capabilities& ContextCapabilities() const override;
  57. const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const override;
  58. void AddObserver(ContextLostObserver* obs) override {}
  59. void RemoveObserver(ContextLostObserver* obs) override {}
  60. void ExecuteOnGpuThread(base::OnceClosure task);
  61. protected:
  62. friend class base::RefCountedThreadSafe<TestInProcessContextProvider>;
  63. ~TestInProcessContextProvider() override;
  64. private:
  65. const TestContextType type_;
  66. raw_ptr<gpu::raster::GrShaderCache> gr_shader_cache_ = nullptr;
  67. raw_ptr<gpu::GpuProcessActivityFlags> activity_flags_ = nullptr;
  68. TestImageFactory image_factory_;
  69. gpu::Capabilities caps_;
  70. // Used for GLES2 contexts only.
  71. std::unique_ptr<gpu::GLInProcessContext> gles2_context_;
  72. std::unique_ptr<skia_bindings::GrContextForGLES2Interface> gr_context_;
  73. // Used for raster contexts only.
  74. std::unique_ptr<gpu::RasterInProcessContext> raster_context_;
  75. std::unique_ptr<ContextCacheController> cache_controller_;
  76. absl::optional<base::Lock> context_lock_;
  77. gpu::GpuFeatureInfo gpu_feature_info_;
  78. };
  79. } // namespace viz
  80. #endif // COMPONENTS_VIZ_TEST_TEST_IN_PROCESS_CONTEXT_PROVIDER_H_