gfx/skia/trunk/include/utils/SkCanvasStateUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/utils/SkCanvasStateUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     1.4 +/*
     1.5 + * Copyright 2013 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkCanvasStateUtils_DEFINED
    1.12 +#define SkCanvasStateUtils_DEFINED
    1.13 +
    1.14 +#include "SkCanvas.h"
    1.15 +
    1.16 +class SkCanvasState;
    1.17 +
    1.18 +/**
    1.19 + * A set of functions that are useful for copying an SkCanvas across a library
    1.20 + * boundary where the Skia libraries on either side of the boundary may not be
    1.21 + * version identical.  The expected usage is outline below...
    1.22 + *
    1.23 + *                          Lib Boundary
    1.24 + * CaptureCanvasState(...)      |||
    1.25 + *   SkCanvas --> SkCanvasState |||
    1.26 + *                              ||| CreateFromCanvasState(...)
    1.27 + *                              |||   SkCanvasState --> SkCanvas`
    1.28 + *                              ||| Draw into SkCanvas`
    1.29 + *                              ||| Unref SkCanvas`
    1.30 + * ReleaseCanvasState(...)      |||
    1.31 + *
    1.32 + */
    1.33 +namespace SkCanvasStateUtils {
    1.34 +    /**
    1.35 +     * Captures the current state of the canvas into an opaque ptr that is safe
    1.36 +     * to pass between different instances of Skia (which may or may not be the
    1.37 +     * same version). The function will return NULL in the event that one of the
    1.38 +     * following conditions are true.
    1.39 +     *  1) the canvas device type is not supported (currently only raster is supported)
    1.40 +     *  2) the canvas clip type is not supported (currently only non-AA clips are supported)
    1.41 +     *
    1.42 +     * It is recommended that the original canvas also not be used until all
    1.43 +     * canvases that have been created using its captured state have been dereferenced.
    1.44 +     *
    1.45 +     * Finally, it is important to note that any draw filters attached to the
    1.46 +     * canvas are NOT currently captured.
    1.47 +     *
    1.48 +     * @param canvas The canvas you wish to capture the current state of.
    1.49 +     * @return NULL or an opaque ptr that can be passed to CreateFromCanvasState
    1.50 +     *         to reconstruct the canvas. The caller is responsible for calling
    1.51 +     *         ReleaseCanvasState to free the memory associated with this state.
    1.52 +     */
    1.53 +    SK_API SkCanvasState* CaptureCanvasState(SkCanvas* canvas);
    1.54 +
    1.55 +    /**
    1.56 +     * Create a new SkCanvas from the captured state of another SkCanvas. The
    1.57 +     * function will return NULL in the event that one of the
    1.58 +     * following conditions are true.
    1.59 +     *  1) the captured state is in an unrecognized format
    1.60 +     *  2) the captured canvas device type is not supported
    1.61 +     *
    1.62 +     * @param canvas The canvas you wish to capture the current state of.
    1.63 +     * @return NULL or an SkCanvas* whose devices and matrix/clip state are
    1.64 +     *         identical to the captured canvas. The caller is responsible for
    1.65 +     *         calling unref on the SkCanvas.
    1.66 +     */
    1.67 +    SK_API SkCanvas* CreateFromCanvasState(const SkCanvasState* state);
    1.68 +
    1.69 +    /**
    1.70 +     * Free the memory associated with the captured canvas state.  The state
    1.71 +     * should not be released until all SkCanvas objects created using that
    1.72 +     * state have been dereferenced.
    1.73 +     *
    1.74 +     * @param state The captured state you wish to dispose of.
    1.75 +     */
    1.76 +    SK_API void ReleaseCanvasState(SkCanvasState* state);
    1.77 +};
    1.78 +
    1.79 +#endif

mercurial