odin-blend2d

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

styledata_p.h (2914B)


      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_STYLEDATA_P_H_INCLUDED
      7 #define BLEND2D_RASTER_STYLEDATA_P_H_INCLUDED
      8 
      9 #include "../raster/rasterdefs_p.h"
     10 #include "../raster/renderfetchdata_p.h"
     11 
     12 //! \cond INTERNAL
     13 //! \addtogroup blend2d_raster_engine_impl
     14 //! \{
     15 
     16 namespace bl::RasterEngine {
     17 
     18 //! Style data holds a copy of user-provided style with additional members that allow to create a `RenderFetchData`
     19 //! from it. When a style is assigned to the rendering context it has to calculate the style transformation matrix
     20 //! and a few other things that could degrade the style into a solid fill.
     21 struct StyleData {
     22   //! \name Members
     23   //! \{
     24 
     25   //! Pointer to a fetch data - it points to either a separate `RenderFetchData` data or to `&solid` data in this
     26   //! struct. Use `has_implicit_fetch_data()` to check whether fetch data points to external fetch data or to &solid.
     27   RenderFetchDataHeader* fetch_data;
     28 
     29   struct SolidData : public RenderFetchDataSolid {
     30     //! The original color passed to set_style() API.
     31     union {
     32       //! Solid color as passed to frontend (non-premultiplied RGBA float components).
     33       BLRgba rgba;
     34       //! Solid color as passed to frontend (non-premultiplied RGBA32 integer components).
     35       BLRgba32 rgba32;
     36       //! Solid color as passed to frontend (non-premultiplied RGBA64 integer components).
     37       BLRgba64 rgba64;
     38     } original;
     39   };
     40 
     41   struct NonSolidData {
     42     //! Style transformation matrix combined with the rendering context transformation matrix.
     43     BLMatrix2D adjusted_transform;
     44   };
     45 
     46   union {
     47     SolidData solid;
     48     NonSolidData non_solid;
     49   };
     50 
     51   //! \}
     52 
     53   //! \name Accessors
     54   //! \{
     55 
     56   BL_INLINE_NODEBUG void make_fetch_data_implicit() noexcept { fetch_data = &solid; }
     57   BL_INLINE_NODEBUG bool has_implicit_fetch_data() const noexcept { return fetch_data == static_cast<const void*>(&solid); }
     58 
     59   BL_INLINE_NODEBUG bool has_fetch_data() const noexcept { return !has_implicit_fetch_data(); }
     60   BL_INLINE_NODEBUG RenderFetchData* get_render_fetch_data() const noexcept { return static_cast<RenderFetchData*>(fetch_data); }
     61 
     62   //! \}
     63 
     64   //! \name Memory Operations
     65   //! \{
     66 
     67   BL_INLINE void swap(StyleData& other) noexcept {
     68     bool this_implicit = has_implicit_fetch_data();
     69     bool other_implicit = other.has_implicit_fetch_data();
     70 
     71     BLInternal::swap(*this, other);
     72 
     73     if (this_implicit)
     74       other.make_fetch_data_implicit();
     75 
     76     if (other_implicit)
     77       make_fetch_data_implicit();
     78   }
     79 
     80   BL_INLINE void copy_from(const StyleData& other) noexcept {
     81     memcpy(this, &other, sizeof(StyleData));
     82     if (other.has_implicit_fetch_data())
     83       make_fetch_data_implicit();
     84   }
     85 
     86   //! \}
     87 };
     88 
     89 } // {bl::RasterEngine}
     90 
     91 //! \}
     92 //! \endcond
     93 
     94 #endif // BLEND2D_RASTER_STYLEDATA_P_H_INCLUDED