MockPlatformRenderInterface.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Avalonia.Media;
  5. using Avalonia.Platform;
  6. using Avalonia.Media.Imaging;
  7. using Avalonia.Media.TextFormatting;
  8. using Avalonia.Rendering;
  9. using Moq;
  10. namespace Avalonia.UnitTests
  11. {
  12. public class MockPlatformRenderInterface : IPlatformRenderInterface, IPlatformRenderInterfaceContext
  13. {
  14. public IGeometryImpl CreateEllipseGeometry(Rect rect)
  15. {
  16. return Mock.Of<IGeometryImpl>();
  17. }
  18. public IGeometryImpl CreateLineGeometry(Point p1, Point p2)
  19. {
  20. return Mock.Of<IGeometryImpl>();
  21. }
  22. public IGeometryImpl CreateRectangleGeometry(Rect rect)
  23. {
  24. return Mock.Of<IGeometryImpl>(x => x.Bounds == rect);
  25. }
  26. class MockRenderTarget : IRenderTarget
  27. {
  28. public void Dispose()
  29. {
  30. }
  31. public IDrawingContextImpl CreateDrawingContext()
  32. {
  33. var m = new Mock<IDrawingContextImpl>();
  34. m.Setup(c => c.CreateLayer(It.IsAny<Size>()))
  35. .Returns(() =>
  36. {
  37. var r = new Mock<IDrawingContextLayerImpl>();
  38. r.Setup(r => r.CreateDrawingContext())
  39. .Returns(CreateDrawingContext());
  40. return r.Object;
  41. }
  42. );
  43. return m.Object;
  44. }
  45. public bool IsCorrupted => false;
  46. }
  47. public IRenderTarget CreateRenderTarget(IEnumerable<object> surfaces)
  48. {
  49. return new MockRenderTarget();
  50. }
  51. public bool IsLost => false;
  52. public object TryGetFeature(Type featureType) => null;
  53. public IRenderTargetBitmapImpl CreateRenderTargetBitmap(PixelSize size, Vector dpi)
  54. {
  55. return Mock.Of<IRenderTargetBitmapImpl>();
  56. }
  57. public IStreamGeometryImpl CreateStreamGeometry()
  58. {
  59. return new MockStreamGeometryImpl();
  60. }
  61. public IGeometryImpl CreateGeometryGroup(FillRule fillRule, IReadOnlyList<Geometry> children)
  62. {
  63. return Mock.Of<IGeometryImpl>();
  64. }
  65. public IGeometryImpl CreateCombinedGeometry(GeometryCombineMode combineMode, Geometry g1, Geometry g2)
  66. {
  67. return Mock.Of<IGeometryImpl>();
  68. }
  69. public IWriteableBitmapImpl CreateWriteableBitmap(
  70. PixelSize size,
  71. Vector dpi,
  72. PixelFormat format,
  73. AlphaFormat alphaFormat)
  74. {
  75. throw new NotImplementedException();
  76. }
  77. public IBitmapImpl LoadBitmap(Stream stream)
  78. {
  79. return Mock.Of<IBitmapImpl>();
  80. }
  81. public IWriteableBitmapImpl LoadWriteableBitmapToWidth(Stream stream, int width,
  82. BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  83. {
  84. throw new NotImplementedException();
  85. }
  86. public IWriteableBitmapImpl LoadWriteableBitmapToHeight(Stream stream, int height,
  87. BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  88. {
  89. throw new NotImplementedException();
  90. }
  91. public IWriteableBitmapImpl LoadWriteableBitmap(string fileName)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public IWriteableBitmapImpl LoadWriteableBitmap(Stream stream)
  96. {
  97. throw new NotImplementedException();
  98. }
  99. public IBitmapImpl LoadBitmap(string fileName)
  100. {
  101. return Mock.Of<IBitmapImpl>();
  102. }
  103. public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  104. {
  105. return Mock.Of<IBitmapImpl>();
  106. }
  107. public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  108. {
  109. return Mock.Of<IBitmapImpl>();
  110. }
  111. public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
  112. {
  113. return Mock.Of<IBitmapImpl>();
  114. }
  115. public IBitmapImpl LoadBitmap(
  116. PixelFormat format,
  117. AlphaFormat alphaFormat,
  118. IntPtr data,
  119. PixelSize size,
  120. Vector dpi,
  121. int stride)
  122. {
  123. throw new NotImplementedException();
  124. }
  125. public IGlyphRunImpl CreateGlyphRun(IGlyphTypeface glyphTypeface, double fontRenderingEmSize,
  126. IReadOnlyList<GlyphInfo> glyphInfos, Point baselineOrigin)
  127. {
  128. return new MockGlyphRun(glyphInfos);
  129. }
  130. public IPlatformRenderInterfaceContext CreateBackendContext(IPlatformGraphicsContext graphicsContext) => this;
  131. public IGeometryImpl BuildGlyphRunGeometry(GlyphRun glyphRun)
  132. {
  133. return Mock.Of<IGeometryImpl>();
  134. }
  135. public IGlyphRunBuffer AllocateGlyphRun(IGlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  136. {
  137. return Mock.Of<IGlyphRunBuffer>();
  138. }
  139. public IHorizontalGlyphRunBuffer AllocateHorizontalGlyphRun(IGlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  140. {
  141. return Mock.Of<IHorizontalGlyphRunBuffer>();
  142. }
  143. public IPositionedGlyphRunBuffer AllocatePositionedGlyphRun(IGlyphTypeface glyphTypeface, float fontRenderingEmSize, int length)
  144. {
  145. return Mock.Of<IPositionedGlyphRunBuffer>();
  146. }
  147. public bool SupportsIndividualRoundRects { get; set; }
  148. public AlphaFormat DefaultAlphaFormat => AlphaFormat.Premul;
  149. public PixelFormat DefaultPixelFormat => PixelFormat.Rgba8888;
  150. public bool IsSupportedBitmapPixelFormat(PixelFormat format) => true;
  151. public void Dispose()
  152. {
  153. }
  154. }
  155. }