2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkCanvas_DEFINED
|
|
|
|
#define SkCanvas_DEFINED
|
|
|
|
|
2016-10-06 00:33:02 +00:00
|
|
|
#include "SkBlendMode.h"
|
2016-09-20 15:42:38 +00:00
|
|
|
#include "SkClipOp.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkDeque.h"
|
|
|
|
#include "SkPaint.h"
|
2017-01-10 16:58:39 +00:00
|
|
|
#include "SkRasterHandleAllocator.h"
|
2014-09-22 14:29:03 +00:00
|
|
|
#include "SkSurfaceProps.h"
|
2016-07-21 17:25:54 +00:00
|
|
|
#include "SkLights.h"
|
2016-08-25 13:30:23 +00:00
|
|
|
#include "../private/SkShadowParams.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-08-05 20:57:49 +00:00
|
|
|
class GrContext;
|
2016-10-27 18:47:55 +00:00
|
|
|
class GrRenderTargetContext;
|
2013-08-29 11:54:56 +00:00
|
|
|
class SkBaseDevice;
|
2017-02-13 14:32:54 +00:00
|
|
|
class SkBitmap;
|
2015-08-05 20:57:49 +00:00
|
|
|
class SkClipStack;
|
2016-03-05 00:36:20 +00:00
|
|
|
class SkData;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkDraw;
|
2015-02-06 16:36:15 +00:00
|
|
|
class SkDrawable;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkDrawFilter;
|
2017-02-13 14:32:54 +00:00
|
|
|
class SkImage;
|
2015-08-05 20:57:49 +00:00
|
|
|
class SkImageFilter;
|
2012-09-26 02:24:45 +00:00
|
|
|
class SkMetaData;
|
2015-08-05 20:57:49 +00:00
|
|
|
class SkPath;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkPicture;
|
2015-08-05 20:57:49 +00:00
|
|
|
class SkPixmap;
|
2016-04-27 14:49:17 +00:00
|
|
|
class SkRasterClip;
|
2017-02-13 14:32:54 +00:00
|
|
|
class SkRegion;
|
2012-12-12 20:48:18 +00:00
|
|
|
class SkRRect;
|
2015-06-24 17:29:17 +00:00
|
|
|
struct SkRSXform;
|
2014-02-05 15:32:21 +00:00
|
|
|
class SkSurface;
|
2012-08-28 12:19:02 +00:00
|
|
|
class SkSurface_Base;
|
2014-08-21 15:53:26 +00:00
|
|
|
class SkTextBlob;
|
2017-02-06 14:41:10 +00:00
|
|
|
class SkVertices;
|
2014-09-04 19:14:36 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \class SkCanvas
|
|
|
|
|
|
|
|
A Canvas encapsulates all of the state about drawing into a device (bitmap).
|
|
|
|
This includes a reference to the device itself, and a stack of matrix/clip
|
|
|
|
values. For any given draw call (e.g. drawRect), the geometry of the object
|
|
|
|
being drawn is transformed by the concatenation of all the matrices in the
|
|
|
|
stack. The transformed geometry is clipped by the intersection of all of
|
|
|
|
the clips in the stack.
|
|
|
|
|
|
|
|
While the Canvas holds the state of the drawing device, the state (style)
|
|
|
|
of the object being drawn is held by the Paint, which is provided as a
|
|
|
|
parameter to each of the draw() methods. The Paint holds attributes such as
|
|
|
|
color, typeface, textSize, strokeWidth, shader (e.g. gradients, patterns),
|
|
|
|
etc.
|
|
|
|
*/
|
2016-12-07 21:52:58 +00:00
|
|
|
class SK_API SkCanvas : SkNoncopyable {
|
2015-12-21 21:09:44 +00:00
|
|
|
enum PrivateSaveLayerFlags {
|
2016-02-26 13:01:42 +00:00
|
|
|
kDontClipToLayer_PrivateSaveLayerFlag = 1U << 31,
|
2015-12-21 21:09:44 +00:00
|
|
|
};
|
2016-09-20 15:42:38 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2014-03-17 02:13:07 +00:00
|
|
|
/**
|
|
|
|
* Attempt to allocate raster canvas, matching the ImageInfo, that will draw directly into the
|
|
|
|
* specified pixels. To access the pixels after drawing to them, the caller should call
|
|
|
|
* flush() or call peekPixels(...).
|
|
|
|
*
|
|
|
|
* On failure, return NULL. This can fail for several reasons:
|
|
|
|
* 1. invalid ImageInfo (e.g. negative dimensions)
|
|
|
|
* 2. unsupported ImageInfo for a canvas
|
|
|
|
* - kUnknown_SkColorType, kIndex_8_SkColorType
|
2015-02-27 18:23:00 +00:00
|
|
|
* - kUnknown_SkAlphaType
|
2014-03-17 02:13:07 +00:00
|
|
|
* - this list is not complete, so others may also be unsupported
|
|
|
|
*
|
|
|
|
* Note: it is valid to request a supported ImageInfo, but with zero
|
|
|
|
* dimensions.
|
|
|
|
*/
|
2016-11-12 14:06:55 +00:00
|
|
|
static std::unique_ptr<SkCanvas> MakeRasterDirect(const SkImageInfo&, void*, size_t);
|
|
|
|
|
|
|
|
static std::unique_ptr<SkCanvas> MakeRasterDirectN32(int width, int height, SkPMColor* pixels,
|
|
|
|
size_t rowBytes) {
|
|
|
|
return MakeRasterDirect(SkImageInfo::MakeN32Premul(width, height), pixels, rowBytes);
|
|
|
|
}
|
|
|
|
|
2014-01-31 19:42:58 +00:00
|
|
|
/**
|
|
|
|
* Creates an empty canvas with no backing device/pixels, and zero
|
|
|
|
* dimensions.
|
|
|
|
*/
|
2011-07-06 20:00:52 +00:00
|
|
|
SkCanvas();
|
2010-10-13 22:13:05 +00:00
|
|
|
|
2014-01-31 19:42:58 +00:00
|
|
|
/**
|
|
|
|
* Creates a canvas of the specified dimensions, but explicitly not backed
|
|
|
|
* by any device/pixels. Typically this use used by subclasses who handle
|
|
|
|
* the draw calls in some other way.
|
|
|
|
*/
|
2015-01-25 18:33:58 +00:00
|
|
|
SkCanvas(int width, int height, const SkSurfaceProps* = NULL);
|
2014-01-31 19:42:58 +00:00
|
|
|
|
2011-07-21 18:00:46 +00:00
|
|
|
/** Construct a canvas with the specified device to draw into.
|
2011-06-17 13:10:25 +00:00
|
|
|
|
2010-10-13 22:13:05 +00:00
|
|
|
@param device Specifies a device for the canvas to draw into.
|
|
|
|
*/
|
2013-08-29 11:54:56 +00:00
|
|
|
explicit SkCanvas(SkBaseDevice* device);
|
2010-10-13 22:13:05 +00:00
|
|
|
|
2013-10-31 17:28:30 +00:00
|
|
|
/** Construct a canvas with the specified bitmap to draw into.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param bitmap Specifies a bitmap for the canvas to draw into. Its
|
|
|
|
structure are copied to the canvas.
|
|
|
|
*/
|
|
|
|
explicit SkCanvas(const SkBitmap& bitmap);
|
2015-02-02 13:25:04 +00:00
|
|
|
|
2017-04-11 12:46:01 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
|
|
|
|
enum class ColorBehavior {
|
|
|
|
kLegacy,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Android framework only constructor.
|
|
|
|
* Allows the creation of a legacy SkCanvas even though the |bitmap|
|
|
|
|
* and its pixel ref may have an SkColorSpace.
|
|
|
|
*/
|
|
|
|
SkCanvas(const SkBitmap& bitmap, ColorBehavior);
|
|
|
|
#endif
|
|
|
|
|
2015-02-02 13:25:04 +00:00
|
|
|
/** Construct a canvas with the specified bitmap to draw into.
|
|
|
|
@param bitmap Specifies a bitmap for the canvas to draw into. Its
|
|
|
|
structure are copied to the canvas.
|
|
|
|
@param props New canvas surface properties.
|
|
|
|
*/
|
|
|
|
SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual ~SkCanvas();
|
|
|
|
|
2012-09-26 02:24:45 +00:00
|
|
|
SkMetaData& getMetaData();
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
/**
|
|
|
|
* Return ImageInfo for this canvas. If the canvas is not backed by pixels
|
|
|
|
* (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
|
|
|
|
*/
|
|
|
|
SkImageInfo imageInfo() const;
|
|
|
|
|
2016-04-06 14:38:23 +00:00
|
|
|
/**
|
|
|
|
* If the canvas is backed by pixels (cpu or gpu), this writes a copy of the SurfaceProps
|
|
|
|
* for the canvas to the location supplied by the caller, and returns true. Otherwise,
|
|
|
|
* return false and leave the supplied props unchanged.
|
|
|
|
*/
|
|
|
|
bool getProps(SkSurfaceProps*) const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-01-30 14:53:22 +00:00
|
|
|
/**
|
2016-02-05 15:17:34 +00:00
|
|
|
* Trigger the immediate execution of all pending draw operations. For the GPU
|
|
|
|
* backend this will resolve all rendering to the GPU surface backing the
|
|
|
|
* SkSurface that owns this canvas.
|
2012-01-30 14:53:22 +00:00
|
|
|
*/
|
|
|
|
void flush();
|
|
|
|
|
2011-11-01 14:24:23 +00:00
|
|
|
/**
|
2014-02-26 20:22:32 +00:00
|
|
|
* Gets the size of the base or root layer in global canvas coordinates. The
|
|
|
|
* origin of the base layer is always (0,0). The current drawable area may be
|
|
|
|
* smaller (due to clipping or saveLayer).
|
2011-11-01 14:24:23 +00:00
|
|
|
*/
|
2015-03-23 14:22:40 +00:00
|
|
|
virtual SkISize getBaseLayerSize() const;
|
2014-02-26 20:22:32 +00:00
|
|
|
|
2014-02-05 15:32:21 +00:00
|
|
|
/**
|
|
|
|
* Create a new surface matching the specified info, one that attempts to
|
2014-04-11 18:34:35 +00:00
|
|
|
* be maximally compatible when used with this canvas. If there is no matching Surface type,
|
|
|
|
* NULL is returned.
|
2014-09-22 14:29:03 +00:00
|
|
|
*
|
|
|
|
* If surfaceprops is specified, those are passed to the new surface, otherwise the new surface
|
|
|
|
* inherits the properties of the surface that owns this canvas. If this canvas has no parent
|
|
|
|
* surface, then the new surface is created with default properties.
|
2014-02-05 15:32:21 +00:00
|
|
|
*/
|
2016-03-24 01:59:25 +00:00
|
|
|
sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps* = nullptr);
|
2011-06-17 13:10:25 +00:00
|
|
|
|
2013-11-21 06:21:58 +00:00
|
|
|
/**
|
|
|
|
* Return the GPU context of the device that is associated with the canvas.
|
|
|
|
* For a canvas with non-GPU device, NULL is returned.
|
|
|
|
*/
|
|
|
|
GrContext* getGrContext();
|
|
|
|
|
2011-01-11 18:32:13 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
/**
|
2014-03-12 18:28:35 +00:00
|
|
|
* If the canvas has writable pixels in its top layer (and is not recording to a picture
|
|
|
|
* or other non-raster target) and has direct access to its pixels (i.e. they are in
|
|
|
|
* local RAM) return the address of those pixels, and if not null,
|
2014-04-21 21:09:38 +00:00
|
|
|
* return the ImageInfo, rowBytes and origin. The returned address is only valid
|
2014-03-12 18:28:35 +00:00
|
|
|
* while the canvas object is in scope and unchanged. Any API calls made on
|
|
|
|
* canvas (or its parent surface if any) will invalidate the
|
|
|
|
* returned address (and associated information).
|
|
|
|
*
|
2014-04-21 21:09:38 +00:00
|
|
|
* On failure, returns NULL and the info, rowBytes, and origin parameters are ignored.
|
2014-03-12 18:28:35 +00:00
|
|
|
*/
|
2014-04-21 21:09:38 +00:00
|
|
|
void* accessTopLayerPixels(SkImageInfo* info, size_t* rowBytes, SkIPoint* origin = NULL);
|
2014-03-12 18:28:35 +00:00
|
|
|
|
2017-01-10 16:58:39 +00:00
|
|
|
SkRasterHandleAllocator::Handle accessTopRasterHandle() const;
|
|
|
|
|
2014-03-12 18:28:35 +00:00
|
|
|
/**
|
|
|
|
* If the canvas has readable pixels in its base layer (and is not recording to a picture
|
|
|
|
* or other non-raster target) and has direct access to its pixels (i.e. they are in
|
2016-03-09 22:26:26 +00:00
|
|
|
* local RAM) return true, and if not null, return in the pixmap parameter information about
|
|
|
|
* the pixels. The pixmap's pixel address is only valid
|
2014-02-13 17:14:46 +00:00
|
|
|
* while the canvas object is in scope and unchanged. Any API calls made on
|
2016-03-09 22:26:26 +00:00
|
|
|
* canvas (or its parent surface if any) will invalidate the pixel address
|
|
|
|
* (and associated information).
|
2014-02-13 17:14:46 +00:00
|
|
|
*
|
2016-03-09 22:26:26 +00:00
|
|
|
* On failure, returns false and the pixmap parameter will be ignored.
|
2014-02-13 17:14:46 +00:00
|
|
|
*/
|
2016-03-09 22:26:26 +00:00
|
|
|
bool peekPixels(SkPixmap*);
|
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
/**
|
|
|
|
* Copy the pixels from the base-layer into the specified buffer (pixels + rowBytes),
|
|
|
|
* converting them into the requested format (SkImageInfo). The base-layer pixels are read
|
2014-07-13 11:32:32 +00:00
|
|
|
* starting at the specified (srcX,srcY) location in the coordinate system of the base-layer.
|
2014-03-17 21:31:26 +00:00
|
|
|
*
|
2014-07-13 11:32:32 +00:00
|
|
|
* The specified ImageInfo and (srcX,srcY) offset specifies a source rectangle
|
2014-03-17 21:31:26 +00:00
|
|
|
*
|
2014-07-13 11:32:32 +00:00
|
|
|
* srcR.setXYWH(srcX, srcY, dstInfo.width(), dstInfo.height());
|
2014-03-17 21:31:26 +00:00
|
|
|
*
|
2014-07-13 11:32:32 +00:00
|
|
|
* srcR is intersected with the bounds of the base-layer. If this intersection is not empty,
|
|
|
|
* then we have two sets of pixels (of equal size). Replace the dst pixels with the
|
|
|
|
* corresponding src pixels, performing any colortype/alphatype transformations needed
|
|
|
|
* (in the case where the src and dst have different colortypes or alphatypes).
|
2014-03-17 21:31:26 +00:00
|
|
|
*
|
|
|
|
* This call can fail, returning false, for several reasons:
|
2014-07-13 11:32:32 +00:00
|
|
|
* - If srcR does not intersect the base-layer bounds.
|
2014-03-17 21:31:26 +00:00
|
|
|
* - If the requested colortype/alphatype cannot be converted from the base-layer's types.
|
|
|
|
* - If this canvas is not backed by pixels (e.g. picture or PDF)
|
|
|
|
*/
|
2014-07-13 11:32:32 +00:00
|
|
|
bool readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
|
|
|
|
int srcX, int srcY);
|
2017-04-17 14:53:29 +00:00
|
|
|
bool readPixels(const SkPixmap&, int srcX, int srcY);
|
|
|
|
bool readPixels(const SkBitmap&, int srcX, int srcY);
|
2014-03-17 21:31:26 +00:00
|
|
|
|
2014-03-07 03:25:16 +00:00
|
|
|
/**
|
|
|
|
* This method affects the pixels in the base-layer, and operates in pixel coordinates,
|
|
|
|
* ignoring the matrix and clip.
|
|
|
|
*
|
|
|
|
* The specified ImageInfo and (x,y) offset specifies a rectangle: target.
|
|
|
|
*
|
|
|
|
* target.setXYWH(x, y, info.width(), info.height());
|
|
|
|
*
|
|
|
|
* Target is intersected with the bounds of the base-layer. If this intersection is not empty,
|
|
|
|
* then we have two sets of pixels (of equal size), the "src" specified by info+pixels+rowBytes
|
|
|
|
* and the "dst" by the canvas' backend. Replace the dst pixels with the corresponding src
|
|
|
|
* pixels, performing any colortype/alphatype transformations needed (in the case where the
|
|
|
|
* src and dst have different colortypes or alphatypes).
|
|
|
|
*
|
|
|
|
* This call can fail, returning false, for several reasons:
|
|
|
|
* - If the src colortype/alphatype cannot be converted to the canvas' types
|
|
|
|
* - If this canvas is not backed by pixels (e.g. picture or PDF)
|
|
|
|
*/
|
|
|
|
bool writePixels(const SkImageInfo&, const void* pixels, size_t rowBytes, int x, int y);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for calling writePixels(info, ...) by passing its pixels and rowbytes. If the bitmap
|
|
|
|
* is just wrapping a texture, returns false and does nothing.
|
|
|
|
*/
|
|
|
|
bool writePixels(const SkBitmap& bitmap, int x, int y);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-10-13 22:13:05 +00:00
|
|
|
|
2010-02-11 16:05:15 +00:00
|
|
|
/** This call saves the current matrix, clip, and drawFilter, and pushes a
|
2008-12-17 15:59:43 +00:00
|
|
|
copy onto a private stack. Subsequent calls to translate, scale,
|
2010-02-11 16:05:15 +00:00
|
|
|
rotate, skew, concat or clipRect, clipPath, and setDrawFilter all
|
|
|
|
operate on this copy.
|
|
|
|
When the balancing call to restore() is made, the previous matrix, clip,
|
|
|
|
and drawFilter are restored.
|
2014-04-24 21:51:58 +00:00
|
|
|
|
|
|
|
@return The value to pass to restoreToCount() to balance this save()
|
|
|
|
*/
|
|
|
|
int save();
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** This behaves the same as save(), but in addition it allocates an
|
|
|
|
offscreen bitmap. All drawing calls are directed there, and only when
|
|
|
|
the balancing call to restore() is made is that offscreen transfered to
|
2010-02-11 16:05:15 +00:00
|
|
|
the canvas (or the previous layer).
|
2014-04-24 21:51:58 +00:00
|
|
|
@param bounds (may be null) This rect, if non-null, is used as a hint to
|
|
|
|
limit the size of the offscreen, and thus drawing may be
|
|
|
|
clipped to it, though that clipping is not guaranteed to
|
|
|
|
happen. If exact clipping is desired, use clipRect().
|
|
|
|
@param paint (may be null) This is copied, and is applied to the
|
|
|
|
offscreen when restore() is called
|
|
|
|
@return The value to pass to restoreToCount() to balance this save()
|
|
|
|
*/
|
|
|
|
int saveLayer(const SkRect* bounds, const SkPaint* paint);
|
2015-08-10 02:41:13 +00:00
|
|
|
int saveLayer(const SkRect& bounds, const SkPaint* paint) {
|
|
|
|
return this->saveLayer(&bounds, paint);
|
|
|
|
}
|
2014-04-24 21:51:58 +00:00
|
|
|
|
2015-12-10 21:44:45 +00:00
|
|
|
/**
|
|
|
|
* Temporary name.
|
|
|
|
* Will allow any requests for LCD text to be respected, so the caller must be careful to
|
|
|
|
* only draw on top of opaque sections of the layer to get good results.
|
|
|
|
*/
|
|
|
|
int saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPaint* paint);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** This behaves the same as save(), but in addition it allocates an
|
|
|
|
offscreen bitmap. All drawing calls are directed there, and only when
|
|
|
|
the balancing call to restore() is made is that offscreen transfered to
|
2010-02-11 16:05:15 +00:00
|
|
|
the canvas (or the previous layer).
|
2014-04-24 21:51:58 +00:00
|
|
|
@param bounds (may be null) This rect, if non-null, is used as a hint to
|
|
|
|
limit the size of the offscreen, and thus drawing may be
|
|
|
|
clipped to it, though that clipping is not guaranteed to
|
|
|
|
happen. If exact clipping is desired, use clipRect().
|
|
|
|
@param alpha This is applied to the offscreen when restore() is called.
|
|
|
|
@return The value to pass to restoreToCount() to balance this save()
|
|
|
|
*/
|
|
|
|
int saveLayerAlpha(const SkRect* bounds, U8CPU alpha);
|
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
enum {
|
|
|
|
kIsOpaque_SaveLayerFlag = 1 << 0,
|
|
|
|
kPreserveLCDText_SaveLayerFlag = 1 << 1,
|
2015-12-21 21:09:44 +00:00
|
|
|
|
2017-02-28 22:45:27 +00:00
|
|
|
/** initialize the new layer with the contents of the previous layer */
|
|
|
|
kInitWithPrevious_SaveLayerFlag = 1 << 2,
|
|
|
|
|
2015-12-21 21:09:44 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
|
|
|
|
kDontClipToLayer_Legacy_SaveLayerFlag = kDontClipToLayer_PrivateSaveLayerFlag,
|
|
|
|
#endif
|
2015-12-18 15:09:18 +00:00
|
|
|
};
|
|
|
|
typedef uint32_t SaveLayerFlags;
|
|
|
|
|
|
|
|
struct SaveLayerRec {
|
2017-04-28 17:48:37 +00:00
|
|
|
SaveLayerRec() {}
|
2015-12-18 15:09:18 +00:00
|
|
|
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, SaveLayerFlags saveLayerFlags = 0)
|
|
|
|
: fBounds(bounds)
|
|
|
|
, fPaint(paint)
|
2016-01-07 19:28:08 +00:00
|
|
|
, fSaveLayerFlags(saveLayerFlags)
|
|
|
|
{}
|
2017-05-01 14:58:40 +00:00
|
|
|
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
|
|
|
|
SaveLayerFlags saveLayerFlags)
|
|
|
|
: fBounds(bounds)
|
|
|
|
, fPaint(paint)
|
|
|
|
, fBackdrop(backdrop)
|
|
|
|
, fSaveLayerFlags(saveLayerFlags)
|
|
|
|
{}
|
2016-01-07 19:28:08 +00:00
|
|
|
SaveLayerRec(const SkRect* bounds, const SkPaint* paint, const SkImageFilter* backdrop,
|
2017-05-01 21:31:32 +00:00
|
|
|
sk_sp<SkImage> clipMask, const SkMatrix* clipMatrix,
|
2016-01-07 19:28:08 +00:00
|
|
|
SaveLayerFlags saveLayerFlags)
|
|
|
|
: fBounds(bounds)
|
|
|
|
, fPaint(paint)
|
|
|
|
, fBackdrop(backdrop)
|
2017-04-28 17:48:37 +00:00
|
|
|
, fClipMask(std::move(clipMask))
|
|
|
|
, fClipMatrix(clipMatrix)
|
2015-12-18 15:09:18 +00:00
|
|
|
, fSaveLayerFlags(saveLayerFlags)
|
|
|
|
{}
|
|
|
|
|
2017-04-28 17:48:37 +00:00
|
|
|
const SkRect* fBounds = nullptr; // optional
|
|
|
|
const SkPaint* fPaint = nullptr; // optional
|
|
|
|
const SkImageFilter* fBackdrop = nullptr; // optional
|
2017-05-01 21:31:32 +00:00
|
|
|
sk_sp<SkImage> fClipMask; // optional
|
2017-04-28 17:48:37 +00:00
|
|
|
const SkMatrix* fClipMatrix = nullptr; // optional -- only used with fClipMask
|
|
|
|
SaveLayerFlags fSaveLayerFlags = 0;
|
2015-12-18 15:09:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int saveLayer(const SaveLayerRec&);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** This call balances a previous call to save(), and is used to remove all
|
2010-02-11 16:05:15 +00:00
|
|
|
modifications to the matrix/clip/drawFilter state since the last save
|
|
|
|
call.
|
|
|
|
It is an error to call restore() more times than save() was called.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2014-03-12 20:21:48 +00:00
|
|
|
void restore();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Returns the number of matrix/clip states on the SkCanvas' private stack.
|
2014-02-13 16:00:51 +00:00
|
|
|
This will equal # save() calls - # restore() calls + 1. The save count on
|
|
|
|
a new canvas is 1.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2012-02-24 21:54:07 +00:00
|
|
|
int getSaveCount() const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Efficient way to pop any calls to save() that happened after the save
|
2014-02-13 16:00:51 +00:00
|
|
|
count reached saveCount. It is an error for saveCount to be greater than
|
|
|
|
getSaveCount(). To pop all the way back to the initial matrix/clip context
|
|
|
|
pass saveCount == 1.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param saveCount The number of save() levels to restore from
|
|
|
|
*/
|
|
|
|
void restoreToCount(int saveCount);
|
|
|
|
|
|
|
|
/** Preconcat the current matrix with the specified translation
|
|
|
|
@param dx The distance to translate in X
|
|
|
|
@param dy The distance to translate in Y
|
|
|
|
*/
|
2014-03-18 12:51:48 +00:00
|
|
|
void translate(SkScalar dx, SkScalar dy);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Preconcat the current matrix with the specified scale.
|
|
|
|
@param sx The amount to scale in X
|
|
|
|
@param sy The amount to scale in Y
|
|
|
|
*/
|
2014-03-18 12:51:48 +00:00
|
|
|
void scale(SkScalar sx, SkScalar sy);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2016-07-12 22:01:19 +00:00
|
|
|
/** Preconcat the current matrix with the specified rotation about the origin.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param degrees The amount to rotate, in degrees
|
|
|
|
*/
|
2014-03-18 12:51:48 +00:00
|
|
|
void rotate(SkScalar degrees);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2016-07-12 22:01:19 +00:00
|
|
|
/** Preconcat the current matrix with the specified rotation about a given point.
|
|
|
|
@param degrees The amount to rotate, in degrees
|
|
|
|
@param px The x coordinate of the point to rotate about.
|
|
|
|
@param py The y coordinate of the point to rotate about.
|
|
|
|
*/
|
|
|
|
void rotate(SkScalar degrees, SkScalar px, SkScalar py);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Preconcat the current matrix with the specified skew.
|
|
|
|
@param sx The amount to skew in X
|
|
|
|
@param sy The amount to skew in Y
|
|
|
|
*/
|
2014-03-18 12:51:48 +00:00
|
|
|
void skew(SkScalar sx, SkScalar sy);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Preconcat the current matrix with the specified matrix.
|
|
|
|
@param matrix The matrix to preconcatenate with the current matrix
|
|
|
|
*/
|
2014-03-18 12:51:48 +00:00
|
|
|
void concat(const SkMatrix& matrix);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Replace the current matrix with a copy of the specified matrix.
|
|
|
|
@param matrix The matrix that will be copied into the current matrix.
|
|
|
|
*/
|
2014-03-13 20:03:58 +00:00
|
|
|
void setMatrix(const SkMatrix& matrix);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Helper for setMatrix(identity). Sets the current matrix to identity.
|
|
|
|
*/
|
|
|
|
void resetMatrix();
|
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
2016-07-13 21:05:28 +00:00
|
|
|
/** Add the specified translation to the current draw depth of the canvas.
|
|
|
|
@param z The distance to translate in Z.
|
|
|
|
Negative into screen, positive out of screen.
|
|
|
|
Without translation, the draw depth defaults to 0.
|
|
|
|
*/
|
|
|
|
void translateZ(SkScalar z);
|
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
/** Set the current set of lights in the canvas.
|
|
|
|
@param lights The lights that we want the canvas to have.
|
|
|
|
*/
|
|
|
|
void setLights(sk_sp<SkLights> lights);
|
|
|
|
|
|
|
|
/** Returns the current set of lights the canvas uses
|
|
|
|
*/
|
|
|
|
sk_sp<SkLights> getLights() const;
|
|
|
|
#endif
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
/**
|
|
|
|
* Modify the current clip with the specified rectangle.
|
|
|
|
* @param rect The rect to combine with the current clip
|
|
|
|
* @param op The region op to apply to the current clip
|
|
|
|
* @param doAntiAlias true if the clip should be antialiased
|
|
|
|
*/
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipRect(const SkRect& rect, SkClipOp, bool doAntiAlias);
|
|
|
|
void clipRect(const SkRect& rect, SkClipOp op) {
|
2016-09-21 18:15:07 +00:00
|
|
|
this->clipRect(rect, op, false);
|
|
|
|
}
|
|
|
|
void clipRect(const SkRect& rect, bool doAntiAlias = false) {
|
2016-12-14 19:00:03 +00:00
|
|
|
this->clipRect(rect, SkClipOp::kIntersect, doAntiAlias);
|
2016-09-21 18:15:07 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2016-12-12 22:39:55 +00:00
|
|
|
/**
|
|
|
|
* Sets the max clip rectangle, which can be set by clipRect, clipRRect and
|
|
|
|
* clipPath and intersect the current clip with the specified rect.
|
|
|
|
* The max clip affects only future ops (it is not retroactive).
|
|
|
|
* We DON'T record the clip restriction in pictures.
|
|
|
|
* This is private API to be used only by Android framework.
|
|
|
|
* @param rect The maximum allowed clip in device coordinates.
|
|
|
|
* Empty rect means max clip is not enforced.
|
|
|
|
*/
|
|
|
|
void androidFramework_setDeviceClipRestriction(const SkIRect& rect);
|
|
|
|
|
2012-12-12 20:48:18 +00:00
|
|
|
/**
|
|
|
|
* Modify the current clip with the specified SkRRect.
|
|
|
|
* @param rrect The rrect to combine with the current clip
|
|
|
|
* @param op The region op to apply to the current clip
|
|
|
|
* @param doAntiAlias true if the clip should be antialiased
|
|
|
|
*/
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipRRect(const SkRRect& rrect, SkClipOp op, bool doAntiAlias);
|
|
|
|
void clipRRect(const SkRRect& rrect, SkClipOp op) {
|
2016-09-21 18:15:07 +00:00
|
|
|
this->clipRRect(rrect, op, false);
|
|
|
|
}
|
|
|
|
void clipRRect(const SkRRect& rrect, bool doAntiAlias = false) {
|
2016-12-14 19:00:03 +00:00
|
|
|
this->clipRRect(rrect, SkClipOp::kIntersect, doAntiAlias);
|
2016-09-21 18:15:07 +00:00
|
|
|
}
|
2012-12-12 20:48:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Modify the current clip with the specified path.
|
|
|
|
* @param path The path to combine with the current clip
|
|
|
|
* @param op The region op to apply to the current clip
|
|
|
|
* @param doAntiAlias true if the clip should be antialiased
|
|
|
|
*/
|
2016-12-09 14:00:50 +00:00
|
|
|
void clipPath(const SkPath& path, SkClipOp op, bool doAntiAlias);
|
|
|
|
void clipPath(const SkPath& path, SkClipOp op) {
|
2016-09-21 18:15:07 +00:00
|
|
|
this->clipPath(path, op, false);
|
|
|
|
}
|
|
|
|
void clipPath(const SkPath& path, bool doAntiAlias = false) {
|
2016-12-14 19:00:03 +00:00
|
|
|
this->clipPath(path, SkClipOp::kIntersect, doAntiAlias);
|
2016-09-21 18:15:07 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2013-04-25 13:34:40 +00:00
|
|
|
/** EXPERIMENTAL -- only used for testing
|
|
|
|
Set to simplify clip stack using path ops.
|
|
|
|
*/
|
|
|
|
void setAllowSimplifyClip(bool allow) {
|
|
|
|
fAllowSimplifyClip = allow;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Modify the current clip with the specified region. Note that unlike
|
|
|
|
clipRect() and clipPath() which transform their arguments by the current
|
|
|
|
matrix, clipRegion() assumes its argument is already in device
|
|
|
|
coordinates, and so no transformation is performed.
|
|
|
|
@param deviceRgn The region to apply to the current clip
|
2016-07-13 16:03:48 +00:00
|
|
|
@param op The region op to apply to the current clip
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2016-12-14 19:00:03 +00:00
|
|
|
void clipRegion(const SkRegion& deviceRgn, SkClipOp op = SkClipOp::kIntersect);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return true if the specified rectangle, after being transformed by the
|
|
|
|
current matrix, would lie completely outside of the current clip. Call
|
|
|
|
this to check if an area you intend to draw into is clipped out (and
|
|
|
|
therefore you can skip making the draw calls).
|
|
|
|
@param rect the rect to compare with the current clip
|
|
|
|
@return true if the rect (transformed by the canvas' matrix) does not
|
|
|
|
intersect with the canvas' clip
|
|
|
|
*/
|
2012-08-16 20:53:31 +00:00
|
|
|
bool quickReject(const SkRect& rect) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Return true if the specified path, after being transformed by the
|
|
|
|
current matrix, would lie completely outside of the current clip. Call
|
|
|
|
this to check if an area you intend to draw into is clipped out (and
|
|
|
|
therefore you can skip making the draw calls). Note, for speed it may
|
|
|
|
return false even if the path itself might not intersect the clip
|
|
|
|
(i.e. the bounds of the path intersects, but the path does not).
|
|
|
|
@param path The path to compare with the current clip
|
|
|
|
@return true if the path (transformed by the canvas' matrix) does not
|
|
|
|
intersect with the canvas' clip
|
|
|
|
*/
|
2012-08-16 20:53:31 +00:00
|
|
|
bool quickReject(const SkPath& path) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-01-23 16:39:45 +00:00
|
|
|
/**
|
|
|
|
* Return the bounds of the current clip in local coordinates. If the clip is empty,
|
|
|
|
* return { 0, 0, 0, 0 }.
|
|
|
|
*/
|
2017-01-23 19:09:13 +00:00
|
|
|
SkRect getLocalClipBounds() const { return this->onGetLocalClipBounds(); }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-01-24 14:13:40 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the clip bounds are non-empty.
|
|
|
|
*/
|
|
|
|
bool getLocalClipBounds(SkRect* bounds) const {
|
|
|
|
*bounds = this->onGetLocalClipBounds();
|
|
|
|
return !bounds->isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-01-23 16:39:45 +00:00
|
|
|
/**
|
|
|
|
* Return the bounds of the current clip in device coordinates. If the clip is empty,
|
|
|
|
* return { 0, 0, 0, 0 }.
|
|
|
|
*/
|
2017-01-23 19:09:13 +00:00
|
|
|
SkIRect getDeviceClipBounds() const { return this->onGetDeviceClipBounds(); }
|
|
|
|
|
2017-01-24 14:13:40 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the clip bounds are non-empty.
|
|
|
|
*/
|
|
|
|
bool getDeviceClipBounds(SkIRect* bounds) const {
|
|
|
|
*bounds = this->onGetDeviceClipBounds();
|
|
|
|
return !bounds->isEmpty();
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Fill the entire canvas' bitmap (restricted to the current clip) with the
|
2009-06-23 03:01:32 +00:00
|
|
|
specified color and mode.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param color the color to draw with
|
|
|
|
@param mode the mode to apply the color in (defaults to SrcOver)
|
|
|
|
*/
|
2016-10-06 00:33:02 +00:00
|
|
|
void drawColor(SkColor color, SkBlendMode mode = SkBlendMode::kSrcOver);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-12-06 04:49:03 +00:00
|
|
|
/**
|
|
|
|
* Helper method for drawing a color in SRC mode, completely replacing all the pixels
|
|
|
|
* in the current clip with this color.
|
|
|
|
*/
|
|
|
|
void clear(SkColor color) {
|
2016-10-06 00:33:02 +00:00
|
|
|
this->drawColor(color, SkBlendMode::kSrc);
|
2014-12-04 15:50:14 +00:00
|
|
|
}
|
2011-04-14 18:59:28 +00:00
|
|
|
|
2014-03-28 16:08:05 +00:00
|
|
|
/**
|
|
|
|
* This makes the contents of the canvas undefined. Subsequent calls that
|
|
|
|
* require reading the canvas contents will produce undefined results. Examples
|
|
|
|
* include blending and readPixels. The actual implementation is backend-
|
2015-12-11 22:08:58 +00:00
|
|
|
* dependent and one legal implementation is to do nothing. This method
|
|
|
|
* ignores the current clip.
|
2014-03-28 16:08:05 +00:00
|
|
|
*
|
|
|
|
* This function should only be called if the caller intends to subsequently
|
|
|
|
* draw to the canvas. The canvas may do real work at discard() time in order
|
|
|
|
* to optimize performance on subsequent draws. Thus, if you call this and then
|
|
|
|
* never draw to the canvas subsequently you may pay a perfomance penalty.
|
|
|
|
*/
|
|
|
|
void discard() { this->onDiscard(); }
|
|
|
|
|
2011-04-14 18:59:28 +00:00
|
|
|
/**
|
2015-12-11 22:08:58 +00:00
|
|
|
* Fill the entire canvas (restricted to the current clip) with the
|
2011-04-14 18:59:28 +00:00
|
|
|
* specified paint.
|
|
|
|
* @param paint The paint used to fill the canvas
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawPaint(const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
enum PointMode {
|
|
|
|
/** drawPoints draws each point separately */
|
|
|
|
kPoints_PointMode,
|
|
|
|
/** drawPoints draws each pair of points as a line segment */
|
|
|
|
kLines_PointMode,
|
|
|
|
/** drawPoints draws the array of points as a polygon */
|
|
|
|
kPolygon_PointMode
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Draw a series of points, interpreted based on the PointMode mode. For
|
|
|
|
all modes, the count parameter is interpreted as the total number of
|
|
|
|
points. For kLine mode, count/2 line segments are drawn.
|
|
|
|
For kPoint mode, each point is drawn centered at its coordinate, and its
|
|
|
|
size is specified by the paint's stroke-width. It draws as a square,
|
|
|
|
unless the paint's cap-type is round, in which the points are drawn as
|
|
|
|
circles.
|
|
|
|
For kLine mode, each pair of points is drawn as a line segment,
|
|
|
|
respecting the paint's settings for cap/join/width.
|
|
|
|
For kPolygon mode, the entire array is drawn as a series of connected
|
|
|
|
line segments.
|
|
|
|
Note that, while similar, kLine and kPolygon modes draw slightly
|
|
|
|
differently than the equivalent path built with a series of moveto,
|
|
|
|
lineto calls, in that the path will draw all of its contours at once,
|
|
|
|
with no interactions if contours intersect each other (think XOR
|
|
|
|
xfermode). drawPoints always draws each element one at a time.
|
|
|
|
@param mode PointMode specifying how to draw the array of points.
|
|
|
|
@param count The number of points in the array
|
|
|
|
@param pts Array of points to draw
|
|
|
|
@param paint The paint used to draw the points
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-02-22 18:21:42 +00:00
|
|
|
/** Helper method for drawing a single point. See drawPoints() for more details.
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void drawPoint(SkScalar x, SkScalar y, const SkPaint& paint);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw a line segment with the specified start and stop x,y coordinates,
|
|
|
|
using the specified paint. NOTE: since a line is always "framed", the
|
|
|
|
paint's Style is ignored.
|
|
|
|
@param x0 The x-coordinate of the start point of the line
|
|
|
|
@param y0 The y-coordinate of the start point of the line
|
|
|
|
@param x1 The x-coordinate of the end point of the line
|
|
|
|
@param y1 The y-coordinate of the end point of the line
|
|
|
|
@param paint The paint used to draw the line
|
|
|
|
*/
|
2017-02-22 18:21:42 +00:00
|
|
|
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Draw the specified rectangle using the specified paint. The rectangle
|
|
|
|
will be filled or stroked based on the Style in the paint.
|
|
|
|
@param rect The rect to be drawn
|
|
|
|
@param paint The paint used to draw the rect
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawRect(const SkRect& rect, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Draw the specified rectangle using the specified paint. The rectangle
|
|
|
|
will be filled or framed based on the Style in the paint.
|
|
|
|
@param rect The rect to be drawn
|
|
|
|
@param paint The paint used to draw the rect
|
|
|
|
*/
|
2014-02-17 16:28:05 +00:00
|
|
|
void drawIRect(const SkIRect& rect, const SkPaint& paint) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkRect r;
|
|
|
|
r.set(rect); // promotes the ints to scalars
|
|
|
|
this->drawRect(r, paint);
|
|
|
|
}
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2016-08-25 20:54:30 +00:00
|
|
|
/** Draw the outline of the specified region using the specified paint.
|
|
|
|
@param region The region to be drawn
|
|
|
|
@param paint The paint used to draw the region
|
|
|
|
*/
|
2016-08-26 13:37:45 +00:00
|
|
|
void drawRegion(const SkRegion& region, const SkPaint& paint);
|
2016-08-25 20:54:30 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the specified oval using the specified paint. The oval will be
|
|
|
|
filled or framed based on the Style in the paint.
|
|
|
|
@param oval The rectangle bounds of the oval to be drawn
|
|
|
|
@param paint The paint used to draw the oval
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawOval(const SkRect& oval, const SkPaint&);
|
2012-12-12 20:48:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the specified RRect using the specified paint The rrect will be filled or stroked
|
|
|
|
* based on the Style in the paint.
|
|
|
|
*
|
|
|
|
* @param rrect The round-rect to draw
|
|
|
|
* @param paint The paint used to draw the round-rect
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawRRect(const SkRRect& rrect, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-02-21 02:32:36 +00:00
|
|
|
/**
|
|
|
|
* Draw the annulus formed by the outer and inner rrects. The results
|
|
|
|
* are undefined if the outer does not contain the inner.
|
|
|
|
*/
|
|
|
|
void drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the specified circle using the specified paint. If radius is <= 0,
|
|
|
|
then nothing will be drawn. The circle will be filled
|
|
|
|
or framed based on the Style in the paint.
|
|
|
|
@param cx The x-coordinate of the center of the cirle to be drawn
|
|
|
|
@param cy The y-coordinate of the center of the cirle to be drawn
|
|
|
|
@param radius The radius of the cirle to be drawn
|
|
|
|
@param paint The paint used to draw the circle
|
|
|
|
*/
|
2017-02-22 18:21:42 +00:00
|
|
|
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Draw the specified arc, which will be scaled to fit inside the
|
2016-08-25 19:29:23 +00:00
|
|
|
specified oval. Sweep angles are not treated as modulo 360 and thus can
|
|
|
|
exceed a full sweep of the oval. Note that this differs slightly from
|
|
|
|
SkPath::arcTo, which treats the sweep angle mod 360. If the oval is empty
|
|
|
|
or the sweep angle is zero nothing is drawn. If useCenter is true the oval
|
|
|
|
center is inserted into the implied path before the arc and the path is
|
|
|
|
closed back to the, center forming a wedge. Otherwise, the implied path
|
|
|
|
contains just the arc and is not closed.
|
2016-08-19 18:25:19 +00:00
|
|
|
@param oval The bounds of oval used to define the shape of the arc.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param startAngle Starting angle (in degrees) where the arc begins
|
2016-08-19 18:25:19 +00:00
|
|
|
@param sweepAngle Sweep angle (in degrees) measured clockwise.
|
2016-08-25 19:29:23 +00:00
|
|
|
@param useCenter true means include the center of the oval.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param paint The paint used to draw the arc
|
|
|
|
*/
|
|
|
|
void drawArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle,
|
|
|
|
bool useCenter, const SkPaint& paint);
|
|
|
|
|
|
|
|
/** Draw the specified round-rect using the specified paint. The round-rect
|
|
|
|
will be filled or framed based on the Style in the paint.
|
|
|
|
@param rect The rectangular bounds of the roundRect to be drawn
|
|
|
|
@param rx The x-radius of the oval used to round the corners
|
|
|
|
@param ry The y-radius of the oval used to round the corners
|
|
|
|
@param paint The paint used to draw the roundRect
|
|
|
|
*/
|
2017-02-22 18:21:42 +00:00
|
|
|
void drawRoundRect(const SkRect& rect, SkScalar rx, SkScalar ry, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** Draw the specified path using the specified paint. The path will be
|
|
|
|
filled or framed based on the Style in the paint.
|
|
|
|
@param path The path to be drawn
|
|
|
|
@param paint The paint used to draw the path
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawPath(const SkPath& path, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-09-25 21:39:40 +00:00
|
|
|
/** Draw the specified image, with its top/left corner at (x,y), using the
|
|
|
|
specified paint, transformed by the current matrix.
|
|
|
|
|
|
|
|
@param image The image to be drawn
|
|
|
|
@param left The position of the left side of the image being drawn
|
|
|
|
@param top The position of the top side of the image being drawn
|
|
|
|
@param paint The paint used to draw the image, or NULL
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawImage(const SkImage* image, SkScalar left, SkScalar top, const SkPaint* paint = NULL);
|
2016-03-17 15:14:57 +00:00
|
|
|
void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top,
|
|
|
|
const SkPaint* paint = NULL) {
|
|
|
|
this->drawImage(image.get(), left, top, paint);
|
|
|
|
}
|
2014-09-24 20:03:30 +00:00
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
/**
|
|
|
|
* Controls the behavior at the edge of the src-rect, when specified in drawImageRect,
|
|
|
|
* trading off speed for exactness.
|
|
|
|
*
|
|
|
|
* When filtering is enabled (in the Paint), skia may need to sample in a neighborhood around
|
|
|
|
* the pixels in the image. If there is a src-rect specified, it is intended to restrict the
|
|
|
|
* pixels that will be read. However, for performance reasons, some implementations may slow
|
|
|
|
* down if they cannot read 1-pixel past the src-rect boundary at times.
|
|
|
|
*
|
|
|
|
* This enum allows the caller to specify if such a 1-pixel "slop" will be visually acceptable.
|
|
|
|
* If it is, the caller should pass kFast, and it may result in a faster draw. If the src-rect
|
|
|
|
* must be strictly respected, the caller should pass kStrict.
|
|
|
|
*/
|
|
|
|
enum SrcRectConstraint {
|
|
|
|
/**
|
|
|
|
* If kStrict is specified, the implementation must respect the src-rect
|
|
|
|
* (if specified) strictly, and will never sample outside of those bounds during sampling
|
|
|
|
* even when filtering. This may be slower than kFast.
|
|
|
|
*/
|
|
|
|
kStrict_SrcRectConstraint,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If kFast is specified, the implementation may sample outside of the src-rect
|
2015-10-23 16:27:42 +00:00
|
|
|
* (if specified) by half the width of filter. This allows greater flexibility
|
2015-07-14 17:54:12 +00:00
|
|
|
* to the implementation and can make the draw much faster.
|
|
|
|
*/
|
|
|
|
kFast_SrcRectConstraint,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Draw the specified image, scaling and translating so that it fills the specified
|
|
|
|
* dst rect. If the src rect is non-null, only that subset of the image is transformed
|
|
|
|
* and drawn.
|
|
|
|
*
|
|
|
|
* @param image The image to be drawn
|
|
|
|
* @param src Optional: specify the subset of the image to be drawn
|
|
|
|
* @param dst The destination rectangle where the scaled/translated
|
|
|
|
* image will be drawn
|
|
|
|
* @param paint The paint used to draw the image, or NULL
|
|
|
|
* @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
|
|
|
|
*/
|
2015-08-06 17:02:53 +00:00
|
|
|
void drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
|
|
|
|
// variant that takes src SkIRect
|
|
|
|
void drawImageRect(const SkImage* image, const SkIRect& isrc, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
|
|
|
|
// variant that assumes src == image-bounds
|
|
|
|
void drawImageRect(const SkImage* image, const SkRect& dst, const SkPaint* paint,
|
|
|
|
SrcRectConstraint = kStrict_SrcRectConstraint);
|
2015-07-17 14:09:43 +00:00
|
|
|
|
2016-03-17 15:14:57 +00:00
|
|
|
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
|
|
|
|
this->drawImageRect(image.get(), src, dst, paint, constraint);
|
|
|
|
}
|
|
|
|
void drawImageRect(const sk_sp<SkImage>& image, const SkIRect& isrc, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint cons = kStrict_SrcRectConstraint) {
|
|
|
|
this->drawImageRect(image.get(), isrc, dst, paint, cons);
|
|
|
|
}
|
|
|
|
void drawImageRect(const sk_sp<SkImage>& image, const SkRect& dst, const SkPaint* paint,
|
|
|
|
SrcRectConstraint cons = kStrict_SrcRectConstraint) {
|
|
|
|
this->drawImageRect(image.get(), dst, paint, cons);
|
|
|
|
}
|
|
|
|
|
2015-06-25 19:32:03 +00:00
|
|
|
/**
|
|
|
|
* Draw the image stretched differentially to fit into dst.
|
|
|
|
* center is a rect within the image, and logically divides the image
|
|
|
|
* into 9 sections (3x3). For example, if the middle pixel of a [5x5]
|
|
|
|
* image is the "center", then the center-rect should be [2, 2, 3, 3].
|
|
|
|
*
|
|
|
|
* If the dst is >= the image size, then...
|
|
|
|
* - The 4 corners are not stretched at all.
|
|
|
|
* - The sides are stretched in only one axis.
|
|
|
|
* - The center is stretched in both axes.
|
|
|
|
* Else, for each axis where dst < image,
|
|
|
|
* - The corners shrink proportionally
|
|
|
|
* - The sides (along the shrink axis) and center are not drawn
|
|
|
|
*/
|
|
|
|
void drawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
|
2016-03-17 15:14:57 +00:00
|
|
|
const SkPaint* paint = nullptr);
|
|
|
|
void drawImageNine(const sk_sp<SkImage>& image, const SkIRect& center, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr) {
|
|
|
|
this->drawImageNine(image.get(), center, dst, paint);
|
|
|
|
}
|
2015-06-25 19:32:03 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the specified bitmap, with its top/left corner at (x,y), using the
|
|
|
|
specified paint, transformed by the current matrix. Note: if the paint
|
|
|
|
contains a maskfilter that generates a mask which extends beyond the
|
|
|
|
bitmap's original width/height, then the bitmap will be drawn as if it
|
|
|
|
were in a Shader with CLAMP mode. Thus the color outside of the original
|
|
|
|
width/height will be the edge color replicated.
|
2013-12-05 15:43:19 +00:00
|
|
|
|
|
|
|
If a shader is present on the paint it will be ignored, except in the
|
2014-03-26 13:44:58 +00:00
|
|
|
case where the bitmap is kAlpha_8_SkColorType. In that case, the color is
|
2013-12-05 15:43:19 +00:00
|
|
|
generated by the shader.
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
@param bitmap The bitmap to be drawn
|
|
|
|
@param left The position of the left side of the bitmap being drawn
|
|
|
|
@param top The position of the top side of the bitmap being drawn
|
|
|
|
@param paint The paint used to draw the bitmap, or NULL
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
|
|
|
|
const SkPaint* paint = NULL);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-07-14 17:54:12 +00:00
|
|
|
/** Draw the specified bitmap, scaling and translating so that it fills the specified
|
|
|
|
* dst rect. If the src rect is non-null, only that subset of the bitmap is transformed
|
|
|
|
* and drawn.
|
|
|
|
*
|
|
|
|
* @param bitmap The bitmap to be drawn
|
|
|
|
* @param src Optional: specify the subset of the bitmap to be drawn
|
|
|
|
* @param dst The destination rectangle where the scaled/translated
|
|
|
|
* bitmap will be drawn
|
|
|
|
* @param paint The paint used to draw the bitmap, or NULL
|
|
|
|
* @param constraint Control the tradeoff between speed and exactness w.r.t. the src-rect.
|
|
|
|
*/
|
2015-08-06 17:02:53 +00:00
|
|
|
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& src, const SkRect& dst,
|
2015-07-17 14:09:43 +00:00
|
|
|
const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
|
2015-08-06 17:02:53 +00:00
|
|
|
// variant where src is SkIRect
|
2015-07-17 14:09:43 +00:00
|
|
|
void drawBitmapRect(const SkBitmap& bitmap, const SkIRect& isrc, const SkRect& dst,
|
|
|
|
const SkPaint* paint, SrcRectConstraint = kStrict_SrcRectConstraint);
|
2015-08-06 17:02:53 +00:00
|
|
|
void drawBitmapRect(const SkBitmap& bitmap, const SkRect& dst, const SkPaint* paint,
|
2015-10-23 16:27:42 +00:00
|
|
|
SrcRectConstraint = kStrict_SrcRectConstraint);
|
2015-07-17 14:09:43 +00:00
|
|
|
|
2011-09-07 11:57:34 +00:00
|
|
|
/**
|
2016-08-02 15:05:56 +00:00
|
|
|
* Draw the bitmap stretched or shrunk differentially to fit into dst.
|
2011-09-07 11:57:34 +00:00
|
|
|
* center is a rect within the bitmap, and logically divides the bitmap
|
|
|
|
* into 9 sections (3x3). For example, if the middle pixel of a [5x5]
|
|
|
|
* bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
|
|
|
|
*
|
|
|
|
* If the dst is >= the bitmap size, then...
|
2013-07-25 12:10:42 +00:00
|
|
|
* - The 4 corners are not stretched at all.
|
|
|
|
* - The sides are stretched in only one axis.
|
|
|
|
* - The center is stretched in both axes.
|
2011-09-07 11:57:34 +00:00
|
|
|
* Else, for each axis where dst < bitmap,
|
|
|
|
* - The corners shrink proportionally
|
|
|
|
* - The sides (along the shrink axis) and center are not drawn
|
|
|
|
*/
|
2015-01-09 22:17:40 +00:00
|
|
|
void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
|
|
|
|
const SkPaint* paint = NULL);
|
2011-09-07 11:57:34 +00:00
|
|
|
|
2016-08-02 15:05:56 +00:00
|
|
|
/**
|
|
|
|
* Specifies coordinates to divide a bitmap into (xCount*yCount) rects.
|
2016-09-30 19:41:42 +00:00
|
|
|
*
|
|
|
|
* If the lattice divs or bounds are invalid, the entire lattice
|
|
|
|
* struct will be ignored on the draw call.
|
2016-08-02 15:05:56 +00:00
|
|
|
*/
|
|
|
|
struct Lattice {
|
2016-09-02 18:24:30 +00:00
|
|
|
enum Flags : uint8_t {
|
|
|
|
// If set, indicates that we should not draw corresponding rect.
|
|
|
|
kTransparent_Flags = 1 << 0,
|
|
|
|
};
|
|
|
|
|
2016-08-02 15:05:56 +00:00
|
|
|
// An array of x-coordinates that divide the bitmap vertically.
|
2016-09-30 19:41:42 +00:00
|
|
|
// These must be unique, increasing, and in the set [fBounds.fLeft, fBounds.fRight).
|
2016-08-02 15:05:56 +00:00
|
|
|
// Does not have ownership.
|
2016-09-30 19:41:42 +00:00
|
|
|
const int* fXDivs;
|
2016-08-02 15:05:56 +00:00
|
|
|
|
|
|
|
// An array of y-coordinates that divide the bitmap horizontally.
|
2016-09-30 19:41:42 +00:00
|
|
|
// These must be unique, increasing, and in the set [fBounds.fTop, fBounds.fBottom).
|
2016-08-02 15:05:56 +00:00
|
|
|
// Does not have ownership.
|
2016-09-30 19:41:42 +00:00
|
|
|
const int* fYDivs;
|
2016-09-02 18:24:30 +00:00
|
|
|
|
|
|
|
// If non-null, the length of this array must be equal to
|
|
|
|
// (fXCount + 1) * (fYCount + 1). Note that we allow the first rect
|
2016-09-30 19:41:42 +00:00
|
|
|
// in each direction to be empty (ex: fXDivs[0] = fBounds.fLeft).
|
|
|
|
// In this case, the caller still must specify a flag (as a placeholder)
|
|
|
|
// for these empty rects.
|
2016-09-02 18:24:30 +00:00
|
|
|
// The flags correspond to the rects in the lattice, first moving
|
|
|
|
// left to right and then top to bottom.
|
2016-09-30 19:41:42 +00:00
|
|
|
const Flags* fFlags;
|
2016-09-02 18:24:30 +00:00
|
|
|
|
|
|
|
// The number of fXDivs.
|
2016-09-30 19:41:42 +00:00
|
|
|
int fXCount;
|
2016-08-02 15:05:56 +00:00
|
|
|
|
|
|
|
// The number of fYDivs.
|
2016-09-30 19:41:42 +00:00
|
|
|
int fYCount;
|
|
|
|
|
|
|
|
// The bound to draw from. Must be contained by the src that is being drawn,
|
|
|
|
// non-empty, and non-inverted.
|
|
|
|
// If nullptr, the bounds are the entire src.
|
|
|
|
const SkIRect* fBounds;
|
2016-08-02 15:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the bitmap stretched or shrunk differentially to fit into dst.
|
|
|
|
*
|
|
|
|
* Moving horizontally across the bitmap, alternating rects will be "scalable"
|
|
|
|
* (in the x-dimension) to fit into dst or must be left "fixed". The first rect
|
|
|
|
* is treated as "fixed", but it's possible to specify an empty first rect by
|
|
|
|
* making lattice.fXDivs[0] = 0.
|
|
|
|
*
|
|
|
|
* The scale factor for all "scalable" rects will be the same, and may be greater
|
|
|
|
* than or less than 1 (meaning we can stretch or shrink). If the number of
|
|
|
|
* "fixed" pixels is greater than the width of the dst, we will collapse all of
|
|
|
|
* the "scalable" regions and appropriately downscale the "fixed" regions.
|
|
|
|
*
|
|
|
|
* The same interpretation also applies to the y-dimension.
|
|
|
|
*/
|
|
|
|
void drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr);
|
|
|
|
void drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint* paint = nullptr);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the text, with origin at (x,y), using the specified paint.
|
|
|
|
The origin is interpreted based on the Align setting in the paint.
|
|
|
|
@param text The text to be drawn
|
|
|
|
@param byteLength The number of bytes to read from the text parameter
|
|
|
|
@param x The x-coordinate of the origin of the text being drawn
|
|
|
|
@param y The y-coordinate of the origin of the text being drawn
|
|
|
|
@param paint The paint used for the text (e.g. color, size, style)
|
|
|
|
*/
|
2014-12-21 19:38:35 +00:00
|
|
|
void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-04-28 19:35:12 +00:00
|
|
|
/** Draw null-terminated UTF-8 string, with origin at (x,y), using the specified paint.
|
|
|
|
The origin is interpreted based on the Align setting in the paint.
|
|
|
|
@param string The null-terminated string to be drawn
|
|
|
|
@param x The x-coordinate of the origin of the string being drawn
|
|
|
|
@param y The y-coordinate of the origin of the string being drawn
|
|
|
|
@param paint The paint used for the string (e.g. color, size, style)
|
|
|
|
*/
|
|
|
|
void drawString(const char* string, SkScalar x, SkScalar y, const SkPaint& paint) {
|
|
|
|
if (!string) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->drawText(string, strlen(string), x, y, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Draw string, with origin at (x,y), using the specified paint.
|
|
|
|
The origin is interpreted based on the Align setting in the paint.
|
|
|
|
@param string The string to be drawn
|
|
|
|
@param x The x-coordinate of the origin of the string being drawn
|
|
|
|
@param y The y-coordinate of the origin of the string being drawn
|
|
|
|
@param paint The paint used for the string (e.g. color, size, style)
|
|
|
|
*/
|
|
|
|
void drawString(const SkString& string, SkScalar x, SkScalar y, const SkPaint& paint);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the text, with each character/glyph origin specified by the pos[]
|
2011-01-11 18:32:13 +00:00
|
|
|
array. The origin is interpreted by the Align setting in the paint.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param text The text to be drawn
|
|
|
|
@param byteLength The number of bytes to read from the text parameter
|
|
|
|
@param pos Array of positions, used to position each character
|
|
|
|
@param paint The paint used for the text (e.g. color, size, style)
|
|
|
|
*/
|
2014-12-21 19:38:35 +00:00
|
|
|
void drawPosText(const void* text, size_t byteLength, const SkPoint pos[],
|
|
|
|
const SkPaint& paint);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the text, with each character/glyph origin specified by the x
|
|
|
|
coordinate taken from the xpos[] array, and the y from the constY param.
|
2011-01-11 18:32:13 +00:00
|
|
|
The origin is interpreted by the Align setting in the paint.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param text The text to be drawn
|
|
|
|
@param byteLength The number of bytes to read from the text parameter
|
|
|
|
@param xpos Array of x-positions, used to position each character
|
|
|
|
@param constY The shared Y coordinate for all of the positions
|
|
|
|
@param paint The paint used for the text (e.g. color, size, style)
|
|
|
|
*/
|
2014-12-21 19:38:35 +00:00
|
|
|
void drawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY,
|
|
|
|
const SkPaint& paint);
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the text, with origin at (x,y), using the specified paint, along
|
|
|
|
the specified path. The paint's Align setting determins where along the
|
|
|
|
path to start the text.
|
|
|
|
@param text The text to be drawn
|
|
|
|
@param byteLength The number of bytes to read from the text parameter
|
|
|
|
@param path The path the text should follow for its baseline
|
|
|
|
@param hOffset The distance along the path to add to the text's
|
|
|
|
starting position
|
|
|
|
@param vOffset The distance above(-) or below(+) the path to
|
|
|
|
position the text
|
|
|
|
@param paint The paint used for the text
|
|
|
|
*/
|
2014-12-21 19:38:35 +00:00
|
|
|
void drawTextOnPathHV(const void* text, size_t byteLength, const SkPath& path, SkScalar hOffset,
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar vOffset, const SkPaint& paint);
|
|
|
|
|
|
|
|
/** Draw the text, with origin at (x,y), using the specified paint, along
|
|
|
|
the specified path. The paint's Align setting determins where along the
|
|
|
|
path to start the text.
|
|
|
|
@param text The text to be drawn
|
|
|
|
@param byteLength The number of bytes to read from the text parameter
|
|
|
|
@param path The path the text should follow for its baseline
|
|
|
|
@param matrix (may be null) Applied to the text before it is
|
|
|
|
mapped onto the path
|
|
|
|
@param paint The paint used for the text
|
|
|
|
*/
|
2014-12-21 19:38:35 +00:00
|
|
|
void drawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
|
|
|
|
const SkMatrix* matrix, const SkPaint& paint);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2016-07-07 19:47:17 +00:00
|
|
|
/**
|
|
|
|
* Draw the text with each character/glyph individually transformed by its xform.
|
|
|
|
* If cullRect is not null, it is a conservative bounds of what will be drawn
|
2016-07-07 23:32:51 +00:00
|
|
|
* taking into account the xforms and the paint, and will be used to accelerate culling.
|
2016-07-07 19:47:17 +00:00
|
|
|
*/
|
|
|
|
void drawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
|
|
|
|
const SkRect* cullRect, const SkPaint& paint);
|
|
|
|
|
2014-08-21 15:53:26 +00:00
|
|
|
/** Draw the text blob, offset by (x,y), using the specified paint.
|
|
|
|
@param blob The text blob to be drawn
|
|
|
|
@param x The x-offset of the text being drawn
|
|
|
|
@param y The y-offset of the text being drawn
|
|
|
|
@param paint The paint used for the text (e.g. color, size, style)
|
|
|
|
*/
|
|
|
|
void drawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, const SkPaint& paint);
|
2016-08-10 21:16:41 +00:00
|
|
|
void drawTextBlob(const sk_sp<SkTextBlob>& blob, SkScalar x, SkScalar y, const SkPaint& paint) {
|
|
|
|
this->drawTextBlob(blob.get(), x, y, paint);
|
|
|
|
}
|
2014-08-21 15:53:26 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Draw the picture into this canvas. This method effective brackets the
|
|
|
|
playback of the picture's draw calls with save/restore, so the state
|
2013-01-02 16:59:19 +00:00
|
|
|
of this canvas will be unchanged after this call.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param picture The recorded drawing commands to playback into this
|
|
|
|
canvas.
|
|
|
|
*/
|
2015-04-30 20:09:24 +00:00
|
|
|
void drawPicture(const SkPicture* picture) {
|
|
|
|
this->drawPicture(picture, NULL, NULL);
|
|
|
|
}
|
2016-03-18 14:25:55 +00:00
|
|
|
void drawPicture(const sk_sp<SkPicture>& picture) {
|
2016-03-17 15:14:57 +00:00
|
|
|
this->drawPicture(picture.get());
|
|
|
|
}
|
2014-06-04 12:40:44 +00:00
|
|
|
|
2014-08-09 18:08:05 +00:00
|
|
|
/**
|
|
|
|
* Draw the picture into this canvas.
|
|
|
|
*
|
|
|
|
* If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
|
|
|
|
* logically equivalent to
|
|
|
|
* save/concat/drawPicture/restore
|
|
|
|
*
|
|
|
|
* If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
|
|
|
|
* alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
|
|
|
|
* This is logically equivalent to
|
|
|
|
* saveLayer(paint)/drawPicture/restore
|
|
|
|
*/
|
|
|
|
void drawPicture(const SkPicture*, const SkMatrix* matrix, const SkPaint* paint);
|
2016-03-18 14:25:55 +00:00
|
|
|
void drawPicture(const sk_sp<SkPicture>& picture, const SkMatrix* matrix, const SkPaint* paint) {
|
2016-03-17 15:14:57 +00:00
|
|
|
this->drawPicture(picture.get(), matrix, paint);
|
|
|
|
}
|
2014-08-09 18:08:05 +00:00
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
|
|
|
/**
|
2016-08-25 13:30:23 +00:00
|
|
|
* Draw the picture into this canvas, with shadows!
|
2016-07-21 17:25:54 +00:00
|
|
|
*
|
|
|
|
* We will use the canvas's lights along with the picture information (draw depths of
|
|
|
|
* objects, etc) to first create a set of shadowmaps for the light-picture pairs, and
|
|
|
|
* then use that set of shadowmaps to render the scene with shadows.
|
|
|
|
*
|
|
|
|
* If matrix is non-null, apply that matrix to the CTM when drawing this picture. This is
|
|
|
|
* logically equivalent to
|
|
|
|
* save/concat/drawPicture/restore
|
|
|
|
*
|
|
|
|
* If paint is non-null, draw the picture into a temporary buffer, and then apply the paint's
|
|
|
|
* alpha/colorfilter/imagefilter/xfermode to that buffer as it is drawn to the canvas.
|
|
|
|
* This is logically equivalent to
|
|
|
|
* saveLayer(paint)/drawPicture/restore
|
|
|
|
*
|
2016-08-25 13:30:23 +00:00
|
|
|
* We also support using variance shadow maps for blurred shadows; the user can specify
|
|
|
|
* what shadow mapping algorithm to use with params.
|
|
|
|
* - Variance Shadow Mapping works by storing both the depth and depth^2 in the shadow map.
|
|
|
|
* - Then, the shadow map can be blurred, and when reading from it, the fragment shader
|
|
|
|
* can calculate the variance of the depth at a position by doing E(x^2) - E(x)^2.
|
|
|
|
* - We can then use the depth variance and depth at a fragment to arrive at an upper bound
|
|
|
|
* of the probability that the current surface is shadowed by using Chebyshev's
|
|
|
|
* inequality, and then use that to shade the fragment.
|
|
|
|
*
|
|
|
|
* - There are a few problems with VSM.
|
|
|
|
* * Light Bleeding | Areas with high variance, such as near the edges of high up rects,
|
|
|
|
* will cause their shadow penumbras to overwrite otherwise solid
|
|
|
|
* shadows.
|
|
|
|
* * Shape Distortion | We can combat Light Bleeding by biasing the shadow (setting
|
|
|
|
* mostly shaded fragments to completely shaded) and increasing
|
|
|
|
* the minimum allowed variance. However, this warps and rounds
|
|
|
|
* out the shape of the shadow.
|
2016-07-21 17:25:54 +00:00
|
|
|
*/
|
|
|
|
void drawShadowedPicture(const SkPicture*,
|
|
|
|
const SkMatrix* matrix,
|
2016-08-25 13:30:23 +00:00
|
|
|
const SkPaint* paint,
|
|
|
|
const SkShadowParams& params);
|
2016-07-21 17:25:54 +00:00
|
|
|
void drawShadowedPicture(const sk_sp<SkPicture>& picture,
|
|
|
|
const SkMatrix* matrix,
|
2016-08-25 13:30:23 +00:00
|
|
|
const SkPaint* paint,
|
|
|
|
const SkShadowParams& params) {
|
|
|
|
this->drawShadowedPicture(picture.get(), matrix, paint, params);
|
2016-07-21 17:25:54 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-06 14:41:10 +00:00
|
|
|
/** Draw vertices from an immutable SkVertices object.
|
|
|
|
|
|
|
|
@param vertices The mesh to draw.
|
|
|
|
@param mode Used if both texs and colors are present and paint has a
|
|
|
|
shader. In this case the colors are combined with the texture
|
|
|
|
using mode, before being drawn using the paint.
|
|
|
|
@param paint Specifies the shader/texture if present.
|
|
|
|
*/
|
2017-03-17 13:50:46 +00:00
|
|
|
void drawVertices(const SkVertices* vertices, SkBlendMode mode, const SkPaint& paint);
|
|
|
|
void drawVertices(const sk_sp<SkVertices>& vertices, SkBlendMode mode, const SkPaint& paint);
|
2016-10-28 19:42:34 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
/**
|
|
|
|
Draw a cubic coons patch
|
2014-08-13 20:33:49 +00:00
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
@param cubic specifies the 4 bounding cubic bezier curves of a patch with clockwise order
|
|
|
|
starting at the top left corner.
|
|
|
|
@param colors specifies the colors for the corners which will be bilerp across the patch,
|
|
|
|
their order is clockwise starting at the top left corner.
|
2014-08-13 20:33:49 +00:00
|
|
|
@param texCoords specifies the texture coordinates that will be bilerp across the patch,
|
2014-08-12 15:34:29 +00:00
|
|
|
their order is the same as the colors.
|
2016-10-28 19:42:34 +00:00
|
|
|
@param mode specifies how are the colors and the textures combined if both of them are
|
2014-08-12 15:34:29 +00:00
|
|
|
present.
|
2014-08-07 14:49:53 +00:00
|
|
|
@param paint Specifies the shader/texture if present.
|
|
|
|
*/
|
2014-08-12 15:34:29 +00:00
|
|
|
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
2016-10-28 19:42:34 +00:00
|
|
|
const SkPoint texCoords[4], SkBlendMode mode, const SkPaint& paint);
|
|
|
|
void drawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
|
|
|
const SkPoint texCoords[4], const SkPaint& paint) {
|
|
|
|
this->drawPatch(cubics, colors, texCoords, SkBlendMode::kModulate, paint);
|
|
|
|
}
|
|
|
|
|
2015-06-24 17:29:17 +00:00
|
|
|
/**
|
|
|
|
* Draw a set of sprites from the atlas. Each is specified by a tex rectangle in the
|
|
|
|
* coordinate space of the atlas, and a corresponding xform which transforms the tex rectangle
|
|
|
|
* into a quad.
|
|
|
|
*
|
|
|
|
* xform maps [0, 0, tex.width, tex.height] -> quad
|
|
|
|
*
|
|
|
|
* The color array is optional. When specified, each color modulates the pixels in its
|
2016-10-28 19:42:34 +00:00
|
|
|
* corresponding quad (via the specified SkBlendMode).
|
2015-06-24 17:29:17 +00:00
|
|
|
*
|
|
|
|
* The cullRect is optional. When specified, it must be a conservative bounds of all of the
|
|
|
|
* resulting transformed quads, allowing the canvas to skip drawing if the cullRect does not
|
|
|
|
* intersect the current clip.
|
|
|
|
*
|
|
|
|
* The paint is optional. If specified, its antialiasing, alpha, color-filter, image-filter
|
2016-10-28 19:42:34 +00:00
|
|
|
* and blendmode are used to affect each of the quads.
|
2015-06-24 17:29:17 +00:00
|
|
|
*/
|
|
|
|
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[],
|
2016-10-28 19:42:34 +00:00
|
|
|
const SkColor colors[], int count, SkBlendMode, const SkRect* cullRect,
|
2015-06-24 17:29:17 +00:00
|
|
|
const SkPaint* paint);
|
2016-10-28 19:42:34 +00:00
|
|
|
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
|
|
|
const SkColor colors[], int count, SkBlendMode mode, const SkRect* cullRect,
|
|
|
|
const SkPaint* paint) {
|
|
|
|
this->drawAtlas(atlas.get(), xform, tex, colors, count, mode, cullRect, paint);
|
|
|
|
}
|
2015-06-24 17:29:17 +00:00
|
|
|
void drawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], int count,
|
|
|
|
const SkRect* cullRect, const SkPaint* paint) {
|
2016-10-28 19:42:34 +00:00
|
|
|
this->drawAtlas(atlas, xform, tex, nullptr, count, SkBlendMode::kDst, cullRect, paint);
|
2015-06-24 17:29:17 +00:00
|
|
|
}
|
2016-03-17 15:14:57 +00:00
|
|
|
void drawAtlas(const sk_sp<SkImage>& atlas, const SkRSXform xform[], const SkRect tex[],
|
2016-10-28 19:42:34 +00:00
|
|
|
int count, const SkRect* cullRect, const SkPaint* paint) {
|
|
|
|
this->drawAtlas(atlas.get(), xform, tex, nullptr, count, SkBlendMode::kDst,
|
|
|
|
cullRect, paint);
|
|
|
|
}
|
|
|
|
|
2015-02-06 16:36:15 +00:00
|
|
|
/**
|
|
|
|
* Draw the contents of this drawable into the canvas. If the canvas is async
|
|
|
|
* (e.g. it is recording into a picture) then the drawable will be referenced instead,
|
|
|
|
* to have its draw() method called when the picture is finalized.
|
|
|
|
*
|
|
|
|
* If the intent is to force the contents of the drawable into this canvas immediately,
|
|
|
|
* then drawable->draw(canvas) may be called.
|
|
|
|
*/
|
2015-07-07 17:22:31 +00:00
|
|
|
void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
|
|
|
|
void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
|
2014-11-12 03:36:09 +00:00
|
|
|
|
2016-03-05 00:36:20 +00:00
|
|
|
/**
|
|
|
|
* Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
|
|
|
|
* a null-terminated utf8 string, and the value is a blob of data stored in an SkData
|
|
|
|
* (which may be null). The annotation is associated with the specified rectangle.
|
|
|
|
*
|
|
|
|
* The caller still retains its ownership of the data (if any).
|
|
|
|
*
|
|
|
|
* Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
|
|
|
|
* a picture or drawing to a PDF document) will pass on this information.
|
|
|
|
*/
|
|
|
|
void drawAnnotation(const SkRect&, const char key[], SkData* value);
|
2016-04-01 11:55:51 +00:00
|
|
|
void drawAnnotation(const SkRect& rect, const char key[], const sk_sp<SkData>& value) {
|
|
|
|
this->drawAnnotation(rect, key, value.get());
|
|
|
|
}
|
2016-03-05 00:36:20 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2016-01-22 02:47:11 +00:00
|
|
|
#ifdef SK_INTERNAL
|
2016-01-25 14:23:54 +00:00
|
|
|
#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
|
|
|
|
#define SK_SUPPORT_LEGACY_DRAWFILTER
|
2016-01-22 02:47:11 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2016-01-25 14:23:54 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Get the current filter object. The filter's reference count is not
|
2010-02-11 16:05:15 +00:00
|
|
|
affected. The filter is saved/restored, just like the matrix and clip.
|
2008-12-17 15:59:43 +00:00
|
|
|
@return the canvas' filter (or NULL).
|
|
|
|
*/
|
2016-01-22 02:47:11 +00:00
|
|
|
SK_ATTR_EXTERNALLY_DEPRECATED("getDrawFilter use is deprecated")
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDrawFilter* getDrawFilter() const;
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Set the new filter (or NULL). Pass NULL to clear any existing filter.
|
|
|
|
As a convenience, the parameter is returned. If an existing filter
|
|
|
|
exists, its refcnt is decrement. If the new filter is not null, its
|
2010-02-11 16:05:15 +00:00
|
|
|
refcnt is incremented. The filter is saved/restored, just like the
|
|
|
|
matrix and clip.
|
2008-12-17 15:59:43 +00:00
|
|
|
@param filter the new filter (or NULL)
|
|
|
|
@return the new filter
|
|
|
|
*/
|
2016-01-22 02:47:11 +00:00
|
|
|
SK_ATTR_EXTERNALLY_DEPRECATED("setDrawFilter use is deprecated")
|
2008-12-17 15:59:43 +00:00
|
|
|
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter);
|
2016-01-22 02:47:11 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-02-24 19:38:20 +00:00
|
|
|
/**
|
|
|
|
* Return true if the current clip is empty (i.e. nothing will draw).
|
|
|
|
* Note: this is not always a free call, so it should not be used
|
|
|
|
* more often than necessary. However, once the canvas has computed this
|
|
|
|
* result, subsequent calls will be cheap (until the clip state changes,
|
|
|
|
* which can happen on any clip..() or restore() call.
|
|
|
|
*/
|
2014-02-28 18:19:39 +00:00
|
|
|
virtual bool isClipEmpty() const;
|
2014-02-24 19:38:20 +00:00
|
|
|
|
2014-03-08 03:57:19 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the current clip is just a (non-empty) rectangle.
|
|
|
|
* Returns false if the clip is empty, or if it is complex.
|
|
|
|
*/
|
|
|
|
virtual bool isClipRect() const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Return the current matrix on the canvas.
|
|
|
|
This does not account for the translate in any of the devices.
|
|
|
|
@return The current matrix on the canvas.
|
|
|
|
*/
|
2012-02-24 21:54:07 +00:00
|
|
|
const SkMatrix& getTotalMatrix() const;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-04-23 15:26:43 +00:00
|
|
|
// don't call
|
2016-10-27 18:47:55 +00:00
|
|
|
GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext();
|
2016-04-23 15:26:43 +00:00
|
|
|
|
|
|
|
// don't call
|
|
|
|
static void Internal_Private_SetIgnoreSaveLayerBounds(bool);
|
|
|
|
static bool Internal_Private_GetIgnoreSaveLayerBounds();
|
|
|
|
static void Internal_Private_SetTreatSpriteAsBitmap(bool);
|
|
|
|
static bool Internal_Private_GetTreatSpriteAsBitmap();
|
|
|
|
|
|
|
|
// TEMP helpers until we switch virtual over to const& for src-rect
|
|
|
|
void legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
|
|
|
|
void legacy_drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
|
|
|
|
const SkPaint* paint,
|
|
|
|
SrcRectConstraint constraint = kStrict_SrcRectConstraint);
|
|
|
|
|
2017-03-07 14:37:29 +00:00
|
|
|
/**
|
|
|
|
* Returns the global clip as a region. If the clip contains AA, then only the bounds
|
|
|
|
* of the clip may be returned.
|
|
|
|
*/
|
2017-01-19 16:36:41 +00:00
|
|
|
void temporary_internal_getRgnClip(SkRegion*);
|
|
|
|
|
2016-04-21 18:05:32 +00:00
|
|
|
protected:
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
2016-07-13 21:05:28 +00:00
|
|
|
/** Returns the current (cumulative) draw depth of the canvas.
|
|
|
|
*/
|
|
|
|
SkScalar getZ() const;
|
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
sk_sp<SkLights> fLights;
|
|
|
|
#endif
|
|
|
|
|
2014-02-05 15:32:21 +00:00
|
|
|
// default impl defers to getDevice()->newSurface(info)
|
2016-03-24 01:59:25 +00:00
|
|
|
virtual sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&);
|
2014-02-05 15:32:21 +00:00
|
|
|
|
2014-02-13 17:14:46 +00:00
|
|
|
// default impl defers to its device
|
2015-05-26 18:31:54 +00:00
|
|
|
virtual bool onPeekPixels(SkPixmap*);
|
|
|
|
virtual bool onAccessTopLayerPixels(SkPixmap*);
|
2016-07-07 23:44:27 +00:00
|
|
|
virtual SkImageInfo onImageInfo() const;
|
|
|
|
virtual bool onGetProps(SkSurfaceProps*) const;
|
|
|
|
virtual void onFlush();
|
2014-02-13 17:14:46 +00:00
|
|
|
|
2014-03-12 20:21:48 +00:00
|
|
|
// Subclass save/restore notifiers.
|
|
|
|
// Overriders should call the corresponding INHERITED method up the inheritance chain.
|
2015-12-18 15:09:18 +00:00
|
|
|
// getSaveLayerStrategy()'s return value may suppress full layer allocation.
|
2014-03-12 20:21:48 +00:00
|
|
|
enum SaveLayerStrategy {
|
|
|
|
kFullLayer_SaveLayerStrategy,
|
2015-12-18 15:09:18 +00:00
|
|
|
kNoLayer_SaveLayerStrategy,
|
2014-03-12 20:21:48 +00:00
|
|
|
};
|
|
|
|
|
2014-06-17 20:52:18 +00:00
|
|
|
virtual void willSave() {}
|
2015-12-18 15:09:18 +00:00
|
|
|
// Overriders should call the corresponding INHERITED method up the inheritance chain.
|
|
|
|
virtual SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) {
|
|
|
|
return kFullLayer_SaveLayerStrategy;
|
|
|
|
}
|
2014-05-14 13:13:44 +00:00
|
|
|
virtual void willRestore() {}
|
2014-08-13 20:33:49 +00:00
|
|
|
virtual void didRestore() {}
|
2014-05-14 13:13:44 +00:00
|
|
|
virtual void didConcat(const SkMatrix&) {}
|
|
|
|
virtual void didSetMatrix(const SkMatrix&) {}
|
2016-08-19 16:05:27 +00:00
|
|
|
virtual void didTranslate(SkScalar dx, SkScalar dy) {
|
|
|
|
this->didConcat(SkMatrix::MakeTrans(dx, dy));
|
|
|
|
}
|
2016-07-21 17:25:54 +00:00
|
|
|
|
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
2016-07-13 21:05:28 +00:00
|
|
|
virtual void didTranslateZ(SkScalar) {}
|
2016-07-21 17:25:54 +00:00
|
|
|
#endif
|
2014-03-13 20:03:58 +00:00
|
|
|
|
2017-01-23 19:09:13 +00:00
|
|
|
virtual SkRect onGetLocalClipBounds() const;
|
|
|
|
virtual SkIRect onGetDeviceClipBounds() const;
|
|
|
|
|
|
|
|
|
2016-03-05 00:36:20 +00:00
|
|
|
virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
|
2014-02-21 02:32:36 +00:00
|
|
|
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
|
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
|
|
|
|
SkScalar y, const SkPaint& paint);
|
2014-04-24 03:05:07 +00:00
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
virtual void onDrawPosText(const void* text, size_t byteLength,
|
|
|
|
const SkPoint pos[], const SkPaint& paint);
|
2014-04-24 03:05:07 +00:00
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
virtual void onDrawPosTextH(const void* text, size_t byteLength,
|
|
|
|
const SkScalar xpos[], SkScalar constY,
|
|
|
|
const SkPaint& paint);
|
2014-04-24 03:05:07 +00:00
|
|
|
|
2014-04-23 04:00:17 +00:00
|
|
|
virtual void onDrawTextOnPath(const void* text, size_t byteLength,
|
|
|
|
const SkPath& path, const SkMatrix* matrix,
|
|
|
|
const SkPaint& paint);
|
2016-07-07 19:47:17 +00:00
|
|
|
virtual void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
|
|
|
|
const SkRect* cullRect, const SkPaint& paint);
|
2014-08-13 20:33:49 +00:00
|
|
|
|
2014-08-21 15:53:26 +00:00
|
|
|
virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
|
|
|
|
const SkPaint& paint);
|
|
|
|
|
2014-08-12 15:34:29 +00:00
|
|
|
virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
|
2016-11-03 18:45:31 +00:00
|
|
|
const SkPoint texCoords[4], SkBlendMode, const SkPaint& paint);
|
2014-04-23 04:00:17 +00:00
|
|
|
|
2015-07-07 17:22:31 +00:00
|
|
|
virtual void onDrawDrawable(SkDrawable*, const SkMatrix*);
|
2014-11-12 03:36:09 +00:00
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawPaint(const SkPaint&);
|
|
|
|
virtual void onDrawRect(const SkRect&, const SkPaint&);
|
2016-08-25 20:54:30 +00:00
|
|
|
virtual void onDrawRegion(const SkRegion& region, const SkPaint& paint);
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawOval(const SkRect&, const SkPaint&);
|
2016-08-19 18:25:19 +00:00
|
|
|
virtual void onDrawArc(const SkRect&, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
|
|
|
|
const SkPaint&);
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawRRect(const SkRRect&, const SkPaint&);
|
|
|
|
virtual void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&);
|
2017-03-17 13:50:46 +00:00
|
|
|
virtual void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&);
|
2015-06-24 17:29:17 +00:00
|
|
|
virtual void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
|
2016-11-03 18:45:31 +00:00
|
|
|
int count, SkBlendMode, const SkRect* cull, const SkPaint*);
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawPath(const SkPath&, const SkPaint&);
|
|
|
|
virtual void onDrawImage(const SkImage*, SkScalar dx, SkScalar dy, const SkPaint*);
|
2015-07-28 14:35:14 +00:00
|
|
|
virtual void onDrawImageRect(const SkImage*, const SkRect*, const SkRect&, const SkPaint*,
|
|
|
|
SrcRectConstraint);
|
2015-06-25 19:32:03 +00:00
|
|
|
virtual void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
|
|
|
|
const SkPaint*);
|
2016-08-16 16:31:08 +00:00
|
|
|
virtual void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint*);
|
2015-06-25 19:32:03 +00:00
|
|
|
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawBitmap(const SkBitmap&, SkScalar dx, SkScalar dy, const SkPaint*);
|
|
|
|
virtual void onDrawBitmapRect(const SkBitmap&, const SkRect*, const SkRect&, const SkPaint*,
|
2015-07-28 14:35:14 +00:00
|
|
|
SrcRectConstraint);
|
2015-01-05 15:49:08 +00:00
|
|
|
virtual void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
|
|
|
|
const SkPaint*);
|
2016-08-16 16:31:08 +00:00
|
|
|
virtual void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
|
|
|
|
const SkPaint*);
|
2015-01-05 15:49:08 +00:00
|
|
|
|
2014-02-28 18:19:39 +00:00
|
|
|
enum ClipEdgeStyle {
|
|
|
|
kHard_ClipEdgeStyle,
|
|
|
|
kSoft_ClipEdgeStyle
|
|
|
|
};
|
|
|
|
|
2016-12-09 14:00:50 +00:00
|
|
|
virtual void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle);
|
|
|
|
virtual void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle);
|
|
|
|
virtual void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle);
|
|
|
|
virtual void onClipRegion(const SkRegion& deviceRgn, SkClipOp);
|
2014-02-28 18:19:39 +00:00
|
|
|
|
2014-03-28 16:08:05 +00:00
|
|
|
virtual void onDiscard();
|
|
|
|
|
2014-08-09 18:08:05 +00:00
|
|
|
virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
|
2014-06-04 12:40:44 +00:00
|
|
|
|
2016-07-21 17:25:54 +00:00
|
|
|
#ifdef SK_EXPERIMENTAL_SHADOWING
|
|
|
|
virtual void onDrawShadowedPicture(const SkPicture*,
|
|
|
|
const SkMatrix*,
|
2016-08-25 13:30:23 +00:00
|
|
|
const SkPaint*,
|
|
|
|
const SkShadowParams& params);
|
2016-07-21 17:25:54 +00:00
|
|
|
#endif
|
2016-10-06 18:33:43 +00:00
|
|
|
|
2012-02-24 21:54:07 +00:00
|
|
|
// Clip rectangle bounds. Called internally by saveLayer.
|
|
|
|
// returns false if the entire rectangle is entirely clipped out
|
2014-02-05 17:51:22 +00:00
|
|
|
// If non-NULL, The imageFilter parameter will be used to expand the clip
|
|
|
|
// and offscreen bounds for any margin required by the filter DAG.
|
2015-12-18 15:09:18 +00:00
|
|
|
bool clipRectBounds(const SkRect* bounds, SaveLayerFlags, SkIRect* intersection,
|
2014-02-05 17:51:22 +00:00
|
|
|
const SkImageFilter* imageFilter = NULL);
|
2012-02-24 21:54:07 +00:00
|
|
|
|
2015-07-16 14:40:45 +00:00
|
|
|
private:
|
2016-08-18 19:45:34 +00:00
|
|
|
/** After calling saveLayer(), there can be any number of devices that make
|
|
|
|
up the top-most drawing area. LayerIter can be used to iterate through
|
|
|
|
those devices. Note that the iterator is only valid until the next API
|
|
|
|
call made on the canvas. Ownership of all pointers in the iterator stays
|
|
|
|
with the canvas, so none of them should be modified or deleted.
|
|
|
|
*/
|
|
|
|
class LayerIter /*: SkNoncopyable*/ {
|
|
|
|
public:
|
|
|
|
/** Initialize iterator with canvas, and set values for 1st device */
|
|
|
|
LayerIter(SkCanvas*);
|
|
|
|
~LayerIter();
|
|
|
|
|
|
|
|
/** Return true if the iterator is done */
|
|
|
|
bool done() const { return fDone; }
|
|
|
|
/** Cycle to the next device */
|
|
|
|
void next();
|
|
|
|
|
|
|
|
// These reflect the current device in the iterator
|
|
|
|
|
|
|
|
SkBaseDevice* device() const;
|
|
|
|
const SkMatrix& matrix() const;
|
2017-03-07 14:37:29 +00:00
|
|
|
void clip(SkRegion*) const;
|
2016-08-18 19:45:34 +00:00
|
|
|
const SkPaint& paint() const;
|
|
|
|
int x() const;
|
|
|
|
int y() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// used to embed the SkDrawIter object directly in our instance, w/o
|
|
|
|
// having to expose that class def to the public. There is an assert
|
|
|
|
// in our constructor to ensure that fStorage is large enough
|
|
|
|
// (though needs to be a compile-time-assert!). We use intptr_t to work
|
|
|
|
// safely with 32 and 64 bit machines (to ensure the storage is enough)
|
|
|
|
intptr_t fStorage[32];
|
|
|
|
class SkDrawIter* fImpl; // this points at fStorage
|
|
|
|
SkPaint fDefaultPaint;
|
|
|
|
bool fDone;
|
|
|
|
};
|
2016-10-06 18:33:43 +00:00
|
|
|
|
2015-12-18 15:09:18 +00:00
|
|
|
static bool BoundsAffectsClip(SaveLayerFlags);
|
2015-12-21 21:09:44 +00:00
|
|
|
static SaveLayerFlags LegacySaveFlagsToSaveLayerFlags(uint32_t legacySaveFlags);
|
2015-12-18 15:09:18 +00:00
|
|
|
|
2016-07-20 13:04:34 +00:00
|
|
|
static void DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filter,
|
2017-02-14 19:25:14 +00:00
|
|
|
SkBaseDevice* dst, const SkIPoint& dstOrigin,
|
2017-03-07 14:37:29 +00:00
|
|
|
const SkMatrix& ctm);
|
2016-07-20 13:04:34 +00:00
|
|
|
|
2015-07-16 14:40:45 +00:00
|
|
|
enum ShaderOverrideOpacity {
|
|
|
|
kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
|
|
|
|
kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
|
|
|
|
kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
|
|
|
|
};
|
|
|
|
|
2012-08-28 12:19:02 +00:00
|
|
|
// notify our surface (if we have one) that we are about to draw, so it
|
|
|
|
// can perform copy-on-write or invalidate any cached images
|
2015-07-16 14:40:45 +00:00
|
|
|
void predrawNotify(bool willOverwritesEntireSurface = false);
|
|
|
|
void predrawNotify(const SkRect* rect, const SkPaint* paint, ShaderOverrideOpacity);
|
|
|
|
void predrawNotify(const SkRect* rect, const SkPaint* paint, bool shaderOverrideIsOpaque) {
|
|
|
|
this->predrawNotify(rect, paint, shaderOverrideIsOpaque ? kOpaque_ShaderOverrideOpacity
|
|
|
|
: kNotOpaque_ShaderOverrideOpacity);
|
|
|
|
}
|
2012-08-28 12:19:02 +00:00
|
|
|
|
2017-01-13 16:56:38 +00:00
|
|
|
SkBaseDevice* getDevice() const;
|
|
|
|
SkBaseDevice* getTopDevice() const;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
class MCRec;
|
|
|
|
|
|
|
|
SkDeque fMCStack;
|
|
|
|
// points to top of stack
|
|
|
|
MCRec* fMCRec;
|
|
|
|
// the first N recs that can fit here mean we won't call malloc
|
2015-04-07 11:40:48 +00:00
|
|
|
enum {
|
2015-05-01 16:34:31 +00:00
|
|
|
kMCRecSize = 128, // most recent measurement
|
2015-11-16 21:22:24 +00:00
|
|
|
kMCRecCount = 32, // common depth for save/restores
|
2017-04-28 17:48:37 +00:00
|
|
|
kDeviceCMSize = 224, // most recent measurement
|
2015-04-07 11:40:48 +00:00
|
|
|
};
|
|
|
|
intptr_t fMCRecStorage[kMCRecSize * kMCRecCount / sizeof(intptr_t)];
|
2015-05-01 16:34:31 +00:00
|
|
|
intptr_t fDeviceCMStorage[kDeviceCMSize / sizeof(intptr_t)];
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-09-22 14:29:03 +00:00
|
|
|
const SkSurfaceProps fProps;
|
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
int fSaveCount; // value returned by getSaveCount()
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2012-09-26 02:24:45 +00:00
|
|
|
SkMetaData* fMetaData;
|
2017-01-10 16:58:39 +00:00
|
|
|
std::unique_ptr<SkRasterHandleAllocator> fAllocator;
|
2012-09-26 02:24:45 +00:00
|
|
|
|
2012-08-28 12:19:02 +00:00
|
|
|
SkSurface_Base* fSurfaceBase;
|
|
|
|
SkSurface_Base* getSurfaceBase() const { return fSurfaceBase; }
|
|
|
|
void setSurfaceBase(SkSurface_Base* sb) {
|
|
|
|
fSurfaceBase = sb;
|
|
|
|
}
|
|
|
|
friend class SkSurface_Base;
|
2013-04-11 17:52:05 +00:00
|
|
|
friend class SkSurface_Gpu;
|
2012-10-11 02:01:14 +00:00
|
|
|
|
2016-12-12 22:39:55 +00:00
|
|
|
SkIRect fClipRestrictionRect = SkIRect::MakeEmpty();
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-12-11 15:07:37 +00:00
|
|
|
void doSave();
|
|
|
|
void checkForDeferredSave();
|
2016-04-20 23:36:51 +00:00
|
|
|
void internalSetMatrix(const SkMatrix&);
|
2014-12-11 15:07:37 +00:00
|
|
|
|
2014-03-12 18:28:35 +00:00
|
|
|
friend class SkDrawIter; // needs setupDrawForLayerDevice()
|
2012-03-23 15:36:36 +00:00
|
|
|
friend class AutoDrawLooper;
|
2014-05-19 13:53:10 +00:00
|
|
|
friend class SkDebugCanvas; // needs experimental fAllowSimplifyClip
|
2014-06-30 16:05:34 +00:00
|
|
|
friend class SkSurface_Raster; // needs getDevice()
|
2016-12-02 17:05:41 +00:00
|
|
|
friend class SkRecorder; // resetForNextPicture
|
|
|
|
friend class SkLiteRecorder; // resetForNextPicture
|
|
|
|
friend class SkNoDrawCanvas; // InitFlags
|
2014-11-20 18:44:58 +00:00
|
|
|
friend class SkPictureImageFilter; // SkCanvas(SkBaseDevice*, SkSurfaceProps*, InitFlags)
|
2015-07-16 14:40:45 +00:00
|
|
|
friend class SkPictureRecord; // predrawNotify (why does it need it? <reed>)
|
2015-12-18 15:09:18 +00:00
|
|
|
friend class SkPicturePlayback; // SaveFlagsToSaveLayerFlags
|
2016-10-06 18:33:43 +00:00
|
|
|
friend class SkDeferredCanvas; // For use of resetForNextPicture
|
2016-11-22 16:31:41 +00:00
|
|
|
friend class SkOverdrawCanvas;
|
2017-01-10 16:58:39 +00:00
|
|
|
friend class SkRasterHandleAllocator;
|
2014-09-24 20:03:30 +00:00
|
|
|
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
enum InitFlags {
|
|
|
|
kDefault_InitFlags = 0,
|
|
|
|
kConservativeRasterClip_InitFlag = 1 << 0,
|
|
|
|
};
|
2014-11-19 16:04:34 +00:00
|
|
|
SkCanvas(const SkIRect& bounds, InitFlags);
|
2015-06-19 18:49:52 +00:00
|
|
|
SkCanvas(SkBaseDevice* device, InitFlags);
|
2017-01-10 16:58:39 +00:00
|
|
|
SkCanvas(const SkBitmap&, std::unique_ptr<SkRasterHandleAllocator>,
|
|
|
|
SkRasterHandleAllocator::Handle);
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
|
2015-04-08 18:25:48 +00:00
|
|
|
void resetForNextPicture(const SkIRect& bounds);
|
|
|
|
|
2014-09-04 19:45:18 +00:00
|
|
|
// needs gettotalclip()
|
2014-10-10 13:19:09 +00:00
|
|
|
friend class SkCanvasStateUtils;
|
2014-09-24 20:03:30 +00:00
|
|
|
|
2014-09-22 14:29:03 +00:00
|
|
|
// call this each time we attach ourselves to a device
|
|
|
|
// - constructor
|
|
|
|
// - internalSaveLayer
|
|
|
|
void setupDevice(SkBaseDevice*);
|
|
|
|
|
Revert of Revert of allow canvas to force conservative clips (for speed) (patchset #1 id:1 of https://codereview.chromium.org/554033003/)
Reason for revert:
May just rebaseline, plus want to see the results of the chrome tests, so re-trying this CL.
Original issue's description:
> Revert of allow canvas to force conservative clips (for speed) (patchset #7 id:120001 of https://codereview.chromium.org/541593005/)
>
> Reason for revert:
> multipicturedraw failed on nvprmsaa -- don't know why yet
>
> Original issue's description:
> > Allow SkCanvas to be initialized to force conservative rasterclips. This has the following effects:
> >
> > 1. Queries to the current clip will be conservatively large. This can mean the quickReject may return false more often.
> >
> > 2. The conservative clips mean less work is done.
> >
> > 3. Enabled by default for Gpu, Record, and NoSaveLayer canvases.
> >
> > 4. API is private for now.
> >
> > Committed: https://skia.googlesource.com/skia/+/27a5e656c3d6ef22f9cb34de18e1b960da3aa241
>
> TBR=robertphillips@google.com,bsalomon@google.com,mtklein@google.com,junov@google.com
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/6f09709519b79a1159f3826645f1c5fbc101ee11
R=robertphillips@google.com, bsalomon@google.com, mtklein@google.com, junov@google.com, reed@google.com
TBR=bsalomon@google.com, junov@google.com, mtklein@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@chromium.org
Review URL: https://codereview.chromium.org/560713002
2014-09-10 01:46:22 +00:00
|
|
|
SkBaseDevice* init(SkBaseDevice*, InitFlags);
|
2011-09-07 11:57:34 +00:00
|
|
|
|
2014-02-26 20:22:32 +00:00
|
|
|
/**
|
2016-02-03 02:44:15 +00:00
|
|
|
* Gets the bounds of the top level layer in global canvas coordinates. We don't want this
|
2014-02-26 20:22:32 +00:00
|
|
|
* to be public because it exposes decisions about layer sizes that are internal to the canvas.
|
|
|
|
*/
|
2016-02-03 02:44:15 +00:00
|
|
|
SkIRect getTopLayerBounds() const;
|
2014-02-17 15:24:26 +00:00
|
|
|
|
2012-09-18 15:14:33 +00:00
|
|
|
void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
|
2013-08-16 10:24:37 +00:00
|
|
|
const SkRect& dst, const SkPaint* paint,
|
2015-07-14 17:54:12 +00:00
|
|
|
SrcRectConstraint);
|
2011-10-05 19:57:55 +00:00
|
|
|
void internalDrawPaint(const SkPaint& paint);
|
2015-12-18 15:09:18 +00:00
|
|
|
void internalSaveLayer(const SaveLayerRec&, SaveLayerStrategy);
|
2017-04-28 17:48:37 +00:00
|
|
|
void internalDrawDevice(SkBaseDevice*, int x, int y, const SkPaint*, SkImage* clipImage,
|
|
|
|
const SkMatrix& clipMatrix);
|
2011-10-05 19:57:55 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// shared by save() and saveLayer()
|
2014-12-11 15:07:37 +00:00
|
|
|
void internalSave();
|
2008-12-17 15:59:43 +00:00
|
|
|
void internalRestore();
|
2011-01-11 18:32:13 +00:00
|
|
|
|
2015-07-16 14:40:45 +00:00
|
|
|
/*
|
|
|
|
* Returns true if drawing the specified rect (or all if it is null) with the specified
|
|
|
|
* paint (or default if null) would overwrite the entire root device of the canvas
|
|
|
|
* (i.e. the canvas' surface if it had one).
|
|
|
|
*/
|
|
|
|
bool wouldOverwriteEntireSurface(const SkRect*, const SkPaint*, ShaderOverrideOpacity) const;
|
|
|
|
|
2015-12-05 21:07:27 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the paint's imagefilter can be invoked directly, without needed a layer.
|
|
|
|
*/
|
|
|
|
bool canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const SkPaint&);
|
2015-07-16 14:40:45 +00:00
|
|
|
|
2017-03-07 14:37:29 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the clip (for any active layer) contains antialiasing.
|
|
|
|
* If the clip is empty, this will return false.
|
2017-01-16 01:02:32 +00:00
|
|
|
*/
|
2017-03-07 14:37:29 +00:00
|
|
|
bool androidFramework_isClipAA() const;
|
2016-08-12 15:29:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep track of the device clip bounds and if the matrix is scale-translate. This allows
|
|
|
|
* us to do a fast quick reject in the common case.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2016-08-18 21:03:30 +00:00
|
|
|
bool fIsScaleTranslate;
|
2016-08-12 15:29:08 +00:00
|
|
|
SkRect fDeviceClipBounds;
|
|
|
|
|
2012-11-07 14:54:49 +00:00
|
|
|
bool fAllowSoftClip;
|
2013-04-25 13:34:40 +00:00
|
|
|
bool fAllowSimplifyClip;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-02-22 19:12:23 +00:00
|
|
|
class AutoValidateClip : ::SkNoncopyable {
|
|
|
|
public:
|
|
|
|
explicit AutoValidateClip(SkCanvas* canvas) : fCanvas(canvas) {
|
|
|
|
fCanvas->validateClip();
|
|
|
|
}
|
|
|
|
~AutoValidateClip() { fCanvas->validateClip(); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const SkCanvas* fCanvas;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
|
|
|
void validateClip() const;
|
|
|
|
#else
|
|
|
|
void validateClip() const {}
|
|
|
|
#endif
|
2012-06-21 20:25:03 +00:00
|
|
|
|
|
|
|
typedef SkRefCnt INHERITED;
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Stack helper class to automatically call restoreToCount() on the canvas
|
|
|
|
when this object goes out of scope. Use this to guarantee that the canvas
|
|
|
|
is restored to a known state.
|
|
|
|
*/
|
|
|
|
class SkAutoCanvasRestore : SkNoncopyable {
|
|
|
|
public:
|
2013-10-14 15:28:01 +00:00
|
|
|
SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) : fCanvas(canvas), fSaveCount(0) {
|
|
|
|
if (fCanvas) {
|
|
|
|
fSaveCount = canvas->getSaveCount();
|
|
|
|
if (doSave) {
|
|
|
|
canvas->save();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
~SkAutoCanvasRestore() {
|
2012-11-20 15:12:21 +00:00
|
|
|
if (fCanvas) {
|
|
|
|
fCanvas->restoreToCount(fSaveCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform the restore now, instead of waiting for the destructor. Will
|
|
|
|
* only do this once.
|
|
|
|
*/
|
|
|
|
void restore() {
|
|
|
|
if (fCanvas) {
|
|
|
|
fCanvas->restoreToCount(fSaveCount);
|
|
|
|
fCanvas = NULL;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkCanvas* fCanvas;
|
|
|
|
int fSaveCount;
|
|
|
|
};
|
2013-11-18 16:03:59 +00:00
|
|
|
#define SkAutoCanvasRestore(...) SK_REQUIRE_LOCAL_VAR(SkAutoCanvasRestore)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#endif
|