| 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 expectSameGenID Whether the genIDs should be the same if success is t
rue. |
| 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 expectSameGenID) { |
| 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 (expectSameGenID) { |
| 54 // exactly, in which case the IDs should be the same, but sometimes
we do a bitmap draw, | |
| 55 // in which case the IDs should not be the same. Is there any way to
determine which is | |
| 56 // the case at this point? | |
| 57 if (deepCopy) { | |
| 58 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera
tionID()); | 54 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera
tionID()); |
| 55 } else { |
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 161 } |
| 158 | 162 |
| 159 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); | 163 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); |
| 160 if (success != canSucceed) { | 164 if (success != canSucceed) { |
| 161 ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s " | 165 ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s " |
| 162 "returned %s, but canCopyTo returned %s", | 166 "returned %s, but canCopyTo returned %s", |
| 163 gConfigName[i], gConfigName[j], boolStr(success), | 167 gConfigName[i], gConfigName[j], boolStr(success), |
| 164 boolStr(canSucceed)); | 168 boolStr(canSucceed)); |
| 165 } | 169 } |
| 166 | 170 |
| 167 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds
t); | 171 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds
t, true); |
| 168 | 172 |
| 169 // Test copying the subset bitmap, using both copyTo and deepCop
yTo. | 173 // Test copying the subset bitmap, using both copyTo and deepCop
yTo. |
| 170 if (extracted) { | 174 if (extracted) { |
| 171 SkBitmap subsetCopy; | 175 SkBitmap subsetCopy; |
| 172 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); | 176 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); |
| 173 REPORTER_ASSERT(reporter, success == expected); | 177 REPORTER_ASSERT(reporter, success == expected); |
| 174 REPORTER_ASSERT(reporter, success == canSucceed); | 178 REPORTER_ASSERT(reporter, success == canSucceed); |
| 175 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, | 179 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, |
| 176 false); | 180 true); |
| 177 | 181 |
| 178 // Reset the bitmap so that a failed copyTo will leave it in
the expected state. | 182 // Reset the bitmap so that a failed copyTo will leave it in
the expected state. |
| 179 subsetCopy.reset(); | 183 subsetCopy.reset(); |
| 180 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); | 184 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); |
| 181 REPORTER_ASSERT(reporter, success == expected); | 185 REPORTER_ASSERT(reporter, success == expected); |
| 182 REPORTER_ASSERT(reporter, success == canSucceed); | 186 REPORTER_ASSERT(reporter, success == canSucceed); |
| 183 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, | 187 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, |
| 184 true); | 188 true); |
| 189 |
| 190 // Now set a bitmap to be a subset that will share the same
pixelref. |
| 191 // This allows testing another case of cloning the genID. Wh
en calling copyTo |
| 192 // on a bitmap representing a subset of its pixelref, the re
sulting pixelref |
| 193 // should not share the genID, since we only copied the subs
et. |
| 194 SkBitmap trueSubset; |
| 195 // FIXME: Once https://codereview.chromium.org/109023008/ la
nds, call |
| 196 // trueSubset.installPixelRef(src.pixelRef(), subset); |
| 197 trueSubset.setConfig(gPairs[i].fConfig, W/2, H/2); |
| 198 trueSubset.setPixelRef(src.pixelRef(), W/2, H/2); |
| 199 |
| 200 subsetCopy.reset(); |
| 201 success = trueSubset.copyTo(&subsetCopy, gPairs[j].fConfig); |
| 202 REPORTER_ASSERT(reporter, success == expected); |
| 203 REPORTER_ASSERT(reporter, success == canSucceed); |
| 204 TestIndividualCopy(reporter, gPairs[j].fConfig, success, tru
eSubset, subsetCopy, |
| 205 false); |
| 206 |
| 207 // deepCopyTo copies the entire pixelref, even if the bitmap
only represents |
| 208 // a subset. Therefore, the result should share the same gen
ID. |
| 209 subsetCopy.reset(); |
| 210 success = trueSubset.deepCopyTo(&subsetCopy, gPairs[j].fConf
ig); |
| 211 REPORTER_ASSERT(reporter, success == expected); |
| 212 REPORTER_ASSERT(reporter, success == canSucceed); |
| 213 TestIndividualCopy(reporter, gPairs[j].fConfig, success, tru
eSubset, subsetCopy, |
| 214 true); |
| 185 } | 215 } |
| 186 } // for (size_t j = ... | 216 } // for (size_t j = ... |
| 187 } // for (size_t i = ... | 217 } // for (size_t i = ... |
| 188 } // GrContextFactory::GLContextType | 218 } // GrContextFactory::GLContextType |
| 189 } | 219 } |
| 190 | 220 |
| 191 #include "TestClassDef.h" | 221 #include "TestClassDef.h" |
| 192 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) | 222 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) |
| 193 | 223 |
| 194 #endif | 224 #endif |
| OLD | NEW |