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