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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2006 The Android Open Source Project
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     8 #ifndef SkPostConfig_DEFINED
     9 #define SkPostConfig_DEFINED
    11 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
    12 #  define SK_BUILD_FOR_WIN
    13 #endif
    15 #if defined(SK_DEBUG) && defined(SK_RELEASE)
    16 #  error "cannot define both SK_DEBUG and SK_RELEASE"
    17 #elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
    18 #  error "must define either SK_DEBUG or SK_RELEASE"
    19 #endif
    21 #if defined(SK_SUPPORT_UNITTEST) && !defined(SK_DEBUG)
    22 #  error "can't have unittests without debug"
    23 #endif
    25 /**
    26  * Matrix calculations may be float or double.
    27  * The default is double, as that is faster given our impl uses doubles
    28  * for intermediate calculations.
    29  */
    30 #if defined(SK_MSCALAR_IS_DOUBLE) && defined(SK_MSCALAR_IS_FLOAT)
    31 #  error "cannot define both SK_MSCALAR_IS_DOUBLE and SK_MSCALAR_IS_FLOAT"
    32 #elif !defined(SK_MSCALAR_IS_DOUBLE) && !defined(SK_MSCALAR_IS_FLOAT)
    33 #  define SK_MSCALAR_IS_DOUBLE
    34 #endif
    36 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
    37 #  error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
    38 #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
    39 #  error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
    40 #endif
    42 /**
    43  * Ensure the port has defined all of SK_X32_SHIFT, or none of them.
    44  */
    45 #ifdef SK_A32_SHIFT
    46 #  if !defined(SK_R32_SHIFT) || !defined(SK_G32_SHIFT) || !defined(SK_B32_SHIFT)
    47 #    error "all or none of the 32bit SHIFT amounts must be defined"
    48 #  endif
    49 #else
    50 #  if defined(SK_R32_SHIFT) || defined(SK_G32_SHIFT) || defined(SK_B32_SHIFT)
    51 #    error "all or none of the 32bit SHIFT amounts must be defined"
    52 #  endif
    53 #endif
    55 #if !defined(SK_HAS_COMPILER_FEATURE)
    56 #  if defined(__has_feature)
    57 #    define SK_HAS_COMPILER_FEATURE(x) __has_feature(x)
    58 #  else
    59 #    define SK_HAS_COMPILER_FEATURE(x) 0
    60 #  endif
    61 #endif
    63 #if !defined(SK_ATTRIBUTE)
    64 #  if defined(__clang__) || defined(__GNUC__)
    65 #    define SK_ATTRIBUTE(attr) __attribute__((attr))
    66 #  else
    67 #    define SK_ATTRIBUTE(attr)
    68 #  endif
    69 #endif
    71 #if !defined(SK_SUPPORT_GPU)
    72 #  define SK_SUPPORT_GPU 1
    73 #endif
    75 /**
    76  * The clang static analyzer likes to know that when the program is not
    77  * expected to continue (crash, assertion failure, etc). It will notice that
    78  * some combination of parameters lead to a function call that does not return.
    79  * It can then make appropriate assumptions about the parameters in code
    80  * executed only if the non-returning function was *not* called.
    81  */
    82 #if !defined(SkNO_RETURN_HINT)
    83 #  if SK_HAS_COMPILER_FEATURE(attribute_analyzer_noreturn)
    84      static inline void SkNO_RETURN_HINT() __attribute__((analyzer_noreturn));
    85      static inline void SkNO_RETURN_HINT() {}
    86 #  else
    87 #    define SkNO_RETURN_HINT() do {} while (false)
    88 #  endif
    89 #endif
    91 #if defined(SK_ZLIB_INCLUDE) && defined(SK_SYSTEM_ZLIB)
    92 #  error "cannot define both SK_ZLIB_INCLUDE and SK_SYSTEM_ZLIB"
    93 #elif defined(SK_ZLIB_INCLUDE) || defined(SK_SYSTEM_ZLIB)
    94 #  define SK_HAS_ZLIB
    95 #endif
    97 ///////////////////////////////////////////////////////////////////////////////
    99 #ifndef SkNEW
   100 #  define SkNEW(type_name)                           (new type_name)
   101 #  define SkNEW_ARGS(type_name, args)                (new type_name args)
   102 #  define SkNEW_ARRAY(type_name, count)              (new type_name[(count)])
   103 #  define SkNEW_PLACEMENT(buf, type_name)            (new (buf) type_name)
   104 #  define SkNEW_PLACEMENT_ARGS(buf, type_name, args) (new (buf) type_name args)
   105 #  define SkDELETE(obj)                              (delete (obj))
   106 #  define SkDELETE_ARRAY(array)                      (delete[] (array))
   107 #endif
   109 #ifndef SK_CRASH
   110 #  if 1   // set to 0 for infinite loop, which can help connecting gdb
   111 #    define SK_CRASH() do { SkNO_RETURN_HINT(); *(int *)(uintptr_t)0xbbadbeef = 0; } while (false)
   112 #  else
   113 #    define SK_CRASH() do { SkNO_RETURN_HINT(); } while (true)
   114 #  endif
   115 #endif
   117 ///////////////////////////////////////////////////////////////////////////////
   119 /**
   120  * SK_ENABLE_INST_COUNT controlls printing how many reference counted objects
   121  * are still held on exit.
   122  * Defaults to 1 in DEBUG and 0 in RELEASE.
   123  */
   124 #ifndef SK_ENABLE_INST_COUNT
   125 #  ifdef SK_DEBUG
   126 // Only enabled for static builds, because instance counting relies on static
   127 // variables in functions defined in header files.
   128 #    define SK_ENABLE_INST_COUNT !defined(SKIA_DLL)
   129 #  else
   130 #    define SK_ENABLE_INST_COUNT 0
   131 #  endif
   132 #endif
   134 ///////////////////////////////////////////////////////////////////////////////
   136 #ifdef SK_BUILD_FOR_WIN
   137 #  ifndef WIN32_LEAN_AND_MEAN
   138 #    define WIN32_LEAN_AND_MEAN
   139 #    define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   140 #  endif
   141 #  ifndef NOMINMAX
   142 #    define NOMINMAX
   143 #    define NOMINMAX_WAS_LOCALLY_DEFINED
   144 #  endif
   145 #
   146 #  include <windows.h>
   147 #
   148 #  ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   149 #    undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
   150 #    undef WIN32_LEAN_AND_MEAN
   151 #  endif
   152 #  ifdef NOMINMAX_WAS_LOCALLY_DEFINED
   153 #    undef NOMINMAX_WAS_LOCALLY_DEFINED
   154 #    undef NOMINMAX
   155 #  endif
   156 #
   157 #  ifndef SK_DEBUGBREAK
   158 #    define SK_DEBUGBREAK(p) do { if (!(p)) { SkNO_RETURN_HINT(); __debugbreak(); }} while (false)
   159 #  endif
   160 #
   161 #  ifndef SK_A32_SHIFT
   162 #    define SK_A32_SHIFT 24
   163 #    define SK_R32_SHIFT 16
   164 #    define SK_G32_SHIFT 8
   165 #    define SK_B32_SHIFT 0
   166 #  endif
   167 #
   168 #else
   169 #  ifdef SK_DEBUG
   170 #    include <stdio.h>
   171 #    ifndef SK_DEBUGBREAK
   172 #      define SK_DEBUGBREAK(cond) do { if (cond) break; \
   173                 SkDebugf("%s:%d: failed assertion \"%s\"\n", \
   174                 __FILE__, __LINE__, #cond); SK_CRASH(); } while (false)
   175 #    endif
   176 #  endif
   177 #endif
   179 /**
   180  *  We check to see if the SHIFT value has already been defined.
   181  *  if not, we define it ourself to some default values. We default to OpenGL
   182  *  order (in memory: r,g,b,a)
   183  */
   184 #ifndef SK_A32_SHIFT
   185 #  ifdef SK_CPU_BENDIAN
   186 #    define SK_R32_SHIFT    24
   187 #    define SK_G32_SHIFT    16
   188 #    define SK_B32_SHIFT    8
   189 #    define SK_A32_SHIFT    0
   190 #  else
   191 #    define SK_R32_SHIFT    0
   192 #    define SK_G32_SHIFT    8
   193 #    define SK_B32_SHIFT    16
   194 #    define SK_A32_SHIFT    24
   195 #  endif
   196 #endif
   198 /**
   199  * SkColor has well defined shift values, but SkPMColor is configurable. This
   200  * macro is a convenience that returns true if the shift values are equal while
   201  * ignoring the machine's endianness.
   202  */
   203 #define SK_COLOR_MATCHES_PMCOLOR_BYTE_ORDER \
   204     (SK_A32_SHIFT == 24 && SK_R32_SHIFT == 16 && SK_G32_SHIFT == 8 && SK_B32_SHIFT == 0)
   206 /**
   207  * SK_PMCOLOR_BYTE_ORDER can be used to query the byte order of SkPMColor at compile time. The
   208  * relationship between the byte order and shift values depends on machine endianness. If the shift
   209  * order is R=0, G=8, B=16, A=24 then ((char*)&pmcolor)[0] will produce the R channel on a little
   210  * endian machine and the A channel on a big endian machine. Thus, given those shifts values,
   211  * SK_PMCOLOR_BYTE_ORDER(R,G,B,A) will be true on a little endian machine and
   212  * SK_PMCOLOR_BYTE_ORDER(A,B,G,R) will be true on a big endian machine.
   213  */
   214 #ifdef SK_CPU_BENDIAN
   215 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
   216         (SK_ ## C3 ## 32_SHIFT == 0  &&             \
   217          SK_ ## C2 ## 32_SHIFT == 8  &&             \
   218          SK_ ## C1 ## 32_SHIFT == 16 &&             \
   219          SK_ ## C0 ## 32_SHIFT == 24)
   220 #else
   221 #  define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3)     \
   222         (SK_ ## C0 ## 32_SHIFT == 0  &&             \
   223          SK_ ## C1 ## 32_SHIFT == 8  &&             \
   224          SK_ ## C2 ## 32_SHIFT == 16 &&             \
   225          SK_ ## C3 ## 32_SHIFT == 24)
   226 #endif
   228 //////////////////////////////////////////////////////////////////////
   230 // TODO: rebaseline as needed so we can remove this flag entirely.
   231 //  - all platforms have int64_t now
   232 //  - we have slightly different fixed math results because of this check
   233 //    since we don't define this for linux/android
   234 #if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_MAC)
   235 #  ifndef SkLONGLONG
   236 #    define SkLONGLONG int64_t
   237 #  endif
   238 #endif
   240 //////////////////////////////////////////////////////////////////////////////////////////////
   241 #ifndef SK_BUILD_FOR_WINCE
   242 #  include <string.h>
   243 #  include <stdlib.h>
   244 #else
   245 #  define _CMNINTRIN_DECLARE_ONLY
   246 #  include "cmnintrin.h"
   247 #endif
   249 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
   250 #  ifdef free
   251 #    undef free
   252 #  endif
   253 #  include <crtdbg.h>
   254 #  undef free
   255 #
   256 #  ifdef SK_DEBUGx
   257 #    if defined(SK_SIMULATE_FAILED_MALLOC) && defined(__cplusplus)
   258        void * operator new(
   259            size_t cb,
   260            int nBlockUse,
   261            const char * szFileName,
   262            int nLine,
   263            int foo
   264            );
   265        void * operator new[](
   266            size_t cb,
   267            int nBlockUse,
   268            const char * szFileName,
   269            int nLine,
   270            int foo
   271            );
   272        void operator delete(
   273            void *pUserData,
   274            int, const char*, int, int
   275            );
   276        void operator delete(
   277            void *pUserData
   278            );
   279        void operator delete[]( void * p );
   280 #      define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__, 0)
   281 #    else
   282 #      define DEBUG_CLIENTBLOCK   new( _CLIENT_BLOCK, __FILE__, __LINE__)
   283 #    endif
   284 #    define new DEBUG_CLIENTBLOCK
   285 #  else
   286 #    define DEBUG_CLIENTBLOCK
   287 #  endif
   288 #endif
   290 //////////////////////////////////////////////////////////////////////
   292 #ifndef SK_OVERRIDE
   293 #  if defined(_MSC_VER)
   294 #    define SK_OVERRIDE override
   295 #  elif defined(__clang__)
   296      // Using __attribute__((override)) on clang does not appear to always work.
   297      // Clang defaults to C++03 and warns about using override. Squelch that. Intentionally no
   298      // push/pop here so all users of SK_OVERRIDE ignore the warning too. This is like passing
   299      // -Wno-c++11-extensions, except that GCC won't die (because it won't see this pragma).
   300 #    pragma clang diagnostic ignored "-Wc++11-extensions"
   301 #
   302 #    if __has_feature(cxx_override_control)
   303 #      define SK_OVERRIDE override
   304 #    elif defined(__has_extension) && __has_extension(cxx_override_control)
   305 #      define SK_OVERRIDE override
   306 #    endif
   307 #  endif
   308 #  ifndef SK_OVERRIDE
   309 #    define SK_OVERRIDE
   310 #  endif
   311 #endif
   313 //////////////////////////////////////////////////////////////////////
   315 #if !defined(SK_UNUSED)
   316 #  define SK_UNUSED SK_ATTRIBUTE(unused)
   317 #endif
   319 #if !defined(SK_ATTR_DEPRECATED)
   320    // FIXME: we ignore msg for now...
   321 #  define SK_ATTR_DEPRECATED(msg) SK_ATTRIBUTE(deprecated)
   322 #endif
   324 /**
   325  * If your judgment is better than the compiler's (i.e. you've profiled it),
   326  * you can use SK_ALWAYS_INLINE to force inlining. E.g.
   327  *     inline void someMethod() { ... }             // may not be inlined
   328  *     SK_ALWAYS_INLINE void someMethod() { ... }   // should always be inlined
   329  */
   330 #if !defined(SK_ALWAYS_INLINE)
   331 #  if defined(SK_BUILD_FOR_WIN)
   332 #    define SK_ALWAYS_INLINE __forceinline
   333 #  else
   334 #    define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
   335 #  endif
   336 #endif
   338 //////////////////////////////////////////////////////////////////////
   340 #if defined(__clang__) || defined(__GNUC__)
   341 #  define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
   342 #  define SK_WRITE_PREFETCH(ptr) __builtin_prefetch(ptr, 1)
   343 #else
   344 #  define SK_PREFETCH(ptr)
   345 #  define SK_WRITE_PREFETCH(ptr)
   346 #endif
   348 //////////////////////////////////////////////////////////////////////
   350 #ifndef SK_PRINTF_LIKE
   351 #  if defined(__clang__) || defined(__GNUC__)
   352 #    define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
   353 #  else
   354 #    define SK_PRINTF_LIKE(A, B)
   355 #  endif
   356 #endif
   358 //////////////////////////////////////////////////////////////////////
   360 #ifndef SK_SIZE_T_SPECIFIER
   361 #  if defined(_MSC_VER)
   362 #    define SK_SIZE_T_SPECIFIER "%Iu"
   363 #  else
   364 #    define SK_SIZE_T_SPECIFIER "%zu"
   365 #  endif
   366 #endif
   368 //////////////////////////////////////////////////////////////////////
   370 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
   371 #  define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 1
   372 #endif
   374 //////////////////////////////////////////////////////////////////////
   376 #ifndef SK_ATOMICS_PLATFORM_H
   377 #  if defined(_MSC_VER)
   378 #    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_win.h"
   379 #  elif defined(SK_BUILD_FOR_ANDROID_FRAMEWORK)
   380 #    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_android.h"
   381 #  else
   382 #    define SK_ATOMICS_PLATFORM_H "../../src/ports/SkAtomics_sync.h"
   383 #  endif
   384 #endif
   386 #ifndef SK_MUTEX_PLATFORM_H
   387 #  if defined(SK_BUILD_FOR_WIN)
   388 #    define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_win.h"
   389 #  else
   390 #    define SK_MUTEX_PLATFORM_H "../../src/ports/SkMutex_pthread.h"
   391 #  endif
   392 #endif
   394 #endif // SkPostConfig_DEFINED

mercurial