Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1177615 - Rip everything related to FLAG_DECODE_STARTED out of Im…
Browse files Browse the repository at this point in the history
…ageLib. r=tn
  • Loading branch information
sethfowler committed Jul 7, 2015
1 parent b5b4146 commit 258879b
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 100 deletions.
4 changes: 0 additions & 4 deletions image/Decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ Decoder::Init()
// No re-initializing
MOZ_ASSERT(!mInitialized, "Can't re-initialize a decoder!");

if (!IsSizeDecode()) {
mProgress |= FLAG_DECODE_STARTED;
}

// Implementation-specific initialization
InitInternal();

Expand Down
1 change: 0 additions & 1 deletion image/IProgressObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class IProgressObserver : public SupportsWeakPtr<IProgressObserver>

// Other, internal-only methods:
virtual void SetHasImage() = 0;
virtual void OnStartDecode() = 0;
virtual bool NotificationsDeferred() const = 0;
virtual void SetNotificationsDeferred(bool aDeferNotifications) = 0;

Expand Down
7 changes: 0 additions & 7 deletions image/MultipartImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class NextPartObserver : public IProgressObserver
virtual void BlockOnload() override { }
virtual void UnblockOnload() override { }
virtual void SetHasImage() override { }
virtual void OnStartDecode() override { }
virtual bool NotificationsDeferred() const override { return false; }
virtual void SetNotificationsDeferred(bool) override { }

Expand Down Expand Up @@ -315,12 +314,6 @@ MultipartImage::SetHasImage()
mTracker->OnImageAvailable();
}

void
MultipartImage::OnStartDecode()
{
mTracker->SyncNotifyProgress(FLAG_DECODE_STARTED);
}

bool
MultipartImage::NotificationsDeferred() const
{
Expand Down
1 change: 0 additions & 1 deletion image/MultipartImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class MultipartImage
const nsIntRect* aRect = nullptr) override;
virtual void OnLoadComplete(bool aLastPart) override;
virtual void SetHasImage() override;
virtual void OnStartDecode() override;
virtual bool NotificationsDeferred() const override;
virtual void SetNotificationsDeferred(bool aDeferNotifications) override;

