OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 if (e != a) { | 26 if (e != a) { |
27 ERRORF(reporter, | 27 ERRORF(reporter, |
28 "Failed alpha readback. Expected: 0x%02x, Got: 0x%02x at
(%d,%d), %s", | 28 "Failed alpha readback. Expected: 0x%02x, Got: 0x%02x at
(%d,%d), %s", |
29 e, a, x, y, extraMsg.c_str()); | 29 e, a, x, y, extraMsg.c_str()); |
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, ctxInfo) { |
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 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}; |
41 for (int rt = 0; rt < 2; ++rt) { | 41 for (int rt = 0; rt < 2; ++rt) { |
42 GrSurfaceDesc desc; | 42 GrSurfaceDesc desc; |
43 // 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 |
44 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlag
s; | 44 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlag
s; |
45 // it is a single channel texture | 45 // it is a single channel texture |
46 desc.fConfig = kAlpha_8_GrPixelConfig; | 46 desc.fConfig = kAlpha_8_GrPixelConfig; |
47 desc.fWidth = X_SIZE; | 47 desc.fWidth = X_SIZE; |
48 desc.fHeight = Y_SIZE; | 48 desc.fHeight = Y_SIZE; |
49 | 49 |
50 // We are initializing the texture with zeros here | 50 // We are initializing the texture with zeros here |
51 memset(alphaData, 0, X_SIZE * Y_SIZE); | 51 memset(alphaData, 0, X_SIZE * Y_SIZE); |
52 SkAutoTUnref<GrTexture> texture( | 52 SkAutoTUnref<GrTexture> texture( |
53 context->textureProvider()->createTexture(desc, SkBudgeted::kNo , al
phaData, 0)); | 53 ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgete
d::kNo , alphaData, |
| 54 0)); |
54 if (!texture) { | 55 if (!texture) { |
55 if (!rt) { | 56 if (!rt) { |
56 ERRORF(reporter, "Could not create alpha texture."); | 57 ERRORF(reporter, "Could not create alpha texture."); |
57 } | 58 } |
58 continue; | 59 continue; |
59 } | 60 } |
60 | 61 |
61 // create a distinctive texture | 62 // create a distinctive texture |
62 for (int y = 0; y < Y_SIZE; ++y) { | 63 for (int y = 0; y < Y_SIZE; ++y) { |
63 for (int x = 0; x < X_SIZE; ++x) { | 64 for (int x = 0; x < X_SIZE; ++x) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 desc.fHeight = Y_SIZE; | 144 desc.fHeight = Y_SIZE; |
144 | 145 |
145 uint32_t rgbaData[X_SIZE * Y_SIZE]; | 146 uint32_t rgbaData[X_SIZE * Y_SIZE]; |
146 // Make the alpha channel of the rgba texture come from alphaData. | 147 // Make the alpha channel of the rgba texture come from alphaData. |
147 for (int y = 0; y < Y_SIZE; ++y) { | 148 for (int y = 0; y < Y_SIZE; ++y) { |
148 for (int x = 0; x < X_SIZE; ++x) { | 149 for (int x = 0; x < X_SIZE; ++x) { |
149 rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaDat
a[y * X_SIZE + x]); | 150 rgbaData[y * X_SIZE + x] = GrColorPackRGBA(6, 7, 8, alphaDat
a[y * X_SIZE + x]); |
150 } | 151 } |
151 } | 152 } |
152 SkAutoTUnref<GrTexture> texture( | 153 SkAutoTUnref<GrTexture> texture( |
153 context->textureProvider()->createTexture(desc, SkBudgeted::kNo,
rgbaData, 0)); | 154 ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBud
geted::kNo, |
| 155 rgbaData, 0
)); |
154 if (!texture) { | 156 if (!texture) { |
155 // We always expect to be able to create a RGBA texture | 157 // We always expect to be able to create a RGBA texture |
156 if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) { | 158 if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) { |
157 ERRORF(reporter, "Failed to create RGBA texture."); | 159 ERRORF(reporter, "Failed to create RGBA texture."); |
158 } | 160 } |
159 continue; | 161 continue; |
160 } | 162 } |
161 | 163 |
162 for (auto rowBytes : kRowBytes) { | 164 for (auto rowBytes : kRowBytes) { |
163 size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; | 165 size_t nonZeroRowBytes = rowBytes ? rowBytes : X_SIZE; |
(...skipping 10 matching lines...) Expand all Loading... |
174 SkString msg; | 176 SkString msg; |
175 msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes)); | 177 msg.printf("rt:%d, rb:%d", rt, SkToU32(rowBytes)); |
176 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no
nZeroRowBytes, | 178 validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), no
nZeroRowBytes, |
177 alphaData, msg); | 179 alphaData, msg); |
178 } | 180 } |
179 } | 181 } |
180 } | 182 } |
181 } | 183 } |
182 | 184 |
183 #endif | 185 #endif |
OLD | NEW |