Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 26962002: Remove unnamed namespace usage from tests. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: revert AreEqual change Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/PremulAlphaRoundTripTest.cpp ('k') | tests/TileGridTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBitmapDevice.h" 9 #include "SkBitmapDevice.h"
11 #include "SkCanvas.h" 10 #include "SkCanvas.h"
12 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
13 #include "SkMathPriv.h" 12 #include "SkMathPriv.h"
14 #include "SkRegion.h" 13 #include "SkRegion.h"
15 #if SK_SUPPORT_GPU 14 #if SK_SUPPORT_GPU
16 #include "SkGpuDevice.h" 15 #include "SkGpuDevice.h"
17 #include "GrContextFactory.h" 16 #include "GrContextFactory.h"
18 #endif 17 #endif
19 18
20
21 static const int DEV_W = 100, DEV_H = 100; 19 static const int DEV_W = 100, DEV_H = 100;
22 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); 20 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
23 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, 21 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
24 DEV_H * SK_Scalar1); 22 DEV_H * SK_Scalar1);
25 23
26 namespace { 24 static SkPMColor getCanvasColor(int x, int y) {
27 SkPMColor getCanvasColor(int x, int y) {
28 SkASSERT(x >= 0 && x < DEV_W); 25 SkASSERT(x >= 0 && x < DEV_W);
29 SkASSERT(y >= 0 && y < DEV_H); 26 SkASSERT(y >= 0 && y < DEV_H);
30 27
31 U8CPU r = x; 28 U8CPU r = x;
32 U8CPU g = y; 29 U8CPU g = y;
33 U8CPU b = 0xc; 30 U8CPU b = 0xc;
34 31
35 U8CPU a = 0xff; 32 U8CPU a = 0xff;
36 switch ((x+y) % 5) { 33 switch ((x+y) % 5) {
37 case 0: 34 case 0:
38 a = 0xff; 35 a = 0xff;
39 break; 36 break;
40 case 1: 37 case 1:
41 a = 0x80; 38 a = 0x80;
42 break; 39 break;
43 case 2: 40 case 2:
44 a = 0xCC; 41 a = 0xCC;
45 break; 42 break;
46 case 4: 43 case 4:
47 a = 0x01; 44 a = 0x01;
48 break; 45 break;
49 case 3: 46 case 3:
50 a = 0x00; 47 a = 0x00;
51 break; 48 break;
52 } 49 }
53 return SkPremultiplyARGBInline(a, r, g, b); 50 return SkPremultiplyARGBInline(a, r, g, b);
54 } 51 }
55 52
56 SkPMColor getBitmapColor(int x, int y, int w) { 53 static SkPMColor getBitmapColor(int x, int y, int w) {
57 int n = y * w + x; 54 int n = y * w + x;
58 55
59 U8CPU b = n & 0xff; 56 U8CPU b = n & 0xff;
60 U8CPU g = (n >> 8) & 0xff; 57 U8CPU g = (n >> 8) & 0xff;
61 U8CPU r = (n >> 16) & 0xff; 58 U8CPU r = (n >> 16) & 0xff;
62 return SkPackARGB32(0xff, r, g , b); 59 return SkPackARGB32(0xff, r, g , b);
63 } 60 }
64 61
65 SkPMColor convertConfig8888ToPMColor(SkCanvas::Config8888 config8888, 62 static SkPMColor convertConfig8888ToPMColor(SkCanvas::Config8888 config8888,
66 uint32_t color, 63 uint32_t color,
67 bool* premul) { 64 bool* premul) {
68 const uint8_t* c = reinterpret_cast<uint8_t*>(&color); 65 const uint8_t* c = reinterpret_cast<uint8_t*>(&color);
69 U8CPU a,r,g,b; 66 U8CPU a,r,g,b;
70 *premul = false; 67 *premul = false;
71 switch (config8888) { 68 switch (config8888) {
72 case SkCanvas::kNative_Premul_Config8888: 69 case SkCanvas::kNative_Premul_Config8888:
73 return color; 70 return color;
74 case SkCanvas::kNative_Unpremul_Config8888: 71 case SkCanvas::kNative_Unpremul_Config8888:
75 *premul = true; 72 *premul = true;
76 a = SkGetPackedA32(color); 73 a = SkGetPackedA32(color);
77 r = SkGetPackedR32(color); 74 r = SkGetPackedR32(color);
(...skipping 21 matching lines...) Expand all
99 return 0; 96 return 0;
100 } 97 }
101 if (*premul) { 98 if (*premul) {
102 r = SkMulDiv255Ceiling(r, a); 99 r = SkMulDiv255Ceiling(r, a);
103 g = SkMulDiv255Ceiling(g, a); 100 g = SkMulDiv255Ceiling(g, a);
104 b = SkMulDiv255Ceiling(b, a); 101 b = SkMulDiv255Ceiling(b, a);
105 } 102 }
106 return SkPackARGB32(a, r, g, b); 103 return SkPackARGB32(a, r, g, b);
107 } 104 }
108 105
109 void fillCanvas(SkCanvas* canvas) { 106 static void fillCanvas(SkCanvas* canvas) {
110 static SkBitmap bmp; 107 static SkBitmap bmp;
111 if (bmp.isNull()) { 108 if (bmp.isNull()) {
112 bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H); 109 bmp.setConfig(SkBitmap::kARGB_8888_Config, DEV_W, DEV_H);
113 SkDEBUGCODE(bool alloc =) bmp.allocPixels(); 110 SkDEBUGCODE(bool alloc =) bmp.allocPixels();
114 SkASSERT(alloc); 111 SkASSERT(alloc);
115 SkAutoLockPixels alp(bmp); 112 SkAutoLockPixels alp(bmp);
116 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels()); 113 intptr_t pixels = reinterpret_cast<intptr_t>(bmp.getPixels());
117 for (int y = 0; y < DEV_H; ++y) { 114 for (int y = 0; y < DEV_H; ++y) {
118 for (int x = 0; x < DEV_W; ++x) { 115 for (int x = 0; x < DEV_W; ++x) {
119 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp .rowBytes() + x * bmp.bytesPerPixel()); 116 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bmp .rowBytes() + x * bmp.bytesPerPixel());
120 *pixel = getCanvasColor(x, y); 117 *pixel = getCanvasColor(x, y);
121 } 118 }
122 } 119 }
123 } 120 }
124 canvas->save(); 121 canvas->save();
125 canvas->setMatrix(SkMatrix::I()); 122 canvas->setMatrix(SkMatrix::I());
126 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op); 123 canvas->clipRect(DEV_RECT_S, SkRegion::kReplace_Op);
127 SkPaint paint; 124 SkPaint paint;
128 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 125 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
129 canvas->drawBitmap(bmp, 0, 0, &paint); 126 canvas->drawBitmap(bmp, 0, 0, &paint);
130 canvas->restore(); 127 canvas->restore();
131 } 128 }
132 129
133 void fillBitmap(SkBitmap* bitmap) { 130 static void fillBitmap(SkBitmap* bitmap) {
134 SkASSERT(bitmap->lockPixelsAreWritable()); 131 SkASSERT(bitmap->lockPixelsAreWritable());
135 SkAutoLockPixels alp(*bitmap); 132 SkAutoLockPixels alp(*bitmap);
136 int w = bitmap->width(); 133 int w = bitmap->width();
137 int h = bitmap->height(); 134 int h = bitmap->height();
138 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels()); 135 intptr_t pixels = reinterpret_cast<intptr_t>(bitmap->getPixels());
139 for (int y = 0; y < h; ++y) { 136 for (int y = 0; y < h; ++y) {
140 for (int x = 0; x < w; ++x) { 137 for (int x = 0; x < w; ++x) {
141 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap- >rowBytes() + x * bitmap->bytesPerPixel()); 138 SkPMColor* pixel = reinterpret_cast<SkPMColor*>(pixels + y * bitmap- >rowBytes() + x * bitmap->bytesPerPixel());
142 *pixel = getBitmapColor(x, y, w); 139 *pixel = getBitmapColor(x, y, w);
143 } 140 }
144 } 141 }
145 } 142 }
146 143
147 bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) { 144 static bool checkPixel(SkPMColor a, SkPMColor b, bool didPremulConversion) {
148 if (!didPremulConversion) { 145 if (!didPremulConversion) {
149 return a == b; 146 return a == b;
150 } 147 }
151 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a)); 148 int32_t aA = static_cast<int32_t>(SkGetPackedA32(a));
152 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a)); 149 int32_t aR = static_cast<int32_t>(SkGetPackedR32(a));
153 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a)); 150 int32_t aG = static_cast<int32_t>(SkGetPackedG32(a));
154 int32_t aB = SkGetPackedB32(a); 151 int32_t aB = SkGetPackedB32(a);
155 152
156 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b)); 153 int32_t bA = static_cast<int32_t>(SkGetPackedA32(b));
157 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b)); 154 int32_t bR = static_cast<int32_t>(SkGetPackedR32(b));
158 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b)); 155 int32_t bG = static_cast<int32_t>(SkGetPackedG32(b));
159 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b)); 156 int32_t bB = static_cast<int32_t>(SkGetPackedB32(b));
160 157
161 return aA == bA && 158 return aA == bA &&
162 SkAbs32(aR - bR) <= 1 && 159 SkAbs32(aR - bR) <= 1 &&
163 SkAbs32(aG - bG) <= 1 && 160 SkAbs32(aG - bG) <= 1 &&
164 SkAbs32(aB - bB) <= 1; 161 SkAbs32(aB - bB) <= 1;
165 } 162 }
166 163
167 // checks the bitmap contains correct pixels after the readPixels 164 // checks the bitmap contains correct pixels after the readPixels
168 // if the bitmap was prefilled with pixels it checks that these weren't 165 // if the bitmap was prefilled with pixels it checks that these weren't
169 // overwritten in the area outside the readPixels. 166 // overwritten in the area outside the readPixels.
170 bool checkRead(skiatest::Reporter* reporter, 167 static bool checkRead(skiatest::Reporter* reporter,
171 const SkBitmap& bitmap, 168 const SkBitmap& bitmap,
172 int x, int y, 169 int x, int y,
173 bool checkCanvasPixels, 170 bool checkCanvasPixels,
174 bool checkBitmapPixels, 171 bool checkBitmapPixels,
175 SkCanvas::Config8888 config8888) { 172 SkCanvas::Config8888 config8888) {
176 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config()); 173 SkASSERT(SkBitmap::kARGB_8888_Config == bitmap.config());
177 SkASSERT(!bitmap.isNull()); 174 SkASSERT(!bitmap.isNull());
178 SkASSERT(checkCanvasPixels || checkBitmapPixels); 175 SkASSERT(checkCanvasPixels || checkBitmapPixels);
179 176
180 int bw = bitmap.width(); 177 int bw = bitmap.width();
181 int bh = bitmap.height(); 178 int bh = bitmap.height();
182 179
183 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh); 180 SkIRect srcRect = SkIRect::MakeXYWH(x, y, bw, bh);
184 SkIRect clippedSrcRect = DEV_RECT; 181 SkIRect clippedSrcRect = DEV_RECT;
185 if (!clippedSrcRect.intersect(srcRect)) { 182 if (!clippedSrcRect.intersect(srcRect)) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 enum BitmapInit { 216 enum BitmapInit {
220 kFirstBitmapInit = 0, 217 kFirstBitmapInit = 0,
221 218
222 kNoPixels_BitmapInit = kFirstBitmapInit, 219 kNoPixels_BitmapInit = kFirstBitmapInit,
223 kTight_BitmapInit, 220 kTight_BitmapInit,
224 kRowBytes_BitmapInit, 221 kRowBytes_BitmapInit,
225 222
226 kBitmapInitCnt 223 kBitmapInitCnt
227 }; 224 };
228 225
229 BitmapInit nextBMI(BitmapInit bmi) { 226 static BitmapInit nextBMI(BitmapInit bmi) {
230 int x = bmi; 227 int x = bmi;
231 return static_cast<BitmapInit>(++x); 228 return static_cast<BitmapInit>(++x);
232 } 229 }
233 230
234 231 static void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init) {
235 void init_bitmap(SkBitmap* bitmap, const SkIRect& rect, BitmapInit init) {
236 int w = rect.width(); 232 int w = rect.width();
237 int h = rect.height(); 233 int h = rect.height();
238 int rowBytes = 0; 234 int rowBytes = 0;
239 bool alloc = true; 235 bool alloc = true;
240 switch (init) { 236 switch (init) {
241 case kNoPixels_BitmapInit: 237 case kNoPixels_BitmapInit:
242 alloc = false; 238 alloc = false;
243 case kTight_BitmapInit: 239 case kTight_BitmapInit:
244 break; 240 break;
245 case kRowBytes_BitmapInit: 241 case kRowBytes_BitmapInit:
246 rowBytes = w * sizeof(SkPMColor) + 16 * sizeof(SkPMColor); 242 rowBytes = w * sizeof(SkPMColor) + 16 * sizeof(SkPMColor);
247 break; 243 break;
248 default: 244 default:
249 SkASSERT(0); 245 SkASSERT(0);
250 break; 246 break;
251 } 247 }
252 bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes); 248 bitmap->setConfig(SkBitmap::kARGB_8888_Config, w, h, rowBytes);
253 if (alloc) { 249 if (alloc) {
254 bitmap->allocPixels(); 250 bitmap->allocPixels();
255 } 251 }
256 } 252 }
257 253
258 void ReadPixelsTest(skiatest::Reporter* reporter, GrContextFactory* factory) { 254 static void ReadPixelsTest(skiatest::Reporter* reporter, GrContextFactory* facto ry) {
259 const SkIRect testRects[] = { 255 const SkIRect testRects[] = {
260 // entire thing 256 // entire thing
261 DEV_RECT, 257 DEV_RECT,
262 // larger on all sides 258 // larger on all sides
263 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10), 259 SkIRect::MakeLTRB(-10, -10, DEV_W + 10, DEV_H + 10),
264 // fully contained 260 // fully contained
265 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4), 261 SkIRect::MakeLTRB(DEV_W / 4, DEV_H / 4, 3 * DEV_W / 4, 3 * DEV_H / 4),
266 // outside top left 262 // outside top left
267 SkIRect::MakeLTRB(-10, -10, -1, -1), 263 SkIRect::MakeLTRB(-10, -10, -1, -1),
268 // touching top left corner 264 // touching top left corner
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 clippedRect.fTop, true, false, 399 clippedRect.fTop, true, false,
404 SkCanvas::kNative_Premul_Config8888); 400 SkCanvas::kNative_Premul_Config8888);
405 } else { 401 } else {
406 REPORTER_ASSERT(reporter, !success); 402 REPORTER_ASSERT(reporter, !success);
407 } 403 }
408 } 404 }
409 } 405 }
410 } 406 }
411 } 407 }
412 } 408 }
413 }
414 409
415 #include "TestClassDef.h" 410 #include "TestClassDef.h"
416 DEFINE_GPUTESTCLASS("ReadPixels", ReadPixelsTestClass, ReadPixelsTest) 411 DEFINE_GPUTESTCLASS("ReadPixels", ReadPixelsTestClass, ReadPixelsTest)
OLDNEW
« no previous file with comments | « tests/PremulAlphaRoundTripTest.cpp ('k') | tests/TileGridTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698