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
#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
#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
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;
#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_));
fCanvasIsDeferred = isDeferred;
}
+#if SK_SUPPORT_GPU
+ static GrContext* GetGr(/*very nearly const*/ SkCanvas*);
+#endif
+
protected:
static SkString gResourcePath;
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) {
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;
if (NULL != auGpuTarget) {
gpuTarget = auGpuTarget;
grSuccess = true;
- autogr.set(gr);
// Set the user specified cache limits if non-default.
size_t bytes;
int count;
#if SK_SUPPORT_GPU
#include "GrContext.h"
-
-namespace skiagm {
-extern GrContext* GetGr();
-};
#endif
static SkData* fileToData(const char path[]) {
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
namespace skiagm {
-extern GrContext* GetGr();
-
static const int S = 200;
class TexDataGM : public GM {
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;