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"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2014-07-22 00:59:22 +00:00
|
|
|
#include "Orientation.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "SVGImageContext.h"
|
2014-07-22 00:59:22 +00: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 04:10:47 +00:00
|
|
|
already_AddRefed<ProgressTracker>
|
|
|
|
DynamicImage::GetProgressTracker()
|
2014-07-22 00:59:22 +00:00
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2014-11-27 02:00:15 +00:00
|
|
|
DynamicImage::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) 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
|
2014-07-22 00:59:22 +00:00
|
|
|
{
|
2015-04-28 18:46:17 +00:00
|
|
|
// 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,
|
|
|
|
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 03:55:57 +00:00
|
|
|
void
|
|
|
|
DynamicImage::OnSurfaceDiscarded()
|
|
|
|
{ }
|
|
|
|
|
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()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ImageURL*
|
|
|
|
DynamicImage::GetURI()
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetIntrinsicSize(nsSize* aSize)
|
|
|
|
{
|
|
|
|
gfxIntSize intSize(mDrawable->Size());
|
|
|
|
*aSize = nsSize(intSize.width, intSize.height);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::GetIntrinsicRatio(nsSize* aSize)
|
|
|
|
{
|
|
|
|
gfxIntSize intSize(mDrawable->Size());
|
|
|
|
*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 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)
|
|
|
|
{
|
|
|
|
gfxIntSize size(mDrawable->Size());
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenContentDrawTarget(IntSize(size.width, size.height),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2015-03-09 19:48:20 +00:00
|
|
|
if (!dt) {
|
2015-03-26 02:39:00 +00:00
|
|
|
gfxWarning() <<
|
|
|
|
"DynamicImage::GetFrame failed in CreateOffscreenContentDrawTarget";
|
2015-03-09 19:48:20 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-07-22 00:59:22 +00:00
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(dt);
|
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
auto result = Draw(context, size, ImageRegion::Create(size),
|
2014-08-22 20:12:38 +00:00
|
|
|
aWhichFrame, GraphicsFilter::FILTER_NEAREST,
|
|
|
|
Nothing(), aFlags);
|
2014-07-22 00:59:22 +00:00
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
return result == DrawResult::SUCCESS ? dt->Snapshot() : nullptr;
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
2014-11-25 07:42:43 +00:00
|
|
|
DynamicImage::IsOpaque()
|
2014-07-22 00:59:22 +00:00
|
|
|
{
|
|
|
|
// XXX(seth): For performance reasons it'd be better to return true here, but
|
|
|
|
// I'm not sure how we can guarantee it for an arbitrary gfxDrawable.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-05-13 07:23:44 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
DynamicImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-18 02:40:16 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
DynamicImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
2014-07-22 00:59:22 +00:00
|
|
|
{
|
2015-03-18 02:40:16 +00:00
|
|
|
return nullptr;
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
NS_IMETHODIMP_(DrawResult)
|
2014-07-22 00:59:22 +00:00
|
|
|
DynamicImage::Draw(gfxContext* aContext,
|
2014-08-22 20:12:38 +00:00
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2014-07-22 00:59:22 +00:00
|
|
|
uint32_t aWhichFrame,
|
2014-08-22 20:12:38 +00:00
|
|
|
GraphicsFilter aFilter,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2014-07-22 00:59:22 +00:00
|
|
|
uint32_t aFlags)
|
|
|
|
{
|
2014-08-22 20:12:38 +00:00
|
|
|
MOZ_ASSERT(!aSize.IsEmpty(), "Unexpected empty size");
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
gfxIntSize drawableSize(mDrawable->Size());
|
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
if (aSize == drawableSize) {
|
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, drawableSize, aRegion,
|
|
|
|
SurfaceFormat::B8G8R8A8, aFilter);
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2014-08-22 20:12:38 +00: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 00:59:22 +00:00
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, mDrawable, drawableSize, region,
|
|
|
|
SurfaceFormat::B8G8R8A8, aFilter);
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2014-07-22 00:59:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::RequestDecode()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::StartDecoding()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DynamicImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{ }
|
|
|
|
|
2014-07-28 21:27:40 +00:00
|
|
|
nsIntSize
|
2014-12-06 00:28:00 +00:00
|
|
|
DynamicImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
GraphicsFilter aFilter, uint32_t aFlags)
|
2014-07-28 21:27:40 +00:00
|
|
|
{
|
|
|
|
gfxIntSize size(mDrawable->Size());
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-06-03 17:42:07 +00:00
|
|
|
void
|
|
|
|
DynamicImage::PropagateUseCounters(nsIDocument*)
|
|
|
|
{
|
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2014-07-22 00:59:22 +00:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|