• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GrContext;
17 class GrStrikeCache;
18 class GrTextBlobCache;
19 
20 class SkAtlasTextRenderer;
21 class SkMatrix;
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 
renderer()33     SkAtlasTextRenderer* renderer() const { return fRenderer.get(); }
34 
grContext()35     GrContext* grContext() const { return fGrContext.get(); }
36     GrStrikeCache* glyphCache();
37     GrTextBlobCache* textBlobCache();
38 
tokenTracker()39     const GrTokenTracker* tokenTracker() final { return &fTokenTracker; }
40     GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final;
41     GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
42 
43     void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
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 
74     GrTokenTracker fTokenTracker;
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
84