[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - desktop/inc desktop/source include/LibreOfficeKit
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Fri May 6 12:40:09 UTC 2016
desktop/inc/lib/init.hxx | 14 ++++++++-
desktop/source/lib/init.cxx | 46 ++++++++++++++++++++++++++++++
include/LibreOfficeKit/LibreOfficeKit.h | 13 ++++++++
include/LibreOfficeKit/LibreOfficeKit.hxx | 21 +++++++++++++
4 files changed, 93 insertions(+), 1 deletion(-)
New commits:
commit 7f6a0f656ddb2312c3d78091fce663a36ef6e1db
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Fri May 6 08:16:00 2016 -0400
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 at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index 8ed1666..3087c1b 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 f1cb9f0..d043a2f 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 be833db..9f604a3 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 5bd3e60..38292da 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
};
More information about the Libreoffice-commits
mailing list