Allow SkThreadPool to be non-borrowing
The GPU thread has privileged access to the GPU so its work can't be easily borrowed. Change-Id: I1eae4c86ff1c36cc1248f74fc48d76b1c243f0b2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/284764 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
42915c2cee
commit
6276819023
@ -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,
|
||||
|
@ -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<SkExecutor> MakeFIFOThreadPool(int threads = 0);
|
||||
static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0);
|
||||
static std::unique_ptr<SkExecutor> MakeFIFOThreadPool(int threads = 0,
|
||||
bool allowBorrowing = true);
|
||||
static std::unique_ptr<SkExecutor> MakeLIFOThreadPool(int threads = 0,
|
||||
bool allowBorrowing = true);
|
||||
|
||||
// There is always a default SkExecutor available by calling SkExecutor::GetDefault().
|
||||
static SkExecutor& GetDefault();
|
||||
|
@ -72,7 +72,7 @@ static inline std::function<void(void)> pop(SkTArray<std::function<void(void)>>*
|
||||
template <typename WorkList>
|
||||
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> SkExecutor::MakeFIFOThreadPool(int threads) {
|
||||
std::unique_ptr<SkExecutor> SkExecutor::MakeFIFOThreadPool(int threads, bool allowBorrowing) {
|
||||
using WorkList = std::deque<std::function<void(void)>>;
|
||||
return std::make_unique<SkThreadPool<WorkList>>(threads > 0 ? threads : num_cores());
|
||||
return std::make_unique<SkThreadPool<WorkList>>(threads > 0 ? threads : num_cores(),
|
||||
allowBorrowing);
|
||||
}
|
||||
std::unique_ptr<SkExecutor> SkExecutor::MakeLIFOThreadPool(int threads) {
|
||||
std::unique_ptr<SkExecutor> SkExecutor::MakeLIFOThreadPool(int threads, bool allowBorrowing) {
|
||||
using WorkList = SkTArray<std::function<void(void)>>;
|
||||
return std::make_unique<SkThreadPool<WorkList>>(threads > 0 ? threads : num_cores());
|
||||
return std::make_unique<SkThreadPool<WorkList>>(threads > 0 ? threads : num_cores(),
|
||||
allowBorrowing);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user