2014-07-22 00:59:22 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#include "DynamicImage.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "gfxContext.h"
|
2014-07-22 00:59:22 +00:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-03-27 11:49:21 +00:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2020-07-12 16:38:26 +00:00
|
|
|
#include "mozilla/SVGImageContext.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2014-07-22 00:59:22 +00:00
|
|
|
#include "Orientation.h"
|
2021-05-05 09:41:23 +00:00
|
|
|
#include "mozilla/image/Resolution.h"
|
2014-07-22 00:59:22 +00:00
|
|
|
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2022-07-14 16:03:25 +00:00
|
|
|
namespace mozilla::image {
|
2014-07-22 00:59:22 +00:00
|
|
|
|
|
|
|
// Inherited methods from Image.
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker> DynamicImage::GetProgressTracker() {
|
2014-07-22 00:59:22 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-28 10:10:04 +00:00
|
|
|
size_t DynamicImage::SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const {
|
2014-07-22 00:59:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
void DynamicImage::CollectSizeOfSurfaces(
|
|
|
|
nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const {
|
|
|
|
// We can't report anything useful because gfxDrawable doesn't expose this
|
|
|
|
// information.
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicImage::IncrementAnimationConsumers() {}
|
|
|
|
|
|
|
|
void DynamicImage::DecrementAnimationConsumers() {}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
uint32_t DynamicImage::GetAnimationConsumers() { return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult DynamicImage::OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DynamicImage::OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsresult aStatus, bool aLastPart) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-16 08:06:06 +00:00
|
|
|
void DynamicImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) {}
|
2014-11-28 03:55:57 +00:00
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
void DynamicImage::SetInnerWindowID(uint64_t aInnerWindowId) {}
|
|
|
|
|
|
|
|
uint64_t DynamicImage::InnerWindowID() const { return 0; }
|
|
|
|
|
|
|
|
bool DynamicImage::HasError() { return !mDrawable; }
|
|
|
|
|
|
|
|
void DynamicImage::SetHasError() {}
|
|
|
|
|
2018-06-06 00:42:56 +00:00
|
|
|
nsIURI* DynamicImage::GetURI() const { return nullptr; }
|
2014-07-22 00:59:22 +00:00
|
|
|
|
|
|
|
// Methods inherited from XPCOM interfaces.
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(DynamicImage, imgIContainer)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetWidth(int32_t* aWidth) {
|
|
|
|
*aWidth = mDrawable->Size().width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetHeight(int32_t* aHeight) {
|
|
|
|
*aHeight = mDrawable->Size().height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2022-07-06 14:53:06 +00:00
|
|
|
void DynamicImage::MediaFeatureValuesChangedAllDocuments(
|
|
|
|
const mozilla::MediaFeatureChange& aChange) {}
|
|
|
|
|
|
|
|
nsresult DynamicImage::GetNativeSizes(nsTArray<IntSize>&) {
|
2017-03-22 13:05:36 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2022-07-06 14:53:06 +00:00
|
|
|
size_t DynamicImage::GetNativeSizesLength() { return 0; }
|
2017-09-05 11:58:44 +00:00
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetIntrinsicSize(nsSize* aSize) {
|
2015-09-23 18:49:05 +00:00
|
|
|
IntSize intSize(mDrawable->Size());
|
2014-07-22 00:59:22 +00:00
|
|
|
*aSize = nsSize(intSize.width, intSize.height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-02 23:28:21 +00:00
|
|
|
Maybe<AspectRatio> DynamicImage::GetIntrinsicRatio() {
|
|
|
|
auto size = mDrawable->Size();
|
|
|
|
return Some(AspectRatio::FromSize(size.width, size.height));
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
DynamicImage::GetOrientation() { return Orientation(); }
|
|
|
|
|
2021-05-05 09:41:23 +00:00
|
|
|
NS_IMETHODIMP_(Resolution)
|
|
|
|
DynamicImage::GetResolution() { return {}; }
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetType(uint16_t* aType) {
|
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-11-27 11:47:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetProviderId(uint32_t* aId) {
|
|
|
|
*aId = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetAnimated(bool* aAnimated) {
|
|
|
|
*aAnimated = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2014-07-22 00:59:22 +00:00
|
|
|
DynamicImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
|
2015-09-23 18:49:05 +00:00
|
|
|
IntSize size(mDrawable->Size());
|
2015-09-19 20:34:09 +00:00
|
|
|
return GetFrameAtSize(IntSize(size.width, size.height), aWhichFrame, aFlags);
|
|
|
|
}
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2015-09-19 20:34:09 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
DynamicImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> dt =
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2019-11-12 18:22:33 +00:00
|
|
|
aSize, SurfaceFormat::OS_RGBA);
|
2016-04-12 19:18:11 +00:00
|
|
|
if (!dt || !dt->IsValid()) {
|
2015-03-26 02:39:00 +00:00
|
|
|
gfxWarning()
|
|
|
|
<< "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget";
|
2015-03-09 19:48:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2023-02-21 07:28:25 +00:00
|
|
|
gfxContext context(dt);
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2023-02-21 07:28:25 +00:00
|
|
|
auto result = Draw(&context, aSize, ImageRegion::Create(aSize), aWhichFrame,
|
|
|
|
SamplingFilter::POINT, SVGImageContext(), aFlags, 1.0);
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
return result == ImgDrawResult::SUCCESS ? dt->Snapshot() : nullptr;
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2016-08-23 02:15:38 +00:00
|
|
|
DynamicImage::WillDrawOpaqueNow() { return false; }
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2015-05-13 07:23:44 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2021-09-05 22:36:45 +00:00
|
|
|
DynamicImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
|
2015-05-13 07:23:44 +00:00
|
|
|
uint32_t aFlags) {
|
2017-11-17 11:45:26 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-27 11:47:36 +00:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
|
|
|
DynamicImage::GetImageProvider(WindowRenderer* aRenderer,
|
|
|
|
const gfx::IntSize& aSize,
|
2022-07-14 16:03:25 +00:00
|
|
|
const SVGImageContext& aSVGContext,
|
2021-11-27 11:47:36 +00:00
|
|
|
const Maybe<ImageIntRegion>& aRegion,
|
|
|
|
uint32_t aFlags,
|
|
|
|
WebRenderImageProvider** aProvider) {
|
|
|
|
return ImgDrawResult::NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2017-12-11 15:37:59 +00:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-07-22 00:59:22 +00:00
|
|
|
DynamicImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
|
2014-08-22 20:12:38 +00:00
|
|
|
const ImageRegion& aRegion, uint32_t aWhichFrame,
|
2016-05-25 16:01:18 +00:00
|
|
|
SamplingFilter aSamplingFilter,
|
2022-07-14 16:03:25 +00:00
|
|
|
const SVGImageContext& aSVGContext, uint32_t aFlags,
|
2017-01-03 05:53:22 +00:00
|
|
|
float aOpacity) {
|
2014-08-22 20:12:38 +00:00
|
|
|
MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size");
|
|
|
|
|
2015-09-23 18:49:05 +00:00
|
|
|
IntSize drawableSize(mDrawable->Size());
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
if (aSize == drawableSize) {
|
2017-06-28 15:41:21 +00:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
|
2019-11-12 18:22:33 +00:00
|
|
|
aRegion, SurfaceFormat::OS_RGBA, aSamplingFilter,
|
|
|
|
aOpacity);
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2014-08-22 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
2022-06-20 19:17:14 +00:00
|
|
|
MatrixScalesDouble scale(double(aSize.width) / drawableSize.width,
|
|
|
|
double(aSize.height) / drawableSize.height);
|
2014-08-22 20:12:38 +00:00
|
|
|
|
|
|
|
ImageRegion region(aRegion);
|
2022-06-20 19:17:14 +00:00
|
|
|
region.Scale(1.0 / scale.xScale, 1.0 / scale.yScale);
|
2014-08-22 20:12:38 +00:00
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
2022-06-20 19:17:14 +00:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scale));
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2017-06-28 15:41:21 +00:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
|
2019-11-12 18:22:33 +00:00
|
|
|
region, SurfaceFormat::OS_RGBA, aSamplingFilter,
|
2017-01-03 05:53:22 +00:00
|
|
|
aOpacity);
|
2017-12-11 15:37:59 +00:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-21 17:34:14 +00:00
|
|
|
DynamicImage::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2019-05-21 17:34:14 +00:00
|
|
|
bool DynamicImage::StartDecodingWithResult(uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-23 07:07:45 +00:00
|
|
|
|
2022-05-20 09:02:32 +00:00
|
|
|
bool DynamicImage::HasDecodedPixels() { return true; }
|
|
|
|
|
2020-04-20 21:04:45 +00:00
|
|
|
imgIContainer::DecodeResult DynamicImage::RequestDecodeWithResult(
|
|
|
|
uint32_t aFlags, uint32_t aWhichFrame) {
|
|
|
|
return imgIContainer::DECODE_SURFACE_AVAILABLE;
|
2019-05-21 17:34:14 +00:00
|
|
|
}
|
2018-11-08 17:45:50 +00:00
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
NS_IMETHODIMP
|
2019-05-21 17:34:14 +00:00
|
|
|
DynamicImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
2015-01-18 22:02:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::LockImage() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::UnlockImage() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::RequestDiscard() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
DynamicImage::RequestRefresh(const mozilla::TimeStamp& aTime) {}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetAnimationMode(uint16_t* aAnimationMode) {
|
|
|
|
*aAnimationMode = kNormalAnimMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::SetAnimationMode(uint16_t aAnimationMode) { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::ResetAnimation() { return NS_OK; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
DynamicImage::GetFrameIndex(uint32_t aWhichFrame) { return 0; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(int32_t)
|
|
|
|
DynamicImage::GetFirstFrameDelay() { return 0; }
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
DynamicImage::SetAnimationStartTime(const mozilla::TimeStamp& aTime) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2014-12-06 00:28:00 +00:00
|
|
|
nsIntSize DynamicImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 16:01:18 +00:00
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aFlags) {
|
2015-09-23 18:49:05 +00:00
|
|
|
IntSize size(mDrawable->Size());
|
2014-07-28 21:27:40 +00:00
|
|
|
return nsIntSize(size.width, size.height);
|
|
|
|
}
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
NS_IMETHODIMP_(nsIntRect)
|
|
|
|
DynamicImage::GetImageSpaceInvalidationRect(const nsIntRect& aRect) {
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<imgIContainer> DynamicImage::Unwrap() {
|
|
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
void DynamicImage::PropagateUseCounters(dom::Document*) {
|
2015-06-03 17:42:07 +00:00
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2020-03-31 21:16:39 +00:00
|
|
|
nsresult DynamicImage::GetHotspotX(int32_t* aX) {
|
|
|
|
return Image::GetHotspotX(aX);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DynamicImage::GetHotspotY(int32_t* aY) {
|
|
|
|
return Image::GetHotspotY(aY);
|
|
|
|
}
|
|
|
|
|
2022-07-14 16:03:25 +00:00
|
|
|
} // namespace mozilla::image
|