Bug 1131638 - Discard video frames that fail to sync. r=cpearce

This commit is contained in:
Matt Woodrow 2015-03-12 22:13:23 +13:00
parent 40c622e1ff
commit def55ce594
4 changed files with 29 additions and 18 deletions

View File

@ -17,6 +17,7 @@ namespace layers {
D3D9SurfaceImage::D3D9SurfaceImage()
: Image(nullptr, ImageFormat::D3D9_RGB32_TEXTURE)
, mSize(0, 0)
, mValid(false)
{}
D3D9SurfaceImage::~D3D9SurfaceImage()
@ -153,6 +154,13 @@ D3D9SurfaceImage::SetData(const Data& aData)
return S_OK;
}
bool
D3D9SurfaceImage::IsValid()
{
EnsureSynchronized();
return mValid;
}
void
D3D9SurfaceImage::EnsureSynchronized()
{
@ -162,22 +170,21 @@ D3D9SurfaceImage::EnsureSynchronized()
return;
}
int iterations = 0;
while (iterations < 10 && S_FALSE == query->GetData(nullptr, 0, D3DGETDATA_FLUSH)) {
Sleep(1);
iterations++;
while (iterations < 10) {
HRESULT hr = query->GetData(nullptr, 0, D3DGETDATA_FLUSH);
if (hr == S_FALSE) {
Sleep(1);
iterations++;
continue;
}
if (hr == S_OK) {
mValid = true;
}
break;
}
mQuery = nullptr;
}
HANDLE
D3D9SurfaceImage::GetShareHandle()
{
// Ensure the image has completed its synchronization,
// and safe to used by the caller on another device.
EnsureSynchronized();
return mShareHandle;
}
const D3DSURFACE_DESC&
D3D9SurfaceImage::GetDesc() const
{

View File

@ -41,12 +41,6 @@ public:
// Returns the description of the shared surface.
const D3DSURFACE_DESC& GetDesc() const;
// Returns the HANDLE that can be used to open the image as a shared resource.
// If the operation to copy the original resource to the shared resource
// hasn't finished yet, this function blocks until the synchronization is
// complete.
HANDLE GetShareHandle();
gfx::IntSize GetSize() MOZ_OVERRIDE;
virtual TemporaryRef<gfx::SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
@ -66,6 +60,7 @@ private:
RefPtr<TextureClient> mTextureClient;
HANDLE mShareHandle;
D3DSURFACE_DESC mDesc;
bool mValid;
};
} // namepace layers

View File

@ -173,6 +173,8 @@ public:
return nullptr;
}
virtual bool IsValid() { return true; }
protected:
Image(void* aImplData, ImageFormat aFormat) :
mImplData(aImplData),

View File

@ -147,6 +147,13 @@ ImageClientSingle::UpdateImage(ImageContainer* aContainer, uint32_t aContentFlag
return false;
}
// Don't try to update to an invalid image. We return true because the caller
// would attempt to recreate the ImageClient otherwise, and that isn't going
// to help.
if (!image->IsValid()) {
return true;
}
if (mLastPaintedImageSerial == image->GetSerial()) {
return true;
}