Bug 1409440. r=tnikkel, a=RyanVM

This commit is contained in:
Andrew Osmond 2018-03-28 14:47:32 -04:00 • committed by Roy Tam
commit 8b03cc774b
2 changed files with 20 additions and 8 deletions

View file

@ -231,6 +231,7 @@ Downscaler::CommitRow()
int32_t inLineToRead = filterOffset + mLinesInBuffer; int32_t inLineToRead = filterOffset + mLinesInBuffer;
MOZ_ASSERT(mCurrentInLine <= inLineToRead, "Reading past end of input"); MOZ_ASSERT(mCurrentInLine <= inLineToRead, "Reading past end of input");
if (mCurrentInLine == inLineToRead) { if (mCurrentInLine == inLineToRead) {
MOZ_RELEASE_ASSERT(mLinesInBuffer < mWindowCapacity, "Need more rows than capacity!");
skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter, skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter,
mWindow[mLinesInBuffer++], mHasAlpha, mWindow[mLinesInBuffer++], mHasAlpha,
supports_sse2() || supports_mmi()); supports_sse2() || supports_mmi());
@ -239,7 +240,7 @@ Downscaler::CommitRow()
MOZ_ASSERT(mCurrentOutLine < mTargetSize.height, MOZ_ASSERT(mCurrentOutLine < mTargetSize.height,
"Writing past end of output"); "Writing past end of output");
while (mLinesInBuffer == filterLength) { while (mLinesInBuffer >= filterLength) {
DownscaleInputLine(); DownscaleInputLine();
if (mCurrentOutLine == mTargetSize.height) { if (mCurrentOutLine == mTargetSize.height) {
@ -340,9 +341,14 @@ Downscaler::DownscaleInputLine()
// Shift the buffer. We're just moving pointers here, so this is cheap. // Shift the buffer. We're just moving pointers here, so this is cheap.
mLinesInBuffer -= diff; mLinesInBuffer -= diff;
mLinesInBuffer = max(mLinesInBuffer, 0); mLinesInBuffer = min(max(mLinesInBuffer, 0), mWindowCapacity);
for (int32_t i = 0; i < mLinesInBuffer; ++i) {
swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]); // If we already have enough rows to satisfy the filter, there is no need
// to swap as we won't be writing more before the next convolution.
if (filterLength > mLinesInBuffer) {
for (int32_t i = 0; i < mLinesInBuffer; ++i) {
swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
}
} }
} }

View file

@ -246,6 +246,7 @@ protected:
int32_t inputRowToRead = filterOffset + mRowsInWindow; int32_t inputRowToRead = filterOffset + mRowsInWindow;
MOZ_ASSERT(mInputRow <= inputRowToRead, "Reading past end of input"); MOZ_ASSERT(mInputRow <= inputRowToRead, "Reading past end of input");
if (mInputRow == inputRowToRead) { if (mInputRow == inputRowToRead) {
MOZ_RELEASE_ASSERT(mRowsInWindow < mWindowCapacity, "Need more rows than capacity!");
skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter, skia::ConvolveHorizontally(mRowBuffer.get(), *mXFilter,
mWindow[mRowsInWindow++], mHasAlpha, mWindow[mRowsInWindow++], mHasAlpha,
supports_sse2() || supports_mmi()); supports_sse2() || supports_mmi());
@ -254,7 +255,7 @@ protected:
MOZ_ASSERT(mOutputRow < mNext.InputSize().height, MOZ_ASSERT(mOutputRow < mNext.InputSize().height,
"Writing past end of output"); "Writing past end of output");
while (mRowsInWindow == filterLength) { while (mRowsInWindow >= filterLength) {
DownscaleInputRow(); DownscaleInputRow();
if (mOutputRow == mNext.InputSize().height) { if (mOutputRow == mNext.InputSize().height) {
@ -330,9 +331,14 @@ private:
// Shift the buffer. We're just moving pointers here, so this is cheap. // Shift the buffer. We're just moving pointers here, so this is cheap.
mRowsInWindow -= diff; mRowsInWindow -= diff;
mRowsInWindow = std::max(mRowsInWindow, 0); mRowsInWindow = std::min(std::max(mRowsInWindow, 0), mWindowCapacity);
for (int32_t i = 0; i < mRowsInWindow; ++i) {
std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]); // If we already have enough rows to satisfy the filter, there is no need
// to swap as we won't be writing more before the next convolution.
if (filterLength > mRowsInWindow) {
for (int32_t i = 0; i < mRowsInWindow; ++i) {
std::swap(mWindow[i], mWindow[filterLength - mRowsInWindow + i]);
}
} }
} }