Bug 1284408: Ensure hard stops are aligned on pixel boundaries for D2D 1.1 internal gradient texture. r=jrmuizel draft
authorBas Schouten <bschouten@mozilla.com>
Wed, 13 Jul 2016 17:02:36 +0200
changeset 387184 cdd62bb54187a21c474e639010c711637c77c71c
parent 385282 cdbdbb4df09a8413b124b5f7a200d44380e5a2f8
child 525299 b17b95cbcedea2acac7ec16f464783ccea989043
push id22907
push userbschouten@mozilla.com
push dateWed, 13 Jul 2016 15:02:54 +0000
reviewersjrmuizel
bugs1284408
milestone50.0a1
Bug 1284408: Ensure hard stops are aligned on pixel boundaries for D2D 1.1 internal gradient texture. r=jrmuizel MozReview-Commit-ID: G37qMe1sz2x
gfx/2d/DrawTargetD2D1.cpp
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -907,16 +907,25 @@ DrawTargetD2D1::CreateGradientStops(Grad
     gfxWarning() << *this << ": Failed to create GradientStopCollection with no stops.";
     return nullptr;
   }
 
   D2D1_GRADIENT_STOP *stops = new D2D1_GRADIENT_STOP[aNumStops];
 
   for (uint32_t i = 0; i < aNumStops; i++) {
     stops[i].position = rawStops[i].offset;
+
+    if (i > 0 && rawStops[i - 1].offset == rawStops[i].offset ||
+        i < (aNumStops - 1) && rawStops[i + 1].offset == rawStops[i].offset) {
+      // For hard stops we ensure they're aligned on pixel boundaries for D2Ds
+      // 1024 pixel internal texture. This ensures when drawing to larger surfaces we
+      // don't get drawing artifacts on hard stops from blending between two stops.
+      stops[i].position += (0.5 - (stops[i].position * 1024 - floor(stops[i].position * 1024))) / 1024;
+    }
+
     stops[i].color = D2DColor(rawStops[i].color);
   }
 
   RefPtr<ID2D1GradientStopCollection> stopCollection;
 
   HRESULT hr =
     mDC->CreateGradientStopCollection(stops, aNumStops,
                                       D2D1_GAMMA_2_2, D2DExtend(aExtendMode, Axis::BOTH),