[Libreoffice-commits] core.git: desktop/source include/LibreOfficeKit ios/LibreOfficeLight ios/UnitTest libreofficekit/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Oct 10 13:29:57 UTC 2018


 desktop/source/lib/init.cxx                                     |   72 +++++++---
 include/LibreOfficeKit/LibreOfficeKit.h                         |   12 +
 include/LibreOfficeKit/LibreOfficeKit.hxx                       |   28 +++
 ios/LibreOfficeLight/LibreOfficeLight.xcodeproj/project.pbxproj |    5 
 ios/LibreOfficeLight/LibreOfficeLight/LOKit/Document.swift      |   24 +--
 ios/UnitTest/UnitTest/ViewController.mm                         |   25 ---
 libreofficekit/qa/tilebench/tilebench.cxx                       |   21 --
 7 files changed, 110 insertions(+), 77 deletions(-)

New commits:
commit 1d279e9c9123d50788cefb186663ef3842aaa8c2
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Oct 10 16:17:18 2018 +0300
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Oct 10 16:25:20 2018 +0300

    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

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index bd907e407a89..5a505910bbfa 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -579,6 +579,13 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
                           const int nCanvasWidth, const int nCanvasHeight,
                           const int nTilePosX, const int nTilePosY,
                           const int nTileWidth, const int nTileHeight);
+#ifdef IOS
+static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
+                                     void* rCGContext,
+                                     const int nCanvasWidth, const int nCanvasHeight,
+                                     const int nTilePosX, const int nTilePosY,
+                                     const int nTileWidth, const int nTileHeight);
+#endif
 static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
                               unsigned char* pBuffer,
                               const int nPart,
@@ -692,6 +699,9 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->getPartName = doc_getPartName;
         m_pDocumentClass->setPartMode = doc_setPartMode;
         m_pDocumentClass->paintTile = doc_paintTile;
+#ifdef IOS
+        m_pDocumentClass->paintTileToCGContext = doc_paintTileToCGContext;
+#endif
         m_pDocumentClass->paintPartTile = doc_paintPartTile;
         m_pDocumentClass->getTileMode = doc_getTileMode;
         m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
@@ -2095,29 +2105,15 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
 #if defined(UNX) && !defined(MACOSX)
 
 #if defined(IOS)
-    SystemGraphicsData aData;
-    aData.rCGContext = reinterpret_cast<CGContextRef>(pBuffer);
-    // the Size argument is irrelevant, I hope
-    ScopedVclPtrInstance<VirtualDevice> pDevice(&aData, Size(1, 1), DeviceFormat::DEFAULT);
+    CGContextRef cgc = CGBitmapContextCreate(pBuffer, nCanvasWidth, nCanvasHeight, 8, nCanvasWidth*4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst | kCGImageByteOrder32Little);
 
-    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    CGContextTranslateCTM(cgc, 0, nCanvasHeight);
+    CGContextScaleCTM(cgc, 1, -1);
 
-    pDevice->SetOutputSizePixel(Size(nCanvasWidth, nCanvasHeight));
+    doc_paintTileToCGContext(pThis, (void*) cgc, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
 
-    pDoc->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight,
-                    nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+    CGContextRelease(cgc);
 
-#if 0
-    // Draw something at least, to see that the context as such is correctly set up
-    CGContextSetRGBFillColor(aData.rCGContext, 0, 0, 1, .5);
-    CGContextFillRect(aData.rCGContext, CGRectMake(20, 0, nCanvasWidth-20, 20));
-    CGContextSetRGBFillColor(aData.rCGContext, 0, 1, 1, .5);
-    CGContextFillRect(aData.rCGContext, CGRectMake(nCanvasWidth-20, 20, 20, nCanvasHeight-20));
-    CGContextSetRGBFillColor(aData.rCGContext, 0, 1, 0, .5);
-    CGContextFillRect(aData.rCGContext, CGRectMake(0, nCanvasHeight-20, nCanvasWidth-20, 20));
-    CGContextSetRGBFillColor(aData.rCGContext, 0, 1, 1, .5);
-    CGContextFillRect(aData.rCGContext, CGRectMake(0, 0, 20, nCanvasHeight-20));
-#endif
 #else
     ScopedVclPtrInstance< VirtualDevice > pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT) ;
 
@@ -2139,6 +2135,44 @@ static void doc_paintTile(LibreOfficeKitDocument* pThis,
 #endif
 }
 
