mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
fffeb135bb
- Bug 1040668 part 2 - Parse and compute text emphasis properties. r=dbaron (0fb79d4709) - Bug 1040668 part 3 - Add helper function gfxTextRun::GetAdvanceForGlyph. r=jfkthame (f1cf02f5ff) - Bug 1216427 - Tests for backspacing over a character with variation selector, and over Regional Indicator flag symbols. r=emk (18957bfe77) - Bug 1216427 - part 1 - Ensure a character+VS sequence or a ligated Regional-Indicator flag symbol is deleted as a single unit when backspacing. r=emk (2776ff8f4a) - Bug 1216427 - part 2 - Ensure mouse selection does not split up a Regional Indicator flag symbol. r=emk (58eb82e6a1) - Bug 1040668 part 4 - Add helper function for ensuring a glyph is a complex glyph. r=jfkthame (ba17f7d0c4) - Bug 1040668 part 5 - Avoid unnecessary allocation inside EnsureComplexGlyph helper function. r=jfkthame (4968a7c68e) - Bug 1040668 part 6 - Add some specifier on gfxTextRun and gfxShapedWord so that compilers are able to reason out certain optimizations. r=jfkthame (69ca3eb959) - Bug 1040668 part 7 - Add NO_EMPHASIS_MARK flag in CompressedGlyph. r=jfkthame (34e9d8a6a6) - Bug 1227001 part 1 - Remove SetupBreakSinksFlags from BuildTextRunsScanner. r=jfkthame (520b1ba111) - Bug 1227001 part 2 - Remove no longer used mExistingTextRun from BreaSink. r=jfkthame (201782a78c) - Bug 1227001 part 3 - Remove no longer used mChangedBreaks from BreakSink. r=jfkthame (e754e2b13f) - Bug 1040668 part 8 - Setup text emphasis for text run. r=jfkthame (376377180e) - Bug 1040668 part 9 - Compute overflow from text-shadow after text decorations. r=dbaron (05c9bd08c2) - Bug 1040668 part 10 - Implement emphasis mark rendering. r=jfkthame (4d270afca8) - Bug 1040668 part 11 - Move line leadings adjusting code into a separate function in nsLineLayout. r=dholbert (fd4dd20ca5) - Bug 1040668 part 12 - Add line leadings for emphasis marks if necessary. r=dholbert (138add5ff7) - Bug 1040668 part 13 - Move first part of nsStyleFont::GetLanguage to nsPresContext::GetContentLanguage. r=dbaron (1e872d2a58) - Bug 1040668 part 14 - Add helper function nsStyleUtil::MatchesLanguagePrefix for doing simple language matching. r=dbaron (9322a02369) - Bug 1040668 part 15 - Make the default value of text-emphasis-position aware of the language. r=dbaron (6587c628da) - Bug 1040668 part 16 - Add reftests for text-emphasis. r=dbaron (9940d65182) - Bug 1040668 followup - Use monospace for text-emphasis reftests. rs=dbaron on a CLOSED TREE (fb7598c3ea) - Bug 1040668 followup 2 - Disable failing reftests of text-emphasis on Windows XP. (7c3f24ac22) - Bug 1040668 followup 3 - Wrap lang attribute mapping code in NS_STYLE_INHERIT_BIT test. r=dbaron (640e3b7b8f) - Bug 1219145 - nsRefreshDriver::IsJankCritical(). r=hiro To refine its alerts, Performance Stats API needs to be able to know whether a long-running operation is actually causing user-visible jank in the current process. This patch introduces a trivial API that lets clients ask the refresh driver whether any kind of animation is ongoing. (7c0868d7c4) - more missing XP theme stuff (637af0c6a0) - Bug 1210261. Tick root refresh driver last. r=mattwoodrow (dae1a325fa) - Bug 1221674 Part 2: Correct for negative content delay values. r=avih (9b9811c41c) - Bug 1211334 - Check if presshell is still available after dispatching transition events; r=mats (8a044a462c) - Bug 1211599 - Only allow whitelisted histograms to have > 100 buckets. r=nfroyd (d467e84130) - Bug 1219733 - Allow a 'bug_numbers' field in Histograms.json entries. r=vladan (8e63a713ec) - Bug 1222044 - Only allow lists of alert_emails r=vladan (1d5fcb009d) - Bug 1168263 - Add a flags parameter to GetResultingTransformMatrix instead of using bools. r=roc (ec5224f9af) - Bug 1168263 - Remove TransformRectOut since it's unused. r=roc (d20a79ae0e) - Bug 1215406 - Part 1: Remove NS_STYLE_ANIMATION_DIRECTION_XXX and NS_STYLE_ANIMATION_FILL_MODE_XXX. r=heycam (4bd7f8116b) - Bug 1215406 - Part 2: Change the types of direction and fillmode in StyleAnimation. r=heycam (e06323c81b) - Bug 1215406 - Part 3: Change the types of direction and fillmode in AnimationTiming. r=heycam (e5454d3ea5) - Bug 1215406 - Part 4: Add KeyframeEffectOptions. r=smaug Add KeyframeEffectOptions in KeyframeEffect.webidl (0ce3372fd1) - Bug 1215406 - Part 5: Implement KeyframeEffectOptions in KeyframeEffectReadOnly constructor. r=birtles (a472e9ac5f) - tch 2 - Use an enum class for NS_STYLE_BOX_SIZING_*. r=heycam (4897b7b8ff) - Bug 1218195, mark MutationObserver as observing in all the nested DOM mutations, r=bz (48a4aa8a91) - Bug 1172870 - Part 3 - Fix openWindow mochitest to work on e10s (574cc6fa4d) - Bug 1223265 - Fix -Wunreachable-code and -Wimplicit-fallthrough warnings in dom/bindings and dom/ipc. r=khuey (9eab632140) - Bug 1189195 - Fix PContentPermissionRequest shutdown () r=fabrice (6bc1a681f5) - Bug 1210508 - Handle null OriginAttributes from JS-implemented nsILoadContext. r=me (2f71edb9d7) - Bug 1224596 part 1. Add a version of WorkerMainThreadRunnable::Dispatch that takes an ErrorResult to report failure to dispatch on. r=khuey (e60a0fb115) - Bug 1224596 part 2. Switch Navigator to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (d9298a4763) - Bug 1224596 part 3. Make some WebSocket(Impl) methods whose return value is totally ignored void. r=khuey (1d04b52d44) - Bug 1224596 part 4. Switch WebSocket to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (aa06e6417b) - Bug 1224596 part 5. Switch nsPerformance to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (0303b7de09) - Bug 1224596 part 6. Switch BroadcastChannel to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (feacc21f63) - Bug 1224636. Fix some code in ImageBitmap that rejects a promise with an ErrorResult, then keeps trying to use that ErrorResult. r=kaku (89b769fe07) - Bug 1224596 part 7. Switch ImageBitmap to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (e21b0a4a0a) - Bug 1183954, Don't leak nsStructuredCloneContainer (use of 'auto' is error prone), r=leak (1a9b30f2ca) - Bug 1114554 - Patch 9 - Fixed crash in b2g-desktop tests. r=nsm (6b12c6d121) - Bug 1189090 - Rework the nsISupports implementation in the ScopeCheckingGetCallback and its subclasses; r=nsm (6bea544597) - Bug 1187018 - Ensure feature is nulled out if it does not get added. r=khuey (9d7439498a) - Bug 1224596 part 8. Switch Notification to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (03f0f6877f) - Bug 1196079 - Always try to release Notification via normal WorkerRunnable first. r=wchen (c093253d6f) - Bug 1203324 - disable notifications on serviceworkers. r=ehsan,wchen (aa39310dc1) - Bug 1199901 - GetOrigin() fails cleanly instead of asserting principal. r=wchen (148c634a4f) - Bug 1199901 - Clear mObserver when WorkerNotificationObserver is destroyed. r=wchen (6d5cd99183) - Bug 1199901 - Bustage fix due to rebase. a=bustage (344bd62af5) - Bug 1225470 Report a message to the console when a service worker waitUntil() is rejected. r=baku (610da2eec6) - Bug 1217909 P1 Report service worker exceptions to controlled documents. r=catalinb (f8bd4677d5) - Bug 1216566 - Fix a bug in nsIServiceWorkerManager.getAllRegistrations;r=catalinb (ed3e14ab43) - Bug 1219205 - ServiceWorkerInfo should be an XPCOM object;r=catalinb (677a6f1ffd) - Bug 1217909 P2 Track registering documents as weak reference so SWM can report errors to them. r=catalinb (4233dc3edc) - Bug 1217909 P3 Refactor service worker register()/update() to reject only with SecurityErr or TypeErr. r=catalinb (c6891a7fae) - Bug 1220740 - nsIServiceWorkerRegistrationInfo should emit an event when its scriptSpec property changes;r=amarchesini (5772bb5914) - Bug 1207727 - Add WPT tests for service worker update algorithm. r=bkelly (a4812571a1) - Bug 1217367 - Service workers update algorithm optimization. r=bkelly (e377debad1) - Bug 1226479. Change ErrorResult::ThrowTypeError/ThrowRangeError to take string references, not pointers. r=mccr8 (0804899666) - Bug 1224659 - Worker DataStore code should not use ErrorResult cross threads, r=bz (aef03b0fdd) - Bug 1224596 part 9. Switch DataStore to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (1eb1c427f2) - Bug 1224596 part 10. Switch DataStoreCursor to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (114af8021b) - Bug 1224596 part 11. Switch WorkerNavigator to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (b2347a0c49) - Bug 1224596 part 12. Switch ServiceWorkerRegistration to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (d1ff076836) - Bug 1224596 part 13. Switch gfxUtils to using the new WorkerMainThreadRunnable::Dispatch signature. r=khuey (a523997588) - Bug 1224007 part 1. Rename ThrowMethodFailed to MaybeSetPendingException and make it an ErrorResult instance method. r=peterv (bdf0891f54) - Bug 1224007 part 2. Make the various ErrorResult::Report* methods private, so consumers all go through MaybeSetPendingException and rename them to more clearly indicate what they're actually doing. r=peterv (48f483c153) - Bug 1203151 - Allow disabling of screen wakelocks for video elements. r=baku (6bd9ff6916) - Bug 1224007 part 4. Fix some cases in which ErrorResult instances are destroyed without doing anything useful with exceptions on them. r=peterv (e328785e5d) - Bug 1224007 part 5. Get rid of ErrorResult::StealJSException. r=peterv (db19cfb31e) - Bug 1224007 part 3. Push down WouldReportJSException into MaybeSetPendingException, since anyone calling the latter will propagate the JS exception as needed. r=peterv (1d3b7b415d) - Bug 1224007 part 6. Change MaybeSetPendingException to set the ErrorResult state to "not failed", just like SuppressException and StealNSResult already do, and assert in the destructor that the ErrorResult is not Failed(). (a028838e8d) - Bug 1213815 - Update URLSearchParams and URLUtils in webidl files, r=bz (28fb8f7de5) - Bug 1213815 - dom/webidl/HTMLHyperlinkElementUtils and URL don't need to throw exceptions as we did before, r=bz (b13dc3bcb9) - Bug 1224596 part 14. Switch URL to using the new WorkerMainThreadRunnable::Dispatch signature. r=baku (232677e50e) - fix updating the backport (9e958da5ca) - Bug 1224596 part 16. Switch Fetch to using the new WorkerMainThreadRunnable::Dispatch signature. r=bkelly (939e338f22) - Bug 1224596 part 17. Remove the old WorkerMainThreadRunnable::Dispatch signature. r=khuey (5a70429ec8) - Bug 1143575. Don't report negative frame delays. r=cpearce (7d8bc0f753) - Bug 1187371 - Get rid of dom.broadcastChannel.enabled pref, r=bz (9335b7ae90) - Bug 1196514 - remove dom.messagechannel.enabled pref, r=smaug (31e06119b4) - Bug 1166356 - Properly detect double-caching in nsXULPrototypeCache; r=ehsan (29df9ffb2d) - Bug 1168916 - Get rid of redundant pref callback in nsXULPrototypeCache; r=janv (9f37fff405) - Bug 1139099: Dispatch DOMDocElementInserted to match the document-element-inserted observer notification. r=mrbkap (6565e4b924) - Bug 1187068 - Tell the cycle collector about nsContentSink::mCSSLoader. r=heycam (4ae23eb26c) - Bug 1172189 - Fix overflow in nsXULContentSink.cpp. r=ehsan (cc6330f5de) - Bug 1126010 - XULContentSinkImpl::mParser should be an nsRefPtr. r=smaug (d6bb567692) - Bug 1147946, part 7 - Remove trailing whitespace from nsXULContentSink.cpp. r=baku (cdcadbfeeb) - Bug 1147946, part 1 - Tuck elses in nsXULContentSink.cpp. r=baku (26fd806676) - Bug 1147946, part 2 - Move body of check inside prior if in XULContentSinkImpl::OpenScript(). r=baku (b509455bdb) - Bug 1147946, part 3 - Eliminate unused case for non-JS scripting languages in XULContentSinkImpl::OpenScript(). r=baku (4136933cc2) - Bug 1147946, part 4 - Use an early return in XULContentSinkImpl::OpenScript(). r=baku (c3e293474b) - Bug 1147946, part 5 - Don't use the generic nsIProgrammingLanguage enum in XULContentSinkImpl::OpenScript(). r=baku (89a124e23f) - Bug 1147946, part 6 - Remove some useless null checks on infallible new in XULContentSinkImpl. r=baku (1ac57e8c3a) - Bug 1221351 P1 ServiceWorkerContainer and ServiceWorkerRegistration should not crash for null window owner. r=catalinb (1a72748632) - Bug 1212867 - Node.isEqualNode() should ignore internal subsets; r=bzBug (99b166ffee) - Bug 492933 - getElementsByTagName should match on localName not tagName, r=smaug (d0c6ceabf1) - Bug 912470 part 1 - Implement Encoding Standard-compliant big5 decoder. r=emk. (c680b0ae9b) - Bug 1170932: Test handling of unmapped characters in unicode-to-codepage encoders (ca36bcbd35) - fix style (95a90bfe3a) - Bug 1170794 - patch 2 - Improve the length check of the input in nsUnicode*::GetMaxLength, r=dveditz (aa864d656f) - Bug 1170794 followup: Add 'override' annotations to Convert() & Reset() methods in intl/uconv. rs=ehsan (bb3e6e492e) - Bug 1176462 - Remove nsTableDecoderSupport. r=smontagu (f4a86c44b3) - Bug 1169248 - Fix GBK/GB18030 encoders. r=smontagu (ed946e1ee1) - Bug 1155539 - Remove obsolete encoding decoder telemetry probes. r=emk. (44e15bfb40) - Bug 912470 part 2 - Implement Encoding Standard-compliant big5 encoder. r=emk. (5cca2dc4a0) - Bug 912470 addendum - Pass override static analysis. r=emk. (c163bffeb4) - Bug 1170932: Improve error handling for the gbk encoder, r=emk (30e95b34a5) - Bug 1202366 - Implement the encoder error mode "HTML" for nsFormSubmission without nsISaveAsCharset. r=NOT_emk. (ebc8b542dd) - update manifest (6cc19172cc) - Bug 1197309 - remove PR_snprintf calls in intl/; r=froydnj (79fcdfa845) - Bug 1214619 - Remove nsISaveAsCharset as much as possible without breaking extensions in popular use. r=emk. (89b71b3d87) - Bug 1214857. Store the document-is-HTML state directly in nsContentList instead of refetching from the node being matched. r=smaug (4c4fbf469e) - Bug 1221351 P2 Add a web-platform-test to check for crash when calling .register() on closed window. r=catalinb (eeb30c1bba) - Bug 1221351 P3 Fix test name in register-closed-window.https.html. a=testonly (5bfa840044) - Bug 1224436: Remove enumerator usage in ServiceWorkerManager.cpp. r=njn (b8cb094d3c) - Bug 1223716. Make HTMLCollection check for the element being HTML before checking for its name inside its named getter. r=bkelly (977e0bff5a) - Bug 1180737 - Add update-test.py and update test to latest version. r=bkelly. (59faa36d5c) - Bug 1217909 P4 Extend wpt tests to verify update() promise values for different script failures. r=catalinb (a2f7352a3a) - Bug 1217909 P5 Add wpt test case for fetch event handlers that throw. r=catalinb (56a77f611c) - Bug 1217909 P6 Fix wpt registration.https.html to expect TypeError for script evaluation errors. r=catalinb (3de8a45688) - Bug 1217909 P7 Fix mochitest to expect TypeError when serviceWorker.register() rejects. r=catalinb (6e8841c41e) - Bug 1217909 P8 Track navigation interceptions per scope in ServiceWorkerManager. r=catalinb (6705ba8337) - Bug 1217909 P9 Report exceptions to windows performing an intercepted navigation. r=catalinb (52f9fece14) - Bug 1217909 P10 Remove stale nsTArray when the last registering document for a scope is removed. r=catalinb (b739bcc3b2) - Bug 1217909 P11 Only report errors to documents that are active and not in the bfcache. r=catalinb (5ffd633af2) - Bug 1223378 Tighten service worker register() principal checks. r=baku (478785f2cc) - Bug 1189685 - Part 1: Ensure that the state of all ServiceWorker instances is up to date when dispatching statechange events; r=bkelly (2bd9b78c58) - Bug 1189685 - Part 2: Make synced-state.https.html pass; r=bkelly (029f942d8c) - Bug 1220740 - nsIServiceWorkerRegistrationInfo should emit an event when its worker properties change;r=amarchesini (8243a3debc) - Bug 1186856 ServiceWorker .register() should always stop current registration from uninstalling. r=jdm (ec7d6e0e7c) - Bug 1224941 Don't crash during ServiceWorker life cycle event dispatch if window is gone. r=baku (a3f45af3e4) - Bug 1180754 - Get serviceworkerobject-scripturl test passing. r=bkelly (c7979bef47) - Bug 1201498 - Service worker update should compare scriptURL to worker URL without fragment, r=bkelly (914f630528) - Bug 594505 - Remove obsolete comment since this bug has now been fixed. r=me DONTBUILD (44f3a15b91) - Bug 1221840. Support repeating images in 1 axis. r=seth (449ea3e97e) - const-var (5433688051) - Bug 1574573 - Disambiguate a use of Handle in XPCShellEnvironment.cpp r=Ehsan (15b44177d1) - clean up warnings (6e64313d0c)
1064 lines
28 KiB
C++
1064 lines
28 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
/* 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 "imgFrame.h"
|
|
#include "ImageRegion.h"
|
|
#include "ShutdownTracker.h"
|
|
|
|
#include "prenv.h"
|
|
|
|
#include "gfx2DGlue.h"
|
|
#include "gfxPlatform.h"
|
|
#include "gfxUtils.h"
|
|
#include "gfxAlphaRecovery.h"
|
|
|
|
static bool gDisableOptimize = false;
|
|
|
|
#include "GeckoProfiler.h"
|
|
#include "mozilla/Likely.h"
|
|
#include "MainThreadUtils.h"
|
|
#include "mozilla/MemoryReporting.h"
|
|
#include "nsMargin.h"
|
|
#include "nsThreadUtils.h"
|
|
#include "mozilla/CheckedInt.h"
|
|
#include "mozilla/gfx/Tools.h"
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace gfx;
|
|
|
|
namespace image {
|
|
|
|
static UserDataKey kVolatileBuffer;
|
|
|
|
static void
|
|
VolatileBufferRelease(void* vbuf)
|
|
{
|
|
delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
|
|
}
|
|
|
|
static int32_t
|
|
VolatileSurfaceStride(const IntSize& size, SurfaceFormat format)
|
|
{
|
|
// Stride must be a multiple of four or cairo will complain.
|
|
return (size.width * BytesPerPixel(format) + 0x3) & ~0x3;
|
|
}
|
|
|
|
static already_AddRefed<DataSourceSurface>
|
|
CreateLockedSurface(VolatileBuffer* vbuf,
|
|
const IntSize& size,
|
|
SurfaceFormat format)
|
|
{
|
|
VolatileBufferPtr<unsigned char>* vbufptr =
|
|
new VolatileBufferPtr<unsigned char>(vbuf);
|
|
MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
|
|
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
|
RefPtr<DataSourceSurface> surf =
|
|
Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format);
|
|
if (!surf) {
|
|
delete vbufptr;
|
|
return nullptr;
|
|
}
|
|
|
|
surf->AddUserData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
|
|
return surf.forget();
|
|
}
|
|
|
|
static already_AddRefed<VolatileBuffer>
|
|
AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
|
|
{
|
|
int32_t stride = VolatileSurfaceStride(size, format);
|
|
RefPtr<VolatileBuffer> buf = new VolatileBuffer();
|
|
if (buf->Init(stride * size.height,
|
|
1 << gfxAlphaRecovery::GoodAlignmentLog2())) {
|
|
return buf.forget();
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
// Returns true if an image of aWidth x aHeight is allowed and legal.
|
|
static bool
|
|
AllowedImageSize(int32_t aWidth, int32_t aHeight)
|
|
{
|
|
// reject over-wide or over-tall images
|
|
const int32_t k64KLimit = 0x0000FFFF;
|
|
if (MOZ_UNLIKELY(aWidth > k64KLimit || aHeight > k64KLimit )) {
|
|
NS_WARNING("image too big");
|
|
return false;
|
|
}
|
|
|
|
// protect against invalid sizes
|
|
if (MOZ_UNLIKELY(aHeight <= 0 || aWidth <= 0)) {
|
|
return false;
|
|
}
|
|
|
|
// check to make sure we don't overflow a 32-bit
|
|
CheckedInt32 requiredBytes = CheckedInt32(aWidth) * CheckedInt32(aHeight) * 4;
|
|
if (MOZ_UNLIKELY(!requiredBytes.isValid())) {
|
|
NS_WARNING("width or height too large");
|
|
return false;
|
|
}
|
|
#if defined(XP_MACOSX)
|
|
// CoreGraphics is limited to images < 32K in *height*, so clamp all surfaces
|
|
// on the Mac to that height
|
|
if (MOZ_UNLIKELY(aHeight > SHRT_MAX)) {
|
|
NS_WARNING("image too big");
|
|
return false;
|
|
}
|
|
#endif
|
|
return true;
|
|
}
|
|
|
|
static bool AllowedImageAndFrameDimensions(const nsIntSize& aImageSize,
|
|
const nsIntRect& aFrameRect)
|
|
{
|
|
if (!AllowedImageSize(aImageSize.width, aImageSize.height)) {
|
|
return false;
|
|
}
|
|
if (!AllowedImageSize(aFrameRect.width, aFrameRect.height)) {
|
|
return false;
|
|
}
|
|
nsIntRect imageRect(0, 0, aImageSize.width, aImageSize.height);
|
|
if (!imageRect.Contains(aFrameRect)) {
|
|
NS_WARNING("Animated image frame does not fit inside bounds of image");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
imgFrame::imgFrame()
|
|
: mMonitor("imgFrame")
|
|
, mDecoded(0, 0, 0, 0)
|
|
, mLockCount(0)
|
|
, mTimeout(100)
|
|
, mDisposalMethod(DisposalMethod::NOT_SPECIFIED)
|
|
, mBlendMethod(BlendMethod::OVER)
|
|
, mHasNoAlpha(false)
|
|
, mAborted(false)
|
|
, mOptimizable(false)
|
|
, mPalettedImageData(nullptr)
|
|
, mPaletteDepth(0)
|
|
, mNonPremult(false)
|
|
, mSinglePixel(false)
|
|
, mCompositingFailed(false)
|
|
{
|
|
static bool hasCheckedOptimize = false;
|
|
if (!hasCheckedOptimize) {
|
|
if (PR_GetEnv("MOZ_DISABLE_IMAGE_OPTIMIZE")) {
|
|
gDisableOptimize = true;
|
|
}
|
|
hasCheckedOptimize = true;
|
|
}
|
|
}
|
|
|
|
imgFrame::~imgFrame()
|
|
{
|
|
#ifdef DEBUG
|
|
MonitorAutoLock lock(mMonitor);
|
|
MOZ_ASSERT(mAborted || IsImageCompleteInternal());
|
|
#endif
|
|
|
|
moz_free(mPalettedImageData);
|
|
mPalettedImageData = nullptr;
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::InitForDecoder(const nsIntSize& aImageSize,
|
|
const nsIntRect& aRect,
|
|
SurfaceFormat aFormat,
|
|
uint8_t aPaletteDepth /* = 0 */,
|
|
bool aNonPremult /* = false */)
|
|
{
|
|
// Assert for properties that should be verified by decoders,
|
|
// warn for properties related to bad content.
|
|
if (!AllowedImageAndFrameDimensions(aImageSize, aRect)) {
|
|
NS_WARNING("Should have legal image size");
|
|
mAborted = true;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
mImageSize = aImageSize;
|
|
mOffset.MoveTo(aRect.x, aRect.y);
|
|
mSize.SizeTo(aRect.width, aRect.height);
|
|
|
|
mFormat = aFormat;
|
|
mPaletteDepth = aPaletteDepth;
|
|
mNonPremult = aNonPremult;
|
|
|
|
if (aPaletteDepth != 0) {
|
|
// We're creating for a paletted image.
|
|
if (aPaletteDepth > 8) {
|
|
NS_WARNING("Should have legal palette depth");
|
|
NS_ERROR("This Depth is not supported");
|
|
mAborted = true;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Use the fallible allocator here. Paletted images always use 1 byte per
|
|
// pixel, so calculating the amount of memory we need is straightforward.
|
|
mPalettedImageData =
|
|
static_cast<uint8_t*>(moz_malloc(PaletteDataLength() +
|
|
(mSize.width * mSize.height)));
|
|
if (!mPalettedImageData) {
|
|
NS_WARNING("malloc for paletted image data should succeed");
|
|
}
|
|
NS_ENSURE_TRUE(mPalettedImageData, NS_ERROR_OUT_OF_MEMORY);
|
|
} else {
|
|
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitForDecoder() twice?");
|
|
|
|
mVBuf = AllocateBufferForImage(mSize, mFormat);
|
|
if (!mVBuf) {
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
if (mVBuf->OnHeap()) {
|
|
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
|
|
VolatileBufferPtr<uint8_t> ptr(mVBuf);
|
|
memset(ptr, 0, stride * mSize.height);
|
|
}
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
if (!mImageSurface) {
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::InitWithDrawable(gfxDrawable* aDrawable,
|
|
const nsIntSize& aSize,
|
|
const SurfaceFormat aFormat,
|
|
Filter aFilter,
|
|
uint32_t aImageFlags)
|
|
{
|
|
// Assert for properties that should be verified by decoders,
|
|
// warn for properties related to bad content.
|
|
if (!AllowedImageSize(aSize.width, aSize.height)) {
|
|
NS_WARNING("Should have legal image size");
|
|
mAborted = true;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
mImageSize = aSize;
|
|
mOffset.MoveTo(0, 0);
|
|
mSize.SizeTo(aSize.width, aSize.height);
|
|
|
|
mFormat = aFormat;
|
|
mPaletteDepth = 0;
|
|
|
|
RefPtr<DrawTarget> target;
|
|
|
|
bool canUseDataSurface =
|
|
gfxPlatform::GetPlatform()->CanRenderContentToDataSurface();
|
|
|
|
if (canUseDataSurface) {
|
|
// It's safe to use data surfaces for content on this platform, so we can
|
|
// get away with using volatile buffers.
|
|
MOZ_ASSERT(!mImageSurface, "Called imgFrame::InitWithDrawable() twice?");
|
|
|
|
mVBuf = AllocateBufferForImage(mSize, mFormat);
|
|
if (!mVBuf) {
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
int32_t stride = VolatileSurfaceStride(mSize, mFormat);
|
|
VolatileBufferPtr<uint8_t> ptr(mVBuf);
|
|
if (!ptr) {
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
if (mVBuf->OnHeap()) {
|
|
memset(ptr, 0, stride * mSize.height);
|
|
}
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
|
|
target = gfxPlatform::GetPlatform()->
|
|
CreateDrawTargetForData(ptr, mSize, stride, mFormat);
|
|
} else {
|
|
// We can't use data surfaces for content, so we'll create an offscreen
|
|
// surface instead. This means if someone later calls RawAccessRef(), we
|
|
// may have to do an expensive readback, but we warned callers about that in
|
|
// the documentation for this method.
|
|
MOZ_ASSERT(!mOptSurface, "Called imgFrame::InitWithDrawable() twice?");
|
|
|
|
target = gfxPlatform::GetPlatform()->
|
|
CreateOffscreenContentDrawTarget(mSize, mFormat);
|
|
}
|
|
|
|
if (!target) {
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
// Draw using the drawable the caller provided.
|
|
nsIntRect imageRect(0, 0, mSize.width, mSize.height);
|
|
RefPtr<gfxContext> ctx = new gfxContext(target);
|
|
gfxUtils::DrawPixelSnapped(ctx, aDrawable, mSize,
|
|
ImageRegion::Create(ThebesRect(imageRect)),
|
|
mFormat, aFilter, aImageFlags);
|
|
|
|
if (canUseDataSurface && !mImageSurface) {
|
|
NS_WARNING("Failed to create VolatileDataSourceSurface");
|
|
mAborted = true;
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
if (!canUseDataSurface) {
|
|
// We used an offscreen surface, which is an "optimized" surface from
|
|
// imgFrame's perspective.
|
|
mOptSurface = target->Snapshot();
|
|
}
|
|
|
|
// If we reach this point, we should regard ourselves as complete.
|
|
mDecoded = GetRect();
|
|
MOZ_ASSERT(IsImageComplete());
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::Optimize()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
MOZ_ASSERT(mLockCount == 1,
|
|
"Should only optimize when holding the lock exclusively");
|
|
|
|
// Don't optimize during shutdown because gfxPlatform may not be available.
|
|
if (ShutdownTracker::ShutdownHasStarted()) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!mOptimizable || gDisableOptimize) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (mPalettedImageData || mOptSurface || mSinglePixel) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// Don't do single-color opts on non-premult data.
|
|
// Cairo doesn't support non-premult single-colors.
|
|
if (mNonPremult) {
|
|
return NS_OK;
|
|
}
|
|
|
|
/* Figure out if the entire image is a constant color */
|
|
|
|
if (gfxPrefs::ImageSingleColorOptimizationEnabled() &&
|
|
mImageSurface->Stride() == mSize.width * 4) {
|
|
uint32_t* imgData = (uint32_t*) ((uint8_t*) mVBufPtr);
|
|
uint32_t firstPixel = * (uint32_t*) imgData;
|
|
uint32_t pixelCount = mSize.width * mSize.height + 1;
|
|
|
|
while (--pixelCount && *imgData++ == firstPixel)
|
|
;
|
|
|
|
if (pixelCount == 0) {
|
|
// all pixels were the same
|
|
if (mFormat == SurfaceFormat::B8G8R8A8 ||
|
|
mFormat == SurfaceFormat::B8G8R8X8) {
|
|
mSinglePixel = true;
|
|
mSinglePixelColor.a = ((firstPixel >> 24) & 0xFF) * (1.0f / 255.0f);
|
|
mSinglePixelColor.r = ((firstPixel >> 16) & 0xFF) * (1.0f / 255.0f);
|
|
mSinglePixelColor.g = ((firstPixel >> 8) & 0xFF) * (1.0f / 255.0f);
|
|
mSinglePixelColor.b = ((firstPixel >> 0) & 0xFF) * (1.0f / 255.0f);
|
|
mSinglePixelColor.r /= mSinglePixelColor.a;
|
|
mSinglePixelColor.g /= mSinglePixelColor.a;
|
|
mSinglePixelColor.b /= mSinglePixelColor.a;
|
|
|
|
// blow away the older surfaces (if they exist), to release their memory
|
|
mVBuf = nullptr;
|
|
mVBufPtr = nullptr;
|
|
mImageSurface = nullptr;
|
|
mOptSurface = nullptr;
|
|
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
// if it's not RGB24/ARGB32, don't optimize, but we never hit this at the
|
|
// moment
|
|
}
|
|
|
|
#ifdef ANDROID
|
|
SurfaceFormat optFormat = gfxPlatform::GetPlatform()
|
|
->Optimal2DFormatForContent(gfxContentType::COLOR);
|
|
|
|
if (mFormat != SurfaceFormat::B8G8R8A8 &&
|
|
optFormat == SurfaceFormat::R5G6B5_UINT16) {
|
|
RefPtr<VolatileBuffer> buf =
|
|
AllocateBufferForImage(mSize, optFormat);
|
|
if (!buf) {
|
|
return NS_OK;
|
|
}
|
|
|
|
RefPtr<DataSourceSurface> surf =
|
|
CreateLockedSurface(buf, mSize, optFormat);
|
|
if (!surf) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
|
|
DataSourceSurface::MappedSurface mapping;
|
|
if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) {
|
|
gfxCriticalError() << "imgFrame::Optimize failed to map surface";
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
RefPtr<DrawTarget> target =
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
mapping.mData,
|
|
mSize,
|
|
mapping.mStride,
|
|
optFormat);
|
|
|
|
if (!target) {
|
|
gfxWarning() << "imgFrame::Optimize failed in CreateDrawTargetForData";
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
Rect rect(0, 0, mSize.width, mSize.height);
|
|
target->DrawSurface(mImageSurface, rect, rect);
|
|
target->Flush();
|
|
surf->Unmap();
|
|
|
|
mImageSurface = surf;
|
|
mVBuf = buf;
|
|
mFormat = optFormat;
|
|
}
|
|
#else
|
|
mOptSurface = gfxPlatform::GetPlatform()
|
|
->ScreenReferenceDrawTarget()->OptimizeSourceSurface(mImageSurface);
|
|
if (mOptSurface == mImageSurface) {
|
|
mOptSurface = nullptr;
|
|
}
|
|
#endif
|
|
|
|
if (mOptSurface) {
|
|
mVBuf = nullptr;
|
|
mVBufPtr = nullptr;
|
|
mImageSurface = nullptr;
|
|
}
|
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
// On Android, free mImageSurface unconditionally if we're discardable. This
|
|
// allows the operating system to free our volatile buffer.
|
|
// XXX(seth): We'd eventually like to do this on all platforms, but right now
|
|
// converting raw memory to a SourceSurface is expensive on some backends.
|
|
mImageSurface = nullptr;
|
|
#endif
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
DrawableFrameRef
|
|
imgFrame::DrawableRef()
|
|
{
|
|
return DrawableFrameRef(this);
|
|
}
|
|
|
|
RawAccessFrameRef
|
|
imgFrame::RawAccessRef()
|
|
{
|
|
return RawAccessFrameRef(this);
|
|
}
|
|
|
|
void
|
|
imgFrame::SetRawAccessOnly()
|
|
{
|
|
AssertImageDataLocked();
|
|
|
|
// Lock our data and throw away the key.
|
|
LockImageData();
|
|
}
|
|
|
|
|
|
imgFrame::SurfaceWithFormat
|
|
imgFrame::SurfaceForDrawing(bool aDoPadding,
|
|
bool aDoPartialDecode,
|
|
bool aDoTile,
|
|
gfxContext* aContext,
|
|
const nsIntMargin& aPadding,
|
|
gfxRect& aImageRect,
|
|
ImageRegion& aRegion,
|
|
SourceSurface* aSurface)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
IntSize size(int32_t(aImageRect.Width()), int32_t(aImageRect.Height()));
|
|
if (!aDoPadding && !aDoPartialDecode) {
|
|
NS_ASSERTION(!mSinglePixel, "This should already have been handled");
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, size), mFormat);
|
|
}
|
|
|
|
gfxRect available = gfxRect(mDecoded.x, mDecoded.y, mDecoded.width,
|
|
mDecoded.height);
|
|
|
|
if (aDoTile || mSinglePixel) {
|
|
// Create a temporary surface.
|
|
// Give this surface an alpha channel because there are
|
|
// transparent pixels in the padding or undecoded area
|
|
RefPtr<DrawTarget> target =
|
|
gfxPlatform::GetPlatform()->
|
|
CreateOffscreenContentDrawTarget(size, SurfaceFormat::B8G8R8A8);
|
|
if (!target) {
|
|
return SurfaceWithFormat();
|
|
}
|
|
|
|
// Fill 'available' with whatever we've got
|
|
if (mSinglePixel) {
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()),
|
|
ColorPattern(mSinglePixelColor),
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
} else {
|
|
SurfacePattern pattern(aSurface,
|
|
aRegion.GetExtendMode(),
|
|
Matrix::Translation(mDecoded.x, mDecoded.y));
|
|
target->FillRect(ToRect(aRegion.Intersect(available).Rect()), pattern);
|
|
}
|
|
|
|
RefPtr<SourceSurface> newsurf = target->Snapshot();
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(newsurf, size),
|
|
target->GetFormat());
|
|
}
|
|
|
|
// Not tiling, and we have a surface, so we can account for
|
|
// padding and/or a partial decode just by twiddling parameters.
|
|
gfxPoint paddingTopLeft(aPadding.left, aPadding.top);
|
|
aRegion = aRegion.Intersect(available) - paddingTopLeft;
|
|
aContext->Multiply(gfxMatrix::Translation(paddingTopLeft));
|
|
aImageRect = gfxRect(0, 0, mSize.width, mSize.height);
|
|
|
|
IntSize availableSize(mDecoded.width, mDecoded.height);
|
|
return SurfaceWithFormat(new gfxSurfaceDrawable(aSurface, availableSize),
|
|
mFormat);
|
|
}
|
|
|
|
bool imgFrame::Draw(gfxContext* aContext, const ImageRegion& aRegion,
|
|
Filter aFilter, uint32_t aImageFlags)
|
|
{
|
|
PROFILER_LABEL("imgFrame", "Draw",
|
|
js::ProfileEntry::Category::GRAPHICS);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
NS_ASSERTION(!aRegion.Rect().IsEmpty(), "Drawing empty region!");
|
|
NS_ASSERTION(!aRegion.IsRestricted() ||
|
|
!aRegion.Rect().Intersect(aRegion.Restriction()).IsEmpty(),
|
|
"We must be allowed to sample *some* source pixels!");
|
|
NS_ASSERTION(!mPalettedImageData, "Directly drawing a paletted image!");
|
|
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
nsIntMargin padding(mOffset.y,
|
|
mImageSize.width - (mOffset.x + mSize.width),
|
|
mImageSize.height - (mOffset.y + mSize.height),
|
|
mOffset.x);
|
|
|
|
bool doPadding = padding != nsIntMargin(0,0,0,0);
|
|
bool doPartialDecode = !IsImageCompleteInternal();
|
|
|
|
if (mSinglePixel && !doPadding && !doPartialDecode) {
|
|
if (mSinglePixelColor.a == 0.0) {
|
|
return true;
|
|
}
|
|
RefPtr<DrawTarget> dt = aContext->GetDrawTarget();
|
|
dt->FillRect(ToRect(aRegion.Rect()),
|
|
ColorPattern(mSinglePixelColor),
|
|
DrawOptions(1.0f, aContext->CurrentOp()));
|
|
return true;
|
|
}
|
|
|
|
RefPtr<SourceSurface> surf = GetSurfaceInternal();
|
|
if (!surf && !mSinglePixel) {
|
|
return false;
|
|
}
|
|
|
|
gfxRect imageRect(0, 0, mImageSize.width, mImageSize.height);
|
|
bool doTile = !imageRect.Contains(aRegion.Rect()) &&
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
|
|
|
ImageRegion region(aRegion);
|
|
// SurfaceForDrawing changes the current transform, and we need it to still
|
|
// be changed when we call gfxUtils::DrawPixelSnapped. We still need to
|
|
// restore it before returning though.
|
|
// XXXjwatt In general having functions require someone further up the stack
|
|
// to undo transform changes that they make is bad practice. We should
|
|
// change how this code works.
|
|
gfxContextMatrixAutoSaveRestore autoSR(aContext);
|
|
SurfaceWithFormat surfaceResult =
|
|
SurfaceForDrawing(doPadding, doPartialDecode, doTile, aContext,
|
|
padding, imageRect, region, surf);
|
|
|
|
if (surfaceResult.IsValid()) {
|
|
gfxUtils::DrawPixelSnapped(aContext, surfaceResult.mDrawable,
|
|
imageRect.Size(), region, surfaceResult.mFormat,
|
|
aFilter, aImageFlags);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::ImageUpdated(const nsIntRect& aUpdateRect)
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
return ImageUpdatedInternal(aUpdateRect);
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::ImageUpdatedInternal(const nsIntRect& aUpdateRect)
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
mDecoded.UnionRect(mDecoded, aUpdateRect);
|
|
|
|
// clamp to bounds, in case someone sends a bogus updateRect (I'm looking at
|
|
// you, gif decoder)
|
|
nsIntRect boundsRect(mOffset, mSize);
|
|
mDecoded.IntersectRect(mDecoded, boundsRect);
|
|
|
|
// If the image is now complete, wake up anyone who's waiting.
|
|
if (IsImageCompleteInternal()) {
|
|
mMonitor.NotifyAll();
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
imgFrame::Finish(Opacity aFrameOpacity /* = Opacity::SOME_TRANSPARENCY */,
|
|
DisposalMethod aDisposalMethod /* = DisposalMethod::KEEP */,
|
|
int32_t aRawTimeout /* = 0 */,
|
|
BlendMethod aBlendMethod /* = BlendMethod::OVER */)
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
if (aFrameOpacity == Opacity::OPAQUE) {
|
|
mHasNoAlpha = true;
|
|
}
|
|
|
|
mDisposalMethod = aDisposalMethod;
|
|
mTimeout = aRawTimeout;
|
|
mBlendMethod = aBlendMethod;
|
|
ImageUpdatedInternal(GetRect());
|
|
}
|
|
|
|
nsIntRect
|
|
imgFrame::GetRect() const
|
|
{
|
|
return gfx::IntRect(mOffset, mSize);
|
|
}
|
|
|
|
int32_t
|
|
imgFrame::GetStride() const
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
if (mImageSurface) {
|
|
return mImageSurface->Stride();
|
|
}
|
|
|
|
return VolatileSurfaceStride(mSize, mFormat);
|
|
}
|
|
|
|
SurfaceFormat
|
|
imgFrame::GetFormat() const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
return mFormat;
|
|
}
|
|
|
|
uint32_t
|
|
imgFrame::GetImageBytesPerRow() const
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
if (mVBuf) {
|
|
return mSize.width * BytesPerPixel(mFormat);
|
|
}
|
|
|
|
if (mPaletteDepth) {
|
|
return mSize.width;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint32_t
|
|
imgFrame::GetImageDataLength() const
|
|
{
|
|
return GetImageBytesPerRow() * mSize.height;
|
|
}
|
|
|
|
void
|
|
imgFrame::GetImageData(uint8_t** aData, uint32_t* aLength) const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
GetImageDataInternal(aData, aLength);
|
|
}
|
|
|
|
void
|
|
imgFrame::GetImageDataInternal(uint8_t** aData, uint32_t* aLength) const
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
if (mImageSurface) {
|
|
*aData = mVBufPtr;
|
|
MOZ_ASSERT(*aData,
|
|
"mImageSurface is non-null, but mVBufPtr is null in GetImageData");
|
|
} else if (mPalettedImageData) {
|
|
*aData = mPalettedImageData + PaletteDataLength();
|
|
MOZ_ASSERT(*aData,
|
|
"mPalettedImageData is non-null, but result is null in GetImageData");
|
|
} else {
|
|
MOZ_ASSERT(false,
|
|
"Have neither mImageSurface nor mPalettedImageData in GetImageData");
|
|
*aData = nullptr;
|
|
}
|
|
|
|
*aLength = GetImageDataLength();
|
|
}
|
|
|
|
uint8_t*
|
|
imgFrame::GetImageData() const
|
|
{
|
|
uint8_t* data;
|
|
uint32_t length;
|
|
GetImageData(&data, &length);
|
|
return data;
|
|
}
|
|
|
|
bool
|
|
imgFrame::GetIsPaletted() const
|
|
{
|
|
return mPalettedImageData != nullptr;
|
|
}
|
|
|
|
void
|
|
imgFrame::GetPaletteData(uint32_t** aPalette, uint32_t* length) const
|
|
{
|
|
AssertImageDataLocked();
|
|
|
|
if (!mPalettedImageData) {
|
|
*aPalette = nullptr;
|
|
*length = 0;
|
|
} else {
|
|
*aPalette = (uint32_t*) mPalettedImageData;
|
|
*length = PaletteDataLength();
|
|
}
|
|
}
|
|
|
|
uint32_t*
|
|
imgFrame::GetPaletteData() const
|
|
{
|
|
uint32_t* data;
|
|
uint32_t length;
|
|
GetPaletteData(&data, &length);
|
|
return data;
|
|
}
|
|
|
|
nsresult
|
|
imgFrame::LockImageData()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(mLockCount >= 0, "Unbalanced locks and unlocks");
|
|
if (mLockCount < 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
mLockCount++;
|
|
|
|
// If we are not the first lock, there's nothing to do.
|
|
if (mLockCount != 1) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// If we're the first lock, but have an image surface, we're OK.
|
|
if (mImageSurface) {
|
|
mVBufPtr = mVBuf;
|
|
return NS_OK;
|
|
}
|
|
|
|
// Paletted images don't have surfaces, so there's nothing to do.
|
|
if (mPalettedImageData) {
|
|
return NS_OK;
|
|
}
|
|
|
|
MOZ_ASSERT_UNREACHABLE("It's illegal to re-lock an optimized imgFrame");
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
void
|
|
imgFrame::AssertImageDataLocked() const
|
|
{
|
|
#ifdef DEBUG
|
|
MonitorAutoLock lock(mMonitor);
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
#endif
|
|
}
|
|
|
|
class UnlockImageDataRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
explicit UnlockImageDataRunnable(imgFrame* aTarget)
|
|
: mTarget(aTarget)
|
|
{
|
|
MOZ_ASSERT(mTarget);
|
|
}
|
|
|
|
NS_IMETHOD Run() { return mTarget->UnlockImageData(); }
|
|
|
|
private:
|
|
RefPtr<imgFrame> mTarget;
|
|
};
|
|
|
|
nsresult
|
|
imgFrame::UnlockImageData()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
MOZ_ASSERT(mLockCount > 0, "Unlocking an unlocked image!");
|
|
if (mLockCount <= 0) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
MOZ_ASSERT(mLockCount > 1 || IsImageCompleteInternal() || mAborted,
|
|
"Should have marked complete or aborted before unlocking");
|
|
|
|
// If we're about to become unlocked, we don't need to hold on to our data
|
|
// surface anymore. (But we don't need to do anything for paletted images,
|
|
// which don't have surfaces.)
|
|
if (mLockCount == 1 && !mPalettedImageData) {
|
|
// We can't safely optimize off-main-thread, so create a runnable to do it.
|
|
if (!NS_IsMainThread()) {
|
|
nsCOMPtr<nsIRunnable> runnable = new UnlockImageDataRunnable(this);
|
|
NS_DispatchToMainThread(runnable);
|
|
return NS_OK;
|
|
}
|
|
|
|
// If we're using a surface format with alpha but the image has no alpha,
|
|
// change the format. This doesn't change the underlying data at all, but
|
|
// allows DrawTargets to avoid blending when drawing known opaque images.
|
|
if (mHasNoAlpha && mFormat == SurfaceFormat::B8G8R8A8 && mImageSurface) {
|
|
mFormat = SurfaceFormat::B8G8R8X8;
|
|
mImageSurface = CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
}
|
|
|
|
// Convert the data surface to a GPU surface or a single color if possible.
|
|
// This will also release mImageSurface if possible.
|
|
Optimize();
|
|
|
|
// Allow the OS to release our data surface.
|
|
mVBufPtr = nullptr;
|
|
}
|
|
|
|
mLockCount--;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
imgFrame::SetOptimizable()
|
|
{
|
|
AssertImageDataLocked();
|
|
MonitorAutoLock lock(mMonitor);
|
|
mOptimizable = true;
|
|
}
|
|
|
|
Color
|
|
imgFrame::SinglePixelColor() const
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
return mSinglePixelColor;
|
|
}
|
|
|
|
bool
|
|
imgFrame::IsSinglePixel() const
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
return mSinglePixel;
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
imgFrame::GetSurface()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
return GetSurfaceInternal();
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
imgFrame::GetSurfaceInternal()
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
|
|
if (mOptSurface) {
|
|
if (mOptSurface->IsValid()) {
|
|
RefPtr<SourceSurface> surf(mOptSurface);
|
|
return surf.forget();
|
|
} else {
|
|
mOptSurface = nullptr;
|
|
}
|
|
}
|
|
|
|
if (mImageSurface) {
|
|
RefPtr<SourceSurface> surf(mImageSurface);
|
|
return surf.forget();
|
|
}
|
|
|
|
if (!mVBuf) {
|
|
return nullptr;
|
|
}
|
|
|
|
VolatileBufferPtr<char> buf(mVBuf);
|
|
if (buf.WasBufferPurged()) {
|
|
return nullptr;
|
|
}
|
|
|
|
return CreateLockedSurface(mVBuf, mSize, mFormat);
|
|
}
|
|
|
|
already_AddRefed<DrawTarget>
|
|
imgFrame::GetDrawTarget()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
uint8_t* data;
|
|
uint32_t length;
|
|
GetImageDataInternal(&data, &length);
|
|
if (!data) {
|
|
return nullptr;
|
|
}
|
|
|
|
int32_t stride = GetStride();
|
|
return gfxPlatform::GetPlatform()->
|
|
CreateDrawTargetForData(data, mSize, stride, mFormat);
|
|
}
|
|
|
|
AnimationData
|
|
imgFrame::GetAnimationData() const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
|
|
uint8_t* data;
|
|
if (mPalettedImageData) {
|
|
data = mPalettedImageData;
|
|
} else {
|
|
uint32_t length;
|
|
GetImageDataInternal(&data, &length);
|
|
}
|
|
|
|
bool hasAlpha = mFormat == SurfaceFormat::B8G8R8A8;
|
|
|
|
return AnimationData(data, PaletteDataLength(), mTimeout, GetRect(),
|
|
mBlendMethod, mDisposalMethod, hasAlpha);
|
|
}
|
|
|
|
ScalingData
|
|
imgFrame::GetScalingData() const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
MOZ_ASSERT(mLockCount > 0, "Image data should be locked");
|
|
MOZ_ASSERT(!GetIsPaletted(), "GetScalingData can't handle paletted images");
|
|
|
|
uint8_t* data;
|
|
uint32_t length;
|
|
GetImageDataInternal(&data, &length);
|
|
|
|
return ScalingData(data, mSize, GetImageBytesPerRow(), mFormat);
|
|
}
|
|
|
|
void
|
|
imgFrame::Abort()
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
mAborted = true;
|
|
|
|
// Wake up anyone who's waiting.
|
|
mMonitor.NotifyAll();
|
|
}
|
|
|
|
bool
|
|
imgFrame::IsImageComplete() const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
return IsImageCompleteInternal();
|
|
}
|
|
|
|
void
|
|
imgFrame::WaitUntilComplete() const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
while (true) {
|
|
// Return if we're aborted or complete.
|
|
if (mAborted || IsImageCompleteInternal()) {
|
|
return;
|
|
}
|
|
|
|
// Not complete yet, so we'll have to wait.
|
|
mMonitor.Wait();
|
|
}
|
|
}
|
|
|
|
bool
|
|
imgFrame::IsImageCompleteInternal() const
|
|
{
|
|
mMonitor.AssertCurrentThreadOwns();
|
|
return mDecoded.IsEqualInterior(nsIntRect(mOffset.x, mOffset.y,
|
|
mSize.width, mSize.height));
|
|
}
|
|
|
|
bool imgFrame::GetCompositingFailed() const
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
return mCompositingFailed;
|
|
}
|
|
|
|
void
|
|
imgFrame::SetCompositingFailed(bool val)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
mCompositingFailed = val;
|
|
}
|
|
|
|
void
|
|
imgFrame::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
|
|
size_t& aHeapSizeOut,
|
|
size_t& aNonHeapSizeOut) const
|
|
{
|
|
MonitorAutoLock lock(mMonitor);
|
|
|
|
if (mPalettedImageData) {
|
|
aHeapSizeOut += aMallocSizeOf(mPalettedImageData);
|
|
}
|
|
if (mImageSurface) {
|
|
aHeapSizeOut += aMallocSizeOf(mImageSurface);
|
|
}
|
|
if (mOptSurface) {
|
|
aHeapSizeOut += aMallocSizeOf(mOptSurface);
|
|
}
|
|
|
|
if (mVBuf) {
|
|
aHeapSizeOut += aMallocSizeOf(mVBuf);
|
|
aHeapSizeOut += mVBuf->HeapSizeOfExcludingThis(aMallocSizeOf);
|
|
aNonHeapSizeOut += mVBuf->NonHeapSizeOfExcludingThis();
|
|
}
|
|
}
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|