static int
copyData(_THIS)
{
    int byte_len;

    if (this->hidden->write_off + this->convert.len_cvt > this->hidden->mixlen) {
        if (this->hidden->write_off > this->hidden->read_off) {
            SDL_memmove(this->hidden->mixbuf,
                        this->hidden->mixbuf + this->hidden->read_off,
                        this->hidden->mixlen - this->hidden->read_off);
            this->hidden->write_off = this->hidden->write_off - this->hidden->read_off;
        } else {
            this->hidden->write_off = 0;
        }
        this->hidden->read_off = 0;
    }

    SDL_memcpy(this->hidden->mixbuf + this->hidden->write_off,
               this->convert.buf,
               this->convert.len_cvt);
    this->hidden->write_off += this->convert.len_cvt;
    byte_len = this->hidden->write_off - this->hidden->read_off;

    return byte_len;
}
Example #2
0
static void SDL_BlitCopyOverlap(SDL_BlitInfo *info)
{
	Uint8 *src, *dst;
	int w, h;
	int srcskip, dstskip;

	w = info->d_width*info->dst->BytesPerPixel;
	h = info->d_height;
	src = info->s_pixels;
	dst = info->d_pixels;
	srcskip = w+info->s_skip;
	dstskip = w+info->d_skip;
	if ( dst < src ) {
		while ( h-- ) {
			SDL_memmove(dst, src, w);
			src += srcskip;
			dst += dstskip;
		}
	} else {
		src += ((h-1) * srcskip);
		dst += ((h-1) * dstskip);
		while ( h-- ) {
			SDL_revcpy(dst, src, w);
			src -= srcskip;
			dst -= dstskip;
		}
	}
}
Example #3
0
/*
 * Close a joystick previously opened with SDL_JoystickOpen()
 */
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
    int i;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return;
    }

    /* First decrement ref count */
    if (--joystick->ref_count > 0) {
        return;
    }

    /* Lock the event queue - prevent joystick polling */
    SDL_Lock_EventThread();

    if (joystick == default_joystick) {
        default_joystick = NULL;
    }
    SDL_SYS_JoystickClose(joystick);

    /* Remove joystick from list */
    for (i = 0; SDL_joysticks[i]; ++i) {
        if (joystick == SDL_joysticks[i]) {
            SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i + 1],
                        (SDL_numjoysticks - i) * sizeof(joystick));
            break;
        }
    }

    /* Let the event thread keep running */
    SDL_Unlock_EventThread();

    /* Free the data associated with this joystick */
    if (joystick->axes) {
        SDL_free(joystick->axes);
    }
    if (joystick->hats) {
        SDL_free(joystick->hats);
    }
    if (joystick->balls) {
        SDL_free(joystick->balls);
    }
    if (joystick->buttons) {
        SDL_free(joystick->buttons);
    }
    SDL_free(joystick);
}
Example #4
0
// Urho3D: added function
static void SDL_RemoveDollarTemplate_one(SDL_GestureTouch* inTouch, int index)
{
    if (index < inTouch->numDollarTemplates - 1) {
        SDL_memmove(&inTouch->dollarTemplate[index], &inTouch->dollarTemplate[index + 1],
            (inTouch->numDollarTemplates - 1 - index) * sizeof(SDL_DollarTemplate));
    }
    if (inTouch->numDollarTemplates > 1) {
        inTouch->dollarTemplate = SDL_realloc(inTouch->dollarTemplate,
            (inTouch->numDollarTemplates - 1) * sizeof(SDL_DollarTemplate));
    }
    else {
        SDL_free(inTouch->dollarTemplate);
        inTouch->dollarTemplate = NULL;
    }
    --inTouch->numDollarTemplates;
}
void SDL_JoystickClose(SDL_Joystick *joystick)
{
	int i;

	if ( ! ValidJoystick(&joystick) ) {
		return;
	}

	
	if ( --joystick->ref_count > 0 ) {
		return;
	}

	
	SDL_Lock_EventThread();

	SDL_SYS_JoystickClose(joystick);

	
	for ( i=0; SDL_joysticks[i]; ++i ) {
		if ( joystick == SDL_joysticks[i] ) {
			SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i+1],
			       (SDL_allocatedjoysticks-i)*sizeof(joystick));
			break;
		}
	}

	
	SDL_Unlock_EventThread();

	
	if ( joystick->axes ) {
		SDL_free(joystick->axes);
	}
	if ( joystick->hats ) {
		SDL_free(joystick->hats);
	}
	if ( joystick->balls ) {
		SDL_free(joystick->balls);
	}
	if ( joystick->buttons ) {
		SDL_free(joystick->buttons);
	}
	SDL_free(joystick);
}
Example #6
0
/*
 * Close a joystick previously opened with SDL_JoystickOpen()
 */
