michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "FrameSequence.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::image; michael@0: michael@0: namespace mozilla { michael@0: namespace image { michael@0: michael@0: FrameSequence::~FrameSequence() michael@0: { michael@0: ClearFrames(); michael@0: } michael@0: michael@0: const FrameDataPair& michael@0: FrameSequence::GetFrame(uint32_t framenum) const michael@0: { michael@0: if (framenum >= mFrames.Length()) { michael@0: static FrameDataPair empty; michael@0: return empty; michael@0: } michael@0: michael@0: return mFrames[framenum]; michael@0: } michael@0: michael@0: uint32_t michael@0: FrameSequence::GetNumFrames() const michael@0: { michael@0: return mFrames.Length(); michael@0: } michael@0: michael@0: void michael@0: FrameSequence::RemoveFrame(uint32_t framenum) michael@0: { michael@0: NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!"); michael@0: michael@0: mFrames.RemoveElementAt(framenum); michael@0: } michael@0: michael@0: void michael@0: FrameSequence::ClearFrames() michael@0: { michael@0: // Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames michael@0: // array also deletes all the frames. michael@0: mFrames.Clear(); michael@0: } michael@0: michael@0: void michael@0: FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame) michael@0: { michael@0: NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!"); michael@0: mFrames.InsertElementAt(framenum, aFrame); michael@0: if (GetNumFrames() > 1) { michael@0: // If we're creating our second element, we now know we're animated. michael@0: // Therefore, we need to lock the first frame too. michael@0: if (GetNumFrames() == 2) { michael@0: mFrames[0].LockAndGetData(); michael@0: } michael@0: michael@0: // Whenever we have more than one frame, we always lock *all* our frames michael@0: // so we have all the image data pointers. michael@0: mFrames[framenum].LockAndGetData(); michael@0: } michael@0: } michael@0: michael@0: imgFrame* michael@0: FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame) michael@0: { michael@0: NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!"); michael@0: michael@0: FrameDataPair ret; michael@0: michael@0: // Steal the imgFrame. michael@0: if (framenum < mFrames.Length()) { michael@0: ret = mFrames[framenum]; michael@0: } michael@0: michael@0: if (aFrame) { michael@0: mFrames.ReplaceElementAt(framenum, aFrame); michael@0: } else { michael@0: mFrames.RemoveElementAt(framenum); michael@0: } michael@0: michael@0: return ret.Forget(); michael@0: } michael@0: michael@0: size_t michael@0: FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation, michael@0: MallocSizeOf aMallocSizeOf) const michael@0: { michael@0: size_t n = 0; michael@0: for (uint32_t i = 0; i < mFrames.Length(); ++i) { michael@0: imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair()); michael@0: NS_ABORT_IF_FALSE(frame, "Null frame in frame array!"); michael@0: n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf); michael@0: } michael@0: michael@0: return n; michael@0: } michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla