summaryrefslogtreecommitdiffstats
path: root/external/skia/source
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /external/skia/source
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'external/skia/source')
-rw-r--r--external/skia/source/SkMemory_malloc.cxx68
-rw-r--r--external/skia/source/skia_compiler.cxx20
-rw-r--r--external/skia/source/skia_opts.cxx77
-rw-r--r--external/skia/source/skia_opts_internal.hxx81
-rw-r--r--external/skia/source/skia_opts_ssse3.cxx17
5 files changed, 263 insertions, 0 deletions
diff --git a/external/skia/source/SkMemory_malloc.cxx b/external/skia/source/SkMemory_malloc.cxx
new file mode 100644
index 0000000000..d1f0cd3f6b
--- /dev/null
+++ b/external/skia/source/SkMemory_malloc.cxx
@@ -0,0 +1,68 @@
+/*
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "include/core/SkTypes.h"
+#include "include/private/base/SkMalloc.h"
+
+#include <sal/log.hxx>
+#include <rtl/alloc.h>
+
+// Based on SkMemory_malloc.cpp :
+
+static inline void sk_out_of_memory(size_t size)
+{
+ SAL_WARN("skia", "sk_out_of_memory (asked for " << size << " bytes)");
+ abort();
+}
+
+static inline void* throw_on_failure(size_t size, void* p)
+{
+ if (size > 0 && p == nullptr)
+ {
+ // If we've got a nullptr here, the only reason we should have failed is running out of RAM.
+ sk_out_of_memory(size);
+ }
+ return p;
+}
+
+void sk_abort_no_print()
+{
+ SAL_WARN("skia", "sk_abort_no_print");
+ abort();
+}
+
+void sk_out_of_memory(void)
+{
+ SAL_WARN("skia", "sk_out_of_memory");
+ abort();
+}
+
+void* sk_realloc_throw(void* addr, size_t size)
+{
+ return throw_on_failure(size, rtl_reallocateMemory(addr, size));
+}
+
+void sk_free(void* p) { rtl_freeMemory(p); }
+
+void* sk_malloc_flags(size_t size, unsigned flags)
+{
+ void* p;
+ if (flags & SK_MALLOC_ZERO_INITIALIZE)
+ {
+ p = rtl_allocateZeroMemory(size);
+ }
+ else
+ {
+ p = rtl_allocateMemory(size);
+ }
+ if (flags & SK_MALLOC_THROW)
+ {
+ return throw_on_failure(size, p);
+ }
+ else
+ {
+ return p;
+ }
+}
diff --git a/external/skia/source/skia_compiler.cxx b/external/skia/source/skia_compiler.cxx
new file mode 100644
index 0000000000..6339a4a4f9
--- /dev/null
+++ b/external/skia/source/skia_compiler.cxx
@@ -0,0 +1,20 @@
+/*
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <skia_compiler.hxx>
+
+// Get the type of compiler that Skia is compiled with.
+const char* skia_compiler_name()
+{
+#if defined __clang__
+ return "Clang";
+#elif defined __GNUC__
+ return "GCC";
+#elif defined _MSC_VER
+ return "MSVC";
+#else
+ return "?";
+#endif
+}
diff --git a/external/skia/source/skia_opts.cxx b/external/skia/source/skia_opts.cxx
new file mode 100644
index 0000000000..7c2dace6d5
--- /dev/null
+++ b/external/skia/source/skia_opts.cxx
@@ -0,0 +1,77 @@
+/*
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <skia_opts.hxx>
+
+#include "include/private/base/SkOnce.h"
+
+#if defined __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
+#endif
+#include "src/core/SkCpu.h"
+#include "src/core/SkOpts.h"
+#if defined __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
+void SkConvertRGBToRGBA(uint32_t* dest, const uint8_t* src, int count)
+{
+ SkOpts::RGB_to_RGB1(dest, src, count);
+}
+
+void SkConvertGrayToRGBA(uint32_t* dest, const uint8_t* src, int count)
+{
+ SkOpts::gray_to_RGB1(dest, src, count);
+}
+
+void SkConvertRGBAToRGB(uint8_t* dest, const uint32_t* src, int count)
+{
+ SkLoOpts::RGB1_to_RGB(dest, src, count);
+}
+
+void SkConvertRGBAToR(uint8_t* dest, const uint32_t* src, int count)
+{
+ SkLoOpts::RGB1_to_R(dest, src, count);
+}
+
+// The rest is mostly based on Skia's SkOpts.cpp, reduced to only SSSE3 so far.
+
+#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+ #define SK_OPTS_NS ssse3
+#else
+ #define SK_OPTS_NS portable
+#endif
+
+#include "skia_opts_internal.hxx"
+
+namespace SkLoOpts {
+ // Define default function pointer values here...
+ // If our global compile options are set high enough, these defaults might even be
+ // CPU-specialized, e.g. a typical x86-64 machine might start with SSE2 defaults.
+ // They'll still get a chance to be replaced with even better ones, e.g. using SSE4.1.
+#define DEFINE_DEFAULT(name) decltype(name) name = SK_OPTS_NS::name
+ DEFINE_DEFAULT(RGB1_to_RGB);
+ DEFINE_DEFAULT(RGB1_to_R);
+#undef DEFINE_DEFAULT
+
+ // Each Init_foo() is defined in its own file.
+ void Init_ssse3();
+
+ static void init() {
+#if !defined(SK_BUILD_NO_OPTS)
+ #if defined(SK_CPU_X86)
+ #if SK_CPU_SSE_LEVEL < SK_CPU_SSE_LEVEL_SSSE3
+ if (SkCpu::Supports(SkCpu::SSSE3)) { Init_ssse3(); }
+ #endif
+ #endif
+#endif
+ }
+
+ void Init() {
+ static SkOnce once;
+ once(init);
+ }
+} // namespace SkLoOpts
diff --git a/external/skia/source/skia_opts_internal.hxx b/external/skia/source/skia_opts_internal.hxx
new file mode 100644
index 0000000000..0ca6a04351
--- /dev/null
+++ b/external/skia/source/skia_opts_internal.hxx
@@ -0,0 +1,81 @@
+/*
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SKIA_OPTS_INTERNAL_H
+#define SKIA_OPTS_INTERNAL_H
+
+#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+ #include <immintrin.h>
+#endif
+
+namespace SK_OPTS_NS {
+
+static void RGB1_to_RGB_portable(uint8_t dst[], const uint32_t* src, int count) {
+ for (int i = 0; i < count; i++) {
+ dst[0] = src[i] >> 0;
+ dst[1] = src[i] >> 8;
+ dst[2] = src[i] >> 16;
+ dst += 3;
+ }
+}
+static void RGB1_to_R_portable(uint8_t dst[], const uint32_t* src, int count) {
+ for (int i = 0; i < count; i++) {
+ dst[i] = src[i] & 0xFF;
+ }
+}
+
+#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+inline void RGB1_to_RGB(uint8_t dst[], const uint32_t* src, int count) {
+ const uint8_t X = 0xFF; // Used a placeholder. The value of X is irrelevant.
+ __m128i pack = _mm_setr_epi8(0,1,2, 4,5,6, 8,9,10, 12,13,14, X,X,X,X);
+
+// Storing 4 pixels should store 12 bytes, but here it stores 16, so test count >= 6
+// in order to not overrun the output buffer.
+ while (count >= 6) {
+ __m128i rgba = _mm_loadu_si128((const __m128i*) src);
+
+ __m128i rgb = _mm_shuffle_epi8(rgba, pack);
+
+ // Store 4 pixels.
+ _mm_storeu_si128((__m128i*) dst, rgb);
+
+ src += 4;
+ dst += 4*3;
+ count -= 4;
+ }
+ RGB1_to_RGB_portable(dst, src, count);
+}
+
+inline void RGB1_to_R(uint8_t dst[], const uint32_t* src, int count) {
+ const uint8_t X = 0xFF; // Used a placeholder. The value of X is irrelevant.
+ __m128i pack = _mm_setr_epi8(0,4,8,12, X,X,X,X,X,X,X,X,X,X,X,X);
+
+ while (count >= 4) {
+ __m128i rgba = _mm_loadu_si128((const __m128i*) src);
+
+ __m128i rgb = _mm_shuffle_epi8(rgba, pack);
+
+ // Store 4 pixels.
+ *((uint32_t*)dst) = _mm_cvtsi128_si32(rgb);
+
+ src += 4;
+ dst += 4;
+ count -= 4;
+ }
+ RGB1_to_R_portable(dst, src, count);
+}
+
+#else
+inline void RGB1_to_RGB(uint8_t dst[], const uint32_t* src, int count) {
+ RGB1_to_RGB_portable(dst, src, count);
+}
+inline void RGB1_to_R(uint8_t dst[], const uint32_t* src, int count) {
+ RGB1_to_R_portable(dst, src, count);
+}
+#endif
+
+} // namespace
+
+#endif
diff --git a/external/skia/source/skia_opts_ssse3.cxx b/external/skia/source/skia_opts_ssse3.cxx
new file mode 100644
index 0000000000..31a446c99a
--- /dev/null
+++ b/external/skia/source/skia_opts_ssse3.cxx
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <skia_opts.hxx>
+#define SK_OPTS_NS ssse3
+#include "skia_opts_internal.hxx"
+
+namespace SkLoOpts {
+ void Init_ssse3() {
+ RGB1_to_RGB = ssse3::RGB1_to_RGB;
+ RGB1_to_R = ssse3::RGB1_to_R;
+ }
+}