SkAtlasTextRenderer.h 2.6 KB

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