예제 #1
0
HRESULT CreateD3D9(OUT LPDIRECT3D9 *ppDirect3D9, UINT SDKVersion)
{
    LPDIRECT3D9_INT pDirect3D9;

    if (ppDirect3D9 == 0)
        return DDERR_INVALIDPARAMS;

    if (AlignedAlloc((LPVOID *)&pDirect3D9, sizeof(DIRECT3D9_INT)) != S_OK)
        return DDERR_OUTOFMEMORY;

    if (pDirect3D9 == 0)
        return DDERR_OUTOFMEMORY;

    pDirect3D9->lpVtbl = &Direct3D9_Vtbl;
    pDirect3D9->dwProcessId = GetCurrentThreadId();
    pDirect3D9->lRefCnt = 1;

    pDirect3D9->SDKVersion = SDKVersion;

    pDirect3D9->lpInt = pDirect3D9;
    pDirect3D9->unknown000007 = 1;

    InitializeCriticalSection(&pDirect3D9->d3d9_cs);

    if (FALSE == GetDisplayDeviceInfo(pDirect3D9))
    {
        DPRINT1("Could not create Direct3D9 object");
        AlignedFree(pDirect3D9);
        return DDERR_GENERIC;
    }

    *ppDirect3D9 = (LPDIRECT3D9)&pDirect3D9->lpVtbl;

    return D3D_OK;
}
예제 #2
0
파일: hostmem.c 프로젝트: stetre/moonglmath
static int CreatePack(lua_State *L, int arg, size_t alignment)
    {
    int err;
    char *ptr;
    int type = checktype(L, arg);
    size_t n = toflattable(L, arg+1);
    size_t size = n * sizeoftype(type);

    if(size == 0) 
        return luaL_argerror(L, arg+1, errstring(ERR_LENGTH));

    ptr = (char*)AlignedAlloc(alignment, size);
    if(!ptr)
        return luaL_error(L, "failed to allocate page aligned memory");

    err = testdata(L, type, n, ptr, size);
    if(err)
        {
        free(ptr);
        return luaL_argerror(L, arg+1, errstring(err));
        }

    CreateAllocated(L, ptr, size);
    return 1;
    }
예제 #3
0
파일: hostmem.c 프로젝트: stetre/moonglmath
static int Create(lua_State *L, int arg, size_t alignment)
    {
    const char *data = NULL;
    char *ptr;
    size_t size;

    if(lua_type(L, arg) == LUA_TSTRING)
        {
        if(!lua_isnoneornil(L, arg+1))
            return CreatePack(L, arg, alignment);
    
        data = luaL_checklstring(L, arg, &size);
        if(size == 0) 
            return luaL_argerror(L, arg, errstring(ERR_LENGTH));
        }
    else
        {
        size = luaL_checkinteger(L, arg);
        if(size == 0) 
            return luaL_argerror(L, arg, errstring(ERR_VALUE));
        }

    ptr = (char*)AlignedAlloc(alignment, size); // (char*)Malloc(L, size);
    if(!ptr)
        return luaL_error(L, "failed to allocate page aligned memory");
            
    if(data)
        memcpy(ptr, data, size);
    else
        memset(ptr, 0, size);

    CreateAllocated(L, ptr, size);
    return 1;
    }
예제 #4
0
파일: Codecs.cpp 프로젝트: bmharper/mvision
void IntelH264Decoder::CreateWorkSurface(mfxFrameSurface1& surf)
{
	// Setup the "work surface". I don't understand why doesn't do this itself (malloc control is all I can assume).
	memset(&surf, 0, sizeof(surf));
	surf.Info = VideoParam.mfx.FrameInfo;
	surf.Info.FourCC = MFX_FOURCC_NV12; // IMSDK docs say NV12 is "Native Format" for IMSDK

	surf.Data.PitchLow = RoundUp(VideoParam.mfx.FrameInfo.Width, 64);
	surf.Data.Y = (mfxU8 *) AlignedAlloc(surf.Data.PitchLow * RoundUp(VideoParam.mfx.FrameInfo.Height, 64) * 3 / 2, 16);
	surf.Data.UV = surf.Data.Y + (surf.Data.PitchLow * RoundUp(VideoParam.mfx.FrameInfo.Height, 64));
}
예제 #5
0
// Test that dynamic allocation works as expected.
TEST(AlignedMemoryTest, DynamicAllocation)
{
    void *p = AlignedAlloc(8, 8);
    EXPECT_TRUE(p);
    EXPECT_ALIGNED(p, 8);
    AlignedFree(p);

    p = AlignedAlloc(8, 16);
    EXPECT_TRUE(p);
    EXPECT_ALIGNED(p, 16);
    AlignedFree(p);

    p = AlignedAlloc(8, 256);
    EXPECT_TRUE(p);
    EXPECT_ALIGNED(p, 256);
    AlignedFree(p);

    p = AlignedAlloc(8, 4096);
    EXPECT_TRUE(p);
    EXPECT_ALIGNED(p, 4096);
    AlignedFree(p);
}
예제 #6
0
long *AlignedAllocLong(size_t lg)
{
	long *r;
	AlignedAlloc(&r, lg);
	return r;
}
예제 #7
0
int *AlignedAllocInt(size_t lg)
{
	int *r;
	AlignedAlloc(&r, lg);
	return r;
}
예제 #8
0
real_t *AlignedAllocReal(size_t lg)
{
	real_t *r;
	AlignedAlloc(&r, lg);
	return r;
}