Take SkStrokeRec::InitStyle rather than SkPaint::Style in mask filter and DrawMask

GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1955633002

Review-Url: https://codereview.chromium.org/1955633002
This commit is contained in:
bsalomon 2016-05-06 07:22:58 -07:00 committed by Commit bot
parent ad3a5c634d
commit 055e192adc
9 changed files with 50 additions and 37 deletions

View File

@ -13,6 +13,7 @@
#include "SkCanvas.h"
#include "SkMask.h"
#include "SkPaint.h"
#include "SkStrokeRec.h"
class SkBitmap;
class SkClipStack;
@ -93,7 +94,7 @@ public:
static bool DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
const SkMaskFilter*, const SkMatrix* filterMatrix,
SkMask* mask, SkMask::CreateMode mode,
SkPaint::Style style);
SkStrokeRec::InitStyle style);
enum RectType {
kHair_RectType,

View File

@ -14,6 +14,7 @@
#include "SkFlattenable.h"
#include "SkMask.h"
#include "SkPaint.h"
#include "SkStrokeRec.h"
class GrClip;
class GrDrawContext;
@ -27,7 +28,6 @@ class SkMatrix;
class SkPath;
class SkRasterClip;
class SkRRect;
class SkStrokeRec;
/** \class SkMaskFilter
@ -228,14 +228,14 @@ private:
This method is not exported to java.
*/
bool filterPath(const SkPath& devPath, const SkMatrix& ctm, const SkRasterClip&, SkBlitter*,
SkPaint::Style) const;
SkStrokeRec::InitStyle) const;
/** Helper method that, given a roundRect in device space, will rasterize it into a kA8_Format
mask and then call filterMask(). If this returns true, the specified blitter will be called
to render that mask. Returns false if filterMask() returned false.
*/
bool filterRRect(const SkRRect& devRRect, const SkMatrix& ctm, const SkRasterClip&,
SkBlitter*, SkPaint::Style style) const;
SkBlitter*) const;
typedef SkFlattenable INHERITED;
};

View File

