IPlatformRenderInterface.cs 11 KB

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