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