test/testnativecocoa.m
author Sam Lantinga <slouken@libsdl.org>
Sun, 07 Jul 2019 09:10:56 -0700
changeset 12928 3c4a4b1077cd
parent 3057 089a77aebb7d
permissions -rw-r--r--
Fixed bug 4710 - audio/alsa: avoid configuring hardware parameters with only a single period

Anthony Pesch

The previous code first configured the period size using snd_pcm_hw_par-
ams_set_period_size_near. Then, it further narrowed the configuration
space by calling snd_pcm_hw_params_set_buffer_size_near using a buffer
size of 2 times the _requested_ period size in order to try and get a
configuration with only 2 periods. If the configured period size was
larger than the requested size, the second call could inadvertently
narrow the configuration space to contain only a single period.

Rather than fixing the call to snd_pcm_hw_params_set_buffer_size_near
to use a size of 2 times the configured period size, the code has been
changed to use snd_pcm_hw_params_set_periods_min in order to more
clearly explain the intent.
slouken@3057
     1
slouken@3057
     2
#include "testnative.h"
slouken@3057
     3
slouken@3057
     4
#ifdef TEST_NATIVE_COCOA
slouken@3057
     5
slouken@3057
     6
#include <Cocoa/Cocoa.h>
slouken@3057
     7
slouken@3057
     8
static void *CreateWindowCocoa(int w, int h);
slouken@3057
     9
static void DestroyWindowCocoa(void *window);
slouken@3057
    10
slouken@3057
    11
NativeWindowFactory CocoaWindowFactory = {
slouken@3057
    12
    "cocoa",
slouken@3057
    13
    CreateWindowCocoa,
slouken@3057
    14
    DestroyWindowCocoa
slouken@3057
    15
};
slouken@3057
    16
slouken@3057
    17
static void *CreateWindowCocoa(int w, int h)
slouken@3057
    18
{
slouken@3057
    19
    NSAutoreleasePool *pool;
slouken@3057
    20
    NSWindow *nswindow;
slouken@3057
    21
    NSRect rect;
slouken@3057
    22
    unsigned int style;
slouken@3057
    23
slouken@3057
    24
    pool = [[NSAutoreleasePool alloc] init];
slouken@3057
    25
slouken@3057
    26
    rect.origin.x = 0;
slouken@3057
    27
    rect.origin.y = 0;
slouken@3057
    28
    rect.size.width = w;
slouken@3057
    29
    rect.size.height = h;
slouken@3057
    30
    rect.origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - rect.origin.y - rect.size.height;
slouken@3057
    31
slouken@3057
    32
    style = (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask);
slouken@3057
    33
slouken@3057
    34
    nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
slouken@3057
    35
    [nswindow makeKeyAndOrderFront:nil];
slouken@3057
    36
slouken@3057
    37
    [pool release];
slouken@3057
    38
slouken@3057
    39
    return nswindow;
slouken@3057
    40
}
slouken@3057
    41
slouken@3057
    42
static void DestroyWindowCocoa(void *window)
slouken@3057
    43
{
slouken@3057
    44
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
slouken@3057
    45
    NSWindow *nswindow = (NSWindow *)window;
slouken@3057
    46
slouken@3057
    47
    [nswindow close];
slouken@3057
    48
    [pool release];
slouken@3057
    49
}
slouken@3057
    50
slouken@3057
    51
#endif