本文整理汇总了C++中SDL_OutOfMemory函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_OutOfMemory函数的具体用法?C++ SDL_OutOfMemory怎么用?C++ SDL_OutOfMemory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_OutOfMemory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ROM_VideoInit
static int ROM_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
long info;
/* Check out some things about the system */
Gestalt(gestaltQuickdrawVersion, &info);
if ( info == gestaltOriginalQD ) {
SDL_SetError("Color Quickdraw not available");
return(-1);
}
/* Start ROMintosh events */
Mac_InitEvents(this);
/* Get a handle to the main monitor */
SDL_Display = GetMainDevice();
/* Determine the current screen size */
this->info.current_w = (**SDL_Display).gdRect.right;
this->info.current_h = (**SDL_Display).gdRect.bottom;
/* Determine pixel format */
vformat->BitsPerPixel = (**(**SDL_Display).gdPMap).pixelSize;
switch (vformat->BitsPerPixel) {
case 16: /* 5-5-5 RGB */
vformat->Rmask = 0x00007c00;
vformat->Gmask = 0x000003e0;
vformat->Bmask = 0x0000001f;
break;
default:
break;
}
/* Create our palette */
SDL_CTab = (CTabHandle)NewHandle(sizeof(ColorSpec)*256 + 8);
if ( SDL_CTab == nil ) {
SDL_OutOfMemory();
return(-1);
}
(**SDL_CTab).ctSeed = GetCTSeed();
(**SDL_CTab).ctFlags = 0;
(**SDL_CTab).ctSize = 255;
CTabChanged(SDL_CTab);
SDL_CPal = NewPalette(256, SDL_CTab, pmExplicit+pmTolerant, 0);
/* Get a list of available fullscreen modes */
SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
if ( SDL_modelist ) {
SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
if ( SDL_modelist[0] ) {
SDL_modelist[0]->x = 0;
SDL_modelist[0]->y = 0;
SDL_modelist[0]->w = (**SDL_Display).gdRect.right;
SDL_modelist[0]->h = (**SDL_Display).gdRect.bottom;
}
SDL_modelist[1] = NULL;
}
/* Fill in some window manager capabilities */
this->info.wm_available = 1;
/* We're done! */
return(0);
}
示例2: SDL_SYS_JoystickOpen
/* Function to open a joystick for use.
The joystick to open is specified by the index field of the joystick.
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
{
int index;
UInt32 count, gotCount, count2;
long numAxis, numButtons, numHats, numBalls;
count = kMaxReferences;
count2 = 0;
numAxis = numButtons = numHats = numBalls = 0;
index = joystick->index;
/* allocate memory for system specific hardware data */
joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
if (joystick->hwdata == NULL)
{
SDL_OutOfMemory();
return(-1);
}
SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
SDL_strlcpy(joystick->hwdata->name, SDL_SYS_JoystickName(index), SDL_arraysize(joystick->hwdata->name));
joystick->name = joystick->hwdata->name;
ISpElementList_ExtractByKind(
SYS_Elements[index],
kISpElementKind_Axis,
count,
&gotCount,
joystick->hwdata->refs);
numAxis = gotCount;
count -= gotCount;
count2 += gotCount;
ISpElementList_ExtractByKind(
SYS_Elements[index],
kISpElementKind_DPad,
count,
&gotCount,
&(joystick->hwdata->refs[count2]));
numHats = gotCount;
count -= gotCount;
count2 += gotCount;
ISpElementList_ExtractByKind(
SYS_Elements[index],
kISpElementKind_Button,
count,
&gotCount,
&(joystick->hwdata->refs[count2]));
numButtons = gotCount;
count -= gotCount;
count2 += gotCount;
joystick->naxes = numAxis;
joystick->nhats = numHats;
joystick->nballs = numBalls;
joystick->nbuttons = numButtons;
ISpDevices_Activate(
1,
&SYS_Joysticks[index]);
return 0;
}
示例3: XAUDIO2_OpenDevice
static int
XAUDIO2_OpenDevice(_THIS, const char *devname, int iscapture)
{
HRESULT result = S_OK;
WAVEFORMATEX waveformat;
int valid_format = 0;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(_this->spec.format);
IXAudio2 *ixa2 = NULL;
IXAudio2SourceVoice *source = NULL;
UINT32 devId = 0; /* 0 == system default device. */
if (iscapture) {
return SDL_SetError("XAudio2: capture devices unsupported.");
} else if (XAudio2Create(&ixa2, 0, XAUDIO2_DEFAULT_PROCESSOR) != S_OK) {
return SDL_SetError("XAudio2: XAudio2Create() failed at open.");
}
if (devname != NULL) {
UINT32 devcount = 0;
UINT32 i = 0;
if (i == devcount) {
ixa2->Release();
return SDL_SetError("XAudio2: Requested device not found.");
}
}
/* Initialize all variables that we clean on shutdown */
_this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *_this->hidden));
if (_this->hidden == NULL) {
return SDL_OutOfMemory();
}
SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
_this->hidden->ixa2 = ixa2;
_this->hidden->semaphore = CreateSemaphoreEx(NULL, 1, 2, NULL, 0, 0);
if (_this->hidden->semaphore == NULL) {
XAUDIO2_CloseDevice(_this);
return SDL_SetError("XAudio2: CreateSemaphore() failed!");
}
while ((!valid_format) && (test_format)) {
switch (test_format) {
case AUDIO_U8:
case AUDIO_S16:
case AUDIO_S32:
case AUDIO_F32:
_this->spec.format = test_format;
valid_format = 1;
break;
}
test_format = SDL_NextAudioFormat();
}
if (!valid_format) {
XAUDIO2_CloseDevice(_this);
return SDL_SetError("XAudio2: Unsupported audio format");
}
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(&_this->spec);
/* We feed a Source, it feeds the Mastering, which feeds the device. */
_this->hidden->mixlen = _this->spec.size;
_this->hidden->mixbuf = (Uint8 *) SDL_malloc(2 * _this->hidden->mixlen);
if (_this->hidden->mixbuf == NULL) {
XAUDIO2_CloseDevice(_this);
return SDL_OutOfMemory();
}
_this->hidden->nextbuf = _this->hidden->mixbuf;
SDL_memset(_this->hidden->mixbuf, 0, 2 * _this->hidden->mixlen);
/* We use XAUDIO2_DEFAULT_CHANNELS instead of _this->spec.channels. On
Xbox360, _this means 5.1 output, but on Windows, it means "figure out
what the system has." It might be preferable to let XAudio2 blast
stereo output to appropriate surround sound configurations
instead of clamping to 2 channels, even though we'll configure the
Source Voice for whatever number of channels you supply. */
result = ixa2->CreateMasteringVoice(&_this->hidden->mastering,
XAUDIO2_DEFAULT_CHANNELS, _this->spec.freq, 0,
nullptr, nullptr, AudioCategory_GameMedia);
// XAUDIO2_DEFAULT_CHANNELS,
// _this->spec.freq, 0, devId, NULL);
if (result != S_OK) {
XAUDIO2_CloseDevice(_this);
return SDL_SetError("XAudio2: Couldn't create mastering voice");
}
SDL_zero(waveformat);
if (SDL_AUDIO_ISFLOAT(_this->spec.format)) {
waveformat.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
} else {
waveformat.wFormatTag = WAVE_FORMAT_PCM;
}
waveformat.wBitsPerSample = SDL_AUDIO_BITSIZE(_this->spec.format);
waveformat.nChannels = _this->spec.channels;
waveformat.nSamplesPerSec = _this->spec.freq;
waveformat.nBlockAlign =
waveformat.nChannels * (waveformat.wBitsPerSample / 8);
//.........这里部分代码省略.........
示例4: GL_CreateRenderer
SDL_Renderer *
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Renderer *renderer;
GL_RenderData *data;
const char *hint;
GLint value;
Uint32 window_flags;
window_flags = SDL_GetWindowFlags(window);
if (!(window_flags & SDL_WINDOW_OPENGL)) {
if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
return NULL;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
GL_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
renderer->WindowEvent = GL_WindowEvent;
renderer->CreateTexture = GL_CreateTexture;
renderer->UpdateTexture = GL_UpdateTexture;
renderer->LockTexture = GL_LockTexture;
renderer->UnlockTexture = GL_UnlockTexture;
renderer->UpdateViewport = GL_UpdateViewport;
renderer->RenderClear = GL_RenderClear;
renderer->RenderDrawPoints = GL_RenderDrawPoints;
renderer->RenderDrawLines = GL_RenderDrawLines;
renderer->RenderFillRects = GL_RenderFillRects;
renderer->RenderCopy = GL_RenderCopy;
renderer->RenderReadPixels = GL_RenderReadPixels;
renderer->RenderPresent = GL_RenderPresent;
renderer->DestroyTexture = GL_DestroyTexture;
renderer->DestroyRenderer = GL_DestroyRenderer;
renderer->info = GL_RenderDriver.info;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->driverdata = data;
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
GL_DestroyRenderer(renderer);
return NULL;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
}
if (GL_LoadFunctions(data) < 0) {
GL_DestroyRenderer(renderer);
return NULL;
}
#ifdef __MACOSX__
/* Enable multi-threaded rendering */
/* Disabled until Ryan finishes his VBO/PBO code...
CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
*/
#endif
if (flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
if (SDL_GL_GetSwapInterval() > 0) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_width = value;
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_height = value;
if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
|| SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
}
/* Check for multitexture support */
if (SDL_GL_ExtensionSupported("GL_ARB_multitexture")) {
data->glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) SDL_GL_GetProcAddress("glActiveTextureARB");
if (data->glActiveTextureARB) {
data->GL_ARB_multitexture_supported = SDL_TRUE;
data->glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &data->num_texture_units);
}
}
/* Check for shader support */
hint = SDL_GetHint(SDL_HINT_RENDER_OPENGL_SHADERS);
//.........这里部分代码省略.........
示例5: N3DSAUD_OpenDevice
static int
N3DSAUD_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
int format, mixlen, i;
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc(sizeof(*this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, sizeof(*this->hidden));
switch (this->spec.format & 0xff) {
case 8:
case 16:
this->spec.format = AUDIO_S16LSB;
break;
default:
return SDL_SetError("Unsupported audio format");
}
/* The sample count must be a multiple of 64. */
// this->spec.samples = PSP_AUDIO_SAMPLE_ALIGN(this->spec.samples);
this->spec.freq = 44100;
/* Update the fragment size as size in bytes. */
/* SDL_CalculateAudioSpec(this->spec); MOD */
/* switch (this->spec.format) {
case AUDIO_U8:
this->spec.silence = 0x80;
break;
default:
this->spec.silence = 0x00;
break;
}*/
this->spec.size = SDL_AUDIO_BITSIZE(this->spec.format) / 8;
this->spec.size *= this->spec.channels;
this->spec.size *= this->spec.samples;
/* ========================================== */
/* Allocate the mixing buffer. Its size and starting address must
be a multiple of 64 bytes. Our sample count is already a multiple of
64, so spec->size should be a multiple of 64 as well. */
mixlen = this->spec.size * NUM_BUFFERS;
this->hidden->rawbuf = (Uint8 *) memalign(64, mixlen);
if (this->hidden->rawbuf == NULL) {
return SDL_SetError("Couldn't allocate mixing buffer");
}
/* Setup the hardware channel. */
if (this->spec.channels == 1) {
//format = PSP_AUDIO_FORMAT_MONO;
} else {
//format = PSP_AUDIO_FORMAT_STEREO;
}
// this->hidden->channel = sceAudioChReserve(PSP_AUDIO_NEXT_CHANNEL, this->spec.samples, format);
if (this->hidden->channel < 0) {
free(this->hidden->rawbuf);
this->hidden->rawbuf = NULL;
return SDL_SetError("Couldn't reserve hardware channel");
}
memset(this->hidden->rawbuf, 0, mixlen);
for (i = 0; i < NUM_BUFFERS; i++) {
this->hidden->mixbufs[i] = &this->hidden->rawbuf[i * this->spec.size];
}
this->hidden->next_buffer = 0;
return 0;
}
示例6: SDL_CreateRGBSurface
/*
* Create an empty RGB surface of the appropriate depth
*/
SDL_Surface *
SDL_CreateRGBSurface(Uint32 flags,
int width, int height, int depth,
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask)
{
SDL_Surface *surface;
Uint32 format;
/* The flags are no longer used, make the compiler happy */
(void)flags;
/* Get the pixel format */
format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask);
if (format == SDL_PIXELFORMAT_UNKNOWN) {
SDL_SetError("Unknown pixel format");
return NULL;
}
/* Allocate the surface */
surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface));
if (surface == NULL) {
SDL_OutOfMemory();
return NULL;
}
surface->format = SDL_AllocFormat(format);
if (!surface->format) {
SDL_FreeSurface(surface);
return NULL;
}
surface->w = width;
surface->h = height;
surface->pitch = SDL_CalculatePitch(surface);
SDL_SetClipRect(surface, NULL);
if (SDL_ISPIXELFORMAT_INDEXED(surface->format->format)) {
SDL_Palette *palette =
SDL_AllocPalette((1 << surface->format->BitsPerPixel));
if (!palette) {
SDL_FreeSurface(surface);
return NULL;
}
if (palette->ncolors == 2) {
/* Create a black and white bitmap palette */
palette->colors[0].r = 0xFF;
palette->colors[0].g = 0xFF;
palette->colors[0].b = 0xFF;
palette->colors[1].r = 0x00;
palette->colors[1].g = 0x00;
palette->colors[1].b = 0x00;
}
SDL_SetSurfacePalette(surface, palette);
SDL_FreePalette(palette);
}
/* Get the pixels */
if (surface->w && surface->h) {
surface->pixels = SDL_malloc(surface->h * surface->pitch);
if (!surface->pixels) {
SDL_FreeSurface(surface);
SDL_OutOfMemory();
return NULL;
}
/* This is important for bitmaps */
SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
}
/* Allocate an empty mapping */
surface->map = SDL_AllocBlitMap();
if (!surface->map) {
SDL_FreeSurface(surface);
return NULL;
}
/* By default surface with an alpha mask are set up for blending */
if (Amask) {
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
}
/* The surface is ready to go */
surface->refcount = 1;
return surface;
}
示例7: GLES_CreateRenderer
SDL_Renderer *
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
{
SDL_Renderer *renderer;
GLES_RenderData *data;
GLint value;
Uint32 windowFlags;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
windowFlags = SDL_GetWindowFlags(window);
if (!(windowFlags & SDL_WINDOW_OPENGL)) {
if (SDL_RecreateWindow(window, windowFlags | SDL_WINDOW_OPENGL) < 0) {
/* Uh oh, better try to put it back... */
SDL_RecreateWindow(window, windowFlags);
return NULL;
}
}
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
SDL_OutOfMemory();
return NULL;
}
data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
if (!data) {
GLES_DestroyRenderer(renderer);
SDL_OutOfMemory();
return NULL;
}
renderer->WindowEvent = GLES_WindowEvent;
renderer->CreateTexture = GLES_CreateTexture;
renderer->UpdateTexture = GLES_UpdateTexture;
renderer->LockTexture = GLES_LockTexture;
renderer->UnlockTexture = GLES_UnlockTexture;
renderer->SetRenderTarget = GLES_SetRenderTarget;
renderer->UpdateViewport = GLES_UpdateViewport;
renderer->UpdateClipRect = GLES_UpdateClipRect;
renderer->RenderClear = GLES_RenderClear;
renderer->RenderDrawPoints = GLES_RenderDrawPoints;
renderer->RenderDrawLines = GLES_RenderDrawLines;
renderer->RenderFillRects = GLES_RenderFillRects;
renderer->RenderCopy = GLES_RenderCopy;
renderer->RenderCopyEx = GLES_RenderCopyEx;
renderer->RenderReadPixels = GLES_RenderReadPixels;
renderer->RenderPresent = GLES_RenderPresent;
renderer->DestroyTexture = GLES_DestroyTexture;
renderer->DestroyRenderer = GLES_DestroyRenderer;
renderer->GL_BindTexture = GLES_BindTexture;
renderer->GL_UnbindTexture = GLES_UnbindTexture;
renderer->info = GLES_RenderDriver.info;
renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->driverdata = data;
renderer->window = window;
data->context = SDL_GL_CreateContext(window);
if (!data->context) {
GLES_DestroyRenderer(renderer);
return NULL;
}
if (SDL_GL_MakeCurrent(window, data->context) < 0) {
GLES_DestroyRenderer(renderer);
return NULL;
}
if (GLES_LoadFunctions(data) < 0) {
GLES_DestroyRenderer(renderer);
return NULL;
}
if (flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
if (SDL_GL_GetSwapInterval() > 0) {
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
}
#if SDL_VIDEO_DRIVER_PANDORA
data->GL_OES_draw_texture_supported = SDL_FALSE;
data->useDrawTexture = SDL_FALSE;
#else
if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
data->GL_OES_draw_texture_supported = SDL_TRUE;
data->useDrawTexture = SDL_TRUE;
} else {
data->GL_OES_draw_texture_supported = SDL_FALSE;
data->useDrawTexture = SDL_FALSE;
}
#endif
value = 0;
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_width = value;
//.........这里部分代码省略.........
示例8: SNDMGR_OpenDevice
static int
SNDMGR_OpenDevice(_THIS, const char *devname, int iscapture)
{
SDL_AudioSpec *spec = &this->spec;
SndChannelPtr channel = NULL;
SndCallBackUPP callback;
int sample_bits;
int i;
long initOptions;
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* !!! FIXME: iterate through format matrix... */
/* Very few conversions are required, but... */
switch (spec->format) {
case AUDIO_S8:
spec->format = AUDIO_U8;
break;
case AUDIO_U16LSB:
spec->format = AUDIO_S16LSB;
break;
case AUDIO_U16MSB:
spec->format = AUDIO_S16MSB;
break;
case AUDIO_F32LSB:
spec->format = AUDIO_F32MSB;
break;
}
SDL_CalculateAudioSpec(&this->spec);
/* initialize bufferCmd header */
SDL_memset(&header, 0, sizeof(header));
callback = (SndCallBackUPP) NewSndCallBackUPP(callBackProc);
sample_bits = spec->size / spec->samples / spec->channels * 8;
#ifdef DEBUG_AUDIO
fprintf(stderr,
"Audio format 0x%x, channels = %d, sample_bits = %d, frequency = %d\n",
spec->format, spec->channels, sample_bits, spec->freq);
#endif /* DEBUG_AUDIO */
header.numChannels = spec->channels;
header.sampleSize = sample_bits;
header.sampleRate = spec->freq << 16;
header.numFrames = spec->samples;
header.encode = cmpSH;
/* Note that we install the 16bitLittleEndian Converter if needed. */
if (spec->format == AUDIO_S16LSB) {
header.compressionID = fixedCompression;
header.format = k16BitLittleEndianFormat;
} else if (spec->format == AUDIO_S32MSB) {
header.compressionID = fixedCompression;
header.format = k32BitFormat;
} else if (spec->format == AUDIO_S32LSB) {
header.compressionID = fixedCompression;
header.format = k32BitLittleEndianFormat;
} else if (spec->format == AUDIO_F32MSB) {
header.compressionID = fixedCompression;
header.format = kFloat32Format;
}
/* allocate 2 buffers */
for (i = 0; i < 2; i++) {
buffer[i] = (UInt8 *) SDL_malloc(sizeof(UInt8) * spec->size);
if (buffer[i] == NULL) {
SNDMGR_CloseDevice(this);
SDL_OutOfMemory();
return 0;
}
SDL_memset(buffer[i], 0, spec->size);
}
/* Create the sound manager channel */
channel = (SndChannelPtr) SDL_malloc(sizeof(*channel));
if (channel == NULL) {
SNDMGR_CloseDevice(this);
SDL_OutOfMemory();
return 0;
}
this->hidden->channel = channel;
if (spec->channels >= 2) {
initOptions = initStereo;
} else {
initOptions = initMono;
}
channel->userInfo = (long) this;
channel->qLength = 128;
if (SndNewChannel(&channel, sampledSynth, initOptions, callback) != noErr) {
SNDMGR_CloseDevice(this);
SDL_SetError("Unable to create audio channel");
return 0;
}
//.........这里部分代码省略.........
示例9: COREAUDIO_OpenDevice
static int
COREAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
{
AudioStreamBasicDescription strdesc;
SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
int valid_datatype = 0;
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
return SDL_OutOfMemory();
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
/* Setup a AudioStreamBasicDescription with the requested format */
SDL_memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
strdesc.mFormatID = kAudioFormatLinearPCM;
strdesc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
strdesc.mChannelsPerFrame = this->spec.channels;
strdesc.mSampleRate = this->spec.freq;
strdesc.mFramesPerPacket = 1;
while ((!valid_datatype) && (test_format)) {
this->spec.format = test_format;
/* Just a list of valid SDL formats, so people don't pass junk here. */
switch (test_format) {
case AUDIO_U8:
case AUDIO_S8:
case AUDIO_U16LSB:
case AUDIO_S16LSB:
case AUDIO_U16MSB:
case AUDIO_S16MSB:
case AUDIO_S32LSB:
case AUDIO_S32MSB:
case AUDIO_F32LSB:
case AUDIO_F32MSB:
valid_datatype = 1;
strdesc.mBitsPerChannel = SDL_AUDIO_BITSIZE(this->spec.format);
if (SDL_AUDIO_ISBIGENDIAN(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
if (SDL_AUDIO_ISFLOAT(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
else if (SDL_AUDIO_ISSIGNED(this->spec.format))
strdesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
break;
}
}
if (!valid_datatype) { /* shouldn't happen, but just in case... */
COREAUDIO_CloseDevice(this);
return SDL_SetError("Unsupported audio format");
}
strdesc.mBytesPerFrame =
strdesc.mBitsPerChannel * strdesc.mChannelsPerFrame / 8;
strdesc.mBytesPerPacket =
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
if (!prepare_audiounit(this, handle, iscapture, &strdesc)) {
COREAUDIO_CloseDevice(this);
return -1; /* prepare_audiounit() will call SDL_SetError()... */
}
return 0; /* good to go. */
}
示例10: X11_CreatePixmapCursor
static Cursor
X11_CreatePixmapCursor(SDL_Surface * surface, int hot_x, int hot_y)
{
Display *display = GetDisplay();
XColor fg, bg;
Cursor cursor = None;
Uint32 *ptr;
Uint8 *data_bits, *mask_bits;
Pixmap data_pixmap, mask_pixmap;
int x, y;
unsigned int rfg, gfg, bfg, rbg, gbg, bbg, fgBits, bgBits;
unsigned int width_bytes = ((surface->w + 7) & ~7) / 8;
data_bits = SDL_calloc(1, surface->h * width_bytes);
mask_bits = SDL_calloc(1, surface->h * width_bytes);
if (!data_bits || !mask_bits) {
SDL_OutOfMemory();
return None;
}
/* Code below assumes ARGB pixel format */
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
rfg = gfg = bfg = rbg = gbg = bbg = fgBits = bgBits = 0;
for (y = 0; y < surface->h; ++y) {
ptr = (Uint32 *)((Uint8 *)surface->pixels + y * surface->pitch);
for (x = 0; x < surface->w; ++x) {
int alpha = (*ptr >> 24) & 0xff;
int red = (*ptr >> 16) & 0xff;
int green = (*ptr >> 8) & 0xff;
int blue = (*ptr >> 0) & 0xff;
if (alpha > 25) {
mask_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
if ((red + green + blue) > 0x40) {
fgBits++;
rfg += red;
gfg += green;
bfg += blue;
data_bits[y * width_bytes + x / 8] |= (0x01 << (x % 8));
} else {
bgBits++;
rbg += red;
gbg += green;
bbg += blue;
}
}
++ptr;
}
}
if (fgBits) {
fg.red = rfg * 257 / fgBits;
fg.green = gfg * 257 / fgBits;
fg.blue = bfg * 257 / fgBits;
}
else fg.red = fg.green = fg.blue = 0;
if (bgBits) {
bg.red = rbg * 257 / bgBits;
bg.green = gbg * 257 / bgBits;
bg.blue = bbg * 257 / bgBits;
}
else bg.red = bg.green = bg.blue = 0;
data_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
(char*)data_bits,
surface->w, surface->h);
mask_pixmap = XCreateBitmapFromData(display, DefaultRootWindow(display),
(char*)mask_bits,
surface->w, surface->h);
cursor = XCreatePixmapCursor(display, data_pixmap, mask_pixmap,
&fg, &bg, hot_x, hot_y);
XFreePixmap(display, data_pixmap);
XFreePixmap(display, mask_pixmap);
return cursor;
}
示例11: X11_CreateDevice
static SDL_VideoDevice *
X11_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
const char *display = NULL; /* Use the DISPLAY environment variable */
if (!SDL_X11_LoadSymbols()) {
return NULL;
}
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_OutOfMemory();
return NULL;
}
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
SDL_OutOfMemory();
SDL_free(device);
return NULL;
}
device->driverdata = data;
#if SDL_VIDEO_DRIVER_PANDORA
device->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
if (!device->gles_data) {
SDL_OutOfMemory();
return NULL;
}
#endif
/* FIXME: Do we need this?
if ( (SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
(SDL_strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
local_X11 = 1;
} else {
local_X11 = 0;
}
*/
data->display = XOpenDisplay(display);
#if defined(__osf__) && defined(SDL_VIDEO_DRIVER_X11_DYNAMIC)
/* On Tru64 if linking without -lX11, it fails and you get following message.
* Xlib: connection to ":0.0" refused by server
* Xlib: XDM authorization key matches an existing client!
*
* It succeeds if retrying 1 second later
* or if running xhost +localhost on shell.
*/
if (data->display == NULL) {
SDL_Delay(1000);
data->display = XOpenDisplay(display);
}
#endif
if (data->display == NULL) {
SDL_free(device);
SDL_SetError("Couldn't open X11 display");
return NULL;
}
#ifdef X11_DEBUG
XSynchronize(data->display, True);
#endif
/* Set the function pointers */
device->VideoInit = X11_VideoInit;
device->VideoQuit = X11_VideoQuit;
device->GetDisplayModes = X11_GetDisplayModes;
device->SetDisplayMode = X11_SetDisplayMode;
device->SuspendScreenSaver = X11_SuspendScreenSaver;
device->PumpEvents = X11_PumpEvents;
device->CreateWindow = X11_CreateWindow;
device->CreateWindowFrom = X11_CreateWindowFrom;
device->SetWindowTitle = X11_SetWindowTitle;
device->SetWindowIcon = X11_SetWindowIcon;
device->SetWindowPosition = X11_SetWindowPosition;
device->SetWindowSize = X11_SetWindowSize;
device->ShowWindow = X11_ShowWindow;
device->HideWindow = X11_HideWindow;
device->RaiseWindow = X11_RaiseWindow;
device->MaximizeWindow = X11_MaximizeWindow;
device->MinimizeWindow = X11_MinimizeWindow;
device->RestoreWindow = X11_RestoreWindow;
device->SetWindowFullscreen = X11_SetWindowFullscreen;
device->SetWindowGammaRamp = X11_SetWindowGammaRamp;
device->SetWindowGrab = X11_SetWindowGrab;
device->DestroyWindow = X11_DestroyWindow;
device->CreateWindowFramebuffer = X11_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = X11_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = X11_DestroyWindowFramebuffer;
device->GetWindowWMInfo = X11_GetWindowWMInfo;
device->shape_driver.CreateShaper = X11_CreateShaper;
device->shape_driver.SetWindowShape = X11_SetWindowShape;
device->shape_driver.ResizeWindowShape = X11_ResizeWindowShape;
#if SDL_VIDEO_OPENGL_GLX
device->GL_LoadLibrary = X11_GL_LoadLibrary;
device->GL_GetProcAddress = X11_GL_GetProcAddress;
//.........这里部分代码省略.........
示例12: MIR_CreateDevice
static SDL_VideoDevice*
MIR_CreateDevice(int device_index)
{
MIR_Data* mir_data;
SDL_VideoDevice* device = NULL;
if (!SDL_MIR_LoadSymbols()) {
return NULL;
}
device = SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_MIR_UnloadSymbols();
SDL_OutOfMemory();
return NULL;
}
mir_data = SDL_calloc(1, sizeof(MIR_Data));
if (!mir_data) {
SDL_free(device);
SDL_MIR_UnloadSymbols();
SDL_OutOfMemory();
return NULL;
}
device->driverdata = mir_data;
/* mirvideo */
device->VideoInit = MIR_VideoInit;
device->VideoQuit = MIR_VideoQuit;
device->GetDisplayBounds = MIR_GetDisplayBounds;
device->GetDisplayModes = MIR_GetDisplayModes;
device->SetDisplayMode = MIR_SetDisplayMode;
device->free = MIR_DeleteDevice;
/* miropengles */
device->GL_SwapWindow = MIR_GL_SwapWindow;
device->GL_MakeCurrent = MIR_GL_MakeCurrent;
device->GL_CreateContext = MIR_GL_CreateContext;
device->GL_DeleteContext = MIR_GL_DeleteContext;
device->GL_LoadLibrary = MIR_GL_LoadLibrary;
device->GL_UnloadLibrary = MIR_GL_UnloadLibrary;
device->GL_GetSwapInterval = MIR_GL_GetSwapInterval;
device->GL_SetSwapInterval = MIR_GL_SetSwapInterval;
device->GL_GetProcAddress = MIR_GL_GetProcAddress;
/* mirwindow */
device->CreateWindow = MIR_CreateWindow;
device->DestroyWindow = MIR_DestroyWindow;
device->GetWindowWMInfo = MIR_GetWindowWMInfo;
device->SetWindowFullscreen = MIR_SetWindowFullscreen;
device->MaximizeWindow = MIR_MaximizeWindow;
device->MinimizeWindow = MIR_MinimizeWindow;
device->RestoreWindow = MIR_RestoreWindow;
device->CreateWindowFrom = NULL;
device->SetWindowTitle = NULL;
device->SetWindowIcon = NULL;
device->SetWindowPosition = NULL;
device->SetWindowSize = NULL;
device->SetWindowMinimumSize = NULL;
device->SetWindowMaximumSize = NULL;
device->ShowWindow = NULL;
device->HideWindow = NULL;
device->RaiseWindow = NULL;
device->SetWindowBordered = NULL;
device->SetWindowGammaRamp = NULL;
device->GetWindowGammaRamp = NULL;
device->SetWindowGrab = NULL;
device->OnWindowEnter = NULL;
/* mirframebuffer */
device->CreateWindowFramebuffer = MIR_CreateWindowFramebuffer;
device->UpdateWindowFramebuffer = MIR_UpdateWindowFramebuffer;
device->DestroyWindowFramebuffer = MIR_DestroyWindowFramebuffer;
device->shape_driver.CreateShaper = MIR_CreateShaper;
device->shape_driver.SetWindowShape = MIR_SetWindowShape;
device->shape_driver.ResizeWindowShape = MIR_ResizeWindowShape;
device->PumpEvents = MIR_PumpEvents;
device->SuspendScreenSaver = NULL;
device->StartTextInput = NULL;
device->StopTextInput = NULL;
device->SetTextInputRect = NULL;
device->HasScreenKeyboardSupport = NULL;
device->ShowScreenKeyboard = NULL;
device->HideScreenKeyboard = NULL;
device->IsScreenKeyboardShown = NULL;
device->SetClipboardText = NULL;
device->GetClipboardText = NULL;
device->HasClipboardText = NULL;
device->ShowMessageBox = NULL;
return device;
//.........这里部分代码省略.........
示例13: SDL_AddTimer
SDL_TimerID
SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *param)
{
SDL_TimerData *data = &SDL_timer_data;
SDL_Timer *timer;
SDL_TimerMap *entry;
if (!data->active) {
int status = 0;
SDL_AtomicLock(&data->lock);
if (!data->active) {
status = SDL_TimerInit();
}
SDL_AtomicUnlock(&data->lock);
if (status < 0) {
return 0;
}
}
SDL_AtomicLock(&data->lock);
timer = data->freelist;
if (timer) {
data->freelist = timer->next;
}
SDL_AtomicUnlock(&data->lock);
if (timer) {
SDL_RemoveTimer(timer->timerID);
} else {
timer = (SDL_Timer *)SDL_malloc(sizeof(*timer));
if (!timer) {
SDL_OutOfMemory();
return 0;
}
}
timer->timerID = SDL_AtomicIncRef(&data->nextID);
timer->callback = callback;
timer->param = param;
timer->interval = interval;
timer->scheduled = SDL_GetTicks() + interval;
timer->canceled = SDL_FALSE;
entry = (SDL_TimerMap *)SDL_malloc(sizeof(*entry));
if (!entry) {
SDL_free(timer);
SDL_OutOfMemory();
return 0;
}
entry->timer = timer;
entry->timerID = timer->timerID;
SDL_LockMutex(data->timermap_lock);
entry->next = data->timermap;
data->timermap = entry;
SDL_UnlockMutex(data->timermap_lock);
/* Add the timer to the pending list for the timer thread */
SDL_AtomicLock(&data->lock);
timer->next = data->pending;
data->pending = timer;
SDL_AtomicUnlock(&data->lock);
/* Wake up the timer thread if necessary */
SDL_SemPost(data->sem);
return entry->timerID;
}
示例14: X11_CreateDevice
static SDL_VideoDevice *
X11_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
SDL_VideoData *data;
const char *display = NULL; /* Use the DISPLAY environment variable */
if (!SDL_X11_LoadSymbols()) {
return NULL;
}
/* Need for threading gl calls. This is also required for the proprietary
nVidia driver to be threaded. */
X11_XInitThreads();
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (!device) {
SDL_OutOfMemory();
return NULL;
}
data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (!data) {
SDL_free(device);
SDL_OutOfMemory();
return NULL;
}
device->driverdata = data;
data->global_mouse_changed = SDL_TRUE;
/* FIXME: Do we need this?
if ( (SDL_strncmp(X11_XDisplayName(display), ":", 1) == 0) ||
(SDL_strncmp(X11_XDisplayName(display), "unix:", 5) == 0) ) {
local_X11 = 1;
} else {
local_X11 = 0;
}
*/
data->display = X11_XOpenDisplay(display);
#ifdef SDL_VIDEO_DRIVER_X11_DYNAMIC
/* On some systems if linking without -lX11, it fails and you get following message.
* Xlib: connection to ":0.0" refused by server
* Xlib: XDM authorization key matches an existing client!
*
* It succeeds if retrying 1 second later
* or if running xhost +localhost on shell.
*/
if (data->display == NULL) {
SDL_Delay(1000);
data->display = X11_XOpenDisplay(display);
}
#endif
if (data->display == NULL) {
SDL_free(device->driverdata);
SDL_free(device);
SDL_SetError("Couldn't open X11 display");
return NULL;
}
#ifdef X11_DEBUG
X11_XSynchronize(data->display, True);
#endif
/* Hook up an X11 error handler to recover the desktop resolution. */
safety_net_triggered = SDL_FALSE;
orig_x11_errhandler = X11_XSetErrorHandler(X11_SafetyNetErrHandler);
/* Set the function pointers */
device->VideoInit = X11_VideoInit;
device->VideoQuit = X11_VideoQuit;
device->ResetTouch = X11_ResetTouch;
device->GetDisplayModes = X11_GetDisplayModes;
device->GetDisplayBounds = X11_GetDisplayBounds;
device->GetDisplayUsableBounds = X11_GetDisplayUsableBounds;
device->GetDisplayDPI = X11_GetDisplayDPI;
device->SetDisplayMode = X11_SetDisplayMode;
device->SuspendScreenSaver = X11_SuspendScreenSaver;
device->PumpEvents = X11_PumpEvents;
device->CreateSDLWindow = X11_CreateWindow;
device->CreateSDLWindowFrom = X11_CreateWindowFrom;
device->SetWindowTitle = X11_SetWindowTitle;
device->SetWindowIcon = X11_SetWindowIcon;
device->SetWindowPosition = X11_SetWindowPosition;
device->SetWindowSize = X11_SetWindowSize;
device->SetWindowMinimumSize = X11_SetWindowMinimumSize;
device->SetWindowMaximumSize = X11_SetWindowMaximumSize;
device->GetWindowBordersSize = X11_GetWindowBordersSize;
device->SetWindowOpacity = X11_SetWindowOpacity;
device->SetWindowModalFor = X11_SetWindowModalFor;
device->SetWindowInputFocus = X11_SetWindowInputFocus;
device->ShowWindow = X11_ShowWindow;
device->HideWindow = X11_HideWindow;
device->RaiseWindow = X11_RaiseWindow;
device->MaximizeWindow = X11_MaximizeWindow;
device->MinimizeWindow = X11_MinimizeWindow;
device->RestoreWindow = X11_RestoreWindow;
device->SetWindowBordered = X11_SetWindowBordered;
device->SetWindowResizable = X11_SetWindowResizable;
device->SetWindowFullscreen = X11_SetWindowFullscreen;
//.........这里部分代码省略.........
示例15: SDL_LoadBMP_RW
//.........这里部分代码省略.........
case BI_BITFIELDS:
break; /* we handled this in the info header. */
default:
SDL_SetError("Compressed BMP files not supported");
was_error = SDL_TRUE;
goto done;
}
/* Create a compatible surface, note that the colors are RGB ordered */
surface =
SDL_CreateRGBSurface(0, biWidth, biHeight, biBitCount, Rmask, Gmask,
Bmask, Amask);
if (surface == NULL) {
was_error = SDL_TRUE;
goto done;
}
/* Load the palette, if any */
palette = (surface->format)->palette;
if (palette) {
SDL_assert(biBitCount <= 8);
if (biClrUsed == 0) {
biClrUsed = 1 << biBitCount;
}
if ((int) biClrUsed > palette->ncolors) {
SDL_Color *colors;
int ncolors = biClrUsed;
colors =
(SDL_Color *) SDL_realloc(palette->colors,
ncolors *
sizeof(*palette->colors));
if (!colors) {
SDL_OutOfMemory();
was_error = SDL_TRUE;
goto done;
}
palette->ncolors = ncolors;
palette->colors = colors;
} else if ((int) biClrUsed < palette->ncolors) {
palette->ncolors = biClrUsed;
}
if (biSize == 12) {
for (i = 0; i < (int) biClrUsed; ++i) {
SDL_RWread(src, &palette->colors[i].b, 1, 1);
SDL_RWread(src, &palette->colors[i].g, 1, 1);
SDL_RWread(src, &palette->colors[i].r, 1, 1);
palette->colors[i].a = SDL_ALPHA_OPAQUE;
}
} else {
for (i = 0; i < (int) biClrUsed; ++i) {
SDL_RWread(src, &palette->colors[i].b, 1, 1);
SDL_RWread(src, &palette->colors[i].g, 1, 1);
SDL_RWread(src, &palette->colors[i].r, 1, 1);
SDL_RWread(src, &palette->colors[i].a, 1, 1);
/* According to Microsoft documentation, the fourth element
is reserved and must be zero, so we shouldn't treat it as
alpha.
*/
palette->colors[i].a = SDL_ALPHA_OPAQUE;
}
}
}
/* Read the surface pixels. Note that the bmp image is upside down */