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
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index eea78ce..a3bf5de 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -11,97 +11,103 @@
#include "Test.h"
#include "SkGpuDevice.h"
+#include "GrContextFactory.h"
static const int X_SIZE = 12;
static const int Y_SIZE = 12;
-static void ReadWriteAlphaTest(skiatest::Reporter* reporter, GrContext* context) {
-
-#if SK_SCALAR_IS_FIXED
- // GPU device known not to work in the fixed pt build.
- return;
-#endif
-
- unsigned char textureData[X_SIZE][Y_SIZE];
-
- memset(textureData, 0, X_SIZE * Y_SIZE);
-
- GrTextureDesc desc;
-
- // let Skia know we will be using this texture as a render target
- desc.fFlags = kRenderTarget_GrTextureFlagBit;
- // it is a single channel texture
- desc.fConfig = kAlpha_8_GrPixelConfig;
- desc.fWidth = X_SIZE;
- desc.fHeight = Y_SIZE;
-
- // We are initializing the texture with zeros here
- GrTexture* texture = context->createUncachedTexture(desc, textureData, 0);
- if (!texture) {
- return;
- }
-
- GrAutoUnref au(texture);
-
- // create a distinctive texture
- for (int y = 0; y < Y_SIZE; ++y) {
- for (int x = 0; x < X_SIZE; ++x) {
- textureData[x][y] = x*Y_SIZE+y;
+static void ReadWriteAlphaTest(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;
+ }
- // upload the texture
- texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- textureData, 0);
+ unsigned char textureData[X_SIZE][Y_SIZE];
- unsigned char readback[X_SIZE][Y_SIZE];
+ memset(textureData, 0, X_SIZE * Y_SIZE);
- // clear readback to something non-zero so we can detect readback failures
- memset(readback, 0x1, X_SIZE * Y_SIZE);
+ GrTextureDesc desc;
- // read the texture back
- texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- readback, 0);
+ // let Skia know we will be using this texture as a render target
+ desc.fFlags = kRenderTarget_GrTextureFlagBit;
+ // it is a single channel texture
+ desc.fConfig = kAlpha_8_GrPixelConfig;
+ desc.fWidth = X_SIZE;
+ desc.fHeight = Y_SIZE;
- // make sure the original & read back versions match
- bool match = true;
+ // We are initializing the texture with zeros here
+ GrTexture* texture = context->createUncachedTexture(desc, textureData, 0);
+ if (!texture) {
+ return;
+ }
- for (int y = 0; y < Y_SIZE; ++y) {
- for (int x = 0; x < X_SIZE; ++x) {
- if (textureData[x][y] != readback[x][y]) {
- match = false;
+ GrAutoUnref au(texture);
+
+ // create a distinctive texture
+ for (int y = 0; y < Y_SIZE; ++y) {
+ for (int x = 0; x < X_SIZE; ++x) {
+ textureData[x][y] = x*Y_SIZE+y;
}
}
- }
- REPORTER_ASSERT(reporter, match);
+ // upload the texture
+ texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ textureData, 0);
- // Now try writing on the single channel texture
- SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, texture->asRenderTarget()));
- SkCanvas canvas(device);
+ unsigned char readback[X_SIZE][Y_SIZE];
- SkPaint paint;
+ // clear readback to something non-zero so we can detect readback failures
+ memset(readback, 0x1, X_SIZE * Y_SIZE);
- const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10);
+ // read the texture back
+ texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ readback, 0);
- paint.setColor(SK_ColorWHITE);
+ // make sure the original & read back versions match
+ bool match = true;
- canvas.drawRect(rect, paint);
-
- texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
- readback, 0);
-
- match = true;
-
- for (int y = 0; y < Y_SIZE; ++y) {
- for (int x = 0; x < X_SIZE; ++x) {
- if (0xFF != readback[x][y]) {
- match = false;
+ for (int y = 0; y < Y_SIZE; ++y) {
+ for (int x = 0; x < X_SIZE; ++x) {
+ if (textureData[x][y] != readback[x][y]) {
+ match = false;
+ }
}
}
- }
- REPORTER_ASSERT(reporter, match);
+ REPORTER_ASSERT(reporter, match);
+
+ // Now try writing on the single channel texture
+ SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, texture->asRenderTarget()));
+ SkCanvas canvas(device);
+
+ SkPaint paint;
+
+ const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10);
+
+ paint.setColor(SK_ColorWHITE);
+
+ canvas.drawRect(rect, paint);
+
+ texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
+ readback, 0);
+
+ match = true;
+
+ for (int y = 0; y < Y_SIZE; ++y) {
+ for (int x = 0; x < X_SIZE; ++x) {
+ if (0xFF != readback[x][y]) {
+ match = false;
+ }
+ }
+ }
+
+ REPORTER_ASSERT(reporter, match);
+ }
}
#ifndef SK_BUILD_FOR_ANDROID