MockPlatformRenderInterface.cs 6.0 KB

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