diff --git a/vncviewer/abstractvncview.cxx b/vncviewer/abstractvncview.cxx index 8f58482e78..a3ce878a65 100644 --- a/vncviewer/abstractvncview.cxx +++ b/vncviewer/abstractvncview.cxx @@ -696,31 +696,44 @@ void QAbstractVNCView::updateWindow() int w = rect.br.x - x; int h = rect.br.y - y; if (!rect.is_empty()) { + damage += QRect(x, y, w, h); update(x, y, w, h); } } void QAbstractVNCView::paintEvent(QPaintEvent *event) { - QRect rect = event->rect(); - int x = rect.x(); - int y = rect.y(); - int w = rect.width(); - int h = rect.height(); - QVNCConnection *cc = AppManager::instance()->connection(); PlatformPixelBuffer *framebuffer = static_cast(cc->framebuffer()); - QPainter painter(this); + if ((framebuffer->width() != pixmap.width()) || + (framebuffer->height() != pixmap.height())) { + pixmap = QPixmap(framebuffer->width(), framebuffer->height()); + damage = QRegion(0, 0, pixmap.width(), pixmap.height()); + } + + if (!damage.isEmpty()) { + QPainter pixmapPainter(&pixmap); + const uint8_t *data; + int stride; + QRect bounds = damage.boundingRect(); + int x = bounds.x(); + int y = bounds.y(); + int w = bounds.width(); + int h = bounds.height(); + rfb::Rect rfbrect(x, y, x+w, y+h); - const uint8_t *data; - int stride; - rfb::Rect rfbrect(x, y, x+w, y+h); + data = framebuffer->getBuffer(rfbrect, &stride); + QImage image(data, w, h, stride*4, QImage::Format_RGB32); - data = framebuffer->getBuffer(rfbrect, &stride); - QImage image(data, w, h, stride*4, QImage::Format_RGB32); + pixmapPainter.drawImage(bounds, image); + damage = QRegion(); + } + + QPainter painter(this); + QRect rect = event->rect(); - painter.drawImage(rect, image); + painter.drawPixmap(rect, pixmap, rect); } void QAbstractVNCView::handleDesktopSize() diff --git a/vncviewer/abstractvncview.h b/vncviewer/abstractvncview.h index 616e4cb3c2..4a9d9f0df8 100644 --- a/vncviewer/abstractvncview.h +++ b/vncviewer/abstractvncview.h @@ -79,6 +79,9 @@ public slots: void delayedInitialized(); protected: + QPixmap pixmap; + QRegion damage; + static QClipboard *clipboard_; QByteArray geometry_; double devicePixelRatio_;