already_AddRefed<gfxASurface> BasicPlanarYCbCrImage::GetAsSurface() { NS_ASSERTION(NS_IsMainThread(), "Must be main thread"); if (mSurface) { nsRefPtr<gfxASurface> result = mSurface.get(); return result.forget(); } if (!mDecodedBuffer) { return PlanarYCbCrImage::GetAsSurface(); } gfxASurface::gfxImageFormat format = GetOffscreenFormat(); nsRefPtr<gfxImageSurface> imgSurface = new gfxImageSurface(mDecodedBuffer, mSize, mStride, format); if (!imgSurface || imgSurface->CairoStatus() != 0) { return nullptr; } // Pass ownership of the buffer to the surface imgSurface->SetData(&imageSurfaceDataKey, mDecodedBuffer.forget(), DestroyBuffer); nsRefPtr<gfxASurface> result = imgSurface.get(); #if defined(XP_MACOSX) nsRefPtr<gfxQuartzImageSurface> quartzSurface = new gfxQuartzImageSurface(imgSurface); if (quartzSurface) { result = quartzSurface.forget(); } #endif mSurface = result; return result.forget(); }
already_AddRefed<gfx::SourceSurface> BasicPlanarYCbCrImage::GetAsSourceSurface() { NS_ASSERTION(NS_IsMainThread(), "Must be main thread"); if (mSourceSurface) { RefPtr<gfx::SourceSurface> surface(mSourceSurface); return surface.forget(); } if (!mDecodedBuffer) { return PlanarYCbCrImage::GetAsSourceSurface(); } gfxImageFormat format = GetOffscreenFormat(); RefPtr<gfx::SourceSurface> surface; { // Create a DrawTarget so that we can own the data inside mDecodeBuffer. // We create the target out of mDecodedBuffer, and get a snapshot from it. // The draw target is destroyed on scope exit and the surface owns the data. RefPtr<gfx::DrawTarget> drawTarget = gfxPlatform::GetPlatform()->CreateDrawTargetForData(mDecodedBuffer, mSize, mStride, gfx::ImageFormatToSurfaceFormat(format)); if (!drawTarget) { return nullptr; } surface = drawTarget->Snapshot(); } mRecycleBin->RecycleBuffer(mDecodedBuffer.forget(), mSize.height * mStride); mSourceSurface = surface; return surface.forget(); }
NS_IMETHOD Run() { mDecoder->AudioAvailable(mFrameBuffer.forget(), mFrameBufferLength, mTime); return NS_OK; }