outset the bounds if we're in hairline before quick-reject in SkDraw.cpp
authorreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 23 Nov 2009 21:46:47 +0000 (21:46 +0000)
committerreed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 23 Nov 2009 21:46:47 +0000 (21:46 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@445 2bbb7eff-a529-9590-31e7-b0007b416f81

samplecode/SampleApp.cpp
src/core/SkDraw.cpp

index 8fcdfa8..84ce0d2 100644 (file)
@@ -254,6 +254,31 @@ SampleWindow::~SampleWindow() {
     delete fGLCanvas;
 }
 
+static SkBitmap capture_bitmap(SkCanvas* canvas) {
+    SkBitmap bm;
+    const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
+    src.copyTo(&bm, src.config());
+    return bm;
+}
+
+static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
+                        SkBitmap* diff) {
+    const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
+    
+    SkAutoLockPixels alp0(src);
+    SkAutoLockPixels alp1(orig);
+    for (int y = 0; y < src.height(); y++) {
+        const void* srcP = src.getAddr(0, y);
+        const void* origP = orig.getAddr(0, y);
+        size_t bytes = src.width() * src.bytesPerPixel();
+        if (memcmp(srcP, origP, bytes)) {
+            SkDebugf("---------- difference on line %d\n", y);
+            return true;
+        }
+    }
+    return false;
+}
+
 #define XCLIP_N  8
 #define YCLIP_N  8
 
@@ -262,23 +287,35 @@ void SampleWindow::draw(SkCanvas* canvas) {
     gAnimTime = SkTime::GetMSecs();
 
     if (fNClip) {
-     //   this->INHERITED::draw(canvas);
-     //   SkBitmap orig = capture_bitmap(canvas);
+        this->INHERITED::draw(canvas);
+        SkBitmap orig = capture_bitmap(canvas);
 
         const SkScalar w = this->width();
         const SkScalar h = this->height();
         const SkScalar cw = w / XCLIP_N;
         const SkScalar ch = h / YCLIP_N;
         for (int y = 0; y < YCLIP_N; y++) {
+            SkRect r;
+            r.fTop = y * ch;
+            r.fBottom = (y + 1) * ch;
+            if (y == YCLIP_N - 1) {
+                r.fBottom = h;
+            }
             for (int x = 0; x < XCLIP_N; x++) {
                 SkAutoCanvasRestore acr(canvas, true);
-                SkRect r = {
-                    x * cw, y * ch, (x + 1) * cw, (y + 1) * ch
-                };
+                r.fLeft = x * cw;
+                r.fRight = (x + 1) * cw;
+                if (x == XCLIP_N - 1) {
+                    r.fRight = w;
+                }
                 canvas->clipRect(r);
                 this->INHERITED::draw(canvas);
             }
         }
+        
+        SkBitmap diff;
+        if (bitmap_diff(canvas, orig, &diff)) {
+        }
     } else {
         this->INHERITED::draw(canvas);
     }
index 7f0cc15..4f28cfe 100644 (file)
@@ -694,6 +694,10 @@ void SkDraw::drawRect(const SkRect& rect, const SkPaint& paint) const {
     {
         SkIRect ir;
         devRect.roundOut(&ir);
+        if (paint.getStyle() != SkPaint::kFill_Style) {
+            // extra space for hairlines
+            ir.inset(-1, -1);
+        }
         if (fClip->quickReject(ir))
             return;
     }