diff options
author | 2009-06-01 21:18:36 +0000 | |
---|---|---|
committer | 2009-06-01 21:18:36 +0000 | |
commit | daa200eba260377f81b84ad060f23322f9ad98a8 (patch) | |
tree | f9f76074445742bce0c208ff6d853c4b7d6c596f /src/gl/SkGLDevice.cpp | |
parent | 24cfaa77515f134732e17f44a730efef3740c70d (diff) |
add unimpl macro to help track bugs
git-svn-id: http://skia.googlecode.com/svn/trunk@195 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gl/SkGLDevice.cpp')
-rw-r--r-- | src/gl/SkGLDevice.cpp | 69 |
1 files changed, 57 insertions, 12 deletions
diff --git a/src/gl/SkGLDevice.cpp b/src/gl/SkGLDevice.cpp index 70968e2428..41feb37995 100644 --- a/src/gl/SkGLDevice.cpp +++ b/src/gl/SkGLDevice.cpp @@ -281,15 +281,39 @@ void SkGLDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, this->updateMatrixClip()); } +/* create a triangle strip that strokes the specified triangle. There are 8 + unique vertices, but we repreat the last 2 to close up. Alternatively we + could use an indices array, and then only send 8 verts, but not sure that + would be faster. + */ +static void setStrokeRectStrip(SkGLVertex verts[10], const SkRect& rect, + SkScalar width) { + const SkScalar rad = SkScalarHalf(width); + + verts[0].setScalars(rect.fLeft + rad, rect.fTop + rad); + verts[1].setScalars(rect.fLeft - rad, rect.fTop - rad); + verts[2].setScalars(rect.fRight - rad, rect.fTop + rad); + verts[3].setScalars(rect.fRight + rad, rect.fTop - rad); + verts[4].setScalars(rect.fRight - rad, rect.fBottom - rad); + verts[5].setScalars(rect.fRight + rad, rect.fBottom + rad); + verts[6].setScalars(rect.fLeft + rad, rect.fBottom - rad); + verts[7].setScalars(rect.fLeft - rad, rect.fBottom + rad); + verts[8] = verts[0]; + verts[9] = verts[1]; +} + void SkGLDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) { TRACE_DRAW("coreDrawRect", this, draw); - - if (paint.getStyle() == SkPaint::kStroke_Style) { - return; - } - - if (paint.getStrokeJoin() != SkPaint::kMiter_Join) { + + bool doStroke = paint.getStyle() == SkPaint::kStroke_Style; + + if (doStroke) { + if (paint.getStrokeJoin() != SkPaint::kMiter_Join) { + SkGL_unimpl("non-miter stroke rect"); + return; + } + } else if (paint.getStrokeJoin() != SkPaint::kMiter_Join) { SkPath path; path.addRect(rect); this->drawPath(draw, path, paint); @@ -297,12 +321,33 @@ void SkGLDevice::drawRect(const SkDraw& draw, const SkRect& rect, } AutoPaintShader shader(this, paint); - - SkGLVertex vertex[4]; - vertex->setRectFan(rect); - const SkGLVertex* texs = shader.useTex() ? vertex : NULL; - - SkGL::DrawVertices(4, GL_TRIANGLE_FAN, vertex, texs, NULL, NULL, + SkScalar width = paint.getStrokeWidth(); + SkGLVertex vertex[10]; // max needed for all cases + int vertCount; + GLenum vertMode; + + if (doStroke) { + if (width > 0) { + vertCount = 10; + vertMode = GL_TRIANGLE_STRIP; + setStrokeRectStrip(vertex, rect, width); + } else { // hairline + vertCount = 5; + vertMode = GL_LINE_STRIP; + vertex[0].setScalars(rect.fLeft, rect.fTop); + vertex[1].setScalars(rect.fRight, rect.fTop); + vertex[2].setScalars(rect.fRight, rect.fBottom); + vertex[3].setScalars(rect.fLeft, rect.fBottom); + vertex[4].setScalars(rect.fLeft, rect.fTop); + } + } else { + vertCount = 4; + vertMode = GL_TRIANGLE_FAN; + vertex->setRectFan(rect); + } + + const SkGLVertex* texs = shader.useTex() ? vertex : NULL; + SkGL::DrawVertices(vertCount, vertMode, vertex, texs, NULL, NULL, this->updateMatrixClip()); } |