add blitter api for aa-hairlines
authorreed <reed@google.com>
Wed, 15 Apr 2015 14:51:15 +0000 (07:51 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 15 Apr 2015 14:51:15 +0000 (07:51 -0700)
BUG=skia:
TBR=

Review URL: https://codereview.chromium.org/1088143002

src/core/SkBlitter.h
src/core/SkScan_Antihair.cpp

index 9447bf1..2d4a0de 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #ifndef SkBlitter_DEFINED
 #define SkBlitter_DEFINED
 
@@ -55,6 +53,35 @@ public:
     */
     virtual const SkBitmap* justAnOpaqueColor(uint32_t* value);
 
+    // (x, y), (x + 1, y)
+    void blitAntiH2(int x, int y, U8CPU a0, U8CPU a1) {
+        int16_t runs[3];
+        uint8_t aa[2];
+        
+        runs[0] = 1;
+        runs[1] = 1;
+        runs[2] = 0;
+        aa[0] = SkToU8(a0);
+        aa[1] = SkToU8(a1);
+        this->blitAntiH(x, y, aa, runs);
+    }
+
+    // (x, y), (x, y + 1)
+    void blitAntiV2(int x, int y, U8CPU a0, U8CPU a1) {
+        int16_t runs[2];
+        uint8_t aa[1];
+        
+        runs[0] = 1;
+        runs[1] = 0;
+        aa[0] = SkToU8(a0);
+        this->blitAntiH(x, y, aa, runs);
+        // reset in case the clipping blitter modified runs
+        runs[0] = 1;
+        runs[1] = 0;
+        aa[0] = SkToU8(a1);
+        this->blitAntiH(x, y + 1, aa, runs);
+    }
+    
     /**
      *  Special method just to identify the null blitter, which is returned
      *  from Choose() if the request cannot be fulfilled. Default impl
index 3073434..546ced0 100644 (file)
@@ -154,70 +154,29 @@ public:
 class Horish_SkAntiHairBlitter : public SkAntiHairBlitter {
 public:
     SkFixed drawCap(int x, SkFixed fy, SkFixed dy, int mod64) override {
-        int16_t runs[2];
-        uint8_t  aa[1];
-
-        runs[0] = 1;
-        runs[1] = 0;
-
         fy += SK_Fixed1/2;
-        SkBlitter* blitter = this->getBlitter();
-
+        
         int lower_y = fy >> 16;
         uint8_t  a = (uint8_t)(fy >> 8);
-        unsigned ma = SmallDot6Scale(a, mod64);
-        if (ma) {
-            aa[0] = ApplyGamma(gamma, ma);
-            blitter->blitAntiH(x, lower_y, aa, runs);
-            // the clipping blitters might edit runs, but should not affect us
-            SkASSERT(runs[0] == 1);
-            SkASSERT(runs[1] == 0);
-        }
-        ma = SmallDot6Scale(255 - a, mod64);
-        if (ma) {
-            aa[0] = ApplyGamma(gamma, ma);
-            blitter->blitAntiH(x, lower_y - 1, aa, runs);
-            // the clipping blitters might edit runs, but should not affect us
-            SkASSERT(runs[0] == 1);
-            SkASSERT(runs[1] == 0);
-        }
-        fy += dy;
-
-        return fy - SK_Fixed1/2;
+        unsigned a0 = SmallDot6Scale(255 - a, mod64);
+        unsigned a1 = SmallDot6Scale(a, mod64);
+        this->getBlitter()->blitAntiV2(x, lower_y - 1, a0, a1);
+        
+        return fy + dy - SK_Fixed1/2;
     }
-
+    
     SkFixed drawLine(int x, int stopx, SkFixed fy, SkFixed dy) override {
         SkASSERT(x < stopx);
-
-        int16_t runs[2];
-        uint8_t  aa[1];
-
-        runs[0] = 1;
-        runs[1] = 0;
-
+        
         fy += SK_Fixed1/2;
         SkBlitter* blitter = this->getBlitter();
         do {
             int lower_y = fy >> 16;
             uint8_t  a = (uint8_t)(fy >> 8);
-            if (a) {
-                aa[0] = a;
-                blitter->blitAntiH(x, lower_y, aa, runs);
-                // the clipping blitters might edit runs, but should not affect us
-                SkASSERT(runs[0] == 1);
-                SkASSERT(runs[1] == 0);
-            }
-            a = 255 - a;
-            if (a) {
-                aa[0] = a;
-                blitter->blitAntiH(x, lower_y - 1, aa, runs);
-                // the clipping blitters might edit runs, but should not affect us
-                SkASSERT(runs[0] == 1);
-                SkASSERT(runs[1] == 0);
-            }
+            blitter->blitAntiV2(x, lower_y - 1, 255 - a, a);
             fy += dy;
         } while (++x < stopx);
-
+        
         return fy - SK_Fixed1/2;
     }
 };
@@ -266,53 +225,26 @@ public:
 class Vertish_SkAntiHairBlitter : public SkAntiHairBlitter {
 public:
     SkFixed drawCap(int y, SkFixed fx, SkFixed dx, int mod64) override {
-        int16_t runs[3];
-        uint8_t  aa[2];
-
-        runs[0] = 1;
-        runs[2] = 0;
-
         fx += SK_Fixed1/2;
+        
         int x = fx >> 16;
-        uint8_t  a = (uint8_t)(fx >> 8);
-
-        aa[0] = SmallDot6Scale(255 - a, mod64);
-        aa[1] = SmallDot6Scale(a, mod64);
-        // the clippng blitters might overwrite this guy, so we have to reset it each time
-        runs[1] = 1;
-        this->getBlitter()->blitAntiH(x - 1, y, aa, runs);
-        // the clipping blitters might edit runs, but should not affect us
-        SkASSERT(runs[0] == 1);
-        SkASSERT(runs[2] == 0);
-        fx += dx;
-
-        return fx - SK_Fixed1/2;
+        uint8_t a = (uint8_t)(fx >> 8);
+        this->getBlitter()->blitAntiH2(x - 1, y,
+                                       SmallDot6Scale(255 - a, mod64), SmallDot6Scale(a, mod64));
+        
+        return fx + dx - SK_Fixed1/2;
     }
-
+    
     SkFixed drawLine(int y, int stopy, SkFixed fx, SkFixed dx) override {
         SkASSERT(y < stopy);
-        int16_t runs[3];
-        uint8_t  aa[2];
-
-        runs[0] = 1;
-        runs[2] = 0;
-
         fx += SK_Fixed1/2;
         do {
             int x = fx >> 16;
-            uint8_t  a = (uint8_t)(fx >> 8);
-
-            aa[0] = 255 - a;
-            aa[1] = a;
-            // the clippng blitters might overwrite this guy, so we have to reset it each time
-            runs[1] = 1;
-            this->getBlitter()->blitAntiH(x - 1, y, aa, runs);
-            // the clipping blitters might edit runs, but should not affect us
-            SkASSERT(runs[0] == 1);
-            SkASSERT(runs[2] == 0);
+            uint8_t a = (uint8_t)(fx >> 8);
+            this->getBlitter()->blitAntiH2(x - 1, y, 255 - a, a);
             fx += dx;
         } while (++y < stopy);
-
+        
         return fx - SK_Fixed1/2;
     }
 };