aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/PremulAlphaRoundTripTest.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-04 16:13:32 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-02-04 16:13:32 +0000
commit67b915de99e6b89d476907930ac8c27afb64d10e (patch)
tree75e0c17ae09477f51ebd8561af40b5c0931433ad /tests/PremulAlphaRoundTripTest.cpp
parent7de18e5c7b4e4a8ad8910b1016688ded902f185b (diff)
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
Diffstat (limited to 'tests/PremulAlphaRoundTripTest.cpp')
-rw-r--r--tests/PremulAlphaRoundTripTest.cpp113
1 files changed, 64 insertions, 49 deletions
diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp
index 8321c940b9..b25d35834d 100644
--- a/tests/PremulAlphaRoundTripTest.cpp
+++ b/tests/PremulAlphaRoundTripTest.cpp
@@ -12,6 +12,7 @@
#include "SkDevice.h"
#if SK_SUPPORT_GPU
+#include "GrContextFactory.h"
#include "SkGpuDevice.h"
#endif
@@ -46,61 +47,75 @@ static const SkCanvas::Config8888 gUnpremulConfigs[] = {
SkCanvas::kRGBA_Unpremul_Config8888,
};
-void PremulAlphaRoundTripTest(skiatest::Reporter* reporter,
- GrContext* context) {
+void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFactory* factory) {
SkAutoTUnref<SkDevice> device;
for (int dtype = 0; dtype < 2; ++dtype) {
- if (0 == dtype) {
- device.reset(new SkDevice(SkBitmap::kARGB_8888_Config,
- 256,
- 256,
- false));
- } else {
-#if !SK_SUPPORT_GPU || defined(SK_SCALAR_IS_FIXED)
- // GPU device known not to work in the fixed pt build.
- continue;
+
+ int glCtxTypeCnt = 1;
+#if SK_SUPPORT_GPU
+ if (0 != dtype) {
+ glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt;
+ }
+#endif
+ for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) {
+ if (0 == dtype) {
+ device.reset(new SkDevice(SkBitmap::kARGB_8888_Config,
+ 256,
+ 256,
+ false));
+ } else {
+#if SK_SUPPORT_GPU
+ GrContextFactory::GLContextType type =
+ static_cast<GrContextFactory::GLContextType>(glCtxType);
+ if (!GrContextFactory::IsRenderingGLContext(type)) {
+ continue;
+ }
+ GrContext* context = factory->get(type);
+ if (NULL == context) {
+ continue;
+ }
+
+ device.reset(new SkGpuDevice(context, SkBitmap::kARGB_8888_Config, 256, 256));
#else
- device.reset(new SkGpuDevice(context,
- SkBitmap::kARGB_8888_Config,
- 256,
- 256));
+ continue;
#endif
- }
- SkCanvas canvas(device);
-
- SkBitmap readBmp1;
- readBmp1.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
- readBmp1.allocPixels();
- SkBitmap readBmp2;
- readBmp2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
- readBmp2.allocPixels();
-
- for (size_t upmaIdx = 0;
- upmaIdx < SK_ARRAY_COUNT(gUnpremulConfigs);
- ++upmaIdx) {
- fillCanvas(&canvas, gUnpremulConfigs[upmaIdx]);
- {
- SkAutoLockPixels alp1(readBmp1);
- SkAutoLockPixels alp2(readBmp2);
- sk_bzero(readBmp1.getPixels(), readBmp1.getSafeSize());
- sk_bzero(readBmp2.getPixels(), readBmp2.getSafeSize());
}
+ SkCanvas canvas(device);
+
+ SkBitmap readBmp1;
+ readBmp1.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
+ readBmp1.allocPixels();
+ SkBitmap readBmp2;
+ readBmp2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
+ readBmp2.allocPixels();
+
+ for (size_t upmaIdx = 0;
+ upmaIdx < SK_ARRAY_COUNT(gUnpremulConfigs);
+ ++upmaIdx) {
+ fillCanvas(&canvas, gUnpremulConfigs[upmaIdx]);
+ {
+ SkAutoLockPixels alp1(readBmp1);
+ SkAutoLockPixels alp2(readBmp2);
+ sk_bzero(readBmp1.getPixels(), readBmp1.getSafeSize());
+ sk_bzero(readBmp2.getPixels(), readBmp2.getSafeSize());
+ }
+
+ canvas.readPixels(&readBmp1, 0, 0, gUnpremulConfigs[upmaIdx]);
+ canvas.writePixels(readBmp1, 0, 0, gUnpremulConfigs[upmaIdx]);
+ canvas.readPixels(&readBmp2, 0, 0, gUnpremulConfigs[upmaIdx]);
- canvas.readPixels(&readBmp1, 0, 0, gUnpremulConfigs[upmaIdx]);
- canvas.writePixels(readBmp1, 0, 0, gUnpremulConfigs[upmaIdx]);
- canvas.readPixels(&readBmp2, 0, 0, gUnpremulConfigs[upmaIdx]);
-
- SkAutoLockPixels alp1(readBmp1);
- SkAutoLockPixels alp2(readBmp2);
- uint32_t* pixels1 =
- reinterpret_cast<uint32_t*>(readBmp1.getPixels());
- uint32_t* pixels2 =
- reinterpret_cast<uint32_t*>(readBmp2.getPixels());
- bool success = true;
- for (int y = 0; y < 256 && success; ++y) {
- for (int x = 0; x < 256 && success; ++x) {
- int i = y * 256 + x;
- REPORTER_ASSERT(reporter, success = pixels1[i] == pixels2[i]);
+ SkAutoLockPixels alp1(readBmp1);
+ SkAutoLockPixels alp2(readBmp2);
+ uint32_t* pixels1 =
+ reinterpret_cast<uint32_t*>(readBmp1.getPixels());
+ uint32_t* pixels2 =
+ reinterpret_cast<uint32_t*>(readBmp2.getPixels());
+ bool success = true;
+ for (int y = 0; y < 256 && success; ++y) {
+ for (int x = 0; x < 256 && success; ++x) {
+ int i = y * 256 + x;
+ REPORTER_ASSERT(reporter, success = pixels1[i] == pixels2[i]);
+ }
}
}
}