Chromium Code Reviews| Index: tests/GpuBitmapCopyTest.cpp |
| diff --git a/tests/GpuBitmapCopyTest.cpp b/tests/GpuBitmapCopyTest.cpp |
| index 6e1d74dd977c3f942bfd557fc6f74154fbe0db25..1501d474ac885a48cfd1c3b912a344231550840d 100644 |
| --- a/tests/GpuBitmapCopyTest.cpp |
| +++ b/tests/GpuBitmapCopyTest.cpp |
| @@ -40,21 +40,19 @@ struct Pair { |
| * @param success True if the copy succeeded. |
| * @param src A GPU-backed SkBitmap that had copyTo or deepCopyTo called on it. |
| * @param dst SkBitmap that was copied to. |
| - * @param deepCopy True if deepCopyTo was used; false if copyTo was used. |
| + * @param expectChangedGenID Whether the genIDs should be different if success is true. |
| */ |
| static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Config desiredConfig, |
| const bool success, const SkBitmap& src, const SkBitmap& dst, |
| - const bool deepCopy = true) { |
| + 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.
|
| if (success) { |
| REPORTER_ASSERT(reporter, src.width() == dst.width()); |
| REPORTER_ASSERT(reporter, src.height() == dst.height()); |
| REPORTER_ASSERT(reporter, dst.config() == desiredConfig); |
| if (src.config() == dst.config()) { |
| - // FIXME: When calling copyTo (so deepCopy is false here), sometimes we copy the pixels |
| - // exactly, in which case the IDs should be the same, but sometimes we do a bitmap draw, |
| - // in which case the IDs should not be the same. Is there any way to determine which is |
| - // the case at this point? |
| - if (deepCopy) { |
| + 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.
|
| + REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGenerationID()); |
| + } else { |
| REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenerationID()); |
| } |
| REPORTER_ASSERT(reporter, src.pixelRef() != NULL && dst.pixelRef() != NULL); |
| @@ -63,11 +61,17 @@ static void TestIndividualCopy(skiatest::Reporter* reporter, const SkBitmap::Con |
| SkBitmap srcReadBack, dstReadBack; |
| { |
| SkASSERT(src.getTexture() != NULL); |
| - bool readBack = src.pixelRef()->readPixels(&srcReadBack); |
| + const SkIPoint origin = src.pixelRefOrigin(); |
| + const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, |
| + src.width(), src.height()); |
| + bool readBack = src.pixelRef()->readPixels(&srcReadBack, &subset); |
| REPORTER_ASSERT(reporter, readBack); |
| } |
| if (dst.getTexture() != NULL) { |
| - bool readBack = dst.pixelRef()->readPixels(&dstReadBack); |
| + const SkIPoint origin = dst.pixelRefOrigin(); |
| + const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, |
| + dst.width(), dst.height()); |
| + bool readBack = dst.pixelRef()->readPixels(&dstReadBack, &subset); |
| REPORTER_ASSERT(reporter, readBack); |
| } else { |
| // If dst is not a texture, do a copy instead, to the same config as srcReadBack. |
| @@ -167,7 +171,7 @@ static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* fa |
| reporter->reportFailed(str); |
| } |
| - TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, dst); |
| + TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, dst, false); |
| // Test copying the subset bitmap, using both copyTo and deepCopyTo. |
| if (extracted) { |
| @@ -184,7 +188,33 @@ static void TestGpuBitmapCopy(skiatest::Reporter* reporter, GrContextFactory* fa |
| REPORTER_ASSERT(reporter, success == expected); |
| REPORTER_ASSERT(reporter, success == canSucceed); |
| TestIndividualCopy(reporter, gPairs[j].fConfig, success, subset, subsetCopy, |
| + false); |
| + |
| + // Now set a bitmap to be a subset that will share the same pixelref. |
| + // This allows testing another case of cloning the genID. When calling copyTo |
| + // on a bitmap representing a subset of its pixelref, the resulting pixelref |
| + // should not share the genID, since we only copied the subset. |
| + SkBitmap trueSubset; |
| + // FIXME: Once https://codereview.chromium.org/109023008/ lands, call |
| + // trueSubset.installPixelRef(src.pixelRef(), subset); |
| + trueSubset.setConfig(gPairs[i].fConfig, W/2, H/2); |
| + trueSubset.setPixelRef(src.pixelRef(), W/2, H/2); |
| + |
| + subsetCopy.reset(); |
| + success = trueSubset.copyTo(&subsetCopy, gPairs[j].fConfig); |
| + REPORTER_ASSERT(reporter, success == expected); |
| + REPORTER_ASSERT(reporter, success == canSucceed); |
| + TestIndividualCopy(reporter, gPairs[j].fConfig, success, trueSubset, subsetCopy, |
| true); |
| + |
| + // deepCopyTo copies the entire pixelref, even if the bitmap only represents |
| + // a subset. Therefore, the result should share the same genID. |
| + subsetCopy.reset(); |
| + success = trueSubset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); |
| + REPORTER_ASSERT(reporter, success == expected); |
| + REPORTER_ASSERT(reporter, success == canSucceed); |
| + TestIndividualCopy(reporter, gPairs[j].fConfig, success, trueSubset, subsetCopy, |
| + false); |
| } |
| } // for (size_t j = ... |
| } // for (size_t i = ... |