| OLD | NEW |
| 1 | |
| 2 /* | 1 /* |
| 3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 4 * | 3 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 7 */ | 6 */ |
| 8 | 7 |
| 9 #include "Test.h" | 8 #include "Test.h" |
| 10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 11 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
| 12 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
| 13 | 12 |
| 14 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 15 #include "GrContextFactory.h" | 14 #include "GrContextFactory.h" |
| 16 #include "SkGpuDevice.h" | 15 #include "SkGpuDevice.h" |
| 17 #endif | 16 #endif |
| 18 | 17 |
| 19 | 18 static void fillCanvas(SkCanvas* canvas, SkCanvas::Config8888 unpremulConfig) { |
| 20 namespace { | |
| 21 | |
| 22 void fillCanvas(SkCanvas* canvas, SkCanvas::Config8888 unpremulConfig) { | |
| 23 SkBitmap bmp; | 19 SkBitmap bmp; |
| 24 bmp.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 20 bmp.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); |
| 25 bmp.allocPixels(); | 21 bmp.allocPixels(); |
| 26 SkAutoLockPixels alp(bmp); | 22 SkAutoLockPixels alp(bmp); |
| 27 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); | 23 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); |
| 28 | 24 |
| 29 for (int a = 0; a < 256; ++a) { | 25 for (int a = 0; a < 256; ++a) { |
| 30 for (int r = 0; r < 256; ++r) { | 26 for (int r = 0; r < 256; ++r) { |
| 31 pixels[a * 256 + r] = SkPackConfig8888(unpremulConfig, a, r, 0, 0); | 27 pixels[a * 256 + r] = SkPackConfig8888(unpremulConfig, a, r, 0, 0); |
| 32 } | 28 } |
| 33 } | 29 } |
| 34 canvas->writePixels(bmp, 0, 0, unpremulConfig); | 30 canvas->writePixels(bmp, 0, 0, unpremulConfig); |
| 35 } | 31 } |
| 36 | 32 |
| 37 static const SkCanvas::Config8888 gUnpremulConfigs[] = { | 33 static const SkCanvas::Config8888 gUnpremulConfigs[] = { |
| 38 SkCanvas::kNative_Unpremul_Config8888, | 34 SkCanvas::kNative_Unpremul_Config8888, |
| 39 SkCanvas::kBGRA_Unpremul_Config8888, | 35 SkCanvas::kBGRA_Unpremul_Config8888, |
| 40 SkCanvas::kRGBA_Unpremul_Config8888, | 36 SkCanvas::kRGBA_Unpremul_Config8888, |
| 41 }; | 37 }; |
| 42 | 38 |
| 43 void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFactory* fa
ctory) { | 39 static void PremulAlphaRoundTripTest(skiatest::Reporter* reporter, GrContextFact
ory* factory) { |
| 44 SkAutoTUnref<SkBaseDevice> device; | 40 SkAutoTUnref<SkBaseDevice> device; |
| 45 for (int dtype = 0; dtype < 2; ++dtype) { | 41 for (int dtype = 0; dtype < 2; ++dtype) { |
| 46 | 42 |
| 47 int glCtxTypeCnt = 1; | 43 int glCtxTypeCnt = 1; |
| 48 #if SK_SUPPORT_GPU | 44 #if SK_SUPPORT_GPU |
| 49 if (0 != dtype) { | 45 if (0 != dtype) { |
| 50 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; | 46 glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; |
| 51 } | 47 } |
| 52 #endif | 48 #endif |
| 53 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { | 49 for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 for (int y = 0; y < 256 && success; ++y) { | 103 for (int y = 0; y < 256 && success; ++y) { |
| 108 for (int x = 0; x < 256 && success; ++x) { | 104 for (int x = 0; x < 256 && success; ++x) { |
| 109 int i = y * 256 + x; | 105 int i = y * 256 + x; |
| 110 REPORTER_ASSERT(reporter, success = pixels1[i] == pixels
2[i]); | 106 REPORTER_ASSERT(reporter, success = pixels1[i] == pixels
2[i]); |
| 111 } | 107 } |
| 112 } | 108 } |
| 113 } | 109 } |
| 114 } | 110 } |
| 115 } | 111 } |
| 116 } | 112 } |
| 117 } | |
| 118 | 113 |
| 119 #include "TestClassDef.h" | 114 #include "TestClassDef.h" |
| 120 DEFINE_GPUTESTCLASS("PremulAlphaRoundTripTest", PremulAlphaRoundTripTestClass, P
remulAlphaRoundTripTest) | 115 DEFINE_GPUTESTCLASS("PremulAlphaRoundTripTest", PremulAlphaRoundTripTestClass, P
remulAlphaRoundTripTest) |
| OLD | NEW |