SkCanvasStateUtils.h 3.1 KB

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