LONG APIENTRY
DrvDescribePixelFormat(
   HDC hdc,
   INT iPixelFormat,
   ULONG cjpfd,
   PIXELFORMATDESCRIPTOR *ppfd )
{
   uint count;
   uint index;
   const struct stw_pixelformat_info *pfi;

   (void) hdc;

   if (!stw_dev)
      return 0;

   count = stw_pixelformat_get_extended_count();
   index = (uint) iPixelFormat - 1;

   if (ppfd == NULL)
      return count;
   if (index >= count || cjpfd != sizeof( PIXELFORMATDESCRIPTOR ))
      return 0;

   pfi = stw_pixelformat_get_info( index );
   
   memcpy(ppfd, &pfi->pfd, sizeof( PIXELFORMATDESCRIPTOR ));

   return count;
}
Example #2
0
/* Only used by the wgl code, but have it here to avoid exporting the
 * pixelformat.h functionality.
 */
int stw_pixelformat_choose( HDC hdc,
                            CONST PIXELFORMATDESCRIPTOR *ppfd )
{
   uint count;
   uint index;
   uint bestindex;
   uint bestdelta;

   (void) hdc;

   count = stw_pixelformat_get_extended_count();
   bestindex = 0;
   bestdelta = ~0U;

   for (index = 1; index <= count; index++) {
      uint delta = 0;
      const struct stw_pixelformat_info *pfi = stw_pixelformat_get_info( index );

      if (!(ppfd->dwFlags & PFD_DOUBLEBUFFER_DONTCARE) &&
          !!(ppfd->dwFlags & PFD_DOUBLEBUFFER) !=
          !!(pfi->pfd.dwFlags & PFD_DOUBLEBUFFER))
         continue;

      /* FIXME: Take in account individual channel bits */
      if (ppfd->cColorBits != pfi->pfd.cColorBits)
         delta += 8;

      if (ppfd->cDepthBits != pfi->pfd.cDepthBits)
         delta += 4;

      if (ppfd->cStencilBits != pfi->pfd.cStencilBits)
         delta += 2;

      if (ppfd->cAlphaBits != pfi->pfd.cAlphaBits)
         delta++;

      if (delta < bestdelta) {
         bestindex = index;
         bestdelta = delta;
         if (bestdelta == 0)
            break;
      }
   }

   return bestindex;
}
Example #3
0
BOOL APIENTRY
DrvSetPixelFormat(
   HDC hdc,
   LONG iPixelFormat )
{
   uint count;
   uint index;
   struct stw_framebuffer *fb;

   if (!stw_dev)
      return FALSE;

   index = (uint) iPixelFormat - 1;
   count = stw_pixelformat_get_extended_count();
   if (index >= count)
      return FALSE;

   fb = stw_framebuffer_from_hdc_locked(hdc);
   if(fb) {
      /* SetPixelFormat must be called only once */
      stw_framebuffer_release( fb );
      return FALSE;
   }

   fb = stw_framebuffer_create(hdc, iPixelFormat);
   if(!fb) {
      return FALSE;
   }
      
   stw_framebuffer_release( fb );

   /* Some applications mistakenly use the undocumented wglSetPixelFormat 
    * function instead of SetPixelFormat, so we call SetPixelFormat here to 
    * avoid opengl32.dll's wglCreateContext to fail */
   if (GetPixelFormat(hdc) == 0) {
        SetPixelFormat(hdc, iPixelFormat, NULL);
   }
   
   return TRUE;
}
Example #4
0
static boolean
stw_query_attrib(
   int iPixelFormat,
   int iLayerPlane,
   int attrib,
   int *pvalue )
{
   uint count;
   const struct stw_pixelformat_info *pfi;

   count = stw_pixelformat_get_extended_count();

   if (attrib == WGL_NUMBER_PIXEL_FORMATS_ARB) {
      *pvalue = (int) count;
      return TRUE;
   }

   pfi = stw_pixelformat_get_info( iPixelFormat );
   if (!pfi) {
      return FALSE;
   }

   switch (attrib) {
   case WGL_DRAW_TO_WINDOW_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_WINDOW ? TRUE : FALSE;
      return TRUE;

   case WGL_DRAW_TO_BITMAP_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_DRAW_TO_BITMAP ? TRUE : FALSE;
      return TRUE;

   case WGL_NEED_PALETTE_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_NEED_PALETTE ? TRUE : FALSE;
      return TRUE;

   case WGL_NEED_SYSTEM_PALETTE_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_NEED_SYSTEM_PALETTE ? TRUE : FALSE;
      return TRUE;

   case WGL_SWAP_METHOD_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_SWAP_COPY ? WGL_SWAP_COPY_ARB : WGL_SWAP_UNDEFINED_ARB;
      return TRUE;

   case WGL_SWAP_LAYER_BUFFERS_ARB:
      *pvalue = FALSE;
      return TRUE;

   case WGL_NUMBER_OVERLAYS_ARB:
      *pvalue = 0;
      return TRUE;

   case WGL_NUMBER_UNDERLAYS_ARB:
      *pvalue = 0;
      return TRUE;
   }

   if (iLayerPlane != 0)
      return FALSE;

   switch (attrib) {
   case WGL_ACCELERATION_ARB:
      *pvalue = WGL_FULL_ACCELERATION_ARB;
      break;

   case WGL_TRANSPARENT_ARB:
      *pvalue = FALSE;
      break;

   case WGL_TRANSPARENT_RED_VALUE_ARB:
   case WGL_TRANSPARENT_GREEN_VALUE_ARB:
   case WGL_TRANSPARENT_BLUE_VALUE_ARB:
   case WGL_TRANSPARENT_ALPHA_VALUE_ARB:
   case WGL_TRANSPARENT_INDEX_VALUE_ARB:
      break;

   case WGL_SHARE_DEPTH_ARB:
   case WGL_SHARE_STENCIL_ARB:
   case WGL_SHARE_ACCUM_ARB:
      *pvalue = TRUE;
      break;

   case WGL_SUPPORT_GDI_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_GDI ? TRUE : FALSE;
      break;

   case WGL_SUPPORT_OPENGL_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_SUPPORT_OPENGL ? TRUE : FALSE;
      break;

   case WGL_DOUBLE_BUFFER_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_DOUBLEBUFFER ? TRUE : FALSE;
      break;

   case WGL_STEREO_ARB:
      *pvalue = pfi->pfd.dwFlags & PFD_STEREO ? TRUE : FALSE;
      break;

   case WGL_PIXEL_TYPE_ARB:
      switch (pfi->pfd.iPixelType) {
      case PFD_TYPE_RGBA:
         if (util_format_is_float(pfi->stvis.color_format)) {
            *pvalue = WGL_TYPE_RGBA_FLOAT_ARB;
         }
         else {
            *pvalue = WGL_TYPE_RGBA_ARB;
         }
         break;
      case PFD_TYPE_COLORINDEX:
         *pvalue = WGL_TYPE_COLORINDEX_ARB;
         break;
      default:
         return FALSE;
      }
      break;

   case WGL_COLOR_BITS_ARB:
      *pvalue = pfi->pfd.cColorBits;
      break;

   case WGL_RED_BITS_ARB:
      *pvalue = pfi->pfd.cRedBits;
      break;

   case WGL_RED_SHIFT_ARB:
      *pvalue = pfi->pfd.cRedShift;
      break;

   case WGL_GREEN_BITS_ARB:
      *pvalue = pfi->pfd.cGreenBits;
      break;

   case WGL_GREEN_SHIFT_ARB:
      *pvalue = pfi->pfd.cGreenShift;
      break;

   case WGL_BLUE_BITS_ARB:
      *pvalue = pfi->pfd.cBlueBits;
      break;

   case WGL_BLUE_SHIFT_ARB:
      *pvalue = pfi->pfd.cBlueShift;
      break;

   case WGL_ALPHA_BITS_ARB:
      *pvalue = pfi->pfd.cAlphaBits;
      break;

   case WGL_ALPHA_SHIFT_ARB:
      *pvalue = pfi->pfd.cAlphaShift;
      break;

   case WGL_ACCUM_BITS_ARB:
      *pvalue = pfi->pfd.cAccumBits;
      break;

   case WGL_ACCUM_RED_BITS_ARB:
      *pvalue = pfi->pfd.cAccumRedBits;
      break;

   case WGL_ACCUM_GREEN_BITS_ARB:
      *pvalue = pfi->pfd.cAccumGreenBits;
      break;

   case WGL_ACCUM_BLUE_BITS_ARB:
      *pvalue = pfi->pfd.cAccumBlueBits;
      break;

   case WGL_ACCUM_ALPHA_BITS_ARB:
      *pvalue = pfi->pfd.cAccumAlphaBits;
      break;

   case WGL_DEPTH_BITS_ARB:
      *pvalue = pfi->pfd.cDepthBits;
      break;

   case WGL_STENCIL_BITS_ARB:
      *pvalue = pfi->pfd.cStencilBits;
      break;

   case WGL_AUX_BUFFERS_ARB:
      *pvalue = pfi->pfd.cAuxBuffers;
      break;

   case WGL_SAMPLE_BUFFERS_ARB:
      *pvalue = 1;
      break;

   case WGL_SAMPLES_ARB:
      *pvalue = pfi->stvis.samples;
      break;


   /* WGL_ARB_pbuffer */

   case WGL_MAX_PBUFFER_WIDTH_ARB:
   case WGL_MAX_PBUFFER_HEIGHT_ARB:
      *pvalue = stw_dev->max_2d_length;
      break;

   case WGL_MAX_PBUFFER_PIXELS_ARB:
      *pvalue = stw_dev->max_2d_length * stw_dev->max_2d_length;
      break;

   case WGL_DRAW_TO_PBUFFER_ARB:
      *pvalue = 1;
      break;


   default:
      return FALSE;
   }

   return TRUE;
}
Example #5
0
WINGDIAPI BOOL APIENTRY
wglChoosePixelFormatARB(
   HDC hdc,
   const int *piAttribIList,
   const FLOAT *pfAttribFList,
   UINT nMaxFormats,
   int *piFormats,
   UINT *nNumFormats )
{
   uint count;
   struct stw_pixelformat_score *scores;
   uint i;

   *nNumFormats = 0;

   /* Allocate and initialize pixelformat score table -- better matches
    * have higher scores. Start with a high score and take out penalty
    * points for a mismatch when the match does not have to be exact.
    * Set a score to 0 if there is a mismatch for an exact match criteria.
    */
   count = stw_pixelformat_get_extended_count();
   scores = (struct stw_pixelformat_score *) MALLOC( count * sizeof( struct stw_pixelformat_score ) );
   if (scores == NULL)
      return FALSE;
   for (i = 0; i < count; i++) {
      scores[i].points = 0x7fffffff;
      scores[i].index = i;
   }

   /* Given the attribute list calculate a score for each pixelformat.
    */
   if (piAttribIList != NULL) {
      while (*piAttribIList != 0) {
         if (!score_pixelformats( scores, count, piAttribIList[0], piAttribIList[1] )) {
            FREE( scores );
            return FALSE;
         }
         piAttribIList += 2;
      }
   }
   if (pfAttribFList != NULL) {
      while (*pfAttribFList != 0) {
         if (!score_pixelformats( scores, count, (int) pfAttribFList[0], (int) pfAttribFList[1] )) {
            FREE( scores );
            return FALSE;
         }
         pfAttribFList += 2;
      }
   }

   /* Bubble-sort the resulting scores. Pixelformats with higher scores go first.
    * TODO: Find out if there are any patent issues with it.
    */
   if (count > 1) {
      uint n = count;
      boolean swapped;

      do {
         swapped = FALSE;
         for (i = 1; i < n; i++) {
            if (scores[i - 1].points < scores[i].points) {
               struct stw_pixelformat_score score = scores[i - 1];

               scores[i - 1] = scores[i];
               scores[i] = score;
               swapped = TRUE;
            }
         }
         n--;
      }
      while (swapped);
   }

   /* Return a list of pixelformats that are the best match.
    * Reject pixelformats with non-positive scores.
    */
   for (i = 0; i < count; i++) {
      if (scores[i].points > 0) {
	 piFormats[*nNumFormats] = scores[i].index + 1;
         (*nNumFormats)++;
	 if (*nNumFormats >= nMaxFormats) {
	    break;
	 }
      }
   }

   FREE( scores );
   return TRUE;
}