void
SDL_JoystickClose(SDL_Joystick * joystick)
{
    int i;

    if (!SDL_PrivateJoystickValid(&joystick)) {
        return;
    }

    /* First decrement ref count */
    if (--joystick->ref_count > 0) {
        return;
    }

    SDL_SYS_JoystickClose(joystick);

    /* Remove joystick from list */
    for (i = 0; SDL_joysticks[i]; ++i) {
        if (joystick == SDL_joysticks[i]) {
            SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i + 1],
                        (SDL_numjoysticks - i) * sizeof(joystick));
            break;
        }
    }

    /* Free the data associated with this joystick */
    if (joystick->axes) {
        SDL_free(joystick->axes);
    }
    if (joystick->hats) {
        SDL_free(joystick->hats);
    }
    if (joystick->balls) {
        SDL_free(joystick->balls);
    }
    if (joystick->buttons) {
        SDL_free(joystick->buttons);
    }
    SDL_free(joystick);
}
Example #7
0
void
SDL_BlitCopy(SDL_BlitInfo * info)
{
    SDL_bool overlap;
    Uint8 *src, *dst;
    int w, h;
    int srcskip, dstskip;

    w = info->dst_w * info->dst_fmt->BytesPerPixel;
    h = info->dst_h;
    src = info->src;
    dst = info->dst;
    srcskip = info->src_pitch;
    dstskip = info->dst_pitch;

    /* Properly handle overlapping blits */
    if (src < dst) {
        overlap = (dst < (src + h*srcskip));
    } else {
        overlap = (src < (dst + h*dstskip));
    }
    if (overlap) {
        if ( dst < src ) {
                while ( h-- ) {
                        SDL_memmove(dst, src, w);
                        src += srcskip;
                        dst += dstskip;
                }
        } else {
                src += ((h-1) * srcskip);
                dst += ((h-1) * dstskip);
                while ( h-- ) {
                        SDL_memmove(dst, src, w);
                        src -= srcskip;
                        dst -= dstskip;
                }
        }
        return;
    }

#ifdef __SSE__
    if (SDL_HasSSE() &&
        !((uintptr_t) src & 15) && !(srcskip & 15) &&
        !((uintptr_t) dst & 15) && !(dstskip & 15)) {
        while (h--) {
            SDL_memcpySSE(dst, src, w);
            src += srcskip;
            dst += dstskip;
        }
        return;
    }
#endif

#ifdef __MMX__
    if (SDL_HasMMX() && !(srcskip & 7) && !(dstskip & 7)) {
        while (h--) {
            SDL_memcpyMMX(dst, src, w);
            src += srcskip;
            dst += dstskip;
        }
        _mm_empty();
        return;
    }
#endif

    while (h--) {
        SDL_memcpy(dst, src, w);
        src += srcskip;
        dst += dstskip;
    }
}
Example #8
0
static BOOL VManQueryVideoModes(SDL_PrivateVideoData *pPVData)
{
  ULONG			ulRC;
  GDDMODEINFO		sCurModeInfo;
  VMIQCI		sVmiQCI;
  CHAININFO		*pChainInfo;
  PGRADDINFO		pGraddInfo;
  GDDMODEINFO		*pModeInfo;
  ULONG			ulIdx;
  PVIDEOMODE		pVideoMode;

  SDL_Rect		**ppSDLRectList;
  ULONG			ulRectIdx;
  LONG			lPos;
  static ULONG		aModeItemBPP[OS2VMAN_FSMODELIST_SIZE] = {15,8,16,24,32};

  // Query avaible video modes from VMAN, fill pVideoModes, detect current mode

  ulRC = pfnVMIEntry( 0, VMI_CMD_QUERYCURRENTMODE, NULL, &sCurModeInfo );
  if ( ulRC != RC_SUCCESS )
  {
    SDL_SetError( "Could not query desktop video mode." );
    return FALSE;
  }

  sVmiQCI.ulLength = sizeof(VMIQCI);
  ulRC = pfnVMIEntry( 0, VMI_CMD_QUERYCHAININFO, NULL, &sVmiQCI );
  if ( ulRC != RC_SUCCESS )
  {
    SDL_SetError( "pfnVMIEntry(,VMI_CMD_QUERYCHAININFO,,), rc = %u", ulRC );
    return FALSE;
  }

  for( pChainInfo = sVmiQCI.pciHead; pChainInfo != NULL;
       pChainInfo = pChainInfo->pNextChainInfo )
  {
    for( pGraddInfo = pChainInfo->pGraddList; pGraddInfo != NULL;
         pGraddInfo = pGraddInfo->pNextGraddInfo )
    {
      pModeInfo = pGraddInfo->pModeInfo;

      for( ulIdx = 0; ulIdx < pGraddInfo->cModes; ulIdx++,
           pModeInfo = (GDDMODEINFO *)&((PCHAR)pModeInfo)[pModeInfo->ulLength] )
      {
        if ( pModeInfo->ulBpp == 16 && pModeInfo->cColors == 32768 )
          pModeInfo->ulBpp = 15;

        debug( "Mode %X %ux%u, BPP: %u (%.4s), colors: %d%s%s",
               pModeInfo->ulModeId, pModeInfo->ulHorizResolution,
               pModeInfo->ulVertResolution, pModeInfo->ulBpp,
               &pModeInfo->fccColorEncoding, pModeInfo->cColors,
               pModeInfo->ulModeId == sCurModeInfo.ulModeId ? " - CURRENT" : "",
               /*pModeInfo->ulBpp <= 8 ? " - IGNORED" : */"" );

        // if ( pModeInfo->ulBpp <= 8 )
        //   continue;

        pVideoMode = SDL_malloc( sizeof(VIDEOMODE) );
        if ( pVideoMode == NULL )
        {
          SDL_NotEnoughMemory();
          VManFreeVideoModes( pPVData );
          return FALSE;
        }

        if ( pModeInfo->ulModeId == sCurModeInfo.ulModeId )
          pPVData->pDesktopVideoMode = pVideoMode;

        pVideoMode->uiModeID         = pModeInfo->ulModeId;
        pVideoMode->sSDLRect.x       = 0;
        pVideoMode->sSDLRect.y       = 0;
        pVideoMode->sSDLRect.w       = pModeInfo->ulHorizResolution;
        pVideoMode->sSDLRect.h       = pModeInfo->ulVertResolution;
        pVideoMode->uiBPP            = pModeInfo->ulBpp;
        pVideoMode->uiScanLineSize   = pModeInfo->ulScanLineSize;
        pVideoMode->fccColorEncoding = pModeInfo->fccColorEncoding;
        pVideoMode->pNext            = pPVData->pVideoModes;
        pPVData->pVideoModes = pVideoMode;
      }
    }
  }

  if ( pPVData->pDesktopVideoMode == NULL )
  {
    SDL_SetError( "Current video mode not found" );
    VManFreeVideoModes( pPVData );
    return FALSE;
  }

  // Sort video modes, fill pListVideoModes - it will be returned to SDL

  for( ulIdx = 0; ulIdx < OS2VMAN_FSMODELIST_SIZE; ulIdx++ )
  {
    ppSDLRectList = pPVData->pListVideoModes[ulIdx];

    for( pVideoMode = pPVData->pVideoModes; pVideoMode != NULL;
         pVideoMode = pVideoMode->pNext )
    {
      if ( pVideoMode->uiBPP != aModeItemBPP[ulIdx] )
        continue;

      if ( ppSDLRectList == NULL )
      {
        // First record in list
        ppSDLRectList = SDL_malloc( 2 * sizeof(SDL_Rect*) );
        if ( ppSDLRectList == NULL )
          continue;

        ppSDLRectList[0] = &pVideoMode->sSDLRect;
        ppSDLRectList[1] = NULL;
        pPVData->pListVideoModes[ulIdx] = ppSDLRectList;
        continue;
      }

      // Search position in sorted list, count number of items
      lPos = -1;
      for( ulRectIdx = 0; ppSDLRectList[ulRectIdx] != NULL; ulRectIdx++ )
      {
        if ( lPos != -1 ) // Position found - continue calc number of items
          continue;

        if ( ( ppSDLRectList[ulRectIdx]->w * ppSDLRectList[ulRectIdx]->h ) <
             ( pVideoMode->sSDLRect.w * pVideoMode->sSDLRect.h ) )
          lPos = ulRectIdx;
      }

      if ( lPos == -1 )
        lPos = ulRectIdx; // Position not found, get position of NULL
      ulRectIdx++;

      // Insert new item
      ppSDLRectList = SDL_realloc( ppSDLRectList,
                                   ( ulRectIdx + 1 ) * sizeof(SDL_Rect*) );
      if ( ppSDLRectList == NULL )
        continue;
      pPVData->pListVideoModes[ulIdx] = ppSDLRectList;
      SDL_memmove( &ppSDLRectList[lPos + 1], &ppSDLRectList[lPos],
                   ( ulRectIdx - lPos ) * sizeof(SDL_Rect*) );
      ppSDLRectList[lPos] = &pVideoMode->sSDLRect;
    }
  }

#ifdef DEBUG_BUILD
  // Debug. Show sorted lists
  for( ulIdx = 0; ulIdx < OS2VMAN_FSMODELIST_SIZE; ulIdx++ )
  {
    ppSDLRectList = pPVData->pListVideoModes[ulIdx];
    if ( ppSDLRectList == NULL )
      continue;
    debug( "Modes list #%u for %u BPP:", ulIdx, aModeItemBPP[ulIdx] );
    for( ulRectIdx = 0; ppSDLRectList[ulRectIdx] != NULL; ulRectIdx++ )
      debug( "  %u x %u", ppSDLRectList[ulRectIdx]->w,
                          ppSDLRectList[ulRectIdx]->h );
  }
#endif
  return TRUE;
}