DrawImage Issue

112 views
Skip to first unread message

L2000

unread,
Aug 2, 2024, 3:20:50 AM8/2/24
to skia-discuss
Hi
    I have created offscreen gpu context and created SkSurface(say surface1) to draw my contents.  I took snapshot of the surface and tried drawing the image on another gpu surface(say surface2).But  it's not drawing anything on the surface2. I can draw the image only when i copy the snapshot image to raster image using makeRasterImage. Does skia not permit copying of pixel data between different gpu contexts?


Here is my code:

surface1 :

GrDirectContext* fGrContext = GrDirectContext::MakeMetal(metaldevice,metalqueue,grContextOptions).release();

auto surface1 = SkSurface::MakeRenderTarget(fGrContext, skgpu::Budgeted::kNo, imgInfo)

....after drawing

sk_sp<SkImage> image = surface1->makeImageSnapshot();

image = image->makeRasterImage();


surface2:

auto context = GrDirectContext::MakeMetal((__bridge void*)_mtDevice,(void*)CFBridgingRetain(_mtQueue), grContextOptions).release();

std::shared_ptr<GrContextHolder> fGrContext = std::make_shared<GrContextHolder(std::move(context));

sk_sp<SkSurface> surface2 = SkSurface::MakeFromMTKView(fGrContext->get(), (__bridge GrMTLHandle)metalView, origin, sampleCount, colorType, colorSpace, &surfaceProps);

auto canvas = surface2->getCanvas();

canvas->drawImage(image);


Brian Osman

unread,
Aug 2, 2024, 9:05:06 AM8/2/24
to skia-d...@googlegroups.com
No, that generally doesn't work in Skia (moving images between contexts). Is there a reason you need two contexts (are you using multiple threads?)

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/c3b3f5f9-b7ab-423f-899a-cfee747bca04n%40googlegroups.com.

L2000

unread,
Aug 2, 2024, 1:16:35 PM8/2/24
to skia-discuss
Yes,  I have 4 background threads each having separate context .I will draw my contents and take snapshot of each surfaces. Parallely , in main thread I draw those images in a separate context.
Reply all
Reply to author
Forward
0 new messages