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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 #include "GrContextFactory.h" | 14 #include "GrContextFactory.h" |
15 #include "SkGpuDevice.h" | 15 #include "SkGpuDevice.h" |
16 #endif | 16 #endif |
17 | 17 |
18 static void fillCanvas(SkCanvas* canvas, SkCanvas::Config8888 unpremulConfig) { | 18 static void fillCanvas(SkCanvas* canvas, SkCanvas::Config8888 unpremulConfig) { |
19 SkBitmap bmp; | 19 SkBitmap bmp; |
20 bmp.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 20 bmp.allocN32Pixels(256, 256); |
21 bmp.allocPixels(); | |
22 SkAutoLockPixels alp(bmp); | 21 SkAutoLockPixels alp(bmp); |
23 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); | 22 uint32_t* pixels = reinterpret_cast<uint32_t*>(bmp.getPixels()); |
24 | 23 |
25 for (int a = 0; a < 256; ++a) { | 24 for (int a = 0; a < 256; ++a) { |
26 for (int r = 0; r < 256; ++r) { | 25 for (int r = 0; r < 256; ++r) { |
27 pixels[a * 256 + r] = SkPackConfig8888(unpremulConfig, a, r, 0, 0); | 26 pixels[a * 256 + r] = SkPackConfig8888(unpremulConfig, a, r, 0, 0); |
28 } | 27 } |
29 } | 28 } |
30 canvas->writePixels(bmp, 0, 0, unpremulConfig); | 29 canvas->writePixels(bmp, 0, 0, unpremulConfig); |
31 } | 30 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 } | 64 } |
66 | 65 |
67 device.reset(new SkGpuDevice(context, SkBitmap::kARGB_8888_Confi
g, 256, 256)); | 66 device.reset(new SkGpuDevice(context, SkBitmap::kARGB_8888_Confi
g, 256, 256)); |
68 #else | 67 #else |
69 continue; | 68 continue; |
70 #endif | 69 #endif |
71 } | 70 } |
72 SkCanvas canvas(device); | 71 SkCanvas canvas(device); |
73 | 72 |
74 SkBitmap readBmp1; | 73 SkBitmap readBmp1; |
75 readBmp1.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 74 readBmp1.allocN32Pixels(256, 256); |
76 readBmp1.allocPixels(); | |
77 SkBitmap readBmp2; | 75 SkBitmap readBmp2; |
78 readBmp2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); | 76 readBmp2.allocN32Pixels(256, 256); |
79 readBmp2.allocPixels(); | |
80 | 77 |
81 for (size_t upmaIdx = 0; | 78 for (size_t upmaIdx = 0; |
82 upmaIdx < SK_ARRAY_COUNT(gUnpremulConfigs); | 79 upmaIdx < SK_ARRAY_COUNT(gUnpremulConfigs); |
83 ++upmaIdx) { | 80 ++upmaIdx) { |
84 fillCanvas(&canvas, gUnpremulConfigs[upmaIdx]); | 81 fillCanvas(&canvas, gUnpremulConfigs[upmaIdx]); |
85 { | 82 { |
86 SkAutoLockPixels alp1(readBmp1); | 83 SkAutoLockPixels alp1(readBmp1); |
87 SkAutoLockPixels alp2(readBmp2); | 84 SkAutoLockPixels alp2(readBmp2); |
88 sk_bzero(readBmp1.getPixels(), readBmp1.getSafeSize()); | 85 sk_bzero(readBmp1.getPixels(), readBmp1.getSafeSize()); |
89 sk_bzero(readBmp2.getPixels(), readBmp2.getSafeSize()); | 86 sk_bzero(readBmp2.getPixels(), readBmp2.getSafeSize()); |
(...skipping 13 matching lines...) Expand all Loading... |
103 for (int y = 0; y < 256 && success; ++y) { | 100 for (int y = 0; y < 256 && success; ++y) { |
104 for (int x = 0; x < 256 && success; ++x) { | 101 for (int x = 0; x < 256 && success; ++x) { |
105 int i = y * 256 + x; | 102 int i = y * 256 + x; |
106 REPORTER_ASSERT(reporter, success = pixels1[i] == pixels
2[i]); | 103 REPORTER_ASSERT(reporter, success = pixels1[i] == pixels
2[i]); |
107 } | 104 } |
108 } | 105 } |
109 } | 106 } |
110 } | 107 } |
111 } | 108 } |
112 } | 109 } |
OLD | NEW |