dep_zstd = null_dep
endif
+with_compression = dep_zlib.found() or dep_zstd.found()
+if with_compression
+ pre_args += '-DHAVE_COMPRESSION'
+elif with_shader_cache
+ error('Shader Cache requires compression')
+endif
+
dep_thread = dependency('threads')
if dep_thread.found() and host_machine.system() != 'windows'
pre_args += '-DHAVE_PTHREAD'
* IN THE SOFTWARE.
*/
+#ifdef HAVE_COMPRESSION
+
#include <assert.h>
/* Ensure that zlib uses 'const' in 'z_const' declarations. */
#define ZLIB_CONST
#endif
+#ifdef HAVE_ZLIB
#include "zlib.h"
+#endif
#ifdef HAVE_ZSTD
#include "zstd.h"
#endif
#include "util/compress.h"
+#include "macros.h"
/* 3 is the recomended level, with 22 as the absolute maximum */
#define ZSTD_COMPRESSION_LEVEL 3
* compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
*/
return ZSTD_compressBound(in_data_size);
-#else
+#elif defined(HAVE_ZLIB)
/* From https://zlib.net/zlib_tech.html:
*
* "In the worst possible case, where the other block types would expand
* entire stream."
*/
size_t num_blocks = (in_data_size + 16383) / 16384; /* round up blocks */
- return in_data_size + 6 + (num_blocks * 5);
+ return in_data_size + 6 + (num_blocks * 5);
+#else
+ STATIC_ASSERT(false);
#endif
}
return 0;
return ret;
-#else
+#elif defined(HAVE_ZLIB)
size_t compressed_size = 0;
/* allocate deflate state */
/* clean up and return */
(void) deflateEnd(&strm);
return compressed_size;
+#else
+ STATIC_ASSERT(false);
# endif
}
#ifdef HAVE_ZSTD
size_t ret = ZSTD_decompress(out_data, out_data_size, in_data, in_data_size);
return !ZSTD_isError(ret);
-#else
+#elif defined(HAVE_ZLIB)
z_stream strm;
/* allocate inflate state */
/* clean up and return */
(void)inflateEnd(&strm);
return true;
+#else
+ STATIC_ASSERT(false);
#endif
}
+
+#endif