diff options
author | Brian Salomon <bsalomon@google.com> | 2017-11-17 14:18:12 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-17 20:35:06 +0000 |
commit | 39631f3df172feb385527a5d125bc53b0bded7e6 (patch) | |
tree | f63361075ecc24f709d379c976b080d4d54949aa /src/atlastext/SkInternalAtlasTextContext.h | |
parent | e686cc4efadec7606b3df0f1e4133011d68b10b3 (diff) |
Add Atlas Text interface for rendering SDF glyphs.
This new API is built upon SDF text atlas code from the GPU backend. Unlike using the GPU
backend to draw text, this set of interfaces allows the client to render the SDF glyphs. The
client issues text draws to potentially multiple targets and then the client flushes. The
client then gets commands from Skia with data to put into a texture atlas and vertices to
draw that reference the texture. The client is responsible for creating the texture, uploading
the SDF data to the texture, and drawing the vertices provided by Skia.
Change-Id: Ie9447e19b85f0ce1c2b942e5216c787a74f335d3
Reviewed-on: https://skia-review.googlesource.com/59360
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/atlastext/SkInternalAtlasTextContext.h')
-rw-r--r-- | src/atlastext/SkInternalAtlasTextContext.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/atlastext/SkInternalAtlasTextContext.h b/src/atlastext/SkInternalAtlasTextContext.h new file mode 100644 index 0000000000..1bb12cee5a --- /dev/null +++ b/src/atlastext/SkInternalAtlasTextContext.h @@ -0,0 +1,80 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkInternalAtlasTextContext_DEFINED +#define SkInternalAtlasTextContext_DEFINED + +#include "GrDeferredUpload.h" +#include "SkArenaAlloc.h" +#include "SkArenaAllocList.h" +#include "SkRefCnt.h" + +class SkAtlasTextRenderer; +class GrContext; +class GrAtlasGlyphCache; +class GrTextBlobCache; + +/** + * The implementation of SkAtlasTextContext. This exists to hide the details from the public class. + * and to be able to use other private types. + */ +class SkInternalAtlasTextContext : public GrDeferredUploadTarget { +public: + static std::unique_ptr<SkInternalAtlasTextContext> Make(sk_sp<SkAtlasTextRenderer>); + + ~SkInternalAtlasTextContext() override; + + SkAtlasTextRenderer* renderer() const { return fRenderer.get(); } + + GrContext* grContext() const { return fGrContext.get(); } + GrAtlasGlyphCache* atlasGlyphCache(); + GrTextBlobCache* textBlobCache(); + + GrDeferredUploadToken addInlineUpload(GrDeferredTextureUploadFn&&) override; + + GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) override; + + void recordDraw(const void* vertexData, int glyphCnt, void* targetHandle); + + void flush(); + +private: + class DeferredUploader; + SkInternalAtlasTextContext() = delete; + SkInternalAtlasTextContext(const SkInternalAtlasTextContext&) = delete; + SkInternalAtlasTextContext& operator=(const SkInternalAtlasTextContext&) = delete; + + SkInternalAtlasTextContext(sk_sp<SkAtlasTextRenderer>); + + sk_sp<SkAtlasTextRenderer> fRenderer; + + struct AtlasTexture { + void* fTextureHandle = nullptr; + GrTextureProxy* fProxy = nullptr; + }; + + struct Draw { + int fGlyphCnt; + GrDeferredUploadToken fToken; + void* fTargetHandle; + const void* fVertexData; + }; + + struct InlineUpload { + GrDeferredTextureUploadFn fUpload; + GrDeferredUploadToken fToken; + }; + + SkArenaAllocList<InlineUpload> fInlineUploads; + SkArenaAllocList<Draw> fDraws; + SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads; + SkArenaAlloc fArena{1024 * 40}; + sk_sp<GrContext> fGrContext; + AtlasTexture fDistanceFieldAtlas; +}; + +#endif |