aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@chromium.org>2015-07-10 12:07:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-10 12:07:02 -0700
commit9b2cdbf4811477487f107a78edc130c733b309ea (patch)
treee3ba5000eb9c2ce6f2e2c07e2fc76d6178b2a672 /tests
parentf9c5db26b401dcff83d39275ba78c36360cd6dc1 (diff)
Allow creating multiple scanline decoders.
Make getScanlineDecoder return a new object each time, which is owned by the caller, and independent from any existing scanline decoders and the SkCodec itself. Since the SkCodec already contains the entire state machine, and it is used by the scanline decoders, simply create a new SkCodec which is now owned by the scanline decoder. Move code that cleans up after using a scanline decoder into its destructor One side effect is that creating the first scanline decoder requires a duplication of the stream and re-reading the header. (With some more complexity/changes, we could pass the state machine to the scanline decoder and make the SkCodec recreate its own state machine instead.) The typical client of the scanline decoder (region decoder) uses an SkMemoryStream, so the duplication is cheap, although we should consider the extra time to reread the header/recreate the state machine. (If/when we use the scanline decoder for other purposes, where the stream may not be cheaply duplicated, we should consider passing the state machine.) One (intended) result of this change is that a client can create a new scanline decoder in a new thread, and decode different pieces of the image simultaneously. In SkPngCodec::decodePalette, use fBitDepth rather than a parameter. Review URL: https://codereview.chromium.org/1230033004
Diffstat (limited to 'tests')
-rw-r--r--tests/CodexTest.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 32968fdb7a..f4682055a4 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -28,6 +28,19 @@ static void md5(const SkBitmap& bm, SkMD5::Digest* digest) {
md5.finish(*digest);
}
+/**
+ * Compute the digest for bm and compare it to a known good digest.
+ * @param r Reporter to assert that bm's digest matches goodDigest.
+ * @param goodDigest The known good digest to compare to.
+ * @param bm The bitmap to test.
+ */
+static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& goodDigest,
+ const SkBitmap& bm) {
+ SkMD5::Digest digest;
+ md5(bm, &digest);
+ REPORTER_ASSERT(r, digest == goodDigest);
+}
+
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
@@ -56,8 +69,8 @@ static void check(skiatest::Reporter* r,
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
- SkMD5::Digest digest1, digest2;
- md5(bm, &digest1);
+ SkMD5::Digest digest;
+ md5(bm, &digest);
bm.eraseColor(SK_ColorYELLOW);
@@ -66,25 +79,26 @@ static void check(skiatest::Reporter* r,
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
// verify that re-decoding gives the same result.
- md5(bm, &digest2);
- REPORTER_ASSERT(r, digest1 == digest2);
+ compare_to_good_digest(r, digest, bm);
- SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info);
+ SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineDecoder(info));
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, scanlineDecoder);
- // Regular decodes should be disabled after creating a scanline decoder
+ // Regular decodes should not be affected by creating a scanline decoder
result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
- REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+ compare_to_good_digest(r, digest, bm);
+
+ bm.eraseColor(SK_ColorYELLOW);
+
for (int y = 0; y < info.height(); y++) {
result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
}
// verify that scanline decoding gives the same result.
- SkMD5::Digest digest3;
- md5(bm, &digest3);
- REPORTER_ASSERT(r, digest3 == digest1);
+ compare_to_good_digest(r, digest, bm);
} else {
REPORTER_ASSERT(r, !scanlineDecoder);
}