Add an (optional) SkTaskGroup to GrContext

GrContextOptions has an SkExecutor field, allowing clients to supply a
thread pool. If present, the GrContext will create an SkTaskGroup that
can be used for internal threading work.

Bug: skia:
Change-Id: I8b01245515a21a83f9fe838caf0a01c9a26c0003
Reviewed-on: https://skia-review.googlesource.com/37580
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-08-23 10:12:00 -04:00 committed by Skia Commit-Bot
parent db816992bb
commit 5127998795
5 changed files with 47 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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();