• 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 #include "include/core/SkPoint3.h"
9 #include "include/core/SkRefCnt.h"
10 
11 #ifndef SkAtlasTextRenderer_DEFINED
12 #define SkAtlasTextRenderer_DEFINED
13 
14 /**
15  * This is the base class for a renderer implemented by the SkAtlasText client. The
16  * SkAtlasTextContext issues texture creations, deletions, uploads, and vertex draws to the
17  * renderer. The renderer must perform those actions in the order called to correctly render
18  * the text drawn to SkAtlasTextTargets.
19  */
20 class SK_API SkAtlasTextRenderer : public SkRefCnt {
21 public:
22     enum class AtlasFormat {
23         /** Unsigned normalized 8 bit single channel format. */
24         kA8
25     };
26 
27     struct SDFVertex {
28         /** Position in device space (not normalized). The third component is w (not z). */
29         SkPoint3 fPosition;
30         /** Color, same value for all four corners of a glyph quad. */
31         uint32_t fColor;
32         /** Texture coordinate (in texel units, not normalized). */
33         int16_t fTextureCoordX;
34         int16_t fTextureCoordY;
35     };
36 
37     virtual ~SkAtlasTextRenderer() = default;
38 
39     /**
40      * Create a texture of the provided format with dimensions 'width' x 'height'
41      * and return a unique handle.
42      */
43     virtual void* createTexture(AtlasFormat, int width, int height) = 0;
44 
45     /**
46      * Delete the texture with the passed handle.
47      */
48     virtual void deleteTexture(void* textureHandle) = 0;
49 
50     /**
51      * Place the pixel data specified by 'data' in the texture with handle
52      * 'textureHandle' in the rectangle ['x', 'x' + 'width') x ['y', 'y' + 'height').
53      * 'rowBytes' specifies the byte offset between successive rows in 'data' and will always be
54      * a multiple of the number of bytes per pixel.
55      * The pixel format of data is the same as that of 'textureHandle'.
56      */
57     virtual void setTextureData(void* textureHandle, const void* data, int x, int y, int width,
58                                 int height, size_t rowBytes) = 0;
59 
60     /**
61      * Draws glyphs using SDFs. The SDF data resides in 'textureHandle'. The array
62      * 'vertices' provides interleaved device-space positions, colors, and
63      * texture coordinates. There are are 4 * 'quadCnt' entries in 'vertices'.
64      */
65     virtual void drawSDFGlyphs(void* targetHandle, void* textureHandle, const SDFVertex vertices[],
66                                int quadCnt) = 0;
67 
68     /** Called when a SkAtlasTextureTarget is destroyed. */
69     virtual void targetDeleted(void* targetHandle) = 0;
70 };
71 
72 #endif
73