Image* CSSCrossfadeValue::image(RenderElement& renderer, const FloatSize& size) { if (size.isEmpty()) return nullptr; // FIXME: Skip Content Security Policy check when cross fade is applied to an element in a user agent shadow tree. // See <https://bugs.webkit.org/show_bug.cgi?id=146663>. auto options = CachedResourceLoader::defaultCachedResourceOptions(); auto& cachedResourceLoader = renderer.document().cachedResourceLoader(); auto* cachedFromImage = cachedImageForCSSValue(m_fromValue, cachedResourceLoader, options); auto* cachedToImage = cachedImageForCSSValue(m_toValue, cachedResourceLoader, options); if (!cachedFromImage || !cachedToImage) return Image::nullImage(); auto* fromImage = cachedFromImage->imageForRenderer(&renderer); auto* toImage = cachedToImage->imageForRenderer(&renderer); if (!fromImage || !toImage) return Image::nullImage(); m_generatedImage = CrossfadeGeneratedImage::create(*fromImage, *toImage, m_percentageValue->floatValue(), fixedSize(renderer), size); return m_generatedImage.get(); }
FloatSize CSSCrossfadeValue::fixedSize(const RenderElement& renderer) { float percentage = m_percentageValue->floatValue(); float inversePercentage = 1 - percentage; // FIXME: Skip Content Security Policy check when cross fade is applied to an element in a user agent shadow tree. // See <https://bugs.webkit.org/show_bug.cgi?id=146663>. auto options = CachedResourceLoader::defaultCachedResourceOptions(); auto& cachedResourceLoader = renderer.document().cachedResourceLoader(); auto* cachedFromImage = cachedImageForCSSValue(m_fromValue, cachedResourceLoader, options); auto* cachedToImage = cachedImageForCSSValue(m_toValue, cachedResourceLoader, options); if (!cachedFromImage || !cachedToImage) return FloatSize(); FloatSize fromImageSize = cachedFromImage->imageForRenderer(&renderer)->size(); FloatSize toImageSize = cachedToImage->imageForRenderer(&renderer)->size(); // Rounding issues can cause transitions between images of equal size to return // a different fixed size; avoid performing the interpolation if the images are the same size. if (fromImageSize == toImageSize) return fromImageSize; return fromImageSize * inversePercentage + toImageSize * percentage; }
void CSSCrossfadeValue::loadSubimages(CachedResourceLoader* cachedResourceLoader) { m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader); if (m_cachedFromImage) m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addClient(&m_crossfadeSubimageObserver); m_crossfadeSubimageObserver.setReady(true); }
PassRefPtr<Image> CSSFilterImageValue::image(RenderObject* renderer, const IntSize& size) { if (size.isEmpty()) return 0; CachedResourceLoader* cachedResourceLoader = renderer->document()->cachedResourceLoader(); CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader); if (!cachedImage) return Image::nullImage(); Image* image = cachedImage->imageForRenderer(renderer); if (!image) return Image::nullImage(); // Transform Image into ImageBuffer. OwnPtr<ImageBuffer> texture = ImageBuffer::create(size); if (!texture) return Image::nullImage(); texture->context()->drawImage(image, ColorSpaceDeviceRGB, IntPoint()); RefPtr<FilterEffectRenderer> filterRenderer = FilterEffectRenderer::create(); filterRenderer->setSourceImage(texture.release()); filterRenderer->setSourceImageRect(FloatRect(FloatPoint(), size)); filterRenderer->setFilterRegion(FloatRect(FloatPoint(), size)); // FIXME: SVG Filter don't work at the moment. if (!filterRenderer->build(0, m_filterOperations, true)) return Image::nullImage(); filterRenderer->apply(); m_generatedImage = filterRenderer->output()->copyImage(); return m_generatedImage.release(); }
IntSize CSSFilterImageValue::fixedSize(const RenderObject* renderer) { CachedResourceLoader* cachedResourceLoader = renderer->document()->cachedResourceLoader(); CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader); if (!cachedImage) return IntSize(); return cachedImage->imageForRenderer(renderer)->size(); }
static Image* renderableImageForCSSValue(CSSValue* value, const LayoutObject& layoutObject) { ImageResourceContent* cachedImage = cachedImageForCSSValue(value, layoutObject.document()); if (!cachedImage || cachedImage->errorOccurred() || cachedImage->getImage()->isNull()) return nullptr; return cachedImage->getImage(); }
PassRefPtr<Image> CSSCrossfadeValue::image(RenderObject* renderer, const IntSize& size) { if (size.isEmpty()) return 0; CachedResourceLoader* cachedResourceLoader = renderer->document()->cachedResourceLoader(); CachedImage* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader); CachedImage* cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader); if (!cachedFromImage || !cachedToImage) return Image::nullImage(); Image* fromImage = cachedFromImage->imageForRenderer(renderer); Image* toImage = cachedToImage->imageForRenderer(renderer); if (!fromImage || !toImage) return Image::nullImage(); m_generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_percentageValue->getFloatValue(), fixedSize(renderer), size); return m_generatedImage.release(); }
PassRefPtr<Image> CSSCrossfadeValue::image(LayoutObject* renderer, const IntSize& size) { if (size.isEmpty()) return nullptr; Document* document = &renderer->document(); ImageResource* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document); ImageResource* cachedToImage = cachedImageForCSSValue(m_toValue.get(), document); if (!cachedFromImage || !cachedToImage) return Image::nullImage(); Image* fromImage = cachedFromImage->imageForLayoutObject(renderer); Image* toImage = cachedToImage->imageForLayoutObject(renderer); if (!fromImage || !toImage) return Image::nullImage(); m_generatedImage = CrossfadeGeneratedImage::create(fromImage, toImage, m_percentageValue->getFloatValue(), fixedSize(renderer), size); return m_generatedImage.release(); }
void CSSCrossfadeValue::loadSubimages(const Document& document) { ImageResourceContent* oldCachedFromImage = m_cachedFromImage; ImageResourceContent* oldCachedToImage = m_cachedToImage; m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), document); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), document); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeObserver(&m_crossfadeSubimageObserver); if (m_cachedFromImage) m_cachedFromImage->addObserver(&m_crossfadeSubimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeObserver(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addObserver(&m_crossfadeSubimageObserver); } m_crossfadeSubimageObserver.setReady(true); }
IntSize CSSCrossfadeValue::fixedSize(const RenderObject* renderer) { float percentage = m_percentageValue->getFloatValue(); float inversePercentage = 1 - percentage; CachedResourceLoader* cachedResourceLoader = renderer->document()->cachedResourceLoader(); CachedImage* cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader); CachedImage* cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader); if (!cachedFromImage || !cachedToImage) return IntSize(); IntSize fromImageSize = cachedFromImage->imageForRenderer(renderer)->size(); IntSize toImageSize = cachedToImage->imageForRenderer(renderer)->size(); // Rounding issues can cause transitions between images of equal size to return // a different fixed size; avoid performing the interpolation if the images are the same size. if (fromImageSize == toImageSize) return fromImageSize; return IntSize(fromImageSize.width() * inversePercentage + toImageSize.width() * percentage, fromImageSize.height() * inversePercentage + toImageSize.height() * percentage); }
FloatSize CSSFilterImageValue::fixedSize(const RenderElement* renderer) { // FIXME: Skip Content Security Policy check when filter is applied to an element in a user agent shadow tree. // See <https://bugs.webkit.org/show_bug.cgi?id=146663>. ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader(); CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader, options); if (!cachedImage) return FloatSize(); return cachedImage->imageForRenderer(renderer)->size(); }
void CSSCrossfadeValue::loadSubimages(CachedResourceLoader* cachedResourceLoader) { CachedResourceHandle<CachedImage> oldCachedFromImage = m_cachedFromImage; CachedResourceHandle<CachedImage> oldCachedToImage = m_cachedToImage; m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), cachedResourceLoader); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), cachedResourceLoader); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedFromImage) m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addClient(&m_crossfadeSubimageObserver); } m_crossfadeSubimageObserver.setReady(true); }
void CSSCrossfadeValue::loadSubimages(ResourceFetcher* fetcher) { ResourcePtr<ImageResource> oldCachedFromImage = m_cachedFromImage; ResourcePtr<ImageResource> oldCachedToImage = m_cachedToImage; m_cachedFromImage = cachedImageForCSSValue(m_fromValue.get(), fetcher); m_cachedToImage = cachedImageForCSSValue(m_toValue.get(), fetcher); if (m_cachedFromImage != oldCachedFromImage) { if (oldCachedFromImage) oldCachedFromImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedFromImage) m_cachedFromImage->addClient(&m_crossfadeSubimageObserver); } if (m_cachedToImage != oldCachedToImage) { if (oldCachedToImage) oldCachedToImage->removeClient(&m_crossfadeSubimageObserver); if (m_cachedToImage) m_cachedToImage->addClient(&m_crossfadeSubimageObserver); } m_crossfadeSubimageObserver.setReady(true); }
RefPtr<Image> CSSFilterImageValue::image(RenderElement* renderer, const FloatSize& size) { if (size.isEmpty()) return nullptr; // FIXME: Skip Content Security Policy check when filter is applied to an element in a user agent shadow tree. // See <https://bugs.webkit.org/show_bug.cgi?id=146663>. ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions(); CachedResourceLoader& cachedResourceLoader = renderer->document().cachedResourceLoader(); CachedImage* cachedImage = cachedImageForCSSValue(m_imageValue.get(), cachedResourceLoader, options); if (!cachedImage) return Image::nullImage(); Image* image = cachedImage->imageForRenderer(renderer); if (!image) return Image::nullImage(); // Transform Image into ImageBuffer. std::unique_ptr<ImageBuffer> texture = ImageBuffer::create(size); if (!texture) return Image::nullImage(); FloatRect imageRect = FloatRect(FloatPoint(), size); texture->context().drawImage(image, ColorSpaceDeviceRGB, imageRect); RefPtr<FilterEffectRenderer> filterRenderer = FilterEffectRenderer::create(); filterRenderer->setSourceImage(WTF::move(texture)); filterRenderer->setSourceImageRect(imageRect); filterRenderer->setFilterRegion(imageRect); if (!filterRenderer->build(renderer, m_filterOperations, FilterFunction)) return Image::nullImage(); filterRenderer->apply(); m_generatedImage = filterRenderer->output()->copyImage(); return m_generatedImage.release(); }