gfx/skia/trunk/include/core/SkPostConfig.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkPostConfig.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,394 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkPostConfig_DEFINED
    1.12 +#define SkPostConfig_DEFINED
    1.13 +
    1.14 +#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
    1.15 +#  define SK_BUILD_FOR_WIN
    1.16 +#endif
    1.17 +
    1.18 +#if defined(SK_DEBUG) && defined(SK_RELEASE)
    1.19 +#  error "cannot define both SK_DEBUG and SK_RELEASE"
    1.20 +#elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
    1.21 +#  error "must define either SK_DEBUG or SK_RELEASE"
    1.22 +#endif
    1.23 +
    1.24 +#if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG)
    1.25 +#  error "can't have unittests without debug"
    1.26 +#endif
    1.27 +
    1.28 +/**
    1.29 + * Matrix calculations may be float or double.
    1.30 + * The default is double, as that is faster given our impl uses doubles
    1.31 + * for intermediate calculations.
    1.32 + */
    1.33 +#if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
    1.34 +#  error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
    1.35 +#elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
    1.36 +#  define SK_MSCALAR_IS_DOUBLE
    1.37 +#endif
    1.38 +
    1.39 +#if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
    1.40 +#  error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
    1.41 +#elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
    1.42 +#  error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
    1.43 +#endif
    1.44 +
    1.45 +/**
    1.46 + * Ensure the port has defined all of SK_X32_SHIFT, or none of them.
    1.47 + */
    1.48 +#ifdef SK_A32_SHIFT
    1.49 +#  if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
    1.50 +#    error "all or none of the 32bit SHIFT amounts must be defined"
    1.51 +#  endif
    1.52 +#else
    1.53 +#  if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
    1.54 +#    error "all or none of the 32bit SHIFT amounts must be defined"
    1.55 +#  endif
    1.56 +#endif
    1.57 +
    1.58 +#if !defined(SK_HAS_COMPILER_FEATURE)
    1.59 +#  if defined(__has_feature)
    1.60 +#    define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
    1.61 +#  else
    1.62 +#    define SK_HAS_COMPILER_FEATURE(x) 0
    1.63 +#  endif
    1.64 +#endif
    1.65 +
    1.66 +#if !defined(SK_ATTRIBUTE)
    1.67 +#  if defined(__clang__) || defined(__GNUC__)
    1.68 +#    define SK_ATTRIBUTE(attr) __attribute__((attr))
    1.69 +#  else
    1.70 +#    define SK_ATTRIBUTE(attr)
    1.71 +#  endif
    1.72 +#endif
    1.73 +
    1.74 +#if !defined(SK_SUPPORT_GPU)
    1.75 +#  define SK_SUPPORT_GPU 1
    1.76 +#endif
    1.77 +
    1.78 +/**
    1.79 + * The clang static analyzer likes to know that when the program is not
    1.80 + * expected to continue (crash, assertion failure, etc). It will notice that
    1.81 + * some combination of parameters lead to a function call that does not return.
    1.82 + * It can then make appropriate assumptions about the parameters in code
    1.83 + * executed only if the non-returning function was *not* called.
    1.84 + */
    1.85 +#if !defined(SkNO_RETURN_HINT)
    1.86 +#  if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
    1.87 +     static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
    1.88 +     static inline void SkNO_RETURN_HINT() {}
    1.89 +#  else
    1.90 +#    define SkNO_RETURN_HINT() do {} while (false)
    1.91 +#  endif
    1.92 +#endif
    1.93 +
    1.94 +#if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
    1.95 +#  error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
    1.96 +#elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
    1.97 +#  define SK_HAS_ZLIB
    1.98 +#endif
    1.99 +
   1.100 +///////////////////////////////////////////////////////////////////////////////
   1.101 +
   1.102 +#ifndef SkNEW
   1.103 +#  define SkNEW(type_name)                           (new type_name)
   1.104 +#  define SkNEW_ARGS(type_name, args)                (new type_name args)
   1.105 +#  define SkNEW_ARRAY(type_name, count)              (new type_name[(count)])
   1.106 +#  define SkNEW_PLACEMENT(buf, type_name)            (new (buf) type_name)
   1.107 +#  define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args)
   1.108 +#  define SkDELETE(obj)                              (delete (obj))
   1.109 +#  define SkDELETE_ARRAY(array)                      (delete[] (array))
   1.110 +#endif
   1.111 +
   1.112 +#ifndef SK_CRASH
   1.113 +#  if 1   // set to 0 for infinite loop, which can help connecting gdb
   1.114 +#    define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
   1.115 +#  else
   1.116 +#    define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
   1.117 +#  endif
   1.118 +#endif
   1.119 +
   1.120 +///////////////////////////////////////////////////////////////////////////////
   1.121 +
   1.122 +/**
   1.123 + * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects
   1.124 + * are still held on exit.
   1.125 + * Defaults to 1 in DEBUG and 0 in RELEASE.
   1.126 + */
   1.127 +#ifndef SK_ENABLE_INST_COUNT
   1.128 +#  ifdef SK_DEBUG
   1.129 +// Only enabled for static builds, because instance counting relies on static
   1.130 +// variables in functions defined in header files.
   1.131 +#    define SK_ENABLE_INST_COUNT !defined(SKIA_DLL)
   1.132 +#  else
   1.133 +#    define SK_ENABLE_INST_COUNT 0
   1.134 +#  endif
   1.135 +#endif
   1.136 +
   1.137 +///////////////////////////////////////////////////////////////////////////////
   1.138 +
   1.139 +#ifdef SK_BUILD_FOR_WIN
   1.140 +#  ifndef WIN32_LEAN_AND_MEAN
   1.141 +#    define WIN32_LEAN_AND_MEAN
   1.142 +#    define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   1.143 +#  endif
   1.144 +#  ifndef NOMINMAX
   1.145 +#    define NOMINMAX
   1.146 +#    define NOMINMAX_WAS_LOCALLY_DEFINED
   1.147 +#  endif
   1.148 +#
   1.149 +#  include <windows.h>
   1.150 +#
   1.151 +#  ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   1.152 +#    undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   1.153 +#    undef WIN32_LEAN_AND_MEAN
   1.154 +#  endif
   1.155 +#  ifdef NOMINMAX_WAS_LOCALLY_DEFINED
   1.156 +#    undef NOMINMAX_WAS_LOCALLY_DEFINED
   1.157 +#    undef NOMINMAX
   1.158 +#  endif
   1.159 +#
   1.160 +#  ifndef SK_DEBUGBREAK
   1.161 +#    define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
   1.162 +#  endif
   1.163 +#
   1.164 +#  ifndef SK_A32_SHIFT
   1.165 +#    define SK_A32_SHIFT 24
   1.166 +#    define SK_R32_SHIFT 16
   1.167 +#    define SK_G32_SHIFT 8
   1.168 +#    define SK_B32_SHIFT 0
   1.169 +#  endif
   1.170 +#
   1.171 +#else
   1.172 +#  ifdef SK_DEBUG
   1.173 +#    include <stdio.h>
   1.174 +#    ifndef SK_DEBUGBREAK
   1.175 +#      define SK_DEBUGBREAK(cond) do { if (cond) break; \
   1.176 +                SkDebugf("%s:%d: failed assertion \"%s\"\n", \
   1.177 +                __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
   1.178 +#    endif
   1.179 +#  endif
   1.180 +#endif
   1.181 +
   1.182 +/**
   1.183 + *  We check to see if the SHIFT value has already been defined.
   1.184 + *  if not, we define it ourself to some default values. We default to OpenGL
   1.185 + *  order (in memory: r,g,b,a)
   1.186 + */
   1.187 +#ifndef SK_A32_SHIFT
   1.188 +#  ifdef SK_CPU_BENDIAN
   1.189 +#    define SK_R32_SHIFT    24
   1.190 +#    define SK_G32_SHIFT    16
   1.191 +#    define SK_B32_SHIFT    8
   1.192 +#    define SK_A32_SHIFT    0
   1.193 +#  else
   1.194 +#    define SK_R32_SHIFT    0
   1.195 +#    define SK_G32_SHIFT    8
   1.196 +#    define SK_B32_SHIFT    16
   1.197 +#    define SK_A32_SHIFT    24
   1.198 +#  endif
   1.199 +#endif
   1.200 +
   1.201 +/**
   1.202 + * SkColor has well defined shift values, but SkPMColor is configurable. This
   1.203 + * macro is a convenience that returns true if the shift values are equal while
   1.204 + * ignoring the machine's endianness.
   1.205 + */
   1.206 +#define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
   1.207 +    (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
   1.208 +
   1.209 +/**
   1.210 + * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
   1.211 + * relationship between the byte order and shift values depends on machine endianness. If the shift
   1.212 + * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
   1.213 + * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
   1.214 + * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
   1.215 + * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
   1.216 + */
   1.217 +#ifdef SK_CPU_BENDIAN
   1.218 +#  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
   1.219 +        (SK_ ## C3 ## 32_SHIFT == 0  &&             \
   1.220 +         SK_ ## C2 ## 32_SHIFT == 8  &&             \
   1.221 +         SK_ ## C1 ## 32_SHIFT == 16 &&             \
   1.222 +         SK_ ## C0 ## 32_SHIFT == 24)
   1.223 +#else
   1.224 +#  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
   1.225 +        (SK_ ## C0 ## 32_SHIFT == 0  &&             \
   1.226 +         SK_ ## C1 ## 32_SHIFT == 8  &&             \
   1.227 +         SK_ ## C2 ## 32_SHIFT == 16 &&             \
   1.228 +         SK_ ## C3 ## 32_SHIFT == 24)
   1.229 +#endif
   1.230 +
   1.231 +//////////////////////////////////////////////////////////////////////
   1.232 +
   1.233 +// TODO: rebaseline as needed so we can remove this flag entirely.
   1.234 +//  - all platforms have int64_t now
   1.235 +//  - we have slightly different fixed math results because of this check
   1.236 +//    since we don't define this for linux/android
   1.237 +#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
   1.238 +#  ifndef SkLONGLONG
   1.239 +#    define SkLONGLONG int64_t
   1.240 +#  endif
   1.241 +#endif
   1.242 +
   1.243 +//////////////////////////////////////////////////////////////////////////////////////////////
   1.244 +#ifndef SK_BUILD_FOR_WINCE
   1.245 +#  include <string.h>
   1.246 +#  include <stdlib.h>
   1.247 +#else
   1.248 +#  define _CMNINTRIN_DECLARE_ONLY
   1.249 +#  include "cmnintrin.h"
   1.250 +#endif
   1.251 +
   1.252 +#if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
   1.253 +#  ifdef free
   1.254 +#    undef free
   1.255 +#  endif
   1.256 +#  include <crtdbg.h>
   1.257 +#  undef free
   1.258 +#
   1.259 +#  ifdef SK_DEBUGx
   1.260 +#    if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
   1.261 +       void * operator new(
   1.262 +           size_t cb,
   1.263 +           int nBlockUse,
   1.264 +           const char * szFileName,
   1.265 +           int nLine,
   1.266 +           int foo
   1.267 +           );
   1.268 +       void * operator new[](
   1.269 +           size_t cb,
   1.270 +           int nBlockUse,
   1.271 +           const char * szFileName,
   1.272 +           int nLine,
   1.273 +           int foo
   1.274 +           );
   1.275 +       void operator delete(
   1.276 +           void *pUserData,
   1.277 +           int, const char*, int, int
   1.278 +           );
   1.279 +       void operator delete(
   1.280 +           void *pUserData
   1.281 +           );
   1.282 +       void operator delete[]( void * p );
   1.283 +#      define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
   1.284 +#    else
   1.285 +#      define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
   1.286 +#    endif
   1.287 +#    define new DEBUG_CLIENTBLOCK
   1.288 +#  else
   1.289 +#    define DEBUG_CLIENTBLOCK
   1.290 +#  endif
   1.291 +#endif
   1.292 +
   1.293 +//////////////////////////////////////////////////////////////////////
   1.294 +
   1.295 +#ifndef SK_OVERRIDE
   1.296 +#  if defined(_MSC_VER)
   1.297 +#    define SK_OVERRIDE override
   1.298 +#  elif defined(__clang__)
   1.299 +     // Using __attribute__((override)) on clang does not appear to always work.
   1.300 +     // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no
   1.301 +     // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing
   1.302 +     // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma).
   1.303 +#    pragma clang diagnostic ignored "-Wc++11-extensions"
   1.304 +#
   1.305 +#    if __has_feature(cxx_override_control)
   1.306 +#      define SK_OVERRIDE override
   1.307 +#    elif defined(__has_extension) && __has_extension(cxx_override_control)
   1.308 +#      define SK_OVERRIDE override
   1.309 +#    endif
   1.310 +#  endif
   1.311 +#  ifndef SK_OVERRIDE
   1.312 +#    define SK_OVERRIDE
   1.313 +#  endif
   1.314 +#endif
   1.315 +
   1.316 +//////////////////////////////////////////////////////////////////////
   1.317 +
   1.318 +#if !defined(SK_UNUSED)
   1.319 +#  define SK_UNUSED SK_ATTRIBUTE(unused)
   1.320 +#endif
   1.321 +
   1.322 +#if !defined(SK_ATTR_DEPRECATED)
   1.323 +   // FIXME: we ignore msg for now...
   1.324 +#  define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
   1.325 +#endif
   1.326 +
   1.327 +/**
   1.328 + * If your judgment is better than the compiler's (i.e. you've profiled it),
   1.329 + * you can use SK_ALWAYS_INLINE to force inlining. E.g.
   1.330 + *     inline void someMethod() { ... }             // may not be inlined
   1.331 + *     SK_ALWAYS_INLINE void someMethod() { ... }   // should always be inlined
   1.332 + */
   1.333 +#if !defined(SK_ALWAYS_INLINE)
   1.334 +#  if defined(SK_BUILD_FOR_WIN)
   1.335 +#    define SK_ALWAYS_INLINE __forceinline
   1.336 +#  else
   1.337 +#    define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
   1.338 +#  endif
   1.339 +#endif
   1.340 +
   1.341 +//////////////////////////////////////////////////////////////////////
   1.342 +
   1.343 +#if defined(__clang__) || defined(__GNUC__)
   1.344 +#  define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
   1.345 +#  define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
   1.346 +#else
   1.347 +#  define SK_PREFETCH(ptr)
   1.348 +#  define SK_WRITE_PREFETCH(ptr)
   1.349 +#endif
   1.350 +
   1.351 +//////////////////////////////////////////////////////////////////////
   1.352 +
   1.353 +#ifndef SK_PRINTF_LIKE
   1.354 +#  if defined(__clang__) || defined(__GNUC__)
   1.355 +#    define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
   1.356 +#  else
   1.357 +#    define SK_PRINTF_LIKE(A, B)
   1.358 +#  endif
   1.359 +#endif
   1.360 +
   1.361 +//////////////////////////////////////////////////////////////////////
   1.362 +
   1.363 +#ifndef SK_SIZE_T_SPECIFIER
   1.364 +#  if defined(_MSC_VER)
   1.365 +#    define SK_SIZE_T_SPECIFIER "%Iu"
   1.366 +#  else
   1.367 +#    define SK_SIZE_T_SPECIFIER "%zu"
   1.368 +#  endif
   1.369 +#endif
   1.370 +
   1.371 +//////////////////////////////////////////////////////////////////////
   1.372 +
   1.373 +#ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
   1.374 +#  define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
   1.375 +#endif
   1.376 +
   1.377 +//////////////////////////////////////////////////////////////////////
   1.378 +
   1.379 +#ifndef SK_ATOMICS_PLATFORM_H
   1.380 +#  if defined(_MSC_VER)
   1.381 +#    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_win.h"
   1.382 +#  elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
   1.383 +#    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_android.h"
   1.384 +#  else
   1.385 +#    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_sync.h"
   1.386 +#  endif
   1.387 +#endif
   1.388 +
   1.389 +#ifndef SK_MUTEX_PLATFORM_H
   1.390 +#  if defined(SK_BUILD_FOR_WIN)
   1.391 +#    define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_win.h"
   1.392 +#  else
   1.393 +#    define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_pthread.h"
   1.394 +#  endif
   1.395 +#endif
   1.396 +
   1.397 +#endif // SkPostConfig_DEFINED

mercurial