Correct way for resizing the SkSurface when the GL viewport changes

1,435 views
Skip to first unread message

Matthew Leibowitz

unread,
Aug 15, 2016, 11:01:48 PM8/15/16
to skia-discuss
Hi Skia Experts,

I have been using Skia for some time now, and I really like it. But, I have been struggling to get started with GPU features.
Right now, I want to start drawing on a OpenGL surface. Using the GLFWTest example, I managed to create this tiny app with GLUT: https://gist.github.com/mattleibow/fb6bfa5146d776f26febfa3a6d4286f0

I can draw text and some cool things, but when the window is resized, the drawing is stretched. If I was to remove the Skia drawing, and use a glutWireCube, it is not stretched. Of course, I am resetting the viewport, but I am not sure how to do the equivalent with Skia. Is it correct to re-create the surface, or is there the correct way?

CODE:

Init once:

 skiaContext = GrContext::Create(kOpenGL_GrBackend, 0);

 GrBackendRenderTargetDesc desc;
 desc.fWidth = w;
 desc.fHeight = h;
 desc.fConfig = kSkia8888_GrPixelConfig;
 desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
 desc.fSampleCnt = 1;
 desc.fStencilBits = 0;
 desc.fRenderTargetHandle = 0;  // assume default framebuffer

 skiaSurface = SkSurface::MakeFromBackendRenderTarget(skiaContext, desc, NULL)

On each frame:

 SkCanvas* skiaCanvas = skiaSurface->getCanvas();

 SkPaint paint;
 paint.setColor(SK_ColorWHITE);
 skiaCanvas->drawCircle(100, 100, 50, paint);

 skiaCanvas->flush();

Brian Osman

unread,
Aug 16, 2016, 9:07:44 AM8/16/16
to skia-d...@googlegroups.com
Yes, you should re-create the surface (at least when a resize event is detected, but you can simply do it every frame, if that's easier).

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Matthew Leibowitz

unread,
Aug 16, 2016, 9:31:59 AM8/16/16
to skia-discuss
Thanks Brian,

This is what I was looking for: The SkSurface is not too expensive to keep re-creating.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages