VectorImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) { MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE); if (aWhichFrame > FRAME_MAX_VALUE) { return nullptr; } if (mError || !mIsFullyLoaded) { return nullptr; } // Look up height & width // ---------------------- SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem(); MOZ_ASSERT(svgElem, "Should have a root SVG elem, since we finished " "loading without errors"); nsIntSize imageIntSize(svgElem->GetIntrinsicWidth(), svgElem->GetIntrinsicHeight()); if (imageIntSize.IsEmpty()) { // We'll get here if our SVG doc has a percent-valued or negative width or // height. return nullptr; } // Make our surface the size of what will ultimately be drawn to it. // (either the full image size, or the restricted region) RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()-> CreateOffscreenContentDrawTarget(IntSize(imageIntSize.width, imageIntSize.height), SurfaceFormat::B8G8R8A8); if (!dt) { NS_ERROR("Could not create a DrawTarget"); return nullptr; } nsRefPtr<gfxContext> context = new gfxContext(dt); auto result = Draw(context, imageIntSize, ImageRegion::Create(imageIntSize), aWhichFrame, GraphicsFilter::FILTER_NEAREST, Nothing(), aFlags); return result == DrawResult::SUCCESS ? dt->Snapshot() : nullptr; }
VectorImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) { // Look up height & width // ---------------------- SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem(); MOZ_ASSERT(svgElem, "Should have a root SVG elem, since we finished " "loading without errors"); nsIntSize imageIntSize(svgElem->GetIntrinsicWidth(), svgElem->GetIntrinsicHeight()); if (imageIntSize.IsEmpty()) { // We'll get here if our SVG doc has a percent-valued or negative width or // height. return nullptr; } return GetFrameAtSize(imageIntSize, aWhichFrame, aFlags); }