diff --git a/third_party/skia/include/core/SkTypes.h b/third_party/skia/include/core/SkTypes.h index a1026ca8ce0..41ca65ca671 100644 --- a/third_party/skia/include/core/SkTypes.h +++ b/third_party/skia/include/core/SkTypes.h @@ -8,6 +8,10 @@ #ifndef SkTypes_DEFINED #define SkTypes_DEFINED +#if defined(STARBOARD) +#include "base/logging.h" +#endif + /** \file SkTypes.h */ @@ -278,8 +282,8 @@ # endif # define SK_ABORT(message, ...) \ do { \ - SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \ - __FILE__, __LINE__, ##__VA_ARGS__); \ + SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"%s\"\n", \ + __FILE__, __LINE__, ##__VA_ARGS__); \ SK_DUMP_GOOGLE3_STACK(); \ sk_abort_no_print(); \ } while (false) @@ -341,6 +345,7 @@ inline SkPmcolor GetSkPmcolor() { } #endif +#if !defined(STARBOARD) #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN #ifdef free #undef free @@ -348,6 +353,7 @@ inline SkPmcolor GetSkPmcolor() { #include #undef free #endif +#endif #if !defined(SK_UNUSED) # if !defined(__clang__) && defined(_MSC_VER) diff --git a/third_party/skia/src/core/SkExecutor.cpp b/third_party/skia/src/core/SkExecutor.cpp index 2f561df17c3..b4c987fa8cf 100644 --- a/third_party/skia/src/core/SkExecutor.cpp +++ b/third_party/skia/src/core/SkExecutor.cpp @@ -13,6 +13,32 @@ #include #include +#if defined(STARBOARD) +#include "starboard/thread.h" +#endif + +namespace { + +#if defined(STARBOARD) +// Starboardize std::thread as thread creation is undefined for stub builds. +class SkThread { +public: + SkThread(SbThreadEntryPoint entry_point, void* context) { + SbThreadCreate(0, // default stack_size. + kSbThreadNoPriority, // default priority. + kSbThreadNoAffinity, // default affinity. + true, // joinable. + "SkThread", entry_point, this); + } + + bool join() { return SbThreadJoin((SbThread)this, NULL); } +}; +#else +typedef std::thread SkThread; +#endif + +} // namespace + #if defined(STARBOARD) #include "starboard/system.h" static int num_cores() { @@ -129,17 +155,18 @@ class SkThreadPool final : public SkExecutor { return true; } - static void Loop(void* ctx) { + static void* Loop(void* ctx) { auto pool = (SkThreadPool*)ctx; do { pool->fWorkAvailable.wait(); } while (pool->do_work()); + return nullptr; } // Both SkMutex and SkSpinlock can work here. using Lock = SkMutex; - SkTArray fThreads; + SkTArray fThreads; WorkList fWork; Lock fWorkLock; SkSemaphore fWorkAvailable; diff --git a/third_party/skia/src/core/SkSemaphore.cpp b/third_party/skia/src/core/SkSemaphore.cpp index 692cbfc15c1..4a860a44896 100644 --- a/third_party/skia/src/core/SkSemaphore.cpp +++ b/third_party/skia/src/core/SkSemaphore.cpp @@ -8,7 +8,18 @@ #include "include/private/SkSemaphore.h" #include "src/core/SkLeanWindows.h" -#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) +#if defined(STARBOARD) + #include "starboard/common/semaphore.h" + + struct SkSemaphore::OSSemaphore { + starboard::Semaphore fSemaphore; + + OSSemaphore(): fSemaphore(0/*initial count*/) {} + + void signal(int n) { while (n -- > 0) { fSemaphore.Put(); } } + void wait() { fSemaphore.Take(); } + }; +#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) #include struct SkSemaphore::OSSemaphore { diff --git a/third_party/skia/src/core/SkStrikeCache.cpp b/third_party/skia/src/core/SkStrikeCache.cpp index c8cc0ad317f..7758ba9407d 100644 --- a/third_party/skia/src/core/SkStrikeCache.cpp +++ b/third_party/skia/src/core/SkStrikeCache.cpp @@ -21,10 +21,12 @@ bool gSkUseThreadLocalStrikeCaches_IAcknowledgeThisIsIncrediblyExperimental = false; SkStrikeCache* SkStrikeCache::GlobalStrikeCache() { +#if !defined(STARBOARD) if (gSkUseThreadLocalStrikeCaches_IAcknowledgeThisIsIncrediblyExperimental) { static thread_local auto* cache = new SkStrikeCache; return cache; } +#endif static auto* cache = new SkStrikeCache; return cache; } diff --git a/third_party/skia/src/core/SkThreadID.cpp b/third_party/skia/src/core/SkThreadID.cpp index e882834e72f..ab2dc707bcd 100644 --- a/third_party/skia/src/core/SkThreadID.cpp +++ b/third_party/skia/src/core/SkThreadID.cpp @@ -7,7 +7,10 @@ #include "include/private/SkThreadID.h" -#ifdef SK_BUILD_FOR_WIN +#if defined(STARBOARD) + #include "starboard/thread.h" + SkThreadID SkGetThreadID() { return SbThreadGetId(); } +#elif defined(SK_BUILD_FOR_WIN) #include "src/core/SkLeanWindows.h" SkThreadID SkGetThreadID() { return GetCurrentThreadId(); } #else diff --git a/third_party/skia/src/gpu/GrAutoLocaleSetter.h b/third_party/skia/src/gpu/GrAutoLocaleSetter.h index aa241777288..08649c82984 100644 --- a/third_party/skia/src/gpu/GrAutoLocaleSetter.h +++ b/third_party/skia/src/gpu/GrAutoLocaleSetter.h @@ -8,6 +8,16 @@ #ifndef GrAutoLocaleSetter_DEFINED #define GrAutoLocaleSetter_DEFINED +#if defined(STARBOARD) + +class GrAutoLocaleSetter : public SkNoncopyable { +public: + // Starboard does not support setting locales. + GrAutoLocaleSetter(const char*) {} +}; + +#else // defined(STARBOARD) + #include "include/gpu/GrTypes.h" #include "include/private/SkNoncopyable.h" @@ -95,4 +105,6 @@ class GrAutoLocaleSetter : public SkNoncopyable { #undef HAVE_LOCALE_T #undef HAVE_XLOCALE +#endif // defined(STARBOARD) + #endif diff --git a/third_party/skia/src/gpu/ops/AtlasTextOp.cpp b/third_party/skia/src/gpu/ops/AtlasTextOp.cpp index 980f9c50a04..1e7fbce6665 100644 --- a/third_party/skia/src/gpu/ops/AtlasTextOp.cpp +++ b/third_party/skia/src/gpu/ops/AtlasTextOp.cpp @@ -32,27 +32,35 @@ namespace skgpu::v1 { +#if !defined(STARBOARD) // If we have thread local, then cache memory for a single AtlasTextOp. static thread_local void* gCache = nullptr; +#endif + void* AtlasTextOp::operator new(size_t s) { +#if !defined(STARBOARD) if (gCache != nullptr) { return std::exchange(gCache, nullptr); } - +#endif return ::operator new(s); } void AtlasTextOp::operator delete(void* bytes) noexcept { +#if !defined(STARBOARD) if (gCache == nullptr) { gCache = bytes; return; } +#endif ::operator delete(bytes); } void AtlasTextOp::ClearCache() { +#if !defined(STARBOARD) ::operator delete(gCache); gCache = nullptr; +#endif } AtlasTextOp::AtlasTextOp(MaskType maskType, diff --git a/third_party/skia/src/gpu/text/GrAtlasManager.cpp b/third_party/skia/src/gpu/text/GrAtlasManager.cpp index 70a7610f11e..f2b421a1c56 100644 --- a/third_party/skia/src/gpu/text/GrAtlasManager.cpp +++ b/third_party/skia/src/gpu/text/GrAtlasManager.cpp @@ -13,6 +13,10 @@ #include "src/gpu/GrImageInfo.h" #include "src/gpu/text/GrStrikeCache.h" +#if defined(STARBOARD) +#include "starboard/file.h" +#endif + GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, size_t maxTextureBytes, GrDrawOpAtlas::AllowMultitexturing allowMultitexturing) @@ -246,19 +250,31 @@ static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrCo return false; } +#if !defined(STARBOARD) // remove any previous version of this file remove(filename); +#else + SbFileDelete(filename); +#endif SkFILEWStream file(filename); if (!file.isValid()) { SkDebugf("------ failed to create file: %s\n", filename); +#if !defined(STARBOARD) remove(filename); // remove any partial file +#else + SbFileDelete(filename); +#endif return false; } if (!SkEncodeImage(&file, bm, SkEncodedImageFormat::kPNG, 100)) { SkDebugf("------ failed to encode %s\n", filename); +#if !defined(STARBOARD) remove(filename); // remove any partial file +#else + SbFileDelete(filename); +#endif return false; } diff --git a/third_party/skia/src/ports/SkFontHost_FreeType.cpp b/third_party/skia/src/ports/SkFontHost_FreeType.cpp index adb747c9e46..3b0277421c4 100644 --- a/third_party/skia/src/ports/SkFontHost_FreeType.cpp +++ b/third_party/skia/src/ports/SkFontHost_FreeType.cpp @@ -55,7 +55,7 @@ // SK_FREETYPE_MINIMUM_RUNTIME_VERSION 0x // Flag SK_FREETYPE_DLOPEN: also try dlopen to get newer features. -#define SK_FREETYPE_DLOPEN (0x1) +#define SK_FREETYPE_DLOPEN (0x0) #ifndef SK_FREETYPE_MINIMUM_RUNTIME_VERSION # if defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) || defined (SK_BUILD_FOR_GOOGLE3) # define SK_FREETYPE_MINIMUM_RUNTIME_VERSION (((FREETYPE_MAJOR) << 24) | ((FREETYPE_MINOR) << 16) | ((FREETYPE_PATCH) << 8)) diff --git a/third_party/skia/src/sksl/SkSLPool.cpp b/third_party/skia/src/sksl/SkSLPool.cpp index da7f40b92cb..7e41a1e3e78 100644 --- a/third_party/skia/src/sksl/SkSLPool.cpp +++ b/third_party/skia/src/sksl/SkSLPool.cpp @@ -11,10 +11,15 @@ #ifndef STARBOARD // Avoid redefining VLOG from base/logging.h #define VLOG(...) // printf(__VA_ARGS__) +#else +#include "starboard/common/log.h" +#include "starboard/once.h" +#include "starboard/thread.h" #endif namespace SkSL { +#if !defined(STARBOARD) static thread_local MemoryPool* sMemPool = nullptr; static MemoryPool* get_thread_local_memory_pool() { @@ -24,6 +29,33 @@ static MemoryPool* get_thread_local_memory_pool() { static void set_thread_local_memory_pool(MemoryPool* memPool) { sMemPool = memPool; } +#else +namespace { +SbOnceControl s_once_flag = SB_ONCE_INITIALIZER; +SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid; + +void InitThreadLocalKey() { + s_thread_local_key = SbThreadCreateLocalKey(nullptr); + SB_DCHECK(SbThreadIsValidLocalKey(s_thread_local_key)); + SbThreadSetLocalValue(s_thread_local_key, nullptr); +} + +void EnsureThreadLocalKeyInited() { + SbOnce(&s_once_flag, InitThreadLocalKey); + SB_DCHECK(SbThreadIsValidLocalKey(s_thread_local_key)); +} +} // namespace + +static MemoryPool* get_thread_local_memory_pool() { + return static_cast(SbThreadGetLocalValue(s_thread_local_key)); +} + +static void set_thread_local_memory_pool(MemoryPool* memPool) { + EnsureThreadLocalKeyInited(); + SbThreadSetLocalValue(s_thread_local_key, memPool); +} +#endif + Pool::~Pool() { if (get_thread_local_memory_pool() == fMemPool.get()) { @@ -56,7 +88,7 @@ void Pool::attachToThread() { #ifndef STARBOARD VLOG("ATTACH Pool:0x%016llX\n", (uint64_t)fMemPool.get()); #endif - SkASSERT(get_thread_local_memory_pool() == nullptr); + // SkASSERT(get_thread_local_memory_pool() == nullptr); set_thread_local_memory_pool(fMemPool.get()); } diff --git a/third_party/skia/src/sksl/SkSLThreadContext.cpp b/third_party/skia/src/sksl/SkSLThreadContext.cpp index fa577ab5eea..85b466a1c13 100644 --- a/third_party/skia/src/sksl/SkSLThreadContext.cpp +++ b/third_party/skia/src/sksl/SkSLThreadContext.cpp @@ -185,6 +185,7 @@ void ThreadContext::ReportErrors(PositionInfo pos) { GetErrorReporter().reportPendingErrors(pos); } +#if !defined(STARBOARD) thread_local ThreadContext* instance = nullptr; bool ThreadContext::IsActive() { @@ -201,5 +202,39 @@ void ThreadContext::SetInstance(std::unique_ptr newInstance) { delete instance; instance = newInstance.release(); } +#else +#include "starboard/common/log.h" +#include "starboard/once.h" +#include "starboard/thread.h" +namespace { +ThreadContext* instance = nullptr; + +SbOnceControl s_once_flag = SB_ONCE_INITIALIZER; +SbThreadLocalKey s_thread_local_key = kSbThreadLocalKeyInvalid; + +void InitThreadLocalKey() { + s_thread_local_key = SbThreadCreateLocalKey(nullptr); + SB_DCHECK(SbThreadIsValidLocalKey(s_thread_local_key)); + SbThreadSetLocalValue(s_thread_local_key, nullptr); +} + +void EnsureThreadLocalKeyInited() { + SbOnce(&s_once_flag, InitThreadLocalKey); + SB_DCHECK(SbThreadIsValidLocalKey(s_thread_local_key)); +} +} // namespace + +bool ThreadContext::IsActive() { return SbThreadGetLocalValue(s_thread_local_key) != nullptr; } + +ThreadContext& ThreadContext::Instance() { return *instance; } + +void ThreadContext::SetInstance(std::unique_ptr newInstance) { + EnsureThreadLocalKeyInited(); + delete instance; + SbThreadSetLocalValue(s_thread_local_key, static_cast(newInstance.release())); + instance = static_cast(SbThreadGetLocalValue(s_thread_local_key)); +} + +#endif } // namespace SkSL