2012-02-05 16:23:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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/. */
|
2012-02-05 16:23:08 +04:00
|
|
|
|
|
|
|
#include "CanvasImageCache.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2012-02-05 16:23:08 +04:00
|
|
|
#include "nsIImageLoadingContent.h"
|
|
|
|
#include "nsExpirationTracker.h"
|
|
|
|
#include "imgIRequest.h"
|
2012-06-30 09:53:21 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-02-05 16:23:08 +04:00
|
|
|
#include "nsTHashtable.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2012-02-05 16:23:08 +04:00
|
|
|
#include "nsContentUtils.h"
|
2013-04-26 18:16:12 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-08-15 08:31:24 +03:00
|
|
|
#include "mozilla/StaticPrefs_canvas.h"
|
2017-08-15 05:51:54 +03:00
|
|
|
#include "mozilla/SystemGroup.h"
|
2013-12-12 01:05:27 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2014-11-04 16:00:36 +03:00
|
|
|
#include "gfx2DGlue.h"
|
2012-02-05 16:23:08 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2012-06-30 09:53:21 +04:00
|
|
|
using namespace dom;
|
2013-12-12 01:05:27 +04:00
|
|
|
using namespace gfx;
|
2012-06-30 09:53:21 +04:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
/**
|
|
|
|
* Used for images specific to this one canvas. Required
|
|
|
|
* due to CORS security.
|
|
|
|
*/
|
|
|
|
struct ImageCacheKey {
|
2019-02-28 17:58:19 +03:00
|
|
|
ImageCacheKey(imgIContainer* aImage, HTMLCanvasElement* aCanvas)
|
|
|
|
: mImage(aImage), mCanvas(aCanvas) {}
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> mImage;
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* mCanvas;
|
2012-02-05 16:23:08 +04:00
|
|
|
};
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
/**
|
|
|
|
* Cache data needs to be separate from the entry
|
|
|
|
* for nsExpirationTracker.
|
|
|
|
*/
|
|
|
|
struct ImageCacheEntryData {
|
2012-02-05 16:23:08 +04:00
|
|
|
ImageCacheEntryData(const ImageCacheEntryData& aOther)
|
|
|
|
: mImage(aOther.mImage),
|
|
|
|
mCanvas(aOther.mCanvas),
|
2013-12-12 01:05:27 +04:00
|
|
|
mSourceSurface(aOther.mSourceSurface),
|
2019-07-12 15:46:03 +03:00
|
|
|
mSize(aOther.mSize),
|
|
|
|
mIntrinsicSize(aOther.mIntrinsicSize) {}
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit ImageCacheEntryData(const ImageCacheKey& aKey)
|
2019-02-28 17:58:19 +03:00
|
|
|
: mImage(aKey.mImage), mCanvas(aKey.mCanvas) {}
|
2012-02-05 16:23:08 +04:00
|
|
|
|
|
|
|
nsExpirationState* GetExpirationState() { return &mState; }
|
2013-04-26 18:16:12 +04:00
|
|
|
size_t SizeInBytes() { return mSize.width * mSize.height * 4; }
|
|
|
|
|
2012-02-05 16:23:08 +04:00
|
|
|
// Key
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> mImage;
|
|
|
|
HTMLCanvasElement* mCanvas;
|
2012-02-05 16:23:08 +04:00
|
|
|
// Value
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> mSourceSurface;
|
2015-09-23 21:49:05 +03:00
|
|
|
IntSize mSize;
|
2019-07-12 15:46:03 +03:00
|
|
|
IntSize mIntrinsicSize;
|
2012-02-05 16:23:08 +04:00
|
|
|
nsExpirationState mState;
|
|
|
|
};
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
class ImageCacheEntry : public PLDHashEntryHdr {
|
2012-02-05 16:23:08 +04:00
|
|
|
public:
|
|
|
|
typedef ImageCacheKey KeyType;
|
|
|
|
typedef const ImageCacheKey* KeyTypePointer;
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit ImageCacheEntry(const KeyType* aKey)
|
|
|
|
: mData(new ImageCacheEntryData(*aKey)) {}
|
2016-05-10 18:00:06 +03:00
|
|
|
ImageCacheEntry(const ImageCacheEntry& toCopy)
|
2012-02-05 16:23:08 +04:00
|
|
|
: mData(new ImageCacheEntryData(*toCopy.mData)) {}
|
|
|
|
~ImageCacheEntry() {}
|
|
|
|
|
|
|
|
bool KeyEquals(KeyTypePointer key) const {
|
2019-02-28 17:58:19 +03:00
|
|
|
return mData->mImage == key->mImage && mData->mCanvas == key->mCanvas;
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType& key) { return &key; }
|
|
|
|
static PLDHashNumber HashKey(KeyTypePointer key) {
|
2019-02-28 17:58:19 +03:00
|
|
|
return HashGeneric(key->mImage.get(), key->mCanvas);
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
|
|
|
|
|
|
|
nsAutoPtr<ImageCacheEntryData> mData;
|
|
|
|
};
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
/**
|
|
|
|
* Used for all images across all canvases.
|
|
|
|
*/
|
|
|
|
struct AllCanvasImageCacheKey {
|
2019-02-28 17:58:19 +03:00
|
|
|
explicit AllCanvasImageCacheKey(imgIContainer* aImage) : mImage(aImage) {}
|
2016-05-10 18:00:06 +03:00
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> mImage;
|
2015-11-04 05:12:24 +03:00
|
|
|
};
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
class AllCanvasImageCacheEntry : public PLDHashEntryHdr {
|
2014-10-29 18:17:00 +03:00
|
|
|
public:
|
2016-05-10 18:00:06 +03:00
|
|
|
typedef AllCanvasImageCacheKey KeyType;
|
|
|
|
typedef const AllCanvasImageCacheKey* KeyTypePointer;
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
explicit AllCanvasImageCacheEntry(const KeyType* aKey)
|
2019-02-28 17:58:19 +03:00
|
|
|
: mImage(aKey->mImage) {}
|
2016-05-10 18:00:06 +03:00
|
|
|
|
|
|
|
AllCanvasImageCacheEntry(const AllCanvasImageCacheEntry& toCopy)
|
2014-10-29 18:17:00 +03:00
|
|
|
: mImage(toCopy.mImage), mSourceSurface(toCopy.mSourceSurface) {}
|
2016-05-10 18:00:06 +03:00
|
|
|
|
|
|
|
~AllCanvasImageCacheEntry() {}
|
2014-10-29 18:17:00 +03:00
|
|
|
|
|
|
|
bool KeyEquals(KeyTypePointer key) const { return mImage == key->mImage; }
|
|
|
|
|
2015-11-04 05:12:24 +03:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType& key) { return &key; }
|
2014-10-29 18:17:00 +03:00
|
|
|
static PLDHashNumber HashKey(KeyTypePointer key) {
|
2019-02-28 17:58:19 +03:00
|
|
|
return HashGeneric(key->mImage.get());
|
2014-10-29 18:17:00 +03:00
|
|
|
}
|
|
|
|
enum { ALLOW_MEMMOVE = true };
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> mImage;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> mSourceSurface;
|
2014-10-29 18:17:00 +03:00
|
|
|
};
|
|
|
|
|
2014-08-25 23:01:46 +04:00
|
|
|
class ImageCacheObserver;
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
class ImageCache final : public nsExpirationTracker<ImageCacheEntryData, 4> {
|
2012-02-05 16:23:08 +04:00
|
|
|
public:
|
|
|
|
// We use 3 generations of 1 second each to get a 2-3 seconds timeout.
|
|
|
|
enum { GENERATION_MS = 1000 };
|
2014-08-25 23:01:46 +04:00
|
|
|
ImageCache();
|
|
|
|
~ImageCache();
|
2012-02-05 16:23:08 +04:00
|
|
|
|
2017-11-06 06:37:28 +03:00
|
|
|
virtual void NotifyExpired(ImageCacheEntryData* aObject) override {
|
2013-04-26 18:16:12 +04:00
|
|
|
mTotal -= aObject->SizeInBytes();
|
2012-02-05 16:23:08 +04:00
|
|
|
RemoveObject(aObject);
|
2016-05-10 18:00:06 +03:00
|
|
|
|
|
|
|
// Remove from the all canvas cache entry first since nsExpirationTracker
|
|
|
|
// will delete aObject.
|
2019-02-28 17:58:19 +03:00
|
|
|
mAllCanvasCache.RemoveEntry(AllCanvasImageCacheKey(aObject->mImage));
|
2016-05-10 18:00:06 +03:00
|
|
|
|
|
|
|
// Deleting the entry will delete aObject since the entry owns aObject.
|
2019-02-28 17:58:19 +03:00
|
|
|
mCache.RemoveEntry(ImageCacheKey(aObject->mImage, aObject->mCanvas));
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsTHashtable<ImageCacheEntry> mCache;
|
2016-05-10 18:00:06 +03:00
|
|
|
nsTHashtable<AllCanvasImageCacheEntry> mAllCanvasCache;
|
2013-04-26 18:16:12 +04:00
|
|
|
size_t mTotal;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ImageCacheObserver> mImageCacheObserver;
|
2012-02-05 16:23:08 +04:00
|
|
|
};
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
static ImageCache* gImageCache = nullptr;
|
2012-02-05 16:23:08 +04:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
// Listen memory-pressure event for image cache purge.
|
2015-03-21 19:28:04 +03:00
|
|
|
class ImageCacheObserver final : public nsIObserver {
|
2014-08-25 23:01:46 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2014-09-02 02:26:43 +04:00
|
|
|
explicit ImageCacheObserver(ImageCache* aImageCache)
|
2014-08-25 23:01:46 +04:00
|
|
|
: mImageCache(aImageCache) {
|
|
|
|
RegisterMemoryPressureEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy() {
|
|
|
|
UnregisterMemoryPressureEvent();
|
|
|
|
mImageCache = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aSomeData) override {
|
2014-08-25 23:01:46 +04:00
|
|
|
if (!mImageCache || strcmp(aTopic, "memory-pressure")) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mImageCache->AgeAllGenerations();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~ImageCacheObserver() {}
|
|
|
|
|
|
|
|
void RegisterMemoryPressureEvent() {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
|
|
|
|
MOZ_ASSERT(observerService);
|
|
|
|
|
|
|
|
if (observerService) {
|
|
|
|
observerService->AddObserver(this, "memory-pressure", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnregisterMemoryPressureEvent() {
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
|
|
|
|
// Do not assert on observerService here. This might be triggered by
|
|
|
|
// the cycle collector at a late enough time, that XPCOM services are
|
|
|
|
// no longer available. See bug 1029504.
|
|
|
|
if (observerService) {
|
|
|
|
observerService->RemoveObserver(this, "memory-pressure");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageCache* mImageCache;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(ImageCacheObserver, nsIObserver)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CanvasImageCacheShutdownObserver final : public nsIObserver {
|
2014-06-26 17:30:49 +04:00
|
|
|
~CanvasImageCacheShutdownObserver() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-02-05 16:23:08 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2014-08-25 23:01:46 +04:00
|
|
|
ImageCache::ImageCache()
|
2017-08-15 05:51:54 +03:00
|
|
|
: nsExpirationTracker<ImageCacheEntryData, 4>(
|
|
|
|
GENERATION_MS, "ImageCache",
|
|
|
|
SystemGroup::EventTargetFor(TaskCategory::Other)),
|
2014-08-25 23:01:46 +04:00
|
|
|
mTotal(0) {
|
|
|
|
mImageCacheObserver = new ImageCacheObserver(this);
|
2016-06-06 18:17:23 +03:00
|
|
|
MOZ_RELEASE_ASSERT(mImageCacheObserver,
|
|
|
|
"GFX: Can't alloc ImageCacheObserver");
|
2014-08-25 23:01:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ImageCache::~ImageCache() {
|
|
|
|
AgeAllGenerations();
|
|
|
|
mImageCacheObserver->Destroy();
|
|
|
|
}
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
static already_AddRefed<imgIContainer> GetImageContainer(dom::Element* aImage) {
|
|
|
|
nsCOMPtr<imgIRequest> request;
|
|
|
|
nsCOMPtr<nsIImageLoadingContent> ilc = do_QueryInterface(aImage);
|
|
|
|
if (!ilc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
ilc->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
|
|
|
|
getter_AddRefs(request));
|
|
|
|
if (!request) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<imgIContainer> imgContainer;
|
|
|
|
request->GetImage(getter_AddRefs(imgContainer));
|
|
|
|
if (!imgContainer) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return imgContainer.forget();
|
|
|
|
}
|
|
|
|
|
2012-06-30 09:53:21 +04:00
|
|
|
void CanvasImageCache::NotifyDrawImage(Element* aImage,
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* aCanvas,
|
2013-12-12 01:05:27 +04:00
|
|
|
SourceSurface* aSource,
|
2019-07-12 15:46:03 +03:00
|
|
|
const IntSize& aSize,
|
|
|
|
const IntSize& aIntrinsicSize) {
|
2012-02-05 16:23:08 +04:00
|
|
|
if (!gImageCache) {
|
|
|
|
gImageCache = new ImageCache();
|
|
|
|
nsContentUtils::RegisterShutdownObserver(
|
|
|
|
new CanvasImageCacheShutdownObserver());
|
|
|
|
}
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer = GetImageContainer(aImage);
|
|
|
|
if (!imgContainer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-28 17:58:19 +03:00
|
|
|
AllCanvasImageCacheKey allCanvasCacheKey(imgContainer);
|
|
|
|
ImageCacheKey canvasCacheKey(imgContainer, aCanvas);
|
2016-05-10 18:00:06 +03:00
|
|
|
ImageCacheEntry* entry = gImageCache->mCache.PutEntry(canvasCacheKey);
|
|
|
|
|
2012-02-05 16:23:08 +04:00
|
|
|
if (entry) {
|
2013-12-12 01:05:27 +04:00
|
|
|
if (entry->mData->mSourceSurface) {
|
2012-02-05 16:23:08 +04:00
|
|
|
// We are overwriting an existing entry.
|
2013-04-26 18:16:12 +04:00
|
|
|
gImageCache->mTotal -= entry->mData->SizeInBytes();
|
2012-02-05 16:23:08 +04:00
|
|
|
gImageCache->RemoveObject(entry->mData);
|
2016-05-10 18:00:06 +03:00
|
|
|
gImageCache->mAllCanvasCache.RemoveEntry(allCanvasCacheKey);
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
gImageCache->AddObject(entry->mData);
|
2013-12-12 01:05:27 +04:00
|
|
|
entry->mData->mSourceSurface = aSource;
|
2012-02-05 16:23:08 +04:00
|
|
|
entry->mData->mSize = aSize;
|
2019-07-12 15:46:03 +03:00
|
|
|
entry->mData->mIntrinsicSize = aIntrinsicSize;
|
2013-04-26 18:16:12 +04:00
|
|
|
gImageCache->mTotal += entry->mData->SizeInBytes();
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
AllCanvasImageCacheEntry* allEntry =
|
|
|
|
gImageCache->mAllCanvasCache.PutEntry(allCanvasCacheKey);
|
|
|
|
if (allEntry) {
|
|
|
|
allEntry->mSourceSurface = aSource;
|
2014-10-29 18:17:00 +03:00
|
|
|
}
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
2013-04-26 18:16:12 +04:00
|
|
|
|
2019-08-15 08:31:24 +03:00
|
|
|
if (!StaticPrefs::canvas_image_cache_limit()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-26 18:16:12 +04:00
|
|
|
|
|
|
|
// Expire the image cache early if its larger than we want it to be.
|
2019-08-15 08:31:24 +03:00
|
|
|
while (gImageCache->mTotal >
|
|
|
|
size_t(StaticPrefs::canvas_image_cache_limit())) {
|
2013-04-26 18:16:12 +04:00
|
|
|
gImageCache->AgeOneGeneration();
|
2019-08-15 08:31:24 +03:00
|
|
|
}
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
|
2019-02-28 17:58:19 +03:00
|
|
|
SourceSurface* CanvasImageCache::LookupAllCanvas(Element* aImage) {
|
2016-05-10 18:00:06 +03:00
|
|
|
if (!gImageCache) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2012-02-05 16:23:08 +04:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer = GetImageContainer(aImage);
|
|
|
|
if (!imgContainer) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2012-02-05 16:23:08 +04:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
AllCanvasImageCacheEntry* entry = gImageCache->mAllCanvasCache.GetEntry(
|
2019-02-28 17:58:19 +03:00
|
|
|
AllCanvasImageCacheKey(imgContainer));
|
2016-05-10 18:00:06 +03:00
|
|
|
if (!entry) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2012-02-05 16:23:08 +04:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
return entry->mSourceSurface;
|
2012-02-05 16:23:08 +04:00
|
|
|
}
|
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
SourceSurface* CanvasImageCache::LookupCanvas(Element* aImage,
|
|
|
|
HTMLCanvasElement* aCanvas,
|
2019-07-12 15:46:03 +03:00
|
|
|
IntSize* aSizeOut,
|
|
|
|
IntSize* aIntrinsicSizeOut) {
|
2016-05-10 18:00:06 +03:00
|
|
|
if (!gImageCache) {
|
2014-10-29 18:17:00 +03:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> imgContainer = GetImageContainer(aImage);
|
|
|
|
if (!imgContainer) {
|
2014-10-29 18:17:00 +03:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
ImageCacheEntry* entry =
|
|
|
|
gImageCache->mCache.GetEntry(ImageCacheKey(imgContainer, aCanvas));
|
|
|
|
if (!entry) {
|
2014-10-29 18:17:00 +03:00
|
|
|
return nullptr;
|
2016-05-10 18:00:06 +03:00
|
|
|
}
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
MOZ_ASSERT(aSizeOut);
|
2014-10-29 18:17:00 +03:00
|
|
|
|
2016-05-10 18:00:06 +03:00
|
|
|
gImageCache->MarkUsed(entry->mData);
|
|
|
|
*aSizeOut = entry->mData->mSize;
|
2019-07-12 15:46:03 +03:00
|
|
|
*aIntrinsicSizeOut = entry->mData->mIntrinsicSize;
|
2016-05-10 18:00:06 +03:00
|
|
|
return entry->mData->mSourceSurface;
|
2014-10-29 18:17:00 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(CanvasImageCacheShutdownObserver, nsIObserver)
|
2012-02-05 16:23:08 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CanvasImageCacheShutdownObserver::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData) {
|
2012-02-05 16:23:08 +04:00
|
|
|
if (strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
delete gImageCache;
|
2012-07-30 18:20:58 +04:00
|
|
|
gImageCache = nullptr;
|
2012-02-05 16:23:08 +04:00
|
|
|
|
|
|
|
nsContentUtils::UnregisterShutdownObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-11 17:29:50 +04:00
|
|
|
} // namespace mozilla
|