Skip to content

Commit 224132f

Browse files
committed
clean
1 parent 37b7739 commit 224132f

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

rendercanvas/contexts/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .basecontext import BaseContext
2-
from .bitmapcontext import BitmapContext
1+
from .basecontext import *
2+
from .bitmapcontext import *

rendercanvas/contexts/basecontext.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
import weakref
22

3+
__all__ = ["BaseContext"]
4+
35

46
class BaseContext:
5-
"""A context that supports rendering by generating grayscale or rgba images.
7+
"""The base class for context objects in ``rendercanvas``.
8+
9+
A context provides an API to provide a rendered image, and implements a
10+
mechanism to present that image to the another system for display. The
11+
concept of a context is heavily inspired by the canvas and its contexts in
12+
the browser.
613
7-
This is inspired by JS ``get_context('bitmaprenderer')`` which returns a ``ImageBitmapRenderingContext``.
8-
It is a relatively simple context to implement, and provides a easy entry to using ``rendercanvas``.
14+
In ``rendercanvas``, there are two types of contexts: the *bitmap* context
15+
provides an API that takes image bitmaps in RAM, and the *wgpu* context
16+
provides an API that takes provides image textures on the GPU to render to.
17+
Each type of context has multiple subclasses to connect it to various
18+
subsystems.
919
"""
1020

1121
def __init__(self, canvas: object, present_info: dict):

rendercanvas/contexts/bitmapcontext.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1-
"""
2-
Provide a simple context class to support ``canvas.get_context('bitmap')``.
3-
"""
4-
51
import sys
62

73
from .basecontext import BaseContext
84

5+
__all__ = ["BitmapContext", "BitmapContextPlain", "BitmapContextToWgpu"]
6+
97

108
class BitmapContext(BaseContext):
11-
"""A context that supports rendering by generating grayscale or rgba images.
9+
"""A context that provides an API that takes a (grayscale or rgba) images bitmap.
10+
11+
This is loosely inspired by JS' ``ImageBitmapRenderingContext``. Rendering
12+
bitmaps is a simple way to use ``rendercanvas``, but usually not as
13+
performant as a wgpu context.
1214
13-
This is inspired by JS ``get_context('bitmaprenderer')`` which returns a ``ImageBitmapRenderingContext``.
14-
It is a relatively simple context to implement, and provides a easy entry to using ``rendercanvas``.
15+
Users typically don't instantiate contexts directly, but use ``canvas.get_context("bitmap")``,
16+
which returns a subclass of this class, depending on the needs of the canvas.
1517
"""
1618

1719
def __new__(cls, canvas: object, present_info: dict):
20+
# Instantiating this class actually produces a subclass
1821
present_method = present_info["method"]
1922
if present_method == "bitmap":
20-
return super().__new__(BitmapToBitmapContext)
23+
return super().__new__(BitmapContextPlain)
2124
elif present_method == "wgpu":
22-
return super().__new__(BitmapToWgpuContext)
25+
return super().__new__(BitmapContextToWgpu)
2326
else:
2427
raise TypeError("Unexpected present_method {present_method!r}")
2528

@@ -66,8 +69,8 @@ def set_bitmap(self, bitmap):
6669
self._bitmap_and_format = m, format
6770

6871

69-
class BitmapToBitmapContext(BitmapContext):
70-
"""A BitmapContext that presents a bitmap to the canvas."""
72+
class BitmapContextPlain(BitmapContext):
73+
"""A BitmapContext that just presents the bitmap to the canvas."""
7174

7275
def __init__(self, canvas, present_info):
7376
super().__init__(canvas, present_info)
@@ -97,11 +100,10 @@ def _rc_present(self):
97100
}
98101

99102

100-
class BitmapToWgpuContext(BitmapContext):
101-
"""A BitmapContext that presents via a wgpu.GPUCanvasContext.
103+
class BitmapContextToWgpu(BitmapContext):
104+
"""A BitmapContext that uploads to a texture and present that to a ``wgpu.GPUCanvasContext``.
102105
103-
This adapter can be used by context objects that want to present a bitmap, when the
104-
canvas only supports presenting to screen.
106+
This is uses for canvases that do not support presenting a bitmap.
105107
"""
106108

107109
def __init__(self, canvas, present_info):

0 commit comments

Comments
 (0)