diff options
author | Ashod Nakashian <ashod.nakashian@collabora.co.uk> | 2016-05-06 08:16:00 -0400 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2016-05-09 13:58:29 +0200 |
commit | 70e8e788beb122b5779693ecece8f65e27192256 (patch) | |
tree | d6736252493f2294fa64faf648ad28f5644fc97f | |
parent | bc990b011a928ab55b42361415c6eeb5cb9d172c (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 315f566b0568..3f962ba7f19c 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 554a4f4abaf2..ed48935a7b19 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -310,6 +310,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, @@ -388,6 +394,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; @@ -1027,6 +1034,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_BGRA; diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 1281a2182b25..110d4d58f8c8 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -228,6 +228,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 // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 3e3a0e1d501a..7969ed52d32e 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -414,6 +414,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 // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; |