@ -992,8 +992,7 @@ void SkDraw::drawRRect(const SkRRect& rrect, const SkPaint& paint) const {
SkRRect devRRect;
if (rrect.transform(*fMatrix, &devRRect)) {
SkAutoBlitterChoose blitter(fDst, *fMatrix, paint);
if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get(),
SkPaint::kFill_Style)) {
if (paint.getMaskFilter()->filterRRect(devRRect, *fMatrix, *fRC, blitter.get())) {
return; // filterRRect() called the blitter, so we're done
}
}
@ -1117,8 +1116,8 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
}
if (paint->getMaskFilter()) {
SkPaint::Style style = doFill ? SkPaint::kFill_Style :
SkPaint::kStroke_Style;
SkStrokeRec::InitStyle style = doFill ? SkStrokeRec::kFill_InitStyle
: SkStrokeRec::kHairline_InitStyle;
if (paint->getMaskFilter()->filterPath(*devPathPtr, *fMatrix, *fRC, blitter, style)) {
return; // filterPath() called the blitter, so we're done
}
@ -2025,7 +2024,8 @@ static bool compute_bounds(const SkPath& devPath, const SkIRect* clipBounds,
return true;
}
static void draw_into_mask(const SkMask& mask, const SkPath& devPath, SkPaint::Style style) {
static void draw_into_mask(const SkMask& mask, const SkPath& devPath,
SkStrokeRec::InitStyle style) {
SkDraw draw;
if (!draw.fDst.reset(mask)) {
return;
@ -2042,14 +2042,23 @@ static void draw_into_mask(const SkMask& mask, const SkPath& devPath, SkPaint::S
draw.fRC = &clip;
draw.fMatrix = &matrix;
paint.setAntiAlias(true);
paint.setStyle(style);
switch (style) {
case SkStrokeRec::kHairline_InitStyle:
SkASSERT(!paint.getStrokeWidth());
paint.setStyle(SkPaint::kStroke_Style);
break;
case SkStrokeRec::kFill_InitStyle:
SkASSERT(paint.getStyle() == SkPaint::kFill_Style);
break;
}
draw.drawPath(devPath, paint);
}
bool SkDraw::DrawToMask(const SkPath& devPath, const SkIRect* clipBounds,
const SkMaskFilter* filter, const SkMatrix* filterMatrix,
SkMask* mask, SkMask::CreateMode mode,
SkPaint::Style style) {
SkStrokeRec::InitStyle style) {
if (SkMask::kJustRenderImage_CreateMode != mode) {
if (!compute_bounds(devPath, clipBounds, filter, filterMatrix, &mask->fBounds))
return false;

View File

@ -214,8 +214,7 @@ static int countNestedRects(const SkPath& path, SkRect rects[2]) {
}
bool SkMaskFilter::filterRRect(const SkRRect& devRRect, const SkMatrix& matrix,
const SkRasterClip& clip, SkBlitter* blitter,
SkPaint::Style style) const {
const SkRasterClip& clip, SkBlitter* blitter) const {
// Attempt to speed up drawing by creating a nine patch. If a nine patch
// cannot be used, return false to allow our caller to recover and perform
// the drawing another way.
@ -233,10 +232,10 @@ bool SkMaskFilter::filterRRect(const SkRRect& devRRect, const SkMatrix& matrix,
bool SkMaskFilter::filterPath(const SkPath& devPath, const SkMatrix& matrix,
const SkRasterClip& clip, SkBlitter* blitter,
SkPaint::Style style) const {
SkStrokeRec::InitStyle style) const {
SkRect rects[2];
int rectCount = 0;
if (SkPaint::kFill_Style == style) {
if (SkStrokeRec::kFill_InitStyle == style) {
rectCount = countNestedRects(devPath, rects);
}
if (rectCount > 0) {

View File

@ -10,6 +10,7 @@
#include "SkDraw.h"
#include "SkMaskFilter.h"
#include "SkPath.h"
#include "SkStrokeRec.h"
bool SkRasterizer::rasterize(const SkPath& fillPath, const SkMatrix& matrix,
const SkIRect* clipBounds, SkMaskFilter* filter,
@ -41,5 +42,5 @@ bool SkRasterizer::onRasterize(const SkPath& fillPath, const SkMatrix& matrix,
fillPath.transform(matrix, &devPath);
return SkDraw::DrawToMask(devPath, clipBounds, nullptr, nullptr, mask, mode,
SkPaint::kFill_Style);
SkStrokeRec::kFill_InitStyle);
}

View File

@ -991,7 +991,7 @@ const GrFragmentProcessor* GrRRectBlurEffect::Create(GrTextureProvider* texProvi
path.addRRect(smallRRect);
SkDraw::DrawToMask(path, &mask.fBounds, nullptr, nullptr, &mask,
SkMask::kJustRenderImage_CreateMode, SkPaint::kFill_Style);
SkMask::kJustRenderImage_CreateMode, SkStrokeRec::kFill_InitStyle);
SkMask blurredMask;
if (!SkBlurMask::BoxBlur(&blurredMask, mask, sigma, kNormal_SkBlurStyle,

View File

@ -16,6 +16,7 @@
#include "SkPath.h"
#include "SkPathEffect.h"
#include "../core/SkRasterClip.h"
#include "../core/SkStrokeRec.h"
#include "SkXfermode.h"
#include <new>
@ -78,7 +79,7 @@ static bool compute_bounds(const SkDeque& layers, const SkPath& path,
if (!SkDraw::DrawToMask(devPath, clipBounds, paint.getMaskFilter(),
&matrix, &mask,
SkMask::kJustComputeBounds_CreateMode,
SkPaint::kFill_Style)) {
SkStrokeRec::kFill_InitStyle)) {
return false;
}

View File

@ -54,7 +54,7 @@ static bool sw_draw_with_mask_filter(GrDrawContext* drawContext,
const SkMaskFilter* filter,
const SkIRect& clipBounds,
GrPaint* grp,
SkPaint::Style style) {
SkStrokeRec::InitStyle style) {
SkMask srcM, dstM;
if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM,
@ -96,7 +96,7 @@ static bool sw_draw_with_mask_filter(GrDrawContext* drawContext,
static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
SkRect* maskRect,
const SkPath& devPath,
const GrStrokeInfo& strokeInfo,
SkStrokeRec::InitStyle style,
bool doAA,
int sampleCnt) {
// This mask will ultimately be drawn as a non-AA rect (see draw_mask).
@ -139,7 +139,7 @@ static sk_sp<GrTexture> create_mask_GPU(GrContext* context,
// the origin using tempPaint.
SkMatrix translate;
translate.setTranslate(-maskRect->fLeft, -maskRect->fTop);
drawContext->drawPath(clip, tempPaint, translate, devPath, strokeInfo);
drawContext->drawPath(clip, tempPaint, translate, devPath, GrStrokeInfo(style));
return drawContext->asTexture();;
}
@ -150,7 +150,7 @@ static void draw_path_with_mask_filter(GrContext* context,
const SkMatrix& viewMatrix,
const SkMaskFilter* maskFilter,
const SkPathEffect* pathEffect,
const GrStrokeInfo& origStrokeInfo,
const GrStrokeInfo& strokeInfo,
SkPath* pathPtr,
bool pathIsMutable) {
SkASSERT(maskFilter);
@ -158,29 +158,30 @@ static void draw_path_with_mask_filter(GrContext* context,
SkIRect clipBounds;
clip.getConservativeBounds(drawContext->width(), drawContext->height(), &clipBounds);
SkTLazy<SkPath> tmpPath;
GrStrokeInfo strokeInfo(origStrokeInfo);
static const SkRect* cullRect = nullptr; // TODO: what is our bounds?
SkASSERT(strokeInfo.isDashed() || !pathEffect);
if (!strokeInfo.isHairlineStyle()) {
SkStrokeRec::InitStyle maskStyle;
if (strokeInfo.isHairlineStyle()) {
maskStyle = SkStrokeRec::kHairline_InitStyle;
} else {
SkPath* strokedPath = pathIsMutable ? pathPtr : tmpPath.init();
SkStrokeRec rec = strokeInfo;
if (strokeInfo.isDashed()) {
if (pathEffect->filterPath(strokedPath, *pathPtr, &strokeInfo, cullRect)) {
if (pathEffect->filterPath(strokedPath, *pathPtr, &rec, cullRect)) {
pathPtr = strokedPath;
pathPtr->setIsVolatile(true);
pathIsMutable = true;
}
strokeInfo.removeDash();
}
if (strokeInfo.applyToPath(strokedPath, *pathPtr)) {
if (rec.applyToPath(strokedPath, *pathPtr)) {
// Apply the stroke to the path if there is one
pathPtr = strokedPath;
pathPtr->setIsVolatile(true);
pathIsMutable = true;
strokeInfo.setFillStyle();
}
maskStyle = SkStrokeRec::kFill_InitStyle;
}
// avoid possibly allocating a new path in transform if we can
@ -209,7 +210,7 @@ static void draw_path_with_mask_filter(GrContext* context,
paint,
clip,
viewMatrix,
strokeInfo,
SkStrokeRec(maskStyle),
*devPathPtr)) {
// the mask filter was able to draw itself directly, so there's nothing
// left to do.
@ -219,7 +220,7 @@ static void draw_path_with_mask_filter(GrContext* context,
sk_sp<GrTexture> mask(create_mask_GPU(context,
&maskRect,
*devPathPtr,
strokeInfo,
maskStyle,
paint->isAntiAlias(),
drawContext->numColorSamples()));
if (mask) {
@ -236,13 +237,9 @@ static void draw_path_with_mask_filter(GrContext* context,
}
}
// draw the mask on the CPU - this is a fallthrough path in case the
// GPU path fails
SkPaint::Style style = strokeInfo.isHairlineStyle() ? SkPaint::kStroke_Style :
SkPaint::kFill_Style;
sw_draw_with_mask_filter(drawContext, context->textureProvider(),
clip, viewMatrix, *devPathPtr,
maskFilter, clipBounds, paint, style);
maskFilter, clipBounds, paint, maskStyle);
}
void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,

View File

@ -1657,6 +1657,11 @@ void SkXPSDevice::drawPath(const SkDraw& d,
SkMask* mask = nullptr;
SkASSERT(SkPaint::kFill_Style == paint->getStyle() ||
(SkPaint::kStroke_Style == paint->getStyle() && 0 == paint->getStrokeWidth()));
SkStrokeRec::InitStyle style = (SkPaint::kFill_Style == paint->getStyle())
? SkStrokeRec::kFill_InitStyle
: SkStrokeRec::kHairline_InitStyle;
//[Pixel-path -> Mask]
SkMask rasteredMask;
if (SkDraw::DrawToMask(
@ -1666,7 +1671,7 @@ void SkXPSDevice::drawPath(const SkDraw& d,
&matrix,
&rasteredMask,
SkMask::kComputeBoundsAndRenderImage_CreateMode,
paint->getStyle())) {
style)) {
SkAutoMaskFreeImage rasteredAmi(rasteredMask.fImage);
mask = &rasteredMask;