From 1d279e9c9123d50788cefb186663ef3842aaa8c2 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 10 Oct 2018 16:17:18 +0300 Subject: Move the iOS CGBitmapContextCreate() call do doc_paintTile() Thus it now actually takes a buffer pointer also on iOS, like on Linux and Android. Less confusing, more uniform. Add a separate iOS-specific paintTileToCGContext() method to LibreOfficeKitDocumentClass that takes a CGContextRef. Adapt callers correspondingly. (The LibreOfficeLight code in particular needs the paintTileToCGContext().) Change-Id: I81084806d37b9aac9f2b2bc03d0c262e991eec81 --- .../LibreOfficeLight.xcodeproj/project.pbxproj | 5 +++++ .../LibreOfficeLight/LOKit/Document.swift | 24 ++++++++++----------- ios/UnitTest/UnitTest/ViewController.mm | 25 ---------------------- 3 files changed, 17 insertions(+), 37 deletions(-) (limited to 'ios') diff --git a/ios/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj b/ios/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj index 42a71811d3f2..819a419620b5 100644 --- a/ios/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj +++ b/ios/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj @@ -549,6 +549,10 @@ ENABLE_TESTABILITY = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "LibreOfficeLight/LibreOfficeLight-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "IOS=1", + ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; HEADER_SEARCH_PATHS = ( "$(inherited)", @@ -583,6 +587,7 @@ ENABLE_TESTABILITY = NO; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "LibreOfficeLight/LibreOfficeLight-Prefix.pch"; + GCC_PREPROCESSOR_DEFINITIONS = "IOS=1"; HEADER_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/../../include", diff --git a/ios/LibreOfficeLight/LibreOfficeLight/LOKit/Document.swift b/ios/LibreOfficeLight/LibreOfficeLight/LOKit/Document.swift index 79e28d674595..218d203f61be 100644 --- a/ios/LibreOfficeLight/LibreOfficeLight/LOKit/Document.swift +++ b/ios/LibreOfficeLight/LibreOfficeLight/LOKit/Document.swift @@ -124,7 +124,7 @@ open class Document * rendering at different zoom levels, as the number of rendered pixels and * the rendered rectangle of the document are independent. * - * @param pBuffer pointer to the buffer, its size is determined by nCanvasWidth and nCanvasHeight. + * @param rCGContext Core Graphics context, cast to a UnsafeMutableRawPointer * @param nCanvasWidth number of pixels in a row of pBuffer. * @param nCanvasHeight number of pixels in a column of pBuffer. * @param nTilePosX logical X position of the top left corner of the rendered rectangle, in TWIPs. @@ -132,7 +132,7 @@ open class Document * @param nTileWidth logical width of the rendered rectangle, in TWIPs. * @param nTileHeight logical height of the rendered rectangle, in TWIPs. */ - public func paintTile( pBuffer: UnsafeMutablePointer, + public func paintTileToCGContext( rCGContext: UnsafeMutableRawPointer, canvasWidth: Int32, canvasHeight: Int32, tilePosX: Int32, @@ -141,8 +141,8 @@ open class Document tileHeight: Int32) { print("paintTile canvasWidth=\(canvasWidth) canvasHeight=\(canvasHeight) tilePosX=\(tilePosX) tilePosY=\(tilePosY) tileWidth=\(tileWidth) tileHeight=\(tileHeight) ") - return docClass.paintTile(pDoc, pBuffer, canvasWidth, canvasHeight, - tilePosX, tilePosY, tileWidth, tileHeight); + return docClass.paintTileToCGContext(pDoc, rCGContext, canvasWidth, canvasHeight, + tilePosX, tilePosY, tileWidth, tileHeight); } /** @@ -562,16 +562,16 @@ public extension Document { let ctx = UIGraphicsGetCurrentContext() //print(ctx!) - let ptr = unsafeBitCast(ctx, to: UnsafeMutablePointer.self) + let ptr = unsafeBitCast(ctx, to: UnsafeMutableRawPointer.self) //print(ptr) - self.paintTile(pBuffer:ptr, - canvasWidth: Int32(canvasSize.width), - canvasHeight: Int32(canvasSize.height), - tilePosX: Int32(tileRect.minX), - tilePosY: Int32(tileRect.minY), - tileWidth: Int32(tileRect.size.width), - tileHeight: Int32(tileRect.size.height)) + self.paintTileToCGContext(rCGContext:ptr, + canvasWidth: Int32(canvasSize.width), + canvasHeight: Int32(canvasSize.height), + tilePosX: Int32(tileRect.minX), + tilePosY: Int32(tileRect.minY), + tileWidth: Int32(tileRect.size.width), + tileHeight: Int32(tileRect.size.height)) } public func paintTileToImage(canvasSize: CGSize, diff --git a/ios/UnitTest/UnitTest/ViewController.mm b/ios/UnitTest/UnitTest/ViewController.mm index c79c003547c8..fa002f107f27 100644 --- a/ios/UnitTest/UnitTest/ViewController.mm +++ b/ios/UnitTest/UnitTest/ViewController.mm @@ -33,31 +33,6 @@ extern "C" { #import "ViewController.h" #include -// This is from online's Mobile app (as it is called at the moment); -// should of course be factored out to some common place. Here in -// core? - -static thread_local CGContextRef cgc = nullptr; - -static unsigned char *lo_ios_app_get_cgcontext_for_buffer(unsigned char *buffer, int width, int height) -{ - assert(cgc == nullptr); - - cgc = CGBitmapContextCreate(buffer, width, height, 8, width*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little); - - CGContextTranslateCTM(cgc, 0, height); - CGContextScaleCTM(cgc, 1, -1); - - return (unsigned char*)cgc; -} - -static void lo_ios_app_release_cgcontext_for_buffer() -{ - assert(cgc != nullptr); - CGContextRelease(cgc); - cgc = nullptr; -} - @interface ViewController () @end -- cgit v1.2.3