diff options
-rw-r--r-- | include/gpu/GrContext.h | 3 | ||||
-rw-r--r-- | include/gpu/GrContextOptions.h | 10 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 2 | ||||
-rw-r--r-- | tests/GrContextFactoryTest.cpp | 26 |
5 files changed, 47 insertions, 0 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 61446875cc..7510a7312d 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -46,6 +46,7 @@ class SkTraceMemoryDump; class SkImage; class SkSurfaceProps; +class SkTaskGroup; class SK_API GrContext : public SkRefCnt { public: @@ -359,6 +360,8 @@ private: // GrRenderTargetContexts. It is also passed to the GrResourceProvider and SkGpuDevice. mutable GrSingleOwner fSingleOwner; + std::unique_ptr<SkTaskGroup> fTaskGroup; + struct CleanUpData { PFCleanUpFunc fFunc; void* fInfo; diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h index f560b31e7b..d01d0725a6 100644 --- a/include/gpu/GrContextOptions.h +++ b/include/gpu/GrContextOptions.h @@ -11,6 +11,8 @@ #include "SkTypes.h" #include "GrTypes.h" +class SkExecutor; + struct GrContextOptions { GrContextOptions() {} @@ -33,6 +35,14 @@ struct GrContextOptions { deduce the optimal value for this platform. */ int fBufferMapThreshold = -1; + /** + * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be + * done serially on the main thread. To have worker threads assist with various tasks, set this + * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used + * for other tasks. + */ + SkExecutor* fExecutor = nullptr; + /** some gpus have problems with partial writes of the rendertarget */ bool fUseDrawInsteadOfPartialRenderTargetWrite = false; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index d5c82c64da..915700ce82 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -27,6 +27,8 @@ #include "SkConvertPixels.h" #include "SkGr.h" #include "SkJSONWriter.h" +#include "SkMakeUnique.h" +#include "SkTaskGroup.h" #include "SkUnPreMultiplyPriv.h" #include "effects/GrConfigConversionEffect.h" #include "text/GrTextBlobCache.h" @@ -201,6 +203,10 @@ bool GrContext::init(const GrContextOptions& options) { fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); + if (options.fExecutor) { + fTaskGroup = skstd::make_unique<SkTaskGroup>(*options.fExecutor); + } + return true; } diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index be67d0e471..e1773c8e81 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -159,6 +159,8 @@ public: GrBackend getBackend() const { return fContext->fBackend; } + SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); } + private: explicit GrContextPriv(GrContext* context) : fContext(context) {} GrContextPriv(const GrContextPriv&); // unimpl diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp index 098b2d61a9..a6291cf42d 100644 --- a/tests/GrContextFactoryTest.cpp +++ b/tests/GrContextFactoryTest.cpp @@ -10,7 +10,9 @@ #if SK_SUPPORT_GPU #include "GrContextFactory.h" +#include "GrContextPriv.h" #include "GrCaps.h" +#include "SkExecutor.h" #include "Test.h" using namespace sk_gpu_test; @@ -139,6 +141,30 @@ DEF_GPUTEST(GrContextFactory_sharedContexts, reporter, /*factory*/) { } } +DEF_GPUTEST(GrContextFactory_executorAndTaskGroup, reporter, /*factory*/) { + // Verify that contexts have a task group iff we supply an executor with context options + GrContextOptions contextOptions; + contextOptions.fExecutor = nullptr; + GrContextFactory serialFactory(contextOptions); + + std::unique_ptr<SkExecutor> threadPool = SkExecutor::MakeThreadPool(1); + contextOptions.fExecutor = threadPool.get(); + GrContextFactory threadedFactory(contextOptions); + + for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { + GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i); + ContextInfo serialInfo = serialFactory.getContextInfo(ctxType); + if (GrContext* serialContext = serialInfo.grContext()) { + REPORTER_ASSERT(reporter, nullptr == serialContext->contextPriv().getTaskGroup()); + } + + ContextInfo threadedInfo = threadedFactory.getContextInfo(ctxType); + if (GrContext* threadedContext = threadedInfo.grContext()) { + REPORTER_ASSERT(reporter, nullptr != threadedContext->contextPriv().getTaskGroup()); + } + } +} + DEF_GPUTEST_FOR_ALL_CONTEXTS(GrContextDump, reporter, ctxInfo) { // Ensure that GrContext::dump doesn't assert (which is possible, if the JSON code is wrong) SkString result = ctxInfo.grContext()->dump(); |