diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 152e5293eb..6cfcbcded1 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1606,10 +1606,11 @@ Result GPUPrecompileTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* return compare_bitmaps(reference, *dst); } +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ GPUDDLSink::GPUDDLSink(const SkCommandLineConfigGpu* config, const GrContextOptions& grCtxOptions) : INHERITED(config, grCtxOptions) , fRecordingThreadPool(SkExecutor::MakeLIFOThreadPool(1)) // TODO: this should be at least 2 - , fGPUThread(SkExecutor::MakeFIFOThreadPool(1)) { + , fGPUThread(SkExecutor::MakeFIFOThreadPool(1, false)) { } Result GPUDDLSink::ddlDraw(const Src& src, diff --git a/include/core/SkExecutor.h b/include/core/SkExecutor.h index b7b823f49e..823882bcf3 100644 --- a/include/core/SkExecutor.h +++ b/include/core/SkExecutor.h @@ -17,8 +17,10 @@ public: virtual ~SkExecutor(); // Create a thread pool SkExecutor with a fixed thread count, by default the number of cores. - static std::unique_ptr MakeFIFOThreadPool(int threads = 0); - static std::unique_ptr MakeLIFOThreadPool(int threads = 0); + static std::unique_ptr MakeFIFOThreadPool(int threads = 0, + bool allowBorrowing = true); + static std::unique_ptr MakeLIFOThreadPool(int threads = 0, + bool allowBorrowing = true); // There is always a default SkExecutor available by calling SkExecutor::GetDefault(). static SkExecutor& GetDefault(); diff --git a/src/core/SkExecutor.cpp b/src/core/SkExecutor.cpp index 9d90aa0536..f4aa65c1b6 100644 --- a/src/core/SkExecutor.cpp +++ b/src/core/SkExecutor.cpp @@ -72,7 +72,7 @@ static inline std::function pop(SkTArray>* template class SkThreadPool final : public SkExecutor { public: - explicit SkThreadPool(int threads) { + explicit SkThreadPool(int threads, bool allowBorrowing) : fAllowBorrowing(allowBorrowing) { for (int i = 0; i < threads; i++) { fThreads.emplace_back(&Loop, this); } @@ -100,8 +100,8 @@ public: } virtual void borrow() override { - // If there is work waiting, do it. - if (fWorkAvailable.try_wait()) { + // If there is work waiting and we're allowed to borrow work, do it. + if (fAllowBorrowing && fWorkAvailable.try_wait()) { SkAssertResult(this->do_work()); } } @@ -138,13 +138,16 @@ private: WorkList fWork; Lock fWorkLock; SkSemaphore fWorkAvailable; + bool fAllowBorrowing; }; -std::unique_ptr SkExecutor::MakeFIFOThreadPool(int threads) { +std::unique_ptr SkExecutor::MakeFIFOThreadPool(int threads, bool allowBorrowing) { using WorkList = std::deque>; - return std::make_unique>(threads > 0 ? threads : num_cores()); + return std::make_unique>(threads > 0 ? threads : num_cores(), + allowBorrowing); } -std::unique_ptr SkExecutor::MakeLIFOThreadPool(int threads) { +std::unique_ptr SkExecutor::MakeLIFOThreadPool(int threads, bool allowBorrowing) { using WorkList = SkTArray>; - return std::make_unique>(threads > 0 ? threads : num_cores()); + return std::make_unique>(threads > 0 ? threads : num_cores(), + allowBorrowing); }