/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
+#include <assert.h>
#include <string.h>
#include <rfb/Cursor.h>
#include <rfb/LogWriter.h>
+#include <rfb/Exception.h>
using namespace rfb;
data = newData;
mask.buf = newMask;
}
+
+RenderedCursor::RenderedCursor()
+{
+}
+
+const rdr::U8* RenderedCursor::getBuffer(const Rect& _r, int* stride)
+{
+ Rect r;
+
+ r = _r.translate(offset.negate());
+ if (!r.enclosed_by(buffer.getRect()))
+ throw Exception("RenderedCursor: Invalid area requested");
+
+ return buffer.getBuffer(r, stride);
+}
+
+void RenderedCursor::update(PixelBuffer* framebuffer,
+ Cursor* cursor, const Point& pos)
+{
+ Point rawOffset;
+ Rect clippedRect;
+
+ const rdr::U8* data;
+ int stride;
+
+ assert(framebuffer);
+ assert(cursor);
+
+ if (!framebuffer->getPF().equal(cursor->getPF()))
+ throw Exception("RenderedCursor: Trying to render cursor on incompatible frame buffer");
+
+ format = framebuffer->getPF();
+ width_ = framebuffer->width();
+ height_ = framebuffer->height();
+
+ rawOffset = pos.subtract(cursor->hotspot);
+ clippedRect = cursor->getRect(rawOffset).intersect(framebuffer->getRect());
+ offset = clippedRect.tl;
+
+ buffer.setPF(cursor->getPF());
+ buffer.setSize(clippedRect.width(), clippedRect.height());
+
+ data = framebuffer->getBuffer(buffer.getRect(offset), &stride);
+ buffer.imageRect(buffer.getRect(), data, stride);
+
+ data = cursor->getBuffer(cursor->getRect(), &stride);
+ buffer.maskRect(cursor->getRect(rawOffset.subtract(offset)),
+ data, cursor->mask.buf);
+}
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
+ * Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
void crop();
};
+ class RenderedCursor : public PixelBuffer {
+ public:
+ RenderedCursor();
+
+ Rect getEffectiveRect() const { return buffer.getRect(offset); }
+
+ virtual const rdr::U8* getBuffer(const Rect& r, int* stride);
+
+ void update(PixelBuffer* framebuffer, Cursor* cursor, const Point& pos);
+
+ protected:
+ ManagedPixelBuffer buffer;
+ Point offset;
+ };
+
}
#endif
if (needRenderedCursor()) {
renderedCursorRect
- = (server->renderedCursor.getRect(server->renderedCursorTL)
- .intersect(req.get_bounding_rect()));
+ = server->renderedCursor.getEffectiveRect()
+ .intersect(req.get_bounding_rect());
if (renderedCursorRect.is_empty()) {
drawRenderedCursor = false;
if (drawRenderedCursor) {
image_getter.setPixelBuffer(&server->renderedCursor);
- image_getter.setOffset(server->renderedCursorTL);
-
encoders[encoding]->writeRect(renderedCursorRect, &image_getter);
-
image_getter.setPixelBuffer(server->pb);
- image_getter.setOffset(Point(0,0));
drawRenderedCursor = false;
}
comparer = new ComparingUpdateTracker(pb);
cursor.setPF(pb->getPF());
- renderedCursor.setPF(pb->getPF());
+ renderedCursorInvalid = true;
// Make sure that we have at least one screen
if (screenLayout.num_screens() == 0)
if (renderCursor) {
Rect clippedCursorRect
- = cursor.getRect(cursorTL()).intersect(pb->getRect());
+ = cursor.getRect(cursorPos.subtract(cursor.hotspot)).intersect(pb->getRect());
if (!renderedCursorInvalid && (toCheck.intersect(clippedCursorRect)
.is_empty())) {
renderCursor = false;
} else {
- renderedCursorTL = clippedCursorRect.tl;
- renderedCursor.setSize(clippedCursorRect.width(),
- clippedCursorRect.height());
toCheck.assign_union(clippedCursorRect);
}
}
comparer->getUpdateInfo(&ui, pb->getRect());
if (renderCursor) {
- const rdr::U8* buffer;
- int stride;
-
- buffer = pb->getBuffer(renderedCursor.getRect(renderedCursorTL), &stride);
- renderedCursor.imageRect(renderedCursor.getRect(), buffer, stride);
-
- buffer = cursor.getBuffer(cursor.getRect(), &stride);
- renderedCursor.maskRect(cursor.getRect(cursorTL()
- .subtract(renderedCursorTL)),
- buffer, cursor.mask.buf);
-
+ renderedCursor.update(pb, &cursor, cursorPos);
renderedCursorInvalid = false;
}
Point cursorPos;
Cursor cursor;
- Point cursorTL() { return cursorPos.subtract(cursor.hotspot); }
- Point renderedCursorTL;
- ManagedPixelBuffer renderedCursor;
+ RenderedCursor renderedCursor;
bool renderedCursorInvalid;
// - Check how many of the clients are authenticated.