context.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright (c) 2011 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_GLES2_CONFORM_SUPPORT_EGL_CONTEXT_H_
  5. #define GPU_GLES2_CONFORM_SUPPORT_EGL_CONTEXT_H_
  6. #include <memory>
  7. #include <EGL/egl.h>
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/ref_counted.h"
  10. #include "gpu/command_buffer/client/gles2_cmd_helper.h"
  11. #include "gpu/command_buffer/client/gpu_control.h"
  12. #include "gpu/command_buffer/service/command_buffer_direct.h"
  13. #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
  14. #include "gpu/command_buffer/service/gpu_tracer.h"
  15. #include "gpu/command_buffer/service/mailbox_manager_impl.h"
  16. #include "gpu/command_buffer/service/passthrough_discardable_manager.h"
  17. #include "gpu/command_buffer/service/service_discardable_manager.h"
  18. #include "gpu/command_buffer/service/shared_image/shared_image_manager.h"
  19. #include "gpu/config/gpu_driver_bug_workarounds.h"
  20. #include "gpu/config/gpu_preferences.h"
  21. #include "ui/gfx/native_widget_types.h"
  22. #include "ui/gl/gl_context.h"
  23. #include "ui/gl/gl_surface.h"
  24. namespace gpu {
  25. class ServiceDiscardableManager;
  26. class TransferBuffer;
  27. namespace gles2 {
  28. class GLES2CmdHelper;
  29. class GLES2Interface;
  30. } // namespace gles2
  31. } // namespace gpu
  32. namespace gles2_conform_support {
  33. namespace egl {
  34. class Display;
  35. class Surface;
  36. class Config;
  37. class Context : public base::RefCountedThreadSafe<Context>,
  38. public gpu::GpuControl {
  39. public:
  40. Context(Display* display, const Config* config);
  41. Context(const Context&) = delete;
  42. Context& operator=(const Context&) = delete;
  43. bool is_current_in_some_thread() const { return is_current_in_some_thread_; }
  44. void set_is_current_in_some_thread(bool flag) {
  45. is_current_in_some_thread_ = flag;
  46. }
  47. void MarkDestroyed();
  48. bool SwapBuffers(Surface* current_surface);
  49. static bool MakeCurrent(Context* current_context,
  50. Surface* current_surface,
  51. Context* new_context,
  52. Surface* new_surface);
  53. static bool ValidateAttributeList(const EGLint* attrib_list);
  54. // GpuControl implementation.
  55. void SetGpuControlClient(gpu::GpuControlClient*) override;
  56. const gpu::Capabilities& GetCapabilities() const override;
  57. void SignalQuery(uint32_t query, base::OnceClosure callback) override;
  58. void CreateGpuFence(uint32_t gpu_fence_id, ClientGpuFence source) override;
  59. void GetGpuFence(uint32_t gpu_fence_id,
  60. base::OnceCallback<void(std::unique_ptr<gfx::GpuFence>)>
  61. callback) override;
  62. void SetLock(base::Lock*) override;
  63. void EnsureWorkVisible() override;
  64. gpu::CommandBufferNamespace GetNamespaceID() const override;
  65. gpu::CommandBufferId GetCommandBufferID() const override;
  66. void FlushPendingWork() override;
  67. uint64_t GenerateFenceSyncRelease() override;
  68. bool IsFenceSyncReleased(uint64_t release) override;
  69. void SignalSyncToken(const gpu::SyncToken& sync_token,
  70. base::OnceClosure callback) override;
  71. void WaitSyncToken(const gpu::SyncToken& sync_token) override;
  72. bool CanWaitUnverifiedSyncToken(const gpu::SyncToken& sync_token) override;
  73. // Called by ThreadState to set the needed global variables when this context
  74. // is current.
  75. void ApplyCurrentContext(gl::GLSurface* current_surface);
  76. static void ApplyContextReleased();
  77. static void SetPlatformGpuFeatureInfo(
  78. const gpu::GpuFeatureInfo& gpu_feature_info);
  79. private:
  80. friend class base::RefCountedThreadSafe<Context>;
  81. ~Context() override;
  82. bool CreateService(gl::GLSurface* gl_surface);
  83. void DestroyService();
  84. // Returns true if the object has GL service, either a working one or one
  85. // that has lost its GL context.
  86. bool HasService() const;
  87. void MarkServiceContextLost();
  88. bool WasServiceContextLost() const;
  89. bool IsCompatibleSurface(Surface* surface) const;
  90. bool Flush(gl::GLSurface* gl_surface);
  91. static gpu::GpuFeatureInfo platform_gpu_feature_info_;
  92. raw_ptr<Display> display_;
  93. raw_ptr<const Config> config_;
  94. bool is_current_in_some_thread_;
  95. bool is_destroyed_;
  96. const gpu::GpuDriverBugWorkarounds gpu_driver_bug_workarounds_;
  97. std::unique_ptr<gpu::CommandBufferDirect> command_buffer_;
  98. std::unique_ptr<gpu::gles2::GLES2CmdHelper> gles2_cmd_helper_;
  99. gpu::gles2::MailboxManagerImpl mailbox_manager_;
  100. gpu::gles2::TraceOutputter outputter_;
  101. gpu::ServiceDiscardableManager discardable_manager_;
  102. gpu::PassthroughDiscardableManager passthrough_discardable_manager_;
  103. gpu::SharedImageManager shared_image_manager_;
  104. gpu::gles2::ShaderTranslatorCache translator_cache_;
  105. gpu::gles2::FramebufferCompletenessCache completeness_cache_;
  106. std::unique_ptr<gpu::gles2::GLES2Decoder> decoder_;
  107. std::unique_ptr<gpu::TransferBuffer> transfer_buffer_;
  108. scoped_refptr<gl::GLContext> gl_context_;
  109. std::unique_ptr<gpu::gles2::GLES2Interface> client_gl_context_;
  110. gpu::Capabilities capabilities_;
  111. };
  112. } // namespace egl
  113. } // namespace gles2_conform_support
  114. #endif // GPU_GLES2_CONFORM_SUPPORT_EGL_CONTEXT_H_