Browse Source

use HAVE_* macros for dependencies

pull/114/head
nillerusr 2 years ago
parent
commit
c909de8faf
  1. 35
      common/imageutils.cpp
  2. 3
      engine/audio/private/voice_record_openal.cpp
  3. 2
      engine/downloadthread.cpp
  4. 4
      engine/sv_log.cpp
  5. 6
      engine/sys_getmodes.cpp
  6. 10
      game/client/vgui_fpspanel.cpp
  7. 8
      launcher/android/main.cpp
  8. 37
      vgui2/vgui_surfacelib/linuxfont.cpp

35
common/imageutils.cpp

@ -93,6 +93,8 @@ extern void longjmp( jmp_buf, int ) __attribute__((noreturn));
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: // Purpose:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if HAVE_JPEG
struct ValveJpegErrorHandler_t struct ValveJpegErrorHandler_t
{ {
// The default manager // The default manager
@ -129,12 +131,12 @@ static void ValveJpegErrorHandler( j_common_ptr cinfo )
// Bail // Bail
longjmp( pError->m_ErrorContext, 1 ); longjmp( pError->m_ErrorContext, 1 );
} }
#endif
// convert the JPEG file given to a TGA file at the given output path. // convert the JPEG file given to a TGA file at the given output path.
ConversionErrorType ImgUtl_ConvertJPEGToTGA( const char *jpegpath, const char *tgaPath, bool bRequirePowerOfTwo ) ConversionErrorType ImgUtl_ConvertJPEGToTGA( const char *jpegpath, const char *tgaPath, bool bRequirePowerOfTwo )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_JPEG
// //
// !FIXME! This really probably should use ImgUtl_ReadJPEGAsRGBA, to avoid duplicated code. // !FIXME! This really probably should use ImgUtl_ReadJPEGAsRGBA, to avoid duplicated code.
@ -485,7 +487,7 @@ unsigned char * ImgUtl_ReadTGAAsRGBA(const char *tgaPath, int &width, int &heigh
unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &height, ConversionErrorType &errcode ) unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &height, ConversionErrorType &errcode )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_JPEG
struct jpeg_decompress_struct jpegInfo; struct jpeg_decompress_struct jpegInfo;
struct ValveJpegErrorHandler_t jerr; struct ValveJpegErrorHandler_t jerr;
JSAMPROW row_pointer[1]; JSAMPROW row_pointer[1];
@ -636,6 +638,7 @@ unsigned char *ImgUtl_ReadJPEGAsRGBA( const char *jpegPath, int &width, int &hei
#endif #endif
} }
#if HAVE_PNG
static void ReadPNGData( png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead ) static void ReadPNGData( png_structp png_ptr, png_bytep outBytes, png_size_t byteCountToRead )
{ {
@ -654,11 +657,11 @@ static void ReadPNGData( png_structp png_ptr, png_bytep outBytes, png_size_t byt
// Read the bytes // Read the bytes
pBuf->Get( outBytes, byteCountToRead ); pBuf->Get( outBytes, byteCountToRead );
} }
#endif
unsigned char *ImgUtl_ReadPNGAsRGBA( const char *pngPath, int &width, int &height, ConversionErrorType &errcode ) unsigned char *ImgUtl_ReadPNGAsRGBA( const char *pngPath, int &width, int &height, ConversionErrorType &errcode )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_PNG
// Just load the whole file into a memory buffer // Just load the whole file into a memory buffer
CUtlBuffer bufFileContents; CUtlBuffer bufFileContents;
@ -679,7 +682,7 @@ unsigned char *ImgUtl_ReadPNGAsRGBA( const char *pngPath, int &width, int &heigh
unsigned char *ImgUtl_ReadPNGAsRGBAFromBuffer( CUtlBuffer &buffer, int &width, int &height, ConversionErrorType &errcode ) unsigned char *ImgUtl_ReadPNGAsRGBAFromBuffer( CUtlBuffer &buffer, int &width, int &height, ConversionErrorType &errcode )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_PNG
png_const_bytep pngData = (png_const_bytep)buffer.Base(); png_const_bytep pngData = (png_const_bytep)buffer.Base();
if (png_sig_cmp( pngData, 0, 8)) if (png_sig_cmp( pngData, 0, 8))
@ -1844,6 +1847,7 @@ static void FlushPNGData( png_structp png_ptr )
// We're writing to a memory buffer, it's a NOP // We're writing to a memory buffer, it's a NOP
} }
#if HAVE_PNG
ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride ) ConversionErrorType ImgUtl_WriteRGBAAsPNGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride )
{ {
#if !defined( _X360 ) #if !defined( _X360 )
@ -1927,11 +1931,13 @@ fail:
return CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED; return CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED;
#endif #endif
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Initialize destination --- called by jpeg_start_compress // Purpose: Initialize destination --- called by jpeg_start_compress
// before any data is actually written. // before any data is actually written.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if HAVE_JPEG
METHODDEF(void) init_destination (j_compress_ptr cinfo) METHODDEF(void) init_destination (j_compress_ptr cinfo)
{ {
JPEGDestinationManager_t *dest = ( JPEGDestinationManager_t *) cinfo->dest; JPEGDestinationManager_t *dest = ( JPEGDestinationManager_t *) cinfo->dest;
@ -2012,12 +2018,14 @@ GLOBAL(void) jpeg_UtlBuffer_dest (j_compress_ptr cinfo, CUtlBuffer *pBuffer )
dest->pub.term_destination = term_destination; dest->pub.term_destination = term_destination;
dest->pBuffer = pBuffer; dest->pBuffer = pBuffer;
} }
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Write three channel RGB data to a JPEG file // Purpose: Write three channel RGB data to a JPEG file
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool ImgUtl_WriteRGBToJPEG( unsigned char *pSrcBuf, unsigned int nSrcWidth, unsigned int nSrcHeight, const char *lpszFilename ) bool ImgUtl_WriteRGBToJPEG( unsigned char *pSrcBuf, unsigned int nSrcWidth, unsigned int nSrcHeight, const char *lpszFilename )
{ {
#if HAVE_JPEG
CUtlBuffer dstBuf; CUtlBuffer dstBuf;
JSAMPROW row_pointer[1]; // pointer to JSAMPLE row[s] JSAMPROW row_pointer[1]; // pointer to JSAMPLE row[s]
@ -2067,13 +2075,16 @@ bool ImgUtl_WriteRGBToJPEG( unsigned char *pSrcBuf, unsigned int nSrcWidth, unsi
// Cleanup // Cleanup
jpeg_destroy_compress(&cinfo); jpeg_destroy_compress(&cinfo);
return CE_SUCCESS; return CE_SUCCESS;
#else
return CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED;
#endif
} }
ConversionErrorType ImgUtl_WriteRGBAAsJPEGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride ) ConversionErrorType ImgUtl_WriteRGBAAsJPEGToBuffer( const unsigned char *pRGBAData, int nWidth, int nHeight, CUtlBuffer &bufOutData, int nStride )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_JPEG
JSAMPROW row_pointer[1]; // pointer to JSAMPLE row[s] JSAMPROW row_pointer[1]; // pointer to JSAMPLE row[s]
int row_stride; // physical row width in image buffer int row_stride; // physical row width in image buffer
@ -2214,6 +2225,7 @@ ConversionErrorType ImgUtl_SaveBitmapToBuffer( CUtlBuffer &fileData, const Bitma
ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap ) ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap_t &bitmap )
{ {
#if HAVE_PNG
bitmap.Clear(); bitmap.Clear();
ConversionErrorType nErrorCode; ConversionErrorType nErrorCode;
int width, height; int width, height;
@ -2226,10 +2238,14 @@ ConversionErrorType ImgUtl_LoadPNGBitmapFromBuffer( CUtlBuffer &fileData, Bitmap
// Install the buffer into the bitmap, and transfer ownership // Install the buffer into the bitmap, and transfer ownership
bitmap.SetBuffer( width, height, IMAGE_FORMAT_RGBA8888, buffer, true, width*4 ); bitmap.SetBuffer( width, height, IMAGE_FORMAT_RGBA8888, buffer, true, width*4 );
return CE_SUCCESS; return CE_SUCCESS;
#else
return CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED;
#endif
} }
ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap ) ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bitmap_t &bitmap )
{ {
#if HAVE_PNG
if ( !bitmap.IsValid() ) if ( !bitmap.IsValid() )
{ {
Assert( bitmap.IsValid() ); Assert( bitmap.IsValid() );
@ -2252,6 +2268,9 @@ ConversionErrorType ImgUtl_SavePNGBitmapToBuffer( CUtlBuffer &fileData, const Bi
bitmap.Stride() bitmap.Stride()
); );
return result; return result;
#else
return CE_SOURCE_FILE_FORMAT_NOT_SUPPORTED;
#endif
} }
ConversionErrorType ImgUtl_ResizeBitmap( Bitmap_t &destBitmap, int nWidth, int nHeight, const Bitmap_t *pImgSource ) ConversionErrorType ImgUtl_ResizeBitmap( Bitmap_t &destBitmap, int nWidth, int nHeight, const Bitmap_t *pImgSource )

3
engine/audio/private/voice_record_openal.cpp

@ -7,6 +7,7 @@
//=============================================================================// //=============================================================================//
// This module implements the voice record and compression functions // This module implements the voice record and compression functions
#if HAVE_OPENAL
//#include "audio_pch.h" //#include "audio_pch.h"
//#include "voice.h" //#include "voice.h"
#include "tier0/platform.h" #include "tier0/platform.h"
@ -207,3 +208,5 @@ IVoiceRecord* CreateVoiceRecord_OpenAL(int sampleRate)
} }
} }
#endif #endif
#endif

