PDFium enables Skia compilation and calls the interface 'FPDF_RenderPageSkia'.

150 views
Skip to first unread message

谢智

unread,
Jun 16, 2025, 1:26:04 PMJun 16
to pdfium
PDFium enables Skia compilation and calls the interface 'FPDF_RenderPageSkia'. After running the program, it was not found that GPU was used (the GPU usage rate remained unchanged). Could it be that additional code needs to be added to enable or control the GPU?

Lei Zhang

unread,
Jun 18, 2025, 8:19:57 PMJun 18
to 谢智, pdfium
What kind of SkCanvas did you pass into FPDF_RenderPageSkia()?

On Mon, Jun 16, 2025 at 10:26 AM '谢智' via pdfium
<pdf...@googlegroups.com> wrote:
>
> PDFium enables Skia compilation and calls the interface 'FPDF_RenderPageSkia'. After running the program, it was not found that GPU was used (the GPU usage rate remained unchanged). Could it be that additional code needs to be added to enable or control the GPU?
>
> --
> You received this message because you are subscribed to the Google Groups "pdfium" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/pdfium/ab929565-f2a1-4b7f-8acf-6247a1cf5c00n%40googlegroups.com.

Alan Xie

unread,
Jun 19, 2025, 10:30:29 PMJun 19
to pdfium
 
 I'm currently trying to render a PDF page using FPDF_RenderPageSkia directly to a GPU-backed SkCanvas. Here's what I initially tried:
-----------------------------------------code begin---------------------------------------------------
std::unique_ptr<SkPictureRecorder> recorder = std::make_unique<SkPictureRecorder>();
recorder->beginRecording(width, height);
SkCanvas* canvas = recorder->getRecordingCanvas();

// Render PDF page to the recorded canvas
FPDF_RenderPageSkia(reinterpret_cast<FPDF_SKIA_CANVAS>(canvas), page, width, height);

sk_sp<SkPicture> picture = recorder->finishRecordingAsPicture();

// Create a GPU surface and draw the picture onto it
SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(grContext.get(), (skgpu::Budgeted)0, info);
surface->getCanvas()->clear(SK_ColorWHITE);
surface->getCanvas()->drawPicture(picture);
---------------------------------code end----------------------------------------------------------------

This worked and rendered correctly using the GPU, but the actual FPDF_RenderPageSkia() call was executed via CPU — the SkPicture was then drawn to the GPU surface afterward, which isn’t what I want.

So I changed my code to render directly to a GPU-backed canvas like this:

-----------------------------------------code begin---------------------------------------------------

SkImageInfo info = SkImageInfo::Make(width, height, kUnknown_SkColorType, kPremul_SkAlphaType);
sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(grContext.get(), skgpu::Budgeted::kNo, info);
SkCanvas* canvas = surface->getCanvas();

canvas->clear(SK_ColorWHITE);
FPDF_RenderPageSkia(reinterpret_cast<FPDF_SKIA_CANVAS>(canvas), page, width, height);

-------------------------------------code end-----------------------------------------------------------

However, SkSurfaces::RenderTarget() returns nullptr in this case, so I can't get a valid GPU-backed SkCanvas.

My question is:
How can I create a valid GPU-backed SkSurface (and SkCanvas) that is compatible with FPDF_RenderPageSkia, so the rendering happens fully on the GPU instead of via CPU-recorded SkPicture?

Any guidance on the proper SkImageInfo configuration, or whether FPDF_RenderPageSkia supports GPU rendering directly, would be greatly appreciated.

Thank you!

  

Reply all
Reply to author
Forward
0 new messages