IPlatformRenderInterface.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Avalonia.Media;
  5. using Avalonia.Media.Imaging;
  6. using Avalonia.Media.TextFormatting;
  7. using Avalonia.Metadata;
  8. namespace Avalonia.Platform
  9. {
  10. /// <summary>
  11. /// Defines the main platform-specific interface for the rendering subsystem.
  12. /// </summary>
  13. [Unstable]
  14. public interface IPlatformRenderInterface
  15. {
  16. /// <summary>
  17. /// Creates an ellipse geometry implementation.
  18. /// </summary>
  19. /// <param name="rect">The bounds of the ellipse.</param>
  20. /// <returns>An ellipse geometry..</returns>
  21. IGeometryImpl CreateEllipseGeometry(Rect rect);
  22. /// <summary>
  23. /// Creates a line geometry implementation.
  24. /// </summary>
  25. /// <param name="p1">The start of the line.</param>
  26. /// <param name="p2">The end of the line.</param>
  27. /// <returns>A line geometry.</returns>
  28. IGeometryImpl CreateLineGeometry(Point p1, Point p2);
  29. /// <summary>
  30. /// Creates a rectangle geometry implementation.
  31. /// </summary>
  32. /// <param name="rect">The bounds of the rectangle.</param>
  33. /// <returns>A rectangle.</returns>
  34. IGeometryImpl CreateRectangleGeometry(Rect rect);
  35. /// <summary>
  36. /// Creates a stream geometry implementation.
  37. /// </summary>
  38. /// <returns>An <see cref="IStreamGeometryImpl"/>.</returns>
  39. IStreamGeometryImpl CreateStreamGeometry();
  40. /// <summary>
  41. /// Creates a geometry group implementation.
  42. /// </summary>
  43. /// <param name="fillRule">The fill rule.</param>
  44. /// <param name="children">The geometries to group.</param>
  45. /// <returns>A combined geometry.</returns>
  46. IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<IGeometryImpl> children);
  47. /// <summary>
  48. /// Creates a geometry group implementation.
  49. /// </summary>
  50. /// <param name="combineMode">The combine mode</param>
  51. /// <param name="g1">The first geometry.</param>
  52. /// <param name="g2">The second geometry.</param>
  53. /// <returns>A combined geometry.</returns>
  54. IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, IGeometryImpl g1, IGeometryImpl g2);
  55. /// <summary>
  56. /// Created a geometry implementation for the glyph run.
  57. /// </summary>
  58. /// <param name="glyphRun">The glyph run to build a geometry from.</param>
  59. /// <returns>The geometry returned contains the combined geometry of all glyphs in the glyph run.</returns>
  60. IGeometryImpl BuildGlyphRunGeometry(GlyphRun glyphRun);
  61. /// <summary>
  62. /// Creates a render target bitmap implementation.
  63. /// </summary>
  64. /// <param name="size">The size of the bitmap in device pixels.</param>
  65. /// <param name="dpi">The DPI of the bitmap.</param>
  66. /// <returns>An <see cref="IRenderTargetBitmapImpl"/>.</returns>
  67. IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi);
  68. /// <summary>
  69. /// Creates a writeable bitmap implementation.
  70. /// </summary>
  71. /// <param name="size">The size of the bitmap in device pixels.</param>
  72. /// <param name="dpi">The DPI of the bitmap.</param>
  73. /// <param name="format">Pixel format.</param>
  74. /// <param name="alphaFormat">Alpha format .</param>
  75. /// <returns>An <see cref="IWriteableBitmapImpl"/>.</returns>
  76. IWriteableBitmapImpl CreateWriteableBitmap(PixelSize size, Vector dpi, PixelFormat format, AlphaFormat alphaFormat);
  77. /// <summary>
  78. /// Loads a bitmap implementation from a file..
  79. /// </summary>
  80. /// <param name="fileName">The filename of the bitmap.</param>
  81. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  82. IBitmapImpl LoadBitmap(string fileName);
  83. /// <summary>
  84. /// Loads a bitmap implementation from a file..
  85. /// </summary>
  86. /// <param name="stream">The stream to read the bitmap from.</param>
  87. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  88. IBitmapImpl LoadBitmap(Stream stream);
  89. /// <summary>
  90. /// Loads a WriteableBitmap implementation from a stream to a specified width maintaining aspect ratio.
  91. /// </summary>
  92. /// <param name="stream">The stream to read the bitmap from.</param>
  93. /// <param name="width">The desired width of the resulting bitmap.</param>
  94. /// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
  95. /// <returns>An <see cref="IWriteableBitmapImpl"/>.</returns>
  96. IWriteableBitmapImpl LoadWriteableBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
  97. /// <summary>
  98. /// Loads a WriteableBitmap implementation from a stream to a specified height maintaining aspect ratio.
  99. /// </summary>
  100. /// <param name="stream">The stream to read the bitmap from.</param>
  101. /// <param name="height">The desired height of the resulting bitmap.</param>
  102. /// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
  103. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  104. IWriteableBitmapImpl LoadWriteableBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
  105. /// <summary>
  106. /// Loads a WriteableBitmap implementation from a file.
  107. /// </summary>
  108. /// <param name="fileName">The filename of the bitmap.</param>
  109. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  110. IWriteableBitmapImpl LoadWriteableBitmap(string fileName);
  111. /// <summary>
  112. /// Loads a WriteableBitmap implementation from a file.
  113. /// </summary>
  114. /// <param name="stream">The stream to read the bitmap from.</param>
  115. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  116. IWriteableBitmapImpl LoadWriteableBitmap(Stream stream);
  117. /// <summary>
  118. /// Loads a bitmap implementation from a stream to a specified width maintaining aspect ratio.
  119. /// </summary>
  120. /// <param name="stream">The stream to read the bitmap from.</param>
  121. /// <param name="width">The desired width of the resulting bitmap.</param>
  122. /// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
  123. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  124. IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
  125. /// <summary>
  126. /// Loads a bitmap implementation from a stream to a specified height maintaining aspect ratio.
  127. /// </summary>
  128. /// <param name="stream">The stream to read the bitmap from.</param>
  129. /// <param name="height">The desired height of the resulting bitmap.</param>
  130. /// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
  131. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  132. IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
  133. IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
  134. /// <summary>
  135. /// Loads a bitmap implementation from a pixels in memory.
  136. /// </summary>
  137. /// <param name="format">The pixel format.</param>
  138. /// <param name="alphaFormat">The alpha format.</param>
  139. /// <param name="data">The pointer to source bytes.</param>
  140. /// <param name="size">The size of the bitmap in device pixels.</param>
  141. /// <param name="dpi">The DPI of the bitmap.</param>
  142. /// <param name="stride">The number of bytes per row.</param>
  143. /// <returns>An <see cref="IBitmapImpl"/>.</returns>
  144. IBitmapImpl LoadBitmap(PixelFormat format, AlphaFormat alphaFormat, IntPtr data, PixelSize size, Vector dpi, int stride);
  145. /// <summary>
  146. /// Creates a platform implementation of a glyph run.
  147. /// </summary>
  148. /// <param name="glyphTypeface">The glyph typeface.</param>
  149. /// <param name="fontRenderingEmSize">The font rendering em size.</param>
  150. /// <param name="glyphInfos">The list of glyphs.</param>
  151. /// <param name="baselineOrigin">The baseline origin of the run. Can be null.</param>
  152. /// <returns>An <see cref="IGlyphRunImpl"/>.</returns>
  153. IGlyphRunImpl CreateGlyphRun(IGlyphTypeface glyphTypeface, double fontRenderingEmSize, IReadOnlyList<GlyphInfo> glyphInfos, Point baselineOrigin);
  154. /// <summary>
  155. /// Creates a backend-specific object using a low-level API graphics context
  156. /// </summary>
  157. /// <param name="graphicsApiContext">An underlying low-level graphics context (e. g. wrapped OpenGL context, Vulkan device, D3DDevice, etc)</param>
  158. /// <returns></returns>
  159. IPlatformRenderInterfaceContext CreateBackendContext(IPlatformGraphicsContext? graphicsApiContext);
  160. /// <summary>
  161. /// Gets a value indicating whether the platform directly supports rectangles with rounded corners.
  162. /// </summary>
  163. /// <remarks>
  164. /// Some platform renderers can't directly handle rounded corners on rectangles.
  165. /// In this case, code that requires rounded corners must generate and retain a geometry instead.
  166. /// </remarks>
  167. bool SupportsIndividualRoundRects { get; }
  168. /// <summary>
  169. /// Default <see cref="AlphaFormat"/> used on this platform.
  170. /// </summary>
  171. public AlphaFormat DefaultAlphaFormat { get; }
  172. /// <summary>
  173. /// Default <see cref="PixelFormat"/> used on this platform.
  174. /// </summary>
  175. public PixelFormat DefaultPixelFormat { get; }
  176. bool IsSupportedBitmapPixelFormat(PixelFormat format);
  177. }
  178. [Unstable]
  179. public interface IPlatformRenderInterfaceContext : IOptionalFeatureProvider, IDisposable
  180. {
  181. /// <summary>
  182. /// Creates a renderer.
  183. /// </summary>
  184. /// <param name="surfaces">
  185. /// The list of native platform surfaces that can be used for output.
  186. /// </param>
  187. /// <returns>An <see cref="IRenderTarget"/>.</returns>
  188. IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces);
  189. /// <summary>
  190. /// Indicates that the context is no longer usable. This method should be thread-safe
  191. /// </summary>
  192. bool IsLost { get; }
  193. }
  194. }