2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-03-13 06:46:04 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2018-01-25 09:55:18 +03:00
|
|
|
/* utility code for drawing images as CSS borders, backgrounds, and shapes. */
|
2017-03-13 06:46:04 +03:00
|
|
|
|
2017-04-04 18:38:20 +03:00
|
|
|
#include "nsImageRenderer.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
|
2017-03-21 02:31:39 +03:00
|
|
|
#include "mozilla/webrender/WebRenderAPI.h"
|
2017-03-13 06:46:04 +03:00
|
|
|
|
2017-06-09 22:14:53 +03:00
|
|
|
#include "gfxContext.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
#include "gfxDrawable.h"
|
|
|
|
#include "ImageOps.h"
|
2018-01-25 09:55:18 +03:00
|
|
|
#include "ImageRegion.h"
|
2017-05-03 15:48:08 +03:00
|
|
|
#include "mozilla/layers/StackingContextHelper.h"
|
2017-09-25 10:48:29 +03:00
|
|
|
#include "mozilla/layers/WebRenderLayerManager.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsCSSRendering.h"
|
2017-04-04 18:38:20 +03:00
|
|
|
#include "nsCSSRenderingGradients.h"
|
2018-01-25 09:55:18 +03:00
|
|
|
#include "nsDeviceContext.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
#include "nsIFrame.h"
|
2017-04-04 18:38:20 +03:00
|
|
|
#include "nsStyleStructInlines.h"
|
2017-06-06 19:04:37 +03:00
|
|
|
#include "nsSVGDisplayableFrame.h"
|
2017-08-30 16:14:46 +03:00
|
|
|
#include "SVGObserverUtils.h"
|
2017-03-31 00:50:47 +03:00
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::image;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
nsSize CSSSizeOrRatio::ComputeConcreteSize() const {
|
|
|
|
NS_ASSERTION(CanComputeConcreteSize(), "Cannot compute");
|
|
|
|
if (mHasWidth && mHasHeight) {
|
|
|
|
return nsSize(mWidth, mHeight);
|
|
|
|
}
|
|
|
|
if (mHasWidth) {
|
|
|
|
nscoord height = NSCoordSaturatingNonnegativeMultiply(
|
2018-09-04 23:46:21 +03:00
|
|
|
mWidth, double(mRatio.height) / mRatio.width);
|
2017-03-13 06:46:04 +03:00
|
|
|
return nsSize(mWidth, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mHasHeight);
|
|
|
|
nscoord width = NSCoordSaturatingNonnegativeMultiply(
|
2018-09-04 23:46:21 +03:00
|
|
|
mHeight, double(mRatio.width) / mRatio.height);
|
2017-03-13 06:46:04 +03:00
|
|
|
return nsSize(width, mHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsImageRenderer::nsImageRenderer(nsIFrame* aForFrame,
|
|
|
|
const nsStyleImage* aImage, uint32_t aFlags)
|
|
|
|
: mForFrame(aForFrame),
|
|
|
|
mImage(aImage),
|
|
|
|
mType(aImage->GetType()),
|
|
|
|
mImageContainer(nullptr),
|
|
|
|
mGradientData(nullptr),
|
|
|
|
mPaintServerFrame(nullptr),
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult(ImgDrawResult::NOT_READY),
|
2017-03-13 06:46:04 +03:00
|
|
|
mSize(0, 0),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mExtendMode(ExtendMode::CLAMP),
|
|
|
|
mMaskOp(NS_STYLE_MASK_MODE_MATCH_SOURCE) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
static bool ShouldTreatAsCompleteDueToSyncDecode(const nsStyleImage* aImage,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
if (!(aFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aImage->GetType() != eStyleImageType_Image) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
imgRequestProxy* req = aImage->GetImageData();
|
|
|
|
if (!req) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t status = 0;
|
|
|
|
if (NS_FAILED(req->GetImageStatus(&status))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & imgIRequest::STATUS_ERROR) {
|
|
|
|
// The image is "complete" since it's a corrupt image. If we created an
|
|
|
|
// imgIContainer at all, return true.
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
req->GetImage(getter_AddRefs(image));
|
|
|
|
return bool(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(status & imgIRequest::STATUS_LOAD_COMPLETE)) {
|
|
|
|
// We must have loaded all of the image's data and the size must be
|
|
|
|
// available, or else sync decoding won't be able to decode the image.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsImageRenderer::PrepareImage() {
|
|
|
|
if (mImage->IsEmpty()) {
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::BAD_IMAGE;
|
2017-03-13 06:46:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mImage->IsComplete()) {
|
|
|
|
// Make sure the image is actually decoding.
|
|
|
|
bool frameComplete = mImage->StartDecoding();
|
|
|
|
|
|
|
|
// Check again to see if we finished.
|
|
|
|
// We cannot prepare the image for rendering if it is not fully loaded.
|
2018-09-04 23:46:21 +03:00
|
|
|
// Special case: If we requested a sync decode and the image has loaded,
|
|
|
|
// push on through because the Draw() will do a sync decode then.
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!(frameComplete || mImage->IsComplete()) &&
|
|
|
|
!ShouldTreatAsCompleteDueToSyncDecode(mImage, mFlags)) {
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::NOT_READY;
|
2017-03-13 06:46:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case eStyleImageType_Image: {
|
|
|
|
MOZ_ASSERT(mImage->GetImageData(),
|
|
|
|
"must have image data, since we checked IsEmpty above");
|
|
|
|
nsCOMPtr<imgIContainer> srcImage;
|
|
|
|
DebugOnly<nsresult> rv =
|
|
|
|
mImage->GetImageData()->GetImage(getter_AddRefs(srcImage));
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv) && srcImage,
|
|
|
|
"If GetImage() is failing, mImage->IsComplete() "
|
|
|
|
"should have returned false");
|
|
|
|
|
|
|
|
if (!mImage->GetCropRect()) {
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
} else {
|
|
|
|
nsIntRect actualCropRect;
|
|
|
|
bool isEntireImage;
|
|
|
|
bool success =
|
|
|
|
mImage->ComputeActualCropRect(actualCropRect, &isEntireImage);
|
|
|
|
if (!success || actualCropRect.IsEmpty()) {
|
|
|
|
// The cropped image has zero size
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::BAD_IMAGE;
|
2017-03-13 06:46:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isEntireImage) {
|
|
|
|
// The cropped image is identical to the source image
|
|
|
|
mImageContainer.swap(srcImage);
|
|
|
|
} else {
|
2018-09-04 23:46:21 +03:00
|
|
|
nsCOMPtr<imgIContainer> subImage =
|
|
|
|
ImageOps::Clip(srcImage, actualCropRect, Nothing());
|
2017-03-13 06:46:04 +03:00
|
|
|
mImageContainer.swap(subImage);
|
|
|
|
}
|
|
|
|
}
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleImageType_Gradient:
|
|
|
|
mGradientData = mImage->GetGradientData();
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Element: {
|
2018-09-20 15:50:23 +03:00
|
|
|
Element* paintElement = // may be null
|
|
|
|
SVGObserverUtils::GetAndObserveBackgroundImage(
|
|
|
|
mForFrame->FirstContinuation(), mImage->GetElementId());
|
2017-03-13 06:46:04 +03:00
|
|
|
// If the referenced element is an <img>, <canvas>, or <video> element,
|
|
|
|
// prefer SurfaceFromElement as it's more reliable.
|
2018-09-20 15:50:23 +03:00
|
|
|
mImageElementSurface = nsLayoutUtils::SurfaceFromElement(paintElement);
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!mImageElementSurface.GetSourceSurface()) {
|
2018-09-20 15:50:23 +03:00
|
|
|
nsIFrame* paintServerFrame =
|
|
|
|
paintElement ? paintElement->GetPrimaryFrame() : nullptr;
|
2017-06-06 19:04:37 +03:00
|
|
|
// If there's no referenced frame, or the referenced frame is
|
|
|
|
// non-displayable SVG, then we have nothing valid to paint.
|
|
|
|
if (!paintServerFrame ||
|
|
|
|
(paintServerFrame->IsFrameOfType(nsIFrame::eSVG) &&
|
|
|
|
!paintServerFrame->IsFrameOfType(nsIFrame::eSVGPaintServer) &&
|
2018-09-04 23:46:21 +03:00
|
|
|
!static_cast<nsSVGDisplayableFrame*>(
|
|
|
|
do_QueryFrame(paintServerFrame)))) {
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::BAD_IMAGE;
|
2017-03-13 06:46:04 +03:00
|
|
|
return false;
|
|
|
|
}
|
2017-06-06 19:04:37 +03:00
|
|
|
mPaintServerFrame = paintServerFrame;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
mPrepareResult = ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IsReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSSizeOrRatio nsImageRenderer::ComputeIntrinsicSize() {
|
2018-09-04 23:46:21 +03:00
|
|
|
NS_ASSERTION(IsReady(),
|
|
|
|
"Ensure PrepareImage() has returned true "
|
|
|
|
"before calling me");
|
2017-03-13 06:46:04 +03:00
|
|
|
|
|
|
|
CSSSizeOrRatio result;
|
|
|
|
switch (mType) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Image: {
|
2017-03-13 06:46:04 +03:00
|
|
|
bool haveWidth, haveHeight;
|
|
|
|
CSSIntSize imageIntSize;
|
2018-09-04 23:46:21 +03:00
|
|
|
nsLayoutUtils::ComputeSizeForDrawing(
|
|
|
|
mImageContainer, imageIntSize, result.mRatio, haveWidth, haveHeight);
|
2017-03-13 06:46:04 +03:00
|
|
|
if (haveWidth) {
|
|
|
|
result.SetWidth(nsPresContext::CSSPixelsToAppUnits(imageIntSize.width));
|
|
|
|
}
|
|
|
|
if (haveHeight) {
|
2018-09-04 23:46:21 +03:00
|
|
|
result.SetHeight(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(imageIntSize.height));
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we know the aspect ratio and one of the dimensions,
|
|
|
|
// we can compute the other missing width or height.
|
|
|
|
if (!haveHeight && haveWidth && result.mRatio.width != 0) {
|
2018-09-04 23:46:21 +03:00
|
|
|
nscoord intrinsicHeight = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
imageIntSize.width,
|
|
|
|
float(result.mRatio.height) / float(result.mRatio.width));
|
2017-03-13 06:46:04 +03:00
|
|
|
result.SetHeight(nsPresContext::CSSPixelsToAppUnits(intrinsicHeight));
|
|
|
|
} else if (haveHeight && !haveWidth && result.mRatio.height != 0) {
|
2018-09-04 23:46:21 +03:00
|
|
|
nscoord intrinsicWidth = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
imageIntSize.height,
|
|
|
|
float(result.mRatio.width) / float(result.mRatio.height));
|
2017-03-13 06:46:04 +03:00
|
|
|
result.SetWidth(nsPresContext::CSSPixelsToAppUnits(intrinsicWidth));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Element: {
|
2017-03-13 06:46:04 +03:00
|
|
|
// XXX element() should have the width/height of the referenced element,
|
|
|
|
// and that element's ratio, if it matches. If it doesn't match, it
|
|
|
|
// should have no width/height or ratio. See element() in CSS images:
|
|
|
|
// <http://dev.w3.org/csswg/css-images-4/#element-notation>.
|
|
|
|
// Make sure to change nsStyleImageLayers::Size::DependsOnFrameSize
|
|
|
|
// when fixing this!
|
|
|
|
if (mPaintServerFrame) {
|
|
|
|
// SVG images have no intrinsic size
|
|
|
|
if (!mPaintServerFrame->IsFrameOfType(nsIFrame::eSVG)) {
|
|
|
|
// The intrinsic image size for a generic nsIFrame paint server is
|
|
|
|
// the union of the border-box rects of all of its continuations,
|
|
|
|
// rounded to device pixels.
|
|
|
|
int32_t appUnitsPerDevPixel =
|
|
|
|
mForFrame->PresContext()->AppUnitsPerDevPixel();
|
2018-09-04 23:46:21 +03:00
|
|
|
result.SetSize(IntSizeToAppUnits(
|
|
|
|
nsSVGIntegrationUtils::GetContinuationUnionSize(mPaintServerFrame)
|
|
|
|
.ToNearestPixels(appUnitsPerDevPixel),
|
|
|
|
appUnitsPerDevPixel));
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mImageElementSurface.GetSourceSurface(),
|
|
|
|
"Surface should be ready.");
|
|
|
|
IntSize surfaceSize = mImageElementSurface.mSize;
|
|
|
|
result.SetSize(
|
|
|
|
nsSize(nsPresContext::CSSPixelsToAppUnits(surfaceSize.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(surfaceSize.height)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleImageType_Gradient:
|
|
|
|
// Per <http://dev.w3.org/csswg/css3-images/#gradients>, gradients have no
|
|
|
|
// intrinsic dimensions.
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsSize nsImageRenderer::ComputeConcreteSize(
|
|
|
|
const CSSSizeOrRatio& aSpecifiedSize, const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
const nsSize& aDefaultSize) {
|
|
|
|
// The specified size is fully specified, just use that
|
|
|
|
if (aSpecifiedSize.IsConcrete()) {
|
|
|
|
return aSpecifiedSize.ComputeConcreteSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!aSpecifiedSize.mHasWidth || !aSpecifiedSize.mHasHeight);
|
|
|
|
|
|
|
|
if (!aSpecifiedSize.mHasWidth && !aSpecifiedSize.mHasHeight) {
|
|
|
|
// no specified size, try using the intrinsic size
|
|
|
|
if (aIntrinsicSize.CanComputeConcreteSize()) {
|
|
|
|
return aIntrinsicSize.ComputeConcreteSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIntrinsicSize.mHasWidth) {
|
|
|
|
return nsSize(aIntrinsicSize.mWidth, aDefaultSize.height);
|
|
|
|
}
|
|
|
|
if (aIntrinsicSize.mHasHeight) {
|
|
|
|
return nsSize(aDefaultSize.width, aIntrinsicSize.mHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// couldn't use the intrinsic size either, revert to using the default size
|
2018-09-04 23:46:21 +03:00
|
|
|
return ComputeConstrainedSize(aDefaultSize, aIntrinsicSize.mRatio, CONTAIN);
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aSpecifiedSize.mHasWidth || aSpecifiedSize.mHasHeight);
|
|
|
|
|
|
|
|
// The specified height is partial, try to compute the missing part.
|
|
|
|
if (aSpecifiedSize.mHasWidth) {
|
|
|
|
nscoord height;
|
|
|
|
if (aIntrinsicSize.HasRatio()) {
|
|
|
|
height = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
aSpecifiedSize.mWidth,
|
|
|
|
double(aIntrinsicSize.mRatio.height) / aIntrinsicSize.mRatio.width);
|
|
|
|
} else if (aIntrinsicSize.mHasHeight) {
|
|
|
|
height = aIntrinsicSize.mHeight;
|
|
|
|
} else {
|
|
|
|
height = aDefaultSize.height;
|
|
|
|
}
|
|
|
|
return nsSize(aSpecifiedSize.mWidth, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aSpecifiedSize.mHasHeight);
|
|
|
|
nscoord width;
|
|
|
|
if (aIntrinsicSize.HasRatio()) {
|
|
|
|
width = NSCoordSaturatingNonnegativeMultiply(
|
|
|
|
aSpecifiedSize.mHeight,
|
|
|
|
double(aIntrinsicSize.mRatio.width) / aIntrinsicSize.mRatio.height);
|
|
|
|
} else if (aIntrinsicSize.mHasWidth) {
|
|
|
|
width = aIntrinsicSize.mWidth;
|
|
|
|
} else {
|
|
|
|
width = aDefaultSize.width;
|
|
|
|
}
|
|
|
|
return nsSize(width, aSpecifiedSize.mHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsSize nsImageRenderer::ComputeConstrainedSize(
|
|
|
|
const nsSize& aConstrainingSize, const nsSize& aIntrinsicRatio,
|
|
|
|
FitType aFitType) {
|
|
|
|
if (aIntrinsicRatio.width <= 0 && aIntrinsicRatio.height <= 0) {
|
|
|
|
return aConstrainingSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
float scaleX = double(aConstrainingSize.width) / aIntrinsicRatio.width;
|
|
|
|
float scaleY = double(aConstrainingSize.height) / aIntrinsicRatio.height;
|
|
|
|
nsSize size;
|
|
|
|
if ((aFitType == CONTAIN) == (scaleX < scaleY)) {
|
|
|
|
size.width = aConstrainingSize.width;
|
2018-09-04 23:46:21 +03:00
|
|
|
size.height =
|
|
|
|
NSCoordSaturatingNonnegativeMultiply(aIntrinsicRatio.height, scaleX);
|
2017-03-13 06:46:04 +03:00
|
|
|
// If we're reducing the size by less than one css pixel, then just use the
|
|
|
|
// constraining size.
|
2018-09-04 23:46:21 +03:00
|
|
|
if (aFitType == CONTAIN &&
|
|
|
|
aConstrainingSize.height - size.height < AppUnitsPerCSSPixel()) {
|
2017-03-13 06:46:04 +03:00
|
|
|
size.height = aConstrainingSize.height;
|
|
|
|
}
|
|
|
|
} else {
|
2018-09-04 23:46:21 +03:00
|
|
|
size.width =
|
|
|
|
NSCoordSaturatingNonnegativeMultiply(aIntrinsicRatio.width, scaleY);
|
|
|
|
if (aFitType == CONTAIN &&
|
|
|
|
aConstrainingSize.width - size.width < AppUnitsPerCSSPixel()) {
|
2017-03-13 06:46:04 +03:00
|
|
|
size.width = aConstrainingSize.width;
|
|
|
|
}
|
|
|
|
size.height = aConstrainingSize.height;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mSize is the image's "preferred" size for this particular rendering, while
|
|
|
|
* the drawn (aka concrete) size is the actual rendered size after accounting
|
|
|
|
* for background-size etc.. The preferred size is most often the image's
|
|
|
|
* intrinsic dimensions. But for images with incomplete intrinsic dimensions,
|
|
|
|
* the preferred size varies, depending on the specified and default sizes, see
|
|
|
|
* nsImageRenderer::Compute*Size.
|
|
|
|
*
|
|
|
|
* This distinction is necessary because the components of a vector image are
|
|
|
|
* specified with respect to its preferred size for a rendering situation, not
|
|
|
|
* to its actual rendered size. For example, consider a 4px wide background
|
|
|
|
* vector image with no height which contains a left-aligned
|
|
|
|
* 2px wide black rectangle with height 100%. If the background-size width is
|
|
|
|
* auto (or 4px), the vector image will render 4px wide, and the black rectangle
|
|
|
|
* will be 2px wide. If the background-size width is 8px, the vector image will
|
|
|
|
* render 8px wide, and the black rectangle will be 4px wide -- *not* 2px wide.
|
|
|
|
* In both cases mSize.width will be 4px; but in the first case the returned
|
|
|
|
* width will be 4px, while in the second case the returned width will be 8px.
|
|
|
|
*/
|
|
|
|
void nsImageRenderer::SetPreferredSize(const CSSSizeOrRatio& aIntrinsicSize,
|
|
|
|
const nsSize& aDefaultSize) {
|
2018-09-04 23:46:21 +03:00
|
|
|
mSize.width =
|
|
|
|
aIntrinsicSize.mHasWidth ? aIntrinsicSize.mWidth : aDefaultSize.width;
|
|
|
|
mSize.height =
|
|
|
|
aIntrinsicSize.mHasHeight ? aIntrinsicSize.mHeight : aDefaultSize.height;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from nsImageRenderer flags to the flags we want to use for drawing in
|
|
|
|
// the imgIContainer namespace.
|
|
|
|
static uint32_t ConvertImageRendererToDrawFlags(uint32_t aImageRendererFlags) {
|
|
|
|
uint32_t drawFlags = imgIContainer::FLAG_NONE;
|
|
|
|
if (aImageRendererFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES) {
|
|
|
|
drawFlags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
|
|
|
if (aImageRendererFlags & nsImageRenderer::FLAG_PAINTING_TO_WINDOW) {
|
|
|
|
drawFlags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
|
|
|
return drawFlags;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult nsImageRenderer::Draw(nsPresContext* aPresContext,
|
|
|
|
gfxContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsRect& aDest, const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor,
|
|
|
|
const nsSize& aRepeatSize,
|
|
|
|
const CSSIntRect& aSrc, float aOpacity) {
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() || mSize.width <= 0 ||
|
|
|
|
mSize.height <= 0) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
SamplingFilter samplingFilter =
|
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(mForFrame);
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult result = ImgDrawResult::SUCCESS;
|
2017-06-09 22:14:53 +03:00
|
|
|
RefPtr<gfxContext> ctx = &aRenderingContext;
|
2017-03-13 06:46:04 +03:00
|
|
|
IntRect tmpDTRect;
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
if (ctx->CurrentOp() != CompositionOp::OP_OVER ||
|
|
|
|
mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
|
2017-10-12 21:42:42 +03:00
|
|
|
gfxRect clipRect = ctx->GetClipExtents(gfxContext::eDeviceSpace);
|
2017-03-13 06:46:04 +03:00
|
|
|
tmpDTRect = RoundedOut(ToRect(clipRect));
|
|
|
|
if (tmpDTRect.IsEmpty()) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
RefPtr<DrawTarget> tempDT =
|
2018-09-04 23:46:21 +03:00
|
|
|
gfxPlatform::GetPlatform()->CreateSimilarSoftwareDrawTarget(
|
|
|
|
ctx->GetDrawTarget(), tmpDTRect.Size(), SurfaceFormat::B8G8R8A8);
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!tempDT || !tempDT->IsValid()) {
|
2018-09-04 23:46:21 +03:00
|
|
|
gfxDevCrash(LogReason::InvalidContext)
|
|
|
|
<< "ImageRenderer::Draw problem " << gfx::hexa(tempDT);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
tempDT->SetTransform(ctx->GetDrawTarget()->GetTransform() *
|
|
|
|
Matrix::Translation(-tmpDTRect.TopLeft()));
|
2017-03-13 06:46:04 +03:00
|
|
|
ctx = gfxContext::CreatePreservingTransformOrNull(tempDT);
|
|
|
|
if (!ctx) {
|
2018-09-04 23:46:21 +03:00
|
|
|
gfxDevCrash(LogReason::InvalidContext)
|
|
|
|
<< "ImageRenderer::Draw problem " << gfx::hexa(tempDT);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (mType) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Image: {
|
2017-03-13 06:46:04 +03:00
|
|
|
CSSIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height));
|
2018-09-04 23:46:21 +03:00
|
|
|
result = nsLayoutUtils::DrawBackgroundImage(
|
|
|
|
*ctx, mForFrame, aPresContext, mImageContainer, imageSize,
|
|
|
|
samplingFilter, aDest, aFill, aRepeatSize, aAnchor, aDirtyRect,
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags), mExtendMode, aOpacity);
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Gradient: {
|
|
|
|
nsCSSGradientRenderer renderer = nsCSSGradientRenderer::Create(
|
|
|
|
aPresContext, mForFrame->Style(), mGradientData, mSize);
|
2017-03-15 10:14:17 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
renderer.Paint(*ctx, aDest, aFill, aRepeatSize, aSrc, aDirtyRect,
|
|
|
|
aOpacity);
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Element: {
|
2017-03-17 07:05:51 +03:00
|
|
|
RefPtr<gfxDrawable> drawable = DrawableForElement(aDest, *ctx);
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!drawable) {
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
|
2018-09-04 23:46:21 +03:00
|
|
|
result = nsLayoutUtils::DrawImage(
|
|
|
|
*ctx, mForFrame->Style(), aPresContext, image, samplingFilter, aDest,
|
|
|
|
aFill, aAnchor, aDirtyRect, ConvertImageRendererToDrawFlags(mFlags),
|
|
|
|
aOpacity);
|
2017-03-13 06:46:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case eStyleImageType_Null:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tmpDTRect.IsEmpty()) {
|
2017-11-22 12:46:40 +03:00
|
|
|
DrawTarget* dt = aRenderingContext.GetDrawTarget();
|
|
|
|
Matrix oldTransform = dt->GetTransform();
|
|
|
|
dt->SetTransform(Matrix());
|
2017-11-22 02:27:34 +03:00
|
|
|
if (mMaskOp == NS_STYLE_MASK_MODE_LUMINANCE) {
|
2018-09-04 23:46:21 +03:00
|
|
|
RefPtr<SourceSurface> surf = ctx->GetDrawTarget()->IntoLuminanceSource(
|
|
|
|
LuminanceType::LUMINANCE, 1.0f);
|
|
|
|
dt->MaskSurface(ColorPattern(Color(0, 0, 0, 1.0f)), surf,
|
|
|
|
tmpDTRect.TopLeft(),
|
2017-11-22 02:27:34 +03:00
|
|
|
DrawOptions(1.0f, aRenderingContext.CurrentOp()));
|
|
|
|
} else {
|
|
|
|
RefPtr<SourceSurface> surf = ctx->GetDrawTarget()->Snapshot();
|
2018-09-04 23:46:21 +03:00
|
|
|
dt->DrawSurface(
|
|
|
|
surf,
|
|
|
|
Rect(tmpDTRect.x, tmpDTRect.y, tmpDTRect.width, tmpDTRect.height),
|
|
|
|
Rect(0, 0, tmpDTRect.width, tmpDTRect.height),
|
|
|
|
DrawSurfaceOptions(SamplingFilter::POINT),
|
|
|
|
DrawOptions(1.0f, aRenderingContext.CurrentOp()));
|
2017-11-22 02:27:34 +03:00
|
|
|
}
|
|
|
|
|
2017-10-12 21:42:42 +03:00
|
|
|
dt->SetTransform(oldTransform);
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2018-08-29 08:53:06 +03:00
|
|
|
if (!mImage->IsComplete()) {
|
2018-08-29 08:53:08 +03:00
|
|
|
result &= ImgDrawResult::SUCCESS_NOT_COMPLETE;
|
2018-08-29 08:53:06 +03:00
|
|
|
}
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult nsImageRenderer::BuildWebRenderDisplayItems(
|
|
|
|
nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
|
|
|
|
const nsRect& aDirtyRect, const nsRect& aDest, const nsRect& aFill,
|
|
|
|
const nsPoint& aAnchor, const nsSize& aRepeatSize, const CSSIntRect& aSrc,
|
|
|
|
float aOpacity) {
|
2017-03-21 02:31:39 +03:00
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() || mSize.width <= 0 ||
|
|
|
|
mSize.height <= 0) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
|
|
|
|
2018-09-14 02:48:27 +03:00
|
|
|
ImgDrawResult drawResult = ImgDrawResult::SUCCESS;
|
2017-03-21 02:31:39 +03:00
|
|
|
switch (mType) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Gradient: {
|
|
|
|
nsCSSGradientRenderer renderer = nsCSSGradientRenderer::Create(
|
|
|
|
aPresContext, mForFrame->Style(), mGradientData, mSize);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
renderer.BuildWebRenderDisplayItems(aBuilder, aSc, aDest, aFill,
|
|
|
|
aRepeatSize, aSrc,
|
|
|
|
!aItem->BackfaceIsHidden(), aOpacity);
|
2017-03-21 02:31:39 +03:00
|
|
|
break;
|
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
case eStyleImageType_Image: {
|
2017-11-23 14:55:06 +03:00
|
|
|
uint32_t containerFlags = imgIContainer::FLAG_ASYNC_NOTIFY;
|
|
|
|
if (mFlags & nsImageRenderer::FLAG_PAINTING_TO_WINDOW) {
|
|
|
|
containerFlags |= imgIContainer::FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
}
|
2017-06-14 19:53:07 +03:00
|
|
|
if (mFlags & nsImageRenderer::FLAG_SYNC_DECODE_IMAGES) {
|
|
|
|
containerFlags |= imgIContainer::FLAG_SYNC_DECODE;
|
|
|
|
}
|
2017-11-23 14:55:06 +03:00
|
|
|
|
2018-03-14 21:19:13 +03:00
|
|
|
CSSIntSize imageSize(nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height));
|
|
|
|
Maybe<SVGImageContext> svgContext(Some(SVGImageContext(Some(imageSize))));
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
const int32_t appUnitsPerDevPixel =
|
|
|
|
mForFrame->PresContext()->AppUnitsPerDevPixel();
|
|
|
|
LayoutDeviceRect destRect =
|
|
|
|
LayoutDeviceRect::FromAppUnits(aDest, appUnitsPerDevPixel);
|
2017-11-23 14:55:06 +03:00
|
|
|
gfx::IntSize decodeSize =
|
2018-09-04 23:46:21 +03:00
|
|
|
nsLayoutUtils::ComputeImageContainerDrawingParameters(
|
|
|
|
mImageContainer, mForFrame, destRect, aSc, containerFlags,
|
|
|
|
svgContext);
|
2018-09-14 02:48:21 +03:00
|
|
|
|
|
|
|
RefPtr<layers::ImageContainer> container;
|
2018-09-14 02:48:27 +03:00
|
|
|
drawResult = mImageContainer->GetImageContainerAtSize(
|
|
|
|
aManager, decodeSize, svgContext, containerFlags,
|
|
|
|
getter_AddRefs(container));
|
2017-04-07 09:53:16 +03:00
|
|
|
if (!container) {
|
|
|
|
NS_WARNING("Failed to get image container");
|
2018-09-14 02:48:27 +03:00
|
|
|
break;
|
2017-04-07 09:53:16 +03:00
|
|
|
}
|
2017-06-29 01:07:45 +03:00
|
|
|
|
2018-09-07 23:28:41 +03:00
|
|
|
mozilla::wr::ImageRendering rendering = wr::ToImageRendering(
|
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(aItem->Frame()));
|
2017-06-29 01:07:45 +03:00
|
|
|
gfx::IntSize size;
|
2018-09-07 23:28:41 +03:00
|
|
|
Maybe<wr::ImageKey> key = aManager->CommandBuilder().CreateImageKey(
|
|
|
|
aItem, container, aBuilder, aResources, rendering, aSc, size,
|
|
|
|
Nothing());
|
2017-06-29 01:07:45 +03:00
|
|
|
|
2017-04-14 03:13:12 +03:00
|
|
|
if (key.isNothing()) {
|
2018-09-14 02:48:27 +03:00
|
|
|
break;
|
2017-04-07 09:53:16 +03:00
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
nsPoint firstTilePos = nsLayoutUtils::GetBackgroundFirstTilePos(
|
|
|
|
aDest.TopLeft(), aFill.TopLeft(), aRepeatSize);
|
|
|
|
LayoutDeviceRect fillRect = LayoutDeviceRect::FromAppUnits(
|
|
|
|
nsRect(firstTilePos.x, firstTilePos.y, aFill.XMost() - firstTilePos.x,
|
|
|
|
aFill.YMost() - firstTilePos.y),
|
|
|
|
appUnitsPerDevPixel);
|
2018-03-30 00:57:43 +03:00
|
|
|
wr::LayoutRect fill = wr::ToRoundedLayoutRect(fillRect);
|
2018-09-07 19:00:43 +03:00
|
|
|
|
|
|
|
wr::LayoutRect roundedDest = wr::ToRoundedLayoutRect(destRect);
|
|
|
|
auto stretchSize = wr::ToLayoutSize(destRect.Size());
|
|
|
|
|
|
|
|
// WebRender special cases situations where stretchSize == fillSize to
|
|
|
|
// infer that it shouldn't use repeat sampling. This makes sure
|
|
|
|
// we hit those special cases when not repeating.
|
|
|
|
|
|
|
|
switch (mExtendMode) {
|
|
|
|
case ExtendMode::CLAMP:
|
|
|
|
fill = roundedDest;
|
|
|
|
stretchSize = roundedDest.size;
|
|
|
|
break;
|
|
|
|
case ExtendMode::REPEAT_Y:
|
|
|
|
fill.origin.x = roundedDest.origin.x;
|
|
|
|
fill.size.width = roundedDest.size.width;
|
|
|
|
stretchSize.width = roundedDest.size.width;
|
|
|
|
break;
|
|
|
|
case ExtendMode::REPEAT_X:
|
|
|
|
fill.origin.y = roundedDest.origin.y;
|
|
|
|
fill.size.height = roundedDest.size.height;
|
|
|
|
stretchSize.height = roundedDest.size.height;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-30 00:57:43 +03:00
|
|
|
wr::LayoutRect clip = wr::ToRoundedLayoutRect(
|
2018-09-04 23:46:21 +03:00
|
|
|
LayoutDeviceRect::FromAppUnits(aFill, appUnitsPerDevPixel));
|
2017-04-07 09:53:16 +03:00
|
|
|
|
2017-05-03 15:48:08 +03:00
|
|
|
LayoutDeviceSize gapSize = LayoutDeviceSize::FromAppUnits(
|
2018-09-04 23:46:21 +03:00
|
|
|
aRepeatSize - aDest.Size(), appUnitsPerDevPixel);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
aBuilder.PushImage(fill, clip, !aItem->BackfaceIsHidden(), stretchSize,
|
|
|
|
wr::ToLayoutSize(gapSize), rendering, key.value());
|
2017-04-07 09:53:16 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-03-21 02:31:39 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-04-26 10:31:49 +03:00
|
|
|
|
2018-09-14 02:48:27 +03:00
|
|
|
if (!mImage->IsComplete() && drawResult == ImgDrawResult::SUCCESS) {
|
|
|
|
return ImgDrawResult::SUCCESS_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
return drawResult;
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
already_AddRefed<gfxDrawable> nsImageRenderer::DrawableForElement(
|
2018-09-04 23:46:21 +03:00
|
|
|
const nsRect& aImageRect, gfxContext& aContext) {
|
2017-03-13 06:46:04 +03:00
|
|
|
NS_ASSERTION(mType == eStyleImageType_Element,
|
|
|
|
"DrawableForElement only makes sense if backed by an element");
|
|
|
|
if (mPaintServerFrame) {
|
|
|
|
// XXX(seth): In order to not pass FLAG_SYNC_DECODE_IMAGES here,
|
2017-12-11 18:37:59 +03:00
|
|
|
// DrawableFromPaintServer would have to return a ImgDrawResult indicating
|
2017-03-13 06:46:04 +03:00
|
|
|
// whether any images could not be painted because they weren't fully
|
|
|
|
// decoded. Even always passing FLAG_SYNC_DECODE_IMAGES won't eliminate all
|
|
|
|
// problems, as it won't help if there are image which haven't finished
|
|
|
|
// loading, but it's better than nothing.
|
2018-09-04 23:46:21 +03:00
|
|
|
int32_t appUnitsPerDevPixel =
|
|
|
|
mForFrame->PresContext()->AppUnitsPerDevPixel();
|
2017-03-13 06:46:04 +03:00
|
|
|
nsRect destRect = aImageRect - aImageRect.TopLeft();
|
|
|
|
nsIntSize roundedOut = destRect.ToOutsidePixels(appUnitsPerDevPixel).Size();
|
|
|
|
IntSize imageSize(roundedOut.width, roundedOut.height);
|
2018-11-13 13:39:27 +03:00
|
|
|
|
|
|
|
RefPtr<gfxDrawable> drawable;
|
|
|
|
|
|
|
|
SurfaceFormat format = aContext.GetDrawTarget()->GetFormat();
|
|
|
|
// Don't allow creating images that are too big
|
|
|
|
if (aContext.GetDrawTarget()->CanCreateSimilarDrawTarget(imageSize,
|
|
|
|
format)) {
|
|
|
|
drawable = nsSVGIntegrationUtils::DrawableFromPaintServer(
|
2018-09-04 23:46:21 +03:00
|
|
|
mPaintServerFrame, mForFrame, mSize, imageSize,
|
2017-11-11 05:14:09 +03:00
|
|
|
aContext.GetDrawTarget(), aContext.CurrentMatrixDouble(),
|
2017-03-13 06:46:04 +03:00
|
|
|
nsSVGIntegrationUtils::FLAG_SYNC_DECODE_IMAGES);
|
2018-11-13 13:39:27 +03:00
|
|
|
}
|
2017-03-13 06:46:04 +03:00
|
|
|
|
|
|
|
return drawable.forget();
|
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
NS_ASSERTION(mImageElementSurface.GetSourceSurface(),
|
|
|
|
"Surface should be ready.");
|
2017-03-13 06:46:04 +03:00
|
|
|
RefPtr<gfxDrawable> drawable =
|
2018-09-04 23:46:21 +03:00
|
|
|
new gfxSurfaceDrawable(mImageElementSurface.GetSourceSurface().get(),
|
|
|
|
mImageElementSurface.mSize);
|
2017-03-13 06:46:04 +03:00
|
|
|
return drawable.forget();
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult nsImageRenderer::DrawLayer(
|
|
|
|
nsPresContext* aPresContext, gfxContext& aRenderingContext,
|
|
|
|
const nsRect& aDest, const nsRect& aFill, const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty, const nsSize& aRepeatSize, float aOpacity) {
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() || mSize.width <= 0 ||
|
|
|
|
mSize.height <= 0) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
return Draw(
|
|
|
|
aPresContext, aRenderingContext, aDirty, aDest, aFill, aAnchor,
|
|
|
|
aRepeatSize,
|
2017-03-13 06:46:04 +03:00
|
|
|
CSSIntRect(0, 0, nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)),
|
|
|
|
aOpacity);
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult nsImageRenderer::BuildWebRenderDisplayItemsForLayer(
|
|
|
|
nsPresContext* aPresContext, mozilla::wr::DisplayListBuilder& aBuilder,
|
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
|
|
|
const mozilla::layers::StackingContextHelper& aSc,
|
|
|
|
mozilla::layers::WebRenderLayerManager* aManager, nsDisplayItem* aItem,
|
|
|
|
const nsRect& aDest, const nsRect& aFill, const nsPoint& aAnchor,
|
|
|
|
const nsRect& aDirty, const nsSize& aRepeatSize, float aOpacity) {
|
2017-03-21 02:31:39 +03:00
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2017-04-26 10:31:49 +03:00
|
|
|
return mPrepareResult;
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
if (aDest.IsEmpty() || aFill.IsEmpty() || mSize.width <= 0 ||
|
|
|
|
mSize.height <= 0) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
2018-09-04 23:46:21 +03:00
|
|
|
return BuildWebRenderDisplayItems(
|
|
|
|
aPresContext, aBuilder, aResources, aSc, aManager, aItem, aDirty, aDest,
|
|
|
|
aFill, aAnchor, aRepeatSize,
|
|
|
|
CSSIntRect(0, 0, nsPresContext::AppUnitsToIntCSSPixels(mSize.width),
|
|
|
|
nsPresContext::AppUnitsToIntCSSPixels(mSize.height)),
|
|
|
|
aOpacity);
|
2017-03-21 02:31:39 +03:00
|
|
|
}
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
/**
|
|
|
|
* Compute the size and position of the master copy of the image. I.e., a single
|
|
|
|
* tile used to fill the dest rect.
|
|
|
|
* aFill The destination rect to be filled
|
|
|
|
* aHFill and aVFill are the repeat patterns for the component -
|
2017-12-21 08:16:40 +03:00
|
|
|
* StyleBorderImageRepeat - i.e., how a tiling unit is used to fill aFill
|
2017-03-13 06:46:04 +03:00
|
|
|
* aUnitSize The size of the source rect in dest coords.
|
|
|
|
*/
|
2017-12-21 08:16:40 +03:00
|
|
|
static nsRect ComputeTile(nsRect& aFill, StyleBorderImageRepeat aHFill,
|
|
|
|
StyleBorderImageRepeat aVFill,
|
2018-09-04 23:46:21 +03:00
|
|
|
const nsSize& aUnitSize, nsSize& aRepeatSize) {
|
2017-03-13 06:46:04 +03:00
|
|
|
nsRect tile;
|
|
|
|
switch (aHFill) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case StyleBorderImageRepeat::Stretch:
|
|
|
|
tile.x = aFill.x;
|
|
|
|
tile.width = aFill.width;
|
|
|
|
aRepeatSize.width = tile.width;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Repeat:
|
|
|
|
tile.x = aFill.x + aFill.width / 2 - aUnitSize.width / 2;
|
|
|
|
tile.width = aUnitSize.width;
|
|
|
|
aRepeatSize.width = tile.width;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Round:
|
|
|
|
tile.x = aFill.x;
|
|
|
|
tile.width =
|
|
|
|
nsCSSRendering::ComputeRoundedSize(aUnitSize.width, aFill.width);
|
|
|
|
aRepeatSize.width = tile.width;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Space: {
|
2017-03-13 06:46:04 +03:00
|
|
|
nscoord space;
|
2018-09-04 23:46:21 +03:00
|
|
|
aRepeatSize.width = nsCSSRendering::ComputeBorderSpacedRepeatSize(
|
|
|
|
aUnitSize.width, aFill.width, space);
|
2017-03-13 06:46:04 +03:00
|
|
|
tile.x = aFill.x + space;
|
|
|
|
tile.width = aUnitSize.width;
|
|
|
|
aFill.x = tile.x;
|
|
|
|
aFill.width = aFill.width - space * 2;
|
2018-09-04 23:46:21 +03:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unrecognized border-image fill style");
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (aVFill) {
|
2018-09-04 23:46:21 +03:00
|
|
|
case StyleBorderImageRepeat::Stretch:
|
|
|
|
tile.y = aFill.y;
|
|
|
|
tile.height = aFill.height;
|
|
|
|
aRepeatSize.height = tile.height;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Repeat:
|
|
|
|
tile.y = aFill.y + aFill.height / 2 - aUnitSize.height / 2;
|
|
|
|
tile.height = aUnitSize.height;
|
|
|
|
aRepeatSize.height = tile.height;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Round:
|
|
|
|
tile.y = aFill.y;
|
|
|
|
tile.height =
|
|
|
|
nsCSSRendering::ComputeRoundedSize(aUnitSize.height, aFill.height);
|
|
|
|
aRepeatSize.height = tile.height;
|
|
|
|
break;
|
|
|
|
case StyleBorderImageRepeat::Space: {
|
2017-03-13 06:46:04 +03:00
|
|
|
nscoord space;
|
2018-09-04 23:46:21 +03:00
|
|
|
aRepeatSize.height = nsCSSRendering::ComputeBorderSpacedRepeatSize(
|
|
|
|
aUnitSize.height, aFill.height, space);
|
2017-03-13 06:46:04 +03:00
|
|
|
tile.y = aFill.y + space;
|
|
|
|
tile.height = aUnitSize.height;
|
|
|
|
aFill.y = tile.y;
|
|
|
|
aFill.height = aFill.height - space * 2;
|
2018-09-04 23:46:21 +03:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unrecognized border-image fill style");
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the given set of arguments will require the tiles which fill
|
|
|
|
* the dest rect to be scaled from the source tile. See comment on ComputeTile
|
|
|
|
* for argument descriptions.
|
|
|
|
*/
|
2018-09-04 23:46:21 +03:00
|
|
|
static bool RequiresScaling(const nsRect& aFill, StyleBorderImageRepeat aHFill,
|
2017-12-21 08:16:40 +03:00
|
|
|
StyleBorderImageRepeat aVFill,
|
2018-09-04 23:46:21 +03:00
|
|
|
const nsSize& aUnitSize) {
|
2017-03-13 06:46:04 +03:00
|
|
|
// If we have no tiling in either direction, we can skip the intermediate
|
|
|
|
// scaling step.
|
2017-12-21 08:16:40 +03:00
|
|
|
return (aHFill != StyleBorderImageRepeat::Stretch ||
|
|
|
|
aVFill != StyleBorderImageRepeat::Stretch) &&
|
2018-09-04 23:46:21 +03:00
|
|
|
(aUnitSize.width != aFill.width || aUnitSize.height != aFill.height);
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult nsImageRenderer::DrawBorderImageComponent(
|
|
|
|
nsPresContext* aPresContext, gfxContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect, const nsRect& aFill, const CSSIntRect& aSrc,
|
2017-12-21 08:16:40 +03:00
|
|
|
StyleBorderImageRepeat aHFill, StyleBorderImageRepeat aVFill,
|
2018-09-04 23:46:21 +03:00
|
|
|
const nsSize& aUnitSize, uint8_t aIndex,
|
2017-03-13 06:46:04 +03:00
|
|
|
const Maybe<nsSize>& aSVGViewportSize, const bool aHasIntrinsicRatio) {
|
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
2018-06-18 08:43:11 +03:00
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
if (aFill.IsEmpty() || aSrc.IsEmpty()) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mType == eStyleImageType_Image || mType == eStyleImageType_Element) {
|
|
|
|
nsCOMPtr<imgIContainer> subImage;
|
|
|
|
|
|
|
|
// To draw one portion of an image into a border component, we stretch that
|
|
|
|
// portion to match the size of that border component and then draw onto.
|
2018-09-04 23:46:21 +03:00
|
|
|
// However, preserveAspectRatio attribute of a SVG image may break this
|
|
|
|
// rule. To get correct rendering result, we add
|
2017-03-13 06:46:04 +03:00
|
|
|
// FLAG_FORCE_PRESERVEASPECTRATIO_NONE flag here, to tell mImage to ignore
|
|
|
|
// preserveAspectRatio attribute, and always do non-uniform stretch.
|
|
|
|
uint32_t drawFlags = ConvertImageRendererToDrawFlags(mFlags) |
|
2018-09-04 23:46:21 +03:00
|
|
|
imgIContainer::FLAG_FORCE_PRESERVEASPECTRATIO_NONE;
|
2017-03-13 06:46:04 +03:00
|
|
|
// For those SVG image sources which don't have fixed aspect ratio (i.e.
|
|
|
|
// without viewport size and viewBox), we should scale the source uniformly
|
|
|
|
// after the viewport size is decided by "Default Sizing Algorithm".
|
|
|
|
if (!aHasIntrinsicRatio) {
|
|
|
|
drawFlags = drawFlags | imgIContainer::FLAG_FORCE_UNIFORM_SCALING;
|
|
|
|
}
|
|
|
|
// Retrieve or create the subimage we'll draw.
|
|
|
|
nsIntRect srcRect(aSrc.x, aSrc.y, aSrc.width, aSrc.height);
|
|
|
|
if (mType == eStyleImageType_Image) {
|
|
|
|
if ((subImage = mImage->GetSubImage(aIndex)) == nullptr) {
|
|
|
|
subImage = ImageOps::Clip(mImageContainer, srcRect, aSVGViewportSize);
|
|
|
|
mImage->SetSubImage(aIndex, subImage);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This path, for eStyleImageType_Element, is currently slower than it
|
|
|
|
// needs to be because we don't cache anything. (In particular, if we have
|
|
|
|
// to draw to a temporary surface inside ClippedImage, we don't cache that
|
|
|
|
// temporary surface since we immediately throw the ClippedImage we create
|
|
|
|
// here away.) However, if we did cache, we'd need to know when to
|
|
|
|
// invalidate that cache, and it's not clear that it's worth the trouble
|
|
|
|
// since using border-image with -moz-element is rare.
|
|
|
|
|
2017-03-17 07:05:51 +03:00
|
|
|
RefPtr<gfxDrawable> drawable =
|
2018-09-04 23:46:21 +03:00
|
|
|
DrawableForElement(nsRect(nsPoint(), mSize), aRenderingContext);
|
2017-03-13 06:46:04 +03:00
|
|
|
if (!drawable) {
|
|
|
|
NS_WARNING("Could not create drawable for element");
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image(ImageOps::CreateFromDrawable(drawable));
|
|
|
|
subImage = ImageOps::Clip(image, srcRect, aSVGViewportSize);
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:27:17 +03:00
|
|
|
MOZ_ASSERT(!aSVGViewportSize ||
|
|
|
|
subImage->GetType() == imgIContainer::TYPE_VECTOR);
|
2017-03-13 06:46:04 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
SamplingFilter samplingFilter =
|
|
|
|
nsLayoutUtils::GetSamplingFilterForFrame(mForFrame);
|
2017-03-13 06:46:04 +03:00
|
|
|
|
|
|
|
if (!RequiresScaling(aFill, aHFill, aVFill, aUnitSize)) {
|
2018-08-29 08:53:06 +03:00
|
|
|
ImgDrawResult result = nsLayoutUtils::DrawSingleImage(
|
|
|
|
aRenderingContext, aPresContext, subImage, samplingFilter, aFill,
|
2018-09-04 23:46:21 +03:00
|
|
|
aDirtyRect,
|
2018-08-29 08:53:06 +03:00
|
|
|
/* no SVGImageContext */ Nothing(), drawFlags);
|
|
|
|
|
|
|
|
if (!mImage->IsComplete()) {
|
2018-08-29 08:53:08 +03:00
|
|
|
result &= ImgDrawResult::SUCCESS_NOT_COMPLETE;
|
2018-08-29 08:53:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize repeatSize;
|
|
|
|
nsRect fillRect(aFill);
|
|
|
|
nsRect tile = ComputeTile(fillRect, aHFill, aVFill, aUnitSize, repeatSize);
|
|
|
|
CSSIntSize imageSize(srcRect.width, srcRect.height);
|
2018-08-29 08:53:06 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
ImgDrawResult result = nsLayoutUtils::DrawBackgroundImage(
|
|
|
|
aRenderingContext, mForFrame, aPresContext, subImage, imageSize,
|
|
|
|
samplingFilter, tile, fillRect, repeatSize, tile.TopLeft(), aDirtyRect,
|
|
|
|
drawFlags, ExtendMode::CLAMP, 1.0);
|
|
|
|
|
|
|
|
if (!mImage->IsComplete()) {
|
|
|
|
result &= ImgDrawResult::SUCCESS_NOT_COMPLETE;
|
|
|
|
}
|
2018-09-04 23:42:36 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
return result;
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSize repeatSize(aFill.Size());
|
|
|
|
nsRect fillRect(aFill);
|
2018-09-04 23:46:21 +03:00
|
|
|
nsRect destTile =
|
|
|
|
RequiresScaling(fillRect, aHFill, aVFill, aUnitSize)
|
|
|
|
? ComputeTile(fillRect, aHFill, aVFill, aUnitSize, repeatSize)
|
|
|
|
: fillRect;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
return Draw(aPresContext, aRenderingContext, aDirtyRect, destTile, fillRect,
|
|
|
|
destTile.TopLeft(), repeatSize, aSrc);
|
2017-03-13 06:46:04 +03:00
|
|
|
}
|
|
|
|
|
2018-01-25 09:55:18 +03:00
|
|
|
ImgDrawResult nsImageRenderer::DrawShapeImage(nsPresContext* aPresContext,
|
|
|
|
gfxContext& aRenderingContext) {
|
|
|
|
if (!IsReady()) {
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"Ensure PrepareImage() has returned true before "
|
|
|
|
"calling me");
|
2018-01-25 09:55:18 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSize.width <= 0 || mSize.height <= 0) {
|
|
|
|
return ImgDrawResult::SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ImgDrawResult result = ImgDrawResult::SUCCESS;
|
|
|
|
|
|
|
|
switch (mType) {
|
|
|
|
case eStyleImageType_Image: {
|
2018-09-04 23:46:21 +03:00
|
|
|
uint32_t drawFlags =
|
|
|
|
ConvertImageRendererToDrawFlags(mFlags) | imgIContainer::FRAME_FIRST;
|
2018-01-25 09:55:18 +03:00
|
|
|
nsRect dest(nsPoint(0, 0), mSize);
|
2018-09-04 23:46:21 +03:00
|
|
|
// We have a tricky situation in our choice of SamplingFilter. Shape
|
|
|
|
// images define a float area based on the alpha values in the rendered
|
|
|
|
// pixels. When multiple device pixels are used for one css pixel, the
|
|
|
|
// sampling can change crisp edges into aliased edges. For visual pixels,
|
|
|
|
// that's usually the right choice. For defining a float area, it can
|
|
|
|
// cause problems. If a style is using a shape-image-threshold value that
|
|
|
|
// is less than the alpha of the edge pixels, any filtering may smear the
|
|
|
|
// alpha into adjacent pixels and expand the float area in a confusing
|
|
|
|
// way. Since the alpha threshold can be set precisely in CSS, and since a
|
|
|
|
// web author may be counting on that threshold to define a precise float
|
|
|
|
// area from an image, it is least confusing to have the rendered pixels
|
|
|
|
// have unfiltered alpha. We use SamplingFilter::POINT to ensure that each
|
|
|
|
// rendered pixel has an alpha that precisely matches the alpha of the
|
|
|
|
// closest pixel in the image.
|
|
|
|
result = nsLayoutUtils::DrawSingleImage(
|
|
|
|
aRenderingContext, aPresContext, mImageContainer,
|
2018-01-25 09:55:18 +03:00
|
|
|
SamplingFilter::POINT, dest, dest, Nothing(), drawFlags, nullptr,
|
2018-09-04 23:46:21 +03:00
|
|
|
nullptr);
|
2018-01-25 09:55:18 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eStyleImageType_Gradient: {
|
2018-09-04 23:46:21 +03:00
|
|
|
nsCSSGradientRenderer renderer = nsCSSGradientRenderer::Create(
|
|
|
|
aPresContext, mForFrame->Style(), mGradientData, mSize);
|
2018-01-25 09:55:18 +03:00
|
|
|
nsRect dest(nsPoint(0, 0), mSize);
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
renderer.Paint(aRenderingContext, dest, dest, mSize,
|
2018-01-25 09:55:18 +03:00
|
|
|
CSSIntRect::FromAppUnitsRounded(dest), dest, 1.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Unsupported image type.
|
|
|
|
result = ImgDrawResult::BAD_IMAGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
bool nsImageRenderer::IsRasterImage() {
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer) return false;
|
|
|
|
return mImageContainer->GetType() == imgIContainer::TYPE_RASTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsImageRenderer::IsAnimatedImage() {
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer) return false;
|
|
|
|
bool animated = false;
|
|
|
|
if (NS_SUCCEEDED(mImageContainer->GetAnimated(&animated)) && animated)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<imgIContainer> nsImageRenderer::GetImage() {
|
|
|
|
if (mType != eStyleImageType_Image || !mImageContainer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> image = mImageContainer;
|
|
|
|
return image.forget();
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:46:21 +03:00
|
|
|
bool nsImageRenderer::IsImageContainerAvailable(layers::LayerManager* aManager,
|
|
|
|
uint32_t aFlags) {
|
2017-03-20 11:27:55 +03:00
|
|
|
if (!mImageContainer) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return mImageContainer->IsImageContainerAvailable(aManager, aFlags);
|
|
|
|
}
|
|
|
|
|
2017-03-13 06:46:04 +03:00
|
|
|
void nsImageRenderer::PurgeCacheForViewportChange(
|
2018-09-04 23:46:21 +03:00
|
|
|
const Maybe<nsSize>& aSVGViewportSize, const bool aHasIntrinsicRatio) {
|
2017-03-13 06:46:04 +03:00
|
|
|
// Check if we should flush the cached data - only vector images need to do
|
|
|
|
// the check since they might not have fixed ratio.
|
|
|
|
if (mImageContainer &&
|
|
|
|
mImageContainer->GetType() == imgIContainer::TYPE_VECTOR) {
|
|
|
|
mImage->PurgeCacheForViewportChange(aSVGViewportSize, aHasIntrinsicRatio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-10 12:27:30 +03:00
|
|
|
already_AddRefed<nsStyleGradient> nsImageRenderer::GetGradientData() {
|
|
|
|
RefPtr<nsStyleGradient> res = mGradientData;
|
|
|
|
return res.forget();
|
|
|
|
}
|