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

Side by Side Diff: tests/SwizzlerTest.cpp

Issue 1055743003: Swizzler changes Index8 and 565 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Cleaner testing Created 5 years, 8 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
« src/codec/SkSwizzler.h ('K') | « src/codec/SkSwizzler.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkSwizzler.h"
9 #include "Test.h"
10
11 static void check_fill(skiatest::Reporter* r,
12 SkColorType colorType,
13 uint32_t width,
14 uint32_t height,
15 uint32_t startRow,
16 size_t rowBytes,
17 size_t totalBytes,
18 uint32_t offset,
19 uint32_t colorOrIndex,
20 SkPMColor* colorTable) {
21
22 // Create fake image data where every byte has a value of 0
23 SkAutoTDelete<uint8_t> storage((uint8_t*) sk_malloc_throw(totalBytes));
24 memset(storage.get(), 0, totalBytes);
25 uint8_t* imageData = storage.get() + offset;
26
27 // Create fake image info (alpha type does not matter)
28 SkImageInfo imageInfo = SkImageInfo::Make(width, height, colorType, kUnknown _SkAlphaType);
29
30 // Fill image with the fill value starting at the indicated row
31 SkSwizzler::Fill(imageData, imageInfo, rowBytes, startRow, colorOrIndex, col orTable);
32
33 // Ensure that the pixels are filled properly
34 // The bots should catch any memory corruption
35 uint8_t* indexPtr = imageData + startRow * rowBytes;
36 uint32_t* colorPtr = (uint32_t*) indexPtr;
37 for (uint32_t y = startRow; y < height; y++) {
38 for (uint32_t x = 0; x < width; x++) {
39 if (kIndex_8_SkColorType == colorType) {
40 REPORTER_ASSERT(r, 0x1 == indexPtr[x]);
scroggo 2015/04/08 20:37:38 nit: make these constants?
msarett 2015/04/09 13:02:48 Done.
41 } else {
42 REPORTER_ASSERT(r, 0x22334455 == colorPtr[x]);
43 }
44 }
45 indexPtr += rowBytes;
46 colorPtr = (uint32_t*) indexPtr;
47 }
48 }
49
50 // Test Fill() with different combinations of dimensions, alignment, and padding
51 DEF_TEST(SwizzlerFill, r) {
52 // These are the values we will look for to indicate that the fill was succe ssful
53 uint8_t fillIndex = 0x1;
54 uint32_t fillColor = 0x22334455;
55
56 // Set up a color table
57 SkPMColor colorTable[fillIndex + 1];
58 memset(colorTable, 0, sizeof(SkPMColor) * (fillIndex + 1));
scroggo 2015/04/08 20:37:37 This seems extra complicated? Why not: colorTable
msarett 2015/04/09 13:02:48 Yeah, essentially it seemed weird to me to test wi
scroggo 2015/04/09 14:53:48 Sgtm. Please add a comment that explains why you'r
59 colorTable[fillIndex] = fillColor;
60
61 // Test on an invalid width and representative widths
62 const uint32_t widths[] = { 0, 10, 50 };
63
64 // In order to call Fill(), there must be at least one row to fill
65 // Test on the smallest possible height and representative heights
66 const uint32_t heights[] = { 1, 5, 10 };
67
68 // Test on interesting possibilities for row padding
69 const uint32_t paddings[] = { 0, 1, 2, 3, 4 };
70
71 // Iterate over test dimensions
72 for (uint32_t w = 0; w < SK_ARRAY_COUNT(widths); w++) {
scroggo 2015/04/08 20:37:37 I know I led you astray when I suggested this befo
msarett 2015/04/09 13:02:48 Excellent!
73 for (uint32_t h = 0; h < SK_ARRAY_COUNT(heights); h++) {
74 for (uint32_t p = 0; p < SK_ARRAY_COUNT(paddings); p++) {
75
76 // Calculate row bytes
77 uint32_t colorRowBytes = sizeof(SkPMColor) * widths[w] + padding s[p];
scroggo 2015/04/08 20:37:37 Same as: SkColorTypeBytesPerPixel(kN32) + paddin
msarett 2015/04/09 13:02:48 I think it is a little clearer!
78 uint32_t indexRowBytes = widths[w] + paddings[p];
79
80 // If there is padding, we can invent an offset to change the me mory alignment
81 for (uint32_t offset = p; offset <= p; offset++) {
scroggo 2015/04/08 20:37:37 Wait, isn't this just a loop that only executes on
msarett 2015/04/09 13:02:48 Yes this is a bug. I intended offset to go from 0
82
83 // Calculate total bytes
84 // The last row may not be padded. We will always assume th at it is in fact
85 // not padded and test on the smallest possible value for to tal bytes.
86 uint32_t colorTotalBytes = colorRowBytes * heights[h] - padd ings[p] + offset;
scroggo 2015/04/08 20:37:38 It seems like this is SkImageInfo colorInfo = SkI
msarett 2015/04/09 13:02:48 I think it is better. I need to be better at bein
87 uint32_t indexTotalBytes = indexRowBytes * heights[h] - padd ings[p] + offset;
88
89 // Test all possible start rows
90 for (uint32_t startRow = 0; startRow < heights[h]; startRow+ +) {
91
92 // Fill with an index that we use to look up a color
93 check_fill(r, kN32_SkColorType, widths[w], heights[h], s tartRow,
94 colorRowBytes, colorTotalBytes, offset, fillInde x,
95 colorTable);
96
97 // Fill with a color
98 check_fill(r, kN32_SkColorType, widths[w], heights[h], s tartRow,
99 colorRowBytes, colorTotalBytes, offset, fillColo r,
100 NULL);
101
102 // Fill with an index
103 check_fill(r, kIndex_8_SkColorType, widths[w], heights[h ], startRow,
104 indexRowBytes, indexTotalBytes, offset, fillInde x,
105 NULL);
106 }
107 }
108 }
109 }
110 }
111 }
OLDNEW
« src/codec/SkSwizzler.h ('K') | « src/codec/SkSwizzler.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698