Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 436e99e

Browse files
committed
Document a bit the cairo fast path.
1 parent b7f834e commit 436e99e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,31 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
108108

109109

110110
def _convert_paths_fast(ctx, paths, transforms, clip=None):
111+
# We directly convert to the internal representation used by cairo, for
112+
# which ABI compatibility is guaranteed. The layout is for each item is
113+
# --CODE(4)-- -LENGTH(4)- ---------PAD(8)---------
114+
# ----------X(8)---------- ----------Y(8)----------
115+
# with the size in bytes in parentheses, and (X, Y) repeated as many times
116+
# as there are points for the current code.
111117
ffi = cairo.ffi
112118
cleaneds = [path.cleaned(transform=transform, clip=clip)
113119
for path, transform in zip(paths, transforms)]
114120
vertices = np.concatenate([cleaned.vertices for cleaned in cleaneds])
115121
codes = np.concatenate([cleaned.codes for cleaned in cleaneds])
116122

117-
# TODO: Implement Bezier degree elevation formula. Note that the "slow"
118-
# implementation is, in fact, also incorrect...
123+
# TODO: Implement Bezier degree elevation formula. For now, fall back to
124+
# the "slow" implementation, though note that that implementation is, in
125+
# fact, also incorrect...
119126
if np.any(codes == Path.CURVE3):
120127
raise NotImplementedError("Quadratic Bezier curves are not supported")
128+
121129
# Remove unused vertices and convert to cairo codes. Note that unlike
122130
# cairo_close_path, we do not explicitly insert an extraneous MOVE_TO after
123131
# CLOSE_PATH, so our resulting buffer may be smaller.
124132
vertices = vertices[(codes != Path.STOP) & (codes != Path.CLOSEPOLY)]
125133
codes = codes[codes != Path.STOP]
126134
codes = _MPL_TO_CAIRO_PATH_TYPE[codes]
135+
127136
# Where are the headers of each cairo portions?
128137
cairo_type_sizes = _CAIRO_PATH_TYPE_SIZES[codes]
129138
cairo_type_positions = np.insert(np.cumsum(cairo_type_sizes), 0, 0)
@@ -286,6 +295,7 @@ def _draw_paths():
286295
return
287296
gc_vars, rgb_fc = reuse_key
288297
gc = copy.copy(gc0)
298+
# We actually need to call the setters to reset the internal state.
289299
vars(gc).update(gc_vars)
290300
for k, v in gc_vars.items():
291301
try:

0 commit comments

Comments
 (0)