gfx/skia/skia/include/utils/SkCanvasStateUtils.h
author Wes Kocher <wkocher@mozilla.com>
Wed, 10 May 2017 10:01:18 -0700
changeset 407965 ce2218406119c36a551e3faea4e192186ee46cc5
parent 407937 af6f19870b2a00759ac1d83dedc3db57213abfee
child 408167 0ded74baeaf23d7985401fe9bbabdb3d9385ac22
permissions -rw-r--r--
Backed out 9 changesets (bug 1340627) for graphical glitches a=backout Backed out changeset 0b1371055c7f (bug 1340627) Backed out changeset f152be1fadb7 (bug 1340627) Backed out changeset c691e2ab6a0c (bug 1340627) Backed out changeset 3cb4bceb8d79 (bug 1340627) Backed out changeset 026aadd76d06 (bug 1340627) Backed out changeset fdbd5d281287 (bug 1340627) Backed out changeset 75fb0d9858a9 (bug 1340627) Backed out changeset 0d4ec7d38a00 (bug 1340627) Backed out changeset af6f19870b2a (bug 1340627) MozReview-Commit-ID: 9dHr7xMZezY

/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkCanvasStateUtils_DEFINED
#define SkCanvasStateUtils_DEFINED

#include "SkCanvas.h"

class SkCanvasState;

/**
 * A set of functions that are useful for copying the state of an SkCanvas
 * across a library boundary where the Skia library on the other side of the
 * boundary may be newer. The expected usage is outline below...
 *
 *                          Lib Boundary
 * CaptureCanvasState(...)      |||
 *   SkCanvas --> SkCanvasState |||
 *                              ||| CreateFromCanvasState(...)
 *                              |||   SkCanvasState --> SkCanvas`
 *                              ||| Draw into SkCanvas`
 *                              ||| Unref SkCanvas`
 * ReleaseCanvasState(...)      |||
 *
 */
class SK_API SkCanvasStateUtils {
public:
    /**
     * Captures the current state of the canvas into an opaque ptr that is safe
     * to pass to a different instance of Skia (which may be the same version,
     * or may be newer). The function will return NULL in the event that one of the
     * following conditions are true.
     *  1) the canvas device type is not supported (currently only raster is supported)
     *  2) the canvas clip type is not supported (currently only non-AA clips are supported)
     *
     * It is recommended that the original canvas also not be used until all
     * canvases that have been created using its captured state have been dereferenced.
     *
     * Finally, it is important to note that any draw filters attached to the
     * canvas are NOT currently captured.
     *
     * @param canvas The canvas you wish to capture the current state of.
     * @return NULL or an opaque ptr that can be passed to CreateFromCanvasState
     *         to reconstruct the canvas. The caller is responsible for calling
     *         ReleaseCanvasState to free the memory associated with this state.
     */
    static SkCanvasState* CaptureCanvasState(SkCanvas* canvas);

    /**
     * Create a new SkCanvas from the captured state of another SkCanvas. The
     * function will return NULL in the event that one of the
     * following conditions are true.
     *  1) the captured state is in an unrecognized format
     *  2) the captured canvas device type is not supported
     *
     * @param state Opaque object created by CaptureCanvasState.
     * @return NULL or an SkCanvas* whose devices and matrix/clip state are
     *         identical to the captured canvas. The caller is responsible for
     *         calling unref on the SkCanvas.
     */
    static SkCanvas* CreateFromCanvasState(const SkCanvasState* state);

    /**
     * Free the memory associated with the captured canvas state.  The state
     * should not be released until all SkCanvas objects created using that
     * state have been dereferenced. Must be called from the same library
     * instance that created the state via CaptureCanvasState.
     *
     * @param state The captured state you wish to dispose of.
     */
    static void ReleaseCanvasState(SkCanvasState* state);
};

#endif