export SkDraw::ComputeRectType() and share that with SkGpuDevice
git-svn-id: http://skia.googlecode.com/svn/trunk@1055 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
569e0435af
commit
62ab7addb0
@ -85,6 +85,24 @@ public:
|
||||
SkMaskFilter* filter, const SkMatrix* filterMatrix,
|
||||
SkMask* mask, SkMask::CreateMode mode);
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
void drawText_asPaths(const char text[], size_t byteLength,
|
||||
SkScalar x, SkScalar y, const SkPaint&) const;
|
||||
|
@ -685,7 +685,7 @@ static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
|
||||
paint.getStrokeMiter() < SK_ScalarSqrt2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
SkASSERT(matrix.rectStaysRect());
|
||||
SkPoint pt = { paint.getStrokeWidth(), paint.getStrokeWidth() };
|
||||
matrix.mapVectors(strokeSize, &pt, 1);
|
||||
@ -694,12 +694,33 @@ static bool easy_rect_join(const SkPaint& paint, const SkMatrix& matrix,
|
||||
return true;
|
||||
}
|
||||
|
||||
enum RectType {
|
||||
kHair_RectType,
|
||||
kFill_RectType,
|
||||
kStroke_RectType,
|
||||
kPath_RectType
|
||||
};
|
||||
SkDraw::RectType SkDraw::ComputeRectType(const SkPaint& paint,
|
||||
const SkMatrix& matrix,
|
||||
SkPoint* strokeSize) {
|
||||
RectType rtype;
|
||||
const SkScalar width = paint.getStrokeWidth();
|
||||
const bool zeroWidth = (0 == width);
|
||||
SkPaint::Style style = paint.getStyle();
|
||||
|
||||
if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) {
|
||||
style = SkPaint::kFill_Style;
|
||||
}
|
||||
|
||||
if (paint.getPathEffect() || paint.getMaskFilter() ||
|
||||
paint.getRasterizer() || !matrix.rectStaysRect() ||
|
||||
SkPaint::kStrokeAndFill_Style == style) {
|
||||
rtype = kPath_RectType;
|
||||
} else if (SkPaint::kFill_Style == style) {
|
||||
rtype = kFill_RectType;
|
||||
} else if (zeroWidth) {
|
||||
rtype = kHair_RectType;
|
||||
} else if (easy_rect_join(paint, matrix, strokeSize)) {
|
||||
rtype = kStroke_RectType;
|
||||
} else {
|
||||
rtype = kPath_RectType;
|
||||
}
|
||||
return rtype;
|
||||
}
|
||||
|
||||
void SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const {
|
||||
SkDEBUGCODE(this->validate();)
|
||||
@ -710,35 +731,15 @@ void SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const {
|
||||
return;
|
||||
}
|
||||
|
||||
RectType rtype;
|
||||
const SkScalar width = paint.getStrokeWidth();
|
||||
bool zeroWidth = (0 == width);
|
||||
SkPaint::Style style = paint.getStyle();
|
||||
SkPoint strokeSize;
|
||||
RectType rtype = ComputeRectType(paint, *fMatrix, &strokeSize);
|
||||
|
||||
if ((SkPaint::kStrokeAndFill_Style == style) && zeroWidth) {
|
||||
style = SkPaint::kFill_Style;
|
||||
}
|
||||
|
||||
if (paint.getPathEffect() || paint.getMaskFilter() ||
|
||||
paint.getRasterizer() || !fMatrix->rectStaysRect() ||
|
||||
SkPaint::kStrokeAndFill_Style == style) {
|
||||
rtype = kPath_RectType;
|
||||
} else if (SkPaint::kFill_Style == paint.getStyle()) {
|
||||
rtype = kFill_RectType;
|
||||
} else if (zeroWidth) {
|
||||
rtype = kHair_RectType;
|
||||
} else if (easy_rect_join(paint, *fMatrix, &strokeSize)) {
|
||||
#ifdef SK_DISABLE_FAST_AA_STROKE_RECT
|
||||
if (paint.isAntiAlias()) {
|
||||
rtype = kPath_RectType;
|
||||
} else
|
||||
#endif
|
||||
rtype = kStroke_RectType;
|
||||
} else {
|
||||
if (kStroke_RectType == rtype && paint.isAntiAlias()) {
|
||||
rtype = kPath_RectType;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (kPath_RectType == rtype) {
|
||||
SkPath tmp;
|
||||
tmp.addRect(rect);
|
||||
|
@ -647,33 +647,27 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
|
||||
const SkPaint& paint) {
|
||||
CHECK_SHOULD_DRAW(draw);
|
||||
|
||||
bool doStroke = paint.getStyle() == SkPaint::kStroke_Style;
|
||||
SkScalar width = paint.getStrokeWidth();
|
||||
const SkMatrix& matrix = *draw.fMatrix;
|
||||
SkPoint strokeSize;
|
||||
SkDraw::RectType type = SkDraw::ComputeRectType(paint, matrix, &strokeSize);
|
||||
|
||||
/*
|
||||
We have special code for hairline strokes, miter-strokes, and fills.
|
||||
Anything else we just call our path code.
|
||||
*/
|
||||
bool usePath = doStroke && width > 0 &&
|
||||
paint.getStrokeJoin() != SkPaint::kMiter_Join;
|
||||
// another reason we might need to call drawPath...
|
||||
if (paint.getMaskFilter()) {
|
||||
usePath = true;
|
||||
}
|
||||
|
||||
if (usePath) {
|
||||
if (SkDraw::kPath_RectType == type) {
|
||||
SkPath path;
|
||||
path.addRect(rect);
|
||||
this->drawPath(draw, path, paint, NULL, true);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
GrPaint grPaint;
|
||||
SkAutoCachedTexture act;
|
||||
if (!this->skPaint2GrPaintShader(paint, &act, matrix, &grPaint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GrPaint grPaint;
|
||||
SkAutoCachedTexture act;
|
||||
if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
|
||||
return;
|
||||
SkScalar width = paint.getStrokeWidth();
|
||||
if (SkDraw::kFill_RectType == type) {
|
||||
width = -1;
|
||||
}
|
||||
fContext->drawRect(grPaint, Sk2Gr(rect), width);
|
||||
}
|
||||
fContext->drawRect(grPaint, Sk2Gr(rect), doStroke ? width : -1);
|
||||
}
|
||||
|
||||
#include "SkMaskFilter.h"
|
||||
|
Loading…
Reference in New Issue
Block a user