+#ifdef IOS
+
+static void doc_paintTileToCGContext(LibreOfficeKitDocument* pThis,
+                                     void* rCGContext,
+                                     const int nCanvasWidth, const int nCanvasHeight,
+                                     const int nTilePosX, const int nTilePosY,
+                                     const int nTileWidth, const int nTileHeight)
+{
+    SolarMutexGuard aGuard;
+    if (gImpl)
+        gImpl->maLastExceptionMsg.clear();
+
+    SAL_INFO( "lok.tiledrendering", "paintTileToCGContext: painting [" << nTileWidth << "x" << nTileHeight <<
+              "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
+              nCanvasWidth << "x" << nCanvasHeight << "]px" );
+
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
+    if (!pDoc)
+    {
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+        return;
+    }
+
+    SystemGraphicsData aData;
+    aData.rCGContext = reinterpret_cast<CGContextRef>(rCGContext);
+    // the Size argument is irrelevant, I hope
+    ScopedVclPtrInstance<VirtualDevice> pDevice(&aData, Size(1, 1), DeviceFormat::DEFAULT);
+
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+
+    pDevice->SetOutputSizePixel(Size(nCanvasWidth, nCanvasHeight));
+
+    pDoc->paintTile(*pDevice.get(), nCanvasWidth, nCanvasHeight,
+                    nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+}
+
+#endif
 
 static void doc_paintPartTile(LibreOfficeKitDocument* pThis,
                               unsigned char* pBuffer,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 0799584d3097..0ae5c6ff1332 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -309,6 +309,18 @@ struct _LibreOfficeKitDocumentClass
     /// @see lok::Document::getPartInfo().
     char* (*getPartInfo) (LibreOfficeKitDocument* pThis, int nPart);
 
+#ifdef IOS
+    /// @see lok::Document::paintTileToCGContext().
+    void (*paintTileToCGContext) (LibreOfficeKitDocument* pThis,
+                                  void* rCGContext,
+                                  const int nCanvasWidth,
+                                  const int nCanvasHeight,
+                                  const int nTilePosX,
+                                  const int nTilePosY,
+                                  const int nTileWidth,
+                                  const int nTileHeight);
+#endif // IOS
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 232eada69821..3568c861f083 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -550,6 +550,34 @@ public:
         mpDoc->pClass->postWindowExtTextInputEvent(mpDoc, nWindowId, nType, pText);
     }
 
+#ifdef IOS
+    /**
+     * Renders a subset of the document to a Core Graphics context.
+     *
+     * Note that the buffer size and the tile size implicitly supports
+     * rendering at different zoom levels, as the number of rendered pixels and
+     * the rendered rectangle of the document are independent.
+     *
+     * @param rCGContext the CGContextRef, cast to a void*.
+     * @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.
+     * @param nTilePosY logical Y position of the top left corner of the rendered rectangle, in TWIPs.
+     * @param nTileWidth logical width of the rendered rectangle, in TWIPs.
+     * @param nTileHeight logical height of the rendered rectangle, in TWIPs.
+     */
+    void paintTileToCGContext(void* rCGContext,
+                              const int nCanvasWidth,
+                              const int nCanvasHeight,
+                              const int nTilePosX,
+                              const int nTilePosY,
+                              const int nTileWidth,
+                              const int nTileHeight)
+    {
+        return mpDoc->pClass->paintTileToCGContext(mpDoc, rCGContext, nCanvasWidth, nCanvasHeight,
+                                                   nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+    }
+#endif // IOS
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
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<UInt8>,
+    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<UInt8>.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 <postmac.h>
 
-// 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
diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx
index 47d468f01773..1d275d6a44ed 100644
--- a/libreofficekit/qa/tilebench/tilebench.cxx
+++ b/libreofficekit/qa/tilebench/tilebench.cxx
@@ -166,15 +166,8 @@ static void testTile( Document *pDocument, int max_parts,
         {
             // whole part; meaningful only for non-writer documents.
             aTimes.emplace_back("render whole part");
-#ifndef IOS
             pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
                                  nWidth/2, 2000, 1000, 1000); // not square
-#else
-            pDocument->paintTile(lo_ios_app_get_cgcontext_for_buffer(pPixels, nTilePixelWidth, nTilePixelHeight),
-                                 nTilePixelWidth, nTilePixelHeight,
-                                 nWidth/2, 2000, 1000, 1000); // not square
-            lo_ios_app_release_cgcontext_for_buffer();
-#endif
             aTimes.emplace_back();
             if (dump)
                 dumpTile(nTilePixelWidth, nTilePixelHeight, mode, pPixels);
@@ -194,15 +187,8 @@ static void testTile( Document *pDocument, int max_parts,
                         nY = nHeight;
                         break;
                     }
-#ifndef IOS
                     pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
                                          nX, nY, nTilePixelWidth, nTilePixelHeight);
-#else
-                    pDocument->paintTile(lo_ios_app_get_cgcontext_for_buffer(pPixels, nTilePixelWidth, nTilePixelHeight),
-                                         nTilePixelWidth, nTilePixelHeight,
-                                         nX, nY, nTilePixelWidth, nTilePixelHeight);
-                    lo_ios_app_release_cgcontext_for_buffer();
-#endif
                     nTiles++;
                     fprintf (stderr, "   rendered 1:1 tile %d at %d, %d\n",
                              nTiles, nX, nY);
@@ -226,15 +212,8 @@ static void testTile( Document *pDocument, int max_parts,
                         nY = nHeight;
                         break;
                     }
-#ifndef IOS
                     pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
                                          nX, nY, nTileTwipWidth, nTileTwipHeight);
-#else
-                    pDocument->paintTile(lo_ios_app_get_cgcontext_for_buffer(pPixels, nTilePixelWidth, nTilePixelHeight),
-                                         nTilePixelWidth, nTilePixelHeight,
-                                         nX, nY, nTileTwipWidth, nTileTwipHeight);
-                    lo_ios_app_release_cgcontext_for_buffer();
-#endif
                     nTiles++;
                     fprintf (stderr, "   rendered scaled tile %d at %d, %d\n",
                              nTiles, nX, nY);


More information about the Libreoffice-commits mailing list