Skip to content

Commit

Permalink
Use framebuffer size to create surface for retina displays (#381)
Browse files Browse the repository at this point in the history
* Always use frame buffer size to create a skia surface to handle retina displays as well, this function will also server as a utility function for PGraphics object so we need 'size' as well, as window is None in that case.

* Update ValueError warning
  • Loading branch information
tushar5526 authored Aug 25, 2022
1 parent 33da3d7 commit a0f1a04
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions p5/sketch/Skia2DRenderer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,22 @@ def glfw_window(self):
glfw.make_context_current(window)
return window

def skia_surface(self, window, size):
def skia_surface(self, window=None, size=None):
self.context = skia.GrDirectContext.MakeGL()
if size:
width, height = size
elif window:
width, height = glfw.get_framebuffer_size(window)
else:
raise ValueError(
"Both window and size can't be None, This is probably an error within p5 instead of the sketch"
)
backend_render_target = skia.GrBackendRenderTarget(
*size,
width,
height,
0, # sampleCnt
0, # stencilBits
skia.GrGLFramebufferInfo(0, GL.GL_RGBA8)
skia.GrGLFramebufferInfo(0, GL.GL_RGBA8),
)
surface = skia.Surface.MakeFromBackendRenderTarget(
self.context,
Expand Down

0 comments on commit a0f1a04

Please sign in to comment.