in_process_gpu_thread_holder.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2018 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 GPU_IPC_IN_PROCESS_GPU_THREAD_HOLDER_H_
  5. #define GPU_IPC_IN_PROCESS_GPU_THREAD_HOLDER_H_
  6. #include <memory>
  7. #include "base/component_export.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "base/threading/thread.h"
  10. #include "gpu/command_buffer/service/shared_context_state.h"
  11. #include "gpu/config/gpu_feature_info.h"
  12. #include "gpu/config/gpu_preferences.h"
  13. #include "gpu/ipc/gpu_in_process_thread_service.h"
  14. namespace gpu {
  15. class CommandBufferTaskExecutor;
  16. class MailboxManager;
  17. class Scheduler;
  18. class SharedImageManager;
  19. class SyncPointManager;
  20. // Starts a GPU thread and task executor that runs tasks on the GPU thread. This
  21. // isn't a full GPU thread implementation and should only be used in tests. A
  22. // default GpuPreferences and GpuFeatureInfo will be constructed from the
  23. // command line when this class is first created.
  24. class COMPONENT_EXPORT(GPU_THREAD_HOLDER) InProcessGpuThreadHolder
  25. : public base::Thread,
  26. public GpuInProcessThreadServiceDelegate {
  27. public:
  28. InProcessGpuThreadHolder();
  29. InProcessGpuThreadHolder(const InProcessGpuThreadHolder&) = delete;
  30. InProcessGpuThreadHolder& operator=(const InProcessGpuThreadHolder&) = delete;
  31. ~InProcessGpuThreadHolder() override;
  32. // Returns GpuPreferences that can be modified before GetTaskExecutor() is
  33. // called for the first time.
  34. GpuPreferences* GetGpuPreferences();
  35. // Returns GpuFeatureInfo that can be modified before GetTaskExecutor() is
  36. // called for the first time.
  37. GpuFeatureInfo* GetGpuFeatureInfo();
  38. // Returns a task executor that runs commands on the GPU thread. The task
  39. // executor will be created the first time this is called.
  40. CommandBufferTaskExecutor* GetTaskExecutor();
  41. // gpu::GpuInProcessThreadServiceDelegate implementation:
  42. scoped_refptr<gpu::SharedContextState> GetSharedContextState() override;
  43. scoped_refptr<gl::GLShareGroup> GetShareGroup() override;
  44. private:
  45. void InitializeOnGpuThread(base::WaitableEvent* completion);
  46. void DeleteOnGpuThread();
  47. GpuPreferences gpu_preferences_;
  48. GpuFeatureInfo gpu_feature_info_;
  49. scoped_refptr<gl::GLShareGroup> share_group_;
  50. scoped_refptr<gl::GLSurface> surface_;
  51. scoped_refptr<gl::GLContext> context_;
  52. scoped_refptr<SharedContextState> context_state_;
  53. std::unique_ptr<SyncPointManager> sync_point_manager_;
  54. std::unique_ptr<Scheduler> scheduler_;
  55. std::unique_ptr<MailboxManager> mailbox_manager_;
  56. std::unique_ptr<SharedImageManager> shared_image_manager_;
  57. std::unique_ptr<CommandBufferTaskExecutor> task_executor_;
  58. };
  59. } // namespace gpu
  60. #endif // GPU_IPC_IN_PROCESS_GPU_THREAD_HOLDER_H_