Expand Down
15 changes: 2 additions & 13 deletions image/ProgressTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ CheckProgressConsistency(Progress aProgress)
if (aProgress & FLAG_SIZE_AVAILABLE) {
// No preconditions.
}
if (aProgress & FLAG_DECODE_STARTED) {
// No preconditions.
}
if (aProgress & FLAG_DECODE_COMPLETE) {
MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
// No preconditions.
}
if (aProgress & FLAG_FRAME_COMPLETE) {
MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
// No preconditions.
}
if (aProgress & FLAG_LOAD_COMPLETE) {
// No preconditions.
Expand All @@ -50,7 +47,6 @@ CheckProgressConsistency(Progress aProgress)
MOZ_ASSERT(aProgress & (FLAG_SIZE_AVAILABLE | FLAG_HAS_ERROR));
}
if (aProgress & FLAG_IS_ANIMATED) {
MOZ_ASSERT(aProgress & FLAG_DECODE_STARTED);
MOZ_ASSERT(aProgress & FLAG_SIZE_AVAILABLE);
}
if (aProgress & FLAG_HAS_TRANSPARENCY) {
Expand Down Expand Up @@ -90,9 +86,6 @@ ProgressTracker::GetImageStatus() const
if (mProgress & FLAG_SIZE_AVAILABLE) {
status |= imgIRequest::STATUS_SIZE_AVAILABLE;
}
if (mProgress & FLAG_DECODE_STARTED) {
status |= imgIRequest::STATUS_DECODE_STARTED;
}
if (mProgress & FLAG_DECODE_COMPLETE) {
status |= imgIRequest::STATUS_DECODE_COMPLETE;
}
Expand Down Expand Up @@ -275,10 +268,6 @@ ProgressTracker::SyncNotifyInternal(ObserverArray& aObservers,
NOTIFY_IMAGE_OBSERVERS(aObservers, Notify(I::SIZE_AVAILABLE));
}

if (aProgress & FLAG_DECODE_STARTED) {
NOTIFY_IMAGE_OBSERVERS(aObservers, OnStartDecode());
}

if (aProgress & FLAG_ONLOAD_BLOCKED) {
NOTIFY_IMAGE_OBSERVERS(aObservers, BlockOnload());
}
Expand Down
19 changes: 9 additions & 10 deletions image/ProgressTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ class Image;
// Image progress bitflags.
enum {
FLAG_SIZE_AVAILABLE = 1u << 0, // STATUS_SIZE_AVAILABLE
FLAG_DECODE_STARTED = 1u << 1, // STATUS_DECODE_STARTED
FLAG_DECODE_COMPLETE = 1u << 2, // STATUS_DECODE_COMPLETE
FLAG_FRAME_COMPLETE = 1u << 3, // STATUS_FRAME_COMPLETE
FLAG_LOAD_COMPLETE = 1u << 4, // STATUS_LOAD_COMPLETE
FLAG_ONLOAD_BLOCKED = 1u << 5,
FLAG_ONLOAD_UNBLOCKED = 1u << 6,
FLAG_IS_ANIMATED = 1u << 7, // STATUS_IS_ANIMATED
FLAG_HAS_TRANSPARENCY = 1u << 8, // STATUS_HAS_TRANSPARENCY
FLAG_LAST_PART_COMPLETE = 1u << 9,
FLAG_HAS_ERROR = 1u << 10 // STATUS_ERROR
FLAG_DECODE_COMPLETE = 1u << 1, // STATUS_DECODE_COMPLETE
FLAG_FRAME_COMPLETE = 1u << 2, // STATUS_FRAME_COMPLETE
FLAG_LOAD_COMPLETE = 1u << 3, // STATUS_LOAD_COMPLETE
FLAG_ONLOAD_BLOCKED = 1u << 4,
FLAG_ONLOAD_UNBLOCKED = 1u << 5,
FLAG_IS_ANIMATED = 1u << 6, // STATUS_IS_ANIMATED
FLAG_HAS_TRANSPARENCY = 1u << 7, // STATUS_HAS_TRANSPARENCY
FLAG_LAST_PART_COMPLETE = 1u << 8,
FLAG_HAS_ERROR = 1u << 9 // STATUS_ERROR
};

typedef uint32_t Progress;
Expand Down
35 changes: 2 additions & 33 deletions image/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,12 +1238,8 @@ RasterImage::NotifyForLoadEvent(Progress aProgress)
if (mDecodeOnlyOnDraw) {
// For decode-only-on-draw images, we want to send notifications as if we've
// already finished decoding. Otherwise some observers will never even try
// to draw. (We may have already sent some of these notifications from
// NotifyForDecodeOnlyOnDraw(), but ProgressTracker will ensure no duplicate
// notifications get sent.)
aProgress |= FLAG_DECODE_STARTED |
FLAG_FRAME_COMPLETE |
FLAG_DECODE_COMPLETE;
// to draw.
aProgress |= FLAG_FRAME_COMPLETE | FLAG_DECODE_COMPLETE;
}

// If we encountered an error, make sure we notify for that as well.
Expand All @@ -1255,19 +1251,6 @@ RasterImage::NotifyForLoadEvent(Progress aProgress)
NotifyProgress(aProgress);
}

void
RasterImage::NotifyForDecodeOnlyOnDraw()
{
if (!NS_IsMainThread()) {
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(this, &RasterImage::NotifyForDecodeOnlyOnDraw);
NS_DispatchToMainThread(runnable);
return;
}

NotifyProgress(FLAG_DECODE_STARTED);
}

