|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #include "FrameSequence.h" |
|
7 |
|
8 using namespace mozilla; |
|
9 using namespace mozilla::image; |
|
10 |
|
11 namespace mozilla { |
|
12 namespace image { |
|
13 |
|
14 FrameSequence::~FrameSequence() |
|
15 { |
|
16 ClearFrames(); |
|
17 } |
|
18 |
|
19 const FrameDataPair& |
|
20 FrameSequence::GetFrame(uint32_t framenum) const |
|
21 { |
|
22 if (framenum >= mFrames.Length()) { |
|
23 static FrameDataPair empty; |
|
24 return empty; |
|
25 } |
|
26 |
|
27 return mFrames[framenum]; |
|
28 } |
|
29 |
|
30 uint32_t |
|
31 FrameSequence::GetNumFrames() const |
|
32 { |
|
33 return mFrames.Length(); |
|
34 } |
|
35 |
|
36 void |
|
37 FrameSequence::RemoveFrame(uint32_t framenum) |
|
38 { |
|
39 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!"); |
|
40 |
|
41 mFrames.RemoveElementAt(framenum); |
|
42 } |
|
43 |
|
44 void |
|
45 FrameSequence::ClearFrames() |
|
46 { |
|
47 // Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames |
|
48 // array also deletes all the frames. |
|
49 mFrames.Clear(); |
|
50 } |
|
51 |
|
52 void |
|
53 FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame) |
|
54 { |
|
55 NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!"); |
|
56 mFrames.InsertElementAt(framenum, aFrame); |
|
57 if (GetNumFrames() > 1) { |
|
58 // If we're creating our second element, we now know we're animated. |
|
59 // Therefore, we need to lock the first frame too. |
|
60 if (GetNumFrames() == 2) { |
|
61 mFrames[0].LockAndGetData(); |
|
62 } |
|
63 |
|
64 // Whenever we have more than one frame, we always lock *all* our frames |
|
65 // so we have all the image data pointers. |
|
66 mFrames[framenum].LockAndGetData(); |
|
67 } |
|
68 } |
|
69 |
|
70 imgFrame* |
|
71 FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame) |
|
72 { |
|
73 NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!"); |
|
74 |
|
75 FrameDataPair ret; |
|
76 |
|
77 // Steal the imgFrame. |
|
78 if (framenum < mFrames.Length()) { |
|
79 ret = mFrames[framenum]; |
|
80 } |
|
81 |
|
82 if (aFrame) { |
|
83 mFrames.ReplaceElementAt(framenum, aFrame); |
|
84 } else { |
|
85 mFrames.RemoveElementAt(framenum); |
|
86 } |
|
87 |
|
88 return ret.Forget(); |
|
89 } |
|
90 |
|
91 size_t |
|
92 FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxMemoryLocation aLocation, |
|
93 MallocSizeOf aMallocSizeOf) const |
|
94 { |
|
95 size_t n = 0; |
|
96 for (uint32_t i = 0; i < mFrames.Length(); ++i) { |
|
97 imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair()); |
|
98 NS_ABORT_IF_FALSE(frame, "Null frame in frame array!"); |
|
99 n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf); |
|
100 } |
|
101 |
|
102 return n; |
|
103 } |
|
104 |
|
105 } // namespace image |
|
106 } // namespace mozilla |