GrContextThreadSafeProxy.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2019 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrContextThreadSafeProxy_DEFINED
  8. #define GrContextThreadSafeProxy_DEFINED
  9. #include "include/private/GrContext_Base.h"
  10. class GrBackendFormat;
  11. class GrContextThreadSafeProxyPriv;
  12. struct SkImageInfo;
  13. class SkSurfaceCharacterization;
  14. /**
  15. * Can be used to perform actions related to the generating GrContext in a thread safe manner. The
  16. * proxy does not access the 3D API (e.g. OpenGL) that backs the generating GrContext.
  17. */
  18. class SK_API GrContextThreadSafeProxy : public GrContext_Base {
  19. public:
  20. ~GrContextThreadSafeProxy() override;
  21. /**
  22. * Create a surface characterization for a DDL that will be replayed into the GrContext
  23. * that created this proxy. On failure the resulting characterization will be invalid (i.e.,
  24. * "!c.isValid()").
  25. *
  26. * @param cacheMaxResourceBytes The max resource bytes limit that will be in effect when the
  27. * DDL created with this characterization is replayed.
  28. * Note: the contract here is that the DDL will be created as
  29. * if it had a full 'cacheMaxResourceBytes' to use. If replayed
  30. * into a GrContext that already has locked GPU memory, the
  31. * replay can exceed the budget. To rephrase, all resource
  32. * allocation decisions are made at record time and at playback
  33. * time the budget limits will be ignored.
  34. * @param ii The image info specifying properties of the SkSurface that
  35. * the DDL created with this characterization will be replayed
  36. * into.
  37. * Note: Ganesh doesn't make use of the SkImageInfo's alphaType
  38. * @param backendFormat Information about the format of the GPU surface that will
  39. * back the SkSurface upon replay
  40. * @param sampleCount The sample count of the SkSurface that the DDL created with
  41. * this characterization will be replayed into
  42. * @param origin The origin of the SkSurface that the DDL created with this
  43. * characterization will be replayed into
  44. * @param surfaceProps The surface properties of the SkSurface that the DDL created
  45. * with this characterization will be replayed into
  46. * @param isMipMapped Will the surface the DDL will be replayed into have space
  47. * allocated for mipmaps?
  48. * @param willUseGLFBO0 Will the surface the DDL will be replayed into be backed by GL
  49. * FBO 0. This flag is only valid if using an GL backend.
  50. * @param isTextureable Will the surface be able to act as a texture?
  51. * @param isProtected Will the (Vulkan) surface be DRM protected?
  52. */
  53. SkSurfaceCharacterization createCharacterization(
  54. size_t cacheMaxResourceBytes,
  55. const SkImageInfo& ii, const GrBackendFormat& backendFormat,
  56. int sampleCount, GrSurfaceOrigin origin,
  57. const SkSurfaceProps& surfaceProps,
  58. bool isMipMapped,
  59. bool willUseGLFBO0 = false,
  60. bool isTextureable = true,
  61. GrProtected isProtected = GrProtected::kNo);
  62. bool operator==(const GrContextThreadSafeProxy& that) const {
  63. // Each GrContext should only ever have a single thread-safe proxy.
  64. SkASSERT((this == &that) == (this->contextID() == that.contextID()));
  65. return this == &that;
  66. }
  67. bool operator!=(const GrContextThreadSafeProxy& that) const { return !(*this == that); }
  68. // Provides access to functions that aren't part of the public API.
  69. GrContextThreadSafeProxyPriv priv();
  70. const GrContextThreadSafeProxyPriv priv() const;
  71. private:
  72. friend class GrContextThreadSafeProxyPriv; // for ctor and hidden methods
  73. // DDL TODO: need to add unit tests for backend & maybe options
  74. GrContextThreadSafeProxy(GrBackendApi, const GrContextOptions&, uint32_t contextID);
  75. bool init(sk_sp<const GrCaps>, sk_sp<GrSkSLFPFactoryCache>) override;
  76. typedef GrContext_Base INHERITED;
  77. };
  78. #endif