2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkCanvasStateUtils_DEFINED
9 #define SkCanvasStateUtils_DEFINED
11 #include "include/core/SkTypes.h"
19 * A set of functions that are useful for copying the state of an SkCanvas
20 * across a library boundary where the Skia library on the other side of the
21 * boundary may be newer. The expected usage is outline below...
24 * CaptureCanvasState(...) |||
25 * SkCanvas --> SkCanvasState |||
26 * ||| CreateFromCanvasState(...)
27 * ||| SkCanvasState --> SkCanvas`
28 * ||| Draw into SkCanvas`
30 * ReleaseCanvasState(...) |||
33 class SK_API SkCanvasStateUtils {
36 * Captures the current state of the canvas into an opaque ptr that is safe
37 * to pass to a different instance of Skia (which may be the same version,
38 * or may be newer). The function will return NULL in the event that one of the
39 * following conditions are true.
40 * 1) the canvas device type is not supported (currently only raster is supported)
41 * 2) the canvas clip type is not supported (currently only non-AA clips are supported)
43 * It is recommended that the original canvas also not be used until all
44 * canvases that have been created using its captured state have been dereferenced.
46 * Finally, it is important to note that any draw filters attached to the
47 * canvas are NOT currently captured.
49 * @param canvas The canvas you wish to capture the current state of.
50 * @return NULL or an opaque ptr that can be passed to CreateFromCanvasState
51 * to reconstruct the canvas. The caller is responsible for calling
52 * ReleaseCanvasState to free the memory associated with this state.
54 static SkCanvasState* CaptureCanvasState(SkCanvas* canvas);
57 * Create a new SkCanvas from the captured state of another SkCanvas. The
58 * function will return NULL in the event that one of the
59 * following conditions are true.
60 * 1) the captured state is in an unrecognized format
61 * 2) the captured canvas device type is not supported
63 * @param state Opaque object created by CaptureCanvasState.
64 * @return NULL or an SkCanvas* whose devices and matrix/clip state are
65 * identical to the captured canvas. The caller is responsible for
66 * calling unref on the SkCanvas.
68 static std::unique_ptr<SkCanvas> MakeFromCanvasState(const SkCanvasState* state);
71 * Free the memory associated with the captured canvas state. The state
72 * should not be released until all SkCanvas objects created using that
73 * state have been dereferenced. Must be called from the same library
74 * instance that created the state via CaptureCanvasState.
76 * @param state The captured state you wish to dispose of.
78 static void ReleaseCanvasState(SkCanvasState* state);