summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2020-07-09 23:16:16 -0700
committerVito Caputo <vcaputo@pengaru.com>2020-07-11 13:36:42 -0700
commit6ff81d0947a68fa5432c88a08bb9842c71c81489 (patch)
tree825f461faae05fbfa63b684d2a150e7325a26e84
parent4aebce99a7811e4defc89c65efd69e9ba71f1f0c (diff)
*: introduce Image type
Baby step towards encapsulating the shmem and ximage state
-rw-r--r--recordmydesktop/src/rmd_get_frame.c106
-rw-r--r--recordmydesktop/src/rmd_types.h6
-rw-r--r--recordmydesktop/src/rmd_update_image.c14
-rw-r--r--recordmydesktop/src/rmd_update_image.h3
4 files changed, 67 insertions, 62 deletions
diff --git a/recordmydesktop/src/rmd_get_frame.c b/recordmydesktop/src/rmd_get_frame.c
index cec2c80..d186f95 100644
--- a/recordmydesktop/src/rmd_get_frame.c
+++ b/recordmydesktop/src/rmd_get_frame.c
@@ -120,51 +120,56 @@ static void mark_buffer_area( unsigned char *data,
//besides taking the first screenshot, this functions primary purpose is to
//initialize the structures and memory.
-static int rmdFirstFrame(ProgData *pdata, XImage **image, XShmSegmentInfo *shminfo) {
+static int rmdFirstFrame(ProgData *pdata, Image *image) {
const XRectangle *rrect = &pdata->brwin.rrect;
- if ((pdata->args.noshared)) {
- (*image) = XGetImage( pdata->dpy,
- pdata->specs.root,
- rrect->x,
- rrect->y,
- rrect->width,
- rrect->height,
- AllPlanes,
- ZPixmap);
+ if (pdata->args.noshared) {
+ image->ximage = XGetImage( pdata->dpy,
+ pdata->specs.root,
+ rrect->x,
+ rrect->y,
+ rrect->width,
+ rrect->height,
+ AllPlanes,
+ ZPixmap);
} else {
- (*image) = XShmCreateImage( pdata->dpy,
+ image->ximage = XShmCreateImage(pdata->dpy,
pdata->specs.visual,
pdata->specs.depth,
ZPixmap,
NULL,
- shminfo,
+ &image->shm_info,
rrect->width,
rrect->height);
- (*shminfo).shmid = shmget(IPC_PRIVATE,
- (*image)->bytes_per_line *
- (*image)->height,
- IPC_CREAT|0777);
+ image->shm_info.shmid = shmget( IPC_PRIVATE,
+ image->ximage->bytes_per_line *
+ image->ximage->height,
+ IPC_CREAT|0777);
- if ((*shminfo).shmid == -1) {
+ if (image->shm_info.shmid == -1) {
fprintf(stderr, "Failed to obtain Shared Memory segment!\n");
return 12;
}
- (*shminfo).shmaddr = (*image)->data = shmat((*shminfo).shmid, NULL,0);
- (*shminfo).readOnly = False;
+ image->shm_info.shmaddr = image->ximage->data = shmat(image->shm_info.shmid, NULL, 0);
+ image->shm_info.readOnly = False;
- if (!XShmAttach(pdata->dpy, shminfo)) {
+ if (!XShmAttach(pdata->dpy, &image->shm_info)) {
fprintf(stderr, "Failed to attach shared memory to proccess.\n");
return 12;
}
- XShmGetImage(pdata->dpy, pdata->specs.root, (*image), rrect->x, rrect->y, AllPlanes);
+ XShmGetImage( pdata->dpy,
+ pdata->specs.root,
+ image->ximage,
+ rrect->x,
+ rrect->y,
+ AllPlanes);
}
rmdUpdateYuvBuffer( &pdata->enc_data->yuv,
- ((unsigned char*)((*image))->data),
+ (unsigned char *)image->ximage->data,
NULL,
pdata->enc_data->x_offset,
pdata->enc_data->y_offset,
@@ -252,14 +257,13 @@ void *rmdGetFrame(ProgData *pdata) {
BRWindow temp_brwin;
Window root_ret, child_ret; //Frame
XFixesCursorImage *xcim = NULL;
- XImage *image = NULL, *image_back = NULL; //the image that holds
+ Image image = {}, image_back = {}; //the image that holds
//the current full screenshot
- XShmSegmentInfo shminfo, shminfo_back; //info structure for the image above.
int init_img1 = 0, init_img2 = 0, img_sel, d_buff;
img_sel = d_buff = pdata->args.full_shots;
- if ((init_img1 = rmdFirstFrame(pdata, &image, &shminfo) != 0)) {
+ if ((init_img1 = rmdFirstFrame(pdata, &image) != 0)) {
if (pdata->args.encOnTheFly) {
if (remove(pdata->args.filename)) {
perror("Error while removing file:\n");
@@ -275,7 +279,7 @@ void *rmdGetFrame(ProgData *pdata) {
}
if (d_buff) {
- if ((init_img2 = rmdFirstFrame(pdata, &image_back, &shminfo_back) != 0)) {
+ if ((init_img2 = rmdFirstFrame(pdata, &image_back) != 0)) {
if (pdata->args.encOnTheFly) {
if (remove(pdata->args.filename)) {
perror("Error while removing file:\n");
@@ -394,8 +398,8 @@ void *rmdGetFrame(ProgData *pdata) {
rmdRectInsert(&pdata->rect_root, &mouse_pos_temp);
} else if (d_buff) {
unsigned char *back_buff= img_sel ?
- ((unsigned char*)image->data) :
- ((unsigned char*)image_back->data);
+ ((unsigned char*)image.ximage->data) :
+ ((unsigned char*)image_back.ximage->data);
mark_buffer_area(
back_buff,
@@ -430,9 +434,8 @@ void *rmdGetFrame(ProgData *pdata) {
&pdata->rect_root,
&temp_brwin,
pdata->enc_data,
- image->data,
+ &image,
pdata->args.noshared,
- &shminfo,
pdata->shm_opcode,
pdata->args.no_quick_subsample);
@@ -444,27 +447,28 @@ void *rmdGetFrame(ProgData *pdata) {
pthread_mutex_unlock(&pdata->yuv_mutex);
} else {
- unsigned char *front_buff = !img_sel ? ((unsigned char*)image->data):
- ((unsigned char*)image_back->data);
+ unsigned char *front_buff = !img_sel ? ((unsigned char*)image.ximage->data):
+ ((unsigned char*)image_back.ximage->data);
unsigned char *back_buff = !d_buff ? NULL : (img_sel ?
- ((unsigned char*)image->data):
- ((unsigned char*)image_back->data));
-
- if (!pdata->args.noshared)
- XShmGetImage( pdata->dpy,
- pdata->specs.root,
- ((!img_sel) ? image : image_back),
- temp_brwin.rrect.x,
- temp_brwin.rrect.y, AllPlanes);
+ ((unsigned char*)image.ximage->data):
+ ((unsigned char*)image_back.ximage->data));
- if (pdata->args.noshared)
+ if (pdata->args.noshared) {
rmdGetZPixmap( pdata->dpy,
pdata->specs.root,
- image->data,
+ image.ximage->data,
temp_brwin.rrect.x,
temp_brwin.rrect.y,
temp_brwin.rrect.width,
temp_brwin.rrect.height);
+ } else {
+ XShmGetImage( pdata->dpy,
+ pdata->specs.root,
+ ((!img_sel) ? image.ximage : image_back.ximage),
+ temp_brwin.rrect.x,
+ temp_brwin.rrect.y,
+ AllPlanes);
+ }
pthread_mutex_lock(&pdata->yuv_mutex);
for(int i = 0; i < blocknum_x * blocknum_y; i++)
@@ -535,8 +539,8 @@ void *rmdGetFrame(ProgData *pdata) {
//will be the back buffer next time it's
//used)
unsigned char *front_buff = !img_sel ?
- ((unsigned char*)image->data) :
- ((unsigned char*)image_back->data);
+ ((unsigned char*)image.ximage->data) :
+ ((unsigned char*)image_back.ximage->data);
mark_buffer_area(
front_buff,
@@ -576,13 +580,13 @@ void *rmdGetFrame(ProgData *pdata) {
pthread_mutex_unlock(&pdata->img_buff_ready_mutex);
if (!pdata->args.noshared) {
- XShmDetach (pdata->dpy, &shminfo);
- shmdt (shminfo.shmaddr);
- shmctl (shminfo.shmid, IPC_RMID, 0);
+ XShmDetach(pdata->dpy, &image.shm_info);
+ shmdt(image.shm_info.shmaddr);
+ shmctl(image.shm_info.shmid, IPC_RMID, 0);
if (d_buff) {
- XShmDetach (pdata->dpy, &shminfo_back);
- shmdt (shminfo_back.shmaddr);
- shmctl (shminfo_back.shmid, IPC_RMID, 0);
+ XShmDetach(pdata->dpy, &image_back.shm_info);
+ shmdt(image_back.shm_info.shmaddr);
+ shmctl(image_back.shm_info.shmid, IPC_RMID, 0);
}
}
diff --git a/recordmydesktop/src/rmd_types.h b/recordmydesktop/src/rmd_types.h
index cbabb47..051e034 100644
--- a/recordmydesktop/src/rmd_types.h
+++ b/recordmydesktop/src/rmd_types.h
@@ -31,6 +31,7 @@
#include <pthread.h>
#include <zlib.h>
#include <X11/Xlib.h>
+#include <X11/extensions/XShm.h>
#include <theora/theora.h>
#include <vorbis/codec.h>
#include <vorbis/vorbisenc.h>
@@ -88,6 +89,11 @@ typedef int boolean;
// Forward declarations
typedef struct _ProgData ProgData;
+typedef struct _Image {
+ XImage *ximage;
+ XShmSegmentInfo shm_info;
+}Image;
+
typedef struct _DisplaySpecs{ //this struct holds some basic information
int screen; //about the display,needed mostly for
unsigned int width, height; //validity checks at startup
diff --git a/recordmydesktop/src/rmd_update_image.c b/recordmydesktop/src/rmd_update_image.c
index 615bcd3..52ed478 100644
--- a/recordmydesktop/src/rmd_update_image.c
+++ b/recordmydesktop/src/rmd_update_image.c
@@ -42,20 +42,18 @@ void rmdUpdateImage( Display * dpy,
RectArea **root,
BRWindow *brwin,
EncData *enc,
- char *datatemp,
+ Image *image,
int noshmem,
- XShmSegmentInfo *shminfo,
int shm_opcode,
int no_quick_subsample){
- unsigned char *dtap=(unsigned char*)datatemp;
RectArea *temp;
for (temp = *root; temp; temp = temp->next) {
if (noshmem) {
rmdGetZPixmap( dpy,
specs->root,
- datatemp,
+ image->ximage->data,
temp->rect.x,
temp->rect.y,
temp->rect.width,
@@ -63,19 +61,17 @@ void rmdUpdateImage( Display * dpy,
} else {
rmdGetZPixmapSHM( dpy,
specs->root,
- shminfo,
+ &image->shm_info,
shm_opcode,
- datatemp,
+ image->ximage->data,
temp->rect.x,
temp->rect.y,
temp->rect.width,
temp->rect.height);
}
-
-
rmdUpdateYuvBuffer(
yuv,
- dtap,
+ (unsigned char *)image->ximage->data,
NULL,
temp->rect.x - brwin->rrect.x + enc->x_offset,
temp->rect.y - brwin->rrect.y + enc->y_offset,
diff --git a/recordmydesktop/src/rmd_update_image.h b/recordmydesktop/src/rmd_update_image.h
index e157f35..3057f18 100644
--- a/recordmydesktop/src/rmd_update_image.h
+++ b/recordmydesktop/src/rmd_update_image.h
@@ -61,9 +61,8 @@ void rmdUpdateImage(Display * dpy,
RectArea **root,
BRWindow *brwin,
EncData *enc,
- char *datatemp,
+ Image *image,
int noshmem,
- XShmSegmentInfo *shminfo,
int shm_opcode,
int no_quick_subsample);
© All Rights Reserved