SkInternalAtlasTextContext.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 SkInternalAtlasTextContext_DEFINED
  8. #define SkInternalAtlasTextContext_DEFINED
  9. #include "include/core/SkRefCnt.h"
  10. #include "src/core/SkArenaAlloc.h"
  11. #include "src/core/SkArenaAllocList.h"
  12. #include "src/gpu/GrDeferredUpload.h"
  13. class GrContext;
  14. class GrStrikeCache;
  15. class GrTextBlobCache;
  16. class SkAtlasTextRenderer;
  17. class SkMatrix;
  18. /**
  19. * The implementation of SkAtlasTextContext. This exists to hide the details from the public class.
  20. * and to be able to use other private types.
  21. */
  22. class SkInternalAtlasTextContext : public GrDeferredUploadTarget {
  23. public:
  24. static std::unique_ptr<SkInternalAtlasTextContext> Make(sk_sp<SkAtlasTextRenderer>);
  25. ~SkInternalAtlasTextContext() override;
  26. SkAtlasTextRenderer* renderer() const { return fRenderer.get(); }
  27. GrContext* grContext() const { return fGrContext.get(); }
  28. GrStrikeCache* glyphCache();
  29. GrTextBlobCache* textBlobCache();
  30. const GrTokenTracker* tokenTracker() final { return &fTokenTracker; }
  31. GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final;
  32. GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
  33. void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
  34. void flush();
  35. private:
  36. class DeferredUploader;
  37. SkInternalAtlasTextContext() = delete;
  38. SkInternalAtlasTextContext(const SkInternalAtlasTextContext&) = delete;
  39. SkInternalAtlasTextContext& operator=(const SkInternalAtlasTextContext&) = delete;
  40. SkInternalAtlasTextContext(sk_sp<SkAtlasTextRenderer>);
  41. sk_sp<SkAtlasTextRenderer> fRenderer;
  42. struct AtlasTexture {
  43. void* fTextureHandle = nullptr;
  44. GrTextureProxy* fProxy = nullptr;
  45. };
  46. struct Draw {
  47. int fGlyphCnt;
  48. GrDeferredUploadToken fToken;
  49. void* fTargetHandle;
  50. const void* fVertexData;
  51. };
  52. struct InlineUpload {
  53. GrDeferredTextureUploadFn fUpload;
  54. GrDeferredUploadToken fToken;
  55. };
  56. GrTokenTracker fTokenTracker;
  57. SkArenaAllocList<InlineUpload> fInlineUploads;
  58. SkArenaAllocList<Draw> fDraws;
  59. SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads;
  60. SkArenaAlloc fArena{1024 * 40};
  61. sk_sp<GrContext> fGrContext;
  62. AtlasTexture fDistanceFieldAtlas;
  63. };
  64. #endif