nsresult
RasterImage::OnImageDataAvailable(nsIRequest*,
nsISupports*,
Expand All @@ -1277,12 +1260,6 @@ RasterImage::OnImageDataAvailable(nsIRequest*,
{
nsresult rv;

if (MOZ_UNLIKELY(mDecodeOnlyOnDraw && aOffset == 0)) {
// If we're a decode-only-on-draw image, send notifications as if we've just
// started decoding.
NotifyForDecodeOnlyOnDraw();
}

// WriteToSourceBuffer always consumes everything it gets if it doesn't run
// out of memory.
uint32_t bytesRead;
Expand Down Expand Up @@ -1635,14 +1612,6 @@ RasterImage::Decode(const Maybe<IntSize>& aSize, uint32_t aFlags)
return NS_ERROR_FAILURE;
}

if (aSize) {
// This isn't a size decode (which doesn't send any early notifications), so
// send out notifications right away.
NotifyProgress(decoder->TakeProgress(),
decoder->TakeInvalidRect(),
decoder->GetDecodeFlags());
}

if (mHasSourceData) {
// If we have all the data, we can sync decode if requested.
if (aFlags & FLAG_SYNC_DECODE) {
Expand Down
1 change: 0 additions & 1 deletion image/RasterImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ class RasterImage final : public ImageResource
bool aLastPart) override;

void NotifyForLoadEvent(Progress aProgress);
void NotifyForDecodeOnlyOnDraw();

/**
* A hint of the number of bytes of source data that the image contains. If
Expand Down
8 changes: 3 additions & 5 deletions image/VectorImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1095,12 +1095,10 @@ VectorImage::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt)
return rv;
}

// Sending StartDecode will block page load until the document's ready. (We
// unblock it by sending StopDecode in OnSVGDocumentLoaded or
// OnSVGDocumentError.)
// Block page load until the document's ready. (We unblock it in
// OnSVGDocumentLoaded or OnSVGDocumentError.)
if (mProgressTracker) {
mProgressTracker->SyncNotifyProgress(FLAG_DECODE_STARTED |
FLAG_ONLOAD_BLOCKED);
mProgressTracker->SyncNotifyProgress(FLAG_ONLOAD_BLOCKED);
}

// Create a listener to wait until the SVG document is fully loaded, which
Expand Down
14 changes: 5 additions & 9 deletions image/imgIRequest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface nsIPrincipal;
* @version 0.1
* @see imagelib2
*/
[scriptable, builtinclass, uuid(83a7708b-5c35-409f-bab3-7fc08be6a264)]
[scriptable, builtinclass, uuid(4cb01f0a-ef94-4345-a8d7-1a93f15ff548)]
interface imgIRequest : nsIRequest
{
/**
Expand Down Expand Up @@ -47,9 +47,6 @@ interface imgIRequest : nsIRequest
*
* STATUS_ERROR: An error occurred loading the image.
*
* STATUS_DECODE_STARTED: The decoding process has begun, but not yet
* finished.
*
* STATUS_FRAME_COMPLETE: The first frame has been
* completely decoded.
*
Expand All @@ -64,11 +61,10 @@ interface imgIRequest : nsIRequest
const long STATUS_SIZE_AVAILABLE = 0x1;
const long STATUS_LOAD_COMPLETE = 0x2;
const long STATUS_ERROR = 0x4;
const long STATUS_DECODE_STARTED = 0x8;
const long STATUS_FRAME_COMPLETE = 0x10;
const long STATUS_DECODE_COMPLETE = 0x20;
const long STATUS_IS_ANIMATED = 0x40;
const long STATUS_HAS_TRANSPARENCY = 0x80;
const long STATUS_FRAME_COMPLETE = 0x8;
const long STATUS_DECODE_COMPLETE = 0x10;
const long STATUS_IS_ANIMATED = 0x20;
const long STATUS_HAS_TRANSPARENCY = 0x40;
//@}

/**
Expand Down
9 changes: 9 additions & 0 deletions image/imgRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,15 @@ struct NewPartResult final
: mImage(aExistingImage)
, mIsFirstPart(!aExistingImage)
, mSucceeded(false)
, mShouldResetCacheEntry(false)
{ }

nsAutoCString mContentType;
nsAutoCString mContentDisposition;
nsRefPtr<Image> mImage;
const bool mIsFirstPart;
bool mSucceeded;
bool mShouldResetCacheEntry;
};

static NewPartResult
Expand Down Expand Up @@ -978,6 +980,9 @@ PrepareForNewPart(nsIRequest* aRequest, nsIInputStream* aInStr, uint32_t aCount,
// Transition to the new part.
auto multipartImage = static_cast<MultipartImage*>(aExistingImage);
multipartImage->BeginTransitionToPart(partImage);

// Reset our cache entry size so it doesn't keep growing without bound.
result.mShouldResetCacheEntry = true;
}
} else {
MOZ_ASSERT(!aExistingImage, "New part for non-multipart channel?");
Expand Down Expand Up @@ -1039,6 +1044,10 @@ imgRequest::FinishPreparingForNewPart(const NewPartResult& aResult)
MOZ_ASSERT(progressTracker->HasImage());
}

if (aResult.mShouldResetCacheEntry) {
ResetCacheEntry();
}

if (IsDecodeRequested()) {
aResult.mImage->RequestDecode();
}
Expand Down
15 changes: 0 additions & 15 deletions image/imgRequestProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,21 +804,6 @@ imgRequestProxy::GetHasTransferredData(bool* hasData)
return NS_OK;
}

void
imgRequestProxy::OnStartDecode()
{
// This notification is deliberately not propagated since there are no
// listeners who care about it.
if (GetOwner()) {
// In the case of streaming jpegs, it is possible to get multiple
// OnStartDecodes which indicates the beginning of a new decode. The cache
// entry's size therefore needs to be reset to 0 here. If we do not do
// this, the code in ProgressTrackerObserver::OnStopFrame will continue to
// increase the data size cumulatively.
GetOwner()->ResetCacheEntry();
}
}

static const char*
NotificationTypeToString(int32_t aType)
{
Expand Down
1 change: 0 additions & 1 deletion image/imgRequestProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class imgRequestProxy : public imgIRequest,

// Other, internal-only methods:
virtual void SetHasImage() override;
virtual void OnStartDecode() override;

// Whether we want notifications from ProgressTracker to be deferred until
// an event it has scheduled has been fired.
Expand Down

0 comments on commit 258879b

Please sign in to comment.