Changeset 235772 in webkit
- Timestamp:
- Sep 6, 2018 6:36:36 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 10 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r235763 r235772 1 2018-09-06 Megan Gardner <megan_gardner@apple.com> 2 3 Add Support for Conic Gradients 4 https://bugs.webkit.org/show_bug.cgi?id=189329 5 <rdar://problem/21444701> 6 7 Reviewed by Simon Fraser. 8 9 Simple tests to see if conic gradients are rendered properly. 10 11 * fast/gradients/conic-expected.html: Added. 12 * fast/gradients/conic-repeating-expected.html: Added. 13 * fast/gradients/conic-repeating.html: Added. 14 * fast/gradients/conic.html: Added. 15 1 16 2018-09-06 Zalan Bujtas <zalan@apple.com> 2 17 -
trunk/LayoutTests/TestExpectations
r235669 r235772 2240 2240 2241 2241 webkit.org/b/185308 legacy-animation-engine/animations/combo-transform-translate+scale.html [ Pass Failure ] 2242 2243 fast/gradients/conic-repeating.html [ Skip ] 2244 fast/gradients/conic.html [ Skip ] 2245 fast/gradients/conic-off-center.html [ Skip ] 2246 fast/gradients/conic-center-outside-box.html [ Skip ] 2247 fast/gradients/conic-extended-stops.html [ Skip ] -
trunk/LayoutTests/platform/ios-12/TestExpectations
r234629 r235772 26 26 # <rdar://problem/41546970> REGRESSION: LayoutTest media/media-fullscreen-loop-inline.html is a flaky timeout 27 27 media/media-fullscreen-loop-inline.html [ Pass Timeout ] 28 29 # < iOS12 doesn't support the CG needed for Conic Gradients 30 fast/gradients/conic-repeating.html [ Pass ] 31 fast/gradients/conic.html [ Pass ] 32 fast/gradients/conic-off-center.html [ Pass ] 33 fast/gradients/conic-center-outside-box.html [ Pass ] 34 fast/gradients/conic-extended-stops.html [ Pass ] -
trunk/LayoutTests/platform/mac/TestExpectations
r235660 r235772 1757 1757 [ Mojave+ ] imported/blink/fast/text/international/text-shaping-arabic.html [ ImageOnlyFailure ] 1758 1758 [ Mojave+ ] imported/blink/fast/text/international/vertical-positioning-with-combining-marks.html [ ImageOnlyFailure ] 1759 1760 # < Mojave doesn't support the CG needed for Conic Gradients 1761 [ Mojave+ ] fast/gradients/conic-repeating.html [ Pass ] 1762 [ Mojave+ ] fast/gradients/conic.html [ Pass ] 1763 [ Mojave+ ] fast/gradients/conic-off-center.html [ Pass ] 1764 [ Mojave+ ] fast/gradients/conic-center-outside-box.html [ Pass ] 1765 [ Mojave+ ] fast/gradients/conic-extended-stops.html [ Pass ] 1766 -
trunk/Source/WebCore/ChangeLog
r235769 r235772 1 2018-09-06 Megan Gardner <megan_gardner@apple.com> 2 3 Add Support for Conic Gradients 4 https://bugs.webkit.org/show_bug.cgi?id=189329 5 <rdar://problem/21444701> 6 7 Reviewed by Simon Fraser. 8 9 Add support for rendering CSS conic gradients. 10 The parsing work was already done, this just hooks up the data we have 11 with the CG functionality for conic gradients. Add the needed plumbing 12 to allow for this additional type and fill in the creation of 13 a conic gradient. 14 15 Tests: fast/gradients/conic-repeating.html 16 fast/gradients/conic.html 17 18 * css/CSSGradientValue.cpp: 19 (WebCore::createGradient): 20 (WebCore::LinearGradientAdapter::gradientLength const): 21 (WebCore::RadialGradientAdapter::gradientLength const): 22 (WebCore::ConicGradientAdapter::ConicGradientAdapter): 23 (WebCore::ConicGradientAdapter::gradientLength const): 24 (WebCore::ConicGradientAdapter::maxExtent const): 25 (WebCore::ConicGradientAdapter::normalizeStopsAndEndpointsOutsideRange): 26 27 Compute what the color stops should be if they extend past 0-1 28 29 (WebCore::CSSGradientValue::computeStops): 30 (WebCore::CSSConicGradientValue::createGradient): 31 (WebCore::LinearGradientAdapter::startPoint const): Deleted. 32 (WebCore::LinearGradientAdapter::endPoint const): Deleted. 33 (WebCore::RadialGradientAdapter::startPoint const): Deleted. 34 (WebCore::RadialGradientAdapter::endPoint const): Deleted. 35 36 Start and End points weren't very universal. All we really need from these 37 gradientAdapters is their length, so just ask for that instead. 38 39 * inspector/InspectorCanvas.cpp: 40 (WebCore::InspectorCanvas::buildArrayForCanvasGradient): 41 * platform/graphics/Gradient.cpp: 42 (WebCore::Gradient::create): 43 (WebCore::Gradient::Gradient): 44 (WebCore::Gradient::type const): 45 (WebCore::Gradient::adjustParametersForTiledDrawing): 46 (WebCore::Gradient::isZeroSize const): 47 (WebCore::Gradient::hash const): 48 * platform/graphics/Gradient.h: 49 * platform/graphics/cg/GradientCG.cpp: 50 (WebCore::Gradient::paint): 51 1 52 2018-09-06 Wenson Hsieh <wenson_hsieh@apple.com> 2 53 -
trunk/Source/WebCore/PAL/ChangeLog
r235620 r235772 1 2018-09-06 Megan Gardner <megan_gardner@apple.com> 2 3 Add Support for Conic Gradients 4 https://bugs.webkit.org/show_bug.cgi?id=189329 5 <rdar://problem/21444701> 6 7 Reviewed by Simon Fraser. 8 9 Define the CG functionality for conic gradients. 10 11 * pal/spi/cg/CoreGraphicsSPI.h: 12 1 13 2018-09-04 Ryan Haddad <ryanhaddad@apple.com> 2 14 -
trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h
r235154 r235772 280 280 CGStyleRef CGStyleCreateFocusRingWithColor(const CGFocusRingStyle*, CGColorRef); 281 281 void CGContextSetStyle(CGContextRef, CGStyleRef); 282 283 void CGContextDrawConicGradient(CGContextRef, CGGradientRef, CGPoint center, CGFloat angle); 282 284 #endif 283 285 -
trunk/Source/WebCore/css/CSSGradientValue.cpp
r232559 r235772 46 46 if (is<CSSLinearGradientValue>(value)) 47 47 return downcast<CSSLinearGradientValue>(value).createGradient(renderer, size); 48 return downcast<CSSRadialGradientValue>(value).createGradient(renderer, size); 48 if (is<CSSRadialGradientValue>(value)) 49 return downcast<CSSRadialGradientValue>(value).createGradient(renderer, size); 50 return downcast<CSSConicGradientValue>(value).createGradient(renderer, size); 49 51 } 50 52 … … 126 128 { 127 129 } 128 129 FloatPoint startPoint() const { return m_data.point0; } 130 FloatPoint endPoint() const { return m_data.point1; } 130 131 float gradientLength() const 132 { 133 auto gradientSize = m_data.point0 - m_data.point1; 134 return gradientSize.diagonalLength(); 135 } 131 136 float maxExtent(float, float) const { return 1; } 132 137 … … 163 168 } 164 169 165 FloatPoint startPoint() const { return m_data.point0; } 166 FloatPoint endPoint() const { return m_data.point0 + FloatSize { m_data.endRadius, 0 }; } 170 float gradientLength() const { return m_data.endRadius; } 167 171 168 172 // Radial gradients may need to extend further than the endpoints, because they have … … 225 229 }; 226 230 231 class ConicGradientAdapter { 232 public: 233 explicit ConicGradientAdapter() { } 234 float gradientLength() const { return 1; } 235 float maxExtent(float, float) const { return 1; } 236 237 void normalizeStopsAndEndpointsOutsideRange(Vector<GradientStop>& stops) 238 { 239 auto numStops = stops.size(); 240 241 size_t firstZeroOrGreaterIndex = numStops; 242 for (size_t i = 0; i < numStops; ++i) { 243 if (stops[i].offset >= 0) { 244 firstZeroOrGreaterIndex = i; 245 break; 246 } 247 } 248 249 if (firstZeroOrGreaterIndex > 0) { 250 if (firstZeroOrGreaterIndex < numStops && stops[firstZeroOrGreaterIndex].offset > 0) { 251 float prevOffset = stops[firstZeroOrGreaterIndex - 1].offset; 252 float nextOffset = stops[firstZeroOrGreaterIndex].offset; 253 254 float interStopProportion = -prevOffset / (nextOffset - prevOffset); 255 // FIXME: when we interpolate gradients using premultiplied colors, this should do premultiplication. 256 Color blendedColor = blend(stops[firstZeroOrGreaterIndex - 1].color, stops[firstZeroOrGreaterIndex].color, interStopProportion); 257 258 // Clamp the positions to 0 and set the color. 259 for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i) { 260 stops[i].offset = 0; 261 stops[i].color = blendedColor; 262 } 263 } else { 264 // All stops are below 0; just clamp them. 265 for (size_t i = 0; i < firstZeroOrGreaterIndex; ++i) 266 stops[i].offset = 0; 267 } 268 } 269 270 size_t lastOneOrLessIndex = numStops; 271 for (int i = numStops - 1; i >= 0; --i) { 272 if (stops[i].offset <= 1) { 273 lastOneOrLessIndex = i; 274 break; 275 } 276 } 277 278 if (lastOneOrLessIndex < numStops - 1) { 279 if (lastOneOrLessIndex < numStops && stops[lastOneOrLessIndex].offset < 1) { 280 float prevOffset = stops[lastOneOrLessIndex].offset; 281 float nextOffset = stops[lastOneOrLessIndex + 1].offset; 282 283 float interStopProportion = 1 / (nextOffset - prevOffset); 284 // FIXME: when we interpolate gradients using premultiplied colors, this should do premultiplication. 285 Color blendedColor = blend(stops[lastOneOrLessIndex].color, stops[lastOneOrLessIndex + 1].color, interStopProportion); 286 287 // Clamp the positions to 1 and set the color. 288 for (size_t i = lastOneOrLessIndex + 1; i < numStops; ++i) { 289 stops[i].offset = 1; 290 stops[i].color = blendedColor; 291 } 292 } else { 293 // All stops are above 1; just clamp them. 294 for (size_t i = lastOneOrLessIndex; i < numStops; ++i) 295 stops[i].offset = 1; 296 } 297 } 298 } 299 }; 300 227 301 template<typename GradientAdapter> 228 Gradient::ColorStopVector CSSGradientValue::computeStops(GradientAdapter& gradient , const CSSToLengthConversionData& conversionData, const RenderStyle& style, float maxLengthForRepeat)302 Gradient::ColorStopVector CSSGradientValue::computeStops(GradientAdapter& gradientAdapter, const CSSToLengthConversionData& conversionData, const RenderStyle& style, float maxLengthForRepeat) 229 303 { 230 304 if (m_gradientType == CSSDeprecatedLinearGradient || m_gradientType == CSSDeprecatedRadialGradient) { … … 253 327 Vector<GradientStop> stops(numStops); 254 328 255 auto gradientStart = gradient.startPoint(); 256 auto gradientEnd = gradient.endPoint(); 257 258 auto gradientSize = gradientStart - gradientEnd; 259 float gradientLength = gradientSize.diagonalLength(); 329 float gradientLength = gradientAdapter.gradientLength(); 260 330 261 331 for (size_t i = 0; i < numStops; ++i) { … … 283 353 } 284 354 stops[i].offset = (gradientLength > 0) ? length / gradientLength : 0; 285 } else { 355 } else if (positionValue.isAngle()) 356 stops[i].offset = positionValue.floatValue(CSSPrimitiveValue::CSS_DEG) / 360; 357 else { 286 358 ASSERT_NOT_REACHED(); 287 359 stops[i].offset = 0; … … 439 511 numStops = 1; 440 512 } else { 441 float maxExtent = gradient .maxExtent(maxLengthForRepeat, gradientLength);513 float maxExtent = gradientAdapter.maxExtent(maxLengthForRepeat, gradientLength); 442 514 443 515 size_t originalNumStops = numStops; … … 487 559 // If the gradient goes outside the 0-1 range, normalize it by moving the endpoints, and adjusting the stops. 488 560 if (stops.size() > 1 && (stops.first().offset < 0 || stops.last().offset > 1)) 489 gradient .normalizeStopsAndEndpointsOutsideRange(stops);561 gradientAdapter.normalizeStopsAndEndpointsOutsideRange(stops); 490 562 491 563 Gradient::ColorStopVector result; … … 1351 1423 } 1352 1424 1353 Ref<Gradient> CSSConicGradientValue::createGradient(RenderElement&, const FloatSize&) 1354 { 1355 // FIXME: Implement. 1356 return Gradient::create(Gradient::LinearData { }); 1425 Ref<Gradient> CSSConicGradientValue::createGradient(RenderElement& renderer, const FloatSize& size) 1426 { 1427 ASSERT(!size.isEmpty()); 1428 1429 CSSToLengthConversionData conversionData(&renderer.style(), renderer.document().documentElement()->renderStyle(), &renderer.view()); 1430 1431 FloatPoint centerPoint = computeEndPoint(m_firstX.get(), m_firstY.get(), conversionData, size); 1432 if (!m_firstX) 1433 centerPoint.setX(size.width() / 2); 1434 if (!m_firstY) 1435 centerPoint.setY(size.height() / 2); 1436 1437 float angle = 0; 1438 if (m_angle) 1439 angle = m_angle->floatValue(CSSPrimitiveValue::CSS_DEG); 1440 1441 Gradient::ConicData data { centerPoint, angle }; 1442 ConicGradientAdapter adapter; 1443 auto stops = computeStops(adapter, conversionData, renderer.style(), 1); 1444 1445 auto gradient = Gradient::create(WTFMove(data)); 1446 gradient->setSortedColorStops(WTFMove(stops)); 1447 return gradient; 1357 1448 } 1358 1449 -
trunk/Source/WebCore/inspector/InspectorCanvas.cpp
r234586 r235772 614 614 { 615 615 const auto& gradient = canvasGradient.gradient(); 616 617 String type = gradient.type() == Gradient::Type::Radial ? "radial-gradient"_s : "linear-gradient"_s;616 617 String type = gradient.type() == Gradient::Type::Radial ? "radial-gradient"_s : gradient.type() == Gradient::Type::Linear ? "linear-gradient"_s : "conic-gradient"_s; 618 618 619 619 auto parameters = JSON::ArrayOf<float>::create(); … … 632 632 parameters->addItem(data.point1.y()); 633 633 parameters->addItem(data.endRadius); 634 }, 635 [¶meters] (const Gradient::ConicData& data) { 636 parameters->addItem(data.point0.x()); 637 parameters->addItem(data.point0.y()); 638 parameters->addItem(data.angle); 634 639 } 635 640 ); -
trunk/Source/WebCore/page/Settings.yaml
r235539 r235772 526 526 527 527 conicGradientsEnabled: 528 initial: false528 initial: defaultConicGradient 529 529 530 530 colorFilterEnabled: -
trunk/Source/WebCore/page/SettingsDefaultValues.h
r230679 r235772 104 104 static const bool defaultMediaEnabled = false; 105 105 #endif 106 107 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(WATCHOS) 108 static const bool defaultConicGradient = true; 109 #else 110 static const bool defaultConicGradient = false; 111 #endif 112 106 113 107 114 } -
trunk/Source/WebCore/platform/graphics/Gradient.cpp
r231565 r235772 47 47 } 48 48 49 Ref<Gradient> Gradient::create(ConicData&& data) 50 { 51 return adoptRef(*new Gradient(WTFMove(data))); 52 } 53 49 54 Gradient::Gradient(LinearData&& data) 50 55 : m_data(WTFMove(data)) … … 54 59 55 60 Gradient::Gradient(RadialData&& data) 61 : m_data(WTFMove(data)) 62 { 63 platformInit(); 64 } 65 66 Gradient::Gradient(ConicData&& data) 56 67 : m_data(WTFMove(data)) 57 68 { … … 72 83 [] (const RadialData&) { 73 84 return Type::Radial; 85 }, 86 [] (const ConicData&) { 87 return Type::Conic; 74 88 } 75 89 ); … … 100 114 }, 101 115 [] (const RadialData&) { 116 }, 117 [] (const ConicData&) { 102 118 } 103 119 ); … … 112 128 [] (const RadialData& data) { 113 129 return data.point0.x() == data.point1.x() && data.point0.y() == data.point1.y() && data.startRadius == data.endRadius; 130 }, 131 [] (const ConicData&) { 132 return false; 114 133 } 115 134 ); … … 205 224 float endRadius; 206 225 float aspectRatio; 226 float angle; 207 227 GradientSpreadMethod spreadMethod; 208 228 AffineTransform gradientSpaceTransformation; … … 224 244 parameters.endRadius = 0; 225 245 parameters.aspectRatio = 0; 246 parameters.angle = 0; 226 247 parameters.type = Type::Linear; 227 248 }, … … 232 253 parameters.endRadius = data.endRadius; 233 254 parameters.aspectRatio = data.aspectRatio; 255 parameters.angle = 0; 234 256 parameters.type = Type::Radial; 257 }, 258 [¶meters] (const ConicData& data) { 259 parameters.point0 = data.point0; 260 parameters.point1 = {0, 0}; 261 parameters.startRadius = 0; 262 parameters.endRadius = 0; 263 parameters.aspectRatio = 0; 264 parameters.angle = data.angle; 265 parameters.type = Type::Conic; 235 266 } 236 267 ); -
trunk/Source/WebCore/platform/graphics/Gradient.h
r225036 r235772 86 86 float aspectRatio; // For elliptical gradient, width / height. 87 87 }; 88 89 struct ConicData { 90 FloatPoint point0; 91 float angle; 92 }; 88 93 89 using Data = Variant<LinearData, RadialData >;94 using Data = Variant<LinearData, RadialData, ConicData>; 90 95 91 enum class Type { Linear, Radial };96 enum class Type { Linear, Radial, Conic }; 92 97 93 98 static Ref<Gradient> create(LinearData&&); 94 99 static Ref<Gradient> create(RadialData&&); 100 static Ref<Gradient> create(ConicData&&); 95 101 96 102 WEBCORE_EXPORT ~Gradient(); … … 134 140 Gradient(LinearData&&); 135 141 Gradient(RadialData&&); 142 Gradient(ConicData&&); 136 143 137 144 PlatformGradient platformGradient(); -
trunk/Source/WebCore/platform/graphics/cg/GradientCG.cpp
r225036 r235772 128 128 if (needScaling) 129 129 CGContextRestoreGState(platformContext); 130 }, 131 [&] (const ConicData& data) { 132 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(WATCHOS) 133 CGContextSaveGState(platformContext); 134 CGContextTranslateCTM(platformContext, data.point0.x(), data.point0.y()); 135 CGContextRotateCTM(platformContext, (CGFloat)-M_PI_2); 136 CGContextTranslateCTM(platformContext, -data.point0.x(), -data.point0.y()); 137 CGContextDrawConicGradient(platformContext, platformGradient(), data.point0, data.angle); 138 CGContextRestoreGState(platformContext); 139 #else 140 UNUSED_PARAM(data); 141 #endif 130 142 } 131 143 ); -
trunk/Source/WebKit/ChangeLog
r235769 r235772 1 2018-09-06 Megan Gardner <megan_gardner@apple.com> 2 3 Add Support for Conic Gradients 4 https://bugs.webkit.org/show_bug.cgi?id=189329 5 <rdar://problem/21444701> 6 7 Reviewed by Simon Fraser. 8 9 Connect up web preferences to allow conic gradients to be turned on in the 10 experimental features menu. 11 12 * Shared/WebPreferences.yaml: 13 1 14 2018-09-06 Wenson Hsieh <wenson_hsieh@apple.com> 2 15 -
trunk/Source/WebKit/Shared/WebPreferences.yaml
r235683 r235772 1149 1149 category: experimental 1150 1150 1151 ConicGradientsEnabled: 1152 type: bool 1153 defaultValue: DEFAULT_CONIC_GRADIENT_ENABLED 1154 humanReadableName: "CSS Conic Gradient" 1155 humanReadableDescription: "Support for CSS Conic Gradients" 1156 category: experimental 1157 1151 1158 ImageBitmapOffscreenCanvasEnabled: 1152 1159 type: bool -
trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h
r235512 r235772 210 210 #endif 211 211 212 #if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || PLATFORM(WATCHOS) 213 #define DEFAULT_CONIC_GRADIENT_ENABLED true 214 #else 215 #define DEFAULT_CONIC_GRADIENT_ENABLED false 216 #endif 217 212 218 bool defaultPassiveTouchListenersAsDefaultOnDocument(); 213 219 bool defaultCustomPasteboardDataEnabled();
Note: See TracChangeset
for help on using the changeset viewer.