odin-blend2d

Odin bindings to Blend2D
Log | Files | Refs | README | LICENSE

rasterdefs_p.h (8720B)


      1 // This file is part of Blend2D project <https://blend2d.com>
      2 //
      3 // See blend2d.h or LICENSE.md for license and copyright information
      4 // SPDX-License-Identifier: Zlib
      5 
      6 #ifndef BLEND2D_RASTER_RASTERDEFS_P_H_INCLUDED
      7 #define BLEND2D_RASTER_RASTERDEFS_P_H_INCLUDED
      8 
      9 #include "../api-internal_p.h"
     10 #include "../compop_p.h"
     11 #include "../context_p.h"
     12 #include "../gradient_p.h"
     13 #include "../image_p.h"
     14 #include "../matrix_p.h"
     15 #include "../object_p.h"
     16 #include "../pattern_p.h"
     17 #include "../path_p.h"
     18 #include "../pipeline/pipedefs_p.h"
     19 
     20 //! \cond INTERNAL
     21 //! \addtogroup blend2d_raster_engine_impl
     22 //! \{
     23 
     24 class BLRasterContextImpl;
     25 
     26 namespace bl::RasterEngine {
     27 
     28 struct RenderFetchData;
     29 struct StyleData;
     30 class WorkData;
     31 
     32 //! Represents the number of bits per a single color channel, rounded up to 8 or 16.
     33 enum class TargetDepth : uint32_t {
     34   kU8,
     35   kU16,
     36   kF32
     37 };
     38 
     39 //! Rendering mode.
     40 enum class RenderingMode : uint32_t {
     41   kSync = 0,
     42   kAsync = 1
     43 };
     44 
     45 //! Rendering context flags that represent the following states:
     46 //!
     47 //!  - no flags - no flags describe a no-operation conditions used to quickly reject render calls.
     48 //!
     49 //!  - fetch flags - fetch flags describe a fetch data state.
     50 //!
     51 //!  - shared flags - describe shared states used by multithreaded rendering. Some functions in the rendering context
     52 //!    don't care whether the rendering is synchronous or asynchronous and just clear the `kSharedState` flags in case
     53 //!    that something shared was changed. Then before a command is enqueued such flags are checked and the shared state
     54 //!    is created when necessary. If a shared state flag is set then the engine would reuse the state if possible.
     55 //!
     56 //!  - informative flags - other flags like integral translation.
     57 //!
     58 //!  - weak state flags - book keeping flags that describe which states must be saved to `SavedState` before they can
     59 //!    be modified. Used by `save()`, `restore()`, and by all other functions that manipulate the context state. When
     60 //!    the rendering context is created, all WEAK state flags are false, which means that there is no previous state
     61 //!    where to save.
     62 //!
     63 //!  - queue flags - TODO
     64 enum class ContextFlags : uint32_t {
     65   //! No flags set.
     66   kNoFlagsSet = 0u,
     67 
     68   //! Reserved for solic color override - set during render call dispatching.
     69   kSolidOverride = 0x00000003u,
     70 
     71   //! The operation is always NOP regardless of the composition operator, source, etc...
     72   //!
     73   //! \note When `CompOpSolidId::kAlwaysNop` is combined with ContextFlags the 3 LSB bits would be modified. This
     74   //! would always be set when the composition is simplified to \ref BL_COMP_OP_DST_COPY. Since this flag is part of
     75   //! 'no-' flags family, we don't have to do anything else to reject render calls that would implicitly or explicitly
     76   //! have this flag set during the call invocation.
     77   kNoOperation = 0x00000004u,
     78 
     79   //! Global alpha is zero.
     80   kNoGlobalAlpha = 0x00000008u,
     81 
     82   //! Start of fill/stroke 'no' alpha.
     83   kNoBaseAlpha = 0x00000010u,
     84   //! Fill alpha is zero.
     85   kNoFillAlpha = kNoBaseAlpha << 0,
     86   //! Stroke alpha is zero.
     87   kNoStrokeAlpha = kNoBaseAlpha << 1,
     88   //! Start of fill/stroke 'no' flags.
     89   kNoBaseStyle = 0x00000040u,
     90   //! Fill style is invalid or none.
     91   kNoFillStyle = kNoBaseStyle << 0,
     92   //! Stroke style is invalid or none.
     93   kNoStrokeStyle = kNoBaseStyle << 1,
     94 
     95   kNoFillAndStrokeAlpha = kNoFillAlpha | kNoStrokeAlpha,
     96   kNoFillAndStrokeStyle = kNoFillStyle | kNoStrokeStyle,
     97 
     98   //! User clip-rect is empty.
     99   kNoClipRect = 0x00000100u,
    100   //! User clip-mask is empty.
    101   kNoClipMask = 0x00000200u,
    102 
    103   //! Meta transform is invalid.
    104   kNoMetaTransform = 0x00000400u,
    105   //! User transform is invalid.
    106   kNoUserTransform = 0x00000800u,
    107 
    108   //! One or more stroke parameter is invalid.
    109   //!
    110   //! TODO: [Rendering Context] Never set!
    111   kNoStrokeOptions = 0x00001000u,
    112 
    113   //! All 'no' flags.
    114   kNoAllFlags = 0x00003FFFu,
    115 
    116   //! A combination of no-clear flags that would prevent a clear all operation.
    117   kNoClearOpAll = kSolidOverride | kNoClipRect | kNoClipMask | kNoOperation,
    118   //! A combination of no-clear flags that would prevent a clear geometry operation.
    119   kNoClearOp = kNoClearOpAll | kNoMetaTransform | kNoUserTransform,
    120 
    121   //! A combination of no-fill flags used by a fill-all render call with an explicit style.
    122   kNoFillOpAllExplicit = kSolidOverride | kNoGlobalAlpha | kNoFillAlpha | kNoClipRect | kNoClipMask | kNoOperation,
    123   //! A combination of no-fill flags used by a fill-all render call with a default style.
    124   kNoFillOpAllImplicit = kNoFillOpAllExplicit | kNoFillStyle,
    125   //! A combination of no-fill flags used by a geometry render call with an explicit style.
    126   kNoFillOpExplicit = kNoFillOpAllExplicit | kNoMetaTransform | kNoUserTransform,
    127   //! A combination of no-fill flags used by a geometry render call with a default style.
    128   kNoFillOpImplicit = kNoFillOpExplicit | kNoFillStyle,
    129 
    130   //! A combination of no-stroke flags used by a geometry render call with an explicit style.
    131   kNoStrokeOpExplicit = kSolidOverride | kNoGlobalAlpha | kNoStrokeAlpha | kNoStrokeOptions | kNoClipRect | kNoClipMask | kNoOperation | kNoMetaTransform | kNoUserTransform,
    132   //! A combination of no-stroke flags used by a geometry render call with a default style.
    133   kNoStrokeOpImplicit = kNoStrokeOpExplicit | kNoStrokeStyle,
    134 
    135   //! A combination of no-blit flags.
    136   kNoBlitFlags = kSolidOverride | kNoGlobalAlpha | kNoClipRect | kNoClipMask | kNoMetaTransform | kNoUserTransform | kNoOperation,
    137 
    138   //! Start of non-solid fill/stroke flag
    139   kFetchDataBase = 0x00004000u,
    140   //! Fill style is not solid nor none.
    141   kFetchDataFill = kFetchDataBase << 0,
    142   //! Stroke style is not solid nor none.
    143   kFetchDataStroke = kFetchDataBase << 1,
    144   //! Invalid style (only used for error checking).
    145   kFetchDataInvalidStyle = kFetchDataBase << 2,
    146 
    147   kFetchDataFillAndStroke = kFetchDataFill | kFetchDataStroke,
    148 
    149   //! Configuration (tolerance).
    150   kWeakStateConfig = 0x001000000,
    151   //! Clip state.
    152   kWeakStateClip = 0x00200000u,
    153   //! Start of fill/stroke style flags.
    154   kWeakStateBaseStyle = 0x00400000u,
    155   //! Fill style state.
    156   kWeakStateFillStyle = kWeakStateBaseStyle << 0,
    157   //! Stroke style state.
    158   kWeakStateStrokeStyle = kWeakStateBaseStyle << 1,
    159   //! Invalid style state (only used for error checking).
    160   kWeakStateInvalidStyle = kWeakStateBaseStyle << 2,
    161   //! Stroke params state.
    162   kWeakStateStrokeOptions = 0x02000000u,
    163   //! Meta transform state.
    164   kWeakStateMetaTransform = 0x04000000u,
    165   //! User transform state.
    166   kWeakStateUserTransform = 0x08000000u,
    167   //! All states' flags.
    168   kWeakStateAllFlags = 0x0FF00000u,
    169 
    170   //! Final translation matrix is just a scale of `fp_scale_d()` and integral translation.
    171   kInfoIntegralTranslation = 0x10000000u,
    172 
    173   //! Shared fill-state has valid data.
    174   kSharedStateFill = 0x00020000u,
    175   //! Shared stroke-state has valid base-stroke data.
    176   kSharedStateStrokeBase = 0x00040000u,
    177   //! Shared stroke-state has valid extended-stroke data.
    178   kSharedStateStrokeExt = 0x00080000u,
    179   //! A combination of all `kShared...` flags.
    180   kSharedStateAllFlags = kSharedStateFill | kSharedStateStrokeBase | kSharedStateStrokeExt,
    181 
    182   //! This flag has multiple meanings - it can be used to mark command/job queues being full or it can mark pools
    183   //! exhausted. It should be checked at the beginning of a render call by the frontend to ensure that that the queue
    184   //! is not full, and if full, the queue should either grow or the rendering engine should execute it if it cannot
    185   //! grow anymore (for example it reaches a limit). Additionally, this flag can mark exhausted pools that need to be
    186   //! refilled.
    187   kMTFullOrExhausted = 0x80000000u,
    188 
    189   //! Flags that must always be preserved during state switching.
    190   kPreservedFlags = kMTFullOrExhausted
    191 };
    192 
    193 BL_DEFINE_ENUM_FLAGS(ContextFlags)
    194 
    195 template<typename ShiftT>
    196 static BL_INLINE_CONSTEXPR ContextFlags operator<<(ContextFlags a, const ShiftT& n) noexcept {
    197   return ContextFlags(std::underlying_type_t<ContextFlags>(a) << n);
    198 }
    199 
    200 template<typename ShiftT>
    201 static BL_INLINE_CONSTEXPR ContextFlags operator>>(ContextFlags a, const ShiftT& n) noexcept {
    202   return ContextFlags(std::underlying_type_t<ContextFlags>(a) >> n);
    203 }
    204 
    205 } // {bl::RasterEngine}
    206 
    207 //! Indexes to a `BLRasterContextImpl::solid_format_table`, which describes pixel
    208 //! formats used by solid fills. There are in total 3 choices that are selected
    209 //! based on properties of the solid color.
    210 enum BLRasterContextSolidFormatId : uint32_t {
    211   BL_RASTER_CONTEXT_SOLID_FORMAT_ARGB = 0,
    212   BL_RASTER_CONTEXT_SOLID_FORMAT_FRGB = 1,
    213   BL_RASTER_CONTEXT_SOLID_FORMAT_ZERO = 2,
    214 
    215   BL_RASTER_CONTEXT_SOLID_FORMAT_COUNT = 3
    216 };
    217 
    218 //! \}
    219 //! \endcond
    220 
    221 #endif // BLEND2D_RASTER_RASTERDEFS_P_H_INCLUDED