Commit 7bd314b8 authored by abmyii's avatar abmyii
Browse files

glReadPixels into QImage and then pass data to FB

parent be4a6685
......@@ -3,10 +3,13 @@ BINS=dummyvncserver mirvncserver mirscreencast
all: $(BINS)
MIRLIBS=-lboost_program_options -lpthread -lmirclient -lEGL -lxcb-glx -lGLESv2 -lmirserver -lmircore -levdev
QTLIBS=-lstdc++ -lQt5Gui -lQt5Core
VNCLIBS=-lvncserver
MIRCFLAGS=-std=c++11 -Wall -fpermissive -I/usr/include/mirclient -I/usr/include/mircommon -I/usr/include/mircore -I/usr/include/libevdev-1.0
MIRLIBS=-lboost_program_options -lpthread -lmirclient -lEGL -lxcb-glx -lGLESv2 -lmirserver -lmircore -levdev
QTCFLAGS=-I/usr/include/$(MULTIARCH)/qt5 -fPIC
dummyvncserver: dummyvncserver.c
$(CC) dummyvncserver.c -o dummyvncserver $(VNCLIBS)
......@@ -18,10 +21,10 @@ mirscreencast: screencast.o
$(CXX) screencast.o -o mirscreencast $(MIRLIBS)
mirvncserver.o: mirvncserver.cpp
$(CXX) mirvncserver.cpp -c $(MIRCFLAGS)
$(CXX) mirvncserver.cpp -c $(MIRCFLAGS) $(QTCFLAGS)
mirvncserver: mirvncserver.o
$(CXX) mirvncserver.o -o mirvncserver $(MIRLIBS) $(VNCLIBS)
$(CXX) mirvncserver.o -o mirvncserver $(MIRLIBS) $(VNCLIBS) $(QTLIBS)
clean:
rm $(BINS) *.o
Mouse scroll wheel / touchpad scrolling
Tilde (~) appearing as grave (¬) - keysym -> scancode conversion needs to be fully refactored
Replace hardcoded 1920x1080 for mouse boundaries
Allow mapping the keycombo for rotation
......@@ -16,6 +16,8 @@
* Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
*/
#include <QtGui/QImage>
#include "mir_toolkit/mir_client_library.h"
#include "mir_toolkit/mir_screencast.h"
#include "mir/geometry/size.h"
......@@ -89,63 +91,17 @@ void shutdown(int)
running = 0;
}
void read_pixels(int bpp, GLenum format, mir::geometry::Size const& size, std::vector<char> &fb)
void read_pixels(int bpp, GLenum format, mir::geometry::Size const& size, void* fb)
{
auto width = size.width.as_uint32_t();
auto height = size.height.as_uint32_t();
// https://stackoverflow.com/a/60696921
std::vector<char> pixels(bpp * width * height);
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, pixels.data());
// Mirror image
if (mirror) {
std::vector<char> mirrored(bpp * width * height);
int i = 0;
for (int y = height; y > 0; y--) {
for (int x = width*bpp; x > 0; x -= bpp) {
int offset = (width * bpp * y) + x;
for (int p = 0; p < bpp; p++)
mirrored[i+p] = pixels[offset-bpp+p];
i += bpp;
}
}
pixels = mirrored;
}
// Read pixels into image (https://community.khronos.org/t/render-to-texture-under-qt/68430/3)
QImage image(width, height, QImage::Format_RGBA8888);
glReadPixels(0, 0, width, height, format, GL_UNSIGNED_BYTE, image.bits());
// Rotate to landscape
if (landscape) {
/** Starts from the last column and moves back reading each vertically and writing it horizontally.
* Given the following matrix of pixels (R G B):
* (1 1 1) (4 4 4) (6 6 6)
* (3 3 3) (2 2 2) (5 5 5)
* (7 7 7) (9 9 9) (8 8 8)
*
* It will be rotated 90 degrees in either direction, with the pixel values remaining grouped, e.g.:
*
* (90 degrees anti-clockwise)
* (6 6 6) (5 5 5) (8 8 8)
* (4 4 4) (2 2 2) (9 9 9)
* (1 1 1) (3 3 3) (7 7 7)
*
**/
int i = 0;
for (int x = 0; x < width*bpp; x += bpp) {
for (int y = height; y > 0; y--) {
int offset = (width * bpp * y) + x;
// Set each of <bpp> pixels (i.e. <offset-3>, <offset-2>, <offset-1> <offset>)
for (int p = 0; p < bpp; p++)
fb[i+p] = pixels[offset-bpp+p];
i += bpp;
}
}
}
else
fb = pixels;
// https://forum.qt.io/topic/92641/converting-a-qimage-to-a-qbytearray-and-convert-it-back-into-an-image/8
memcpy(fb, image.bits(), image.byteCount());
#ifdef DEBUG
unsigned int sum = 0;
unsigned int *pui = (unsigned int *) buffer;
......@@ -647,7 +603,11 @@ void do_screencast(EGLSetup const& egl_setup,
{
auto time_point = std::chrono::steady_clock::now() + capture_period;
read_pixels(bpp, format, size, frame_data);
auto start = std::chrono::high_resolution_clock::now();
read_pixels(bpp, format, size, frame_data.data());
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
std::cout << "Elapsed time: " << elapsed.count() << " s, " << 1/elapsed.count() << " fps\n";
if (maxx/maxy != rfbScreen->width/rfbScreen->height) {
printf("Ratios don't match\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment