Commit b53b0657 by Ludmány Balázs

Reuse buffers

parent 3aeb58bf
TEMPLATE = app TEMPLATE = app
QT += qml quick QT += qml quick
CONFIG += c++14 CONFIG += c++11 ofast
SOURCES += main.cpp \ SOURCES += main.cpp \
jpegdecoder.cpp \ jpegdecoder.cpp \
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2016-07-26T16:47:48. --> <!-- Written by QtCreator 3.5.1, 2016-07-27T15:57:27. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
......
...@@ -3,6 +3,5 @@ varying mediump vec2 vartexcoord; ...@@ -3,6 +3,5 @@ varying mediump vec2 vartexcoord;
void main(void) void main(void)
{ {
gl_FragColor = vec4(texture2D(texture, vartexcoord).rgb, 1.0); gl_FragColor = texture2D(texture, vartexcoord);
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
} }
...@@ -7,5 +7,5 @@ varying mediump vec2 vartexcoord; ...@@ -7,5 +7,5 @@ varying mediump vec2 vartexcoord;
void main(void) void main(void)
{ {
gl_Position = vec4((position.x - 1024.0) / 1024.0, (position.y - 1024.0) / 1024.0, 0.0, 1.0); gl_Position = vec4((position.x - 1024.0) / 1024.0, (position.y - 1024.0) / 1024.0, 0.0, 1.0);
vartexcoord = vec2(0.0, 1.0) - vec2(texcoord.x / 1280.0, texcoord.y / 720.0); vartexcoord = vec2(texcoord.x / 1280.0, texcoord.y / 720.0);
} }
...@@ -31,8 +31,7 @@ void Dispatcher::GotBitmap(rfbClient *client, const uint8_t *buffer, int x, int ...@@ -31,8 +31,7 @@ void Dispatcher::GotBitmap(rfbClient *client, const uint8_t *buffer, int x, int
{ {
Dispatcher *dispatcher = (Dispatcher *) rfbClientGetClientData(client, 0); Dispatcher *dispatcher = (Dispatcher *) rfbClientGetClientData(client, 0);
// We have to make a deep copy because libvnc might free the buffer as soon as this function returns // We have to make a deep copy because libvnc might free the buffer as soon as this function returns
QImage image(buffer, w, h, QImage::Format_RGBX8888); dispatcher->uploader()->gotBitmap(buffer, x, y, w, h);
dispatcher->uploader()->gotBitmap(image.convertToFormat(QImage::Format_RGB888), x, y, w, h);
} }
rfbBool Dispatcher::GotJpeg(rfbClient *client, const uint8_t *buffer, int length, int x, int y, int w, int h) rfbBool Dispatcher::GotJpeg(rfbClient *client, const uint8_t *buffer, int length, int x, int y, int w, int h)
...@@ -152,21 +151,21 @@ void Dispatcher::refresh() ...@@ -152,21 +151,21 @@ void Dispatcher::refresh()
int message = 0; int message = 0;
// Wait until we get something if(!HandleRFBServerMessage(m_client)) {
while(message == 0) {
message = WaitForMessage(m_client, 1000);
if(message < 0) {
terminate(); terminate();
emit error(); emit error();
return; return;
} }
}
if(!HandleRFBServerMessage(m_client)) { // Wait until we get something
while(message == 0) {
message = WaitForMessage(m_client, 1000);
if(message < 0) {
terminate(); terminate();
emit error(); emit error();
return; return;
} }
}
} }
void Dispatcher::terminate() void Dispatcher::terminate()
......
...@@ -4,6 +4,5 @@ varying lowp vec4 varcolor; ...@@ -4,6 +4,5 @@ varying lowp vec4 varcolor;
void main(void) void main(void)
{ {
gl_FragColor = vec4(texture2D(texture, vartexcoord).rgb, 1.0) + varcolor; gl_FragColor = vec4(texture2D(texture, vartexcoord).rgb + varcolor.rgb, 1.0);
// gl_FragColor = vec4(vartexcoord, 0.0, 1.0);
} }
...@@ -10,6 +10,6 @@ varying mediump vec2 vartexcoord; ...@@ -10,6 +10,6 @@ varying mediump vec2 vartexcoord;
void main(void) void main(void)
{ {
gl_Position = ortho * vec4(position, 0.0, 1.0); gl_Position = ortho * vec4(position, 0.0, 1.0);
varcolor = color.gggg; varcolor = color;
vartexcoord = vec2(texcoord.x / 2048.0, texcoord.y / 2048.0); vartexcoord = vec2(texcoord.x / 2048.0, texcoord.y / 2048.0);
} }
...@@ -9,10 +9,6 @@ JpegDecoder::JpegDecoder(ConcurrentQueue<Jpeg *, 256u> *queue, QObject *parent) ...@@ -9,10 +9,6 @@ JpegDecoder::JpegDecoder(ConcurrentQueue<Jpeg *, 256u> *queue, QObject *parent)
void JpegDecoder::operate() void JpegDecoder::operate()
{ {
Jpeg *jpeg;
forever {
jpeg = m_queue->dequeue();
struct jpeg_decompress_struct cinfo; struct jpeg_decompress_struct cinfo;
struct error_mgr jerr; struct error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr.mgr); cinfo.err = jpeg_std_error(&jerr.mgr);
...@@ -21,15 +17,24 @@ void JpegDecoder::operate() ...@@ -21,15 +17,24 @@ void JpegDecoder::operate()
jpeg_destroy_decompress(&cinfo); jpeg_destroy_decompress(&cinfo);
} }
jpeg_create_decompress(&cinfo); jpeg_create_decompress(&cinfo);
cinfo.do_fancy_upsampling = TRUE; Jpeg *jpeg;
cinfo.dct_method = JDCT_FLOAT; JSAMPLE *samples;
JSAMPROW *rows;
forever {
jpeg = m_queue->dequeue();
jpeg_mem_src(&cinfo, jpeg->data, jpeg->length); jpeg_mem_src(&cinfo, jpeg->data, jpeg->length);
(void) jpeg_read_header(&cinfo, TRUE); (void) jpeg_read_header(&cinfo, TRUE);
cinfo.dct_method = JDCT_FASTEST;
cinfo.do_fancy_upsampling = FALSE;
cinfo.two_pass_quantize = FALSE;
cinfo.dither_mode = JDITHER_ORDERED;
//cinfo.scale_num = 1;
//cinfo.scale_denom = 8;
cinfo.out_color_space = JCS_EXT_RGBX;
(void) jpeg_start_decompress(&cinfo); (void) jpeg_start_decompress(&cinfo);
JSAMPLE *samples = new JSAMPLE[cinfo.output_width * cinfo.output_height * cinfo.output_components]; samples = new JSAMPLE[cinfo.output_width * cinfo.output_height * cinfo.output_components];
JSAMPROW *rows = new JSAMPROW[cinfo.output_height * cinfo.output_components]; rows = new JSAMPROW[cinfo.output_height * cinfo.output_components];
for(size_t i = 0; i < cinfo.output_height; i++) { for(size_t i = 0; i < cinfo.output_height; i++) {
rows[i] = samples + (i * cinfo.output_width * cinfo.output_components); rows[i] = samples + (i * cinfo.output_width * cinfo.output_components);
} }
...@@ -41,7 +46,7 @@ void JpegDecoder::operate() ...@@ -41,7 +46,7 @@ void JpegDecoder::operate()
emit finished(samples, jpeg->x, jpeg->y, jpeg->width, jpeg->height); emit finished(samples, jpeg->x, jpeg->y, jpeg->width, jpeg->height);
delete[] jpeg->data; delete[] jpeg->data;
delete jpeg; delete jpeg;
delete rows; delete[] rows;
jpeg_destroy_decompress(&cinfo);
} }
jpeg_destroy_decompress(&cinfo);
} }
...@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) ...@@ -16,7 +16,7 @@ int main(int argc, char *argv[])
format.setMajorVersion(2); format.setMajorVersion(2);
format.setMinorVersion(0); format.setMinorVersion(0);
format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRenderableType(QSurfaceFormat::OpenGLES);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); format.setSwapBehavior(QSurfaceFormat::SingleBuffer);
format.setSwapInterval(0); format.setSwapInterval(0);
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES, true); QGuiApplication::setAttribute(Qt::AA_UseOpenGLES, true);
...@@ -28,4 +28,3 @@ int main(int argc, char *argv[]) ...@@ -28,4 +28,3 @@ int main(int argc, char *argv[])
return app.exec(); return app.exec();
} }
...@@ -4,8 +4,8 @@ import thinclient 1.3 ...@@ -4,8 +4,8 @@ import thinclient 1.3
ApplicationWindow { ApplicationWindow {
visible: true visible: true
width: vnc.width width: 800
height: tab.height + vnc.height height: 600
id: window id: window
header: TabBar { header: TabBar {
...@@ -30,5 +30,6 @@ ApplicationWindow { ...@@ -30,5 +30,6 @@ ApplicationWindow {
port: 10495 port: 10495
width: 1280 width: 1280
height: 720 height: 720
transform: Scale {xScale: window.width / vnc.width; yScale: (window.height - tab.height) / vnc.height}
} }
} }
...@@ -164,7 +164,7 @@ void QVnc::wheelEvent(QWheelEvent *event) ...@@ -164,7 +164,7 @@ void QVnc::wheelEvent(QWheelEvent *event)
void QVnc::mouseMoveEvent(QMouseEvent *event) void QVnc::mouseMoveEvent(QMouseEvent *event)
{ {
// Filter mouse move events, we don't need 100+ of them in a second // Filter mouse move events, we don't need 100+ of them in a second
if((event->timestamp() - m_lastMouseEvent) > 33) { //if((event->timestamp() - m_lastMouseEvent) > 33) {
Qt::MouseButtons buttons = event->buttons(); Qt::MouseButtons buttons = event->buttons();
m_lastMouseEvent = event->timestamp(); m_lastMouseEvent = event->timestamp();
if(m_dispatcher->mouseEvent(event->x(), if(m_dispatcher->mouseEvent(event->x(),
...@@ -177,7 +177,7 @@ void QVnc::mouseMoveEvent(QMouseEvent *event) ...@@ -177,7 +177,7 @@ void QVnc::mouseMoveEvent(QMouseEvent *event)
event->accept(); event->accept();
else else
event->ignore(); event->ignore();
} //}
} }
void QVnc::hoverMoveEvent(QHoverEvent *event) void QVnc::hoverMoveEvent(QHoverEvent *event)
......
#ifndef VNC_H #ifndef VNC_H
#define VNC_H #define VNC_H
#define DECODER_COUNT 8 #define DECODER_COUNT 256
#include <QQuickWindow> #include <QQuickWindow>
#include <QObject> #include <QObject>
......
...@@ -40,7 +40,7 @@ struct Indices ...@@ -40,7 +40,7 @@ struct Indices
{ {
// 4 corner/rectangle and the first and last one duplicated except for the first and last rectangle // 4 corner/rectangle and the first and last one duplicated except for the first and last rectangle
unsigned short i[(VERTEX_BUFFER / 4) * 6 - 2]; unsigned short i[(VERTEX_BUFFER / 4) * 6 - 2];
constexpr Indices() : i() Indices() : i()
{ {
i[0] = 0; i[0] = 0;
auto index = 1; auto index = 1;
...@@ -51,7 +51,7 @@ struct Indices ...@@ -51,7 +51,7 @@ struct Indices
} }
} }
}; };
constexpr Indices ind; const struct Indices ind;
struct Vertex struct Vertex
{ {
...@@ -97,7 +97,7 @@ public: ...@@ -97,7 +97,7 @@ public:
void gotCopy(const GLushort src_x, const GLushort src_y, void gotCopy(const GLushort src_x, const GLushort src_y,
const GLushort width, const GLushort height, const GLushort width, const GLushort height,
const GLushort dest_x, const GLushort dest_y); const GLushort dest_x, const GLushort dest_y);
void gotBitmap(const QImage &image, void gotBitmap(const unsigned char *image,
const GLushort x, const GLushort y, const GLushort x, const GLushort y,
const GLushort width, const GLushort height); const GLushort width, const GLushort height);
void gotJpeg(); void gotJpeg();
......
...@@ -25,9 +25,9 @@ VncRenderer::VncRenderer(QQuickWindow *window, ...@@ -25,9 +25,9 @@ VncRenderer::VncRenderer(QQuickWindow *window,
void VncRenderer::render() void VncRenderer::render()
{ {
/*static QTime frameTime; static QTime frameTime;
qDebug() << qRound(1000.0 / frameTime.elapsed()) << *m_drawCount; qDebug() << qRound(1000.0 / frameTime.elapsed()) << *m_drawCount;
frameTime.restart();*/ frameTime.restart();
if(*m_drawCount > 0) { if(*m_drawCount > 0) {
m_program.bind(); m_program.bind();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment