Changeset 65331 in webkit
- Timestamp:
- Aug 13, 2010 10:24:45 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r65330 r65331 1 2010-08-13 Ariya Hidayat <ariya@sencha.com> 2 3 Reviewed by Simon Hausmann. 4 5 [Qt] Canvas and CSS: blur option in shadow not working 6 https://bugs.webkit.org/show_bug.cgi?id=34479 7 8 Patch 1: Refactor shadow states handling. 9 10 * platform/graphics/qt/GraphicsContextQt.cpp: 11 (WebCore::GraphicsContextPlatformPrivate::): Added shadow states as 12 member variables. 13 (WebCore::GraphicsContextPlatformPrivate::hasShadow): Convenient 14 function to check whether there is shadow or not. 15 (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): 16 (WebCore::GraphicsContext::drawRect): Use shadow states instead of 17 calling getShadow. 18 (WebCore::GraphicsContext::drawLine): ditto. 19 (WebCore::GraphicsContext::strokeArc): ditto. 20 (WebCore::GraphicsContext::drawConvexPolygon): ditto. 21 (WebCore::GraphicsContext::fillPath): ditto. 22 (WebCore::GraphicsContext::strokePath): ditto. 23 (WebCore::GraphicsContext::fillRect): Removes the use of helper function 24 drawBorderlessRectShadow as the code already becomes a lot simpler. 25 (WebCore::GraphicsContext::fillRoundedRect): Removes the use of helper 26 function drawFilledShadowPath as the code already becomes a lot simpler. 27 (WebCore::GraphicsContext::setPlatformShadow): Store shadow states 28 and find out the shadow type (complexity) for future use. 29 (WebCore::GraphicsContext::clearPlatformShadow): Reset shadow states. 30 1 31 2010-08-11 Zhenyao Mo <zmo@google.com> 2 32 -
trunk/WebCore/platform/graphics/qt/GraphicsContextQt.cpp
r65276 r65331 200 200 QPainterPath currentPath; 201 201 202 enum { 203 NoShadow, 204 OpaqueSolidShadow, 205 AlphaSolidShadow, 206 BlurShadow 207 } shadowType; 208 QColor shadowColor; 209 int shadowBlurRadius; 210 QPointF shadowOffset; 211 212 bool hasShadow() const 213 { 214 return shadowType != NoShadow; 215 } 216 202 217 private: 203 218 QPainter* painter; … … 223 238 } else 224 239 antiAliasingForRectsAndLines = false; 240 241 shadowType = NoShadow; 242 shadowBlurRadius = 0; 225 243 } 226 244 … … 293 311 p->setRenderHint(QPainter::Antialiasing, m_data->antiAliasingForRectsAndLines); 294 312 295 if (m_common->state.shadowColor.isValid()) { 296 FloatSize shadowSize; 297 float shadowBlur; 298 Color shadowColor; 299 if (getShadow(shadowSize, shadowBlur, shadowColor)) { 300 IntRect shadowRect = rect; 301 shadowRect.move(shadowSize.width(), shadowSize.height()); 302 shadowRect.inflate(static_cast<int>(p->pen().widthF())); 303 p->fillRect(shadowRect, QColor(shadowColor)); 304 } 313 if (m_data->hasShadow()) { 314 IntRect shadowRect = rect; 315 shadowRect.move(m_data->shadowOffset.x(), m_data->shadowOffset.y()); 316 shadowRect.inflate(static_cast<int>(p->pen().widthF())); 317 p->fillRect(shadowRect, m_data->shadowColor); 305 318 } 306 319 … … 332 345 adjustLineToPixelBoundaries(p1, p2, width, style); 333 346 334 FloatSize shadowSize; 335 float shadowBlur; 336 Color shadowColor; 337 if (textDrawingMode() == cTextFill && getShadow(shadowSize, shadowBlur, shadowColor)) { 338 p->save(); 339 p->translate(shadowSize.width(), shadowSize.height()); 340 p->setPen(shadowColor); 341 p->drawLine(p1, p2); 342 p->restore(); 347 if (m_data->hasShadow()) { 348 if (textDrawingMode() == cTextFill) { 349 p->save(); 350 p->translate(m_data->shadowOffset); 351 p->setPen(m_data->shadowColor); 352 p->drawLine(p1, p2); 353 p->restore(); 354 } 343 355 } 344 356 … … 434 446 p->setRenderHint(QPainter::Antialiasing, true); 435 447 436 FloatSize shadowSize;437 float shadowBlur;438 Color shadowColor;439 448 startAngle *= 16; 440 449 angleSpan *= 16; 441 if (getShadow(shadowSize, shadowBlur, shadowColor)) { 450 451 if (m_data->hasShadow()) { 442 452 p->save(); 443 p->translate( shadowSize.width(), shadowSize.height());453 p->translate(m_data->shadowOffset); 444 454 QPen pen(p->pen()); 445 pen.setColor( shadowColor);455 pen.setColor(m_data->shadowColor); 446 456 p->setPen(pen); 447 457 p->drawArc(rect, startAngle, angleSpan); … … 469 479 p->save(); 470 480 p->setRenderHint(QPainter::Antialiasing, shouldAntialias); 471 FloatSize shadowSize; 472 float shadowBlur; 473 Color shadowColor; 474 if (getShadow(shadowSize, shadowBlur, shadowColor)) { 481 if (m_data->hasShadow()) { 475 482 p->save(); 476 p->translate( shadowSize.width(), shadowSize.height());483 p->translate(m_data->shadowOffset); 477 484 if (p->brush().style() != Qt::NoBrush) 478 p->setBrush(QBrush( shadowColor));485 p->setBrush(QBrush(m_data->shadowColor)); 479 486 QPen pen(p->pen()); 480 487 if (pen.style() != Qt::NoPen) { 481 pen.setColor( shadowColor);488 pen.setColor(m_data->shadowColor); 482 489 p->setPen(pen); 483 490 } … … 513 520 } 514 521 515 static void inline drawFilledShadowPath(GraphicsContext* context, QPainter* p, const QPainterPath& path)516 {517 FloatSize shadowSize;518 float shadowBlur;519 Color shadowColor;520 if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {521 p->translate(shadowSize.width(), shadowSize.height());522 p->fillPath(path, QBrush(shadowColor));523 p->translate(-shadowSize.width(), -shadowSize.height());524 }525 }526 527 522 void GraphicsContext::fillPath() 528 523 { … … 534 529 path.setFillRule(toQtFillRule(fillRule())); 535 530 536 drawFilledShadowPath(this, p, path); 531 if (m_data->hasShadow()) { 532 p->translate(m_data->shadowOffset); 533 p->fillPath(path, m_data->shadowColor); 534 p->translate(-m_data->shadowOffset); 535 } 537 536 if (m_common->state.fillPattern) { 538 537 AffineTransform affine; … … 558 557 path.setFillRule(toQtFillRule(fillRule())); 559 558 560 FloatSize shadowSize; 561 float shadowBlur; 562 Color shadowColor; 563 if (getShadow(shadowSize, shadowBlur, shadowColor)) { 564 QTransform t(p->worldTransform()); 565 p->translate(shadowSize.width(), shadowSize.height()); 559 if (m_data->hasShadow()) { 560 p->translate(m_data->shadowOffset); 566 561 QPen shadowPen(pen); 567 shadowPen.setColor( shadowColor);562 shadowPen.setColor(m_data->shadowColor); 568 563 p->strokePath(path, shadowPen); 569 p-> setWorldTransform(t);564 p->translate(-m_data->shadowOffset); 570 565 } 571 566 if (m_common->state.strokePattern) { … … 583 578 p->strokePath(path, pen); 584 579 m_data->currentPath = QPainterPath(); 585 }586 587 static inline void drawBorderlessRectShadow(GraphicsContext* context, QPainter* p, const FloatRect& rect)588 {589 FloatSize shadowSize;590 float shadowBlur;591 Color shadowColor;592 if (context->getShadow(shadowSize, shadowBlur, shadowColor)) {593 FloatRect shadowRect(rect);594 shadowRect.move(shadowSize.width(), shadowSize.height());595 p->fillRect(shadowRect, QColor(shadowColor));596 }597 580 } 598 581 … … 672 655 FloatRect normalizedRect = rect.normalized(); 673 656 674 FloatSize shadowSize; 675 float shadowBlur; 676 Color shadowColor; 677 bool hasShadow = getShadow(shadowSize, shadowBlur, shadowColor); 678 FloatRect shadowDestRect; 657 QRectF shadowDestRect; 679 658 QImage* shadowImage = 0; 680 659 QPainter* pShadow = 0; 681 660 682 if ( hasShadow) {661 if (m_data->hasShadow()) { 683 662 shadowImage = new QImage(roundedIntSize(normalizedRect.size()), QImage::Format_ARGB32_Premultiplied); 684 663 pShadow = new QPainter(shadowImage); 685 664 shadowDestRect = normalizedRect; 686 shadowDestRect. move(shadowSize.width(), shadowSize.height());665 shadowDestRect.translate(m_data->shadowOffset); 687 666 688 667 pShadow->setCompositionMode(QPainter::CompositionMode_Source); 689 pShadow->fillRect(shadow Image->rect(),shadowColor);668 pShadow->fillRect(shadowDestRect, m_data->shadowColor); 690 669 pShadow->setCompositionMode(QPainter::CompositionMode_DestinationIn); 691 670 } … … 697 676 QPixmap* image = m_common->state.fillPattern->tileImage()->nativeImageForCurrentFrame(); 698 677 699 if ( hasShadow) {678 if (m_data->hasShadow()) { 700 679 drawRepeatPattern(pShadow, image, FloatRect(static_cast<QRectF>(shadowImage->rect())), m_common->state.fillPattern->repeatX(), m_common->state.fillPattern->repeatY()); 701 680 pShadow->end(); … … 707 686 brush.setTransform(m_common->state.fillGradient->gradientSpaceTransform()); 708 687 709 if ( hasShadow) {688 if (m_data->hasShadow()) { 710 689 pShadow->fillRect(shadowImage->rect(), brush); 711 690 pShadow->end(); … … 714 693 p->fillRect(normalizedRect, brush); 715 694 } else { 716 if ( hasShadow) {695 if (m_data->hasShadow()) { 717 696 pShadow->fillRect(shadowImage->rect(), p->brush()); 718 697 pShadow->end(); … … 734 713 m_data->solidColor.setColor(color); 735 714 QPainter* p = m_data->p(); 736 if (m_common->state.shadowColor.isValid()) 737 drawBorderlessRectShadow(this, p, rect); 715 716 if (m_data->hasShadow()) 717 p->fillRect(QRectF(rect).translated(m_data->shadowOffset), m_data->shadowColor); 718 738 719 p->fillRect(rect, m_data->solidColor); 739 720 } … … 746 727 Path path = Path::createRoundedRectangle(rect, topLeft, topRight, bottomLeft, bottomRight); 747 728 QPainter* p = m_data->p(); 748 drawFilledShadowPath(this, p, path.platformPath()); 729 if (m_data->hasShadow()) { 730 p->translate(m_data->shadowOffset); 731 p->fillPath(path.platformPath(), m_data->shadowColor); 732 p->translate(-m_data->shadowOffset); 733 } 749 734 p->fillPath(path.platformPath(), QColor(color)); 750 735 } … … 888 873 } 889 874 890 void GraphicsContext::setPlatformShadow(const FloatSize& size, float , const Color&, ColorSpace)875 void GraphicsContext::setPlatformShadow(const FloatSize& size, float blur, const Color& color, ColorSpace) 891 876 { 892 877 // Qt doesn't support shadows natively, they are drawn manually in the draw* … … 898 883 m_common->state.shadowSize = FloatSize(size.width(), -size.height()); 899 884 } 885 886 // Here we just store important shadow states. 887 888 m_data->shadowBlurRadius = qRound(blur); 889 m_data->shadowOffset = QPointF(m_common->state.shadowSize.width(), m_common->state.shadowSize.height()); 890 m_data->shadowColor = color; 891 892 // The type of shadow is decided by the blur radius, shadow offset, and shadow color. 893 894 if (!color.isValid() || !color.alpha()) { 895 // Can't paint the shadow with invalid or invisible color. 896 m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow; 897 } else { 898 if (blur >= 1) { 899 // Shadow is always blurred, even the offset is zero. 900 m_data->shadowType = GraphicsContextPlatformPrivate::BlurShadow; 901 } else { 902 if (m_data->shadowOffset.isNull()) { 903 // Without blur and zero offset means the shadow is fully hidden. 904 m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow; 905 } else { 906 if (color.hasAlpha()) 907 m_data->shadowType = GraphicsContextPlatformPrivate::AlphaSolidShadow; 908 else 909 m_data->shadowType = GraphicsContextPlatformPrivate::OpaqueSolidShadow; 910 } 911 } 912 } 900 913 } 901 914 902 915 void GraphicsContext::clearPlatformShadow() 903 916 { 904 // Qt doesn't support shadows natively, they are drawn manually in the draw* 905 // functions 917 m_data->shadowType = GraphicsContextPlatformPrivate::NoShadow; 906 918 } 907 919
Note: See TracChangeset
for help on using the changeset viewer.