Commit dcf6c8f9 authored by akling@apple.com's avatar akling@apple.com

Let RenderImage construct its RenderImageResource.

<https://webkit.org/b/127290>

Everyone who creates a RenderImage immediately follows up with
creating a RenderImageResource and assigning it to the image.

Let the RenderImage constructor do this instead, and make the
imageResource() accessors return references. This exposed a
number of unnecessary null checks.

Also modernized the touched code with std::unique_ptr.

Reviewed by Antti Koivisto.

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::createElementRenderer):
(WebCore::HTMLImageElement::didAttachRenderers):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::createElementRenderer):
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::didAttachRenderers):
(WebCore::HTMLVideoElement::parseAttribute):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::createInputRenderer):
(WebCore::ImageInputType::attach):
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::renderImageResource):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::createFor):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::RenderImage):
(WebCore::RenderImage::~RenderImage):
(WebCore::RenderImage::styleDidChange):
(WebCore::RenderImage::imageChanged):
(WebCore::RenderImage::updateIntrinsicSizeIfNeeded):
(WebCore::RenderImage::updateInnerContentRect):
(WebCore::RenderImage::imageDimensionsChanged):
(WebCore::RenderImage::notifyFinished):
(WebCore::RenderImage::paintReplaced):
(WebCore::RenderImage::paintIntoRect):
(WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect):
(WebCore::RenderImage::minimumReplacedHeight):
(WebCore::RenderImage::computeIntrinsicRatioInformation):
(WebCore::RenderImage::embeddedContentBox):
* rendering/RenderImage.h:
(WebCore::RenderImage::imageResource):
(WebCore::RenderImage::cachedImage):
* rendering/RenderImageResource.h:
* rendering/RenderImageResourceStyleImage.h:
* rendering/RenderMedia.cpp:
(WebCore::RenderMedia::RenderMedia):
* rendering/RenderSnapshottedPlugIn.cpp:
(WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn):
* rendering/RenderSnapshottedPlugIn.h:
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::calculateIntrinsicSize):
* rendering/style/ContentData.cpp:
(WebCore::ImageContentData::createContentRenderer):
* rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::RenderSVGImage):
(WebCore::RenderSVGImage::~RenderSVGImage):
(WebCore::RenderSVGImage::updateImageViewport):
(WebCore::RenderSVGImage::paint):
(WebCore::RenderSVGImage::paintForeground):
* rendering/svg/RenderSVGImage.h:
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::didAttachRenderers):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@162356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 51fde83f
2014-01-20 Andreas Kling <akling@apple.com>
Let RenderImage construct its RenderImageResource.
<https://webkit.org/b/127290>
Everyone who creates a RenderImage immediately follows up with
creating a RenderImageResource and assigning it to the image.
Let the RenderImage constructor do this instead, and make the
imageResource() accessors return references. This exposed a
number of unnecessary null checks.
Also modernized the touched code with std::unique_ptr.
Reviewed by Antti Koivisto.
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::createElementRenderer):
(WebCore::HTMLImageElement::didAttachRenderers):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::createElementRenderer):
* html/HTMLVideoElement.cpp:
(WebCore::HTMLVideoElement::didAttachRenderers):
(WebCore::HTMLVideoElement::parseAttribute):
* html/ImageInputType.cpp:
(WebCore::ImageInputType::createInputRenderer):
(WebCore::ImageInputType::attach):
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::renderImageResource):
* rendering/RenderElement.cpp:
(WebCore::RenderElement::createFor):
* rendering/RenderImage.cpp:
(WebCore::RenderImage::RenderImage):
(WebCore::RenderImage::~RenderImage):
(WebCore::RenderImage::styleDidChange):
(WebCore::RenderImage::imageChanged):
(WebCore::RenderImage::updateIntrinsicSizeIfNeeded):
(WebCore::RenderImage::updateInnerContentRect):
(WebCore::RenderImage::imageDimensionsChanged):
(WebCore::RenderImage::notifyFinished):
(WebCore::RenderImage::paintReplaced):
(WebCore::RenderImage::paintIntoRect):
(WebCore::RenderImage::foregroundIsKnownToBeOpaqueInRect):
(WebCore::RenderImage::minimumReplacedHeight):
(WebCore::RenderImage::computeIntrinsicRatioInformation):
(WebCore::RenderImage::embeddedContentBox):
* rendering/RenderImage.h:
(WebCore::RenderImage::imageResource):
(WebCore::RenderImage::cachedImage):
* rendering/RenderImageResource.h:
* rendering/RenderImageResourceStyleImage.h:
* rendering/RenderMedia.cpp:
(WebCore::RenderMedia::RenderMedia):
* rendering/RenderSnapshottedPlugIn.cpp:
(WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn):
* rendering/RenderSnapshottedPlugIn.h:
* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::calculateIntrinsicSize):
* rendering/style/ContentData.cpp:
(WebCore::ImageContentData::createContentRenderer):
* rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::RenderSVGImage):
(WebCore::RenderSVGImage::~RenderSVGImage):
(WebCore::RenderSVGImage::updateImageViewport):
(WebCore::RenderSVGImage::paint):
(WebCore::RenderSVGImage::paintForeground):
* rendering/svg/RenderSVGImage.h:
* svg/SVGImageElement.cpp:
(WebCore::SVGImageElement::didAttachRenderers):
2014-01-20 Antti Koivisto <antti@apple.com>
Update overlay scrollbars in single pass
......@@ -179,9 +179,7 @@ RenderPtr<RenderElement> HTMLImageElement::createElementRenderer(PassRef<RenderS
if (style.get().hasContent())
return RenderElement::createFor(*this, std::move(style));
auto image = createRenderer<RenderImage>(*this, std::move(style));
image->setImageResource(RenderImageResource::create());
return std::move(image);
return createRenderer<RenderImage>(*this, std::move(style));
}
bool HTMLImageElement::canStartSelection() const
......@@ -199,14 +197,14 @@ void HTMLImageElement::didAttachRenderers()
if (m_imageLoader.hasPendingBeforeLoadEvent())
return;
RenderImage* renderImage = toRenderImage(renderer());
RenderImageResource* renderImageResource = renderImage->imageResource();
if (renderImageResource->hasImage())
RenderImageResource& renderImageResource = renderImage->imageResource();
if (renderImageResource.hasImage())
return;
renderImageResource->setCachedImage(m_imageLoader.image());
renderImageResource.setCachedImage(m_imageLoader.image());
// If we have no image at all because we have no src attribute, set
// image height and width for the alt text instead.
if (!m_imageLoader.image() && !renderImageResource->cachedImage())
if (!m_imageLoader.image() && !renderImageResource.cachedImage())
renderImage->setImageSizeForAltText();
}
......
......@@ -222,11 +222,8 @@ RenderPtr<RenderElement> HTMLPlugInImageElement::createElementRenderer(PassRef<R
if (useFallbackContent())
return RenderElement::createFor(*this, std::move(style));
if (isImageType()) {
auto image = createRenderer<RenderImage>(*this, std::move(style));
image->setImageResource(RenderImageResource::create());
return std::move(image);
}
if (isImageType())
return createRenderer<RenderImage>(*this, std::move(style));
#if PLATFORM(IOS)
if (ShadowRoot* shadowRoot = this->shadowRoot()) {
......
......@@ -89,7 +89,7 @@ void HTMLVideoElement::didAttachRenderers()
m_imageLoader = adoptPtr(new HTMLImageLoader(this));
m_imageLoader->updateFromElement();
if (renderer())
toRenderImage(renderer())->imageResource()->setCachedImage(m_imageLoader->image());
toRenderImage(renderer())->imageResource().setCachedImage(m_imageLoader->image());
}
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
}
......@@ -129,7 +129,7 @@ void HTMLVideoElement::parseAttribute(const QualifiedName& name, const AtomicStr
m_imageLoader->updateFromElementIgnoringPreviousError();
} else {
if (renderer())
toRenderImage(renderer())->imageResource()->setCachedImage(0);
toRenderImage(renderer())->imageResource().setCachedImage(0);
}
}
#if ENABLE(IOS_AIRPLAY)
......
......@@ -103,9 +103,7 @@ void ImageInputType::handleDOMActivateEvent(Event* event)
RenderPtr<RenderElement> ImageInputType::createInputRenderer(PassRef<RenderStyle> style)
{
auto image = createRenderer<RenderImage>(element(), std::move(style));
image->setImageResource(RenderImageResource::create());
return std::move(image);
return createRenderer<RenderImage>(element(), std::move(style));
}
void ImageInputType::altAttributeChanged()
......@@ -137,12 +135,12 @@ void ImageInputType::attach()
if (imageLoader->hasPendingBeforeLoadEvent())
return;
RenderImageResource* imageResource = renderer->imageResource();
imageResource->setCachedImage(imageLoader->image());
auto& imageResource = renderer->imageResource();
imageResource.setCachedImage(imageLoader->image());
// If we have no image at all because we have no src attribute, set
// image height and width for the alt text instead.
if (!imageLoader->image() && !imageResource->cachedImage())
if (!imageLoader->image() && !imageResource.cachedImage())
renderer->setImageSizeForAltText();
}
......
......@@ -326,16 +326,16 @@ RenderImageResource* ImageLoader::renderImageResource()
// We don't return style generated image because it doesn't belong to the ImageLoader.
// See <https://bugs.webkit.org/show_bug.cgi?id=42840>
if (renderer->isImage() && !toRenderImage(*renderer).isGeneratedContent())
return toRenderImage(*renderer).imageResource();
return &toRenderImage(*renderer).imageResource();
#if ENABLE(SVG)
if (renderer->isSVGImage())
return toRenderSVGImage(renderer)->imageResource();
return &toRenderSVGImage(renderer)->imageResource();
#endif
#if ENABLE(VIDEO)
if (renderer->isVideo())
return toRenderVideo(*renderer).imageResource();
return &toRenderVideo(*renderer).imageResource();
#endif
return nullptr;
......
......@@ -131,12 +131,10 @@ RenderPtr<RenderElement> RenderElement::createFor(Element& element, PassRef<Rend
// Otherwise acts as if we didn't support this feature.
const ContentData* contentData = style.get().contentData();
if (contentData && !contentData->next() && contentData->isImage() && !element.isPseudoElement()) {
auto image = createRenderer<RenderImage>(element, std::move(style));
if (const StyleImage* styleImage = static_cast<const ImageContentData*>(contentData)->image()) {
image->setImageResource(RenderImageResourceStyleImage::create(const_cast<StyleImage&>(*styleImage)));
auto styleImage = const_cast<StyleImage*>(static_cast<const ImageContentData*>(contentData)->image());
auto image = createRenderer<RenderImage>(element, std::move(style), styleImage);
if (styleImage)
image->setIsGeneratedContent();
} else
image->setImageResource(RenderImageResource::create());
return std::move(image);
}
......
......@@ -44,6 +44,7 @@
#include "InlineElementBox.h"
#include "Page.h"
#include "PaintInfo.h"
#include "RenderImageResourceStyleImage.h"
#include "RenderView.h"
#include "SVGImage.h"
#include <wtf/StackStats.h>
......@@ -115,27 +116,30 @@ void RenderImage::collectSelectionRects(Vector<SelectionRect>& rects, unsigned,
using namespace HTMLNames;
RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style)
RenderImage::RenderImage(Element& element, PassRef<RenderStyle> style, StyleImage* styleImage)
: RenderReplaced(element, std::move(style), IntSize())
, m_imageResource(styleImage ? std::make_unique<RenderImageResourceStyleImage>(*styleImage) : std::make_unique<RenderImageResource>())
, m_needsToSetSizeForAltText(false)
, m_didIncrementVisuallyNonEmptyPixelCount(false)
, m_isGeneratedContent(false)
{
updateAltText();
imageResource().initialize(this);
}
RenderImage::RenderImage(Document& document, PassRef<RenderStyle> style)
RenderImage::RenderImage(Document& document, PassRef<RenderStyle> style, StyleImage* styleImage)
: RenderReplaced(document, std::move(style), IntSize())
, m_imageResource(styleImage ? std::make_unique<RenderImageResourceStyleImage>(*styleImage) : std::make_unique<RenderImageResource>())
, m_needsToSetSizeForAltText(false)
, m_didIncrementVisuallyNonEmptyPixelCount(false)
, m_isGeneratedContent(false)
{
imageResource().initialize(this);
}
RenderImage::~RenderImage()
{
ASSERT(m_imageResource);
m_imageResource->shutdown();
imageResource().shutdown();
}
PassRef<RenderStyle> RenderImage::createStyleInheritingFromPseudoStyle(const RenderStyle& pseudoStyle)
......@@ -150,13 +154,6 @@ PassRef<RenderStyle> RenderImage::createStyleInheritingFromPseudoStyle(const Ren
return style;
}
void RenderImage::setImageResource(PassOwnPtr<RenderImageResource> imageResource)
{
ASSERT(!m_imageResource);
m_imageResource = imageResource;
m_imageResource->initialize(this);
}
// If we'll be displaying either alt text or an image, add some padding.
static const unsigned short paddingWidth = 4;
static const unsigned short paddingHeight = 4;
......@@ -217,7 +214,7 @@ void RenderImage::styleDidChange(StyleDifference diff, const RenderStyle* oldSty
{
RenderReplaced::styleDidChange(diff, oldStyle);
if (m_needsToSetSizeForAltText) {
if (!m_altText.isEmpty() && setImageSizeForAltText(m_imageResource->cachedImage()))
if (!m_altText.isEmpty() && setImageSizeForAltText(imageResource().cachedImage()))
imageDimensionsChanged(true /* imageSizeChanged */);
m_needsToSetSizeForAltText = false;
}
......@@ -246,22 +243,19 @@ void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
if (hasBoxDecorations() || hasMask())
RenderReplaced::imageChanged(newImage, rect);
if (!m_imageResource)
return;
if (newImage != m_imageResource->imagePtr() || !newImage)
if (newImage != imageResource().imagePtr() || !newImage)
return;
if (!m_didIncrementVisuallyNonEmptyPixelCount) {
// At a zoom level of 1 the image is guaranteed to have an integer size.
view().frameView().incrementVisuallyNonEmptyPixelCount(flooredIntSize(m_imageResource->imageSize(1.0f)));
view().frameView().incrementVisuallyNonEmptyPixelCount(flooredIntSize(imageResource().imageSize(1.0f)));
m_didIncrementVisuallyNonEmptyPixelCount = true;
}
bool imageSizeChanged = false;
// Set image dimensions, taking into account the size of the alt text.
if (m_imageResource->errorOccurred()) {
if (imageResource().errorOccurred()) {
if (!m_altText.isEmpty() && document().hasPendingStyleRecalc()) {
ASSERT(element());
if (element()) {
......@@ -270,7 +264,7 @@ void RenderImage::imageChanged(WrappedImagePtr newImage, const IntRect* rect)
}
return;
}
imageSizeChanged = setImageSizeForAltText(m_imageResource->cachedImage());
imageSizeChanged = setImageSizeForAltText(imageResource().cachedImage());
}
imageDimensionsChanged(imageSizeChanged, rect);
......@@ -280,7 +274,7 @@ bool RenderImage::updateIntrinsicSizeIfNeeded(const LayoutSize& newSize, bool im
{
if (newSize == intrinsicSize() && !imageSizeChanged)
return false;
if (m_imageResource->errorOccurred())
if (imageResource().errorOccurred())
return imageSizeChanged;
setIntrinsicSize(newSize);
return true;
......@@ -292,7 +286,7 @@ void RenderImage::updateInnerContentRect()
LayoutRect paintRect = replacedContentRect(intrinsicSize());
IntSize containerSize(paintRect.width(), paintRect.height());
if (!containerSize.isEmpty())
m_imageResource->setContainerSizeForRenderer(containerSize);
imageResource().setContainerSizeForRenderer(containerSize);
}
void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* rect)
......@@ -303,9 +297,9 @@ void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* r
scale = roundForImpreciseConversion<int>(scale);
if (scale <= 0)
scale = 1;
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(m_imageResource->intrinsicSize(style().effectiveZoom() / scale), imageSizeChanged);
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(imageResource().intrinsicSize(style().effectiveZoom() / scale), imageSizeChanged);
#else
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(m_imageResource->intrinsicSize(style().effectiveZoom()), imageSizeChanged);
bool intrinsicSizeChanged = updateIntrinsicSizeIfNeeded(imageResource().intrinsicSize(style().effectiveZoom()), imageSizeChanged);
#endif
// In the case of generated image content using :before/:after/content, we might not be
......@@ -362,7 +356,7 @@ void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* r
if (rect) {
// The image changed rect is in source image coordinates (pre-zooming),
// so map from the bounds of the image to the contentsBox.
repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), m_imageResource->imageSize(1.0f)), contentBoxRect()));
repaintRect = enclosingIntRect(mapRect(*rect, FloatRect(FloatPoint(), imageResource().imageSize(1.0f)), contentBoxRect()));
// Guard against too-large changed rects.
repaintRect.intersect(contentBoxRect());
} else
......@@ -379,16 +373,13 @@ void RenderImage::imageDimensionsChanged(bool imageSizeChanged, const IntRect* r
void RenderImage::notifyFinished(CachedResource* newImage)
{
if (!m_imageResource)
return;
if (documentBeingDestroyed())
return;
invalidateBackgroundObscurationStatus();
#if USE(ACCELERATED_COMPOSITING)
if (newImage == m_imageResource->cachedImage()) {
if (newImage == imageResource().cachedImage()) {
// tell any potential compositing layers
// that the image is done and they can reference it directly.
contentChanged(ImageChanged);
......@@ -411,7 +402,7 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
Page* page = frame().page();
if (!m_imageResource->hasImage() || m_imageResource->errorOccurred()) {
if (!imageResource().hasImage() || imageResource().errorOccurred()) {
if (paintInfo.phase == PaintPhaseSelection)
return;
......@@ -434,12 +425,12 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
LayoutUnit usableWidth = cWidth - 2 * borderWidth;
LayoutUnit usableHeight = cHeight - 2 * borderWidth;
RefPtr<Image> image = m_imageResource->image();
RefPtr<Image> image = imageResource().image();
if (m_imageResource->errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
if (imageResource().errorOccurred() && !image->isNull() && usableWidth >= image->width() && usableHeight >= image->height()) {
float deviceScaleFactor = WebCore::deviceScaleFactor(&frame());
// Call brokenImage() explicitly to ensure we get the broken image icon at the appropriate resolution.
std::pair<Image*, float> brokenImageAndImageScaleFactor = m_imageResource->cachedImage()->brokenImage(deviceScaleFactor);
std::pair<Image*, float> brokenImageAndImageScaleFactor = imageResource().cachedImage()->brokenImage(deviceScaleFactor);
image = brokenImageAndImageScaleFactor.first;
IntSize imageSize = image->size();
imageSize.scale(1 / brokenImageAndImageScaleFactor.second);
......@@ -480,8 +471,8 @@ void RenderImage::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOf
context->drawText(font, textRun, altTextOffset);
}
}
} else if (m_imageResource->hasImage() && cWidth > 0 && cHeight > 0) {
RefPtr<Image> img = m_imageResource->image(cWidth, cHeight);
} else if (imageResource().hasImage() && cWidth > 0 && cHeight > 0) {
RefPtr<Image> img = imageResource().image(cWidth, cHeight);
if (!img || img->isNull()) {
if (page && paintInfo.phase == PaintPhaseForeground)
page->addRelevantUnpaintedObject(this, visualOverflowRect());
......@@ -576,22 +567,22 @@ void RenderImage::areaElementFocusChanged(HTMLAreaElement* element)
void RenderImage::paintIntoRect(GraphicsContext* context, const LayoutRect& rect)
{
IntRect alignedRect = pixelSnappedIntRect(rect);
if (!m_imageResource->hasImage() || m_imageResource->errorOccurred() || alignedRect.width() <= 0 || alignedRect.height() <= 0)
if (!imageResource().hasImage() || imageResource().errorOccurred() || alignedRect.width() <= 0 || alignedRect.height() <= 0)
return;
RefPtr<Image> img = m_imageResource->image(alignedRect.width(), alignedRect.height());
RefPtr<Image> img = imageResource().image(alignedRect.width(), alignedRect.height());
if (!img || img->isNull())
return;
HTMLImageElement* imageElt = (element() && isHTMLImageElement(element())) ? toHTMLImageElement(element()) : 0;
CompositeOperator compositeOperator = imageElt ? imageElt->compositeOperator() : CompositeSourceOver;
Image* image = m_imageResource->image().get();
Image* image = imageResource().image().get();
bool useLowQualityScaling = shouldPaintAtLowQuality(context, image, image, alignedRect.size());
ImageOrientationDescription orientationDescription(shouldRespectImageOrientation());
#if ENABLE(CSS_IMAGE_ORIENTATION)
orientationDescription.setImageOrientationEnum(style().imageOrientation());
#endif
context->drawImage(m_imageResource->image(alignedRect.width(), alignedRect.height()).get(), style().colorSpace(), alignedRect, compositeOperator, orientationDescription, useLowQualityScaling);
context->drawImage(imageResource().image(alignedRect.width(), alignedRect.height()).get(), style().colorSpace(), alignedRect, compositeOperator, orientationDescription, useLowQualityScaling);
}
bool RenderImage::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance bleedAvoidance, InlineFlowBox*) const
......@@ -605,9 +596,9 @@ bool RenderImage::boxShadowShouldBeAppliedToBackground(BackgroundBleedAvoidance
bool RenderImage::foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect, unsigned maxDepthToTest) const
{
UNUSED_PARAM(maxDepthToTest);
if (!m_imageResource->hasImage() || m_imageResource->errorOccurred())
if (!imageResource().hasImage() || imageResource().errorOccurred())
return false;
if (m_imageResource->cachedImage() && !m_imageResource->cachedImage()->isLoaded())
if (imageResource().cachedImage() && !imageResource().cachedImage()->isLoaded())
return false;
if (!contentBoxRect().contains(localRect))
return false;
......@@ -623,7 +614,7 @@ bool RenderImage::foregroundIsKnownToBeOpaqueInRect(const LayoutRect& localRect,
if (objectFit != ObjectFitFill && objectFit != ObjectFitCover)
return false;
// Check for image with alpha.
return m_imageResource->cachedImage() && m_imageResource->cachedImage()->currentFrameKnownToBeOpaque(this);
return imageResource().cachedImage() && imageResource().cachedImage()->currentFrameKnownToBeOpaque(this);
}
bool RenderImage::computeBackgroundIsKnownToBeObscured()
......@@ -639,7 +630,7 @@ bool RenderImage::computeBackgroundIsKnownToBeObscured()
LayoutUnit RenderImage::minimumReplacedHeight() const
{
return m_imageResource->errorOccurred() ? intrinsicSize().height() : LayoutUnit();
return imageResource().errorOccurred() ? intrinsicSize().height() : LayoutUnit();
}
HTMLMapElement* RenderImage::imageMap() const
......@@ -695,7 +686,7 @@ void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou
RenderReplaced::computeIntrinsicRatioInformation(intrinsicSize, intrinsicRatio, isPercentageIntrinsicSize);
// Our intrinsicSize is empty if we're rendering generated images with relative width/height. Figure out the right intrinsic size to use.
if (intrinsicSize.isEmpty() && (m_imageResource->imageHasRelativeWidth() || m_imageResource->imageHasRelativeHeight())) {
if (intrinsicSize.isEmpty() && (imageResource().imageHasRelativeWidth() || imageResource().imageHasRelativeHeight())) {
RenderObject* containingBlock = isOutOfFlowPositioned() ? container() : this->containingBlock();
if (containingBlock->isBox()) {
RenderBox* box = toRenderBox(containingBlock);
......@@ -704,7 +695,7 @@ void RenderImage::computeIntrinsicRatioInformation(FloatSize& intrinsicSize, dou
}
}
// Don't compute an intrinsic ratio to preserve historical WebKit behavior if we're painting alt text and/or a broken image.
if (m_imageResource && m_imageResource->errorOccurred()) {
if (imageResource().errorOccurred()) {
intrinsicRatio = 1;
return;
}
......@@ -719,11 +710,8 @@ bool RenderImage::needsPreferredWidthsRecalculation() const
RenderBox* RenderImage::embeddedContentBox() const
{
if (!m_imageResource)
return 0;
#if ENABLE(SVG)
CachedImage* cachedImage = m_imageResource->cachedImage();
CachedImage* cachedImage = imageResource().cachedImage();
if (cachedImage && cachedImage->image() && cachedImage->image()->isSVGImage())
return static_cast<SVGImage*>(cachedImage->image())->embeddedContentBox();
#endif
......
......@@ -35,18 +35,16 @@ class HTMLMapElement;
class RenderImage : public RenderReplaced {
public:
explicit RenderImage(Element&, PassRef<RenderStyle>);
explicit RenderImage(Document&, PassRef<RenderStyle>);
RenderImage(Element&, PassRef<RenderStyle>, StyleImage* = nullptr);
RenderImage(Document&, PassRef<RenderStyle>, StyleImage* = nullptr);
virtual ~RenderImage();
// Create a RenderStyle for generated content by inheriting from a pseudo style.
static PassRef<RenderStyle> createStyleInheritingFromPseudoStyle(const RenderStyle&);
void setImageResource(PassOwnPtr<RenderImageResource>);
RenderImageResource* imageResource() { return m_imageResource.get(); }
const RenderImageResource* imageResource() const { return m_imageResource.get(); }
CachedImage* cachedImage() const { return m_imageResource ? m_imageResource->cachedImage() : 0; }
RenderImageResource& imageResource() { return *m_imageResource; }
const RenderImageResource& imageResource() const { return *m_imageResource; }
CachedImage* cachedImage() const { return imageResource().cachedImage(); }
bool setImageSizeForAltText(CachedImage* newImage = 0);
......@@ -84,8 +82,7 @@ protected:
virtual void intrinsicSizeChanged() override
{
if (m_imageResource)
imageChanged(m_imageResource->imagePtr());
imageChanged(imageResource().imagePtr());
}
private:
......@@ -115,7 +112,7 @@ private:
// Text to display as long as the image isn't available.
String m_altText;
OwnPtr<RenderImageResource> m_imageResource;
std::unique_ptr<RenderImageResource> m_imageResource;
bool m_needsToSetSizeForAltText;
bool m_didIncrementVisuallyNonEmptyPixelCount;
bool m_isGeneratedContent;
......
......@@ -38,13 +38,9 @@ class RenderElement;
class RenderImageResource {
WTF_MAKE_NONCOPYABLE(RenderImageResource); WTF_MAKE_FAST_ALLOCATED;
public:
RenderImageResource();
virtual ~RenderImageResource();
static PassOwnPtr<RenderImageResource> create()
{
return adoptPtr(new RenderImageResource);
}
virtual void initialize(RenderElement*);
virtual void shutdown();
......@@ -67,8 +63,6 @@ public:
virtual WrappedImagePtr imagePtr() const { return m_cachedImage.get(); }
protected:
RenderImageResource();
RenderElement* m_renderer;
CachedResourceHandle<CachedImage> m_cachedImage;
};
......
......@@ -34,15 +34,11 @@ namespace WebCore {
class RenderElement;
class RenderImageResourceStyleImage : public RenderImageResource {
class RenderImageResourceStyleImage final : public RenderImageResource {
public:
explicit RenderImageResourceStyleImage(StyleImage&);
virtual ~RenderImageResourceStyleImage();
static PassOwnPtr<RenderImageResource> create(StyleImage& styleImage)
{
return adoptPtr(new RenderImageResourceStyleImage(styleImage));
}
private:
virtual void initialize(RenderElement*) override;
virtual void shutdown() override;
......@@ -60,7 +56,6 @@ private:
virtual WrappedImagePtr imagePtr() const override { return m_styleImage->data(); }
explicit RenderImageResourceStyleImage(StyleImage&);
Ref<StyleImage> m_styleImage;
};
......
......@@ -37,13 +37,11 @@ namespace WebCore {
RenderMedia::RenderMedia(HTMLMediaElement& element, PassRef<RenderStyle> style)
: RenderImage(element, std::move(style))
{
setImageResource(RenderImageResource::create());
}
RenderMedia::RenderMedia(HTMLMediaElement& element, PassRef<RenderStyle> style, const IntSize& intrinsicSize)
: RenderImage(element, std::move(style))
{
setImageResource(RenderImageResource::create());
setIntrinsicSize(intrinsicSize);
}
......
......@@ -48,7 +48,7 @@ namespace WebCore {
RenderSnapshottedPlugIn::RenderSnapshottedPlugIn(HTMLPlugInImageElement& element, PassRef<RenderStyle> style)
: RenderEmbeddedObject(element, std::move(style))
, m_snapshotResource(RenderImageResource::create())
, m_snapshotResource(std::make_unique<RenderImageResource>())
, m_isPotentialMouseActivation(false)
{
m_snapshotResource->initialize(this);
......
......@@ -59,7 +59,7 @@ private:
virtual void layout() override;
OwnPtr<RenderImageResource> m_snapshotResource;
std::unique_ptr<RenderImageResource> m_snapshotResource;
bool m_isPotentialMouseActivation;
};
......
......@@ -113,7 +113,7 @@ LayoutSize RenderVideo::calculateIntrinsicSize()
return size;
}
if (videoElement().shouldDisplayPosterImage() && !m_cachedImageSize.isEmpty() && !imageResource()->errorOccurred())
if (videoElement().shouldDisplayPosterImage() && !m_cachedImageSize.isEmpty() && !imageResource().errorOccurred())
return m_cachedImageSize;
// <video> in standalone media documents should not use the default 300x150
......