LCOV - code coverage report
Current view: top level - xenolith/core - XLCoreDynamicImage.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2024-05-12 00:16:13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2022 Roman Katuntsev <sbkarr@stappler.org>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_CORE_XLCOREDYNAMICIMAGE_H_
      24             : #define XENOLITH_CORE_XLCOREDYNAMICIMAGE_H_
      25             : 
      26             : #include "XLCoreObject.h"
      27             : #include "XLCoreAttachment.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith::core {
      30             : 
      31             : class Loop;
      32             : class DynamicImage;
      33             : class MaterialAttachment;
      34             : 
      35             : struct DynamicImageInstance : public Ref {
      36        1688 :         virtual ~DynamicImageInstance() { }
      37             : 
      38             :         ImageData data;
      39             :         Rc<Ref> userdata;
      40             :         Rc<DynamicImage> image = nullptr;
      41             :         uint32_t gen = 0;
      42             : };
      43             : 
      44             : class DynamicImage : public Ref {
      45             : public:
      46             :         class Builder;
      47             : 
      48             :         virtual ~DynamicImage();
      49             : 
      50             :         bool init(const Callback<bool(Builder &)> &);
      51             :         void finalize();
      52             : 
      53             :         Rc<DynamicImageInstance> getInstance();
      54             : 
      55             :         void updateInstance(Loop &, const Rc<ImageObject> &, Rc<DataAtlas> && = Rc<DataAtlas>(), Rc<Ref> &&userdata = Rc<Ref>(),
      56             :                         const Vector<Rc<DependencyEvent>> & = Vector<Rc<DependencyEvent>>());
      57             : 
      58             :         void addTracker(const MaterialAttachment *);
      59             :         void removeTracker(const MaterialAttachment *);
      60             : 
      61             :         ImageInfo getInfo() const;
      62             :         Extent3 getExtent() const;
      63             : 
      64             :         // called when image compiled successfully
      65             :         void setImage(const Rc<ImageObject> &);
      66             :         void acquireData(const Callback<void(BytesView)> &);
      67             : 
      68             : protected:
      69             :         friend class Builder;
      70             : 
      71             :         mutable Mutex _mutex;
      72             :         String _keyData;
      73             :         Bytes _imageData;
      74             :         ImageData _data;
      75             :         Rc<DynamicImageInstance> _instance;
      76             :         Set<const MaterialAttachment *> _materialTrackers;
      77             : };
      78             : 
      79             : class DynamicImage::Builder {
      80             : public:
      81             :         const ImageData * setImageByRef(StringView key, ImageInfo &&, BytesView data, Rc<DataAtlas> && = nullptr);
      82             :         const ImageData * setImage(StringView key, ImageInfo &&, FilePath data, Rc<DataAtlas> && = nullptr);
      83             :         const ImageData * setImage(StringView key, ImageInfo &&, BytesView data, Rc<DataAtlas> && = nullptr);
      84             :         const ImageData * setImage(StringView key, ImageInfo &&,
      85             :                         Function<void(uint8_t *, uint64_t, const ImageData::DataCallback &)> &&cb, Rc<DataAtlas> && = nullptr);
      86             : 
      87             : protected:
      88             :         friend class DynamicImage;
      89             : 
      90             :         Builder(DynamicImage *);
      91             : 
      92             :         DynamicImage *_data = nullptr;
      93             : };
      94             : 
      95             : }
      96             : 
      97             : #endif /* XENOLITH_CORE_XLCOREDYNAMICIMAGE_H_ */

Generated by: LCOV version 1.14