From ba2d75a9932c9a42cc54d52645be88a7cd420466 Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Thu, 16 Jan 2025 16:46:52 +0000 Subject: [PATCH] fix(slideshow): Use CoreGraphics to render on iOS Similarly to `doc_paintTile` in init.cxx, we can't use the regular initialization for our graphics backend on iOS. If we do so, we render a completely white area. Instead, we need to use CoreGraphics, which is the iOS library for rendering graphics Change-Id: I94cb620d422c02f8343db30eea24cecc53d928c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185095 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sd/source/ui/tools/SlideshowLayerRenderer.cxx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sd/source/ui/tools/SlideshowLayerRenderer.cxx b/sd/source/ui/tools/SlideshowLayerRenderer.cxx index 4178cc4ec690..96cdc9cb6e6e 100644 --- a/sd/source/ui/tools/SlideshowLayerRenderer.cxx +++ b/sd/source/ui/tools/SlideshowLayerRenderer.cxx @@ -48,6 +48,33 @@ #include +#ifdef IOS +#include +namespace CoreGraphics +{ // Namespace here because iOS redefines Point and Size +#import + +SystemGraphicsData getiOSGraphicsData(unsigned char* pBuffer, long width, long height) +{ + double fDPIScale = 1.0; + + // Onine uses the LOK_TILEMODE_RGBA by default so flip the normal flags + // to kCGImageAlphaPremultipliedLast | kCGImageByteOrder32Big + CGContextRef pCGContext + = CGBitmapContextCreate(pBuffer, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), + kCGImageAlphaPremultipliedLast | kCGImageByteOrder32Big); + + CGContextTranslateCTM(pCGContext, 0, height); + CGContextScaleCTM(pCGContext, fDPIScale, -fDPIScale); + + SystemGraphicsData aData; + aData.rCGContext = reinterpret_cast(pCGContext); + + return aData; +} +} +#endif + using namespace ::com::sun::star; namespace sd @@ -67,7 +94,13 @@ public: RenderContext(unsigned char* pBuffer, SdrModel& rModel, const SdrPage& rPage, Size const& rSlideSize, const Fraction& rScale) : mrModel(rModel) +#if defined(IOS) + , maVirtualDevice( + CoreGraphics::getiOSGraphicsData(pBuffer, rSlideSize.Width(), rSlideSize.Height()), + Size(1, 1), DeviceFormat::WITHOUT_ALPHA) +#else , maVirtualDevice(DeviceFormat::WITHOUT_ALPHA) +#endif { SdrOutliner& rOutliner = mrModel.GetDrawOutliner(); @@ -103,6 +136,10 @@ public: SdrOutliner& rOutliner = mrModel.GetDrawOutliner(); rOutliner.SetControlWord(mnSavedControlBits); rOutliner.SetBackgroundColor(maSavedBackgroundColor); + +#ifdef IOS + CoreGraphics::CGContextRelease(maVirtualDevice->GetSystemGfxData().rCGContext); +#endif } };