diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/osx/graphics/quartz/Image.h | 7 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/ImageFactory.h | 1 | ||||
-rw-r--r-- | include/cru/platform/graphics/Image.h | 16 | ||||
-rw-r--r-- | include/cru/platform/graphics/ImageFactory.h | 8 | ||||
-rw-r--r-- | include/cru/platform/graphics/Painter.h | 4 | ||||
-rw-r--r-- | include/cru/win/graphics/direct/Image.h | 2 | ||||
-rw-r--r-- | include/cru/win/graphics/direct/ImageFactory.h | 2 | ||||
-rw-r--r-- | include/cru/win/graphics/direct/Painter.h | 11 |
8 files changed, 47 insertions, 4 deletions
diff --git a/include/cru/osx/graphics/quartz/Image.h b/include/cru/osx/graphics/quartz/Image.h index 458f5db0..5b3aead9 100644 --- a/include/cru/osx/graphics/quartz/Image.h +++ b/include/cru/osx/graphics/quartz/Image.h @@ -9,7 +9,8 @@ namespace cru::platform::graphics::osx::quartz { class QuartzImage : public OsxQuartzResource, public virtual IImage { public: QuartzImage(IGraphicsFactory* graphics_factory, IImageFactory* image_factory, - CGImageRef image, bool auto_release); + CGImageRef image, bool auto_release, + unsigned char* buffer = nullptr); CRU_DELETE_COPY(QuartzImage) CRU_DELETE_MOVE(QuartzImage) @@ -22,11 +23,15 @@ class QuartzImage : public OsxQuartzResource, public virtual IImage { std::unique_ptr<IImage> CreateWithRect(const Rect& rect) override; + std::unique_ptr<IPainter> CreatePainter() override; + CGImageRef GetCGImage() const { return image_; } private: IImageFactory* image_factory_; CGImageRef image_; bool auto_release_ = false; + + unsigned char* buffer_; }; } // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/ImageFactory.h b/include/cru/osx/graphics/quartz/ImageFactory.h index e9854738..19e9c8c1 100644 --- a/include/cru/osx/graphics/quartz/ImageFactory.h +++ b/include/cru/osx/graphics/quartz/ImageFactory.h @@ -15,5 +15,6 @@ class QuartzImageFactory : public OsxQuartzResource, public: std::unique_ptr<IImage> DecodeFromStream(io::Stream* stream) override; + std::unique_ptr<IImage> CreateBitmap(int width, int height) override; }; } // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/platform/graphics/Image.h b/include/cru/platform/graphics/Image.h index 51e27678..de3b32d5 100644 --- a/include/cru/platform/graphics/Image.h +++ b/include/cru/platform/graphics/Image.h @@ -6,5 +6,21 @@ struct CRU_PLATFORM_GRAPHICS_API IImage : public virtual IGraphicsResource { virtual float GetWidth() = 0; virtual float GetHeight() = 0; virtual std::unique_ptr<IImage> CreateWithRect(const Rect& rect) = 0; + + /** + * \brief Create a painter for this image. + * \remarks Not all image could create a painter. If not this method will + * throw. Currently we only ensure images returned by + * IImageFactory::CreateBitmap or CloneToBitmap can create a painter. + * \todo Implement on Windows. + */ + virtual std::unique_ptr<IPainter> CreatePainter() = 0; + + /** + * \brief Create a bitmap image with the same pixels as this image's. + * \remarks This method can be used to create a bitmap image, so you can draw + * on the new bitmap, if the original image can't be directly painted. + */ + virtual std::unique_ptr<IImage> CloneToBitmap(); }; } // namespace cru::platform::graphics diff --git a/include/cru/platform/graphics/ImageFactory.h b/include/cru/platform/graphics/ImageFactory.h index 2a7902b2..d2c2a468 100644 --- a/include/cru/platform/graphics/ImageFactory.h +++ b/include/cru/platform/graphics/ImageFactory.h @@ -7,5 +7,13 @@ namespace cru::platform::graphics { struct CRU_PLATFORM_GRAPHICS_API IImageFactory : public virtual IGraphicsResource { virtual std::unique_ptr<IImage> DecodeFromStream(io::Stream* stream) = 0; + + /** + * \brief Create an empty bitmap with given width and height. + * \remarks Implementation should ensure that the bitmap supports alpha + * channel. It had better be in 32-bit rgba format. + * \todo Implement on Windows. + */ + virtual std::unique_ptr<IImage> CreateBitmap(int width, int height) = 0; }; } // namespace cru::platform::graphics diff --git a/include/cru/platform/graphics/Painter.h b/include/cru/platform/graphics/Painter.h index 38ff8849..4268133e 100644 --- a/include/cru/platform/graphics/Painter.h +++ b/include/cru/platform/graphics/Painter.h @@ -3,6 +3,10 @@ namespace cru::platform::graphics { +/** + * \brief Painter is a object to paint on something like window, bitmap and etc. + * \remarks Remember to call EndDraw() when you are done with painting. + */ struct CRU_PLATFORM_GRAPHICS_API IPainter : virtual IPlatformResource { virtual Matrix GetTransform() = 0; virtual void SetTransform(const Matrix& matrix) = 0; diff --git a/include/cru/win/graphics/direct/Image.h b/include/cru/win/graphics/direct/Image.h index 0b51f350..bcf2386b 100644 --- a/include/cru/win/graphics/direct/Image.h +++ b/include/cru/win/graphics/direct/Image.h @@ -20,6 +20,8 @@ class CRU_WIN_GRAPHICS_DIRECT_API Direct2DImage : public DirectGraphicsResource, std::unique_ptr<IImage> CreateWithRect(const Rect& rect) override; + std::unique_ptr<IPainter> CreatePainter() override; + const Microsoft::WRL::ComPtr<ID2D1Bitmap1>& GetD2DBitmap() const { return d2d_bitmap_; } diff --git a/include/cru/win/graphics/direct/ImageFactory.h b/include/cru/win/graphics/direct/ImageFactory.h index 34d363b0..923e682f 100644 --- a/include/cru/win/graphics/direct/ImageFactory.h +++ b/include/cru/win/graphics/direct/ImageFactory.h @@ -19,6 +19,8 @@ class CRU_WIN_GRAPHICS_DIRECT_API WinImageFactory public: std::unique_ptr<IImage> DecodeFromStream(io::Stream* stream) override; + std::unique_ptr<IImage> CreateBitmap(int width, int height) override; + private: DirectGraphicsFactory* graphics_factory_; diff --git a/include/cru/win/graphics/direct/Painter.h b/include/cru/win/graphics/direct/Painter.h index b1795395..da89ba5d 100644 --- a/include/cru/win/graphics/direct/Painter.h +++ b/include/cru/win/graphics/direct/Painter.h @@ -2,6 +2,7 @@ #include "ComResource.h" #include "Resource.h" +#include "cru/common/Base.h" #include "cru/platform/graphics/Painter.h" #include <vector> @@ -11,13 +12,15 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter : public DirectResource, public virtual IPainter, public virtual IComResource<ID2D1DeviceContext1> { + CRU_DEFINE_CLASS_LOG_TAG(u"D2DDeviceContextPainter") public: - explicit D2DDeviceContextPainter(ID2D1DeviceContext1* device_context); + explicit D2DDeviceContextPainter(ID2D1DeviceContext1* device_context, + bool release = false); CRU_DELETE_COPY(D2DDeviceContextPainter) CRU_DELETE_MOVE(D2DDeviceContextPainter) - ~D2DDeviceContextPainter() override = default; + ~D2DDeviceContextPainter() override; public: ID2D1DeviceContext1* GetComInterface() const override { @@ -57,7 +60,7 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter void EndDraw() override final; protected: - virtual void DoEndDraw() = 0; + virtual void DoEndDraw() {} private: bool IsValid() { return is_drawing_; } @@ -71,5 +74,7 @@ class CRU_WIN_GRAPHICS_DIRECT_API D2DDeviceContextPainter drawing_state_stack_; bool is_drawing_ = true; + + bool release_; }; } // namespace cru::platform::graphics::win::direct |