blob: ea8943558003dc0aa7600586c0ac5223e0ce7e22 [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
38 GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) override;
39
40 GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) override;
41
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
73 SkArenaAllocList<InlineUpload> fInlineUploads;
74 SkArenaAllocList<Draw> fDraws;
75 SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads;
76 SkArenaAlloc fArena{1024 * 40};
77 sk_sp<GrContext> fGrContext;
78 AtlasTexture fDistanceFieldAtlas;
79};
80
81#endif