grcontext_for_webgpu_interface.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 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_SKIA_BINDINGS_GRCONTEXT_FOR_WEBGPU_INTERFACE_H_
  5. #define GPU_SKIA_BINDINGS_GRCONTEXT_FOR_WEBGPU_INTERFACE_H_
  6. #include "base/memory/raw_ptr.h"
  7. #include "third_party/skia/include/core/SkRefCnt.h"
  8. #include "third_party/skia/include/gpu/GrContextOptions.h"
  9. class GrDirectContext;
  10. namespace gpu {
  11. struct Capabilities;
  12. class ContextSupport;
  13. namespace webgpu {
  14. class WebGPUInterface;
  15. }
  16. } // namespace gpu
  17. namespace skia_bindings {
  18. // This class binds an offscreen GrContext to a WebGPU Device. The Device is
  19. // used by the GrContext so must be valid as long as this class is alive.
  20. class GrContextForWebGPUInterface
  21. : public GrContextOptions::ShaderErrorHandler {
  22. public:
  23. GrContextForWebGPUInterface(gpu::webgpu::WebGPUInterface* webgpu,
  24. gpu::ContextSupport* context_support,
  25. const gpu::Capabilities& capabilities,
  26. size_t max_resource_cache_bytes,
  27. size_t max_glyph_cache_texture_bytes);
  28. GrContextForWebGPUInterface(const GrContextForWebGPUInterface&) = delete;
  29. GrContextForWebGPUInterface& operator=(const GrContextForWebGPUInterface&) =
  30. delete;
  31. ~GrContextForWebGPUInterface() override;
  32. // GrContextOptions::ShaderErrorHandler implementation
  33. // Handles Skia-reported shader compilation errors.
  34. void compileError(const char* shader, const char* errors) override;
  35. GrDirectContext* get();
  36. private:
  37. sk_sp<class GrDirectContext> gr_context_;
  38. raw_ptr<gpu::ContextSupport> context_support_;
  39. };
  40. } // namespace skia_bindings
  41. #endif // GPU_SKIA_BINDINGS_GRCONTEXT_FOR_WEBGPU_INTERFACE_H_