From b060891f8991060041a6fe5b632d10b06afe520d Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Sat, 19 Sep 2015 16:21:02 -0700 Subject: [PATCH] Bug 1146663 (Part 3) - Make it impossible to deoptimize imgFrames. r=tn --- image/imgFrame.cpp | 84 ++-------------------------------------------- image/imgFrame.h | 4 ++- 2 files changed, 5 insertions(+), 83 deletions(-) diff --git a/image/imgFrame.cpp b/image/imgFrame.cpp index f48794d1d76c..803c63f60b43 100644 --- a/image/imgFrame.cpp +++ b/image/imgFrame.cpp @@ -796,88 +796,8 @@ imgFrame::LockImageData() return NS_OK; } - return Deoptimize(); -} - -nsresult -imgFrame::Deoptimize() -{ - MOZ_ASSERT(NS_IsMainThread()); - mMonitor.AssertCurrentThreadOwns(); - MOZ_ASSERT(!mImageSurface); - - if (!mImageSurface) { - if (mVBuf) { - VolatileBufferPtr ref(mVBuf); - if (ref.WasBufferPurged()) { - return NS_ERROR_FAILURE; - } - - mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat); - if (!mImageSurface) { - return NS_ERROR_OUT_OF_MEMORY; - } - } - if (mOptSurface || mSinglePixel || mFormat == SurfaceFormat::R5G6B5) { - SurfaceFormat format = mFormat; - if (mFormat == SurfaceFormat::R5G6B5) { - format = SurfaceFormat::B8G8R8A8; - } - - // Recover the pixels - RefPtr buf = - AllocateBufferForImage(mSize, format); - if (!buf) { - return NS_ERROR_OUT_OF_MEMORY; - } - - RefPtr surf = - CreateLockedSurface(buf, mSize, format); - if (!surf) { - return NS_ERROR_OUT_OF_MEMORY; - } - - DataSourceSurface::MappedSurface mapping; - if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) { - gfxCriticalError() << "imgFrame::Deoptimize failed to map surface"; - return NS_ERROR_FAILURE; - } - - RefPtr target = - Factory::CreateDrawTargetForData(BackendType::CAIRO, - mapping.mData, - mSize, - mapping.mStride, - format); - if (!target) { - gfxWarning() << - "imgFrame::Deoptimize failed in CreateDrawTargetForData"; - return NS_ERROR_OUT_OF_MEMORY; - } - - Rect rect(0, 0, mSize.width, mSize.height); - if (mSinglePixel) { - target->FillRect(rect, ColorPattern(mSinglePixelColor), - DrawOptions(1.0f, CompositionOp::OP_SOURCE)); - } else if (mFormat == SurfaceFormat::R5G6B5) { - target->DrawSurface(mImageSurface, rect, rect); - } else { - target->DrawSurface(mOptSurface, rect, rect, - DrawSurfaceOptions(), - DrawOptions(1.0f, CompositionOp::OP_SOURCE)); - } - target->Flush(); - surf->Unmap(); - - mFormat = format; - mVBuf = buf; - mImageSurface = surf; - mOptSurface = nullptr; - } - } - - mVBufPtr = mVBuf; - return NS_OK; + MOZ_ASSERT_UNREACHABLE("It's illegal to re-lock an optimized imgFrame"); + return NS_ERROR_FAILURE; } void diff --git a/image/imgFrame.h b/image/imgFrame.h index 89724c46f4ff..e5f62d01aa99 100644 --- a/image/imgFrame.h +++ b/image/imgFrame.h @@ -274,7 +274,6 @@ private: // methods nsresult LockImageData(); nsresult UnlockImageData(); nsresult Optimize(); - nsresult Deoptimize(); void AssertImageDataLocked() const; @@ -448,6 +447,9 @@ private: * This may be considerably more expensive than is necessary just for drawing, * so only use this when you need to read or write the raw underlying image data * that the imgFrame holds. + * + * Once all an imgFrame's RawAccessFrameRefs go out of scope, new + * RawAccessFrameRefs cannot be created. */ class RawAccessFrameRef final {