#include <rdr/MemInStream.h>
#include <rdr/OutStream.h>
#include <rfb/PixelBuffer.h>
+#include <rfb/Region.h>
#include <rfb/CopyRectDecoder.h>
using namespace rfb;
os->copyBytes(is, 4);
}
+
+void CopyRectDecoder::getAffectedRegion(const Rect& rect,
+ const void* buffer,
+ size_t buflen,
+ const ConnParams& cp,
+ Region* region)
+{
+ rdr::MemInStream is(buffer, buflen);
+ int srcX = is.readU16();
+ int srcY = is.readU16();
+
+ Decoder::getAffectedRegion(rect, buffer, buflen, cp, region);
+
+ region->assign_union(Region(rect.translate(Point(srcX-rect.tl.x,
+ srcY-rect.tl.y))));
+}
+
void CopyRectDecoder::decodeRect(const Rect& r, const void* buffer,
size_t buflen, const ConnParams& cp,
ModifiablePixelBuffer* pb)
virtual ~CopyRectDecoder();
virtual void readRect(const Rect& r, rdr::InStream* is,
const ConnParams& cp, rdr::OutStream* os);
+ virtual void getAffectedRegion(const Rect& rect, const void* buffer,
+ size_t buflen, const ConnParams& cp,
+ Region* region);
virtual void decodeRect(const Rect& r, const void* buffer,
size_t buflen, const ConnParams& cp,
ModifiablePixelBuffer* pb);
#include <rfb/CConnection.h>
#include <rfb/DecodeManager.h>
#include <rfb/Decoder.h>
+#include <rfb/Region.h>
#include <rfb/LogWriter.h>
entry->pb = pb;
entry->bufferStream = bufferStream;
+ decoder->getAffectedRegion(r, bufferStream->data(),
+ bufferStream->length(), conn->cp,
+ &entry->affectedRegion);
+
queueMutex->lock();
// The workers add buffers to the end so it's safe to assume
DecodeManager::QueueEntry* DecodeManager::DecodeThread::findEntry()
{
std::list<DecodeManager::QueueEntry*>::iterator iter;
+ Region lockedRegion;
if (manager->workQueue.empty())
return NULL;
for (iter = manager->workQueue.begin();
iter != manager->workQueue.end();
++iter) {
+ DecodeManager::QueueEntry* entry;
+
+ entry = *iter;
+
// Another thread working on this?
- if ((*iter)->active)
- continue;
+ if (entry->active)
+ goto next;
+
+ // Check overlap with earlier rectangles
+ if (!lockedRegion.intersect(entry->affectedRegion).is_empty())
+ goto next;
// FIXME: check dependencies between rects
- return *iter;
+ return entry;
+
+next:
+ lockedRegion.assign_union(entry->affectedRegion);
}
return NULL;
#include <os/Thread.h>
+#include <rfb/Region.h>
#include <rfb/encodings.h>
namespace os {
const ConnParams* cp;
ModifiablePixelBuffer* pb;
rdr::MemOutStream* bufferStream;
+ Region affectedRegion;
};
std::list<rdr::MemOutStream*> freeBuffers;
*/
#include <stdio.h>
#include <rfb/encodings.h>
+#include <rfb/Region.h>
#include <rfb/Decoder.h>
#include <rfb/RawDecoder.h>
#include <rfb/CopyRectDecoder.h>
{
}
+void Decoder::getAffectedRegion(const Rect& rect, const void* buffer,
+ size_t buflen, const ConnParams& cp,
+ Region* region)
+{
+ region->reset(rect);
+}
+
bool Decoder::supported(int encoding)
{
switch (encoding) {
// A lock will be held whilst these are called so it is safe to
// read and update internal state as necessary.
+ // getAffectedRegion() returns the parts of the frame buffer will
+ // be either read from or written do when decoding this rect. The
+ // default implementation simply returns the given rectangle.
+ virtual void getAffectedRegion(const Rect& rect, const void* buffer,
+ size_t buflen, const ConnParams& cp,
+ Region* region);
+
// decodeRect() decodes the given rectangle with data from the
// given buffer, onto the ModifiablePixelBuffer. The PixelFormat of
// the PixelBuffer might not match the ConnParams and it is up to