2013-08-29 20:20:40 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2013-08-29 20:20:40 +00:00
|
|
|
|
|
|
|
class SkCanvasState;
|
|
|
|
|
|
|
|
/**
|
Change SkCanvasState to use inheritance.
The base class, SkCanvasState, now holds the version, width, and
height. These fields will always be a necessary part of the class.
(Also add in some padding.)
The other fields, which may change, have been moved into the
subclass, SkCanvasState_v1. If/when the version changes, it will
correspond to a new subclass.
In SkCanvasStateUtils::CreateFromCanvasState, check the version on
the base class, then do a static_cast to the version corresponding
to SkCanvasState::version.
Remove CANVAS_STATE_VERSION, which is redundant with the version
specified by the subclass.
Use unambiguous type for rowBytes.
Build Android with SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG. This allows us
to run the full suite of CanvasState tests. It is also representative
of what will be used on Android by WebView.
Fix CanvasStateTest where it was broken inside ifdef'ed out code.
Use SkCanvas::getBaseLayerSize() instead of the deprecated
SkCanvas::getDeviceSize().
Update the comments in the header to be more clear. In particular,
an SkCanvasState can only be used to pass an SkCanvas' state to a
future version of Skia (or the same); not an older version.
NOTREECHECKS=true
BUG=b/15693384
R=reed@google.com, mtklein@google.com, djsollen@google.com
Author: scroggo@google.com
Review URL: https://codereview.chromium.org/372003002
2014-07-15 19:34:26 +00:00
|
|
|
* 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...
|
2013-08-29 20:20:40 +00:00
|
|
|
*
|
|
|
|
* Lib Boundary
|
|
|
|
* CaptureCanvasState(...) |||
|
|
|
|
* SkCanvas --> SkCanvasState |||
|
|
|
|
* ||| CreateFromCanvasState(...)
|
|
|
|
* ||| SkCanvasState --> SkCanvas`
|
|
|
|
* ||| Draw into SkCanvas`
|
|
|
|
* ||| Unref SkCanvas`
|
|
|
|
* ReleaseCanvasState(...) |||
|
|
|
|
*
|
|
|
|
*/
|
2014-10-10 13:19:09 +00:00
|
|
|
class SK_API SkCanvasStateUtils {
|
|
|
|
public:
|
2013-08-29 20:20:40 +00:00
|
|
|
/**
|
|
|
|
* Captures the current state of the canvas into an opaque ptr that is safe
|
Change SkCanvasState to use inheritance.
The base class, SkCanvasState, now holds the version, width, and
height. These fields will always be a necessary part of the class.
(Also add in some padding.)
The other fields, which may change, have been moved into the
subclass, SkCanvasState_v1. If/when the version changes, it will
correspond to a new subclass.
In SkCanvasStateUtils::CreateFromCanvasState, check the version on
the base class, then do a static_cast to the version corresponding
to SkCanvasState::version.
Remove CANVAS_STATE_VERSION, which is redundant with the version
specified by the subclass.
Use unambiguous type for rowBytes.
Build Android with SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG. This allows us
to run the full suite of CanvasState tests. It is also representative
of what will be used on Android by WebView.
Fix CanvasStateTest where it was broken inside ifdef'ed out code.
Use SkCanvas::getBaseLayerSize() instead of the deprecated
SkCanvas::getDeviceSize().
Update the comments in the header to be more clear. In particular,
an SkCanvasState can only be used to pass an SkCanvas' state to a
future version of Skia (or the same); not an older version.
NOTREECHECKS=true
BUG=b/15693384
R=reed@google.com, mtklein@google.com, djsollen@google.com
Author: scroggo@google.com
Review URL: https://codereview.chromium.org/372003002
2014-07-15 19:34:26 +00:00
|
|
|
* 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
|
2013-08-29 20:20:40 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-10-10 13:19:09 +00:00
|
|
|
static SkCanvasState* CaptureCanvasState(SkCanvas* canvas);
|
2013-08-29 20:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
Change SkCanvasState to use inheritance.
The base class, SkCanvasState, now holds the version, width, and
height. These fields will always be a necessary part of the class.
(Also add in some padding.)
The other fields, which may change, have been moved into the
subclass, SkCanvasState_v1. If/when the version changes, it will
correspond to a new subclass.
In SkCanvasStateUtils::CreateFromCanvasState, check the version on
the base class, then do a static_cast to the version corresponding
to SkCanvasState::version.
Remove CANVAS_STATE_VERSION, which is redundant with the version
specified by the subclass.
Use unambiguous type for rowBytes.
Build Android with SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG. This allows us
to run the full suite of CanvasState tests. It is also representative
of what will be used on Android by WebView.
Fix CanvasStateTest where it was broken inside ifdef'ed out code.
Use SkCanvas::getBaseLayerSize() instead of the deprecated
SkCanvas::getDeviceSize().
Update the comments in the header to be more clear. In particular,
an SkCanvasState can only be used to pass an SkCanvas' state to a
future version of Skia (or the same); not an older version.
NOTREECHECKS=true
BUG=b/15693384
R=reed@google.com, mtklein@google.com, djsollen@google.com
Author: scroggo@google.com
Review URL: https://codereview.chromium.org/372003002
2014-07-15 19:34:26 +00:00
|
|
|
* @param state Opaque object created by CaptureCanvasState.
|
2013-08-29 20:20:40 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2016-11-12 14:06:55 +00:00
|
|
|
static std::unique_ptr<SkCanvas> MakeFromCanvasState(const SkCanvasState* state);
|
2013-08-29 20:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the memory associated with the captured canvas state. The state
|
|
|
|
* should not be released until all SkCanvas objects created using that
|
Change SkCanvasState to use inheritance.
The base class, SkCanvasState, now holds the version, width, and
height. These fields will always be a necessary part of the class.
(Also add in some padding.)
The other fields, which may change, have been moved into the
subclass, SkCanvasState_v1. If/when the version changes, it will
correspond to a new subclass.
In SkCanvasStateUtils::CreateFromCanvasState, check the version on
the base class, then do a static_cast to the version corresponding
to SkCanvasState::version.
Remove CANVAS_STATE_VERSION, which is redundant with the version
specified by the subclass.
Use unambiguous type for rowBytes.
Build Android with SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG. This allows us
to run the full suite of CanvasState tests. It is also representative
of what will be used on Android by WebView.
Fix CanvasStateTest where it was broken inside ifdef'ed out code.
Use SkCanvas::getBaseLayerSize() instead of the deprecated
SkCanvas::getDeviceSize().
Update the comments in the header to be more clear. In particular,
an SkCanvasState can only be used to pass an SkCanvas' state to a
future version of Skia (or the same); not an older version.
NOTREECHECKS=true
BUG=b/15693384
R=reed@google.com, mtklein@google.com, djsollen@google.com
Author: scroggo@google.com
Review URL: https://codereview.chromium.org/372003002
2014-07-15 19:34:26 +00:00
|
|
|
* state have been dereferenced. Must be called from the same library
|
|
|
|
* instance that created the state via CaptureCanvasState.
|
2013-08-29 20:20:40 +00:00
|
|
|
*
|
|
|
|
* @param state The captured state you wish to dispose of.
|
|
|
|
*/
|
2014-10-10 13:19:09 +00:00
|
|
|
static void ReleaseCanvasState(SkCanvasState* state);
|
2013-08-29 20:20:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|