2011-07-28 14:26:00 +00:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkDraw_DEFINED
|
|
|
|
#define SkDraw_DEFINED
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkMask.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
|
2013-04-03 10:18:17 +00:00
|
|
|
class SkBitmap;
|
2011-02-23 22:39:18 +00:00
|
|
|
class SkClipStack;
|
2013-08-29 11:54:56 +00:00
|
|
|
class SkBaseDevice;
|
2014-08-06 18:12:14 +00:00
|
|
|
class SkBlitter;
|
2013-04-03 10:18:17 +00:00
|
|
|
class SkMatrix;
|
2008-12-17 15:59:43 +00:00
|
|
|
class SkPath;
|
|
|
|
class SkRegion;
|
2011-10-24 12:19:46 +00:00
|
|
|
class SkRasterClip;
|
2008-12-17 15:59:43 +00:00
|
|
|
struct SkDrawProcs;
|
2013-04-03 10:18:17 +00:00
|
|
|
struct SkRect;
|
2013-11-08 18:02:53 +00:00
|
|
|
class SkRRect;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkDraw {
|
|
|
|
public:
|
2010-12-20 18:26:13 +00:00
|
|
|
SkDraw();
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDraw(const SkDraw& src);
|
|
|
|
|
|
|
|
void drawPaint(const SkPaint&) const;
|
|
|
|
void drawPoints(SkCanvas::PointMode, size_t count, const SkPoint[],
|
2010-12-20 18:26:13 +00:00
|
|
|
const SkPaint&, bool forceUseDevice = false) const;
|
2014-12-15 21:42:51 +00:00
|
|
|
void drawRect(const SkRect& prePaintRect, const SkPaint&, const SkMatrix* paintMatrix,
|
|
|
|
const SkRect* postPaintRect) const;
|
|
|
|
void drawRect(const SkRect& rect, const SkPaint& paint) const {
|
|
|
|
this->drawRect(rect, paint, NULL, NULL);
|
|
|
|
}
|
2013-11-08 18:02:53 +00:00
|
|
|
void drawRRect(const SkRRect&, const SkPaint&) const;
|
2011-03-25 15:08:16 +00:00
|
|
|
/**
|
|
|
|
* To save on mallocs, we allow a flag that tells us that srcPath is
|
|
|
|
* mutable, so that we don't have to make copies of it as we transform it.
|
|
|
|
*
|
|
|
|
* If prePathMatrix is not null, it should logically be applied before any
|
|
|
|
* stroking or other effects. If there are no effects on the paint that
|
|
|
|
* affect the geometry/rasterization, then the pre matrix can just be
|
|
|
|
* pre-concated with the current matrix.
|
|
|
|
*/
|
2013-11-07 16:06:53 +00:00
|
|
|
void drawPath(const SkPath& path, const SkPaint& paint,
|
|
|
|
const SkMatrix* prePathMatrix, bool pathIsMutable) const {
|
|
|
|
this->drawPath(path, paint, prePathMatrix, pathIsMutable, false);
|
|
|
|
}
|
|
|
|
|
2014-08-06 18:12:14 +00:00
|
|
|
void drawPath(const SkPath& path, const SkPaint& paint,
|
|
|
|
SkBlitter* customBlitter = NULL) const {
|
|
|
|
this->drawPath(path, paint, NULL, false, false, customBlitter);
|
2013-11-07 16:06:53 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 21:42:51 +00:00
|
|
|
/* If dstOrNull is null, computes a dst by mapping the bitmap's bounds through the matrix. */
|
|
|
|
void drawBitmap(const SkBitmap&, const SkMatrix&, const SkRect* dstOrNull,
|
|
|
|
const SkPaint&) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
void drawSprite(const SkBitmap&, int x, int y, const SkPaint&) const;
|
|
|
|
void drawText(const char text[], size_t byteLength, SkScalar x,
|
|
|
|
SkScalar y, const SkPaint& paint) const;
|
|
|
|
void drawPosText(const char text[], size_t byteLength,
|
Revert of Revert of Fix SkTextBlob offset semantics. (patchset #1 id:1 of https://codereview.chromium.org/609223003/)
Reason for revert:
Re-landing: Chromium-side fix to be landed with the roll (https://codereview.chromium.org/607853003/)
Original issue's description:
> Revert of Fix SkTextBlob offset semantics. (patchset #2 id:20001 of https://codereview.chromium.org/605533002/)
>
> Reason for revert:
> Breaking the Chrome builds with the error:
>
> [14:54:14.317833] ../../skia/ext/pixel_ref_utils.cc:221:16: error: 'drawPosText' marked 'override' but does not override any member functions
> [14:54:14.318022] virtual void drawPosText(const SkDraw& draw,
> [14:54:14.318082] ^
>
> Original issue's description:
> > Fix SkTextBlob offset semantics.
> >
> > Implement proper x/y drawTextBlob() handling by plumbing a
> > drawPosText() offset parameter (to act as an additional glyph pos
> > translation) throughout the device layer.
> >
> > The new offset superceeds the existing constY, with a minor semantic
> > tweak: whereas previous implementations were ignoring constY in 2D
> > positioning mode (scalarsPerGlyph == 2), now the offset is always
> > observed, in all positioning modes. We can do this because existing
> > drawPosText() clients always pass constY == 0 for full positioning mode.
> >
> > R=reed@google.com, jvanverth@google.com, robertphillips@google.com
> >
> > Committed: https://skia.googlesource.com/skia/+/c13bc571d3e61a43b87eb97f0719abd304cafaf2
>
> TBR=jvanverth@google.com,reed@google.com,bsalomon@google.com,fmalita@chromium.org
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/d46b8d2bab7cfba8458432248e1568ac377429e9
R=jvanverth@google.com, reed@google.com, bsalomon@google.com, robertphillips@google.com
TBR=bsalomon@google.com, jvanverth@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: fmalita@chromium.org
Review URL: https://codereview.chromium.org/607413003
2014-09-29 13:29:53 +00:00
|
|
|
const SkScalar pos[], int scalarsPerPosition,
|
|
|
|
const SkPoint& offset, const SkPaint& paint) const;
|
2008-12-17 15:59:43 +00:00
|
|
|
void drawVertices(SkCanvas::VertexMode mode, int count,
|
|
|
|
const SkPoint vertices[], const SkPoint textures[],
|
|
|
|
const SkColor colors[], SkXfermode* xmode,
|
|
|
|
const uint16_t indices[], int ptCount,
|
|
|
|
const SkPaint& paint) const;
|
2011-02-23 22:39:18 +00:00
|
|
|
|
2013-11-07 16:06:53 +00:00
|
|
|
/**
|
|
|
|
* Overwrite the target with the path's coverage (i.e. its mask).
|
|
|
|
* Will overwrite the entire device, so it need not be zero'd first.
|
|
|
|
*
|
|
|
|
* Only device A8 is supported right now.
|
|
|
|
*/
|
2014-08-06 18:12:14 +00:00
|
|
|
void drawPathCoverage(const SkPath& src, const SkPaint& paint,
|
|
|
|
SkBlitter* customBlitter = NULL) const {
|
|
|
|
this->drawPath(src, paint, NULL, false, true, customBlitter);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Helper function that creates a mask from a path and an optional maskfilter.
|
|
|
|
Note however, that the resulting mask will not have been actually filtered,
|
|
|
|
that must be done afterwards (by calling filterMask). The maskfilter is provided
|
|
|
|
solely to assist in computing the mask's bounds (if the mode requests that).
|
|
|
|
*/
|
|
|
|
static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
|
2012-12-18 19:18:39 +00:00
|
|
|
const SkMaskFilter*, const SkMatrix* filterMatrix,
|
2012-04-04 15:16:51 +00:00
|
|
|
SkMask* mask, SkMask::CreateMode mode,
|
|
|
|
SkPaint::Style style);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-05 14:08:25 +00:00
|
|
|
enum RectType {
|
|
|
|
kHair_RectType,
|
|
|
|
kFill_RectType,
|
|
|
|
kStroke_RectType,
|
|
|
|
kPath_RectType
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Based on the paint's style, strokeWidth, and the matrix, classify how
|
|
|
|
* to draw the rect. If no special-case is available, returns
|
|
|
|
* kPath_RectType.
|
|
|
|
*
|
|
|
|
* Iff RectType == kStroke_RectType, then strokeSize is set to the device
|
|
|
|
* width and height of the stroke.
|
|
|
|
*/
|
|
|
|
static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
|
|
|
|
SkPoint* strokeSize);
|
|
|
|
|
2013-12-19 16:12:25 +00:00
|
|
|
static bool ShouldDrawTextAsPaths(const SkPaint&, const SkMatrix&);
|
|
|
|
void drawText_asPaths(const char text[], size_t byteLength,
|
|
|
|
SkScalar x, SkScalar y, const SkPaint&) const;
|
|
|
|
void drawPosText_asPaths(const char text[], size_t byteLength,
|
Revert of Revert of Fix SkTextBlob offset semantics. (patchset #1 id:1 of https://codereview.chromium.org/609223003/)
Reason for revert:
Re-landing: Chromium-side fix to be landed with the roll (https://codereview.chromium.org/607853003/)
Original issue's description:
> Revert of Fix SkTextBlob offset semantics. (patchset #2 id:20001 of https://codereview.chromium.org/605533002/)
>
> Reason for revert:
> Breaking the Chrome builds with the error:
>
> [14:54:14.317833] ../../skia/ext/pixel_ref_utils.cc:221:16: error: 'drawPosText' marked 'override' but does not override any member functions
> [14:54:14.318022] virtual void drawPosText(const SkDraw& draw,
> [14:54:14.318082] ^
>
> Original issue's description:
> > Fix SkTextBlob offset semantics.
> >
> > Implement proper x/y drawTextBlob() handling by plumbing a
> > drawPosText() offset parameter (to act as an additional glyph pos
> > translation) throughout the device layer.
> >
> > The new offset superceeds the existing constY, with a minor semantic
> > tweak: whereas previous implementations were ignoring constY in 2D
> > positioning mode (scalarsPerGlyph == 2), now the offset is always
> > observed, in all positioning modes. We can do this because existing
> > drawPosText() clients always pass constY == 0 for full positioning mode.
> >
> > R=reed@google.com, jvanverth@google.com, robertphillips@google.com
> >
> > Committed: https://skia.googlesource.com/skia/+/c13bc571d3e61a43b87eb97f0719abd304cafaf2
>
> TBR=jvanverth@google.com,reed@google.com,bsalomon@google.com,fmalita@chromium.org
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://skia.googlesource.com/skia/+/d46b8d2bab7cfba8458432248e1568ac377429e9
R=jvanverth@google.com, reed@google.com, bsalomon@google.com, robertphillips@google.com
TBR=bsalomon@google.com, jvanverth@google.com, reed@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: fmalita@chromium.org
Review URL: https://codereview.chromium.org/607413003
2014-09-29 13:29:53 +00:00
|
|
|
const SkScalar pos[], int scalarsPerPosition,
|
|
|
|
const SkPoint& offset, const SkPaint&) const;
|
2016-01-21 15:07:02 +00:00
|
|
|
static SkScalar ComputeResScaleForStroking(const SkMatrix& );
|
2013-10-14 13:42:12 +00:00
|
|
|
private:
|
|
|
|
void drawDevMask(const SkMask& mask, const SkPaint&) const;
|
|
|
|
void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;
|
2013-11-07 16:06:53 +00:00
|
|
|
|
|
|
|
void drawPath(const SkPath&, const SkPaint&, const SkMatrix* preMatrix,
|
2014-08-06 18:12:14 +00:00
|
|
|
bool pathIsMutable, bool drawCoverage,
|
|
|
|
SkBlitter* customBlitter = NULL) const;
|
2013-06-05 07:01:06 +00:00
|
|
|
|
2013-01-24 21:03:11 +00:00
|
|
|
/**
|
|
|
|
* Return the current clip bounds, in local coordinates, with slop to account
|
|
|
|
* for antialiasing or hairlines (i.e. device-bounds outset by 1, and then
|
|
|
|
* run through the inverse of the matrix).
|
|
|
|
*
|
|
|
|
* If the matrix cannot be inverted, or the current clip is empty, return
|
|
|
|
* false and ignore bounds parameter.
|
|
|
|
*/
|
|
|
|
bool SK_WARN_UNUSED_RESULT
|
|
|
|
computeConservativeLocalClipBounds(SkRect* bounds) const;
|
2013-01-25 07:06:46 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2015-06-09 19:16:53 +00:00
|
|
|
SkPixmap fDst;
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkMatrix* fMatrix; // required
|
2011-10-24 12:19:46 +00:00
|
|
|
const SkRegion* fClip; // DEPRECATED
|
|
|
|
const SkRasterClip* fRC; // required
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2011-02-23 22:39:18 +00:00
|
|
|
const SkClipStack* fClipStack; // optional
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBaseDevice* fDevice; // optional
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#ifdef SK_DEBUG
|
2010-12-20 18:26:13 +00:00
|
|
|
void validate() const;
|
|
|
|
#else
|
|
|
|
void validate() const {}
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|