surf.cpp
来自「6410BSP3」· C++ 代码 · 共 474 行 · 第 1/2 页
CPP
474 行
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// Copyright (c) Samsung Electronics. Co. LTD. All rights reserved.
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
surf.cpp
Abstract:
surface allocation/manipulation/free routines
Functions:
Notes:
--*/
#include "precomp.h"
#define ALIGN(x, align) (((x) + ((align) - 1)) & ~((align) - 1))
static DWORD dwSurfaceCount = 0;
SCODE
S3C6410Disp::AllocSurfacePACS(
GPESurf **ppSurf,
int width,
int height,
EGPEFormat format)
{
/// try to allocate physically linear address
*ppSurf = new PACSurf(width, height, format);
if (*ppSurf == NULL)
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : PACSurface allocate Failed -> Try to allocate Normal GPE Surface\n\r")));
return E_OUTOFMEMORY;
}
else if ((*ppSurf)->Buffer() == NULL)
{
delete *ppSurf;
*ppSurf = NULL;
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : PACSurface Buffer is NULL -> Try to allocate Normal GPE Surface\n\r")));
}
else /// PAC Allocation succeeded.
{
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV] AllocSurface() : PACSurf() Allocated in System Memory\n\r")));
return S_OK;
}
return E_FAIL;
}
// This method is called for all normal surface allocations from ddgpe and gpe
SCODE
S3C6410Disp::AllocSurface(
GPESurf **ppSurf,
int width,
int height,
EGPEFormat format,
int surfaceFlags)
{
RETAILMSG(DISP_ZONE_CREATE,(_T("[AS] %dx%d FMT:%d F:%08x\n\r"), width, height, format, surfaceFlags));
// This method is only for surface in system memory
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : Can not allocate GPE_REQUIRE_VIDEO_MEMORY Surface in system memory\n\r")));
return E_OUTOFMEMORY;
}
if(m_G2DControlArgs.HWOnOff && m_G2DControlArgs.UsePACSurf)
{
/// Only Support 16bpp, 24bpp, 32bpp
if( format == gpe16Bpp || format == gpe24Bpp || format == gpe32Bpp || format == gpeDeviceCompatible)
{
if(m_G2DControlArgs.SetBltLimitSize)
{
if(width*height*(EGPEFormatToBpp[format] >> 3) > PAC_ALLOCATION_BOUNDARY)
{
if(S_OK == AllocSurfacePACS(ppSurf, width, height, format))
{
return S_OK;
}
}
}
else
{
if(S_OK == AllocSurfacePACS(ppSurf, width, height, format))
{
return S_OK;
}
}
}
}
/// if allocation is failed or boundary condition is not met, just create GPESurf in normal system memory that can be non-linear physically.
// Allocate surface from system memory
*ppSurf = new GPESurf(width, height, format);
if (*ppSurf != NULL)
{
if (((*ppSurf)->Buffer()) == NULL)
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : Surface Buffer is NULL\n\r")));
delete *ppSurf;
return E_OUTOFMEMORY;
}
else
{
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV] AllocSurface() : GPESurf() Allocated in System Memory\n\r")));
return S_OK;
}
}
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : Surface allocate Failed\n\r")));
return E_OUTOFMEMORY;
}
// This method is used for DirectDraw enabled surfaces
SCODE
S3C6410Disp::AllocSurface(
DDGPESurf **ppSurf,
int width,
int height,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat,
int surfaceFlags)
{
RETAILMSG(DISP_ZONE_CREATE,(_T("[DISPDRV] %s(%d, %d, %d, %d, 0x%08x)\n\r"), _T(__FUNCTION__), width, height, format, pixelFormat, surfaceFlags));
unsigned int bpp;
unsigned int stride;
unsigned int align_width;
if (pixelFormat == ddgpePixelFormat_I420 || pixelFormat == ddgpePixelFormat_YV12)
{
// in this case, stride can't be calculated. because of planar format (non-interleaved...)
bpp = 12;
align_width = ALIGN(width, 16);
}
else if (pixelFormat == ddgpePixelFormat_YVYU || pixelFormat == ddgpePixelFormat_VYUY)
{
bpp = 16;
align_width = width;
}
else
{
bpp = EGPEFormatToBpp[format];
align_width = width;
}
//DISPDRV_ERR((_T("[AS] %dx%d %dbpp FMT:%d F:%08x\n\r"), width, height, bpp, format, surfaceFlags));
//--------------------------------------
// Try to allocate surface from video memory
//--------------------------------------
// stride are all 32bit aligned for Video Memory
stride = ((bpp * align_width + 31) >> 5) << 2;
if ((surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
|| (surfaceFlags & GPE_BACK_BUFFER)
//|| ((surfaceFlags & GPE_PREFER_VIDEO_MEMORY) && (format == m_pMode->format)))
|| (surfaceFlags & GPE_PREFER_VIDEO_MEMORY) && (format == m_pMode->format))
{
SCODE rv = AllocSurfaceVideo(ppSurf, width, height, stride, format, pixelFormat);
if (rv == S_OK)
{
return S_OK;
}
else
{
if (surfaceFlags & (GPE_REQUIRE_VIDEO_MEMORY|GPE_BACK_BUFFER))
{
RETAILMSG(DISP_ZONE_ERROR,(_T("[DISPDRV:ERR] AllocSurface() : AllocSurfaceVideo() failed\n\r")));
return E_OUTOFMEMORY;
}
}
}
//--------------------------------------
// Try to allocate surface from system memory
//--------------------------------------
// stride and surface size for system memory surfaces
stride = ((bpp * width + 31) >> 5) << 2;
unsigned int surface_size = stride*height;
// Allocate from system memory
*ppSurf = new DDGPESurf(width, height, stride, format, pixelFormat);
if (*ppSurf) // check we allocated bits succesfully
{
if (!((*ppSurf)->Buffer()))
{
delete *ppSurf;
return E_OUTOFMEMORY;
}
}
return S_OK;
}
SCODE
S3C6410Disp::AllocSurfaceVideo(
DDGPESurf **ppSurf,
int width,
int height,
int stride,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat)
{
// align frame buffer size with 4-word unit
DWORD dwSize = ALIGN(stride * height, 16);
// Try to allocate surface from video memory
SurfaceHeap *pHeap = m_pVideoMemoryHeap->Alloc(dwSize);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?