add SkRect::joinNonEmptyArg for faster unioning
authorreed <reed@google.com>
Wed, 1 Oct 2014 16:24:12 +0000 (09:24 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 1 Oct 2014 16:24:12 +0000 (09:24 -0700)
BUG=skia:

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

include/core/SkRect.h
src/gpu/GrBitmapTextContext.cpp
src/gpu/GrDistanceFieldTextContext.cpp

index c8fc7c6..d249aee 100644 (file)
@@ -702,8 +702,19 @@ struct SK_API SkRect {
     void join(const SkRect& r) {
         this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
     }
-    // alias for join()
-    void growToInclude(const SkRect& r) { this->join(r); }
+
+    void joinNonEmptyArg(const SkRect& r) {
+        SkASSERT(!r.isEmpty());
+        // if we are empty, just assign
+        if (fLeft >= fRight || fTop >= fBottom) {
+            *this = r;
+        } else {
+            fLeft   = SkMinScalar(fLeft, r.left());
+            fTop    = SkMinScalar(fTop, r.top());
+            fRight  = SkMaxScalar(fRight, r.right());
+            fBottom = SkMaxScalar(fBottom, r.bottom());
+        }
+    }
 
     /**
      *  Grow the rect to include the specified (x,y). After this call, the
index 422a7e0..c9cdf2c 100755 (executable)
@@ -575,7 +575,7 @@ HAS_ATLAS:
     r.fRight = SkFixedToFloat(vx + width);
     r.fBottom = SkFixedToFloat(vy + height);
 
-    fVertexBounds.growToInclude(r);
+    fVertexBounds.joinNonEmptyArg(r);
 
     size_t vertSize = useColorVerts ? (2 * sizeof(SkPoint) + sizeof(GrColor)) :
                                       (2 * sizeof(SkPoint));
index 07e9a2e..b565dd6 100755 (executable)
@@ -411,7 +411,7 @@ HAS_ATLAS:
     r.fRight = sx + width;
     r.fBottom = sy + height;
 
-    fVertexBounds.growToInclude(r);
+    fVertexBounds.joinNonEmptyArg(r);
 
     size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint))
                                   : (2 * sizeof(SkPoint) + sizeof(GrColor));