GrOnFlushResourceProvider.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2017 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 GrOnFlushResourceProvider_DEFINED
  8. #define GrOnFlushResourceProvider_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "include/private/SkTArray.h"
  11. #include "src/gpu/GrDeferredUpload.h"
  12. #include "src/gpu/GrOpFlushState.h"
  13. #include "src/gpu/GrResourceProvider.h"
  14. class GrDrawingManager;
  15. class GrOpList;
  16. class GrOnFlushResourceProvider;
  17. class GrRenderTargetOpList;
  18. class GrRenderTargetContext;
  19. class GrSurfaceProxy;
  20. class SkColorSpace;
  21. class SkSurfaceProps;
  22. /*
  23. * This is the base class from which all pre-flush callback objects must be derived. It
  24. * provides the "preFlush" / "postFlush" interface.
  25. */
  26. class GrOnFlushCallbackObject {
  27. public:
  28. virtual ~GrOnFlushCallbackObject() {}
  29. /*
  30. * The onFlush callback allows subsystems (e.g., text, path renderers) to create atlases
  31. * for a specific flush. All the GrOpList IDs required for the flush are passed into the
  32. * callback. The callback should return the render target contexts used to render the atlases
  33. * in 'results'.
  34. */
  35. virtual void preFlush(GrOnFlushResourceProvider*,
  36. const uint32_t* opListIDs, int numOpListIDs,
  37. SkTArray<sk_sp<GrRenderTargetContext>>* results) = 0;
  38. /**
  39. * Called once flushing is complete and all ops indicated by preFlush have been executed and
  40. * released. startTokenForNextFlush can be used to track resources used in the current flush.
  41. */
  42. virtual void postFlush(GrDeferredUploadToken startTokenForNextFlush,
  43. const uint32_t* opListIDs, int numOpListIDs) {}
  44. /**
  45. * Tells the callback owner to hold onto this object when freeing GPU resources
  46. *
  47. * In particular, GrDrawingManager::freeGPUResources() deletes all the path renderers.
  48. * Any OnFlushCallbackObject associated with a path renderer will need to be deleted.
  49. */
  50. virtual bool retainOnFreeGpuResources() { return false; }
  51. };
  52. /*
  53. * This class is a shallow wrapper around the drawing manager. It is passed into the
  54. * onFlush callbacks and is intended to limit the functionality available to them.
  55. * It should never have additional data members or virtual methods.
  56. */
  57. class GrOnFlushResourceProvider {
  58. public:
  59. explicit GrOnFlushResourceProvider(GrDrawingManager* drawingMgr) : fDrawingMgr(drawingMgr) {}
  60. sk_sp<GrRenderTargetContext> makeRenderTargetContext(sk_sp<GrSurfaceProxy>,
  61. GrColorType,
  62. sk_sp<SkColorSpace>,
  63. const SkSurfaceProps*);
  64. // Proxy unique key management. See GrProxyProvider.h.
  65. bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
  66. void removeUniqueKeyFromProxy(GrTextureProxy*);
  67. void processInvalidUniqueKey(const GrUniqueKey&);
  68. sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
  69. bool instatiateProxy(GrSurfaceProxy*);
  70. // Creates a GPU buffer with a "dynamic" access pattern.
  71. sk_sp<GrGpuBuffer> makeBuffer(GrGpuBufferType, size_t, const void* data = nullptr);
  72. // Either finds and refs, or creates a static GPU buffer with the given data.
  73. sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType, size_t, const void* data,
  74. const GrUniqueKey&);
  75. uint32_t contextID() const;
  76. const GrCaps* caps() const;
  77. private:
  78. GrOnFlushResourceProvider(const GrOnFlushResourceProvider&) = delete;
  79. GrOnFlushResourceProvider& operator=(const GrOnFlushResourceProvider&) = delete;
  80. GrDrawingManager* fDrawingMgr;
  81. };
  82. #endif