OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 const char* fValid; | 33 const char* fValid; |
34 }; | 34 }; |
35 | 35 |
36 /** | 36 /** |
37 * Check to ensure that copying a GPU-backed SkBitmap behaved as expected. | 37 * Check to ensure that copying a GPU-backed SkBitmap behaved as expected. |
38 * @param reporter Used to report failures. | 38 * @param reporter Used to report failures. |
39 * @param desiredConfig Config being copied to. If the copy succeeded, dst must have this Config. | 39 * @param desiredConfig Config being copied to. If the copy succeeded, dst must have this Config. |
40 * @param success True if the copy succeeded. | 40 * @param success True if the copy succeeded. |
41 * @param src A GPU-backed SkBitmap that had copyTo or deepCopyTo called on it. | 41 * @param src A GPU-backed SkBitmap that had copyTo or deepCopyTo called on it. |
42 * @param dst SkBitmap that was copied to. | 42 * @param dst SkBitmap that was copied to. |
43 * @param deepCopy True if deepCopyTo was used; false if copyTo was used. | 43 * @param expectChangedGenID Whether the genIDs should be different if success is true. |
44 */ | 44 */ |
45 static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con fig desiredConfig, | 45 static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con fig desiredConfig, |
46 const bool success, const SkBitmap& src, const Sk Bitmap& dst, | 46 const bool success, const SkBitmap& src, const Sk Bitmap& dst, |
47 const bool deepCopy = true) { | 47 const bool expectChangedGenID) { |
mtklein
2014/01/09 15:58:07
I think I might find this easier to follow inverte
scroggo
2014/01/09 20:45:23
Agreed. Inverted.
| |
48 if (success) { | 48 if (success) { |
49 REPORTER_ASSERT(reporter, src.width() == dst.width()); | 49 REPORTER_ASSERT(reporter, src.width() == dst.width()); |
50 REPORTER_ASSERT(reporter, src.height() == dst.height()); | 50 REPORTER_ASSERT(reporter, src.height() == dst.height()); |
51 REPORTER_ASSERT(reporter, dst.config() == desiredConfig); | 51 REPORTER_ASSERT(reporter, dst.config() == desiredConfig); |
52 if (src.config() == dst.config()) { | 52 if (src.config() == dst.config()) { |
53 // FIXME: When calling copyTo (so deepCopy is false here), sometimes we copy the pixels | 53 if (expectChangedGenID) { |
mtklein
2014/01/09 15:58:07
Don't know if you find this clearer or not, but I
scroggo
2014/01/09 20:45:23
I find it clever but less clear.
| |
54 // exactly, in which case the IDs should be the same, but sometimes we do a bitmap draw, | 54 REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGenera tionID()); |
55 // in which case the IDs should not be the same. Is there any way to determine which is | 55 } else { |
56 // the case at this point? | |
57 if (deepCopy) { | |
58 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera tionID()); | 56 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera tionID()); |
59 } | 57 } |
60 REPORTER_ASSERT(reporter, src.pixelRef() != NULL && dst.pixelRef() ! = NULL); | 58 REPORTER_ASSERT(reporter, src.pixelRef() != NULL && dst.pixelRef() ! = NULL); |
61 | 59 |
62 // Do read backs and make sure that the two are the same. | 60 // Do read backs and make sure that the two are the same. |
63 SkBitmap srcReadBack, dstReadBack; | 61 SkBitmap srcReadBack, dstReadBack; |
64 { | 62 { |
65 SkASSERT(src.getTexture() != NULL); | 63 SkASSERT(src.getTexture() != NULL); |
66 bool readBack = src.pixelRef()->readPixels(&srcReadBack); | 64 const SkIPoint origin = src.pixelRefOrigin(); |
65 const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, | |
66 src.width(), src.height ()); | |
67 bool readBack = src.pixelRef()->readPixels(&srcReadBack, &subset ); | |
67 REPORTER_ASSERT(reporter, readBack); | 68 REPORTER_ASSERT(reporter, readBack); |
68 } | 69 } |
69 if (dst.getTexture() != NULL) { | 70 if (dst.getTexture() != NULL) { |
70 bool readBack = dst.pixelRef()->readPixels(&dstReadBack); | 71 const SkIPoint origin = dst.pixelRefOrigin(); |
72 const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, | |
73 dst.width(), dst.height ()); | |
74 bool readBack = dst.pixelRef()->readPixels(&dstReadBack, &subset ); | |
71 REPORTER_ASSERT(reporter, readBack); | 75 REPORTER_ASSERT(reporter, readBack); |
72 } else { | 76 } else { |
73 // If dst is not a texture, do a copy instead, to the same confi g as srcReadBack. | 77 // If dst is not a texture, do a copy instead, to the same confi g as srcReadBack. |
74 bool copy = dst.copyTo(&dstReadBack, srcReadBack.config()); | 78 bool copy = dst.copyTo(&dstReadBack, srcReadBack.config()); |
75 REPORTER_ASSERT(reporter, copy); | 79 REPORTER_ASSERT(reporter, copy); |
76 } | 80 } |
77 | 81 |
78 SkAutoLockPixels srcLock(srcReadBack); | 82 SkAutoLockPixels srcLock(srcReadBack); |
79 SkAutoLockPixels dstLock(dstReadBack); | 83 SkAutoLockPixels dstLock(dstReadBack); |
80 REPORTER_ASSERT(reporter, srcReadBack.readyToDraw() && dstReadBack.r eadyToDraw()); | 84 REPORTER_ASSERT(reporter, srcReadBack.readyToDraw() && dstReadBack.r eadyToDraw()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); | 164 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); |
161 if (success != canSucceed) { | 165 if (success != canSucceed) { |
162 SkString str; | 166 SkString str; |
163 str.printf("SkBitmap::deepCopyTo from %s to %s returned %s," | 167 str.printf("SkBitmap::deepCopyTo from %s to %s returned %s," |
164 "but canCopyTo returned %s", | 168 "but canCopyTo returned %s", |
165 gConfigName[i], gConfigName[j], boolStr(success), | 169 gConfigName[i], gConfigName[j], boolStr(success), |
166 boolStr(canSucceed)); | 170 boolStr(canSucceed)); |
167 reporter->reportFailed(str); | 171 reporter->reportFailed(str); |
168 } | 172 } |
169 | 173 |
170 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds t); | 174 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds t, false); |
171 | 175 |
172 // Test copying the subset bitmap, using both copyTo and deepCop yTo. | 176 // Test copying the subset bitmap, using both copyTo and deepCop yTo. |
173 if (extracted) { | 177 if (extracted) { |
174 SkBitmap subsetCopy; | 178 SkBitmap subsetCopy; |
175 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); | 179 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); |
176 REPORTER_ASSERT(reporter, success == expected); | 180 REPORTER_ASSERT(reporter, success == expected); |
177 REPORTER_ASSERT(reporter, success == canSucceed); | 181 REPORTER_ASSERT(reporter, success == canSucceed); |
178 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub set, subsetCopy, | 182 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub set, subsetCopy, |
179 false); | 183 false); |
180 | 184 |
181 // Reset the bitmap so that a failed copyTo will leave it in the expected state. | 185 // Reset the bitmap so that a failed copyTo will leave it in the expected state. |
182 subsetCopy.reset(); | 186 subsetCopy.reset(); |
183 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); | 187 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); |
184 REPORTER_ASSERT(reporter, success == expected); | 188 REPORTER_ASSERT(reporter, success == expected); |
185 REPORTER_ASSERT(reporter, success == canSucceed); | 189 REPORTER_ASSERT(reporter, success == canSucceed); |
186 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub set, subsetCopy, | 190 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub set, subsetCopy, |
191 false); | |
192 | |
193 // Now set a bitmap to be a subset that will share the same pixelref. | |
194 // This allows testing another case of cloning the genID. Wh en calling copyTo | |
195 // on a bitmap representing a subset of its pixelref, the re sulting pixelref | |
196 // should not share the genID, since we only copied the subs et. | |
197 SkBitmap trueSubset; | |
198 // FIXME: Once https://codereview.chromium.org/109023008/ la nds, call | |
199 // trueSubset.installPixelRef(src.pixelRef(), subset); | |
200 trueSubset.setConfig(gPairs[i].fConfig, W/2, H/2); | |
201 trueSubset.setPixelRef(src.pixelRef(), W/2, H/2); | |
202 | |
203 subsetCopy.reset(); | |
204 success = trueSubset.copyTo(&subsetCopy, gPairs[j].fConfig); | |
205 REPORTER_ASSERT(reporter, success == expected); | |
206 REPORTER_ASSERT(reporter, success == canSucceed); | |
207 TestIndividualCopy(reporter, gPairs[j].fConfig, success, tru eSubset, subsetCopy, | |
187 true); | 208 true); |
209 | |
210 // deepCopyTo copies the entire pixelref, even if the bitmap only represents | |
211 // a subset. Therefore, the result should share the same gen ID. | |
212 subsetCopy.reset(); | |
213 success = trueSubset.deepCopyTo(&subsetCopy, gPairs[j].fConf ig); | |
214 REPORTER_ASSERT(reporter, success == expected); | |
215 REPORTER_ASSERT(reporter, success == canSucceed); | |
216 TestIndividualCopy(reporter, gPairs[j].fConfig, success, tru eSubset, subsetCopy, | |
217 false); | |
188 } | 218 } |
189 } // for (size_t j = ... | 219 } // for (size_t j = ... |
190 } // for (size_t i = ... | 220 } // for (size_t i = ... |
191 } // GrContextFactory::GLContextType | 221 } // GrContextFactory::GLContextType |
192 } | 222 } |
193 | 223 |
194 #include "TestClassDef.h" | 224 #include "TestClassDef.h" |
195 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) | 225 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) |
196 | 226 |
197 #endif | 227 #endif |
OLD | NEW |