def test_Surface_MakeFromBackendRenderTarget(context):
    target = skia.GrBackendRenderTarget()
    assert isinstance(
        skia.Surface.MakeFromBackendRenderTarget(
            context, target, skia.kTopLeft_GrSurfaceOrigin,
            skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB()),
        (type(None), skia.Surface))
Beispiel #2
0
    def new_skia_context_surface(w, h) -> (skia.GrDirectContext, skia.Surface):
        glContext = skia.GrDirectContext.MakeGL()
        fbInfo = skia.GrGLFramebufferInfo(0, 0x8058)  # GL_RGBA8
        target = skia.GrBackendRenderTarget(w, h, 0, 0, fbInfo)

        surface = skia.Surface.MakeFromBackendRenderTarget(
            glContext, target,
            skia.GrSurfaceOrigin.kBottomLeft_GrSurfaceOrigin,
            skia.ColorType.kRGBA_8888_ColorType, None)
        return glContext, surface
    def __init__(self, mmv_main, *args, **kwargs):
        self.mmv_main = mmv_main
        self.pyskt_context = PysktContext(self, *args, **kwargs)
        self.pyskt_processing = PysktProcessing(self)
        self.draw_utils = SkiaDrawUtils(self)
        self.colors = PysktColors(self)
        self.events = PysktEvents(self)
        self.previous_mouse_pos = [0, 0]
        self.mouse_moved = False

        # Where stuff is rendered from and activated

        self.components = []

        # # # Make main window

        # Init GLFW
        if not glfw.init():
            raise RuntimeError('glfw.init() failed')

        # GLFW config
        glfw.window_hint(glfw.STENCIL_BITS, 0)
        glfw.window_hint(glfw.DEPTH_BITS, 0)
        # glfw.window_hint(glfw.DECORATED, False)
        glfw.window_hint(glfw.DOUBLEBUFFER, False)

        # Create window
        self.window = glfw.create_window(
            self.pyskt_context.width,
            self.pyskt_context.height,
            kwargs.get("context_window_name", "PySKT Window"),
            None,
            None,
        )

        # Make context, init surface
        glfw.make_context_current(self.window)
        glfw.swap_interval(1)
        context = skia.GrContext.MakeGL()

        # Set render to a display compatible
        backend_render_target = skia.GrBackendRenderTarget(
            self.pyskt_context.width,
            self.pyskt_context.height,
            0,  # sample count
            0,  # stencil bits
            skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))

        # Create draw surface
        self.surface = skia.Surface.MakeFromBackendRenderTarget(
            context, backend_render_target, skia.kBottomLeft_GrSurfaceOrigin,
            skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
        assert self.surface, 'Failed to create a surface'
        self.canvas = self.surface.getCanvas()
    def init(self, **kwargs) -> None:
        debug_prefix = "[SkiaNoWindowBackend.init]"

        self.width = kwargs["width"]
        self.height = kwargs["height"]

        # Assume to render on CPU if not said GPU, GPU is less "compatible"
        self.render_backend = kwargs.get("render_backend", "cpu")
        self.show_preview_window = kwargs.get("show_preview_window", True)

        print(debug_prefix, f"Render backend is [{self.render_backend}]")

        # GPU for rasterization, faster rendering but slower images transfers
        if self.render_backend == "gpu":
            self.glfw_context()
            self.gl_context = skia.GrDirectContext.MakeGL()

            if self.show_preview_window:
                backend_render_target = skia.GrBackendRenderTarget(
                    self.width,
                    self.height,
                    0,  # sampleCnt
                    0,  # stencilBits
                    skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))
                self.info = skia.ImageInfo.MakeN32Premul(
                    self.width, self.height)
                self.surface = skia.Surface.MakeFromBackendRenderTarget(
                    self.gl_context, backend_render_target,
                    skia.kBottomLeft_GrSurfaceOrigin,
                    skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
            else:
                self.info = skia.ImageInfo.MakeN32Premul(
                    self.width, self.height)
                self.surface = skia.Surface.MakeRenderTarget(
                    self.gl_context, skia.Budgeted.kNo, self.info)

        # Use CPU for rasterizing, faster transportation of images but slow rendering
        elif self.render_backend == "cpu":
            self.surface = skia.Surface.MakeRasterN32Premul(
                self.width, self.height)

        else:
            raise RuntimeError(
                f"Wrong | Not found render backend: [{self.render_backend}]")

        # Make sure the surface was created
        assert self.surface is not None

        # Get the canvas to draw on
        with self.surface as canvas:
            self.canvas = canvas
Beispiel #5
0
def skia_surface(window):
    context = skia.GrContext.MakeGL()
    backend_render_target = skia.GrBackendRenderTarget(
        WIDTH,
        HEIGHT,
        0,  # sampleCnt
        0,  # stencilBits
        skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))
    surface = skia.Surface.MakeFromBackendRenderTarget(
        context, backend_render_target, skia.kBottomLeft_GrSurfaceOrigin,
        skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
    assert surface is not None
    yield surface
    context.abandonContext()
Beispiel #6
0
    def __init__(self, window: Window):
        self.window = window

        self.context = skia.GrDirectContext.MakeGL()

        self.render_target = skia.GrBackendRenderTarget(
            self.window.size.x, self.window.size.y, 0, 0,
            skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))

        self.surface = skia.Surface.MakeFromBackendRenderTarget(
            self.context, self.render_target, skia.kBottomLeft_GrSurfaceOrigin,
            skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())

        self.canvas = self.surface.getCanvas()
