943N/A/* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
830N/A *
830N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
830N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
830N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
830N/A */
830N/A
830N/A
830N/A/*
830N/A * dga_ab.c - the client side code for Ancillary Buffers (ABMG )
830N/A */
830N/A
830N/A#include <stdio.h>
830N/A#include <unistd.h>
830N/A#include <fcntl.h>
830N/A#include <sys/mman.h>
830N/A#include <sys/fcntl.h>
830N/A#include <X11/X.h>
830N/A#include "dga_incls.h"
830N/A
830N/Aextern int XDgaGrabABuffers(Display *dpy, Window win, int type, int buffer_site);
830N/Aextern int XDgaUnGrabABuffers(Display *dpy, Window win, int type);
830N/Aextern void *_dga_is_X_window(Dga_token token, Display **dpyp, Window *winp);
830N/A
830N/A#ifdef DEBUG
830N/A#define assert(expr) \
830N/Aif(!(expr)) \
830N/A{fprintf(stderr, "Assertion fails in file %s, line %d: expr\n",__FILE__,__LINE__); \
830N/Aabort();}
830N/A#else
830N/A#define assert(expr)
830N/A#endif /* DEBUG */
830N/A
830N/A#define UNMAP_BUFFER(addr, allocsize) \
830N/A if ( addr ) { \
830N/A munmap((char *)addr, allocsize); \
830N/A addr = NULL; \
830N/A }
830N/A
830N/A#define GET_SW_HW_BUFFER(dgawin_buf, fname, bufsize) \
830N/A bufferp = (dga_buffer)get_specified_buffer((char *)fname, bufsize); \
830N/A (dgawin_buf)->bufferp = bufferp; \
830N/A (dgawin_buf)->pDraw = dgadraw; \
830N/A (dgawin_buf)->buf_size = bufsize; \
830N/A ret_buf = dgawin_buf;
830N/A
830N/A#define STORE_BUFFERS(buf_addr, filename, fn_addr0, allocsize) \
830N/A bufferp = (buf_addr)->bufferp; \
830N/A if ( bufferp) { \
830N/A if (resize_flag) \
830N/A UNMAP_BUFFER(bufferp, (buf_addr)->buf_size) \
830N/A if ( filename && fn_addr0) { \
830N/A if ( bufferp ) { \
830N/A buffers[count++] = (Dga_buffer *)buf_addr; \
830N/A bufferp->pDraw = dgadraw; \
830N/A } \
830N/A else {\
830N/A (buf_addr)->bufferp = bufferp = (void *) \
830N/A get_specified_buffer((char *)filename, allocsize); \
830N/A (buf_addr)->pDraw = dgadraw; \
830N/A if (bufferp) { \
830N/A buffers[count++] = (Dga_buffer *)buf_addr; \
830N/A bufferp->pDraw = dgadraw; \
830N/A (buf_addr)->buf_size = allocsize; \
830N/A } \
830N/A else { \
830N/A (buf_addr)->buf_size = 0; \
830N/A } \
830N/A }\
830N/A }\
830N/A }
830N/A
830N/Astatic dga_buffer
830N/Aget_specified_buffer(char *filename, int allocsize)
830N/A{
830N/A int filefd = -1;
830N/A dga_buffer return_buf = NULL;
830N/A
830N/A if ( filename && filename[0] ) {
830N/A if ((filefd = open(filename,O_RDWR,0666)) != -1 ) {
830N/A return_buf = (dga_buffer)mmap(0, allocsize,
830N/A PROT_READ|PROT_WRITE, MAP_SHARED, filefd, (off_t)0);
830N/A close (filefd); /* May need to keep trap of fds... */
830N/A
830N/A if ( return_buf == (dga_buffer) -1)
830N/A return ( (dga_buffer)NULL ); /* mmap failed. */
830N/A
830N/A /* Set the data filed properly */
830N/A assert(sizeof(dga_buffer_rec) & 0x7 == 0);
830N/A return_buf->data = (char *)(return_buf + 1);
830N/A }
830N/A }
830N/A return return_buf;
830N/A
830N/A}
830N/A
830N/Astatic void
830N/Aremap_buffers(Dga_drawable dgadraw)
830N/A{
830N/A int filefd = -1;
830N/A char *filename;
830N/A int count = 0;
830N/A dga_buffer bufferp = NULL;
830N/A static void *buffers[DGA_NUM_BUFFER_TYPES];
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop = wx_infop(dgawin);
830N/A int resize_flag = True;
830N/A
830N/A if ( dgawin->buf_resize_flag >= infop->wx_abuf.s_modified )
830N/A return;
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->back, infop->wx_abuf.back_fn, infop->wx_abuf.back_fn[0], infop->wx_abuf.back_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->depth, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_fn[0], infop->wx_abuf.depth_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->stencil, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_fn[0], infop->wx_abuf.stencil_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->accum, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_fn[0], infop->wx_abuf.accum_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->alpha, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_fn[0], infop->wx_abuf.alpha_size);
830N/A
830N/A dgawin->buf_resize_flag = infop->wx_abuf.s_modified;
830N/A
830N/A return;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_draw_grab_buffer
830N/A * Synopsis: This function requests the window system to provide
830N/A * ancillary buffer service for the grabbed drawable name in the
830N/A * dgadraw argument. The call requests the type of the buffer
830N/A * specified to be grabbed to the client. If buffer_site is
830N/A * DGA_SITE_SYSTEM, server allocates the buffer in the shared
830N/A * memory. If it is DGA_SITE_DEVICE, the server tries to grab
830N/A * hardware buffers. If the device does not support the given
830N/A * buffer type in hardware, the request fails.
830N/A * The drawable must have been grabbed previously via XDgaGrabDrawable.
830N/A *
830N/A * Implementation: If buffer_stie is DGA_SITE_SYSTEM, this function
830N/A * increments the grab_cnt if the buffer is already grabbed by other clients.
830N/A * If this client has grabbed the specified buffer already, this function
830N/A * returns the grabbed buffer pointer.
830N/A * Otherwise, it sends a request to the server to grab a buffer.
830N/A * If the request is successful, this function returns the buffer
830N/A * address.
830N/A * A special case where if the grab_cnt is "0", this function still sends
830N/A * a request to the server to grab the buffer because there is a chance
830N/A * that the visual capabilities of the window might have been changed.
830N/A */
830N/A
830N/ADga_buffer
830N/Adga_draw_grab_buffer(Dga_drawable dgadraw, Dga_buffer_type type, int buffer_site)
830N/A{
830N/A _Dga_window dgawin = (struct dga_window *)dgadraw;
830N/A Dga_window clientpi = (Dga_window)dgawin;
830N/A _Dga_window clientp = (struct dga_window *)clientpi;
830N/A WXINFO *infop;
830N/A Display *dpy;
830N/A Window win;
830N/A int depth = 0;
830N/A dga_buffer bufferp = NULL;
830N/A dga_internal_buffer ret_buf = NULL;
830N/A dga_internal_buffer c_bufferp = NULL;
830N/A
830N/A /* Ancillary Buffers are not supported for drawable_type
830N/A * DGA_DRAW_PIXMAP
830N/A */
830N/A if ( ((_Dga_drawable)dgadraw)->drawable_type != DGA_DRAW_WINDOW )
830N/A return (0);
830N/A
830N/A if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj))
830N/A return (0);
830N/A
830N/A if ((clientp == (_Dga_window) NULL)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_draw_grab_buffer: passed null pointer\n");
830N/A#endif
830N/A return (0);
830N/A }
830N/A
830N/A /*
830N/A * Find out if this is an X window. If so get the Display and window
830N/A * id.
830N/A */
830N/A if (!_dga_is_X_window(clientp->w_token, &dpy, &win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_draw_grab_buffer: Unsupported window type\n");
830N/A#endif
830N/A return (0);
830N/A }
830N/A
830N/A infop = wx_infop(dgawin) ;
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified )
830N/A remap_buffers(dgadraw);
830N/A
830N/A switch ( type ) {
830N/A case DGA_BACK_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->back;
830N/A if ( c_bufferp->bufferp )
830N/A return dgawin->back;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
830N/A break;
830N/A case DGA_DEPTH_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->depth;
830N/A if ( c_bufferp->bufferp )
830N/A return dgawin->depth;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
830N/A break;
830N/A case DGA_STENCIL_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->stencil;
830N/A if ( c_bufferp->bufferp )
830N/A return dgawin->stencil;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
830N/A break;
830N/A case DGA_ACCUM_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->accum;
830N/A if ( c_bufferp->bufferp )
830N/A return dgawin->accum;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
830N/A break;
830N/A case DGA_ALPHA_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->alpha;
830N/A if ( c_bufferp->bufferp )
830N/A return dgawin->alpha;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
830N/A break;
830N/A default:
830N/A return (0);
830N/A }
830N/A
830N/A /* If grab_cnt is "0", then the reinitialization should go thru'
830N/A * server. We can not just increment the grab_cnt.
830N/A * There is a chance that the buffers capabilities might have
830N/A * been changed in which case the server gets the bitsPerPixel
830N/A * from SunExtVis info struct and reallocates the buffer.
830N/A * If buffer_site is not DGA_SITE_SYSTEM, then it might be
830N/A * a Hardware Buffers.
830N/A */
830N/A if ( bufferp && (bufferp->buffer_site == DGA_SITE_SYSTEM) &&
830N/A bufferp->grab_cnt > 0 ) {
830N/A bufferp->grab_cnt++;
830N/A return (Dga_buffer ) ret_buf;
830N/A }
830N/A
830N/A /*
830N/A * Request the server to allow DGA to the buffers associated
830N/A * with this Dga_window.
830N/A */
830N/A if (!XDgaGrabABuffers(dpy, win, type, buffer_site)) {
830N/A#ifdef DEBUG
830N/A (void)fprintf(stderr, "dga_draw_grab_buffer: XDgaGrabABuffers failed\n");
830N/A#endif
830N/A return (0);
830N/A }
830N/A
830N/A /* infop will contain the proper pointer to the selected buffer since
830N/A * it is in the dga shared page.
830N/A */
830N/A infop = wx_infop(dgawin) ;
830N/A
830N/A /* get_specified_buffer: This function checks on the filenames
830N/A * where if it is software buffer this member should have a
830N/A * valid file name.
830N/A * If it is NULL, then it may be a hardware buffer and just
830N/A * return from this point where the hardware buffer would have
830N/A * been allocated already.
830N/A */
830N/A switch ( type ) {
830N/A case DGA_BACK_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->back;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
830N/A break;
830N/A
830N/A case DGA_DEPTH_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->depth;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
830N/A break;
830N/A
830N/A case DGA_STENCIL_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->stencil;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
830N/A break;
830N/A
830N/A case DGA_ACCUM_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->accum;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
830N/A break;
830N/A
830N/A case DGA_ALPHA_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->alpha;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
830N/A break;
830N/A
830N/A }
830N/A
830N/A if ( bufferp ) {
830N/A bufferp->pDraw = ret_buf->pDraw = dgadraw;
830N/A return (Dga_buffer) ret_buf;
830N/A } else {
830N/A if (buffer_site == DGA_SITE_DEVICE)
830N/A return (Dga_buffer) c_bufferp;
830N/A }
830N/A
830N/A return NULL;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_draw_ungrab_buffer
830N/A * Synopsis: This function ungrabs the buffer for the specified drawable
830N/A * which has been grabbed previously. Note that ungrabbing a buffer does
830N/A * not necessarily cause it to be freed. If any of these steps fail,
830N/A * zero is returned. True is returned upon success.
830N/A *
830N/A * Implementation: If the buffer is grabbed already, this function
830N/A * decrements the grab_cnt. If grab_cnt is negative, it will be
830N/A * reset to "0".
830N/A * If this client hasn't grabbed the buffer already, this function returns 0.
830N/A * This function will send a request to the server to ungrab the
830N/A * buffer only if buffer grabbed is in DGA_SITE_DEVICE ( Hardware ).
830N/A */
830N/Aint
830N/Adga_draw_ungrab_buffer(Dga_drawable dgadraw, Dga_buffer_type type)
830N/A{
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop;
830N/A Display *dpy;
830N/A Window win;
830N/A dga_buffer bufferp = NULL;
830N/A dga_internal_buffer ret_buf = NULL;
830N/A dga_internal_buffer c_bufferp = NULL;
830N/A
830N/A /* Ancillary Buffers are not supported for drawable_type
830N/A * DGA_DRAW_PIXMAP
830N/A */
830N/A if ( ((_Dga_drawable)dgadraw)->drawable_type != DGA_DRAW_WINDOW )
830N/A return (0);
830N/A
830N/A if (!DGA_LOCKSUBJ_WINDOW(dgawin, dgawin->eLockSubj))
830N/A return (0);
830N/A
830N/A if ((dgawin == (_Dga_window) NULL)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_draw_ungrab_buffer: passed null pointer\n");
830N/A#endif
830N/A return (0);
830N/A }
830N/A
830N/A /*
830N/A * Find out if this is an X window. If so get the Display and window
830N/A * id.
830N/A */
830N/A if (!_dga_is_X_window(dgawin->w_token, &dpy, &win)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_draw_ungrab_buffer: Unsupported window type\n");
830N/A#endif
830N/A return (0);
830N/A }
830N/A
830N/A infop = wx_infop(dgawin) ;
830N/A
830N/A switch ( type ) {
830N/A case DGA_BACK_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->back;
830N/A if ( c_bufferp->bufferp )
830N/A return 0;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.back_fn, infop->wx_abuf.back_size);
830N/A break;
830N/A case DGA_DEPTH_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->depth;
830N/A if ( c_bufferp->bufferp )
830N/A return 0;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_size);
830N/A break;
830N/A case DGA_STENCIL_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->stencil;
830N/A if ( c_bufferp->bufferp )
830N/A return 0;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_size);
830N/A break;
830N/A case DGA_ACCUM_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->accum;
830N/A if ( c_bufferp->bufferp )
830N/A return 0;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_size);
830N/A break;
830N/A case DGA_ALPHA_BUFFER:
830N/A c_bufferp = (dga_internal_buffer)dgawin->alpha;
830N/A if ( c_bufferp->bufferp )
830N/A return 0;
830N/A GET_SW_HW_BUFFER(c_bufferp, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_size);
830N/A break;
830N/A default:
830N/A return (0);
830N/A } /* end of switch ( type ).. */
830N/A
830N/A/* Currently Just decrement the grab_cnt and if there is no grab
830N/A * don't free it. Next time when it is getting grabbed, we will
830N/A * increment the count
830N/A * If the when the grab_cnt is "0" and the dga_drawable is getting
830N/A * resized then the buffers are thrown away.
830N/A */
830N/A
830N/A if ( !bufferp )
830N/A return (0);
830N/A
830N/A if ( bufferp->buffer_site == DGA_SITE_SYSTEM ) {
830N/A bufferp->grab_cnt--;
830N/A
830N/A if ( bufferp->grab_cnt < 0 )
830N/A bufferp->grab_cnt = 0;
830N/A
830N/A switch ( type ) {
830N/A case DGA_BACK_BUFFER:
830N/A ((dga_internal_buffer)dgawin->back)->bufferp = NULL;
830N/A break;
830N/A case DGA_DEPTH_BUFFER:
830N/A ((dga_internal_buffer)dgawin->depth)->bufferp = NULL;
830N/A break;
830N/A case DGA_STENCIL_BUFFER:
830N/A ((dga_internal_buffer)dgawin->stencil)->bufferp = NULL;
830N/A break;
830N/A case DGA_ACCUM_BUFFER:
830N/A ((dga_internal_buffer)dgawin->accum)->bufferp = NULL;
830N/A break;
830N/A case DGA_ALPHA_BUFFER:
830N/A ((dga_internal_buffer)dgawin->alpha)->bufferp = NULL;
830N/A break;
830N/A default:
830N/A return (0);
830N/A } /* end of switch */
830N/A }
830N/A else {
830N/A /* Buffer site is DGA_SITE_DEVICE */
830N/A if (!XDgaUnGrabABuffers(dpy, win, type)) {
830N/A#ifdef DEBUG
830N/A (void) fprintf(stderr, "dga_draw_ungrab_buffer: XDgaUnGrabABuffers failed\n");
830N/A#endif
830N/A return (0);
830N/A
830N/A }
830N/A } /* end of ( ret_buf->buffer_site == DGA_SITE_SYSTEM ).. */
830N/A
830N/A return 1;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_draw_get_buffers
830N/A * Synopsis: This function returns the number of ancillary buffers
830N/A * associated with the specified dgadraw and an arry of buffer
830N/A * pointers. Note that only buffers which have been grabbed by
830N/A * the client are returned. Buffers which might exist (because of
830N/A * grabs by other clients or the server) are not returned.
830N/A */
830N/Aint
830N/Adga_draw_get_buffers(Dga_drawable dgadraw, Dga_buffer **pBufs )
830N/A{
830N/A char *filename;
830N/A int count = 0;
830N/A dga_buffer bufferp = NULL;
830N/A static void *buffers[DGA_NUM_BUFFER_TYPES];
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop = wx_infop(dgawin);
830N/A int resize_flag = False;
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified )
830N/A resize_flag = True;
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->back, infop->wx_abuf.back_fn, infop->wx_abuf.back_fn[0], infop->wx_abuf.back_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->depth, infop->wx_abuf.depth_fn, infop->wx_abuf.depth_fn[0], infop->wx_abuf.depth_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->stencil, infop->wx_abuf.stencil_fn, infop->wx_abuf.stencil_fn[0], infop->wx_abuf.stencil_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->accum, infop->wx_abuf.accum_fn, infop->wx_abuf.accum_fn[0], infop->wx_abuf.accum_size);
830N/A
830N/A STORE_BUFFERS((dga_internal_buffer)dgawin->alpha, infop->wx_abuf.alpha_fn, infop->wx_abuf.alpha_fn[0], infop->wx_abuf.alpha_size);
830N/A
830N/A if ( resize_flag )
830N/A dgawin->buf_resize_flag = infop->wx_abuf.s_modified;
830N/A
830N/A *pBufs = buffers;
830N/A
830N/A return count;
830N/A}
830N/A
830N/A
830N/A/*
830N/A * Name : dga_buffer_type
830N/A * Synopsis: This function returns the type of the buffer specified.
830N/A */
830N/ADga_buffer_type
830N/Adga_buffer_type(Dga_buffer bufferp)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return -1;
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A return local_buf->buffer_type;
830N/A}
830N/A
830N/A
830N/A#if 0
830N/A/* We had this function for completeness. */
830N/A/*
830N/A * Name : dga_buffer_get_drawable
830N/A * Synopsis: This function returns the Dga_drawable associated with the
830N/A * buffer specified.
830N/A */
830N/ADga_drawable
830N/Adga_buffer_get_drawable(Dga_buffer bufferp )
830N/A{
830N/A if ( !bufferp )
830N/A return NULL;
830N/A
830N/A return ((dga_buffer)bufferp)->pDraw;
830N/A}
830N/A#endif
830N/A
830N/A
830N/A/*
830N/A * Name : dga_buffer_site (Lock Only)
830N/A * Synopsis: This function returns the site of the buffer specified.
830N/A * The values are the same as those returned by dga_draw_site().
830N/A * DGA_SITE_SYSTEM, DGA_SITE_DEVICE and DGA_SITE_NULL.
830N/A */
830N/Aint
830N/Adga_buffer_site(Dga_buffer bufferp)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return DGA_SITE_NULL;
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A return local_buf->buffer_site;
830N/A}
830N/A
830N/A
830N/A/*
830N/A * Name : dga_draw_bufferchg
830N/A * Synopsis: This function returns True if any of the buffers
830N/A * associated with the dgadraw have undergone a state change
830N/A * since the last lock. When dga_draw_bufferchg returns True,
830N/A * the client should call dga_buffer_sitechg for each of the
830N/A * Drawable's buffers.
830N/A */
830N/Aint
830N/Adga_draw_bufferchg(Dga_drawable dgadraw)
830N/A{
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop = wx_infop(dgawin);
830N/A
830N/A if (infop && (infop->wx_abuf.s_modified))
830N/A return True;
830N/A
830N/A return False;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_buffer_sitechg
830N/A * Synopsis: This function returns True if the buffer has sitechg
830N/A * flag set. Note that this function always returns False for
830N/A * device buffers. Only memory buffers ever have a site chagne.
830N/A * dga_buffer_sitechg() also returns the reason for site change.
830N/A * Currenly the only possible values for reason are DGA_SITECHG_INITIAL,
830N/A * which is reported the first time a Drawable is locaked after a buffer
830N/A * has been created and DGA_SITECHG_CACHE which indicates that the
830N/A * buffer has been resized since the time that the Dga_drawable was last
830N/A * locked.
830N/A */
830N/Aint
830N/Adga_buffer_sitechg(Dga_buffer bufferp, int *reason)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return False; /* Returning False may mislead the developer */
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A if (local_buf->buffer_site != DGA_SITE_SYSTEM)
830N/A return False;
830N/A
830N/A if (local_buf->sitechg) {
830N/A *reason = local_buf->sitechg;
830N/A local_buf->sitechg = DGA_SITECHG_UNKNOWN;
830N/A return True;
830N/A } else
830N/A return False;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_buffer_address (Lock Only)
830N/A * Synopsis: This function returns the data pointer from the shared
830N/A * buffer page of the buffer specified. An address will be returned
830N/A * only for buffers which are located in system memory.
830N/A * If dga_buffer_address is called on a buffer located with
830N/A * DGA_SITE_DEVICE, NULL will be returned. The value returned
830N/A * remains valid across locks until a sitechg is reported as
830N/A * described above.
830N/A */
830N/Avoid *
830N/Adga_buffer_address(Dga_buffer bufferp)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return NULL;
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A if (local_buf->buffer_site == DGA_SITE_SYSTEM) {
830N/A local_buf->data = (char *)(local_buf + 1);
830N/A return local_buf->data;
830N/A }
830N/A else
830N/A return NULL;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_buffer_linebytes
830N/A * Synopsis: This function returns the number of bytes per scanline
830N/A * of the buffer specified. Only buffers which are located in
830N/A * system memory are addressable. If dga_buffer_linebytes is called
830N/A * for a buffer located on the device, "0" is returned.
830N/A */
830N/Aint
830N/Adga_buffer_linebytes(Dga_buffer bufferp)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return 0;
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A if (local_buf->buffer_site == DGA_SITE_SYSTEM)
830N/A return local_buf->linebytes;
830N/A else
830N/A return 0;
830N/A}
830N/A
830N/A/*
830N/A * Name : dga_buffer_bitsperpixel
830N/A * Synopsis: This function returns bitsperpixel of the buffer
830N/A * specified if the buffer is located in system memory. If the
830N/A * buffer is located on the device, zero is returned. Note that
830N/A * the value might be different than the number of significant bits.
830N/A * For example, an unpacked 4 bit stencil buffer would return
830N/A * 8 bits per pixel, and a 24 bit Z buffer would return
830N/A * 32 bits per pixel.
830N/A */
830N/Aint
830N/Adga_buffer_bitsperpixel(Dga_buffer bufferp)
830N/A{
830N/A _Dga_window dgawin;
830N/A WXINFO *infop;
830N/A dga_buffer local_buf;
830N/A
830N/A if ( !bufferp || !(local_buf = ((dga_internal_buffer)bufferp)->bufferp))
830N/A return 0;
830N/A
830N/A dgawin = (_Dga_window)((dga_internal_buffer)bufferp)->pDraw;
830N/A infop = wx_infop(dgawin);
830N/A
830N/A if ( dgawin->buf_resize_flag < infop->wx_abuf.s_modified ) {
830N/A remap_buffers((Dga_drawable)((dga_internal_buffer)bufferp)->pDraw);
830N/A local_buf = ((dga_internal_buffer)bufferp)->bufferp;
830N/A }
830N/A
830N/A if (local_buf->buffer_site == DGA_SITE_SYSTEM)
830N/A return local_buf->bitsPerPixel;
830N/A else
830N/A return 0;
830N/A}
830N/A
830N/Avoid
830N/Adga_draw_buffer_swap(Dga_drawable dgadraw, int (*visfunc)(Dga_window))
830N/A{
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop = wx_infop(dgawin);
830N/A
830N/A if (visfunc)
830N/A (*visfunc)(dgawin);
830N/A
830N/A if ( infop && infop->wx_abuf.back_fn && infop->wx_abuf.back_fn[0]
830N/A && infop->wx_abuf.back ) {
830N/A infop->wx_abuf.buffer_swap++;
830N/A dgawin->c_buffer_swap = infop->wx_abuf.buffer_swap;
830N/A }
830N/A
830N/A return;
830N/A}
830N/A
830N/Aint
830N/Adga_draw_swap_check(Dga_drawable dgadraw)
830N/A{
830N/A _Dga_window dgawin = (_Dga_window)dgadraw;
830N/A WXINFO *infop = wx_infop(dgawin);
830N/A
830N/A if ( infop && infop->wx_abuf.back_fn && infop->wx_abuf.back_fn[0]
830N/A && infop->wx_abuf.back
830N/A && ( dgawin->c_buffer_swap != infop->wx_abuf.buffer_swap)) {
830N/A dgawin->c_buffer_swap = infop->wx_abuf.buffer_swap;
830N/A return 1;
830N/A }
830N/A
830N/A return 0;
830N/A}