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

Side by Side Diff: tests/ReadWriteAlphaTest.cpp

Issue 1662533002: Fix printfs for Windows and undo speculative test disable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | 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
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "Test.h"
9 9
10 // This test is specific to the GPU backend. 10 // This test is specific to the GPU backend.
(...skipping 19 matching lines...) Expand all
30 return; 30 return;
31 } 31 }
32 } 32 }
33 } 33 }
34 } 34 }
35 35
36 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { 36 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) {
37 unsigned char alphaData[X_SIZE * Y_SIZE]; 37 unsigned char alphaData[X_SIZE * Y_SIZE];
38 38
39 bool match; 39 bool match;
40 #ifdef SK_BUILD_FOR_WIN // TODO: Figure out why this breaks on Windows.
41 static const size_t kRowBytes[] = {0, X_SIZE};
42 #else
43 static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1}; 40 static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1};
44 #endif
45 for (int rt = 0; rt < 2; ++rt) { 41 for (int rt = 0; rt < 2; ++rt) {
46 GrSurfaceDesc desc; 42 GrSurfaceDesc desc;
47 // let Skia know we will be using this texture as a render target 43 // let Skia know we will be using this texture as a render target
48 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlag s; 44 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlag s;
49 // it is a single channel texture 45 // it is a single channel texture
50 desc.fConfig = kAlpha_8_GrPixelConfig; 46 desc.fConfig = kAlpha_8_GrPixelConfig;
51 desc.fWidth = X_SIZE; 47 desc.fWidth = X_SIZE;
52 desc.fHeight = Y_SIZE; 48 desc.fHeight = Y_SIZE;
53 49
54 // We are initializing the texture with zeros here 50 // We are initializing the texture with zeros here
(...skipping 23 matching lines...) Expand all
78 SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y _SIZE]); 74 SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y _SIZE]);
79 // clear readback to something non-zero so we can detect readback fa ilures 75 // clear readback to something non-zero so we can detect readback fa ilures
80 memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); 76 memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE);
81 77
82 // read the texture back 78 // read the texture back
83 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, 79 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
84 readback.get(), rowBytes); 80 readback.get(), rowBytes);
85 81
86 // make sure the original & read back versions match 82 // make sure the original & read back versions match
87 SkString msg; 83 SkString msg;
88 msg.printf("rt:%d, rb:%zd", rt, rowBytes); 84 msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes));
89 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZer oRowBytes, 85 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZer oRowBytes,
90 alphaData, msg); 86 alphaData, msg);
91 87
92 // Now try writing on the single channel texture (if we could create as a RT). 88 // Now try writing on the single channel texture (if we could create as a RT).
93 if (texture->asRenderTarget()) { 89 if (texture->asRenderTarget()) {
94 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); 90 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
95 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create( 91 SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(
96 texture->asRenderTarget(), &props, SkGpuDevice::kUninit_Init Contents)); 92 texture->asRenderTarget(), &props, SkGpuDevice::kUninit_Init Contents));
97 SkCanvas canvas(device); 93 SkCanvas canvas(device);
98 94
99 SkPaint paint; 95 SkPaint paint;
100 96
101 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SI ZE + 10); 97 const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SI ZE + 10);
102 98
103 paint.setColor(SK_ColorWHITE); 99 paint.setColor(SK_ColorWHITE);
104 100
105 canvas.drawRect(rect, paint); 101 canvas.drawRect(rect, paint);
106 102
107 memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE); 103 memset(readback.get(), 0x1, nonZeroRowBytes * Y_SIZE);
108 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfi g, readback.get(), 104 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfi g, readback.get(),
109 rowBytes); 105 rowBytes);
110 106
111 match = true; 107 match = true;
112 for (int y = 0; y < Y_SIZE && match; ++y) { 108 for (int y = 0; y < Y_SIZE && match; ++y) {
113 for (int x = 0; x < X_SIZE && match; ++x) { 109 for (int x = 0; x < X_SIZE && match; ++x) {
114 uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x ]; 110 uint8_t rbValue = readback.get()[y * nonZeroRowBytes + x ];
115 if (0xFF != rbValue) { 111 if (0xFF != rbValue) {
116 ERRORF(reporter, 112 ERRORF(reporter,
117 "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x" 113 "Failed alpha readback after clear. Expected: 0xFF, Got: 0x%02x"
118 " at (%d,%d), rb:%zd", rbValue, x, y, rowByte s); 114 " at (%d,%d), rb:%d", rbValue, x, y, SkToU32( rowBytes));
119 match = false; 115 match = false;
120 } 116 }
121 } 117 }
122 } 118 }
123 } 119 }
124 } 120 }
125 } 121 }
126 122
127 static const GrPixelConfig kRGBAConfigs[] { 123 static const GrPixelConfig kRGBAConfigs[] {
128 kRGBA_8888_GrPixelConfig, 124 kRGBA_8888_GrPixelConfig,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]); 165 SkAutoTDeleteArray<uint8_t> readback(new uint8_t[nonZeroRowBytes * Y_SIZE]);
170 // Clear so we don't accidentally see values from previous itera tion. 166 // Clear so we don't accidentally see values from previous itera tion.
171 memset(readback.get(), 0x0, nonZeroRowBytes * Y_SIZE); 167 memset(readback.get(), 0x0, nonZeroRowBytes * Y_SIZE);
172 168
173 // read the texture back 169 // read the texture back
174 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, kAlpha_8_Gr PixelConfig, 170 texture->readPixels(0, 0, desc.fWidth, desc.fHeight, kAlpha_8_Gr PixelConfig,
175 readback.get(), rowBytes); 171 readback.get(), rowBytes);
176 172
177 // make sure the original & read back versions match 173 // make sure the original & read back versions match
178 SkString msg; 174 SkString msg;
179 msg.printf("rt:%d, rb:%zd", rt, rowBytes); 175 msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes));
180 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no nZeroRowBytes, 176 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no nZeroRowBytes,
181 alphaData, msg); 177 alphaData, msg);
182 } 178 }
183 } 179 }
184 } 180 }
185 } 181 }
186 182
187 #endif 183 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698