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