Bug 1079653 (Part 4) - Move the recording imgStatusTracker onto RasterImage. r=tn

--HG--
extra : rebase_source : ee06a99abfaf5c2a6f53f562088ceb453bfe2259
This commit is contained in:
Seth Fowler 2014-10-15 13:52:22 -07:00
Родитель 987dbea9f5
Коммит 4cd6dd5c37
2 изменённых файлов: 43 добавлений и 47 удалений

Просмотреть файл

@ -1767,6 +1767,7 @@ RasterImage::OnNewSourceData()
mHasSize = false;
mWantFullDecode = true;
mDecodeRequest = nullptr;
mDecodeStatusTracker = nullptr;
if (mAnim) {
mAnim->SetDoneDecoding(false);
@ -1868,6 +1869,7 @@ RasterImage::Discard(bool force)
mStatusTracker->OnDiscard();
mDecodeRequest = nullptr;
mDecodeStatusTracker = nullptr;
if (force)
DiscardTracker::Remove(&mDiscardTrackerNode);
@ -1988,11 +1990,14 @@ RasterImage::InitDecoder(bool aDoSizeDecode)
// Initialize the decoder
if (!mDecodeRequest) {
mDecodeRequest = new DecodeRequest(this);
mDecodeRequest = new DecodeRequest();
}
MOZ_ASSERT(mDecodeRequest->mStatusTracker);
MOZ_ASSERT(mDecodeRequest->mStatusTracker->GetDecoderObserver());
mDecoder->SetObserver(mDecodeRequest->mStatusTracker->GetDecoderObserver());
if (!mDecodeStatusTracker) {
MOZ_ASSERT(mStatusTracker, "Should have an imgStatusTracker");
mDecodeStatusTracker = mStatusTracker->CloneForRecording();
}
MOZ_ASSERT(mDecodeStatusTracker->GetDecoderObserver());
mDecoder->SetObserver(mDecodeStatusTracker->GetDecoderObserver());
mDecoder->SetSizeDecode(aDoSizeDecode);
mDecoder->SetDecodeFlags(mFrameDecodeFlags);
if (!aDoSizeDecode) {
@ -2978,18 +2983,15 @@ RasterImage::RequestDecodeIfNeeded(nsresult aStatus,
nsresult
RasterImage::FinishedSomeDecoding(eShutdownIntent aIntent /* = eShutdownIntent_Done */,
DecodeRequest* aRequest /* = nullptr */)
imgStatusTracker* aDecodeTracker /* = nullptr */)
{
MOZ_ASSERT(NS_IsMainThread());
mDecodingMonitor.AssertCurrentThreadIn();
nsRefPtr<DecodeRequest> request;
if (aRequest) {
request = aRequest;
} else {
request = mDecodeRequest;
}
nsRefPtr<imgStatusTracker> statusTracker = aDecodeTracker
? aDecodeTracker
: mDecodeStatusTracker.get();
// Ensure that, if the decoder is the last reference to the image, we don't
// destroy it by destroying the decoder.
@ -3020,7 +3022,7 @@ RasterImage::FinishedSomeDecoding(eShutdownIntent aIntent /* = eShutdownIntent_D
wasSize = decoder->IsSizeDecode();
// Do some telemetry if this isn't a size decode.
if (request && !wasSize) {
if (!wasSize) {
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
int32_t(decoder->DecodeTime().ToMicroseconds()));
@ -3043,8 +3045,8 @@ RasterImage::FinishedSomeDecoding(eShutdownIntent aIntent /* = eShutdownIntent_D
}
}
ImageStatusDiff diff =
request ? image->mStatusTracker->Difference(request->mStatusTracker)
ImageStatusDiff diff = statusTracker
? image->mStatusTracker->Difference(statusTracker)
: image->mStatusTracker->DecodeStateAsDifference();
image->mStatusTracker->ApplyDifference(diff);
@ -3273,13 +3275,15 @@ RasterImage::DecodePool::DecodeJob::Run()
// If we were interrupted, we shouldn't do any work.
if (mRequest->mRequestStatus == DecodeRequest::REQUEST_STOPPED) {
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage, mRequest);
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage,
mImage->mDecodeStatusTracker);
return NS_OK;
}
// If someone came along and synchronously decoded us, there's nothing for us to do.
if (!mImage->mDecoder || mImage->IsDecodeFinished()) {
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage, mRequest);
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage,
mImage->mDecodeStatusTracker);
return NS_OK;
}
@ -3327,7 +3331,8 @@ RasterImage::DecodePool::DecodeJob::Run()
DecodePool::Singleton()->RequestDecode(mImage);
} else {
// Nothing more for us to do - let everyone know what happened.
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage, mRequest);
DecodeDoneWorker::NotifyFinishedSomeDecoding(mImage,
mImage->mDecodeStatusTracker);
}
return NS_OK;
@ -3498,17 +3503,13 @@ RasterImage::DecodePool::DecodeSomeOfImage(RasterImage* aImg,
return NS_OK;
}
RasterImage::DecodeDoneWorker::DecodeDoneWorker(RasterImage* image, DecodeRequest* request)
: mImage(image)
, mRequest(request)
{}
void
RasterImage::DecodeDoneWorker::NotifyFinishedSomeDecoding(RasterImage* image, DecodeRequest* request)
RasterImage::DecodeDoneWorker::NotifyFinishedSomeDecoding(RasterImage* aImage,
imgStatusTracker* aTracker)
{
image->mDecodingMonitor.AssertCurrentThreadIn();
aImage->mDecodingMonitor.AssertCurrentThreadIn();
nsCOMPtr<nsIRunnable> worker = new DecodeDoneWorker(image, request);
nsCOMPtr<nsIRunnable> worker = new DecodeDoneWorker(aImage, aTracker);
NS_DispatchToMainThread(worker);
}
@ -3518,7 +3519,7 @@ RasterImage::DecodeDoneWorker::Run()
MOZ_ASSERT(NS_IsMainThread());
ReentrantMonitorAutoEnter lock(mImage->mDecodingMonitor);
mImage->FinishedSomeDecoding(eShutdownIntent_Done, mRequest);
mImage->FinishedSomeDecoding(eShutdownIntent_Done, mTracker);
return NS_OK;
}

Просмотреть файл

@ -313,7 +313,7 @@ private:
{
mDecodingMonitor.AssertCurrentThreadIn();
nsRefPtr<imgStatusTracker> statusTracker;
statusTracker = mDecodeRequest ? mDecodeRequest->mStatusTracker
statusTracker = mDecodeStatusTracker ? mDecodeStatusTracker
: mStatusTracker;
MOZ_ASSERT(statusTracker);
return statusTracker.forget();
@ -327,22 +327,12 @@ private:
*/
struct DecodeRequest
{
explicit DecodeRequest(RasterImage* aImage)
: mImage(aImage)
, mRequestStatus(REQUEST_INACTIVE)
{
MOZ_ASSERT(aImage, "aImage cannot be null");
MOZ_ASSERT(aImage->mStatusTracker,
"aImage should have an imgStatusTracker");
mStatusTracker = aImage->mStatusTracker->CloneForRecording();
}
explicit DecodeRequest()
: mRequestStatus(REQUEST_INACTIVE)
{ }
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodeRequest)
// The status tracker that is associated with a given decode request, to
// ensure their lifetimes are linked.
nsRefPtr<imgStatusTracker> mStatusTracker;
RasterImage* mImage;
enum DecodeRequestStatus
@ -479,17 +469,21 @@ private:
* Ensures the decode state accumulated by the decoding process gets
* applied to the image.
*/
static void NotifyFinishedSomeDecoding(RasterImage* image, DecodeRequest* request);
static void NotifyFinishedSomeDecoding(RasterImage* aImage,
imgStatusTracker* aTracker);
NS_IMETHOD Run();
private: /* methods */
DecodeDoneWorker(RasterImage* image, DecodeRequest* request);
DecodeDoneWorker(RasterImage* aImage, imgStatusTracker* aTracker)
: mImage(aImage)
, mTracker(aTracker)
{ }
private: /* members */
nsRefPtr<RasterImage> mImage;
nsRefPtr<DecodeRequest> mRequest;
nsRefPtr<imgStatusTracker> mTracker;
};
class FrameNeededWorker : public nsRunnable
@ -514,8 +508,8 @@ private:
nsRefPtr<RasterImage> mImage;
};
nsresult FinishedSomeDecoding(eShutdownIntent intent = eShutdownIntent_Done,
DecodeRequest* request = nullptr);
nsresult FinishedSomeDecoding(eShutdownIntent aIntent = eShutdownIntent_Done,
imgStatusTracker* aDecodeTracker = nullptr);
void DrawWithPreDownscaleIfNeeded(DrawableFrameRef&& aFrameRef,
gfxContext* aContext,
@ -640,6 +634,7 @@ private: // data
// Decoder and friends
nsRefPtr<Decoder> mDecoder;
nsRefPtr<DecodeRequest> mDecodeRequest;
nsRefPtr<imgStatusTracker> mDecodeStatusTracker;
bool mInDecoder;
// END LOCKED MEMBER VARIABLES