forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 717872 - Move frame ownership to a separate container object, Fra…
…meSequence, which only exposes const access to its frames. r=seth The eventual goal here is to have FrameBlenders be able to share FrameSequences.
- Loading branch information
Showing
5 changed files
with
315 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "FrameSequence.h" | ||
|
||
using namespace mozilla; | ||
using namespace mozilla::image; | ||
|
||
namespace mozilla { | ||
namespace image { | ||
|
||
FrameSequence::~FrameSequence() | ||
{ | ||
ClearFrames(); | ||
} | ||
|
||
const FrameDataPair& | ||
FrameSequence::GetFrame(uint32_t framenum) const | ||
{ | ||
if (framenum >= mFrames.Length()) { | ||
static FrameDataPair empty; | ||
return empty; | ||
} | ||
|
||
return mFrames[framenum]; | ||
} | ||
|
||
uint32_t | ||
FrameSequence::GetNumFrames() const | ||
{ | ||
return mFrames.Length(); | ||
} | ||
|
||
void | ||
FrameSequence::RemoveFrame(uint32_t framenum) | ||
{ | ||
NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Deleting invalid frame!"); | ||
|
||
mFrames.RemoveElementAt(framenum); | ||
} | ||
|
||
void | ||
FrameSequence::ClearFrames() | ||
{ | ||
// Since FrameDataPair holds an nsAutoPtr to its frame, clearing the mFrames | ||
// array also deletes all the frames. | ||
mFrames.Clear(); | ||
} | ||
|
||
void | ||
FrameSequence::InsertFrame(uint32_t framenum, imgFrame* aFrame) | ||
{ | ||
NS_ABORT_IF_FALSE(framenum <= mFrames.Length(), "Inserting invalid frame!"); | ||
mFrames.InsertElementAt(framenum, aFrame); | ||
if (GetNumFrames() > 1) { | ||
// If we're creating our second element, we now know we're animated. | ||
// Therefore, we need to lock the first frame too. | ||
if (GetNumFrames() == 2) { | ||
mFrames[0].LockAndGetData(); | ||
} | ||
|
||
// Whenever we have more than one frame, we always lock *all* our frames | ||
// so we have all the image data pointers. | ||
mFrames[framenum].LockAndGetData(); | ||
} | ||
} | ||
|
||
imgFrame* | ||
FrameSequence::SwapFrame(uint32_t framenum, imgFrame* aFrame) | ||
{ | ||
NS_ABORT_IF_FALSE(framenum < mFrames.Length(), "Swapping invalid frame!"); | ||
|
||
FrameDataPair ret; | ||
|
||
// Steal the imgFrame. | ||
if (framenum < mFrames.Length()) { | ||
ret = mFrames[framenum]; | ||
} | ||
|
||
if (aFrame) { | ||
mFrames.ReplaceElementAt(framenum, aFrame); | ||
} else { | ||
mFrames.RemoveElementAt(framenum); | ||
} | ||
|
||
return ret.Forget(); | ||
} | ||
|
||
size_t | ||
FrameSequence::SizeOfDecodedWithComputedFallbackIfHeap(gfxASurface::MemoryLocation aLocation, | ||
MallocSizeOf aMallocSizeOf) const | ||
{ | ||
size_t n = 0; | ||
for (uint32_t i = 0; i < mFrames.Length(); ++i) { | ||
imgFrame* frame = mFrames.SafeElementAt(i, FrameDataPair()); | ||
NS_ABORT_IF_FALSE(frame, "Null frame in frame array!"); | ||
n += frame->SizeOfExcludingThisWithComputedFallbackIfHeap(aLocation, aMallocSizeOf); | ||
} | ||
|
||
return n; | ||
} | ||
|
||
} // namespace image | ||
} // namespace mozilla |
Oops, something went wrong.