Check defines to build for mac or ios This starts a pattern in rive_types.hpp where we do some common compiler-define checking, to determine which platform we compiling on. The specific goal here is to allow cg_skia_factory.cpp to build on both OSX and iOS (just needs different includes) Diffs= b515308af Check defines to build for mac or ios
diff --git a/.rive_head b/.rive_head index 24f2dd3..0be0140 100644 --- a/.rive_head +++ b/.rive_head
@@ -1 +1 @@ -99b96518a27fd47f231ba4bb17148ac2099e14d1 +b515308af7839e87f7b5fee7859a703d820a7026
diff --git a/include/rive/rive_types.hpp b/include/rive/rive_types.hpp index 3723aea..2bdf100 100644 --- a/include/rive/rive_types.hpp +++ b/include/rive/rive_types.hpp
@@ -32,6 +32,21 @@ #endif #endif +// Some checks to guess what platform we're building for + +#ifdef __APPLE__ + + #define RIVE_BUILD_FOR_APPLE + #include <TargetConditionals.h> + + #if TARGET_OS_IPHONE + #define RIVE_BUILD_FOR_IOS + #elif TARGET_OS_MAC + #define RIVE_BUILD_FOR_OSX + #endif + +#endif + // We really like these headers, so we include them all the time. #include <algorithm>
diff --git a/skia/viewer/src/cg_skia_factory.cpp b/skia/viewer/src/cg_skia_factory.cpp index 0e6baee..7ffad4d 100644 --- a/skia/viewer/src/cg_skia_factory.cpp +++ b/skia/viewer/src/cg_skia_factory.cpp
@@ -3,11 +3,18 @@ */ #include "cg_skia_factory.hpp" - -#include <ApplicationServices/ApplicationServices.h> - +#include "rive/core/type_conversions.hpp" #include <vector> +#ifdef RIVE_BUILD_FOR_APPLE + +#if defined(RIVE_BUILD_FOR_OSX) + #include <ApplicationServices/ApplicationServices.h> +#elif defined(RIVE_BUILD_FOR_IOS) + #include <CoreGraphics/CoreGraphics.h> + #include <ImageIO/ImageIO.h> +#endif + // Helper that remembers to call CFRelease when an object goes out of scope. template <typename T> class AutoCF { T m_Obj; @@ -22,7 +29,8 @@ using namespace rive; -std::vector<uint8_t> CGSkiaFactory::platformDecode(rive::Span<const uint8_t> span, ImageInfo* info) { +std::vector<uint8_t> CGSkiaFactory::platformDecode(Span<const uint8_t> span, + SkiaFactory::ImageInfo* info) { std::vector<uint8_t> pixels; AutoCF data = CFDataCreateWithBytesNoCopy(nullptr, span.data(), span.size(), nullptr); @@ -60,8 +68,8 @@ } else { cgInfo |= kCGImageAlphaPremultipliedLast; // premul } - const int width = CGImageGetWidth(image); - const int height = CGImageGetHeight(image); + const size_t width = CGImageGetWidth(image); + const size_t height = CGImageGetHeight(image); const size_t rowBytes = width * 4; // 4 bytes per pixel const size_t size = rowBytes * height; @@ -79,8 +87,10 @@ info->alphaType = isOpaque ? AlphaType::opaque : AlphaType::premul; info->colorType = ColorType::rgba; - info->width = width; - info->height = height; + info->width = castTo<uint32_t>(width); + info->height = castTo<uint32_t>(height); info->rowBytes = rowBytes; return pixels; }; + +#endif // RIVE_BUILD_FOR_APPLE
diff --git a/skia/viewer/src/cg_skia_factory.hpp b/skia/viewer/src/cg_skia_factory.hpp index 77557eb..050735f 100644 --- a/skia/viewer/src/cg_skia_factory.hpp +++ b/skia/viewer/src/cg_skia_factory.hpp
@@ -8,11 +8,10 @@ #include "skia_factory.hpp" namespace rive { - struct CGSkiaFactory : public SkiaFactory { - std::vector<uint8_t> platformDecode(rive::Span<const uint8_t> span, ImageInfo* info) override; + std::vector<uint8_t> platformDecode(Span<const uint8_t>, + SkiaFactory::ImageInfo*) override; }; - } // namespace -#endif +#endif // _RIVE_CGSkiaFactory_HPP_