Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 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; |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 17 | class SkMatrix; |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 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 | |
| 32 | SkAtlasTextRenderer* renderer() const { return fRenderer.get(); } |
| 33 | |
| 34 | GrContext* grContext() const { return fGrContext.get(); } |
| 35 | GrAtlasGlyphCache* atlasGlyphCache(); |
| 36 | GrTextBlobCache* textBlobCache(); |
| 37 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame^] | 38 | const GrTokenTracker* tokenTracker() final { return &fTokenTracker; } |
| 39 | GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final; |
| 40 | GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final; |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 41 | |
Brian Salomon | b508696 | 2017-12-13 10:59:33 -0500 | [diff] [blame] | 42 | void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle); |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 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 | |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame^] | 73 | GrTokenTracker fTokenTracker; |
Brian Salomon | cbcb0a1 | 2017-11-19 13:20:13 -0500 | [diff] [blame] | 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 |