Beispiel #7
0
 def __init__(self, window):
     self.window = window
     self.context = skia.GrDirectContext.MakeGL()
     self.width, self.height = glfw.get_window_size(window)
     backend_render_target = skia.GrBackendRenderTarget(
         self.width,
         self.height,
         0,  # sampleCnt
         0,  # stencilBits
         skia.GrGLFramebufferInfo(0, GL.GL_RGBA8))
     self.surface = skia.Surface.MakeFromBackendRenderTarget(
         self.context, backend_render_target, skia.kBottomLeft_GrSurfaceOrigin,
         skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
     # typeface = skia.Typeface.MakeFromFile('JetBrainsMono-Regular.ttf')
     self.font = skia.Font(skia.Typeface.MakeDefault(), size=40)
     print(self.font)
     self.text = skia.TextBlob.MakeFromString('drawTextBlob', self.font)
     self.start = time.time()
     assert self.surface is not None
Beispiel #8
0
def main():
    if not glfw.init():
        return
    glfw.window_hint(glfw.STENCIL_BITS, 8)
    window = glfw.create_window(WIDTH, HEIGHT, 'Hello World', None, None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)

    context = skia.GrContext.MakeGL()
    backend_render_target = skia.GrBackendRenderTarget(
        WIDTH,
        HEIGHT,
        0,  # sampleCnt
        0,  # stencilBits
        skia.GrGLFramebufferInfo(0, gl.GL_RGBA8))
    surface = skia.Surface.MakeFromBackendRenderTarget(
        context, backend_render_target, skia.kBottomLeft_GrSurfaceOrigin,
        skia.kRGBA_8888_ColorType, skia.ColorSpace.MakeSRGB())
    assert surface is not None

    start = time.time()
    while (glfw.get_key(window, glfw.KEY_ESCAPE) != glfw.PRESS
           and not glfw.window_should_close(window)):
        t = time.time() - start

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        with surface as canvas:
            canvas.drawCircle(100 + 10 * t, 100 + 10 * t, 40,
                              skia.Paint(Color=skia.ColorGREEN))
        surface.flushAndSubmit()

        glfw.swap_buffers(window)
        glfw.poll_events()

    context.abandonContext()
    glfw.terminate()
Beispiel #9
0
def test_GrBackendRenderTarget_init(args):
    assert isinstance(skia.GrBackendRenderTarget(*args),
                      skia.GrBackendRenderTarget)
Beispiel #10
0
def backend_render_target():
    return skia.GrBackendRenderTarget()