blob: 22cda5ca51aa61939d39978aa91f6e9ffefa8613 [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
Robert Phillipse4fda6c2018-02-21 12:10:41 -050016class GrContext;
Robert Phillipsc4039ea2018-03-01 11:36:45 -050017class GrGlyphCache;
Robert Phillipse4fda6c2018-02-21 12:10:41 -050018class GrTextBlobCache;
19
Brian Salomoncbcb0a12017-11-19 13:20:13 -050020class SkAtlasTextRenderer;
Brian Salomonb5086962017-12-13 10:59:33 -050021class SkMatrix;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050022
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 */
27class SkInternalAtlasTextContext : public GrDeferredUploadTarget {
28public:
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 Phillipsc4039ea2018-03-01 11:36:45 -050036 GrGlyphCache* glyphCache();
Brian Salomoncbcb0a12017-11-19 13:20:13 -050037 GrTextBlobCache* textBlobCache();
38
Robert Phillips40a29d72018-01-18 12:59:22 -050039 const GrTokenTracker* tokenTracker() final { return &fTokenTracker; }
40 GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) final;
41 GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050042
Brian Salomonb5086962017-12-13 10:59:33 -050043 void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
Brian Salomoncbcb0a12017-11-19 13:20:13 -050044
45 void flush();
46
47private:
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 Phillips40a29d72018-01-18 12:59:22 -050074 GrTokenTracker fTokenTracker;
Brian Salomoncbcb0a12017-11-19 13:20:13 -050075 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