int v4l2_overlay_set_position(int fd, int32_t x, int32_t y, int32_t w, int32_t h) { LOG_FUNCTION_NAME struct v4l2_format format; int ret; /* configure the src format pix */ /* configure the dst v4l2_overlay window */ format.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; ret = v4l2_overlay_ioctl(fd, VIDIOC_G_FMT, &format, "get v4l2_overlay format"); if (ret) return ret; LOGV("v4l2_overlay_set_position:: w=%d h=%d", format.fmt.win.w.width, format.fmt.win.w.height); if (mRotateOverlay) { w = 480; h = 800; x = 0; y = 0; } configure_window(&format.fmt.win, w, h, x, y); format.type = V4L2_BUF_TYPE_VIDEO_OVERLAY; ret = v4l2_overlay_ioctl(fd, VIDIOC_S_FMT, &format, "set v4l2_overlay format"); LOGV("v4l2_overlay_set_position:: w=%d h=%d", format.fmt.win.w.width, format.fmt.win.w.height); if (ret) return ret; v4l2_overlay_dump_state(fd); return 0; }
static void xprHideWindow(RootlessFrameID wid) { xp_window_changes wc; wc.stack_mode = XP_UNMAPPED; wc.sibling = 0; configure_window(MAKE_WINDOW_ID(wid), XP_STACKING, &wc); }
static void xprUpdateColormap(RootlessFrameID wid, ScreenPtr pScreen) { /* This is how we tell xp that the colormap may have changed. */ xp_window_changes wc; wc.colormap = xprColormapCallback; wc.colormap_data = pScreen; configure_window(MAKE_WINDOW_ID(wid), XP_COLORMAP, &wc); }
void renderOpenGLFromBlocks(struct OpenGL* ogl, int width, int height, int destWidth, int destHeight, int upx, int upy, int upwidth, int upheight) { if (!ogl->blocktextureids) return; printf("updating blocks\n"); configure_window(ogl, destWidth, destHeight); gdk_gl_drawable_gl_begin(ogl->drawable, ogl->context); int x, y; int bw = width / 32; int bh = 8; glEnable(GL_TEXTURE_2D); for (y = 0; y < height / bh; y++) { for (x = 0; x < width / bw; x++) { int block = y * 32 + x; if (block >= ogl->nblocks) printf("bad block %d %d -> %d\n", x, y, block); else glBindTexture(GL_TEXTURE_2D, ogl->blocktextureids[block]); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2f(x * bw, y * bh); glTexCoord2i(1, 0); glVertex2f(x * bw + bw, y * bh); glTexCoord2i(1, 1); glVertex2f(x * bw + bw, y * bh + bh); glTexCoord2i(0, 1); glVertex2f(x * bw, y * bh + bh); glEnd(); } } gdk_gl_drawable_swap_buffers(ogl->drawable); gdk_gl_drawable_gl_end(ogl->drawable); }
void renderOpenGLFromImageData(OpenGL* ogl, char* pixels, int width, int height, int rowstride, int destWidth, int destHeight, int upx, int upy, int upwidth, int upheight) { if (ogl == NULL) { printf("null OGL\n"); return; } //return; configure_window(ogl, destWidth, destHeight); gdk_gl_drawable_gl_begin(ogl->drawable, ogl->context); if (1) { glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, ogl->screentexid); if (1||!ogl->screentexloaded) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, rowstride / 3, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); ogl->screentexloaded = 1; } else { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, height-upy, rowstride / 3, upheight, GL_RGB, GL_UNSIGNED_BYTE, pixels); } /* glPushMatrix(); glScalef((double)destWidth / (rowstride/3), (double)destHeight / height, 1); glBegin(GL_QUADS); glTexCoord2i((double)upx / (rowstride/3), (double)upy / height); glVertex2f(upx, upy); glTexCoord2i((double)(upx + upwidth) / (rowstride/3), (double)upy / height); glVertex2f(upx + upwidth, upy); glTexCoord2i((double)(upx + upwidth) / (rowstride/3), (double)(upy + upheight) / height); glVertex2f(upx + upwidth, upy + upheight); glTexCoord2i((double)upx / (rowstride/3), (double)(upy + upheight) / height); glVertex2f(upx, upy + upheight); */ if (0 && ogl->displaylist) { glPushMatrix(); glScalef((double)destWidth/width, (double)destHeight/height, 1); glCallList(ogl->displaylist); glPopMatrix(); } else { //int list = glGenLists(1); // ogl->displaylist = list; //glNewList(ogl->displaylist, GL_COMPILE_AND_EXECUTE); glPushMatrix(); glScalef((double)destWidth, (double)destHeight, 1); glClearColor(0, 0, 0, 1); //glClear(GL_COLOR_BUFFER_BIT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2f(0, 0); glTexCoord2i(1, 0); glVertex2f(1, 0); glTexCoord2i(1, 1); glVertex2f(1, 1); glTexCoord2i(0, 1); glVertex2f(0, 1); glEnd(); glPopMatrix(); //glEndList(); } } else if (0) { glPixelZoom((double) destWidth / width, (double) -destHeight / height); glClearColor(0, 0, 0, 1); //glClear(GL_COLOR_BUFFER_BIT); //glRasterPos2i(0, 0); //glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); glPixelStorei(GL_UNPACK_ROW_LENGTH, width); glPixelStorei(GL_UNPACK_SKIP_ROWS, upy); glPixelStorei(GL_UNPACK_SKIP_PIXELS, upx); glRasterPos2i((double) upx * destWidth / height, (double) upy * destHeight / height); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); } else if (0) { int r, c; //glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_TEXTURE_2D); float scalex = (double) destWidth / width; float scaley = (double) destHeight / height; glPointSize((scalex + scaley) / 2); glBegin(GL_POINTS); glColor3b(0, 0, 0); int last = 0; for (r = 0; r < height; r++) { unsigned char* ptr = (unsigned char *) pixels + (r * rowstride); for (c = 0; c < width; c++) { int color = (ptr[0] << 16) | (ptr[1] << 8) | (ptr[2]); if (color != last) glColor3b(ptr[0], ptr[1], ptr[2]); glVertex3f(c * scalex, r * scaley, 0.0); ptr += 3; last = color; } } glEnd(); } else if (1) { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(2, GL_SHORT, 0, ogl->vertices); glColorPointer(3, GL_UNSIGNED_BYTE, 0, pixels); glPushMatrix(); glScalef((double)destWidth / width, (double)destHeight / height, 1); glDrawElements(GL_QUADS, 49152 * 4, GL_UNSIGNED_SHORT, ogl->indices); glPopMatrix(); } //if (gdk_gl_drawable_is_double_buffered (ogl->drawable)) gdk_gl_drawable_swap_buffers(ogl->drawable); gdk_gl_drawable_gl_end(ogl->drawable); }
void gui_main_loop (void) { XEvent event; struct gui_instance *gi; while (0 == XNextEvent (GUI_display, &event)) { if (0 == (gi = find_instance (event.xany.window))) continue; if (XFilterEvent (&event, gi->window)) continue; if (gi->definition.x11_event) gi->definition.x11_event (gi, &event); switch (event.type) { case KeyPress: gi->last_event = event.xkey.time; if (gi->definition.key_pressed) { wchar_t text[32]; Status status; KeySym key_sym; int len; len = XwcLookupString (gi->xic, &event.xkey, text, sizeof (text) / sizeof (text[0]) - 1, &key_sym, &status); text[len] = 0; if (status == XLookupNone) return; gi->definition.key_pressed (gi, (status == XLookupKeySym || status == XLookupBoth) ? key_sym : 0, (status == XLookupChars || status == XLookupBoth) ? text : NULL, event.xkey.state); } break; case KeyRelease: gi->last_event = event.xkey.time; if (gi->definition.key_released) { KeySym key_sym; key_sym = XLookupKeysym (&event.xkey, 0); gi->definition.key_released (gi, key_sym); } break; case MotionNotify: gi->last_event = event.xmotion.time; if (gi->definition.mouse_moved) gi->definition.mouse_moved (gi, event.xmotion.x, event.xmotion.y); break; case ButtonPress: gi->last_event = event.xbutton.time; if (gi->definition.button_pressed) gi->definition.button_pressed (gi, event.xbutton.button - 1, event.xbutton.state); break; case ButtonRelease: gi->last_event = event.xbutton.time; if (gi->definition.button_released) gi->definition.button_released (gi, event.xbutton.button - 1, event.xbutton.state); break; case ConfigureNotify: while (XCheckTypedWindowEvent (GUI_display, gi->window, ConfigureNotify, &event)) { /* Do nothing */ } if (gi->width == event.xconfigure.width && gi->height == event.xconfigure.height) break; gi->width = event.xconfigure.width; gi->height = event.xconfigure.height; configure_window (gi); XClearArea (GUI_display, gi->window, 0, 0, 0, 0, True); break; case NoExpose: break; case Expose: { int minx = event.xexpose.x; int miny = event.xexpose.y; int maxx = minx + event.xexpose.width; int maxy = miny + event.xexpose.height; while (XCheckTypedWindowEvent (GUI_display, gi->window, Expose, &event)) { if (event.xexpose.x < minx) minx = event.xexpose.x; if (event.xexpose.y < miny) miny = event.xexpose.y; if (event.xexpose.x + event.xexpose.width > maxx) maxx = event.xexpose.x + event.xexpose.width; if (event.xexpose.y + event.xexpose.height > maxx) maxx = event.xexpose.y + event.xexpose.height; } gi->repaint_waiting = 0; if (!gi->back_buffer) configure_window (gi); gi->definition.paint (gi, minx, miny, maxx - minx, maxy - miny); XRenderComposite (GUI_display, PictOpSrc, gi->back_buffer, None, gi->front_buffer, minx, miny, 0, 0, minx, miny, maxx - minx, maxy - miny); } break; case ClientMessage: if (event.xclient.data.l[0] == xa_wm_delete_window) gi->definition.destroy (gi); break; case SelectionRequest: { XSelectionRequestEvent* request; XSelectionEvent response; enum gui_clipboard clipboard; int ret; request = &event.xselectionrequest; if (request->selection == XA_PRIMARY) clipboard = GUI_PRIMARY_SELECTION; else if (request->selection == XA_SECONDARY) clipboard = GUI_SECONDARY_SELECTION; else if (request->selection == xa_clipboard) clipboard = GUI_CLIPBOARD; else break; if (!gi->clipboards[clipboard].length) break; if (request->target != XA_STRING && request->target != xa_utf8_string) break; if (request->property == None) request->property = request->target; response.type = SelectionNotify; response.send_event = True; response.display = GUI_display; response.requestor = request->requestor; response.selection = request->selection; response.target = request->target; response.property = None; response.time = request->time; ret = XChangeProperty (GUI_display, request->requestor, request->property, request->target, 8, PropModeReplace, gi->clipboards[clipboard].data, gi->clipboards[clipboard].length); if (ret != BadAlloc && ret != BadAtom && ret != BadValue && ret != BadWindow) response.property = request->property; XSendEvent (request->display, request->requestor, False, NoEventMask, (XEvent*) &response); } break; case SelectionNotify: { unsigned char* prop; unsigned long nitems, bytes_after; Atom type; int format, result; result = XGetWindowProperty (GUI_display, gi->window, xa_prop_paste, 0, 0, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop); if (result != Success) break; XFree (prop); result = XGetWindowProperty (GUI_display, gi->window, xa_prop_paste, 0, bytes_after, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &prop); if (result != Success) break; if (gi->definition.paste && type == xa_utf8_string && format == 8) { gi->definition.paste (gi, (const char*) prop, nitems); } XFree (prop); } break; } } }