diff options
author | Mike Reed <reed@google.com> | 2009-06-02 15:02:19 -0400 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2009-06-02 15:48:46 -0400 |
commit | b630785db28d3dbd2ef9fa2b15eb7aea0def82e8 (patch) | |
tree | 5e60a1561ea3c6798176aed7f093425b52445967 /src/gl | |
parent | dab163f0b2658c2dba48839e72f81d3d8ee0ae8b (diff) | |
download | external_skia-b630785db28d3dbd2ef9fa2b15eb7aea0def82e8.zip external_skia-b630785db28d3dbd2ef9fa2b15eb7aea0def82e8.tar.gz external_skia-b630785db28d3dbd2ef9fa2b15eb7aea0def82e8.tar.bz2 |
refresh from skia, esp. with opengl updates
initialize fFlags in shader constructors
Diffstat (limited to 'src/gl')
-rw-r--r-- | src/gl/SkGL.h | 4 | ||||
-rw-r--r-- | src/gl/SkGLDevice.cpp | 67 |
2 files changed, 60 insertions, 11 deletions
diff --git a/src/gl/SkGL.h b/src/gl/SkGL.h index 86b8f22..dd2c77f 100644 --- a/src/gl/SkGL.h +++ b/src/gl/SkGL.h @@ -10,6 +10,7 @@ #elif defined(ANDROID) #include <GLES/gl.h> #include <EGL/egl.h> + #include <GLES/glext.h> #endif #include "SkColor.h" @@ -23,6 +24,9 @@ class SkGLClipIter; //#define TRACE_TEXTURE_CREATE +static void SkGL_unimpl(const char str[]) { + SkDebugf("SkGL unimplemented: %s\n", str); +} /////////////////////////////////////////////////////////////////////////////// #if GL_OES_compressed_paletted_texture diff --git a/src/gl/SkGLDevice.cpp b/src/gl/SkGLDevice.cpp index 70968e2..148f9e9 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); + 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(4, GL_TRIANGLE_FAN, vertex, texs, NULL, NULL, + SkGL::DrawVertices(vertCount, vertMode, vertex, texs, NULL, NULL, this->updateMatrixClip()); } |