2014-07-22 04:59:22 +04: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"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-03-27 14:49:21 +03:00
|
|
|
#include "mozilla/gfx/Logging.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "ImageRegion.h"
|
2014-07-22 04:59:22 +04:00
|
|
|
#include "Orientation.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "SVGImageContext.h"
|
2014-07-22 04:59:22 +04:00
|
|
|
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using mozilla::layers::ImageContainer;
|
|
|
|
using mozilla::layers::LayerManager;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
|
|
|
// Inherited methods from Image.
|
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
already_AddRefed<ProgressTracker> DynamicImage::GetProgressTracker() {
|
2014-07-22 04:59:22 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:10:04 +03:00
|
|
|
size_t DynamicImage::SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const {
|
2014-07-22 04:59:22 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-28 21:46:17 +03: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 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DynamicImage::IncrementAnimationConsumers() {}
|
|
|
|
|
|
|
|
void DynamicImage::DecrementAnimationConsumers() {}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
uint32_t DynamicImage::GetAnimationConsumers() { return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult DynamicImage::OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DynamicImage::OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsresult aStatus, bool aLastPart) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-16 11:06:06 +03:00
|
|
|
void DynamicImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) {}
|
2014-11-28 06:55:57 +03:00
|
|
|
|
2014-07-22 04:59:22 +04: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 03:42:56 +03:00
|
|
|
nsIURI* DynamicImage::GetURI() const { return nullptr; }
|
2014-07-22 04:59:22 +04: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;
|
|
|
|
}
|
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
nsresult DynamicImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2017-09-05 14:58:44 +03:00
|
|
|
size_t DynamicImage::GetNativeSizesLength() const { return 0; }
|
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetIntrinsicSize(nsSize* aSize) {
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize intSize(mDrawable->Size());
|
2014-07-22 04:59:22 +04:00
|
|
|
*aSize = nsSize(intSize.width, intSize.height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-03 02:28:21 +03:00
|
|
|
Maybe<AspectRatio> DynamicImage::GetIntrinsicRatio() {
|
|
|
|
auto size = mDrawable->Size();
|
|
|
|
return Some(AspectRatio::FromSize(size.width, size.height));
|
2014-07-22 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
DynamicImage::GetOrientation() { return Orientation(); }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetType(uint16_t* aType) {
|
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-02-13 22:13:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetProducerId(uint32_t* aId) {
|
|
|
|
*aId = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetAnimated(bool* aAnimated) {
|
|
|
|
*aAnimated = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2014-07-22 04:59:22 +04:00
|
|
|
DynamicImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize size(mDrawable->Size());
|
2015-09-19 23:34:09 +03:00
|
|
|
return GetFrameAtSize(IntSize(size.width, size.height), aWhichFrame, aFlags);
|
|
|
|
}
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2015-09-19 23:34:09 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
DynamicImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> dt =
|
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2019-11-12 21:22:33 +03:00
|
|
|
aSize, SurfaceFormat::OS_RGBA);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!dt || !dt->IsValid()) {
|
2015-03-26 05:39:00 +03:00
|
|
|
gfxWarning()
|
|
|
|
<< "DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget";
|
2015-03-09 22:48:20 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-07 02:39:56 +03:00
|
|
|
RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
|
2016-04-12 22:18:11 +03:00
|
|
|
MOZ_ASSERT(context); // already checked the draw target above
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2015-09-19 23:34:09 +03:00
|
|
|
auto result = Draw(context, aSize, ImageRegion::Create(aSize), aWhichFrame,
|
2017-01-03 08:53:22 +03:00
|
|
|
SamplingFilter::POINT, Nothing(), aFlags, 1.0);
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
return result == ImgDrawResult::SUCCESS ? dt->Snapshot() : nullptr;
|
2014-07-22 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2016-08-23 05:15:38 +03:00
|
|
|
DynamicImage::WillDrawOpaqueNow() { return false; }
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2015-05-13 10:23:44 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
DynamicImage::IsImageContainerAvailable(LayerManager* aManager,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 05:40:16 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
DynamicImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags) {
|
|
|
|
return nullptr;
|
2014-07-22 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:26 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
DynamicImage::IsImageContainerAvailableAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:48:21 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
|
|
|
DynamicImage::GetImageContainerAtSize(layers::LayerManager* aManager,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags,
|
|
|
|
layers::ImageContainer** aContainer) {
|
|
|
|
return ImgDrawResult::NOT_SUPPORTED;
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-07-22 04:59:22 +04:00
|
|
|
DynamicImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
|
2014-08-23 00:12:38 +04:00
|
|
|
const ImageRegion& aRegion, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2014-08-23 00:12:38 +04:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext, uint32_t aFlags,
|
2017-01-03 08:53:22 +03:00
|
|
|
float aOpacity) {
|
2014-08-23 00:12:38 +04:00
|
|
|
MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size");
|
|
|
|
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize drawableSize(mDrawable->Size());
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
if (aSize == drawableSize) {
|
2017-06-28 18:41:21 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
|
2019-11-12 21:22:33 +03:00
|
|
|
aRegion, SurfaceFormat::OS_RGBA, aSamplingFilter,
|
|
|
|
aOpacity);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2014-08-23 00:12:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxSize scale(double(aSize.width) / drawableSize.width,
|
|
|
|
double(aSize.height) / drawableSize.height);
|
|
|
|
|
|
|
|
ImageRegion region(aRegion);
|
|
|
|
region.Scale(1.0 / scale.width, 1.0 / scale.height);
|
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2017-06-28 18:41:21 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, SizeDouble(drawableSize),
|
2019-11-12 21:22:33 +03:00
|
|
|
region, SurfaceFormat::OS_RGBA, aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
aOpacity);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2014-07-22 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-05-21 20:34:14 +03:00
|
|
|
DynamicImage::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2019-05-21 20:34:14 +03:00
|
|
|
bool DynamicImage::StartDecodingWithResult(uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-23 10:07:45 +03:00
|
|
|
|
2019-05-21 20:34:14 +03:00
|
|
|
bool DynamicImage::RequestDecodeWithResult(uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-08 20:45:50 +03:00
|
|
|
|
2015-01-19 01:02:13 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-21 20:34:14 +03:00
|
|
|
DynamicImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
2015-01-19 01:02:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:59:22 +04: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 13:46:48 +03:00
|
|
|
|
2014-12-06 03:28:00 +03:00
|
|
|
nsIntSize DynamicImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aFlags) {
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize size(mDrawable->Size());
|
2014-07-29 01:27:40 +04:00
|
|
|
return nsIntSize(size.width, size.height);
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:59:22 +04: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 16:05:23 +03:00
|
|
|
void DynamicImage::PropagateUseCounters(dom::Document*) {
|
2015-06-03 20:42:07 +03:00
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|