1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/src/FrameSequence.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,106 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "FrameSequence.h" 1.10 + 1.11 +using namespace mozilla; 1.12 +using namespace mozilla::image; 1.13 + 1.14 +namespace mozilla { 1.15 +namespace image { 1.16 + 1.17 +FrameSequence::~FrameSequence() 1.18 +{ 1.19 + ClearFrames(); 1.20 +} 1.21 + 1.22 +const FrameDataPair& 1.23 +FrameSequence::GetFrame(uint32_t framenum) const 1.24 +{ 1.25 + if (framenum >= mFrames.Length()) { 1.26 + static FrameDataPair empty; 1.27 + return empty; 1.28 + } 1.29 + 1.30 + return mFrames[framenum]; 1.31 +} 1.32 + 1.33 +uint32_t 1.34 +FrameSequence::GetNumFrames() const 1.35 +{ 1.36 + return mFrames.Length(); 1.37 +} 1.38 + 1.39 +void 1.40 +FrameSequence::RemoveFrame(uint32_t framenum) 1.41 +{ 1.42 + NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!"); 1.43 + 1.44 + mFrames.RemoveElementAt(framenum); 1.45 +} 1.46 + 1.47 +void 1.48 +FrameSequence::ClearFrames() 1.49 +{ 1.50 + // Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames 1.51 + // array also deletes all the frames. 1.52 + mFrames.Clear(); 1.53 +} 1.54 + 1.55 +void 1.56 +FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame) 1.57 +{ 1.58 + NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!"); 1.59 + mFrames.InsertElementAt(framenum, aFrame); 1.60 + if (GetNumFrames() > 1) { 1.61 + // If we're creating our second element, we now know we're animated. 1.62 + // Therefore, we need to lock the first frame too. 1.63 + if (GetNumFrames() == 2) { 1.64 + mFrames[0].LockAndGetData(); 1.65 + } 1.66 + 1.67 + // Whenever we have more than one frame, we always lock *all* our frames 1.68 + // so we have all the image data pointers. 1.69 + mFrames[framenum].LockAndGetData(); 1.70 + } 1.71 +} 1.72 + 1.73 +imgFrame* 1.74 +FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame) 1.75 +{ 1.76 + NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!"); 1.77 + 1.78 + FrameDataPair ret; 1.79 + 1.80 + // Steal the imgFrame. 1.81 + if (framenum < mFrames.Length()) { 1.82 + ret = mFrames[framenum]; 1.83 + } 1.84 + 1.85 + if (aFrame) { 1.86 + mFrames.ReplaceElementAt(framenum, aFrame); 1.87 + } else { 1.88 + mFrames.RemoveElementAt(framenum); 1.89 + } 1.90 + 1.91 + return ret.Forget(); 1.92 +} 1.93 + 1.94 +size_t 1.95 +FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation, 1.96 + MallocSizeOf aMallocSizeOf) const 1.97 +{ 1.98 + size_t n = 0; 1.99 + for (uint32_t i = 0; i < mFrames.Length(); ++i) { 1.100 + imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair()); 1.101 + NS_ABORT_IF_FALSE(frame, "Null frame in frame array!"); 1.102 + n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf); 1.103 + } 1.104 + 1.105 + return n; 1.106 +} 1.107 + 1.108 +} // namespace image 1.109 +} // namespace mozilla