Skip to content

Commit

Permalink
Bug 1357318 - remember previous priority boost request in imgRequest.…
Browse files Browse the repository at this point in the history
… r=tnikkel

MozReview-Commit-ID: IieWWUw8EIB
  • Loading branch information
schien committed Mar 22, 2017
1 parent fc03a65 commit d12a1de
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
18 changes: 18 additions & 0 deletions image/imgIRequest.idl
Original file line number Diff line number Diff line change
Expand Up @@ -208,5 +208,23 @@ interface imgIRequest : nsIRequest
* underlying call.
*/
void decrementAnimationConsumers();

/**
* Request loading priority boost to requested category, each category
* of request increases priority only one time..
*
* CATEGORY_FRAME_INIT: increase priority when the imgRequest is associated
* with an nsImageFrame.
*
* CATEGORY_SIZE_QUERY: increase priority when size decoding is necessary to
* determine the layout size of the associated nsImageFrame.
*
* CATEGORY_DISPLAY: increase priority when the image is about to be displayed
* in the viewport.
*/
const uint32_t CATEGORY_FRAME_INIT = 1 << 0;
const uint32_t CATEGORY_SIZE_QUERY = 1 << 1;
const uint32_t CATEGORY_DISPLAY = 1 << 2;
void boostPriority(in uint32_t aCategory);
};

40 changes: 39 additions & 1 deletion image/imgRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,48 @@ imgRequest::AdjustPriority(imgRequestProxy* proxy, int32_t delta)
return;
}

AdjustPriorityInternal(delta);
}

void
imgRequest::AdjustPriorityInternal(int32_t aDelta)
{
nsCOMPtr<nsISupportsPriority> p = do_QueryInterface(mChannel);
if (p) {
p->AdjustPriority(delta);
p->AdjustPriority(aDelta);
}
}

void
imgRequest::BoostPriority(uint32_t aCategory)
{
uint32_t newRequestedCategory =
(mBoostCategoriesRequested & aCategory) ^ aCategory;
if (!newRequestedCategory) {
// priority boost for each category can only apply once.
return;
}

MOZ_LOG(gImgLog, LogLevel::Debug,
("[this=%p] imgRequest::BoostPriority for category %x",
this, newRequestedCategory));

int32_t delta = 0;

if (newRequestedCategory & imgIRequest::CATEGORY_FRAME_INIT) {
--delta;
}

if (newRequestedCategory & imgIRequest::CATEGORY_SIZE_QUERY) {
--delta;
}

if (newRequestedCategory & imgIRequest::CATEGORY_DISPLAY) {
delta += nsISupportsPriority::PRIORITY_HIGH;
}

AdjustPriorityInternal(delta);
mBoostCategoriesRequested |= newRequestedCategory;
}

bool
Expand Down
7 changes: 7 additions & 0 deletions image/imgRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class imgRequest final : public nsIStreamListener,
/// of @aProxy.
void AdjustPriority(imgRequestProxy* aProxy, int32_t aDelta);

void BoostPriority(uint32_t aCategory);

/// Returns a weak pointer to the underlying request.
nsIRequest* GetRequest() const { return mRequest; }

Expand Down Expand Up @@ -223,6 +225,8 @@ class imgRequest final : public nsIStreamListener,
/// Returns true if StartDecoding() was called.
bool IsDecodeRequested() const;

void AdjustPriorityInternal(int32_t aDelta);

// Weak reference to parent loader; this request cannot outlive its owner.
imgLoader* mLoader;
nsCOMPtr<nsIRequest> mRequest;
Expand Down Expand Up @@ -275,6 +279,9 @@ class imgRequest final : public nsIStreamListener,

nsresult mImageErrorCode;

// The categories of prioritization strategy that have been requested.
uint32_t mBoostCategoriesRequested = 0;

mutable mozilla::Mutex mMutex;

// Member variables protected by mMutex. Note that *all* flags in our bitfield
Expand Down
8 changes: 8 additions & 0 deletions image/imgRequestProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,14 @@ imgRequestProxy::GetCORSMode(int32_t* aCorsMode)
return NS_OK;
}

NS_IMETHODIMP
imgRequestProxy::BoostPriority(uint32_t aCategory)
{
NS_ENSURE_STATE(GetOwner() && !mCanceled);
GetOwner()->BoostPriority(aCategory);
return NS_OK;
}

/** nsISupportsPriority methods **/

NS_IMETHODIMP
Expand Down

0 comments on commit d12a1de

Please sign in to comment.