diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2016-05-06 08:16:00 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2016-05-06 12:39:45 +0000 |
commit | 7f6a0f656ddb2312c3d78091fce663a36ef6e1db (patch) | |
tree | 4a92267c0efaf0bb9d8344bcc20b68291115c632 | |
parent | bd5f5ee9b21fd52e13e759643fe885836f0b82f8 (diff) |
Allow painting for arbitrary part
Painting should not cause any state changes, but
to paint a tile on a different part than the current
has to change the document, which sends notifications
to all clients.
A new API, paintPartTile, allows for painting tiles
on any part without sending change of part notifications.
Furthermore, because we block notifications during this
operation, no tile invalidation is issued due to
changing of the part.
One issue remains in the cases when the LO Core
resets the cursor position internally and we resume
editing after painting, the cursor might be at the top
of the page. This needs fixing separately.
Change-Id: If19bd1c90ecad4d5ed5e8d09513741b7994fa6e5
Reviewed-on: https://gerrit.libreoffice.org/24698
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
-rw-r--r-- | desktop/inc/lib/init.hxx | 14 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 46 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 13 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 21 |
4 files changed, 93 insertions, 1 deletions
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx index 8ed166676c91..3087c1b89b97 100644 --- a/desktop/inc/lib/init.hxx +++ b/desktop/inc/lib/init.hxx @@ -33,7 +33,8 @@ namespace desktop { explicit CallbackFlushHandler(LibreOfficeKitCallback pCallback, void* pData) : Idle( "lokit timer callback" ), m_pCallback(pCallback), - m_pData(pData) + m_pData(pData), + m_bPartTilePainting(false) { SetPriority(SchedulerPriority::POST_PAINT); @@ -78,6 +79,13 @@ namespace desktop { void queue(const int type, const char* data) { + if (m_bPartTilePainting) + { + // We drop notifications when this is set. + return; + } + + const std::string payload(data ? data : "(nil)"); std::unique_lock<std::mutex> lock(m_mutex); @@ -145,6 +153,9 @@ namespace desktop { } } + void setPartTilePainting(const bool bPartPainting) { m_bPartTilePainting = bPartPainting; } + bool isPartTilePainting() const { return m_bPartTilePainting; } + private: void flush() { @@ -187,6 +198,7 @@ namespace desktop { std::map<int, std::string> m_states; LibreOfficeKitCallback m_pCallback; void *m_pData; + bool m_bPartTilePainting; std::mutex m_mutex; }; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index f1cb9f05ff0d..d043a2f32f2c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -324,6 +324,12 @@ void doc_paintTile(LibreOfficeKitDocument* pThis, const int nCanvasWidth, const int nCanvasHeight, const int nTilePosX, const int nTilePosY, const int nTileWidth, const int nTileHeight); +void doc_paintPartTile(LibreOfficeKitDocument* pThis, + unsigned char* pBuffer, + const int nPart, + const int nCanvasWidth, const int nCanvasHeight, + const int nTilePosX, const int nTilePosY, + const int nTileWidth, const int nTileHeight); static int doc_getTileMode(LibreOfficeKitDocument* pThis); static void doc_getDocumentSize(LibreOfficeKitDocument* pThis, long* pWidth, @@ -402,6 +408,7 @@ 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; + m_pDocumentClass->paintPartTile = doc_paintPartTile; m_pDocumentClass->getTileMode = doc_getTileMode; m_pDocumentClass->getDocumentSize = doc_getDocumentSize; m_pDocumentClass->initializeForRendering = doc_initializeForRendering; @@ -1076,6 +1083,45 @@ void doc_paintTile(LibreOfficeKitDocument* pThis, #endif } + +void doc_paintPartTile(LibreOfficeKitDocument* pThis, + unsigned char* pBuffer, + const int nPart, + const int nCanvasWidth, const int nCanvasHeight, + const int nTilePosX, const int nTilePosY, + const int nTileWidth, const int nTileHeight) +{ + SAL_INFO( "lok.tiledrendering", "paintPartTile: painting @ " << nPart << " [" + << nTileWidth << "x" << nTileHeight << "]@(" + << nTilePosX << ", " << nTilePosY << ") to [" + << nCanvasWidth << "x" << nCanvasHeight << "]px" ); + + // Disable callbacks while we are painting. + LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis); + pDocument->mpCallbackFlushHandler->setPartTilePainting(true); + try + { + const int nOrigPart = doc_getPart(pThis); + if (nPart != nOrigPart) + { + doc_setPart(pThis, nPart); + } + + doc_paintTile(pThis, pBuffer, nCanvasWidth, nCanvasHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight); + + if (nPart != nOrigPart) + { + doc_setPart(pThis, nOrigPart); + } + } + catch (const std::exception& exception) + { + // Nothing to do but restore the PartTilePainting flag. + } + + pDocument->mpCallbackFlushHandler->setPartTilePainting(false); +} + static int doc_getTileMode(LibreOfficeKitDocument* /*pThis*/) { return LOK_TILEMODE_RGBA; diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index be833dbaf1d9..9f604a39ed5f 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -226,6 +226,19 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::getPartHash(). char* (*getPartHash) (LibreOfficeKitDocument* pThis, int nPart); + + /// Paints a tile from a specific part. + /// @see lok::Document::paintTile(). + void (*paintPartTile) (LibreOfficeKitDocument* pThis, + unsigned char* pBuffer, + const int nPart, + const int nCanvasWidth, + const int nCanvasHeight, + const int nTilePosX, + const int nTilePosY, + const int nTileWidth, + const int nTileHeight); + #endif // LOK_USE_UNSTABLE_API }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 5bd3e60b9286..38292daafe17 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -411,6 +411,27 @@ public: return mpDoc->pClass->renderFont(mpDoc, pFontName, pFontWidth, pFontHeight); } + /** + * Renders a subset of the document's part to a pre-allocated buffer. + * + * @param nPart the part number of the document of which the tile is painted. + * @see paintTile. + */ + inline void paintPartTile(unsigned char* pBuffer, + const int nPart, + const int nCanvasWidth, + const int nCanvasHeight, + const int nTilePosX, + const int nTilePosY, + const int nTileWidth, + const int nTileHeight) + { + return mpDoc->pClass->paintPartTile(mpDoc, pBuffer, nPart, + nCanvasWidth, nCanvasHeight, + nTilePosX, nTilePosY, + nTileWidth, nTileHeight); + } + #endif // LOK_USE_UNSTABLE_API }; |