@@ -258,11 +258,19 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
258258 sk_sp<SkImage> result;
259259 SkImageInfo image_info = SkImageInfo::MakeN32Premul (
260260 size.width (), size.height (), SkColorSpace::MakeSRGB ());
261- if (surface_ == nullptr || surface_->GetContext () == nullptr ) {
261+
262+ std::shared_ptr<Surface> pbuffer_surface;
263+ if (!surface_) {
264+ pbuffer_surface = delegate_.GetSnapshotSurface ();
265+ }
266+
267+ if ((surface_ == nullptr || surface_->GetContext () == nullptr ) &&
268+ (pbuffer_surface == nullptr ||
269+ pbuffer_surface->GetContext () == nullptr )) {
262270 // Raster surface is fine if there is no on screen surface. This might
263271 // happen in case of software rendering.
264- sk_sp<SkSurface> surface = SkSurface::MakeRaster (image_info);
265- result = DrawSnapshot (surface , draw_callback);
272+ sk_sp<SkSurface> sk_surface = SkSurface::MakeRaster (image_info);
273+ result = DrawSnapshot (sk_surface , draw_callback);
266274 } else {
267275 delegate_.GetIsGpuDisabledSyncSwitch ()->Execute (
268276 fml::SyncSwitch::Handlers ()
@@ -271,12 +279,17 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
271279 result = DrawSnapshot (surface, draw_callback);
272280 })
273281 .SetIfFalse ([&] {
274- auto context_switch = surface_->MakeRenderContextCurrent ();
282+ Surface* surface = surface_.get ();
283+ if (!surface) {
284+ surface = pbuffer_surface.get ();
285+ }
286+ FML_DCHECK (surface);
287+ auto context_switch = surface->MakeRenderContextCurrent ();
275288 if (!context_switch->GetResult ()) {
276289 return ;
277290 }
278291
279- GrRecordingContext* context = surface_ ->GetContext ();
292+ GrRecordingContext* context = surface ->GetContext ();
280293 auto max_size = context->maxRenderTargetSize ();
281294 double scale_factor = std::min (
282295 1.0 , static_cast <double >(max_size) /
@@ -294,19 +307,19 @@ sk_sp<SkImage> Rasterizer::DoMakeRasterSnapshot(
294307
295308 // When there is an on screen surface, we need a render target
296309 // SkSurface because we want to access texture backed images.
297- sk_sp<SkSurface> surface =
310+ sk_sp<SkSurface> sk_surface =
298311 SkSurface::MakeRenderTarget (context, // context
299312 SkBudgeted::kNo , // budgeted
300313 image_info // image info
301314 );
302- if (!surface ) {
315+ if (!sk_surface ) {
303316 FML_LOG (ERROR)
304317 << " DoMakeRasterSnapshot can not create GPU render target" ;
305318 return ;
306319 }
307320
308- surface ->getCanvas ()->scale (scale_factor, scale_factor);
309- result = DrawSnapshot (surface , draw_callback);
321+ sk_surface ->getCanvas ()->scale (scale_factor, scale_factor);
322+ result = DrawSnapshot (sk_surface , draw_callback);
310323 }));
311324 }
312325
@@ -680,6 +693,7 @@ Rasterizer::Screenshot Rasterizer::ScreenshotLastLayerTree(
680693 FML_LOG (ERROR) << " Screenshot data was null." ;
681694 return {};
682695 }
696+ FML_DLOG (ERROR) << data;
683697
684698 if (base64_encode) {
685699 size_t b64_size = SkBase64::Encode (data->data (), data->size (), nullptr );
0 commit comments