SkPostConfig.h revision 8a1c16ff38322f0210116fa7293eb8817c7e477e
1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef SkPostConfig_DEFINED 18#define SkPostConfig_DEFINED 19 20#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE) 21 #define SK_BUILD_FOR_WIN 22#endif 23 24#if defined(SK_DEBUG) && defined(SK_RELEASE) 25 #error "cannot define both SK_DEBUG and SK_RELEASE" 26#elif !defined(SK_DEBUG) && !defined(SK_RELEASE) 27 #error "must define either SK_DEBUG or SK_RELEASE" 28#endif 29 30#if defined SK_SUPPORT_UNITTEST && !defined(SK_DEBUG) 31 #error "can't have unittests without debug" 32#endif 33 34#if defined(SK_SCALAR_IS_FIXED) && defined(SK_SCALAR_IS_FLOAT) 35 #error "cannot define both SK_SCALAR_IS_FIXED and SK_SCALAR_IS_FLOAT" 36#elif !defined(SK_SCALAR_IS_FIXED) && !defined(SK_SCALAR_IS_FLOAT) 37 #ifdef SK_CAN_USE_FLOAT 38 #define SK_SCALAR_IS_FLOAT 39 #else 40 #define SK_SCALAR_IS_FIXED 41 #endif 42#endif 43 44#if defined(SK_SCALAR_IS_FLOAT) && !defined(SK_CAN_USE_FLOAT) 45 #define SK_CAN_USE_FLOAT 46 // we do nothing in the else case: fixed-scalars can have floats or not 47#endif 48 49#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN) 50 #error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN" 51#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN) 52 #error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN" 53#endif 54 55// ensure the port has defined all of these, or none of them 56#ifdef SK_A32_SHIFT 57 #if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT) 58 #error "all or none of the 32bit SHIFT amounts must be defined" 59 #endif 60#else 61 #if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT) 62 #error "all or none of the 32bit SHIFT amounts must be defined" 63 #endif 64#endif 65 66/////////////////////////////////////////////////////////////////////////////// 67 68#ifndef SkNEW 69 #define SkNEW(type_name) new type_name 70 #define SkNEW_ARGS(type_name, args) new type_name args 71 #define SkNEW_ARRAY(type_name, count) new type_name[count] 72 #define SkDELETE(obj) delete obj 73 #define SkDELETE_ARRAY(array) delete[] array 74#endif 75 76#ifndef SK_CRASH 77#if 1 // set to 0 for infinite loop, which can help connecting gdb 78 #define SK_CRASH() *(int *)(uintptr_t)0xbbadbeef = 0 79#else 80 #define SK_CRASH() do {} while (true) 81#endif 82#endif 83 84/////////////////////////////////////////////////////////////////////////////// 85 86#if defined(SK_SOFTWARE_FLOAT) && defined(SK_SCALAR_IS_FLOAT) 87 // if this is defined, we convert floats to 2scompliment ints for compares 88 #ifndef SK_SCALAR_SLOW_COMPARES 89 #define SK_SCALAR_SLOW_COMPARES 90 #endif 91#endif 92 93#ifdef SK_BUILD_FOR_WIN 94 #define WIN32_LEAN_AND_MEAN 95 #include <windows.h> 96 #undef WIN32_LEAN_AND_MEAN 97 98 #ifndef SK_DEBUGBREAK 99 #define SK_DEBUGBREAK(cond) do { if (!(cond)) DebugBreak(); } while (false) 100 #endif 101 102 #ifdef SK_BUILD_FOR_WIN32 103 #define strcasecmp(a, b) stricmp(a, b) 104 #define strncasecmp(a, b, c) strnicmp(a, b, c) 105 #elif defined(SK_BUILD_FOR_WINCE) 106 #define strcasecmp(a, b) _stricmp(a, b) 107 #define strncasecmp(a, b, c) _strnicmp(a, b, c) 108 #endif 109#elif defined(SK_BUILD_FOR_MAC) 110 #ifndef SK_DEBUGBREAK 111 #define SK_DEBUGBREAK(cond) do { if (!(cond)) SK_CRASH(); } while (false) 112 #endif 113#else 114 #ifdef SK_DEBUG 115 #include <stdio.h> 116 #ifndef SK_DEBUGBREAK 117 #define SK_DEBUGBREAK(cond) do { if (cond) break; \ 118 SkDebugf("%s:%d: failed assertion \"%s\"\n", \ 119 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false) 120 #endif 121 #endif 122#endif 123 124// stdlib macros 125 126#if 0 127#if !defined(strlen) && defined(SK_DEBUG) 128 extern size_t sk_strlen(const char*); 129 #define strlen(s) sk_strlen(s) 130#endif 131#ifndef sk_strcpy 132 #define sk_strcpy(dst, src) strcpy(dst, src) 133#endif 134#ifndef sk_strchr 135 #define sk_strchr(s, c) strchr(s, c) 136#endif 137#ifndef sk_strrchr 138 #define sk_strrchr(s, c) strrchr(s, c) 139#endif 140#ifndef sk_strcmp 141 #define sk_strcmp(s, t) strcmp(s, t) 142#endif 143#ifndef sk_strncmp 144 #define sk_strncmp(s, t, n) strncmp(s, t, n) 145#endif 146#ifndef sk_memcpy 147 #define sk_memcpy(dst, src, n) memcpy(dst, src, n) 148#endif 149#ifndef memmove 150 #define memmove(dst, src, n) memmove(dst, src, n) 151#endif 152#ifndef sk_memset 153 #define sk_memset(dst, val, n) memset(dst, val, n) 154#endif 155#ifndef sk_memcmp 156 #define sk_memcmp(s, t, n) memcmp(s, t, n) 157#endif 158 159#define sk_strequal(s, t) (!sk_strcmp(s, t)) 160#define sk_strnequal(s, t, n) (!sk_strncmp(s, t, n)) 161#endif 162 163////////////////////////////////////////////////////////////////////////////////////////////// 164#ifndef SK_BUILD_FOR_WINCE 165#include <string.h> 166#include <stdlib.h> 167#else 168#define _CMNINTRIN_DECLARE_ONLY 169#include "cmnintrin.h" 170#endif 171 172#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32 173//#define _CRTDBG_MAP_ALLOC 174#ifdef free 175#undef free 176#endif 177#include <crtdbg.h> 178#undef free 179 180#ifdef SK_DEBUGx 181#if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus) 182 void * operator new( 183 size_t cb, 184 int nBlockUse, 185 const char * szFileName, 186 int nLine, 187 int foo 188 ); 189 void * operator new[]( 190 size_t cb, 191 int nBlockUse, 192 const char * szFileName, 193 int nLine, 194 int foo 195 ); 196 void operator delete( 197 void *pUserData, 198 int, const char*, int, int 199 ); 200 void operator delete( 201 void *pUserData 202 ); 203 void operator delete[]( void * p ); 204 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__, 0) 205#else 206 #define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__) 207#endif 208 #define new DEBUG_CLIENTBLOCK 209#else 210#define DEBUG_CLIENTBLOCK 211#endif // _DEBUG 212 213#endif 214 215#endif 216 217