1 // 2 // Copyright (c) 2010-2021 Antmicro 3 // Copyright (c) 2020-2021 Microsoft 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 9 using System; 10 using System.Collections.Generic; 11 using Antmicro.Renode.Backends.Display; 12 13 namespace Antmicro.Renode.Peripherals.DMA 14 { 15 // ordering of entry is taken from the documentation and should not be altered! 16 internal enum Dma2DColorMode 17 { 18 ARGB8888, 19 RGB888, 20 RGB565, 21 ARGB1555, 22 ARGB4444, 23 L8, 24 AL44, 25 AL88, 26 L4, 27 A8, 28 A4 29 } 30 31 // ordering of entry is taken from the documentation and should not be altered! 32 internal enum Dma2DAlphaMode 33 { 34 NoModification, 35 Replace, 36 Combine 37 } 38 39 internal static class Dma2DColorModeExtensions 40 { Dma2DColorModeExtensions()41 static Dma2DColorModeExtensions() 42 { 43 cache = new Dictionary<Dma2DColorMode, PixelFormat>(); 44 foreach(Dma2DColorMode mode in Enum.GetValues(typeof(Dma2DColorMode))) 45 { 46 PixelFormat format; 47 if(!Enum.TryParse(mode.ToString(), out format)) 48 { 49 throw new ArgumentException(string.Format("Could not find pixel format matching DMA2D color mode: {0}", mode)); 50 } 51 52 cache[mode] = format; 53 } 54 } 55 ToPixelFormat(this Dma2DColorMode mode)56 public static PixelFormat ToPixelFormat(this Dma2DColorMode mode) 57 { 58 PixelFormat result; 59 if(!cache.TryGetValue(mode, out result)) 60 { 61 throw new ArgumentException(string.Format("Unsupported color mode: {0}", mode)); 62 } 63 64 return result; 65 } 66 67 private static Dictionary<Dma2DColorMode, PixelFormat> cache; 68 } 69 70 internal static class Dma2DAlphaModeExtensions 71 { ToPixelBlendingMode(this Dma2DAlphaMode mode)72 public static PixelBlendingMode ToPixelBlendingMode(this Dma2DAlphaMode mode) 73 { 74 switch(mode) 75 { 76 case Dma2DAlphaMode.NoModification: 77 return PixelBlendingMode.NoModification; 78 case Dma2DAlphaMode.Replace: 79 return PixelBlendingMode.Replace; 80 case Dma2DAlphaMode.Combine: 81 return PixelBlendingMode.Multiply; 82 } 83 return PixelBlendingMode.NoModification; 84 } 85 } 86 } 87 88