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 expectSameGenID Whether the genIDs should be the same if success is t
rue. | 43 * @param deepCopy True if deepCopyTo was used; false if copyTo was used. |
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 expectSameGenID) { | 47 const bool deepCopy = true) { |
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 if (expectSameGenID) { | 53 // FIXME: When calling copyTo (so deepCopy is false here), sometimes
we copy the pixels |
| 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) { |
54 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera
tionID()); | 58 REPORTER_ASSERT(reporter, src.getGenerationID() == dst.getGenera
tionID()); |
55 } else { | |
56 REPORTER_ASSERT(reporter, src.getGenerationID() != dst.getGenera
tionID()); | |
57 } | 59 } |
58 REPORTER_ASSERT(reporter, src.pixelRef() != NULL && dst.pixelRef() !
= NULL); | 60 REPORTER_ASSERT(reporter, src.pixelRef() != NULL && dst.pixelRef() !
= NULL); |
59 | 61 |
60 // Do read backs and make sure that the two are the same. | 62 // Do read backs and make sure that the two are the same. |
61 SkBitmap srcReadBack, dstReadBack; | 63 SkBitmap srcReadBack, dstReadBack; |
62 { | 64 { |
63 SkASSERT(src.getTexture() != NULL); | 65 SkASSERT(src.getTexture() != NULL); |
64 const SkIPoint origin = src.pixelRefOrigin(); | 66 bool readBack = src.pixelRef()->readPixels(&srcReadBack); |
65 const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, | |
66 src.width(), src.height
()); | |
67 bool readBack = src.pixelRef()->readPixels(&srcReadBack, &subset
); | |
68 REPORTER_ASSERT(reporter, readBack); | 67 REPORTER_ASSERT(reporter, readBack); |
69 } | 68 } |
70 if (dst.getTexture() != NULL) { | 69 if (dst.getTexture() != NULL) { |
71 const SkIPoint origin = dst.pixelRefOrigin(); | 70 bool readBack = dst.pixelRef()->readPixels(&dstReadBack); |
72 const SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, | |
73 dst.width(), dst.height
()); | |
74 bool readBack = dst.pixelRef()->readPixels(&dstReadBack, &subset
); | |
75 REPORTER_ASSERT(reporter, readBack); | 71 REPORTER_ASSERT(reporter, readBack); |
76 } else { | 72 } else { |
77 // If dst is not a texture, do a copy instead, to the same confi
g as srcReadBack. | 73 // If dst is not a texture, do a copy instead, to the same confi
g as srcReadBack. |
78 bool copy = dst.copyTo(&dstReadBack, srcReadBack.config()); | 74 bool copy = dst.copyTo(&dstReadBack, srcReadBack.config()); |
79 REPORTER_ASSERT(reporter, copy); | 75 REPORTER_ASSERT(reporter, copy); |
80 } | 76 } |
81 | 77 |
82 SkAutoLockPixels srcLock(srcReadBack); | 78 SkAutoLockPixels srcLock(srcReadBack); |
83 SkAutoLockPixels dstLock(dstReadBack); | 79 SkAutoLockPixels dstLock(dstReadBack); |
84 REPORTER_ASSERT(reporter, srcReadBack.readyToDraw() && dstReadBack.r
eadyToDraw()); | 80 REPORTER_ASSERT(reporter, srcReadBack.readyToDraw() && dstReadBack.r
eadyToDraw()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 157 } |
162 | 158 |
163 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); | 159 bool canSucceed = src.canCopyTo(gPairs[j].fConfig); |
164 if (success != canSucceed) { | 160 if (success != canSucceed) { |
165 ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s " | 161 ERRORF(reporter, "SkBitmap::deepCopyTo from %s to %s " |
166 "returned %s, but canCopyTo returned %s", | 162 "returned %s, but canCopyTo returned %s", |
167 gConfigName[i], gConfigName[j], boolStr(success), | 163 gConfigName[i], gConfigName[j], boolStr(success), |
168 boolStr(canSucceed)); | 164 boolStr(canSucceed)); |
169 } | 165 } |
170 | 166 |
171 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds
t, true); | 167 TestIndividualCopy(reporter, gPairs[j].fConfig, success, src, ds
t); |
172 | 168 |
173 // Test copying the subset bitmap, using both copyTo and deepCop
yTo. | 169 // Test copying the subset bitmap, using both copyTo and deepCop
yTo. |
174 if (extracted) { | 170 if (extracted) { |
175 SkBitmap subsetCopy; | 171 SkBitmap subsetCopy; |
176 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); | 172 success = subset.copyTo(&subsetCopy, gPairs[j].fConfig); |
177 REPORTER_ASSERT(reporter, success == expected); | 173 REPORTER_ASSERT(reporter, success == expected); |
178 REPORTER_ASSERT(reporter, success == canSucceed); | 174 REPORTER_ASSERT(reporter, success == canSucceed); |
179 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, | 175 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, |
180 true); | 176 false); |
181 | 177 |
182 // Reset the bitmap so that a failed copyTo will leave it in
the expected state. | 178 // Reset the bitmap so that a failed copyTo will leave it in
the expected state. |
183 subsetCopy.reset(); | 179 subsetCopy.reset(); |
184 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); | 180 success = subset.deepCopyTo(&subsetCopy, gPairs[j].fConfig); |
185 REPORTER_ASSERT(reporter, success == expected); | 181 REPORTER_ASSERT(reporter, success == expected); |
186 REPORTER_ASSERT(reporter, success == canSucceed); | 182 REPORTER_ASSERT(reporter, success == canSucceed); |
187 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, | 183 TestIndividualCopy(reporter, gPairs[j].fConfig, success, sub
set, subsetCopy, |
188 true); | 184 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); | |
215 } | 185 } |
216 } // for (size_t j = ... | 186 } // for (size_t j = ... |
217 } // for (size_t i = ... | 187 } // for (size_t i = ... |
218 } // GrContextFactory::GLContextType | 188 } // GrContextFactory::GLContextType |
219 } | 189 } |
220 | 190 |
221 #include "TestClassDef.h" | 191 #include "TestClassDef.h" |
222 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) | 192 DEFINE_GPUTESTCLASS("GpuBitmapCopy", TestGpuBitmapCopyClass, TestGpuBitmapCopy) |
223 | 193 |
224 #endif | 194 #endif |
OLD | NEW |