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