Changeset 213404 in webkit
- Timestamp:
- Mar 3, 2017, 5:45:39 PM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 6 edited
-
ChangeLog (modified) (1 diff)
-
rendering/RenderImage.cpp (modified) (12 diffs)
-
rendering/RenderImageResource.cpp (modified) (1 diff)
-
rendering/RenderImageResource.h (modified) (1 diff)
-
rendering/RenderImageResourceStyleImage.cpp (modified) (1 diff)
-
rendering/RenderImageResourceStyleImage.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r213400 r213404 1 2017-03-03 Simon Fraser <simon.fraser@apple.com> 2 3 Clean up RenderImage and a RenderImageResource function 4 https://bugs.webkit.org/show_bug.cgi?id=169153 5 6 Reviewed by Zalan Bujtas. 7 8 Change all calls to imageResource().cachedImage() in RenderImage to use the inline 9 cachedImage() function. 10 11 In RenderImage::paintReplaced(), early return after the broken image block (and no need 12 to test imageResource().hasImage() again in the second condition). Convert height/width to size, 13 which also forces us to be explicit about using flooredIntSize() when fetching the image 14 (perhaps this should be a roundedIntSize, but I didn't want to change behavior). 15 16 Change RenderImageResource::image() to take an IntSize, rather than int height and width. 17 18 No behavior change. 19 20 * rendering/RenderImage.cpp: 21 (WebCore::RenderImage::styleDidChange): 22 (WebCore::RenderImage::imageChanged): 23 (WebCore::RenderImage::notifyFinished): 24 (WebCore::RenderImage::paintReplaced): 25 (WebCore::RenderImage::paintIntoRect): 26 (WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect): 27 (WebCore::RenderImage::embeddedContentBox): 28 * rendering/RenderImageResource.cpp: 29 (WebCore::RenderImageResource::image): 30 * rendering/RenderImageResource.h: 31 (WebCore::RenderImageResource::image): 32 * rendering/RenderImageResourceStyleImage.cpp: 33 (WebCore::RenderImageResourceStyleImage::image): 34 * rendering/RenderImageResourceStyleImage.h: 35 1 36 2017-03-03 Antoine Quint <graouts@apple.com> 2 37 -
trunk/Source/WebCore/rendering/RenderImage.cpp
r210768 r213404 211 211 RenderReplaced::styleDidChange(diff, oldStyle); 212 212 if (m_needsToSetSizeForAltText) { 213 if (!m_altText.isEmpty() && setImageSizeForAltText( imageResource().cachedImage()))213 if (!m_altText.isEmpty() && setImageSizeForAltText(cachedImage())) 214 214 repaintOrMarkForLayout(ImageSizeChangeForAltText); 215 215 m_needsToSetSizeForAltText = false; … … 258 258 return; 259 259 } 260 imageSizeChange = setImageSizeForAltText( imageResource().cachedImage());260 imageSizeChange = setImageSizeForAltText(cachedImage()); 261 261 } 262 262 … … 343 343 invalidateBackgroundObscurationStatus(); 344 344 345 if (&newImage == imageResource().cachedImage()) {345 if (&newImage == cachedImage()) { 346 346 // tell any potential compositing layers 347 347 // that the image is done and they can reference it directly. … … 352 352 void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset) 353 353 { 354 LayoutUnit cWidth = contentWidth(); 355 LayoutUnit cHeight = contentHeight(); 356 LayoutUnit leftBorder = borderLeft(); 357 LayoutUnit topBorder = borderTop(); 358 LayoutUnit leftPad = paddingLeft(); 359 LayoutUnit topPad = paddingTop(); 354 LayoutSize contentSize = this->contentSize(); 360 355 361 356 GraphicsContext& context = paintInfo.context(); … … 369 364 page().addRelevantUnpaintedObject(this, visualOverflowRect()); 370 365 371 if (c Width > 2 && cHeight> 2) {366 if (contentSize.width() > 2 && contentSize.height() > 2) { 372 367 LayoutUnit borderWidth = LayoutUnit(1 / deviceScaleFactor); 368 369 LayoutUnit leftBorder = borderLeft(); 370 LayoutUnit topBorder = borderTop(); 371 LayoutUnit leftPad = paddingLeft(); 372 LayoutUnit topPad = paddingTop(); 373 373 374 374 // Draw an outline rect where the image should be. … … 376 376 context.setStrokeColor(Color::lightGray); 377 377 context.setFillColor(Color::transparent); 378 context.drawRect(snapRectToDevicePixels(LayoutRect( paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad, cWidth, cHeight), deviceScaleFactor), borderWidth);378 context.drawRect(snapRectToDevicePixels(LayoutRect({ paintOffset.x() + leftBorder + leftPad, paintOffset.y() + topBorder + topPad }, contentSize), deviceScaleFactor), borderWidth); 379 379 380 380 bool errorPictureDrawn = false; … … 382 382 // When calculating the usable dimensions, exclude the pixels of 383 383 // the ouline rect so the error image/alt text doesn't draw on it. 384 LayoutUnit usableWidth = cWidth - 2 * borderWidth; 385 LayoutUnit usableHeight = cHeight - 2 * borderWidth; 384 LayoutSize usableSize = contentSize - LayoutSize(2 * borderWidth, 2 * borderWidth); 386 385 387 386 RefPtr<Image> image = imageResource().image(); 388 387 389 if (imageResource().errorOccurred() && !image->isNull() && usable Width >= image->width() && usableHeight>= image->height()) {388 if (imageResource().errorOccurred() && !image->isNull() && usableSize.width() >= image->width() && usableSize.height() >= image->height()) { 390 389 // Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution. 391 std::pair<Image*, float> brokenImageAndImageScaleFactor = imageResource().cachedImage()->brokenImage(document().deviceScaleFactor());390 std::pair<Image*, float> brokenImageAndImageScaleFactor = cachedImage()->brokenImage(document().deviceScaleFactor()); 392 391 image = brokenImageAndImageScaleFactor.first; 393 392 FloatSize imageSize = image->size(); 394 393 imageSize.scale(1 / brokenImageAndImageScaleFactor.second); 395 394 // Center the error image, accounting for border and padding. 396 LayoutUnit centerX = (usable Width- imageSize.width()) / 2;395 LayoutUnit centerX = (usableSize.width() - imageSize.width()) / 2; 397 396 if (centerX < 0) 398 397 centerX = 0; 399 LayoutUnit centerY = (usable Height- imageSize.height()) / 2;398 LayoutUnit centerY = (usableSize.height() - imageSize.height()) / 2; 400 399 if (centerY < 0) 401 400 centerY = 0; … … 424 423 LayoutUnit textWidth = font.width(textRun); 425 424 if (errorPictureDrawn) { 426 if (usable Width>= textWidth && fontMetrics.height() <= imageOffset.height())425 if (usableSize.width() >= textWidth && fontMetrics.height() <= imageOffset.height()) 427 426 context.drawText(font, textRun, altTextOffset); 428 } else if (usable Width >= textWidth && usableHeight>= fontMetrics.height())427 } else if (usableSize.width() >= textWidth && usableSize.height() >= fontMetrics.height()) 429 428 context.drawText(font, textRun, altTextOffset); 430 429 } 431 430 } 432 } else if (imageResource().hasImage() && cWidth > 0 && cHeight > 0) { 433 RefPtr<Image> img = imageResource().image(cWidth, cHeight); 434 if (!img || img->isNull()) { 435 if (paintInfo.phase == PaintPhaseForeground) 436 page().addRelevantUnpaintedObject(this, visualOverflowRect()); 437 return; 438 } 439 440 LayoutRect contentBoxRect = this->contentBoxRect(); 441 contentBoxRect.moveBy(paintOffset); 442 LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize()); 443 replacedContentRect.moveBy(paintOffset); 444 bool clip = !contentBoxRect.contains(replacedContentRect); 445 GraphicsContextStateSaver stateSaver(context, clip); 446 if (clip) 447 context.clip(contentBoxRect); 448 449 paintIntoRect(context, snapRectToDevicePixels(replacedContentRect, deviceScaleFactor)); 450 451 if (cachedImage() && paintInfo.phase == PaintPhaseForeground) { 452 // For now, count images as unpainted if they are still progressively loading. We may want 453 // to refine this in the future to account for the portion of the image that has painted. 454 LayoutRect visibleRect = intersection(replacedContentRect, contentBoxRect); 455 if (cachedImage()->isLoading()) 456 page().addRelevantUnpaintedObject(this, visibleRect); 457 else 458 page().addRelevantRepaintedObject(this, visibleRect); 459 } 431 return; 432 } 433 434 if (contentSize.isEmpty()) 435 return; 436 437 RefPtr<Image> img = imageResource().image(flooredIntSize(contentSize)); 438 if (!img || img->isNull()) { 439 if (paintInfo.phase == PaintPhaseForeground) 440 page().addRelevantUnpaintedObject(this, visualOverflowRect()); 441 return; 442 } 443 444 LayoutRect contentBoxRect = this->contentBoxRect(); 445 contentBoxRect.moveBy(paintOffset); 446 LayoutRect replacedContentRect = this->replacedContentRect(intrinsicSize()); 447 replacedContentRect.moveBy(paintOffset); 448 bool clip = !contentBoxRect.contains(replacedContentRect); 449 GraphicsContextStateSaver stateSaver(context, clip); 450 if (clip) 451 context.clip(contentBoxRect); 452 453 paintIntoRect(context, snapRectToDevicePixels(replacedContentRect, deviceScaleFactor)); 454 455 if (cachedImage() && paintInfo.phase == PaintPhaseForeground) { 456 // For now, count images as unpainted if they are still progressively loading. We may want 457 // to refine this in the future to account for the portion of the image that has painted. 458 LayoutRect visibleRect = intersection(replacedContentRect, contentBoxRect); 459 if (cachedImage()->isLoading()) 460 page().addRelevantUnpaintedObject(this, visibleRect); 461 else 462 page().addRelevantRepaintedObject(this, visibleRect); 460 463 } 461 464 } … … 537 540 return; 538 541 539 RefPtr<Image> img = imageResource().image( rect.width(), rect.height());542 RefPtr<Image> img = imageResource().image(flooredIntSize(rect.size())); 540 543 if (!img || img->isNull()) 541 544 return; … … 570 573 if (!imageResource().hasImage() || imageResource().errorOccurred()) 571 574 return false; 572 if ( imageResource().cachedImage() && !imageResource().cachedImage()->isLoaded())575 if (cachedImage() && !cachedImage()->isLoaded()) 573 576 return false; 574 577 if (!contentBoxRect().contains(localRect)) … … 591 594 592 595 // Check for image with alpha. 593 return imageResource().cachedImage() && imageResource().cachedImage()->currentFrameKnownToBeOpaque(this);596 return cachedImage() && cachedImage()->currentFrameKnownToBeOpaque(this); 594 597 } 595 598 … … 742 745 RenderBox* RenderImage::embeddedContentBox() const 743 746 { 744 CachedImage* cachedImage = imageResource().cachedImage();747 CachedImage* cachedImage = this->cachedImage(); 745 748 if (cachedImage && is<SVGImage>(cachedImage->image())) 746 749 return downcast<SVGImage>(*cachedImage->image()).embeddedContentBox(); -
trunk/Source/WebCore/rendering/RenderImageResource.cpp
r208511 r213404 93 93 } 94 94 95 RefPtr<Image> RenderImageResource::image( int, int) const95 RefPtr<Image> RenderImageResource::image(const IntSize&) const 96 96 { 97 97 return m_cachedImage ? m_cachedImage->imageForRenderer(m_renderer) : Image::nullImage(); -
trunk/Source/WebCore/rendering/RenderImageResource.h
r208668 r213404 50 50 void resetAnimation(); 51 51 52 virtual RefPtr<Image> image( int width = 0, int height = 0) const;52 virtual RefPtr<Image> image(const IntSize& size = { }) const; 53 53 virtual bool errorOccurred() const; 54 54 -
trunk/Source/WebCore/rendering/RenderImageResourceStyleImage.cpp
r208511 r213404 64 64 } 65 65 66 RefPtr<Image> RenderImageResourceStyleImage::image( int width, int height) const66 RefPtr<Image> RenderImageResourceStyleImage::image(const IntSize& size) const 67 67 { 68 68 // Generated content may trigger calls to image() while we're still pending, don't assert but gracefully exit. 69 69 if (m_styleImage->isPending()) 70 70 return nullptr; 71 return m_styleImage->image(m_renderer, IntSize(width, height));71 return m_styleImage->image(m_renderer, size); 72 72 } 73 73 -
trunk/Source/WebCore/rendering/RenderImageResourceStyleImage.h
r208668 r213404 44 44 45 45 bool hasImage() const override { return true; } 46 RefPtr<Image> image( int width = 0, int height = 0) const override;46 RefPtr<Image> image(const IntSize& = { }) const override; 47 47 bool errorOccurred() const override { return m_styleImage->errorOccurred(); } 48 48
Note:
See TracChangeset
for help on using the changeset viewer.