types.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2019 David Forsgren Piuva
  4. //
  5. // This software is provided 'as-is', without any express or implied
  6. // warranty. In no event will the authors be held liable for any damages
  7. // arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it
  11. // freely, subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented; you must not
  14. // claim that you wrote the original software. If you use this software
  15. // in a product, an acknowledgment in the product documentation would be
  16. // appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such, and must not be
  19. // misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. #ifndef DFPSR_API_TYPES
  24. #define DFPSR_API_TYPES
  25. #include <stdint.h>
  26. #include <memory>
  27. #include "../image/Color.h"
  28. #include "../math/IRect.h"
  29. #include "../base/text.h"
  30. #ifdef DFPSR_INTERNAL_ACCESS
  31. #define IMPL_ACCESS public
  32. #else
  33. #define IMPL_ACCESS protected
  34. #endif
  35. namespace dsr {
  36. enum class PackOrderIndex {
  37. RGBA, // Windows
  38. BGRA, // Ubuntu
  39. ARGB,
  40. ABGR
  41. };
  42. enum class Sampler {
  43. Nearest,
  44. Linear
  45. };
  46. enum class ReturnCode {
  47. Good,
  48. KeyNotFound,
  49. ParsingFailure
  50. };
  51. // A handle to a model.
  52. class ModelImpl;
  53. using Model = std::shared_ptr<ModelImpl>;
  54. // A handle to a multi-threaded rendering context.
  55. class RendererImpl;
  56. using Renderer = std::shared_ptr<RendererImpl>;
  57. // A handle to a window.
  58. // The Window wraps itself around native window backends to abstract away platform specific details.
  59. // It also makes it easy to load and use a graphical interface using the optional component system.
  60. class DsrWindow;
  61. using Window = std::shared_ptr<DsrWindow>;
  62. // A handle to a GUI component.
  63. // Components are an abstraction for graphical user interfaces, which might not always be powerful enough.
  64. // * If you're making something advanced that components cannot do,
  65. // you can also use draw calls and input events directly against the window without using Component.
  66. class VisualComponent;
  67. using Component = std::shared_ptr<VisualComponent>;
  68. // A handle to a GUI theme.
  69. // Themes describes the visual appearance of an interface.
  70. // By having more than one theme for your interface, you can let the user select one.
  71. class VisualThemeImpl;
  72. using VisualTheme = std::shared_ptr<VisualThemeImpl>;
  73. // A handle to a raster font
  74. class RasterFontImpl;
  75. using RasterFont = std::shared_ptr<RasterFontImpl>;
  76. // A handle to a media machine.
  77. // Media machines can be used to generate, filter and analyze images.
  78. // Everything running in a media machine is guaranteed to be 100% deterministic to the last bit.
  79. // This reduces the amount of code where maintenance has to be performed during porting.
  80. // It also means that any use of float or double is forbidden.
  81. class VirtualMachine;
  82. struct MediaMachine : IMPL_ACCESS std::shared_ptr<VirtualMachine> {
  83. MediaMachine(); // Defaults to null
  84. IMPL_ACCESS:
  85. explicit MediaMachine(const std::shared_ptr<VirtualMachine>& machine);
  86. };
  87. // Images
  88. // Points to a buffer region holding at least height * stride bytes.
  89. // Each row contains:
  90. // * A number of visible pixels
  91. // * A number of unused bytes
  92. // New or cloned images have their stride aligned to 16-bytes
  93. // Stride is the number of bytes from the start of one row to the next
  94. // Sub-images have the same stride and buffer as their parent
  95. // Some unused pixels may be visible somewhere else
  96. // 8-bit unsigned integer grayscale image
  97. class ImageU8Impl;
  98. struct ImageU8 : IMPL_ACCESS std::shared_ptr<ImageU8Impl> {
  99. ImageU8(); // Defaults to null
  100. IMPL_ACCESS:
  101. explicit ImageU8(const std::shared_ptr<ImageU8Impl>& image);
  102. explicit ImageU8(const ImageU8Impl& image);
  103. };
  104. // Invariant:
  105. // * Each row's start and stride is aligned with 16-bytes in memory (16-byte = 16 pixels)
  106. // This allow reading a full SIMD vector at each row's end without violating memory bounds
  107. // * No other image can displays pixels from its padding
  108. // This allow writing a full SIMD vector at each row's end without making visible changes outside of the bound
  109. struct AlignedImageU8 : public ImageU8 {
  110. AlignedImageU8() {} // Defaults to null
  111. IMPL_ACCESS:
  112. explicit AlignedImageU8(const std::shared_ptr<ImageU8Impl>& image) : ImageU8(image) {}
  113. explicit AlignedImageU8(const ImageU8Impl& image) : ImageU8(image) {}
  114. };
  115. // 16-bit unsigned integer grayscale image
  116. class ImageU16Impl;
  117. struct ImageU16 : IMPL_ACCESS std::shared_ptr<ImageU16Impl> {
  118. ImageU16(); // Defaults to null
  119. IMPL_ACCESS:
  120. explicit ImageU16(const std::shared_ptr<ImageU16Impl>& image);
  121. explicit ImageU16(const ImageU16Impl& image);
  122. };
  123. // Invariant:
  124. // * Each row's start and stride is aligned with 16-bytes in memory (16-byte = 16 pixels)
  125. // This allow reading a full SIMD vector at each row's end without violating memory bounds
  126. // * No other image can displays pixels from its padding
  127. // This allow writing a full SIMD vector at each row's end without making visible changes outside of the bound
  128. struct AlignedImageU16 : public ImageU16 {
  129. AlignedImageU16() {} // Defaults to null
  130. IMPL_ACCESS:
  131. explicit AlignedImageU16(const std::shared_ptr<ImageU16Impl>& image) : ImageU16(image) {}
  132. explicit AlignedImageU16(const ImageU16Impl& image) : ImageU16(image) {}
  133. };
  134. // 32-bit floating-point grayscale image
  135. class ImageF32Impl;
  136. struct ImageF32 : IMPL_ACCESS std::shared_ptr<ImageF32Impl> {
  137. ImageF32(); // Defaults to null
  138. IMPL_ACCESS:
  139. explicit ImageF32(const std::shared_ptr<ImageF32Impl>& image);
  140. explicit ImageF32(const ImageF32Impl& image);
  141. };
  142. // Invariant:
  143. // * Each row's start and stride is aligned with 16-bytes in memory (16-byte = 4 pixels)
  144. // This allow reading a full SIMD vector at each row's end without violating memory bounds
  145. // * No other image can displays pixels from its padding
  146. // This allow writing a full SIMD vector at each row's end without making visible changes outside of the bound
  147. struct AlignedImageF32 : public ImageF32 {
  148. AlignedImageF32() {} // Defaults to null
  149. IMPL_ACCESS:
  150. explicit AlignedImageF32(const std::shared_ptr<ImageF32Impl>& image) : ImageF32(image) {}
  151. explicit AlignedImageF32(const ImageF32Impl& image) : ImageF32(image) {}
  152. };
  153. // 4x8-bit unsigned integer RGBA color image
  154. class ImageRgbaU8Impl;
  155. struct ImageRgbaU8 : IMPL_ACCESS std::shared_ptr<ImageRgbaU8Impl> {
  156. ImageRgbaU8(); // Defaults to null
  157. IMPL_ACCESS:
  158. explicit ImageRgbaU8(const std::shared_ptr<ImageRgbaU8Impl>& image);
  159. explicit ImageRgbaU8(const ImageRgbaU8Impl& image);
  160. };
  161. // Invariant:
  162. // * Each row's start and stride is aligned with 16-bytes in memory (16-byte = 4 pixels)
  163. // This allow reading a full SIMD vector at each row's end without violating memory bounds
  164. // * No other image can displays pixels from its padding
  165. // This allow writing a full SIMD vector at each row's end without making visible changes outside of the bound
  166. struct AlignedImageRgbaU8 : public ImageRgbaU8 {
  167. AlignedImageRgbaU8() {} // Defaults to null
  168. IMPL_ACCESS:
  169. explicit AlignedImageRgbaU8(const std::shared_ptr<ImageRgbaU8Impl>& image) : ImageRgbaU8(image) {}
  170. explicit AlignedImageRgbaU8(const ImageRgbaU8Impl& image) : ImageRgbaU8(image) {}
  171. };
  172. // Invariant:
  173. // * Using the default RGBA pack order
  174. // This removes the need to implement filters for different pack orders when RGBA can be safely assumed
  175. // Just use AlignedImageRgbaU8 if channels don't have to be aligned
  176. struct OrderedImageRgbaU8 : public AlignedImageRgbaU8 {
  177. OrderedImageRgbaU8() {} // Defaults to null
  178. IMPL_ACCESS:
  179. explicit OrderedImageRgbaU8(const std::shared_ptr<ImageRgbaU8Impl>& image) : AlignedImageRgbaU8(image) {}
  180. explicit OrderedImageRgbaU8(const ImageRgbaU8Impl& image) : AlignedImageRgbaU8(image) {}
  181. };
  182. }
  183. #endif