[Libreoffice-commits] online.git: kit/Kit.cpp loleaflet/src
Pranav Kant
pranavk at collabora.co.uk
Thu Nov 9 03:25:32 UTC 2017
kit/Kit.cpp | 89 +++++++++++++++++++++--------
loleaflet/src/control/Control.LokDialog.js | 30 +++++----
loleaflet/src/control/Toolbar.js | 3
loleaflet/src/core/Socket.js | 15 +++-
loleaflet/src/layer/tile/TileLayer.js | 5 -
5 files changed, 99 insertions(+), 43 deletions(-)
New commits:
commit a2a72572bbc7f48b6772ea5481b004102b3f08a0
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Tue Nov 7 15:30:51 2017 +0530
lokdialog: Paint only part of the dialog when specified
Change-Id: I5543c95a48fd0192e5c654598991125bcaeb62e4
Reviewed-on: https://gerrit.libreoffice.org/44519
Reviewed-by: pranavk <pranavk at collabora.co.uk>
Tested-by: pranavk <pranavk at collabora.co.uk>
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index d798ce88..1a7d87c1 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -851,10 +851,6 @@ public:
assert(ws && "Expected a non-null websocket.");
const bool child = tokens[0] == "dialogchild";
- const int nCanvasWidth = 800;
- const int nCanvasHeight = 600;
- size_t pixmapDataSize = 4 * nCanvasWidth * nCanvasHeight;
- std::vector<unsigned char> pixmap(pixmapDataSize);
std::unique_lock<std::mutex> lock(_documentMutex);
if (!_loKitDocument)
@@ -869,38 +865,83 @@ public:
return;
}
- int nWidth = nCanvasWidth;
- int nHeight = nCanvasHeight;
- Timestamp timestamp;
+ int startX = 0, startY = 0;
+ int bufferWidth = 800, bufferHeight = 600; // hopefully, this is big enough
+ std::string paintRectangle;
+ // find the rectangle to paint, if specified
+ if (tokens.size() >= 3 && getTokenString(tokens[2], "rectangle", paintRectangle))
+ {
+ const std::vector<std::string> rectParts = LOOLProtocol::tokenize(paintRectangle.c_str(), paintRectangle.length(), ',');
+ startX = std::atoi(rectParts[0].c_str());
+ startY = std::atoi(rectParts[1].c_str());
+ bufferWidth = std::atoi(rectParts[2].c_str());
+ bufferHeight = std::atoi(rectParts[3].c_str());
+ }
+
+ size_t pixmapDataSize = 4 * bufferWidth * bufferHeight;
+ std::vector<unsigned char> pixmap(pixmapDataSize);
+
char* pDialogTitle = nullptr;
+ int width = bufferWidth;
+ int height = bufferHeight;
+ std::string response;
if (child)
- _loKitDocument->paintActiveFloatingWindow(tokens[1].c_str(), pixmap.data(), nWidth, nHeight);
+ {
+ Timestamp timestamp;
+ _loKitDocument->paintActiveFloatingWindow(tokens[1].c_str(), pixmap.data(), width, height);
+ const auto elapsed = timestamp.elapsed();
+ const double area = width * height;
+ LOG_TRC("paintActiveFloatingWindow for " << tokens[1] << " returned floating window "
+ << width << "X" << height << " "
+ << "rendered in " << (elapsed/1000.)
+ << "ms (" << area / elapsed << " MP/s).");
+
+ response = "dialogchildpaint: id=" + tokens[1] + " width=" + std::to_string(width) + " height=" + std::to_string(height) + "\n";
+ }
else
- _loKitDocument->paintDialog(tokens[1].c_str(), pixmap.data(), &pDialogTitle, nWidth, nHeight);
+ {
+ Timestamp timestamp;
+ _loKitDocument->paintDialog(tokens[1].c_str(), pixmap.data(), startX, startY, width, height);
+ const auto elapsed = timestamp.elapsed();
- const double area = nWidth * nHeight;
- const auto elapsed = timestamp.elapsed();
- LOG_TRC((child ? std::string("paintActiveFloatingWindow") : std::string("paintDialog")) +
- " for " << tokens[1] << " returned with size" << nWidth << "X" << nHeight
- << " and rendered in " << (elapsed/1000.) <<
- " ms (" << area / elapsed << " MP/s).");
+ int dialogWidth = 0;
+ int dialogHeight = 0;
+ _loKitDocument->getDialogInfo(tokens[1].c_str(), &pDialogTitle, dialogWidth, dialogHeight);
- std::string encodedDialogTitle;
- if (pDialogTitle)
- {
- std::string aDialogTitle(pDialogTitle);
- URI::encode(aDialogTitle, "", encodedDialogTitle);
- free(pDialogTitle);
+ std::string encodedDialogTitle;
+ if (pDialogTitle)
+ {
+ std::string aDialogTitle(pDialogTitle);
+ URI::encode(aDialogTitle, "", encodedDialogTitle);
+ free(pDialogTitle);
+ }
+
+ // rendered width, height cannot be less than the dialog width, height
+ width = std::min(width, dialogWidth);
+ height = std::min(height, dialogHeight);
+ const double area = width * height;
+
+ LOG_TRC("paintDialog for " << tokens[1] << " returned " << width << "X" << height
+ << "@(" << startX << "," << startY << ")"
+ << "and rendered in " << (elapsed/1000.)
+ << "ms (" << area / elapsed << " MP/s).");
+
+ response = "dialogpaint: id=" + tokens[1] + " title=" + encodedDialogTitle +
+ " dialogwidth=" + std::to_string(dialogWidth) + " dialogheight=" + std::to_string(dialogHeight);
+
+ if (!paintRectangle.empty())
+ response += " rectangle=" + paintRectangle;
+
+ response += "\n";
}
- const std::string response = std::string(child ? "dialogchildpaint:" : "dialogpaint:") + " id=" + tokens[1] +
- (!encodedDialogTitle.empty() ? " title=" + encodedDialogTitle : "") + " width=" + std::to_string(nWidth) + " height=" + std::to_string(nHeight) + "\n";
+
std::vector<char> output;
output.reserve(response.size() + pixmapDataSize);
output.resize(response.size());
std::memcpy(output.data(), response.data(), response.size());
// TODO: use png cache for dialogs too
- if (!Png::encodeSubBufferToPNG(pixmap.data(), 0, 0, nWidth, nHeight, nCanvasWidth, nCanvasHeight, output, LOK_TILEMODE_RGBA))
+ if (!Png::encodeSubBufferToPNG(pixmap.data(), 0, 0, width, height, bufferWidth, bufferHeight, output, LOK_TILEMODE_RGBA))
{
LOG_ERR("Failed to encode into PNG.");
return;
diff --git a/loleaflet/src/control/Control.LokDialog.js b/loleaflet/src/control/Control.LokDialog.js
index 65ebf07c..e7c2cd4c 100644
--- a/loleaflet/src/control/Control.LokDialog.js
+++ b/loleaflet/src/control/Control.LokDialog.js
@@ -23,13 +23,7 @@ L.Control.LokDialog = L.Control.extend({
if (e.action === 'invalidate') {
// ignore any invalidate callbacks when we have closed the dialog
if (this._isOpen(e.dialogId)) {
- var rect = e.rectangle.match(/\d+g/);
- if (rect != null && rect.length == 4) {
- var json = {
- rectangle: e.rectangle
- };
- }
- this._map.sendDialogCommand(e.dialogId, json);
+ this._map.sendDialogCommand(e.dialogId, e.rectangle);
}
} else if (e.action === 'close') {
this._onDialogClose(e.dialogId);
@@ -158,7 +152,7 @@ L.Control.LokDialog = L.Control.extend({
delete this._dialogs[dialogId];
},
- _paintDialog: function(dialogId, title, imgData) {
+ _paintDialog: function(dialogId, title, rectangle, imgData) {
if (!this._isOpen(dialogId))
return;
@@ -167,7 +161,15 @@ L.Control.LokDialog = L.Control.extend({
var canvas = document.getElementById(dialogId + '-canvas');
var ctx = canvas.getContext('2d');
img.onload = function() {
- ctx.drawImage(img, 0, 0);
+ var x = 0;
+ var y = 0;
+ if (rectangle) {
+ rectangle = rectangle.split(',');
+ x = parseInt(rectangle[0]);
+ y = parseInt(rectangle[1]);
+ }
+
+ ctx.drawImage(img, x, y);
};
img.src = imgData;
},
@@ -178,7 +180,7 @@ L.Control.LokDialog = L.Control.extend({
{
var oldWidth = $('#' + dialogId + '-canvas').width();
var oldHeight = $('#' + dialogId + '-canvas').height();
- if (oldWidth === newWidth && oldHeight === newHeight)
+ if (oldWidth == newWidth && oldHeight == newHeight)
ret = true;
}
@@ -193,14 +195,14 @@ L.Control.LokDialog = L.Control.extend({
return;
if (!this._isOpen(dialogId)) {
- this._launchDialog(dialogId, e.width, e.height);
- } else if (!this._isSameSize(dialogId, e.width, e.height)) {
+ this._launchDialog(dialogId, e.dialogWidth, e.dialogHeight);
+ } else if (!this._isSameSize(dialogId, e.dialogWidth, e.dialogHeight)) {
// size changed - destroy the old sized dialog
this._onDialogClose(dialogId);
- this._launchDialog(dialogId, e.width, e.height);
+ this._launchDialog(dialogId, e.dialogWidth, e.dialogHeight);
}
- this._paintDialog(dialogId, e.title, e.dialog);
+ this._paintDialog(dialogId, e.title, e.rectangle, e.dialog);
},
_onDialogChildPaint: function(e) {
diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 960c02d4..46ebabea 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -146,6 +146,9 @@ L.Map.include({
var dialogCmd = 'dialog';
if (child)
dialogCmd = 'dialogchild';
+ // make sure there are no spaces in rectangle
+ if (rectangle)
+ rectangle = rectangle.replace(/ /g, '');
this._socket.sendMessage(dialogCmd + ' ' + command + (rectangle ? ' rectangle=' + rectangle : ''));
}
},
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 97faaae9..367e2f18 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -745,9 +745,6 @@ L.Socket = L.Class.extend({
else if (tokens[i].substring(0, 6) === 'width=') {
command.width = parseInt(tokens[i].substring(6));
}
- else if (tokens[i].substring(0, 6) === 'title=') {
- command.title = tokens[i].substring(6);
- }
else if (tokens[i].substring(0, 7) === 'height=') {
command.height = parseInt(tokens[i].substring(7));
}
@@ -813,6 +810,18 @@ L.Socket = L.Class.extend({
else if (tokens[i].startsWith('wid=')) {
command.wireId = this.getParameterValue(tokens[i]);
}
+ else if (tokens[i].substring(0, 6) === 'title=') {
+ command.title = tokens[i].substring(6);
+ }
+ else if (tokens[i].substring(0, 12) === 'dialogwidth=') {
+ command.dialogwidth = tokens[i].substring(12);
+ }
+ else if (tokens[i].substring(0, 13) === 'dialogheight=') {
+ command.dialogheight = tokens[i].substring(13);
+ }
+ else if (tokens[i].substring(0, 10) === 'rectangle=') {
+ command.rectangle = tokens[i].substring(10);
+ }
}
if (command.tileWidth && command.tileHeight && this._map._docLayer) {
var defaultZoom = this._map.options.zoom;
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 65f1c5c3..7ee9c90c 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1200,8 +1200,9 @@ L.TileLayer = L.GridLayer.extend({
dialog: img,
title: command.title,
// TODO: add id too
- width: command.width,
- height: command.height
+ dialogWidth: command.dialogwidth,
+ dialogHeight: command.dialogheight,
+ rectangle: command.rectangle
});
},
More information about the Libreoffice-commits
mailing list