2
engine/downloadthread.cpp

@ -522,7 +522,7 @@ DWORD __stdcall DownloadThread( void *voidPtr )
} }
#elif defined( POSIX ) #elif defined( POSIX ) && HAVE_CURL
#include "curl/curl.h" #include "curl/curl.h"

4
engine/sv_log.cpp

@ -713,6 +713,7 @@ static bool CreateTempFilename( TempFilename_t &info, const char *filenameBase,
// Gzip Filename to Filename.gz. // Gzip Filename to Filename.gz.
static bool gzip_file_compress( const CUtlString &Filename ) static bool gzip_file_compress( const CUtlString &Filename )
{ {
#if HAVE_ZLIB
bool bRet = false; bool bRet = false;
// Try to find a unique temp filename. // Try to find a unique temp filename.
@ -758,6 +759,9 @@ static bool gzip_file_compress( const CUtlString &Filename )
} }
return bRet; return bRet;
#else
return false;
#endif
} }
static void FixupInvalidPathChars( char *filename ) static void FixupInvalidPathChars( char *filename )

6
engine/sys_getmodes.cpp

@ -1932,7 +1932,9 @@ static void VID_ProcessMovieFrame( const MovieInfo_t& info, bool jpeg, const cha
bool bSuccess = false; bool bSuccess = false;
if ( jpeg ) if ( jpeg )
{ {
#if HAVE_JPEG
bSuccess = videomode->TakeSnapshotJPEGToBuffer( outBuf, info.jpeg_quality ); bSuccess = videomode->TakeSnapshotJPEGToBuffer( outBuf, info.jpeg_quality );
#endif
} }
else else
{ {
@ -2001,6 +2003,7 @@ void CVideoMode_Common::WriteMovieFrame( const MovieInfo_t& info )
delete[] hp; delete[] hp;
} }
#if HAVE_JPEG
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Purpose: Expanded data destination object for CUtlBuffer output // Purpose: Expanded data destination object for CUtlBuffer output
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -2099,10 +2102,11 @@ GLOBAL(void) jpeg_UtlBuffer_dest (j_compress_ptr cinfo, CUtlBuffer *pBuffer )
dest->pub.term_destination = term_destination; dest->pub.term_destination = term_destination;
dest->pBuffer = pBuffer; dest->pBuffer = pBuffer;
} }
#endif
bool CVideoMode_Common::TakeSnapshotJPEGToBuffer( CUtlBuffer& buf, int quality ) bool CVideoMode_Common::TakeSnapshotJPEGToBuffer( CUtlBuffer& buf, int quality )
{ {
#if !defined( _X360 ) #if !defined( _X360 ) && HAVE_JPEG
if ( g_LostVideoMemory ) if ( g_LostVideoMemory )
return false; return false;

10
game/client/vgui_fpspanel.cpp

@ -310,12 +310,18 @@ void CFPSPanel::Paint()
vel = player->GetLocalVelocity(); vel = player->GetLocalVelocity();
} }
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + i * ( vgui::surface()->GetFontTall( m_hFont ) + 2 ), if( nShowPosMode > 1 )
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + i * ( vgui::surface()->GetFontTall( m_hFont ) + 2 ),
255, 255, 255, 255,
"vel: %.2f %.2f %.2f",
vel.x, vel.y, vel.z );
else
g_pMatSystemSurface->DrawColoredText( m_hFont, x, 2 + i * ( vgui::surface()->GetFontTall( m_hFont ) + 2 ),
255, 255, 255, 255, 255, 255, 255, 255,
"vel: %.2f", "vel: %.2f",
vel.Length() ); vel.Length() );
} }
if ( cl_showbattery.GetInt() > 0 ) if ( cl_showbattery.GetInt() > 0 )
{ {
if ( steamapicontext && steamapicontext->SteamUtils() && if ( steamapicontext && steamapicontext->SteamUtils() &&

8
launcher/android/main.cpp

@ -31,18 +31,18 @@ int iLastArgs = 0;
DLL_EXPORT int LauncherMain( int argc, char **argv ); // from launcher.cpp DLL_EXPORT int LauncherMain( int argc, char **argv ); // from launcher.cpp
extern void InitCrashHandler(); extern void InitCrashHandler();
JNIEXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over) DLL_EXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over)
{ {
Msg( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) ); Msg( "Java_com_valvesoftware_ValveActivity2_setenv %s=%s", jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL) );
return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over ); return setenv( jenv->GetStringUTFChars(env, NULL), jenv->GetStringUTFChars(value, NULL), over );
} }
JNIEXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult() DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_nativeOnActivityResult()
{ {
Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" ); Msg( "Java_com_valvesoftware_ValveActivity_nativeOnActivityResult" );
} }
JNIEXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str) DLL_EXPORT void Java_com_valvesoftware_ValveActivity2_setArgs(JNIEnv *env, jclass *clazz, jstring str)
{ {
strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args ); strncpy( java_args, env->GetStringUTFChars(str, NULL), sizeof java_args );
} }
@ -77,7 +77,7 @@ void SetLauncherArgs()
#undef D #undef D
} }
JNIEXPORT int LauncherMainAndroid( int argc, char **argv ) DLL_EXPORT int LauncherMainAndroid( int argc, char **argv )
{ {
SDL_version ver; SDL_version ver;
SDL_GetVersion( &ver ); SDL_GetVersion( &ver );

37
vgui2/vgui_surfacelib/linuxfont.cpp

@ -96,7 +96,7 @@ void CLinuxFont::CreateFontList()
if ( m_FriendlyNameCache.Count() > 0 ) if ( m_FriendlyNameCache.Count() > 0 )
return; return;
#ifndef ANDROID #if HAVE_FC
if(!FcInit()) if(!FcInit())
return; return;
FcConfig *config; FcConfig *config;
@ -169,7 +169,7 @@ void CLinuxFont::CreateFontList()
#endif #endif
} }
#ifndef ANDROID #if HAVE_FC
static FcPattern* FontMatch(const char* type, ...) static FcPattern* FontMatch(const char* type, ...)
{ {
FcValue fcvalue; FcValue fcvalue;
@ -405,19 +405,40 @@ bool CLinuxFont::CreateFromMemory(const char *windowsFontName, void *data, int d
return true; return true;
} }
#ifdef ANDROID #if !HAVE_FC
char *FindFontAndroid(const char *winFontName, bool bBold, int italic) char *TryFindFont(const char *winFontName, bool bBold, int italic)
{ {
static char fontFile[MAX_PATH]; static char fontFile[MAX_PATH];
const char *fontName; const char *fontName, *fontNamePost;
#ifdef ANDROID
if( strcmp( winFontName, "Courier New") == 0 ) if( strcmp( winFontName, "Courier New") == 0 )
fontName = "LiberationMono-Regular.ttf"; fontName = "LiberationMono-Regular.ttf";
else else
fontName = "DroidSansFallback.ttf"; // for chinese/japanese/korean fontName = "DroidSansFallback.ttf"; // for chinese/japanese/korean
snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName); snprintf( fontFile, sizeof fontFile, "%s/files/%s", getenv("APP_DATA_PATH"), fontName);
#else
// "platform/resource/linux_fonts/";
if( strcmp( winFontName, "Courier New") == 0 )
fontName = "liberationmono";
if( bBold )
{
if( italic )
fontNamePost = "boldoblique";
else
fontNamePost = "bold";
}
else if( italic )
fontNamePost = "oblique";
else
fontNamePost = "regular";
snprintf(fontFile, sizeof fontFile, "platform/resource/linux_fonts/%s-%s.ttf", fontName, fontNamePost);
#endif
return fontFile; return fontFile;
#if 0 // Old detect #if 0 // Old detect
@ -480,9 +501,9 @@ char *CLinuxFont::GetFontFileName( const char *windowsFontName, int flags )
const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN; const int italic = ( flags & vgui::ISurface::FONTFLAG_ITALIC ) ? FC_SLANT_ITALIC : FC_SLANT_ROMAN;
#ifdef ANDROID #if !HAVE_FC
char *filename = FindFontAndroid( windowsFontName, bBold, italic ); char *filename = TryFindFont( windowsFontName, bBold, italic );
Msg("Android font: %s\n", filename); Msg("Found font: %s\n", filename);
if( !filename ) return NULL; if( !filename ) return NULL;
return strdup( filename ); return strdup( filename );
#else #else

Loading…
Cancel
Save