2010-09-08 20:40:39 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
#include "VectorImage.h"
|
2011-10-15 07:33:26 +00:00
|
|
|
|
2014-02-09 08:04:37 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2010-09-08 20:40:39 +00:00
|
|
|
#include "gfxContext.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "gfxDrawable.h"
|
2013-10-22 11:38:08 +00:00
|
|
|
#include "gfxPlatform.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "gfxUtils.h"
|
2014-09-14 22:22:45 +00:00
|
|
|
#include "imgFrame.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2014-03-05 16:10:34 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
2013-08-23 17:56:20 +00:00
|
|
|
#include "nsIDOMEvent.h"
|
2010-09-08 20:40:39 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIStreamListener.h"
|
2013-01-08 21:40:47 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsRect.h"
|
2014-05-08 09:53:00 +00:00
|
|
|
#include "nsString.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "nsStubDocumentObserver.h"
|
2010-09-08 20:40:39 +00:00
|
|
|
#include "nsSVGEffects.h" // for nsSVGRenderingObserver
|
2014-05-08 09:53:00 +00:00
|
|
|
#include "nsWindowMemoryReporter.h"
|
2014-08-22 20:12:38 +00:00
|
|
|
#include "ImageRegion.h"
|
2013-08-25 07:19:42 +00:00
|
|
|
#include "Orientation.h"
|
2013-03-17 07:55:13 +00:00
|
|
|
#include "SVGDocumentWrapper.h"
|
2013-08-29 21:18:25 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2013-10-22 11:38:08 +00:00
|
|
|
#include "SurfaceCache.h"
|
2010-09-08 20:40:40 +00:00
|
|
|
|
2013-11-19 06:03:36 +00:00
|
|
|
// undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
|
|
|
|
#undef GetCurrentTime
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
namespace mozilla {
|
2011-10-15 07:33:26 +00:00
|
|
|
|
|
|
|
using namespace dom;
|
2014-02-09 08:04:37 +00:00
|
|
|
using namespace gfx;
|
2012-11-28 02:34:45 +00:00
|
|
|
using namespace layers;
|
2011-10-15 07:33:26 +00:00
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2010-09-08 20:40:40 +00:00
|
|
|
// Helper-class: SVGRootRenderingObserver
|
2015-03-21 16:28:04 +00:00
|
|
|
class SVGRootRenderingObserver final : public nsSVGRenderingObserver {
|
2010-09-08 20:40:40 +00:00
|
|
|
public:
|
|
|
|
SVGRootRenderingObserver(SVGDocumentWrapper* aDocWrapper,
|
|
|
|
VectorImage* aVectorImage)
|
2013-06-21 20:32:34 +00:00
|
|
|
: nsSVGRenderingObserver()
|
|
|
|
, mDocWrapper(aDocWrapper)
|
|
|
|
, mVectorImage(aVectorImage)
|
|
|
|
, mHonoringInvalidations(true)
|
2010-09-08 20:40:40 +00:00
|
|
|
{
|
2013-03-01 06:44:59 +00:00
|
|
|
MOZ_ASSERT(mDocWrapper, "Need a non-null SVG document wrapper");
|
|
|
|
MOZ_ASSERT(mVectorImage, "Need a non-null VectorImage");
|
|
|
|
|
2010-09-08 20:40:40 +00:00
|
|
|
StartListening();
|
|
|
|
Element* elem = GetTarget();
|
2013-03-01 06:44:59 +00:00
|
|
|
MOZ_ASSERT(elem, "no root SVG node for us to observe");
|
|
|
|
|
|
|
|
nsSVGEffects::AddRenderingObserver(elem, this);
|
|
|
|
mInObserverList = true;
|
2010-09-08 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SVGRootRenderingObserver()
|
|
|
|
{
|
|
|
|
StopListening();
|
|
|
|
}
|
|
|
|
|
2013-06-21 20:32:34 +00:00
|
|
|
void ResumeHonoringInvalidations()
|
|
|
|
{
|
|
|
|
mHonoringInvalidations = true;
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:40 +00:00
|
|
|
protected:
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual Element* GetTarget() override
|
2010-09-08 20:40:40 +00:00
|
|
|
{
|
|
|
|
return mDocWrapper->GetRootSVGElem();
|
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void DoUpdate() override
|
2010-09-08 20:40:40 +00:00
|
|
|
{
|
|
|
|
Element* elem = GetTarget();
|
2013-03-01 06:44:59 +00:00
|
|
|
MOZ_ASSERT(elem, "missing root SVG node");
|
2010-09-08 20:40:40 +00:00
|
|
|
|
2013-06-21 20:32:34 +00:00
|
|
|
if (mHonoringInvalidations && !mDocWrapper->ShouldIgnoreInvalidation()) {
|
2010-09-08 20:40:40 +00:00
|
|
|
nsIFrame* frame = elem->GetPrimaryFrame();
|
|
|
|
if (!frame || frame->PresContext()->PresShell()->IsDestroying()) {
|
|
|
|
// We're being destroyed. Bail out.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-21 20:32:34 +00:00
|
|
|
// Ignore further invalidations until we draw.
|
|
|
|
mHonoringInvalidations = false;
|
|
|
|
|
2013-09-04 10:39:30 +00:00
|
|
|
mVectorImage->InvalidateObserversOnNextRefreshDriverTick();
|
2013-03-21 18:22:42 +00:00
|
|
|
}
|
2013-06-21 20:32:33 +00:00
|
|
|
|
2013-06-21 20:32:34 +00:00
|
|
|
// Our caller might've removed us from rendering-observer list.
|
|
|
|
// Add ourselves back!
|
|
|
|
if (!mInObserverList) {
|
|
|
|
nsSVGEffects::AddRenderingObserver(elem, this);
|
|
|
|
mInObserverList = true;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Private data
|
2013-03-01 06:44:59 +00:00
|
|
|
const nsRefPtr<SVGDocumentWrapper> mDocWrapper;
|
|
|
|
VectorImage* const mVectorImage; // Raw pointer because it owns me.
|
2013-06-21 20:32:34 +00:00
|
|
|
bool mHonoringInvalidations;
|
2010-09-08 20:40:40 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class SVGParseCompleteListener final : public nsStubDocumentObserver {
|
2013-02-14 02:04:08 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
SVGParseCompleteListener(nsIDocument* aDocument,
|
|
|
|
VectorImage* aImage)
|
|
|
|
: mDocument(aDocument)
|
|
|
|
, mImage(aImage)
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mDocument, "Need an SVG document");
|
|
|
|
MOZ_ASSERT(mImage, "Need an image");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
mDocument->AddObserver(this);
|
|
|
|
}
|
|
|
|
|
2014-06-23 18:49:08 +00:00
|
|
|
private:
|
2013-02-14 02:04:08 +00:00
|
|
|
~SVGParseCompleteListener()
|
2013-03-29 20:14:19 +00:00
|
|
|
{
|
2013-02-14 02:04:08 +00:00
|
|
|
if (mDocument) {
|
|
|
|
// The document must have been destroyed before we got our event.
|
|
|
|
// Otherwise this can't happen, since documents hold strong references to
|
|
|
|
// their observers.
|
|
|
|
Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 18:49:08 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
void EndLoad(nsIDocument* aDocument) override
|
2013-02-14 02:04:08 +00:00
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(aDocument == mDocument, "Got EndLoad for wrong document?");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
// OnSVGDocumentParsed will release our owner's reference to us, so ensure
|
|
|
|
// we stick around long enough to complete our work.
|
|
|
|
nsRefPtr<SVGParseCompleteListener> kungFuDeathGroup(this);
|
|
|
|
|
|
|
|
mImage->OnSVGDocumentParsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel()
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mDocument, "Duplicate call to Cancel");
|
2013-02-26 21:21:07 +00:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->RemoveObserver(this);
|
|
|
|
mDocument = nullptr;
|
|
|
|
}
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2013-03-01 06:44:59 +00:00
|
|
|
VectorImage* const mImage; // Raw pointer to owner.
|
2013-02-14 02:04:08 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(SVGParseCompleteListener, nsIDocumentObserver)
|
2013-02-14 02:04:08 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class SVGLoadEventListener final : public nsIDOMEventListener {
|
2013-02-14 02:04:08 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
SVGLoadEventListener(nsIDocument* aDocument,
|
|
|
|
VectorImage* aImage)
|
|
|
|
: mDocument(aDocument)
|
|
|
|
, mImage(aImage)
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mDocument, "Need an SVG document");
|
|
|
|
MOZ_ASSERT(mImage, "Need an image");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
|
|
|
|
this, true, false);
|
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("SVGAbort"), this, true,
|
|
|
|
false);
|
|
|
|
mDocument->AddEventListener(NS_LITERAL_STRING("SVGError"), this, true,
|
|
|
|
false);
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 18:49:08 +00:00
|
|
|
private:
|
2013-02-14 02:04:08 +00:00
|
|
|
~SVGLoadEventListener()
|
|
|
|
{
|
|
|
|
if (mDocument) {
|
|
|
|
// The document must have been destroyed before we got our event.
|
|
|
|
// Otherwise this can't happen, since documents hold strong references to
|
|
|
|
// their observers.
|
|
|
|
Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 18:49:08 +00:00
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override
|
2013-02-14 02:04:08 +00:00
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mDocument, "Need an SVG document. Received multiple events?");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
// OnSVGDocumentLoaded/OnSVGDocumentError will release our owner's reference
|
|
|
|
// to us, so ensure we stick around long enough to complete our work.
|
|
|
|
nsRefPtr<SVGLoadEventListener> kungFuDeathGroup(this);
|
|
|
|
|
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(eventType.EqualsLiteral("MozSVGAsImageDocumentLoad") ||
|
|
|
|
eventType.EqualsLiteral("SVGAbort") ||
|
|
|
|
eventType.EqualsLiteral("SVGError"),
|
|
|
|
"Received unexpected event");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
if (eventType.EqualsLiteral("MozSVGAsImageDocumentLoad")) {
|
|
|
|
mImage->OnSVGDocumentLoaded();
|
|
|
|
} else {
|
|
|
|
mImage->OnSVGDocumentError();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cancel()
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mDocument, "Duplicate call to Cancel");
|
2013-02-26 21:21:07 +00:00
|
|
|
if (mDocument) {
|
2015-04-04 19:58:00 +00:00
|
|
|
mDocument
|
|
|
|
->RemoveEventListener(NS_LITERAL_STRING("MozSVGAsImageDocumentLoad"),
|
|
|
|
this, true);
|
2013-02-26 21:21:07 +00:00
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("SVGAbort"), this, true);
|
|
|
|
mDocument->RemoveEventListener(NS_LITERAL_STRING("SVGError"), this, true);
|
|
|
|
mDocument = nullptr;
|
|
|
|
}
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIDocument> mDocument;
|
2013-03-01 06:44:59 +00:00
|
|
|
VectorImage* const mImage; // Raw pointer to owner.
|
2013-02-14 02:04:08 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(SVGLoadEventListener, nsIDOMEventListener)
|
2013-02-14 02:04:08 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
// Helper-class: SVGDrawingCallback
|
|
|
|
class SVGDrawingCallback : public gfxDrawingCallback {
|
|
|
|
public:
|
|
|
|
SVGDrawingCallback(SVGDocumentWrapper* aSVGDocumentWrapper,
|
2015-04-21 15:04:57 +00:00
|
|
|
const IntRect& aViewport,
|
2014-08-22 20:12:38 +00:00
|
|
|
const IntSize& aSize,
|
|
|
|
uint32_t aImageFlags)
|
|
|
|
: mSVGDocumentWrapper(aSVGDocumentWrapper)
|
|
|
|
, mViewport(aViewport)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mImageFlags(aImageFlags)
|
2015-04-04 19:58:00 +00:00
|
|
|
{ }
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool operator()(gfxContext* aContext,
|
2014-12-16 03:50:02 +00:00
|
|
|
const gfxRect& aFillRect,
|
|
|
|
const GraphicsFilter& aFilter,
|
|
|
|
const gfxMatrix& aTransform);
|
2010-09-08 20:40:39 +00:00
|
|
|
private:
|
|
|
|
nsRefPtr<SVGDocumentWrapper> mSVGDocumentWrapper;
|
2015-04-21 15:04:57 +00:00
|
|
|
const IntRect mViewport;
|
2014-08-22 20:12:38 +00:00
|
|
|
const IntSize mSize;
|
|
|
|
uint32_t mImageFlags;
|
2010-09-08 20:40:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Based loosely on nsSVGIntegrationUtils' PaintFrameCallback::operator()
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-09-08 20:40:39 +00:00
|
|
|
SVGDrawingCallback::operator()(gfxContext* aContext,
|
|
|
|
const gfxRect& aFillRect,
|
2013-10-01 21:01:19 +00:00
|
|
|
const GraphicsFilter& aFilter,
|
2010-09-08 20:40:39 +00:00
|
|
|
const gfxMatrix& aTransform)
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mSVGDocumentWrapper, "need an SVGDocumentWrapper");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
// Get (& sanity-check) the helper-doc's presShell
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
if (NS_FAILED(mSVGDocumentWrapper->GetPresShell(getter_AddRefs(presShell)))) {
|
|
|
|
NS_WARNING("Unable to draw -- presShell lookup failed");
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(presShell, "GetPresShell succeeded but returned null");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2011-01-24 18:32:34 +00:00
|
|
|
gfxContextAutoSaveRestore contextRestorer(aContext);
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
// Clip to aFillRect so that we don't paint outside.
|
|
|
|
aContext->NewPath();
|
|
|
|
aContext->Rectangle(aFillRect);
|
|
|
|
aContext->Clip();
|
|
|
|
|
2014-07-11 07:06:39 +00:00
|
|
|
gfxMatrix matrix = aTransform;
|
|
|
|
if (!matrix.Invert()) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-11 06:57:38 +00:00
|
|
|
aContext->SetMatrix(
|
|
|
|
aContext->CurrentMatrix().PreMultiply(matrix).
|
|
|
|
Scale(double(mSize.width) / mViewport.width,
|
|
|
|
double(mSize.height) / mViewport.height));
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
nsPresContext* presContext = presShell->GetPresContext();
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(presContext, "pres shell w/out pres context");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
nsRect svgRect(presContext->DevPixelsToAppUnits(mViewport.x),
|
|
|
|
presContext->DevPixelsToAppUnits(mViewport.y),
|
|
|
|
presContext->DevPixelsToAppUnits(mViewport.width),
|
|
|
|
presContext->DevPixelsToAppUnits(mViewport.height));
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t renderDocFlags = nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING;
|
2010-09-08 20:40:39 +00:00
|
|
|
if (!(mImageFlags & imgIContainer::FLAG_SYNC_DECODE)) {
|
|
|
|
renderDocFlags |= nsIPresShell::RENDER_ASYNC_DECODE_IMAGES;
|
|
|
|
}
|
|
|
|
|
|
|
|
presShell->RenderDocument(svgRect, renderDocFlags,
|
|
|
|
NS_RGBA(0, 0, 0, 0), // transparent
|
|
|
|
aContext);
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Implement VectorImage's nsISupports-inherited methods
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(VectorImage,
|
|
|
|
imgIContainer,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Constructor / Destructor
|
|
|
|
|
2015-04-28 23:32:02 +00:00
|
|
|
VectorImage::VectorImage(ImageURL* aURI /* = nullptr */) :
|
2013-09-28 18:28:44 +00:00
|
|
|
ImageResource(aURI), // invoke superclass's constructor
|
2015-03-28 03:17:23 +00:00
|
|
|
mLockCount(0),
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInitialized(false),
|
|
|
|
mIsFullyLoaded(false),
|
|
|
|
mIsDrawing(false),
|
2013-09-04 10:39:30 +00:00
|
|
|
mHaveAnimations(false),
|
|
|
|
mHasPendingInvalidation(false)
|
2015-04-28 23:32:02 +00:00
|
|
|
{ }
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
VectorImage::~VectorImage()
|
|
|
|
{
|
2013-02-26 01:40:13 +00:00
|
|
|
CancelAllListeners();
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Methods inherited from Image.h
|
|
|
|
|
|
|
|
nsresult
|
2013-02-13 03:00:03 +00:00
|
|
|
VectorImage::Init(const char* aMimeType,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2010-09-08 20:40:39 +00:00
|
|
|
// We don't support re-initialization
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mIsInitialized) {
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-04-05 21:15:05 +00:00
|
|
|
MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations && !mError,
|
2013-03-01 06:45:00 +00:00
|
|
|
"Flags unexpectedly set before initialization");
|
|
|
|
MOZ_ASSERT(!strcmp(aMimeType, IMAGE_SVG_XML), "Unexpected mimetype");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-03-28 03:17:23 +00:00
|
|
|
mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
|
|
|
|
|
|
|
|
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
|
|
|
|
if (!mDiscardable) {
|
|
|
|
mLockCount++;
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsInitialized = true;
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 03:51:48 +00:00
|
|
|
size_t
|
2014-11-27 02:00:15 +00:00
|
|
|
VectorImage::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
|
2014-11-26 09:37:57 +00:00
|
|
|
{
|
2014-11-26 10:56:28 +00:00
|
|
|
nsIDocument* doc = mSVGDocumentWrapper->GetDocument();
|
|
|
|
if (!doc) {
|
2014-11-27 02:00:15 +00:00
|
|
|
return 0; // No document, so no memory used for the document.
|
2014-11-26 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 02:00:15 +00:00
|
|
|
nsWindowSizes windowSizes(aMallocSizeOf);
|
|
|
|
doc->DocAddSizeOfIncludingThis(&windowSizes);
|
|
|
|
|
|
|
|
if (windowSizes.getTotalSize() == 0) {
|
|
|
|
// MallocSizeOf fails on this platform. Because we also use this method for
|
|
|
|
// determining the size of cache entries, we need to return something
|
|
|
|
// reasonable here. Unfortunately, there's no way to estimate the document's
|
|
|
|
// size accurately, so we just use a constant value of 100KB, which will
|
|
|
|
// generally underestimate the true size.
|
|
|
|
return 100 * 1024;
|
2014-11-26 10:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return windowSizes.getTotalSize();
|
2014-11-26 09:37:57 +00:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
void
|
|
|
|
VectorImage::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const
|
2014-11-27 02:00:15 +00:00
|
|
|
{
|
2015-04-28 18:46:17 +00:00
|
|
|
SurfaceCache::CollectSizeOfSurfaces(ImageKey(this), aCounters, aMallocSizeOf);
|
2014-11-27 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 22:05:18 +00:00
|
|
|
nsresult
|
|
|
|
VectorImage::OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
2013-02-14 02:41:10 +00:00
|
|
|
nsresult aStatus,
|
|
|
|
bool aLastPart)
|
2012-12-17 22:05:18 +00:00
|
|
|
{
|
2013-02-14 02:41:10 +00:00
|
|
|
// Call our internal OnStopRequest method, which only talks to our embedded
|
2014-11-15 04:10:47 +00:00
|
|
|
// SVG document. This won't have any effect on our ProgressTracker.
|
2013-02-14 02:41:10 +00:00
|
|
|
nsresult finalStatus = OnStopRequest(aRequest, aContext, aStatus);
|
|
|
|
|
|
|
|
// Give precedence to Necko failure codes.
|
2015-04-04 19:58:00 +00:00
|
|
|
if (NS_FAILED(aStatus)) {
|
2013-02-14 02:41:10 +00:00
|
|
|
finalStatus = aStatus;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2015-06-18 21:48:41 +00:00
|
|
|
|
|
|
|
Progress loadProgress = LoadCompleteProgress(aLastPart, mError, finalStatus);
|
2013-02-14 02:41:10 +00:00
|
|
|
|
2015-06-18 21:48:41 +00:00
|
|
|
if (mIsFullyLoaded || mError) {
|
|
|
|
// Our document is loaded, so we're ready to notify now.
|
|
|
|
mProgressTracker->SyncNotifyProgress(loadProgress);
|
|
|
|
} else {
|
|
|
|
// Record our progress so far; we'll actually send the notifications in
|
|
|
|
// OnSVGDocumentLoaded or OnSVGDocumentError.
|
|
|
|
mLoadProgress = Some(loadProgress);
|
2013-02-12 00:34:20 +00:00
|
|
|
}
|
2015-06-18 21:48:41 +00:00
|
|
|
|
2013-02-14 02:41:10 +00:00
|
|
|
return finalStatus;
|
2012-12-17 22:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
VectorImage::OnImageDataAvailable(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount)
|
|
|
|
{
|
|
|
|
return OnDataAvailable(aRequest, aContext, aInStr, aSourceOffset, aCount);
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
nsresult
|
|
|
|
VectorImage::StartAnimation()
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError) {
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
mSVGDocumentWrapper->StartAnimation();
|
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
VectorImage::StopAnimation()
|
|
|
|
{
|
2013-09-20 12:12:10 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mError) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mIsFullyLoaded && mHaveAnimations,
|
|
|
|
"Should not have been animating!");
|
|
|
|
|
|
|
|
mSVGDocumentWrapper->StopAnimation();
|
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-09-20 12:12:10 +00:00
|
|
|
mAnimating = false;
|
|
|
|
return rv;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-05 13:57:16 +00:00
|
|
|
bool
|
2010-11-17 20:39:23 +00:00
|
|
|
VectorImage::ShouldAnimate()
|
|
|
|
{
|
2012-12-19 22:24:32 +00:00
|
|
|
return ImageResource::ShouldAnimate() && mIsFullyLoaded && mHaveAnimations;
|
2010-11-17 20:39:23 +00:00
|
|
|
}
|
|
|
|
|
2013-05-17 20:57:20 +00:00
|
|
|
NS_IMETHODIMP_(void)
|
2014-07-10 15:00:31 +00:00
|
|
|
VectorImage::SetAnimationStartTime(const TimeStamp& aTime)
|
2013-05-17 20:57:20 +00:00
|
|
|
{
|
|
|
|
// We don't care about animation start time.
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// imgIContainer methods
|
|
|
|
|
|
|
|
//******************************************************************************
|
2012-08-22 15:56:38 +00:00
|
|
|
/* readonly attribute int32_t width; */
|
2010-09-08 20:40:39 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
VectorImage::GetWidth(int32_t* aWidth)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2010-09-08 20:40:39 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2015-01-20 19:12:54 +00:00
|
|
|
*aWidth = -1;
|
|
|
|
} else {
|
|
|
|
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
|
|
|
|
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
|
|
|
|
"loading without errors");
|
|
|
|
*aWidth = rootElem->GetIntrinsicWidth();
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
2015-01-20 19:12:54 +00:00
|
|
|
return *aWidth >= 0 ? NS_OK : NS_ERROR_FAILURE;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2011-11-09 21:39:15 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* [notxpcom] void requestRefresh ([const] in TimeStamp aTime); */
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-07-10 15:00:31 +00:00
|
|
|
VectorImage::RequestRefresh(const TimeStamp& aTime)
|
2011-11-09 21:39:15 +00:00
|
|
|
{
|
2014-05-08 18:37:39 +00:00
|
|
|
if (HadRecentRefresh(aTime)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-17 20:57:26 +00:00
|
|
|
EvaluateAnimation();
|
2013-09-04 10:39:30 +00:00
|
|
|
|
2014-05-01 16:31:54 +00:00
|
|
|
mSVGDocumentWrapper->TickRefreshDriver();
|
|
|
|
|
2013-11-21 01:21:50 +00:00
|
|
|
if (mHasPendingInvalidation) {
|
|
|
|
SendInvalidationNotifications();
|
|
|
|
mHasPendingInvalidation = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VectorImage::SendInvalidationNotifications()
|
|
|
|
{
|
|
|
|
// Animated images don't send out invalidation notifications as soon as
|
|
|
|
// they're generated. Instead, InvalidateObserversOnNextRefreshDriverTick
|
|
|
|
// records that there are pending invalidations and then returns immediately.
|
|
|
|
// The notifications are actually sent from RequestRefresh(). We send these
|
|
|
|
// notifications there to ensure that there is actually a document observing
|
|
|
|
// us. Otherwise, the notifications are just wasted effort.
|
|
|
|
//
|
|
|
|
// Non-animated images call this method directly from
|
|
|
|
// InvalidateObserversOnNextRefreshDriverTick, because RequestRefresh is never
|
|
|
|
// called for them. Ordinarily this isn't needed, since we send out
|
|
|
|
// invalidation notifications in OnSVGDocumentLoaded, but in rare cases the
|
|
|
|
// SVG document may not be 100% ready to render at that time. In those cases
|
|
|
|
// we would miss the subsequent invalidations if we didn't send out the
|
|
|
|
// notifications directly in |InvalidateObservers...|.
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
if (mProgressTracker) {
|
2014-11-26 21:22:10 +00:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2014-11-17 22:29:56 +00:00
|
|
|
mProgressTracker->SyncNotifyProgress(FLAG_FRAME_COMPLETE,
|
2015-04-21 15:04:57 +00:00
|
|
|
GetMaxSizedIntRect());
|
2013-09-04 10:39:30 +00:00
|
|
|
}
|
2011-11-09 21:39:15 +00:00
|
|
|
}
|
|
|
|
|
2015-04-21 15:04:57 +00:00
|
|
|
NS_IMETHODIMP_(IntRect)
|
|
|
|
VectorImage::GetImageSpaceInvalidationRect(const IntRect& aRect)
|
2014-06-26 23:02:04 +00:00
|
|
|
{
|
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
2012-08-22 15:56:38 +00:00
|
|
|
/* readonly attribute int32_t height; */
|
2010-09-08 20:40:39 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
VectorImage::GetHeight(int32_t* aHeight)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2010-09-08 20:40:39 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2015-01-20 19:12:54 +00:00
|
|
|
*aHeight = -1;
|
|
|
|
} else {
|
|
|
|
SVGSVGElement* rootElem = mSVGDocumentWrapper->GetRootSVGElem();
|
|
|
|
MOZ_ASSERT(rootElem, "Should have a root SVG elem, since we finished "
|
|
|
|
"loading without errors");
|
|
|
|
*aHeight = rootElem->GetIntrinsicHeight();
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
2015-01-20 19:12:54 +00:00
|
|
|
return *aHeight >= 0 ? NS_OK : NS_ERROR_FAILURE;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2013-01-11 03:38:34 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* [noscript] readonly attribute nsSize intrinsicSize; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::GetIntrinsicSize(nsSize* aSize)
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2013-01-11 03:38:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-01-11 03:38:34 +00:00
|
|
|
|
2013-02-28 20:22:46 +00:00
|
|
|
nsIFrame* rootFrame = mSVGDocumentWrapper->GetRootLayoutFrame();
|
2015-04-04 19:58:00 +00:00
|
|
|
if (!rootFrame) {
|
2013-07-22 20:42:05 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-07-22 20:42:05 +00:00
|
|
|
|
2013-01-11 03:38:34 +00:00
|
|
|
*aSize = nsSize(-1, -1);
|
2013-09-30 21:26:04 +00:00
|
|
|
IntrinsicSize rfSize = rootFrame->GetIntrinsicSize();
|
2015-04-04 19:58:00 +00:00
|
|
|
if (rfSize.width.GetUnit() == eStyleUnit_Coord) {
|
2013-01-11 03:38:34 +00:00
|
|
|
aSize->width = rfSize.width.GetCoordValue();
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
|
|
|
if (rfSize.height.GetUnit() == eStyleUnit_Coord) {
|
2013-01-11 03:38:34 +00:00
|
|
|
aSize->height = rfSize.height.GetCoordValue();
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-01-11 03:38:34 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* [noscript] readonly attribute nsSize intrinsicRatio; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2013-01-11 03:38:34 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-01-11 03:38:34 +00:00
|
|
|
|
2013-02-28 20:22:46 +00:00
|
|
|
nsIFrame* rootFrame = mSVGDocumentWrapper->GetRootLayoutFrame();
|
2015-04-04 19:58:00 +00:00
|
|
|
if (!rootFrame) {
|
2013-07-22 20:42:05 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-07-22 20:42:05 +00:00
|
|
|
|
2013-01-11 03:38:34 +00:00
|
|
|
*aRatio = rootFrame->GetIntrinsicRatio();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-25 07:19:42 +00:00
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
VectorImage::GetOrientation()
|
|
|
|
{
|
|
|
|
return Orientation();
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* readonly attribute unsigned short type; */
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
VectorImage::GetType(uint16_t* aType)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2010-12-07 18:40:28 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
|
2015-03-19 14:12:52 +00:00
|
|
|
*aType = imgIContainer::TYPE_VECTOR;
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* readonly attribute boolean animated; */
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
VectorImage::GetAnimated(bool* aAnimated)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
*aAnimated = mSVGDocumentWrapper->IsAnimated();
|
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-17 17:42:20 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* [notxpcom] int32_t getFirstFrameDelay (); */
|
|
|
|
int32_t
|
|
|
|
VectorImage::GetFirstFrameDelay()
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError) {
|
2013-05-17 17:42:20 +00:00
|
|
|
return -1;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-05-17 17:42:20 +00:00
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
if (!mSVGDocumentWrapper->IsAnimated()) {
|
2013-05-17 17:42:20 +00:00
|
|
|
return -1;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-05-17 17:42:20 +00:00
|
|
|
|
|
|
|
// We don't really have a frame delay, so just pretend that we constantly
|
|
|
|
// need updates.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-04 22:22:30 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
2014-11-25 07:42:43 +00:00
|
|
|
VectorImage::IsOpaque()
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2013-02-04 22:22:30 +00:00
|
|
|
return false; // In general, SVG content is not opaque.
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
2014-04-15 18:02:23 +00:00
|
|
|
/* [noscript] SourceSurface getFrame(in uint32_t aWhichFrame,
|
|
|
|
* in uint32_t aFlags; */
|
|
|
|
NS_IMETHODIMP_(TemporaryRef<SourceSurface>)
|
2012-08-22 15:56:38 +00:00
|
|
|
VectorImage::GetFrame(uint32_t aWhichFrame,
|
2013-12-13 08:34:24 +00:00
|
|
|
uint32_t aFlags)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2013-12-13 08:34:24 +00:00
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
|
2013-03-11 01:43:37 +00:00
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
2013-12-13 08:34:24 +00:00
|
|
|
return nullptr;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError || !mIsFullyLoaded) {
|
2013-12-13 08:34:24 +00:00
|
|
|
return nullptr;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2010-10-12 19:00:30 +00:00
|
|
|
// Look up height & width
|
|
|
|
// ----------------------
|
2015-01-20 19:12:54 +00:00
|
|
|
SVGSVGElement* svgElem = mSVGDocumentWrapper->GetRootSVGElem();
|
|
|
|
MOZ_ASSERT(svgElem, "Should have a root SVG elem, since we finished "
|
|
|
|
"loading without errors");
|
|
|
|
nsIntSize imageIntSize(svgElem->GetIntrinsicWidth(),
|
|
|
|
svgElem->GetIntrinsicHeight());
|
2015-04-04 19:58:00 +00:00
|
|
|
|
2015-01-20 19:12:54 +00:00
|
|
|
if (imageIntSize.IsEmpty()) {
|
|
|
|
// We'll get here if our SVG doc has a percent-valued or negative width or
|
|
|
|
// height.
|
2013-12-13 08:34:24 +00:00
|
|
|
return nullptr;
|
2010-10-12 19:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make our surface the size of what will ultimately be drawn to it.
|
|
|
|
// (either the full image size, or the restricted region)
|
2014-04-15 18:02:23 +00:00
|
|
|
RefPtr<DrawTarget> dt = gfxPlatform::GetPlatform()->
|
|
|
|
CreateOffscreenContentDrawTarget(IntSize(imageIntSize.width,
|
2014-03-05 16:10:34 +00:00
|
|
|
imageIntSize.height),
|
|
|
|
SurfaceFormat::B8G8R8A8);
|
2014-05-31 10:26:04 +00:00
|
|
|
if (!dt) {
|
|
|
|
NS_ERROR("Could not create a DrawTarget");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-04-15 18:02:23 +00:00
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(dt);
|
2014-03-05 16:10:34 +00:00
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
auto result = Draw(context, imageIntSize,
|
2014-08-22 20:12:38 +00:00
|
|
|
ImageRegion::Create(imageIntSize),
|
|
|
|
aWhichFrame, GraphicsFilter::FILTER_NEAREST,
|
|
|
|
Nothing(), aFlags);
|
2010-10-12 19:00:30 +00:00
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
return result == DrawResult::SUCCESS ? dt->Snapshot() : nullptr;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 07:23:44 +00:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
VectorImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 23:39:48 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* [noscript] ImageContainer getImageContainer(); */
|
2015-03-18 02:40:16 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
|
|
VectorImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
2013-03-05 23:39:48 +00:00
|
|
|
{
|
2015-03-18 02:40:16 +00:00
|
|
|
return nullptr;
|
2013-03-05 23:39:48 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 11:38:08 +00:00
|
|
|
struct SVGDrawingParameters
|
|
|
|
{
|
|
|
|
SVGDrawingParameters(gfxContext* aContext,
|
2014-08-22 20:12:38 +00:00
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2013-10-22 11:38:08 +00:00
|
|
|
GraphicsFilter aFilter,
|
2014-08-22 20:12:38 +00:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2013-10-22 11:38:08 +00:00
|
|
|
float aAnimationTime,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: context(aContext)
|
2014-08-22 20:12:38 +00:00
|
|
|
, size(aSize.width, aSize.height)
|
|
|
|
, imageRect(0, 0, aSize.width, aSize.height)
|
|
|
|
, region(aRegion)
|
2013-10-22 11:38:08 +00:00
|
|
|
, filter(aFilter)
|
|
|
|
, svgContext(aSVGContext)
|
2015-04-03 19:48:12 +00:00
|
|
|
, viewportSize(aSize)
|
2014-08-22 20:12:38 +00:00
|
|
|
, animationTime(aAnimationTime)
|
2013-10-22 11:38:08 +00:00
|
|
|
, flags(aFlags)
|
2014-08-29 14:04:34 +00:00
|
|
|
, opacity(aSVGContext ? aSVGContext->GetGlobalOpacity() : 1.0)
|
2015-04-03 19:48:12 +00:00
|
|
|
{
|
|
|
|
if (aSVGContext) {
|
|
|
|
CSSIntSize sz = aSVGContext->GetViewportSize();
|
|
|
|
viewportSize = nsIntSize(sz.width, sz.height); // XXX losing unit
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 20:12:38 +00:00
|
|
|
|
|
|
|
gfxContext* context;
|
|
|
|
IntSize size;
|
|
|
|
IntRect imageRect;
|
|
|
|
ImageRegion region;
|
|
|
|
GraphicsFilter filter;
|
|
|
|
const Maybe<SVGImageContext>& svgContext;
|
|
|
|
nsIntSize viewportSize;
|
|
|
|
float animationTime;
|
|
|
|
uint32_t flags;
|
2014-08-29 14:04:34 +00:00
|
|
|
gfxFloat opacity;
|
2013-10-22 11:38:08 +00:00
|
|
|
};
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* [noscript] void draw(in gfxContext aContext,
|
2014-12-16 03:49:59 +00:00
|
|
|
* [const] in nsIntSize aSize,
|
|
|
|
* [const] in ImageRegion aRegion,
|
2013-03-11 01:43:37 +00:00
|
|
|
* in uint32_t aWhichFrame,
|
2014-12-16 03:49:59 +00:00
|
|
|
* in gfxGraphicsFilter aFilter,
|
|
|
|
* [const] in MaybeSVGImageContext aSVGContext,
|
2012-08-22 15:56:38 +00:00
|
|
|
* in uint32_t aFlags); */
|
2015-02-04 21:50:56 +00:00
|
|
|
NS_IMETHODIMP_(DrawResult)
|
2010-09-08 20:40:39 +00:00
|
|
|
VectorImage::Draw(gfxContext* aContext,
|
2014-08-22 20:12:38 +00:00
|
|
|
const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
2013-03-11 01:43:37 +00:00
|
|
|
uint32_t aWhichFrame,
|
2014-08-22 20:12:38 +00:00
|
|
|
GraphicsFilter aFilter,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aFlags)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2015-02-04 21:50:56 +00:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
|
|
|
return DrawResult::BAD_ARGS;
|
|
|
|
}
|
2013-03-11 01:43:37 +00:00
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
if (!aContext) {
|
|
|
|
return DrawResult::BAD_ARGS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mError) {
|
|
|
|
return DrawResult::BAD_IMAGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mIsFullyLoaded) {
|
|
|
|
return DrawResult::NOT_READY;
|
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2010-11-19 16:56:06 +00:00
|
|
|
if (mIsDrawing) {
|
|
|
|
NS_WARNING("Refusing to make re-entrant call to VectorImage::Draw");
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::TEMPORARY_ERROR;
|
2010-11-19 16:56:06 +00:00
|
|
|
}
|
2013-04-29 19:10:16 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
if (mAnimationConsumers == 0 && mProgressTracker) {
|
|
|
|
mProgressTracker->OnUnlockedDraw();
|
2013-04-29 19:10:16 +00:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:44:57 +00:00
|
|
|
AutoRestore<bool> autoRestoreIsDrawing(mIsDrawing);
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsDrawing = true;
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-04-04 19:58:00 +00:00
|
|
|
float animTime =
|
|
|
|
(aWhichFrame == FRAME_FIRST) ? 0.0f
|
|
|
|
: mSVGDocumentWrapper->GetCurrentTime();
|
2013-10-22 11:38:08 +00:00
|
|
|
AutoSVGRenderingState autoSVGState(aSVGContext, animTime,
|
2013-02-28 20:22:43 +00:00
|
|
|
mSVGDocumentWrapper->GetRootSVGElem());
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-10-22 11:38:08 +00:00
|
|
|
// Pack up the drawing parameters.
|
2014-08-22 20:12:38 +00:00
|
|
|
SVGDrawingParameters params(aContext, aSize, aRegion, aFilter,
|
|
|
|
aSVGContext, animTime, aFlags);
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2014-08-22 20:12:38 +00:00
|
|
|
if (aFlags & FLAG_BYPASS_SURFACE_CACHE) {
|
2014-09-14 22:22:45 +00:00
|
|
|
CreateSurfaceAndShow(params);
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2014-06-26 07:40:12 +00:00
|
|
|
}
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2015-06-03 06:51:36 +00:00
|
|
|
DrawableFrameRef frameRef =
|
2014-08-22 20:12:38 +00:00
|
|
|
SurfaceCache::Lookup(ImageKey(this),
|
2014-09-19 21:53:28 +00:00
|
|
|
VectorSurfaceKey(params.size,
|
|
|
|
params.svgContext,
|
|
|
|
params.animationTime));
|
2014-08-22 20:12:38 +00:00
|
|
|
|
2013-10-22 11:38:08 +00:00
|
|
|
// Draw.
|
2015-06-03 06:51:36 +00:00
|
|
|
if (frameRef) {
|
|
|
|
RefPtr<SourceSurface> surface = frameRef->GetSurface();
|
2015-02-04 00:38:39 +00:00
|
|
|
if (surface) {
|
|
|
|
nsRefPtr<gfxDrawable> svgDrawable =
|
2015-06-03 06:51:36 +00:00
|
|
|
new gfxSurfaceDrawable(surface, frameRef->GetSize());
|
2015-02-04 00:38:39 +00:00
|
|
|
Show(svgDrawable, params);
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2015-02-04 00:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We lost our surface due to some catastrophic event.
|
|
|
|
RecoverFromLossOfSurfaces();
|
2013-10-22 11:38:08 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2015-02-04 00:38:39 +00:00
|
|
|
CreateSurfaceAndShow(params);
|
|
|
|
|
2015-02-04 21:50:56 +00:00
|
|
|
return DrawResult::SUCCESS;
|
2013-10-22 11:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-14 22:22:45 +00:00
|
|
|
VectorImage::CreateSurfaceAndShow(const SVGDrawingParameters& aParams)
|
2013-10-22 11:38:08 +00:00
|
|
|
{
|
|
|
|
mSVGDocumentWrapper->UpdateViewportBounds(aParams.viewportSize);
|
|
|
|
mSVGDocumentWrapper->FlushImageTransformInvalidation();
|
2013-10-21 18:39:33 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
nsRefPtr<gfxDrawingCallback> cb =
|
|
|
|
new SVGDrawingCallback(mSVGDocumentWrapper,
|
2015-04-21 15:04:57 +00:00
|
|
|
IntRect(IntPoint(0, 0), aParams.viewportSize),
|
2014-08-22 20:12:38 +00:00
|
|
|
aParams.size,
|
2013-10-22 11:38:08 +00:00
|
|
|
aParams.flags);
|
|
|
|
|
2014-02-09 08:04:37 +00:00
|
|
|
nsRefPtr<gfxDrawable> svgDrawable =
|
2015-03-29 14:59:15 +00:00
|
|
|
new gfxCallbackDrawable(cb, aParams.size);
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2014-06-26 07:40:12 +00:00
|
|
|
bool bypassCache = bool(aParams.flags & FLAG_BYPASS_SURFACE_CACHE) ||
|
|
|
|
// Refuse to cache animated images:
|
|
|
|
// XXX(seth): We may remove this restriction in bug 922893.
|
|
|
|
mHaveAnimations ||
|
|
|
|
// The image is too big to fit in the cache:
|
2014-08-22 20:12:38 +00:00
|
|
|
!SurfaceCache::CanHold(aParams.size);
|
2015-04-04 19:58:00 +00:00
|
|
|
if (bypassCache) {
|
2014-08-06 22:43:25 +00:00
|
|
|
return Show(svgDrawable, aParams);
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2015-03-28 03:17:23 +00:00
|
|
|
// We're about to rerasterize, which may mean that some of the previous
|
|
|
|
// surfaces we've rasterized aren't useful anymore. We can allow them to
|
|
|
|
// expire from the cache by unlocking them here, and then sending out an
|
|
|
|
// invalidation. If this image is locked, any surfaces that are still useful
|
|
|
|
// will become locked again when Draw touches them, and the remainder will
|
|
|
|
// eventually expire.
|
|
|
|
SurfaceCache::UnlockSurfaces(ImageKey(this));
|
|
|
|
|
2014-09-14 22:22:45 +00:00
|
|
|
// Try to create an imgFrame, initializing the surface it contains by drawing
|
|
|
|
// our gfxDrawable into it. (We use FILTER_NEAREST since we never scale here.)
|
|
|
|
nsRefPtr<imgFrame> frame = new imgFrame;
|
|
|
|
nsresult rv =
|
2015-03-29 14:59:15 +00:00
|
|
|
frame->InitWithDrawable(svgDrawable, aParams.size,
|
2014-09-14 22:22:45 +00:00
|
|
|
SurfaceFormat::B8G8R8A8,
|
|
|
|
GraphicsFilter::FILTER_NEAREST, aParams.flags);
|
2013-10-21 18:39:33 +00:00
|
|
|
|
2014-09-14 22:22:45 +00:00
|
|
|
// If we couldn't create the frame, it was probably because it would end
|
2013-10-22 11:38:08 +00:00
|
|
|
// up way too big. Generally it also wouldn't fit in the cache, but the prefs
|
2013-11-13 04:32:29 +00:00
|
|
|
// could be set such that the cache isn't the limiting factor.
|
2015-04-04 19:58:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-08-06 22:43:25 +00:00
|
|
|
return Show(svgDrawable, aParams);
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2014-09-14 22:22:45 +00:00
|
|
|
// Take a strong reference to the frame's surface and make sure it hasn't
|
|
|
|
// already been purged by the operating system.
|
|
|
|
RefPtr<SourceSurface> surface = frame->GetSurface();
|
2015-04-04 19:58:00 +00:00
|
|
|
if (!surface) {
|
2014-09-14 22:22:45 +00:00
|
|
|
return Show(svgDrawable, aParams);
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2014-07-29 00:05:40 +00:00
|
|
|
|
2014-09-14 22:22:45 +00:00
|
|
|
// Attempt to cache the frame.
|
|
|
|
SurfaceCache::Insert(frame, ImageKey(this),
|
2014-09-19 21:53:28 +00:00
|
|
|
VectorSurfaceKey(aParams.size,
|
|
|
|
aParams.svgContext,
|
2014-11-26 21:22:10 +00:00
|
|
|
aParams.animationTime),
|
2015-03-28 03:17:23 +00:00
|
|
|
Lifetime::Persistent);
|
2013-10-22 11:38:08 +00:00
|
|
|
|
2014-09-14 22:22:45 +00:00
|
|
|
// Draw.
|
2014-02-09 08:04:37 +00:00
|
|
|
nsRefPtr<gfxDrawable> drawable =
|
2015-03-29 14:59:15 +00:00
|
|
|
new gfxSurfaceDrawable(surface, aParams.size);
|
2014-08-06 22:43:25 +00:00
|
|
|
Show(drawable, aParams);
|
2015-03-28 03:17:23 +00:00
|
|
|
|
|
|
|
// Send out an invalidation so that surfaces that are still in use get
|
|
|
|
// re-locked. See the discussion of the UnlockSurfaces call above.
|
|
|
|
mProgressTracker->SyncNotifyProgress(FLAG_FRAME_COMPLETE,
|
2015-04-21 15:04:57 +00:00
|
|
|
GetMaxSizedIntRect());
|
2013-10-22 11:38:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2014-08-06 22:43:25 +00:00
|
|
|
VectorImage::Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams)
|
2013-10-22 11:38:08 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDrawable, "Should have a gfxDrawable by now");
|
|
|
|
gfxUtils::DrawPixelSnapped(aParams.context, aDrawable,
|
2015-03-29 14:59:15 +00:00
|
|
|
aParams.size,
|
2014-08-22 20:12:38 +00:00
|
|
|
aParams.region,
|
2014-04-20 01:28:38 +00:00
|
|
|
SurfaceFormat::B8G8R8A8,
|
2014-08-29 14:04:34 +00:00
|
|
|
aParams.filter, aParams.flags, aParams.opacity);
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-06-21 20:32:34 +00:00
|
|
|
MOZ_ASSERT(mRenderingObserver, "Should have a rendering observer by now");
|
|
|
|
mRenderingObserver->ResumeHonoringInvalidations();
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2015-02-04 00:38:39 +00:00
|
|
|
void
|
|
|
|
VectorImage::RecoverFromLossOfSurfaces()
|
|
|
|
{
|
|
|
|
NS_WARNING("An imgFrame became invalid. Attempting to recover...");
|
|
|
|
|
|
|
|
// Discard all existing frames, since they're probably all now invalid.
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* void requestDecode() */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::RequestDecode()
|
|
|
|
{
|
|
|
|
// Nothing to do for SVG images
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-04 20:02:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::StartDecoding()
|
|
|
|
{
|
|
|
|
// Nothing to do for SVG images
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:02:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags)
|
|
|
|
{
|
|
|
|
// Nothing to do for SVG images, though in theory we could rasterize to the
|
|
|
|
// provided size ahead of time if we supported off-main-thread SVG
|
|
|
|
// rasterization...
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* void lockImage() */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::LockImage()
|
|
|
|
{
|
2015-03-28 03:17:23 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLockCount++;
|
|
|
|
|
|
|
|
if (mLockCount == 1) {
|
|
|
|
// Lock this image's surfaces in the SurfaceCache.
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* void unlockImage() */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::UnlockImage()
|
|
|
|
{
|
2015-03-28 03:17:23 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLockCount == 0) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Calling UnlockImage with a zero lock count");
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
|
|
|
mLockCount--;
|
|
|
|
|
|
|
|
if (mLockCount == 0) {
|
|
|
|
// Unlock this image's surfaces in the SurfaceCache.
|
|
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-10 06:29:28 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* void requestDiscard() */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::RequestDiscard()
|
|
|
|
{
|
2015-03-28 03:17:23 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mDiscardable && mLockCount == 0) {
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
mProgressTracker->OnDiscard();
|
|
|
|
}
|
|
|
|
|
2012-03-10 06:29:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-28 03:17:23 +00:00
|
|
|
void
|
|
|
|
VectorImage::OnSurfaceDiscarded()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mProgressTracker);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NS_NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//******************************************************************************
|
|
|
|
/* void resetAnimation (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::ResetAnimation()
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError) {
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
if (!mIsFullyLoaded || !mHaveAnimations) {
|
|
|
|
return NS_OK; // There are no animations to be reset.
|
|
|
|
}
|
|
|
|
|
|
|
|
mSVGDocumentWrapper->ResetAnimation();
|
2011-02-03 06:36:09 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 22:58:20 +00:00
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
VectorImage::GetFrameIndex(uint32_t aWhichFrame)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
|
|
|
|
return aWhichFrame == FRAME_FIRST
|
|
|
|
? 0.0f
|
|
|
|
: mSVGDocumentWrapper->GetCurrentTime();
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// nsIRequestObserver methods
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* void onStartRequest(in nsIRequest request, in nsISupports ctxt); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt)
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(!mSVGDocumentWrapper,
|
|
|
|
"Repeated call to OnStartRequest -- can this happen?");
|
2010-09-08 20:40:39 +00:00
|
|
|
|
|
|
|
mSVGDocumentWrapper = new SVGDocumentWrapper();
|
|
|
|
nsresult rv = mSVGDocumentWrapper->OnStartRequest(aRequest, aCtxt);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
mSVGDocumentWrapper = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mError = true;
|
2013-02-14 02:04:08 +00:00
|
|
|
return rv;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
// Sending StartDecode will block page load until the document's ready. (We
|
|
|
|
// unblock it by sending StopDecode in OnSVGDocumentLoaded or
|
|
|
|
// OnSVGDocumentError.)
|
2014-11-15 04:10:47 +00:00
|
|
|
if (mProgressTracker) {
|
|
|
|
mProgressTracker->SyncNotifyProgress(FLAG_DECODE_STARTED |
|
|
|
|
FLAG_ONLOAD_BLOCKED);
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create a listener to wait until the SVG document is fully loaded, which
|
|
|
|
// will signal that this image is ready to render. Certain error conditions
|
|
|
|
// will prevent us from ever getting this notification, so we also create a
|
|
|
|
// listener that waits for parsing to complete and cancels the
|
|
|
|
// SVGLoadEventListener if needed. The listeners are automatically attached
|
|
|
|
// to the document by their constructors.
|
|
|
|
nsIDocument* document = mSVGDocumentWrapper->GetDocument();
|
|
|
|
mLoadEventListener = new SVGLoadEventListener(document, this);
|
|
|
|
mParseCompleteListener = new SVGParseCompleteListener(document, this);
|
|
|
|
|
|
|
|
return NS_OK;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* void onStopRequest(in nsIRequest request, in nsISupports ctxt,
|
|
|
|
in nsresult status); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::OnStopRequest(nsIRequest* aRequest, nsISupports* aCtxt,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError) {
|
2010-09-08 20:40:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
return mSVGDocumentWrapper->OnStopRequest(aRequest, aCtxt, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VectorImage::OnSVGDocumentParsed()
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mParseCompleteListener, "Should have the parse complete listener");
|
|
|
|
MOZ_ASSERT(mLoadEventListener, "Should have the load event listener");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
if (!mSVGDocumentWrapper->GetRootSVGElem()) {
|
|
|
|
// This is an invalid SVG document. It may have failed to parse, or it may
|
|
|
|
// be missing the <svg> root element, or the <svg> root element may not
|
|
|
|
// declare the correct namespace. In any of these cases, we'll never be
|
2015-04-04 19:58:00 +00:00
|
|
|
// notified that the SVG finished loading, so we need to treat this as an
|
|
|
|
// error.
|
2013-02-14 02:04:08 +00:00
|
|
|
OnSVGDocumentError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VectorImage::CancelAllListeners()
|
|
|
|
{
|
|
|
|
if (mParseCompleteListener) {
|
|
|
|
mParseCompleteListener->Cancel();
|
|
|
|
mParseCompleteListener = nullptr;
|
|
|
|
}
|
|
|
|
if (mLoadEventListener) {
|
|
|
|
mLoadEventListener->Cancel();
|
|
|
|
mLoadEventListener = nullptr;
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
VectorImage::OnSVGDocumentLoaded()
|
|
|
|
{
|
2013-03-01 06:45:00 +00:00
|
|
|
MOZ_ASSERT(mSVGDocumentWrapper->GetRootSVGElem(),
|
|
|
|
"Should have parsed successfully");
|
|
|
|
MOZ_ASSERT(!mIsFullyLoaded && !mHaveAnimations,
|
|
|
|
"These flags shouldn't get set until OnSVGDocumentLoaded. "
|
|
|
|
"Duplicate calls to OnSVGDocumentLoaded?");
|
2013-02-14 02:04:08 +00:00
|
|
|
|
|
|
|
CancelAllListeners();
|
|
|
|
|
|
|
|
// XXX Flushing is wasteful if embedding frame hasn't had initial reflow.
|
|
|
|
mSVGDocumentWrapper->FlushLayout();
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsFullyLoaded = true;
|
2010-09-08 20:40:39 +00:00
|
|
|
mHaveAnimations = mSVGDocumentWrapper->IsAnimated();
|
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
// Start listening to our image for rendering updates.
|
2010-09-08 20:40:40 +00:00
|
|
|
mRenderingObserver = new SVGRootRenderingObserver(mSVGDocumentWrapper, this);
|
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
// Tell *our* observers that we're done loading.
|
2014-11-15 04:10:47 +00:00
|
|
|
if (mProgressTracker) {
|
2015-06-18 21:48:41 +00:00
|
|
|
Progress progress = FLAG_SIZE_AVAILABLE |
|
|
|
|
FLAG_HAS_TRANSPARENCY |
|
|
|
|
FLAG_FRAME_COMPLETE |
|
|
|
|
FLAG_DECODE_COMPLETE |
|
|
|
|
FLAG_ONLOAD_UNBLOCKED;
|
|
|
|
|
|
|
|
// Merge in any saved progress from OnImageDataComplete.
|
|
|
|
if (mLoadProgress) {
|
|
|
|
progress |= *mLoadProgress;
|
|
|
|
mLoadProgress = Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgressTracker->SyncNotifyProgress(progress, GetMaxSizedIntRect());
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
2013-02-14 02:04:08 +00:00
|
|
|
|
2010-12-20 00:45:29 +00:00
|
|
|
EvaluateAnimation();
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
|
2013-02-14 02:04:08 +00:00
|
|
|
void
|
|
|
|
VectorImage::OnSVGDocumentError()
|
|
|
|
{
|
|
|
|
CancelAllListeners();
|
|
|
|
|
|
|
|
// XXXdholbert Need to do something more for the parsing failed case -- right
|
|
|
|
// now, this just makes us draw the "object" icon, rather than the (jagged)
|
|
|
|
// "broken image" icon. See bug 594505.
|
|
|
|
mError = true;
|
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
if (mProgressTracker) {
|
2015-06-18 21:48:41 +00:00
|
|
|
// Notify observers about the error and unblock page load.
|
|
|
|
Progress progress = FLAG_DECODE_COMPLETE |
|
|
|
|
FLAG_ONLOAD_UNBLOCKED |
|
|
|
|
FLAG_HAS_ERROR;
|
|
|
|
|
|
|
|
// Merge in any saved progress from OnImageDataComplete.
|
|
|
|
if (mLoadProgress) {
|
|
|
|
progress |= *mLoadProgress;
|
|
|
|
mLoadProgress = Nothing();
|
|
|
|
}
|
|
|
|
|
|
|
|
mProgressTracker->SyncNotifyProgress(progress);
|
2013-02-14 02:04:08 +00:00
|
|
|
}
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// nsIStreamListener method
|
|
|
|
|
|
|
|
//******************************************************************************
|
|
|
|
/* void onDataAvailable(in nsIRequest request, in nsISupports ctxt,
|
|
|
|
in nsIInputStream inStr, in unsigned long sourceOffset,
|
|
|
|
in unsigned long count); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
VectorImage::OnDataAvailable(nsIRequest* aRequest, nsISupports* aCtxt,
|
2012-09-06 02:41:02 +00:00
|
|
|
nsIInputStream* aInStr, uint64_t aSourceOffset,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aCount)
|
2010-09-08 20:40:39 +00:00
|
|
|
{
|
2015-04-04 19:58:00 +00:00
|
|
|
if (mError) {
|
2011-05-23 02:22:13 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-04-04 19:58:00 +00:00
|
|
|
}
|
2011-05-23 02:22:13 +00:00
|
|
|
|
2010-09-08 20:40:39 +00:00
|
|
|
return mSVGDocumentWrapper->OnDataAvailable(aRequest, aCtxt, aInStr,
|
|
|
|
aSourceOffset, aCount);
|
2010-09-08 20:40:39 +00:00
|
|
|
}
|
|
|
|
|
2010-09-08 20:40:40 +00:00
|
|
|
// --------------------------
|
|
|
|
// Invalidation helper method
|
|
|
|
|
|
|
|
void
|
2013-09-04 10:39:30 +00:00
|
|
|
VectorImage::InvalidateObserversOnNextRefreshDriverTick()
|
2010-09-08 20:40:40 +00:00
|
|
|
{
|
2013-11-21 01:21:50 +00:00
|
|
|
if (mHaveAnimations) {
|
|
|
|
mHasPendingInvalidation = true;
|
|
|
|
} else {
|
|
|
|
SendInvalidationNotifications();
|
|
|
|
}
|
2010-09-08 20:40:40 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 21:27:39 +00:00
|
|
|
nsIntSize
|
2015-04-04 19:58:00 +00:00
|
|
|
VectorImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
|
|
|
GraphicsFilter aFilter,
|
|
|
|
uint32_t aFlags)
|
2014-07-28 21:27:39 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDest.width >= 0 || ceil(aDest.width) <= INT32_MAX ||
|
|
|
|
aDest.height >= 0 || ceil(aDest.height) <= INT32_MAX,
|
|
|
|
"Unexpected destination size");
|
|
|
|
|
|
|
|
// We can rescale SVGs freely, so just return the provided destination size.
|
|
|
|
return nsIntSize(ceil(aDest.width), ceil(aDest.height));
|
|
|
|
}
|
|
|
|
|
2014-06-28 03:50:26 +00:00
|
|
|
already_AddRefed<imgIContainer>
|
|
|
|
VectorImage::Unwrap()
|
|
|
|
{
|
|
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-09-08 20:40:39 +00:00
|
|
|
} // namespace mozilla
|