summaryrefslogtreecommitdiff
path: root/libreofficekit
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2017-11-19 20:38:43 -0500
committerAshod Nakashian <ashnakash@gmail.com>2017-12-23 01:30:01 +0100
commita692cdf779dc998f58ebf9e9f84f22edf7dbe421 (patch)
tree746cdb231833aab33d9c6fed5ecdafe469d05cdf /libreofficekit
parent39d1022967297524b852b5c82e78d815cf908b3d (diff)
LOK: tilebench improvements
* Arguments for max number of parts and tiles to render (optional). + Automatic estimation of maximum tiles to render based on max parts for Writer docs, since there is only 1 part, this caps the number of pages to render, similar to other doc types. * Fixed rendering of Writer documents over and over (as many times as pages). + Writer has a single part, unlike other doc types. + No point in rendering the whole document in writer to a single tile, since that's completely unrealistic and impractical (it takes forever for large docs and artificially spikes the memory). * Rendering starts at the current part and not the first. + This gives the spreadsheet of interest priority (if saved as visible). * The tile size is now more realistic as we use the same dimensions as the Online client does. * When rendering tiles at scale, we use the same dimensions as the Online client rather than splitting the width by 4, for realism. * Rendering of tiles is done rows-first, rather than columns-first, which is similar to what the Online client does, which is more cache friendly, therefore more realistic. * Enabled compiling of tilebench when GTK3 is disabled, which was erroneous, since tilebench doesn't have any dependency on GTK. + Now it's possible to compile with local Cairo/Pixman libs. Reviewed-on: https://gerrit.libreoffice.org/44936 Reviewed-by: Jan Holesovsky <kendy@collabora.com> Tested-by: Jan Holesovsky <kendy@collabora.com> (cherry picked from commit 7db98521548de9eab955ee25a5aacaaef42df323) Change-Id: I6ad2e97f39572778dd7d0c12d14550841c1d6963 Reviewed-on: https://gerrit.libreoffice.org/46984 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'libreofficekit')
-rw-r--r--libreofficekit/Executable_tilebench.mk1
-rw-r--r--libreofficekit/Module_libreofficekit.mk5
-rw-r--r--libreofficekit/qa/tilebench/tilebench.cxx102
3 files changed, 73 insertions, 35 deletions
diff --git a/libreofficekit/Executable_tilebench.mk b/libreofficekit/Executable_tilebench.mk
index 4da51d3ca686..9d8b2a134f99 100644
--- a/libreofficekit/Executable_tilebench.mk
+++ b/libreofficekit/Executable_tilebench.mk
@@ -15,7 +15,6 @@ $(eval $(call gb_Executable_set_include,tilebench,\
))
$(eval $(call gb_Executable_use_libraries,tilebench,\
- libreofficekitgtk \
sal \
))
diff --git a/libreofficekit/Module_libreofficekit.mk b/libreofficekit/Module_libreofficekit.mk
index c74c0681328e..2d7519c46ca1 100644
--- a/libreofficekit/Module_libreofficekit.mk
+++ b/libreofficekit/Module_libreofficekit.mk
@@ -24,10 +24,13 @@ ifneq ($(ENABLE_GTK3),)
$(eval $(call gb_Module_add_targets,libreofficekit,\
Library_libreofficekitgtk \
Executable_gtktiledviewer \
+))
+endif # ($(ENABLE_GTK3),)
+
+$(eval $(call gb_Module_add_targets,libreofficekit,\
Executable_tilebench \
Package_selectionhandles \
))
-endif # ($(ENABLE_GTK3),)
endif
diff --git a/libreofficekit/qa/tilebench/tilebench.cxx b/libreofficekit/qa/tilebench/tilebench.cxx
index 686523211a3b..ed8d44c13789 100644
--- a/libreofficekit/qa/tilebench/tilebench.cxx
+++ b/libreofficekit/qa/tilebench/tilebench.cxx
@@ -10,10 +10,12 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
+#include <cmath>
#include <vector>
#include <osl/time.h>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <LibreOfficeKit/LibreOfficeKitInit.h>
#include <LibreOfficeKit/LibreOfficeKit.hxx>
@@ -21,7 +23,7 @@ using namespace lok;
static int help()
{
- fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document]\n" );
+ fprintf( stderr, "Usage: tilebench <absolute-path-to-libreoffice-install> [path to document] [max parts|-1] [max tiles|-1]\n" );
fprintf( stderr, "renders a selection of small tiles from the document, checksums them and times the process\n" );
return 1;
}
@@ -36,13 +38,17 @@ static double getTimeNow()
int main( int argc, char* argv[] )
{
+ static const double origin = getTimeNow();
struct TimeRecord {
const char *mpName;
double mfTime;
TimeRecord() : mpName(nullptr), mfTime(getTimeNow()) { }
explicit TimeRecord(const char *pName) :
- mpName(pName ), mfTime(getTimeNow()) { }
+ mpName(pName), mfTime(getTimeNow())
+ {
+ fprintf(stderr, "%3.3fs - %s\n", (mfTime - origin), mpName);
+ }
};
std::vector< TimeRecord > aTimes;
if( argc < 2 ||
@@ -55,11 +61,20 @@ int main( int argc, char* argv[] )
return 1;
}
+ // Use realistic dimensions, similar to the Online client.
+ long nTilePixelWidth = 512;
+ long nTilePixelHeight = 512;
+ long nTileTwipWidth = 3840;
+ long nTileTwipHeight = 3840;
+
aTimes.emplace_back("initialization");
// coverity[tainted_string] - build time test tool
Office *pOffice = lok_cpp_init(argv[1]);
aTimes.emplace_back();
+ const int max_parts = (argc > 3 ? atoi(argv[3]) : -1);
+ const int max_tiles = (argc > 4 ? atoi(argv[4]) : -1);
+
if (argv[2] != nullptr)
{
aTimes.emplace_back("load document");
@@ -67,12 +82,17 @@ int main( int argc, char* argv[] )
aTimes.emplace_back();
aTimes.emplace_back("getparts");
- int nParts = pDocument->getParts();
+ const int nOriginalPart = pDocument->getPart();
+ // Writer really has 1 part (the full doc).
+ const int nTotalParts = (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT ? 1 : pDocument->getParts());
+ const int nParts = (max_parts < 0 ? nTotalParts : std::min(max_parts, nTotalParts));
+ fprintf(stderr, "Parts to render: %d, Total Parts: %d, Max parts: %d, Max tiles: %d\n", nParts, nTotalParts, max_parts, max_tiles);
aTimes.emplace_back();
aTimes.emplace_back("get size of parts");
- for (int nPart = 0; nPart < nParts; nPart++)
+ for (int n = 0; n < nParts; ++n)
{
+ const int nPart = (nOriginalPart + n) % nTotalParts;
char* pName = pDocument->getPartName(nPart);
pDocument->setPart(nPart);
long nWidth = 0, nHeight = 0;
@@ -82,40 +102,49 @@ int main( int argc, char* argv[] )
}
aTimes.emplace_back();
- unsigned char pPixels[256*256*4];
- for (int nPart = 0; nPart < nParts; nPart++)
+ std::vector<unsigned char> vBuffer(nTilePixelWidth * nTilePixelHeight * 4);
+ unsigned char* pPixels = &vBuffer[0];
+
+ for (int n = 0; n < nParts; ++n)
{
- {
- char* pName = pDocument->getPartName(nPart);
- fprintf (stderr, "render '%s'\n", pName);
- free (pName);
- }
+ const int nPart = (nOriginalPart + n) % nTotalParts;
+ char* pName = pDocument->getPartName(nPart);
pDocument->setPart(nPart);
long nWidth = 0, nHeight = 0;
pDocument->getDocumentSize(&nWidth, &nHeight);
+ fprintf (stderr, "render '%s' -> %ld, %ld\n", pName, nWidth, nHeight);
+ free (pName);
- { // whole document
- aTimes.emplace_back("render whole document");
- pDocument->paintTile(pPixels, 256, 256,
+ if (pDocument->getDocumentType() != LOK_DOCTYPE_TEXT)
+ { // whole part; meaningful only for non-writer documents.
+ aTimes.emplace_back("render whole part");
+ pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
0, 0, nWidth, nHeight); // not square
aTimes.emplace_back();
}
{ // 1:1
aTimes.emplace_back("render sub-region at 1:1");
+ // Estimate the maximum tiles based on the number of parts requested, if Writer.
+ int nMaxTiles = max_tiles;
+ if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT)
+ nMaxTiles = (int)ceil(max_parts * 16128. / nTilePixelHeight) * ceil((double)nWidth / nTilePixelWidth);
int nTiles = 0;
- int nSplit = nWidth / 4;
- for (int nX = 0; nX < 4; nX++)
+ for (int nY = 0; nY < nHeight - 1; nY += nTilePixelHeight)
{
- for (int nY = 0; nY < nHeight / nSplit; nY++)
+ for (int nX = 0; nX < nWidth - 1; nX += nTilePixelWidth)
{
- int nTilePosX = nX * nSplit;
- int nTilePosY = nY * nSplit;
- pDocument->paintTile(pPixels, 256, 256,
- nTilePosX, nTilePosY, 256, 256);
+ if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
+ {
+ nY = nHeight;
+ break;
+ }
+
+ pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
+ nX, nY, nTilePixelWidth, nTilePixelHeight);
nTiles++;
- fprintf (stderr, " rendered tile %d at %d, %d\n",
- nTiles, nTilePosX, nTilePosY);
+ fprintf (stderr, " rendered 1:1 tile %d at %d, %d\n",
+ nTiles, nX, nY);
}
}
aTimes.emplace_back();
@@ -123,19 +152,26 @@ int main( int argc, char* argv[] )
{ // scaled
aTimes.emplace_back("render sub-regions at scale");
+ // Estimate the maximum tiles based on the number of parts requested, if Writer.
+ int nMaxTiles = max_tiles;
+ if (pDocument->getDocumentType() == LOK_DOCTYPE_TEXT)
+ nMaxTiles = (int)ceil(max_parts * 16128. / nTileTwipHeight) * ceil((double)nWidth / nTileTwipWidth);
int nTiles = 0;
- int nSplit = nWidth / 4;
- for (int nX = 0; nX < 4; nX++)
+ for (int nY = 0; nY < nHeight - 1; nY += nTileTwipHeight)
{
- for (int nY = 0; nY < nHeight / nSplit; nY++)
+ for (int nX = 0; nX < nWidth - 1; nX += nTileTwipWidth)
{
- int nTilePosX = nX * nSplit;
- int nTilePosY = nY * nSplit;
- pDocument->paintTile(pPixels, 256, 256,
- nTilePosX, nTilePosY, nSplit, nSplit);
+ if (nMaxTiles >= 0 && nTiles >= nMaxTiles)
+ {
+ nY = nHeight;
+ break;
+ }
+
+ pDocument->paintTile(pPixels, nTilePixelWidth, nTilePixelHeight,
+ nX, nY, nTileTwipWidth, nTileTwipHeight);
nTiles++;
- fprintf (stderr, " rendered tile %d at %d, %d\n",
- nTiles, nTilePosX, nTilePosY);
+ fprintf (stderr, " rendered scaled tile %d at %d, %d\n",
+ nTiles, nX, nY);
}
}
aTimes.emplace_back();
@@ -153,7 +189,7 @@ int main( int argc, char* argv[] )
fprintf (stderr, "profile run:\n");
for (size_t i = 0; i < aTimes.size() - 1; i++)
{
- double nDelta = aTimes[i+1].mfTime - aTimes[i].mfTime;
+ const double nDelta = aTimes[i+1].mfTime - aTimes[i].mfTime;
fprintf (stderr, " %s - %2.4f(ms)\n", aTimes[i].mpName, nDelta * 1000.0);
if (aTimes[i+1].mpName == nullptr)
i++; // skip it.