diff options
author | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-16 20:42:15 +0000 |
---|---|---|
committer | mtklein@google.com <mtklein@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-09-16 20:42:15 +0000 |
commit | 62b50b7bb8395f9bc281a4d0ed20acc4813f1445 (patch) | |
tree | 5af9e93540690a23e482c36632bbf4effaec5da7 /gm | |
parent | 1cf02a8adffd096dff0eecabc1d3ee66ec18f911 (diff) |
Have GMs read the GrContext via a setter/getter rather than a global.
GetGr's current global state makes things rather tricky to run GPU GMs in
parallel (DM). This API change will let me feed the right GrContext to the
right GM in DM.
I'm not planning on changing the status quo in GM-the-tool: the new getters and
setters still just return the same global.
BUG=skia:1590
R=bsalomon@google.com, robertphillips@google.com
Review URL: https://codereview.chromium.org/23567032
git-svn-id: http://skia.googlecode.com/svn/trunk@11306 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm')
-rw-r--r-- | gm/bleed.cpp | 6 | ||||
-rw-r--r-- | gm/gm.cpp | 13 | ||||
-rw-r--r-- | gm/gm.h | 8 | ||||
-rw-r--r-- | gm/gmmain.cpp | 44 | ||||
-rw-r--r-- | gm/image.cpp | 6 | ||||
-rw-r--r-- | gm/texdata.cpp | 4 |
6 files changed, 24 insertions, 57 deletions
diff --git a/gm/bleed.cpp b/gm/bleed.cpp index 2b2d8497cf..dc7e96fbb1 100644 --- a/gm/bleed.cpp +++ b/gm/bleed.cpp @@ -12,10 +12,6 @@ #if SK_SUPPORT_GPU #include "GrContext.h" - -namespace skiagm { -extern GrContext* GetGr(); -}; #endif // Create a black&white checked texture with a 1-pixel red ring @@ -175,7 +171,7 @@ protected: #if SK_SUPPORT_GPU - GrContext* ctx = skiagm::GetGr(); + GrContext* ctx = GM::GetGr(canvas); int oldMaxTextureSize = 0; if (NULL != ctx) { // shrink the max texture size so all our textures can be reasonably sized @@ -62,5 +62,18 @@ void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) { canvas->drawRect(r, paint); } +#if SK_SUPPORT_GPU +// canvas could almost be a const&, but accessRenderTarget isn't const. +/*static*/ GrContext* GM::GetGr(SkCanvas* canvas) { + SkASSERT(NULL != canvas); + SkBaseDevice* device = canvas->getTopDevice(); + GrRenderTarget* renderTarget = device->accessRenderTarget(); + if (NULL != renderTarget) { + return renderTarget->getContext(); + } + return NULL; +} +#endif + // need to explicitly declare this, or we get some weird infinite loop llist template GMRegistry* SkTRegistry<GM*(*)(void*)>::gHead; @@ -16,6 +16,10 @@ #include "SkString.h" #include "SkTRegistry.h" +#if SK_SUPPORT_GPU +#include "GrContext.h" +#endif + #define DEF_GM(code) \ static skiagm::GM* SK_MACRO_APPEND_LINE(F_)(void*) { code; } \ static skiagm::GMRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); @@ -93,6 +97,10 @@ namespace skiagm { fCanvasIsDeferred = isDeferred; } +#if SK_SUPPORT_GPU + static GrContext* GetGr(/*very nearly const*/ SkCanvas*); +#endif + protected: static SkString gResourcePath; diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index 018dfe6ced..4939624055 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -1464,48 +1464,6 @@ static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { return NULL; } -namespace skiagm { -#if SK_SUPPORT_GPU -SkAutoTUnref<GrContext> gGrContext; -/** - * Sets the global GrContext, accessible by individual GMs - */ -static void SetGr(GrContext* grContext) { - SkSafeRef(grContext); - gGrContext.reset(grContext); -} - -/** - * Gets the global GrContext, can be called by GM tests. - */ -GrContext* GetGr(); -GrContext* GetGr() { - return gGrContext.get(); -} - -/** - * Sets the global GrContext and then resets it to its previous value at - * destruction. - */ -class AutoResetGr : SkNoncopyable { -public: - AutoResetGr() : fOld(NULL) {} - void set(GrContext* context) { - SkASSERT(NULL == fOld); - fOld = GetGr(); - SkSafeRef(fOld); - SetGr(context); - } - ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } -private: - GrContext* fOld; -}; -#else -GrContext* GetGr(); -GrContext* GetGr() { return NULL; } -#endif -} - template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { int index = array->find(value); if (index < 0) { @@ -1573,7 +1531,6 @@ ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, GrSurface* gpuTarget = NULL; #if SK_SUPPORT_GPU SkAutoTUnref<GrSurface> auGpuTarget; - AutoResetGr autogr; if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { GrContext* gr = grFactory->get(config.fGLContextType); bool grSuccess = false; @@ -1589,7 +1546,6 @@ ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, if (NULL != auGpuTarget) { gpuTarget = auGpuTarget; grSuccess = true; - autogr.set(gr); // Set the user specified cache limits if non-default. size_t bytes; int count; diff --git a/gm/image.cpp b/gm/image.cpp index 3ed85f9bab..6dada0d949 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -13,10 +13,6 @@ #if SK_SUPPORT_GPU #include "GrContext.h" - -namespace skiagm { -extern GrContext* GetGr(); -}; #endif static SkData* fileToData(const char path[]) { @@ -193,7 +189,7 @@ protected: SkAutoTUnref<SkSurface> surf2(SkSurface::NewPicture(info.fWidth, info.fHeight)); SkAutoTUnref<SkSurface> surf3(SkSurface::NewPicture(info.fWidth, info.fHeight)); #if SK_SUPPORT_GPU - GrContext* ctx = skiagm::GetGr(); + GrContext* ctx = GM::GetGr(canvas); SkAutoTUnref<SkSurface> surf4(SkSurface::NewRenderTarget(ctx, info, 0)); #endif diff --git a/gm/texdata.cpp b/gm/texdata.cpp index b2c7139d85..8ba0c7741c 100644 --- a/gm/texdata.cpp +++ b/gm/texdata.cpp @@ -18,8 +18,6 @@ namespace skiagm { -extern GrContext* GetGr(); - static const int S = 200; class TexDataGM : public GM { @@ -40,7 +38,7 @@ protected: virtual void onDraw(SkCanvas* canvas) { SkBaseDevice* device = canvas->getTopDevice(); GrRenderTarget* target = device->accessRenderTarget(); - GrContext* ctx = GetGr(); + GrContext* ctx = GM::GetGr(canvas); if (ctx && target) { SkPMColor gTextureData[(2 * S) * (2 * S)]; static const int stride = 2 * S; |