Permalink
Browse files

Make GPU unit tests use GrContexts of different GL types.

Review URL: https://codereview.appspot.com/7281046

git-svn-id: http://skia.googlecode.com/svn/trunk@7540 2bbb7eff-a529-9590-31e7-b0007b416f81
  • Loading branch information...
1 parent 0bfd4f1 commit 99697948d40b506f0a1fcad28d9904bb817b964a bsalomon@google.com committed Feb 4, 2013
@@ -43,25 +43,43 @@ class GrContextFactory : GrNoncopyable {
#endif
kNull_GLContextType,
kDebug_GLContextType,
+
+ kLastGLContextType = kDebug_GLContextType
};
+ static const int kGLContextTypeCnt = kLastGLContextType + 1;
+
+ static bool IsRenderingGLContext(GLContextType type) {
+ switch (type) {
+ case kNull_GLContextType:
+ case kDebug_GLContextType:
+ return false;
+ default:
+ return true;
+ }
+ }
+
GrContextFactory() {
}
- ~GrContextFactory() {
+ ~GrContextFactory() { this->destroyContexts(); }
+
+ void destroyContexts() {
for (int i = 0; i < fContexts.count(); ++i) {
fContexts[i].fGrContext->unref();
fContexts[i].fGLContext->unref();
}
+ fContexts.reset();
}
/**
- * Get a GrContext initalized with a type of GL context.
+ * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
*/
GrContext* get(GLContextType type) {
for (int i = 0; i < fContexts.count(); ++i) {
if (fContexts[i].fType == type) {
+ fContexts[i].fGLContext->makeCurrent();
return fContexts[i].fGrContext;
}
}
View
@@ -9,6 +9,7 @@
#include "Test.h"
// This is a GR test
#if SK_SUPPORT_GPU
+#include "GrContextFactory.h"
#include "SkGpuDevice.h"
#include "../../src/gpu/GrClipMaskManager.h"
@@ -216,10 +217,20 @@ static void test_cache(skiatest::Reporter* reporter, GrContext* context) {
}
////////////////////////////////////////////////////////////////////////////////
-static void TestClipCache(skiatest::Reporter* reporter, GrContext* context) {
-
- test_cache(reporter, context);
- test_clip_bounds(reporter, context);
+static void TestClipCache(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
+ GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
+ if (!GrContextFactory::IsRenderingGLContext(glType)) {
+ continue;
+ }
+ GrContext* context = factory->get(glType);
+ if (NULL == context) {
+ continue;
+ }
+
+ test_cache(reporter, context);
+ test_clip_bounds(reporter, context);
+ }
}
////////////////////////////////////////////////////////////////////////////////
View
@@ -14,6 +14,7 @@
#include "gl/GrGpuGL.h"
#include "GrBackendEffectFactory.h"
+#include "GrContextFactory.h"
#include "effects/GrConfigConversionEffect.h"
#include "SkRandom.h"
@@ -147,9 +148,14 @@ bool GrGpuGL::programUnitTest() {
return true;
}
-static void GLProgramsTest(skiatest::Reporter* reporter, GrContext* context) {
- GrGpuGL* shadersGpu = static_cast<GrGpuGL*>(context->getGpu());
- REPORTER_ASSERT(reporter, shadersGpu->programUnitTest());
+static void GLProgramsTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
+ for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
+ GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type));
+ if (NULL != context) {
+ GrGpuGL* shadersGpu = static_cast<GrGpuGL*>(context->getGpu());
+ REPORTER_ASSERT(reporter, shadersGpu->programUnitTest());
+ }
+ }
}
#include "TestClassDef.h"
View
@@ -9,6 +9,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrContextFactory.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColor.h"
@@ -117,88 +118,106 @@ static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con
// Stripped down version of TestBitmapCopy that checks basic fields (width, height, config, genID)
// to ensure that they were copied properly.
-static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContext* grContext) {
+static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* factory) {
#ifdef SK_BUILD_FOR_ANDROID // https://code.google.com/p/skia/issues/detail?id=753
return;
#endif
- if (NULL == grContext) {
- return;
- }
- static const Pair gPairs[] = {
- { SkBitmap::kNo_Config, "000" },
- { SkBitmap::kARGB_4444_Config, "011" },
- { SkBitmap::kARGB_8888_Config, "011" },
- };
-
- const int W = 20;
- const int H = 33;
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
- SkBitmap src, dst;
-
- SkGpuDevice* device = SkNEW_ARGS(SkGpuDevice, (grContext, gPairs[i].fConfig, W, H));
- SkAutoUnref aur(device);
- src = device->accessBitmap(false);
- device->clear(SK_ColorWHITE);
-
- // Draw something different to the same portion of the bitmap that we will extract as a
- // subset, so that comparing the pixels of the subset will be meaningful.
- SkIRect subsetRect = SkIRect::MakeLTRB(W/2, H/2, W, H);
- SkCanvas drawingCanvas(device);
- SkPaint paint;
- paint.setColor(SK_ColorRED);
- drawingCanvas.drawRect(SkRect::MakeFromIRect(subsetRect), paint);
-
- // Extract a subset. If this succeeds we will test copying the subset.
- SkBitmap subset;
- const bool extracted = src.extractSubset(&subset, subsetRect);
- if (extracted) {
- TestSubsetHelpers(reporter, subset);
+ for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) {
+ GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type);
+ if (!GrContextFactory::IsRenderingGLContext(glType)) {
+ continue;
}
+#if SK_ANGLE // This test breaks ANGLE: memcmps fail and readpixels return value is false.
+ if (type == GrContextFactory::kANGLE_GLContextType) {
+ continue;
+ }
+#endif
- for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
- dst.reset();
- bool success = src.deepCopyTo(&dst, gPairs[j].fConfig);
- bool expected = gPairs[i].fValid[j] != '0';
- if (success != expected) {
- SkString str;
- str.printf("SkBitmap::deepCopyTo from %s to %s. expected %s returned %s",
- gConfigName[i], gConfigName[j], boolStr(expected),
- boolStr(success));
- reporter->reportFailed(str);
- }
-
- bool canSucceed = src.canCopyTo(gPairs[j].fConfig);
- if (success != canSucceed) {
- SkString str;
- str.printf("SkBitmap::deepCopyTo from %s to %s returned %s,"
- "but canCopyTo returned %s",
- gConfigName[i], gConfigName[j], boolStr(success),
- boolStr(canSucceed));
- reporter->reportFailed(str);
- }
+ GrContext* grContext = factory->get(glType);
+ if (NULL == grContext) {
+ continue;
+ }
- TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, dst);
- // Test copying the subset bitmap, using both copyTo and deepCopyTo.
+ if (NULL == grContext) {
+ return;
+ }
+ static const Pair gPairs[] = {
+ { SkBitmap::kNo_Config, "000" },
+ { SkBitmap::kARGB_4444_Config, "011" },
+ { SkBitmap::kARGB_8888_Config, "011" },
+ };
+
+ const int W = 20;
+ const int H = 33;
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gPairs); i++) {
+ SkBitmap src, dst;
+
+ SkGpuDevice* device = SkNEW_ARGS(SkGpuDevice, (grContext, gPairs[i].fConfig, W, H));
+ SkAutoUnref aur(device);
+ src = device->accessBitmap(false);
+ device->clear(SK_ColorWHITE);
+
+ // Draw something different to the same portion of the bitmap that we will extract as a
+ // subset, so that comparing the pixels of the subset will be meaningful.
+ SkIRect subsetRect = SkIRect::MakeLTRB(W/2, H/2, W, H);
+ SkCanvas drawingCanvas(device);
+ SkPaint paint;
+ paint.setColor(SK_ColorRED);
+ drawingCanvas.drawRect(SkRect::MakeFromIRect(subsetRect), paint);
+
+ // Extract a subset. If this succeeds we will test copying the subset.
+ SkBitmap subset;
+ const bool extracted = src.extractSubset(&subset, subsetRect);
if (extracted) {
- SkBitmap subsetCopy;
- success = subset.copyTo(&subsetCopy, gPairs[j].fConfig);
- REPORTER_ASSERT(reporter, success == expected);
- REPORTER_ASSERT(reporter, success == canSucceed);
- TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, false,
- &subsetRect);
-
- // Reset the bitmap so that a failed copyTo will leave it in the expected state.
- subsetCopy.reset();
- success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig);
- REPORTER_ASSERT(reporter, success == expected);
- REPORTER_ASSERT(reporter, success == canSucceed);
- TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, true,
- &subsetRect);
+ TestSubsetHelpers(reporter, subset);
}
- } // for (size_t j = ...
- } // for (size_t i = ...
+
+ for (size_t j = 0; j < SK_ARRAY_COUNT(gPairs); j++) {
+ dst.reset();
+ bool success = src.deepCopyTo(&dst, gPairs[j].fConfig);
+ bool expected = gPairs[i].fValid[j] != '0';
+ if (success != expected) {
+ SkString str;
+ str.printf("SkBitmap::deepCopyTo from %s to %s. expected %s returned %s",
+ gConfigName[i], gConfigName[j], boolStr(expected),
+ boolStr(success));
+ reporter->reportFailed(str);
+ }
+
+ bool canSucceed = src.canCopyTo(gPairs[j].fConfig);
+ if (success != canSucceed) {
+ SkString str;
+ str.printf("SkBitmap::deepCopyTo from %s to %s returned %s,"
+ "but canCopyTo returned %s",
+ gConfigName[i], gConfigName[j], boolStr(success),
+ boolStr(canSucceed));
+ reporter->reportFailed(str);
+ }
+
+ TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, dst);
+
+ // Test copying the subset bitmap, using both copyTo and deepCopyTo.
+ if (extracted) {
+ SkBitmap subsetCopy;
+ success = subset.copyTo(&subsetCopy, gPairs[j].fConfig);
+ REPORTER_ASSERT(reporter, success == expected);
+ REPORTER_ASSERT(reporter, success == canSucceed);
+ TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, false,
+ &subsetRect);
+
+ // Reset the bitmap so that a failed copyTo will leave it in the expected state.
+ subsetCopy.reset();
+ success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig);
+ REPORTER_ASSERT(reporter, success == expected);
+ REPORTER_ASSERT(reporter, success == canSucceed);
+ TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, true,
+ &subsetRect);
+ }
+ } // for (size_t j = ...
+ } // for (size_t i = ...
+ } // GrContextFactory::GLContextType
}
#include "TestClassDef.h"
View
@@ -63,7 +63,7 @@ class HashKey {
};
////////////////////////////////////////////////////////////////////////////////
-static void TestHashCache(skiatest::Reporter* reporter, GrContext* context) {
+static void TestHashCache(skiatest::Reporter* reporter) {
GrTHashTable<HashElement, HashKey, 4> cache;
@@ -165,6 +165,6 @@ static void TestHashCache(skiatest::Reporter* reporter, GrContext* context) {
////////////////////////////////////////////////////////////////////////////////
#include "TestClassDef.h"
-DEFINE_GPUTESTCLASS("HashCache", HashCacheTestClass, TestHashCache)
+DEFINE_TESTCLASS("HashCache", HashCacheTestClass, TestHashCache)
#endif
Oops, something went wrong.

0 comments on commit 9969794

Please sign in to comment.