blob: 49a55cce15e702d6b47adfb89fefdbc78f86da68 [file] [log] [blame]
Brian Salomoncbcb0a12017-11-19 13:20:13 -05001/*
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
16class SkAtlasTextRenderer;
Brian Salomonb5086962017-12-13 10:59:33 -050017class SkMatrix;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050018class GrContext;
19class GrAtlasGlyphCache;
20class 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 */
26class SkInternalAtlasTextContext : public GrDeferredUploadTarget {
27public:
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 Phillips40a29d72018-01-18 12:59:22 -050038 const GrTokenTracker* tokenTracker() final { return &fTokenTracker; }
39 GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final;
40 GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050041
Brian Salomonb5086962017-12-13 10:59:33 -050042 void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
Brian Salomoncbcb0a12017-11-19 13:20:13 -050043
44 void flush();
45
46private:
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 Phillips40a29d72018-01-18 12:59:22 -050073 GrTokenTracker fTokenTracker;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050074 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