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::LayerManager;
|
|
|
|
using mozilla::layers::ImageContainer;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2017-07-28 13:10:04 +03:00
|
|
|
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
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
2015-04-28 21:46:17 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2014-11-28 06:55:57 +03:00
|
|
|
void
|
2017-03-16 11:06:06 +03:00
|
|
|
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
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetIntrinsicRatio(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
DynamicImage::GetOrientation()
|
|
|
|
{
|
|
|
|
return Orientation();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetType(uint16_t* aType)
|
|
|
|
{
|
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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()->
|
2015-09-19 23:34:09 +03:00
|
|
|
CreateOffscreenContentDrawTarget(aSize, SurfaceFormat::B8G8R8A8);
|
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),
|
2017-01-03 08:53:22 +03:00
|
|
|
aWhichFrame, 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()
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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)
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
2015-03-18 05:40:16 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
DynamicImage::GetImageContainerAtSize(LayerManager* aManager,
|
|
|
|
const IntSize& aSize,
|
2017-11-17 22:08:52 +03:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 14:45:26 +03:00
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-07-22 04:59:22 +04:00
|
|
|
DynamicImage::Draw(gfxContext* aContext,
|
2014-08-23 00:12:38 +04:00
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2014-07-22 04:59:22 +04:00
|
|
|
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,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
float aOpacity)
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
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), aRegion,
|
2017-01-03 08:53:22 +03:00
|
|
|
SurfaceFormat::B8G8R8A8, 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), region,
|
2017-01-03 08:53:22 +03:00
|
|
|
SurfaceFormat::B8G8R8A8, aSamplingFilter,
|
|
|
|
aOpacity);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2014-07-22 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-11-26 10:56:26 +03:00
|
|
|
DynamicImage::StartDecoding(uint32_t aFlags)
|
2014-07-22 04:59:22 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-12-23 10:07:45 +03:00
|
|
|
bool
|
|
|
|
DynamicImage::StartDecodingWithResult(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-19 01:02:13 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{ }
|
|
|
|
|
2014-07-29 01:27:40 +04:00
|
|
|
nsIntSize
|
2014-12-06 03:28:00 +03:00
|
|
|
DynamicImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aFlags)
|
2014-07-29 01:27:40 +04:00
|
|
|
{
|
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();
|
|
|
|
}
|
|
|
|
|
2015-06-03 20:42:07 +03:00
|
|
|
void
|
|
|
|
DynamicImage::PropagateUseCounters(nsIDocument*)
|
|
|
|
{
|
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|