add unimpl macro to help track bugs



git-svn-id: http://skia.googlecode.com/svn/trunk@195 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gl/SkGL.h b/src/gl/SkGL.h
index 8c8c6899..dd2c77f 100644
--- a/src/gl/SkGL.h
+++ b/src/gl/SkGL.h
@@ -24,6 +24,9 @@
 
 //#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..41feb37 100644
--- a/src/gl/SkGLDevice.cpp
+++ b/src/gl/SkGLDevice.cpp
@@ -281,15 +281,39 @@
                        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 @@
     }
     
     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());
 }
 
diff --git a/xcode/sampleapp_sdl/SDLApp.xcodeproj/project.pbxproj b/xcode/sampleapp_sdl/SDLApp.xcodeproj/project.pbxproj
index 34d2770..1d07278 100644
--- a/xcode/sampleapp_sdl/SDLApp.xcodeproj/project.pbxproj
+++ b/xcode/sampleapp_sdl/SDLApp.xcodeproj/project.pbxproj
@@ -75,6 +75,7 @@
 		006DC7EC0FC7475F00BF5F45 /* libcore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 006DC7E90FC7475900BF5F45 /* libcore.a */; };
 		00A728490FD43E7600D5051F /* SampleMovie.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0064EE0C0FC72BEE00D71FB0 /* SampleMovie.cpp */; };
 		00A7284D0FD43E8900D5051F /* SkMovie.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A7284B0FD43E8900D5051F /* SkMovie.cpp */; };
+		00A7288C0FD4702A00D5051F /* SampleTestGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 00A7288B0FD4702A00D5051F /* SampleTestGL.cpp */; };
 		2762F6040FCCC832002BD8B4 /* SampleShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0064EE190FC72BEE00D71FB0 /* SampleShapes.cpp */; };
 		2762F6420FCCCA6C002BD8B4 /* SkFlipPixelRef.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2762F6400FCCCA6C002BD8B4 /* SkFlipPixelRef.cpp */; };
 		2762F6430FCCCA6C002BD8B4 /* SkPageFlipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2762F6410FCCCA6C002BD8B4 /* SkPageFlipper.cpp */; };
@@ -213,6 +214,7 @@
 		0096585B0FC7201800C3AE15 /* maccore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = maccore.xcodeproj; path = ../maccore/maccore.xcodeproj; sourceTree = SOURCE_ROOT; };
 		00A7284B0FD43E8900D5051F /* SkMovie.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkMovie.cpp; path = ../../src/images/SkMovie.cpp; sourceTree = SOURCE_ROOT; };
 		00A7284C0FD43E8900D5051F /* SkMovie_gif.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkMovie_gif.cpp; path = ../../src/images/SkMovie_gif.cpp; sourceTree = SOURCE_ROOT; };
+		00A7288B0FD4702A00D5051F /* SampleTestGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SampleTestGL.cpp; sourceTree = "<group>"; };
 		089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
 		2762F6400FCCCA6C002BD8B4 /* SkFlipPixelRef.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SkFlipPixelRef.cpp; path = ../../src/images/SkFlipPixelRef.cpp; sourceTree = SOURCE_ROOT; };
@@ -264,6 +266,7 @@
 				0064EDFB0FC72BEE00D71FB0 /* SampleEmboss.cpp */,
 				0064EDFC0FC72BEE00D71FB0 /* SampleEncode.cpp */,
 				0064EDFD0FC72BEE00D71FB0 /* SampleFillType.cpp */,
+				00A7288B0FD4702A00D5051F /* SampleTestGL.cpp */,
 				0064EDFE0FC72BEE00D71FB0 /* SampleFilter.cpp */,
 				0064EDFF0FC72BEE00D71FB0 /* SampleFilter2.cpp */,
 				0064EE000FC72BEE00D71FB0 /* SampleFontCache.cpp */,
@@ -632,6 +635,7 @@
 				27E1AB2B0FD0D06600098FC5 /* SamplePageFlip.cpp in Sources */,
 				00A728490FD43E7600D5051F /* SampleMovie.cpp in Sources */,
 				00A7284D0FD43E8900D5051F /* SkMovie.cpp in Sources */,
+				00A7288C0FD4702A00D5051F /* SampleTestGL.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};