mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
ebda1f73c4
- Bug 1208341 - Make NativeObject::goodElementsAllocationAmount fallible. r=Waldo (64eac96aa2) - minor reformat (95d27e5332) - Bug 1214049 - Use ReportOutOfMemory in NativeObject::goodElementsAllocationAmount. r=Waldo (6779dd81c6) - Bug 1206700 - Fix an bug in property assignment, recently exposed by Reflect.set. r=waldo (0a7484ab70) - Bug 1186810 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm. (05a550c94f) - Bug 1186810 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm. (f1659abf38) - Bug 1186810 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm. (cda73950f3) - Bug 1186810 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm. (555e83bacb) - Bug 1186810 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=nsm. (c9520dbc5f) - Bug 1186810 (part 6) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=khuey. (24fcdfd772) - Bug 1186810 (part 7) - Replace nsBaseHashtable::EnumerateRead() calls in dom/workers/ with iterators. r=khuey. (657cd575fb) - Bug 1186810 (part 8) - Replace nsBaseHashtable::Enumerate() calls in dom/workers/ with iterators. r=khuey. (0ff6a5e5ff) - Bug 1205020 - Disable optimizations in TestTuple.cpp since it breaks the build on VS2013 Windows 10. r=froydnj (1c98d8485c) - Bug 1199068 - Soothe a unused variable warning in TestSplayTree.cpp. r=nfroyd (d4d4ab56fe) - Bug 1209751 - Make sync decoding more reliable when nsImageRenderer is used with -moz-element. r=roc (95c99bb907) - Bug 1209731 - Return DrawResult::NOT_READY from PaintBackgroundWithSC if we couldn't prepare the nsImageRenderer. r=tn (8bd98872cb) - Bug 1209715 - Add operator overloads for combining DrawResults. r=tn (f3a9806d03) - Bug 1209725 - Use DrawResult combining operators in nsCSSRendering::PaintBackgroundWithSC. r=tn (420cfde63e) - Bug 1211363. Calculate min inset blur with max border radius. r=mstange (5e408bc67f) - Bug 1213545. Carry x,y offsets with inset box shadows. r=mstange (52c20715bc) - Bug 1209739 - Make nsImageRenderer::PrepareImage() fail unless an image has STATUS_LOAD_COMPLETE. r=tn (c1cc4d79d8) - Bug 1209765 (Part 1) - Support sync decoding of border-image in nsCSSRendering. r=tn (3a54b7d117) - Bug 1209765 (Part 2) - Support sync decoding and track draw results in nsDisplayBorder. r=tn (03abe63e67) - Bug 1209765 (Part 3) - Support sync decoding and track draw results when drawing borders in nsButtonFrameRenderer. r=tn (107b9bb851) - Bug 1209765 (Part 4) - Support sync decoding and track draw results when drawing borders in nsFieldSetFrame. r=tn (16fd30aba3) - Bug 1209765 (Part 5) - Support sync decoding and track draw results when drawing borders in nsRangeFrame. r=tn (289de3c17e) - Bug 1209765 (Part 6) - Support sync decoding and track draw results when drawing borders in nsColumnSetFrame. r=tn (0317d6a914) - Bug 1143267 - Make nsDisplayAltFeedback use nsGenericImageGeometry. r=tn (8fc6372d48) - Bug 1176081. Add a pref to control drawing of the image loading place holder icon and border, and disable it. r=seth (792e8ec9b3) - Bug 1209765 (Part 7) - Support sync decoding and track draw results when drawing borders in nsImageFrame. r=tn (70d9af60a3) - Bug 1209765 (Part 8) - Support sync decoding and track draw results when drawing borders in MathML code. r=tn (555bff2635) - Bug 1209765 (Part 9) - Support sync decoding and track draw results when drawing borders in nsTableFrame. r=tn (d242dc5c79) - Bug 1209765 (Part 10) - Support sync decoding and track draw results when drawing borders in nsGroupBoxFrame. r=tn (a7187cfa5d) - Bug 1209765 (Part 11) - Support sync decoding and track draw results when drawing borders in nsTreeBodyFrame. r=tn (21bd2b3285) - Bug 1209765 (Followup) - Add very minor fuzz to underline-button-2.html on OS X 10.10. r=me (04cff3c2ff) - Bug 1209765 (Followup) - Add very minor fuzz to underline-button-1.html on OS X 10.10. r=me DONTBUILD (187fdb4106) - Bug 1217069 - Don't attempt to mis-optimize JSON.stringify's filter-list creation for replacer arrays with trailing holes. r=arai (04fb907d42) - Bug 1156463 - Add a preference option to disable the scale transform applied to MathML operators. r=karl (415a041117) - Bug 1174143 - Remove private tables for Standard Symbols L and MathJax fonts. r=karlt (1f58d14229) - Bug 1222297 - Use channel->Open2() in netwerk/base/nsNetUtil.cpp (r=sicking) (cbd12ebb0a) - Bug 1139709. Remove unused parameters from nsMathMLChar::GetMaxWidth. r=mats (6ea90a0a02) - Bug 1160635 patch 1 - Add reftests. r=dholbert (b58f8fd7fa) - Bug 1160635 patch 2 - Stop making image resizing optimization when image has percent width or height. r=dholbert (9ae3621baf) - Bug 1156097 - Make nsImageFrame::mImageMap an nsRefPtr; r=roc (b49157e424) - Bug 1176156. Make sure images are asked to decode if we are drawing the alt feedback instead of the image. r=seth (8d7a09622e) - Bug 1207355 (Part 2) - Stop requesting decodes in nsImageLoadingContent. r=tn (c781285098) - Bug 1207355 (Part 3) - Request decodes intelligently in nsImageFrame. r=tn (c61b7591fb) - Bug 1156028 - Teach clang-analyzer about XPCOM assertion macros; r=froydnj (4d8b7ecf03) - Bug 1207355 (Part 4) - Request decodes intelligently in nsBulletFrame. r=tn (2d7ced9c0f) - Bug 1207355 (Part 5) - Request decodes intelligently in MultipartImage. r=tn (c0cb580838) - Bug 1207355 (Part 6) - Only respect StartDecoding() in imgRequest/imgRequestProxy. r=tn (0e108cda4c) - Bug 1207355 (Part 7) - Only trigger intrinsic size decode in FinalizeDecoder() if StartDecoding() was called. r=tn (a71fc0d1b7) - Bug 1207355 (Part 8) - Remove imgIContainer::RequestDecode() and imgIRequest::RequestDecode(). r=tn (fbce1ccbe1) - Bug 1215596 - outline: auto; will render as outline: solid; when disabled. r=roc (b8ea369628) - Bug 1180966. Remove code that made no sense. r=mstange (eac62913ef) - Bug 1217905. Don't transform dest rects if destination context has a rotation with inset box shadows. r=mstange (53cf4d6f86) - Bug 1189010. In ScrollFrameHelper::BuildDisplayList decide if we are building a scrollable layer before we call AppendScrollPartsTo because it needs this information. r=mstange (a008c7e34d) - Bug 1204535 - Flatten conditional structure one level. r=tn (152ff398a0) - Bug 1204535 - Remove no-op code. r=tn (95d17e64c3) - Bug 1204535 - Collapse redundant conditional block. r=tn (d0e90b8d80) - Bug 1204535 - Rename usingDisplayport to usingDisplayPort for consistency. r=tn (516757a933) - Bug 1204535 - Relocate comment to go with the line of code it's commenting. r=tn (70ae0c5e71) - Bug 1204535 - Hoist out the code to initially compute usingDisplayPort. r=tn (4a5336a480) - Bug 1210578. Part 1. Rename mShouldBuildScrollableLayer to mWillBuildScrollableLayer to better capture the meaning of the variable. r=mstange (d13bb100f4) - Bug 1210578. Part 2. Rename shouldBuildLayer to couldBuildLayer to better reflect it's actual meaning. r=mstange (ae21c687c2) - Bug 1151663 - Only call GetOrMaybeCreateDisplayPort() in nsLayoutUtils::PaintFrame() if we are using containers for root scroll frames. r=tn (2bef3f9457) - Bug 1195431 - Small refactoring to use conditionals consistently. r=tn (897eb0f42a) - Bug 1167069 - Initialize nsPluginFrame::mInstanceOwner to null. r=jmathies (6ce1fcb8c2) - Bug 1137944 - Add support for hiding plugin windows during async dom scroll operations managed in the content process. r=roc (730a0ed004) - Bug 1210578. Part 3. Create DecideScrollableLayer that encapsulates all logic to create display ports and build scrollable layers. r=mstange (994ac6ec5e) - Bug 376679 part.1 Change the result of EventStateManager::ComputeScrollTarget() from nsIScrollableFrame* to nsIFrame* r=smaug (914878edbd) - Bug 376679 part.2 EventStateManager should treat plugin frame as scrollable frame if the plugin wants to handle wheel events as default action r=smaug (58c146b7ba) - Bug 376679 part.3 Compute default action target frame for wheel event before deciding the action because plugin should decide what is the default action when the target is a plugin frame r=smaug (334cbfcf53) - Bug 376679 part.4 Manage wheel transaction at sending a wheel event to target plugin r=smaug (d76062a429) - Bug 376679 part.5 nsPluginInstanceOwner::ProcessEvent() should create WM_MOUSE*WHEEL message from WidgetWheelEvent data r=smaug+jimm (56ee6bdf90) - Bug 376679 part.6 nsPluginInstanceOwner::ProcessEvent() should refer both deltaMode and system scroll amount settings when it generates WM_MOSUE*WHEEL messages r=jimm (927cb10a3b) - Bug 1145546 - Add missing nsBidiPresUtils.h include to nsGfxScrollFrame.cpp to fix non-unified bustage. r=jfkthame (af4043c024) - Bug 1137944 - Add plugin window handling for apz related notifications received by the content process. r=mstange (798e9676fd) - Bug 1208819 - Fix irregexp overrecursion check to ignore interrupts. r=bhackett (c845e65a2e) - Bug 1218640 - IonMonkey: MIPS64: Add support into irregexp. r=arai (613ddd95ef) - Bug 1211964 - Fix a couple of OOM handling issues in regexp code r=terrence (bb269eef3e) - Bug 1200734 - Use stable hashing for LiveScopesMap; r=shu (1d717c8f53) - Bug 1223853 - Use stable hashing for ObjectValueMap; r=jonco (c91f3b1b21) - Bug 1223863 - Use stable hashing for WeakGlobalObjectSet; r=jonco (eb29e841f1) - Bug 1223918 - Use stable hashing for WatchPointMap; r=jonco (7a69630c83) - Bug 1212011 - Replace more uses of CrashAtUnhandlableOOM() with AutoEnterOOMUnsafeRegion r=terrence (0079439d90) - Bug 1224347 - Use stable hashing for DebuggerWeakMaps; r=jonco (d2a627e077) - Bug 1219418 - Always access minEmptyChunkCount under the GC lock; r=jonco (f67f74ca57) - Bug 1202923 - Encapsulate GC begin and end notification callbacks in an RAII guard; r=jonco (46f63fd090) - Bug 1212624 - Tests for LinkedList, r=Waldo (3d48b12918) - Bug 1215752 - Weakmap refactoring, r=terrence (90cbf4d294) - Bug 1216744 - Move weakKeys to the zone, r=terrence (5fdb1d57bf) - Bug 1215336 - Measure unmark gray time, r=terrence (278e0ee562) - Bug 1211939 - Don't call JSRuntime::onOutOfMemory from helper threads. r=jonco (86c6906421) - Bug 1218638 - IonMonkey: MIPS64: Add support into jit/shared. r=lth (e4f2904c53) - Bug 1216277 - Don't assert properties of the buffer location if the assembler is out of memory r=jandem (65556e83ce) - Bug 1211962 - addNativeToBytecodeEntry: Check that the masm.currentOffset() returns a valid result. r=djvj (3c5723c65a) - Bug 1090957 - IonMonkey: Add temp registers for mips atomics. r=lth (00f23fe2e9) - Bug 1218967 - Do not stop executing autospider.sh on test failure. r=sfink (75f912efbb) - Bug 1213881 - Run jsapi-tests in the arm64-sim autospider. r=sfink (2e731f14e7) - Bug 1216607 - Fix assertion failure ARM assembler on OOM r=jandem (0bc2dcb5db) - Bug 1209515 part 1 - IonBuilder: Attach hit counts on the MIRGraph. r=bhackett (f5448d9596) - Bug 1209515 part 2 - Ensure that MPhi removal considers removed uses. r=bhackett (95de413c50) - Bug 1209515 part 3 - IonMonkey: Add branch pruning based on code coverage counters. r=bhackett (fb71022658) - Bug 1209515 part 0 - Move callerResumePoint field next to other resume points of basic blocks. r=bbouvier (394b52860d) - Bug 1209515 part 4 - Increment code coverage counters on bailouts. r=bhackett (22edac5c24) - Bug 1209515 part 5 - Ensure that we recompile when we have frequent bailouts caused by the first execution. r=jandem (bca0fa4118) - Bug 1209515 part 7 - IonBuilder: pushLoop should not infer the continuepc from the entry block. r=jandem (025d10fd57) - Bug 1209515 part 8 - IonBuilder: newOsrPreheader should not use the hit-count of the loop. r=jandem (5db05ef17f) - Bug 1209515 part 9 - IonBuilder: Loop header should use the hit count of the loop, instead of before the loop. r=jandem (b259b490bf) - Bug 1209515 part 10 - Prevent PruneUnusedBranches from being greedy while removing branches which have only be visited a few times. r=bhackett (4a1a7b34b6) - Bug 1209515 part 11 - Increase JitSpewer mask size to avoid overflow. r=bbouvier (28546de94e) - Bug 1219401 - Don't call script->hasIonScript() off-thread, fixes a TSan race. r=h4writer (8f31724484) - Bug 1172076 - Assert that SnapshotIterator::initInstructionResults always match the recover instructions data. r=jandem (6ed0eebc65) - Bug 1209260 - Don't use sincos on iOS r=npb (eaa3cacac7) - Bug 1222499 - "JitSpew/IonSpew: warmupCounter should use PRIu32 instead of PRIuSIZE". r=nbp (50b80b985a) - Bug 1216182: Rename MODE_MASK to MODE_BITS_MASK, r=hv1989 (f28e461d94) - Bug 1137944 - Add a pref to control plugin window hiding. r=roc (691dc99b94) - Bug 1214878 - When async scrolling with e10s hide windowed plugins in sub documents. r=roc (79c0eac459) - Bug 1215434 part.1 If scroll target is a plugin frame, EventStateManager::PostHandleEvent() should send the wheel event to the plugin frame even if APZC already handled it r=smaug (f2e8e33d7f) - Bug 1215434 part.2 Add plugin frame rect to dispatch-to-content region if it wants to handle wheel event as default action r=mstange (dbecb1e256) - Fix inactive scroll frames sometimes creating very large, incorrect hit regions. (bug 1190112, r=tn) (2056d8d63e) - Fix scrollbars on subframes not directing APZ events to the correct scrollframe. (bug 1213324, r=tn) (0594923ab2) - Bug 1182017. Call Send__delete__ immediately rather than through an event. r=nical (90714b065b) - Bug 1212656 - ARM64: Fix automation build failures. (r=efaust) (5695518dd1) - Bug 1137944 - Simplify the api associated with hiding e10s plugin widgets. r=roc (dfbfda4d31) - Bug 1137944 - Fire before and after composite events. r=matt.woodrow (0048aeb8cb) - Bug 1201660 - When layer tree updates get dropped, hide plugins associated with the tree. Fixes a bug where we were hiding all plugins associated with the window. r=matt.woodrow (9352150c73) - Bug 1137944 - Backout compositor bits (cset b4711fa5f734) which caused a telemetry metric regression. r=backout (241659d6a8) - Bug 1127270: Only acquire a hold on the compositor thread once the channel for a parent actor has been succesfully connected. r=nical (1d1b077d68) - Bug 1207270 - Ensure that the TaskThrottler objects are created on the main thread. r=botond (b43af025f1) - Bug 1194876 - Add test. r=botond (440c72ec81) - Bug 1152051 - Gtest. r=Cwiiis,kats (011f066f37) - Bug 1144112 - Update the FlingStop tests to check if events are flowing properly after the fast-motion blocks are done. r=botond (25f71629d7) - Bug 1092128 - Ensure that when touch-action is enabled the gtests always provide default touch behaviours where expected. r=botond (3f0d1229f3) - Bug 1144112 - Only set the default allowed touch behaviour if the event is not consumed, to have the tests better reflect reality. r=botond (1548bd14bb) - Bug 1163845 - Unify handling of time in APZ gtests. r=kats (b73a16ef5e) - Bug 1159398 - Set the controller thread when running APZ gtests. r=dvander (96b551036e) - Bug 1159985 - Gtest. r=kats (23d7d86492) - Bug 1159985 - In APZ gtests, allow panning in both directions. r=kats (14f4b1156a) - Bug 1169695 - Make the test timestamp privately held by the MockContentControllerDelayed. r=botond (ffe04249c1) - Bug 1198900 - Add a gtest to ensure we don't crash when prevent-defaulting a wheel event. r=botond, a=topcrash (c9e5993f18) - Bug 1169690 - Gtests. r=kats (7e825b34ac) - Bug 1207270 - Update tests to ensure that TaskThrottlers are created as appropriate. r=botond (7bb6f1f406) - Bug 1169695 - Ensure timed tasks are dispatched appropriately when advancing the time. r=botond (af1fbe0a85) - Bug 1204837, Part 1: Make ClosingService thread Nuwa-friedly. r=khuey (eb790b5215) - Bug 1204837, Part 2: Cloned ImageBridgeParent and CompositorParent should hold a reference to the compositor thread. r=nical (cd742df2e2) - Bug 1205016: double ClosingService thread stack size to avoid stack overflow r=glandium (cb9acc828f) - Bug 1163570 - Ignore pending plugin updates and hide plugin windows when a remote layer tree associated with a tab is no longer in use. r=roc (ae852ad442) - Bug 1196539 - Apply plugin config using AutoResolveRefLayers during composition. r=matt.woodrow (12dbdb6222) - Bug 1137944 - Cache compositor plugin update data to avoid sending updates to the main thread when the data doesn't change. r=roc (63c503d2f6) - Bug 1137944 - On Windows defer composition until we receive confirmation plugin window metrics have been updated. r=roc (39d5786519) - Bug 1137944 - Move plugin window metrics updates to a point during comososition where we know the remote layer tree is hooked up to the chrome layer tree. r=matt.woodrow (a32f77ffb1) - Bug 1213671 - CompositorParent::UpdatePluginWindowState should always return an accurate result indicating when an ipc request for plugin geometry updates was sent. r=roc (311e65a8ce) - Bug 1214267 - Send the side to which fixed-pos items are attached so that we can move them in the compositor more correctly when the viewport size is changing. r=mattwoodrow (fa2de207cd) - Bug 1209964 - In AlignFixedAndStickyLayers(), properly handle the case where a fixed or sticky layer is its own subtree root and has a local transform. r=kats (1a6922699a) - Bug 1213762 - Clear AsyncCompositionManager::mIsFirstPaint on non-Android platforms, too. r=mstange (c4cf2b722a) - Bug 1223436 - Fix AsyncCompositionManager so that mLayersUpdated is only set to false after SyncFrameMetrics has been called. r=kats (f3fa84325b) - bits of 1073545 (3bc7d76081) - Bug 1213795, Part 1: Don't fire timers in the Nuwa process to fix test case test_NuwaProcessDeadlock.html. r=khuey (5ebca946e5) - Bug 1213795, Part 2: Fix protocol cloning of actor CrossProcessCompositorParent. r=khuey (92969e2b06) - spacing (f4857ed898) - Bug 1213758 - Aquire the inderect layer trees data lock during plugin window update calculations. r=matt.woodrow (ae70d955ec) - Bug 1208502 - Use more smart pointers in XULDocument. r=smaug (20a92d72e8) - Bug 1193086 - Remove some null checks of infallible new code in XUL. r=baku (2f463c5a3d) - Bug 1217190 - Make PrintingParent return an nsresult when attempting to show print progress. r=bobowen (addf31f3a7) - Bug 1217190 - Make sure to initialize outparam in PrintingParent::RecvShowProgress. r=bobowen (f6c11a0181) - Bug 1152921 - Don't send an uninitialized PrintData over IPC when cancelling print dialog (or failing ShowPrintDialog for other reasons). r=mconley (4ea146ccf1) - Bug 1178233 - [non-e10s] The update process doesn't work within about:serviceworkers in non-e10s mode. r=baku (7a08441bec) - Bug 929846 - Considering key size when calculating quota usage. r=jdm (a97ddc7906) - Bug 1194049 - Part 3: support device update; r=fabrice (6ba600a03d) - Bug 1194049 - Part 1: add thread assertion; r=schien (68c4658ae0) - Bug 1194049 - Part 2: add discovery timeout support; r=schien (14f5f537d5) - Bug 1194049 - Part 4: clear discovered devices when re-discover; r=schien (e2ecdb573f) - Bug 1136565 - report session request from device provider. r=xeonchen,junior,seanlin. (19daa67751) - Bug 1216398 - support non-discoverable controlling device. r=junior,xeonchen. (7383401dbc) - Bug 1200132 - Use adderss to create socketTransport, r=schien, junior (263d253562) - Bug 1200132 - Part1: Get address info after service resolved, r=mcmanus (9bcc344d20) - Bug 1200132 - Part2: Get IP address by calling InetAddress.getHostAddress(), r=mcmanus, rnewman (502c243314) - Bug 1173334: Open nfcd connections with socket type SOCK_SEQPACKET, allstars.chh (03a11dc077) - Bug 1173802: Move NFC socket and messaging code into |NfcConsumer|, r=allstars.chh (f92946b40e) - Bug 1173802: Run |NfcConsumer| on NFC thread, r=allstars.chh (87989483a7) - Bug 1173802: Clean up |NfcEventDispatcher|, r=allstars.chh (87f58b7310) - Bug 1173802: Replace |assertIsNfcServiceThread| with thread-safe checks, r=allstars.chh (1a6a76ae05) - Bug 1173802: Store global NFC service in ref-counted variable, r=allstars.chh (a33c025976) - Bug 1188639 - Fix typo in BrowserElement.webidl and add tests for it. r=yoshi,bz (7b657a335d) - Bug 1175387 - close file descriptor after detached from STS. r=mcmanus (377943bad5) - Bug 1190069 - Fix uninitialized variable in MDNSResponderOperator.cpp. r=xeonchen (ebf47b613e) - Bug 1217807 - Part 1: use ServiceWatcher to extend life cycle of mDNS operators; r=schien (70201259d2) - missing namespace (c6bccda1e5) - Bug 1209843 - Stop checking for UNKNOWN_APP_ID in all places except those where AppId() is explicitly queried. r=sicking (e364223906) - Bug 1168337: Kill the processes on startup of the Nuwa test case fix the abort in the preallocated process. r=khuey (501a30cb9b) - Bug 1202424 - Free shared memory when IPC system shuts down, not after. r=mrbkap (f718cbf801) - Bug 1209987 - webrtc.org Engine creation and destruction should happen on the WebRTC threads. r=jesup (4bbab795cf) - Bug 1214675 - Factor out cleanup functions to avoid deadlock/dispatch-without-IPC. r=jesup (bd466c85e4) - Bug 1210560 - Part 2: Convert some simple users to use PushGroupForBlendBack. r=jrmuizel (158b532f9f) - Bug 1174785 - Part 0: Use mozilla/StaticPtr.h in signaling. r=jesup (c98ec23ee0) - Bug 1174785 - Part 1: Add LogModule, LogModuleManager, and LazyLogModule. r=froydnj (e797bca424) - Bug 1195867 - Hoist StateWatching and StateMirroring into XPCOM. r=froydnj (a62fbbf749) - Bug 1194631 - Make firefox build with --disable-logging. r=jrmuizel (ba8238dc42) - Bug 1174785 - Part 2: Convert xpcom over to LogModule. r=froydnj (ccb119d496) - Bug 1205237 - Part 2: add PresentationNetworkHelper; r=schien (be47702ffe) - Bug 1205237 - Part 3: get self Wi-Fi IP address; r=seanlin (f31163e895) - Bug 1217683 - Add sendIceCandidate and implement |close(aReason)| in TCPControlChannel. r=fabrice (0004ea93f1) - Bug 1217807 - Part 2: Handle network online/offline event in TCPPresentationServer; r=junior (48c9236adb) - Bug 1217807 - disable MDNS discovery. r=xeonchen. (ee3cb0ddb6)
1839 lines
50 KiB
C++
1839 lines
50 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
// Must #include ImageLogging.h before any IPDL-generated files or other files
|
|
// that #include prlog.h
|
|
#include "ImageLogging.h"
|
|
|
|
#include "RasterImage.h"
|
|
|
|
#include "base/histogram.h"
|
|
#include "gfxPlatform.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "nsError.h"
|
|
#include "Decoder.h"
|
|
#include "nsAutoPtr.h"
|
|
#include "prenv.h"
|
|
#include "prsystem.h"
|
|
#include "ImageContainer.h"
|
|
#include "ImageRegion.h"
|
|
#include "Layers.h"
|
|
#include "LookupResult.h"
|
|
#include "nsIConsoleService.h"
|
|
#include "nsIInputStream.h"
|
|
#include "nsIScriptError.h"
|
|
#include "nsISupportsPrimitives.h"
|
|
#include "nsPresContext.h"
|
|
#include "SourceBuffer.h"
|
|
#include "SurfaceCache.h"
|
|
#include "FrameAnimator.h"
|
|
|
|
#include "nsPNGDecoder.h"
|
|
#include "nsGIFDecoder2.h"
|
|
#include "nsJPEGDecoder.h"
|
|
#ifdef MOZ_JXR
|
|
#include "nsJXRDecoder.h"
|
|
#endif
|
|
#include "nsBMPDecoder.h"
|
|
#include "nsICODecoder.h"
|
|
#include "nsIconDecoder.h"
|
|
#include "nsWEBPDecoder.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "mozilla/DebugOnly.h"
|
|
#include "mozilla/Likely.h"
|
|
#include "mozilla/RefPtr.h"
|
|
#include "mozilla/Move.h"
|
|
#include "mozilla/MemoryReporting.h"
|
|
#include "mozilla/Services.h"
|
|
#include <stdint.h>
|
|
#include "mozilla/TimeStamp.h"
|
|
#include "mozilla/Tuple.h"
|
|
#include "mozilla/ClearOnShutdown.h"
|
|
#include "mozilla/gfx/Scale.h"
|
|
|
|
#include "GeckoProfiler.h"
|
|
#include "gfx2DGlue.h"
|
|
#include "gfxPrefs.h"
|
|
#include <algorithm>
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace gfx;
|
|
using namespace layers;
|
|
|
|
namespace image {
|
|
|
|
using std::ceil;
|
|
using std::min;
|
|
|
|
// The maximum number of times any one RasterImage was decoded. This is only
|
|
// used for statistics.
|
|
static int32_t sMaxDecodeCount = 0;
|
|
|
|
#ifndef DEBUG
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties)
|
|
#else
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, nsIProperties,
|
|
imgIContainerDebug)
|
|
#endif
|
|
|
|
//******************************************************************************
|
|
RasterImage::RasterImage(ImageURL* aURI /* = nullptr */) :
|
|
ImageResource(aURI), // invoke superclass's constructor
|
|
mSize(0,0),
|
|
mLockCount(0),
|
|
mDecodeCount(0),
|
|
mRequestedSampleSize(0),
|
|
mLastImageContainerDrawResult(DrawResult::NOT_READY),
|
|
#ifdef DEBUG
|
|
mFramesNotified(0),
|
|
#endif
|
|
mSourceBuffer(new SourceBuffer()),
|
|
mFrameCount(0),
|
|
mHasSize(false),
|
|
mTransient(false),
|
|
mSyncLoad(false),
|
|
mDiscardable(false),
|
|
mHasSourceData(false),
|
|
mHasBeenDecoded(false),
|
|
mPendingAnimation(false),
|
|
mAnimationFinished(false),
|
|
mWantFullDecode(false)
|
|
{
|
|
//Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Add(0);
|
|
}
|
|
|
|
//******************************************************************************
|
|
RasterImage::~RasterImage()
|
|
{
|
|
// Make sure our SourceBuffer is marked as complete. This will ensure that any
|
|
// outstanding decoders terminate.
|
|
if (!mSourceBuffer->IsComplete()) {
|
|
mSourceBuffer->Complete(NS_ERROR_ABORT);
|
|
}
|
|
|
|
// Release all frames from the surface cache.
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
}
|
|
|
|
nsresult
|
|
RasterImage::Init(const char* aMimeType,
|
|
uint32_t aFlags)
|
|
{
|
|
// We don't support re-initialization
|
|
if (mInitialized) {
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
}
|
|
|
|
// Not sure an error can happen before init, but be safe
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// We want to avoid redecodes for transient images.
|
|
MOZ_ASSERT_IF(aFlags & INIT_FLAG_TRANSIENT,
|
|
!(aFlags & INIT_FLAG_DISCARDABLE));
|
|
|
|
// Store initialization data
|
|
mDiscardable = !!(aFlags & INIT_FLAG_DISCARDABLE);
|
|
mWantFullDecode = !!(aFlags & INIT_FLAG_DECODE_IMMEDIATELY);
|
|
mTransient = !!(aFlags & INIT_FLAG_TRANSIENT);
|
|
mSyncLoad = !!(aFlags & INIT_FLAG_SYNC_LOAD);
|
|
|
|
// Use the MIME type to select a decoder type, and make sure there *is* a
|
|
// decoder for this MIME type.
|
|
NS_ENSURE_ARG_POINTER(aMimeType);
|
|
mDecoderType = DecoderFactory::GetDecoderType(aMimeType);
|
|
if (mDecoderType == DecoderType::UNKNOWN) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
|
|
if (!mDiscardable) {
|
|
mLockCount++;
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
}
|
|
|
|
if (!mSyncLoad) {
|
|
// Create an async metadata decoder and verify we succeed in doing so.
|
|
nsresult rv = DecodeMetadata(DECODE_FLAGS_DEFAULT);
|
|
if (NS_FAILED(rv)) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
}
|
|
|
|
// Mark us as initialized
|
|
mInitialized = true;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
// [notxpcom] void requestRefresh ([const] in TimeStamp aTime);
|
|
NS_IMETHODIMP_(void)
|
|
RasterImage::RequestRefresh(const TimeStamp& aTime)
|
|
{
|
|
if (HadRecentRefresh(aTime)) {
|
|
return;
|
|
}
|
|
|
|
EvaluateAnimation();
|
|
|
|
if (!mAnimating) {
|
|
return;
|
|
}
|
|
|
|
FrameAnimator::RefreshResult res;
|
|
if (mAnim) {
|
|
res = mAnim->RequestRefresh(aTime);
|
|
}
|
|
|
|
if (res.frameAdvanced) {
|
|
// Notify listeners that our frame has actually changed, but do this only
|
|
// once for all frames that we've now passed (if AdvanceFrame() was called
|
|
// more than once).
|
|
#ifdef DEBUG
|
|
mFramesNotified++;
|
|
#endif
|
|
|
|
NotifyProgress(NoProgress, res.dirtyRect);
|
|
}
|
|
|
|
if (res.animationFinished) {
|
|
mAnimationFinished = true;
|
|
EvaluateAnimation();
|
|
}
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetWidth(int32_t* aWidth)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
|
|
|
if (mError) {
|
|
*aWidth = 0;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
*aWidth = mSize.width;
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetHeight(int32_t* aHeight)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
|
|
|
if (mError) {
|
|
*aHeight = 0;
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
*aHeight = mSize.height;
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetIntrinsicSize(nsSize* aSize)
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
|
|
nsPresContext::CSSPixelsToAppUnits(mSize.height));
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetIntrinsicRatio(nsSize* aRatio)
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
*aRatio = nsSize(mSize.width, mSize.height);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
RasterImage::GetOrientation()
|
|
{
|
|
return mOrientation;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetType(uint16_t* aType)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
|
return NS_OK;
|
|
}
|
|
|
|
LookupResult
|
|
RasterImage::LookupFrameInternal(uint32_t aFrameNum,
|
|
const IntSize& aSize,
|
|
uint32_t aFlags)
|
|
{
|
|
if (!mAnim) {
|
|
NS_ASSERTION(aFrameNum == 0,
|
|
"Don't ask for a frame > 0 if we're not animated!");
|
|
aFrameNum = 0;
|
|
}
|
|
|
|
if (mAnim && aFrameNum > 0) {
|
|
MOZ_ASSERT(ToSurfaceFlags(aFlags) == DefaultSurfaceFlags(),
|
|
"Can't composite frames with non-default surface flags");
|
|
return mAnim->GetCompositedFrame(aFrameNum);
|
|
}
|
|
|
|
Maybe<SurfaceFlags> alternateFlags;
|
|
if (IsOpaque()) {
|
|
// If we're opaque, we can always substitute a frame that was decoded with a
|
|
// different decode flag for premultiplied alpha, because that can only
|
|
// matter for frames with transparency.
|
|
alternateFlags.emplace(ToSurfaceFlags(aFlags) ^
|
|
SurfaceFlags::NO_PREMULTIPLY_ALPHA);
|
|
}
|
|
|
|
// We don't want any substitution for sync decodes (except the premultiplied
|
|
// alpha optimization above), so we use SurfaceCache::Lookup in this case.
|
|
if (aFlags & FLAG_SYNC_DECODE) {
|
|
return SurfaceCache::Lookup(ImageKey(this),
|
|
RasterSurfaceKey(aSize,
|
|
ToSurfaceFlags(aFlags),
|
|
aFrameNum),
|
|
alternateFlags);
|
|
}
|
|
|
|
// We'll return the best match we can find to the requested frame.
|
|
return SurfaceCache::LookupBestMatch(ImageKey(this),
|
|
RasterSurfaceKey(aSize,
|
|
ToSurfaceFlags(aFlags),
|
|
aFrameNum),
|
|
alternateFlags);
|
|
}
|
|
|
|
DrawableFrameRef
|
|
RasterImage::LookupFrame(uint32_t aFrameNum,
|
|
const IntSize& aSize,
|
|
uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
IntSize requestedSize = CanDownscaleDuringDecode(aSize, aFlags)
|
|
? aSize : mSize;
|
|
if (requestedSize.IsEmpty()) {
|
|
return DrawableFrameRef(); // Can't decode to a surface of zero size.
|
|
}
|
|
|
|
LookupResult result = LookupFrameInternal(aFrameNum, requestedSize, aFlags);
|
|
|
|
if (!result && !mHasSize) {
|
|
// We can't request a decode without knowing our intrinsic size. Give up.
|
|
return DrawableFrameRef();
|
|
}
|
|
|
|
if (result.Type() == MatchType::NOT_FOUND ||
|
|
result.Type() == MatchType::SUBSTITUTE_BECAUSE_NOT_FOUND ||
|
|
((aFlags & FLAG_SYNC_DECODE) && !result)) {
|
|
// We don't have a copy of this frame, and there's no decoder working on
|
|
// one. (Or we're sync decoding and the existing decoder hasn't even started
|
|
// yet.) Trigger decoding so it'll be available next time.
|
|
MOZ_ASSERT(!mAnim || GetNumFrames() < 1, "Animated frames should be locked");
|
|
|
|
Decode(requestedSize, aFlags);
|
|
|
|
// If we can sync decode, we should already have the frame.
|
|
if (aFlags & FLAG_SYNC_DECODE) {
|
|
result = LookupFrameInternal(aFrameNum, requestedSize, aFlags);
|
|
}
|
|
}
|
|
|
|
if (!result) {
|
|
// We still weren't able to get a frame. Give up.
|
|
return DrawableFrameRef();
|
|
}
|
|
|
|
if (result.DrawableRef()->GetCompositingFailed()) {
|
|
return DrawableFrameRef();
|
|
}
|
|
|
|
MOZ_ASSERT(!result.DrawableRef()->GetIsPaletted(),
|
|
"Should not have a paletted frame");
|
|
|
|
// Sync decoding guarantees that we got the frame, but if it's owned by an
|
|
// async decoder that's currently running, the contents of the frame may not
|
|
// be available yet. Make sure we get everything.
|
|
if (mHasSourceData && (aFlags & FLAG_SYNC_DECODE)) {
|
|
result.DrawableRef()->WaitUntilComplete();
|
|
}
|
|
|
|
return Move(result.DrawableRef());
|
|
}
|
|
|
|
uint32_t
|
|
RasterImage::GetCurrentFrameIndex() const
|
|
{
|
|
if (mAnim) {
|
|
return mAnim->GetCurrentAnimationFrameIndex();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint32_t
|
|
RasterImage::GetRequestedFrameIndex(uint32_t aWhichFrame) const
|
|
{
|
|
return aWhichFrame == FRAME_FIRST ? 0 : GetCurrentFrameIndex();
|
|
}
|
|
|
|
IntRect
|
|
RasterImage::GetFirstFrameRect()
|
|
{
|
|
if (mAnim && mHasBeenDecoded) {
|
|
return mAnim->GetFirstFrameRefreshArea();
|
|
}
|
|
|
|
// Fall back to our size. This is implicitly zero-size if !mHasSize.
|
|
return IntRect(IntPoint(0,0), mSize);
|
|
}
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
RasterImage::IsOpaque()
|
|
{
|
|
if (mError) {
|
|
return false;
|
|
}
|
|
|
|
Progress progress = mProgressTracker->GetProgress();
|
|
|
|
// If we haven't yet finished decoding, the safe answer is "not opaque".
|
|
if (!(progress & FLAG_DECODE_COMPLETE)) {
|
|
return false;
|
|
}
|
|
|
|
// Other, we're opaque if FLAG_HAS_TRANSPARENCY is not set.
|
|
return !(progress & FLAG_HAS_TRANSPARENCY);
|
|
}
|
|
|
|
void
|
|
RasterImage::OnSurfaceDiscarded()
|
|
{
|
|
MOZ_ASSERT(mProgressTracker);
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
NS_NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard);
|
|
NS_DispatchToMainThread(runnable);
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::GetAnimated(bool* aAnimated)
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
NS_ENSURE_ARG_POINTER(aAnimated);
|
|
|
|
// If we have mAnim, we can know for sure
|
|
if (mAnim) {
|
|
*aAnimated = true;
|
|
return NS_OK;
|
|
}
|
|
|
|
// Otherwise, we need to have been decoded to know for sure, since if we were
|
|
// decoded at least once mAnim would have been created for animated images.
|
|
// This is true even though we check for animation during the metadata decode,
|
|
// because we may still discover animation only during the full decode for
|
|
// corrupt images.
|
|
if (!mHasBeenDecoded) {
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
}
|
|
|
|
// We know for sure
|
|
*aAnimated = false;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP_(int32_t)
|
|
RasterImage::GetFirstFrameDelay()
|
|
{
|
|
if (mError) {
|
|
return -1;
|
|
}
|
|
|
|
bool animated = false;
|
|
if (NS_FAILED(GetAnimated(&animated)) || !animated) {
|
|
return -1;
|
|
}
|
|
|
|
MOZ_ASSERT(mAnim, "Animated images should have a FrameAnimator");
|
|
return mAnim->GetTimeoutForFrame(0);
|
|
}
|
|
|
|
already_AddRefed<SourceSurface>
|
|
RasterImage::CopyFrame(uint32_t aWhichFrame, uint32_t aFlags)
|
|
{
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (mError) {
|
|
return nullptr;
|
|
}
|
|
|
|
// Get the frame. If it's not there, it's probably the caller's fault for
|
|
// not waiting for the data to be loaded from the network or not passing
|
|
// FLAG_SYNC_DECODE
|
|
DrawableFrameRef frameRef =
|
|
LookupFrame(GetRequestedFrameIndex(aWhichFrame), mSize, aFlags);
|
|
if (!frameRef) {
|
|
// The OS threw this frame away and we couldn't redecode it right now.
|
|
return nullptr;
|
|
}
|
|
|
|
// Create a 32-bit image surface of our size, but draw using the frame's
|
|
// rect, implicitly padding the frame out to the image's size.
|
|
|
|
IntSize size(mSize.width, mSize.height);
|
|
RefPtr<DataSourceSurface> surf =
|
|
Factory::CreateDataSourceSurface(size,
|
|
SurfaceFormat::B8G8R8A8,
|
|
/* aZero = */ true);
|
|
if (NS_WARN_IF(!surf)) {
|
|
return nullptr;
|
|
}
|
|
|
|
DataSourceSurface::MappedSurface mapping;
|
|
if (!surf->Map(DataSourceSurface::MapType::WRITE, &mapping)) {
|
|
gfxCriticalError() << "RasterImage::CopyFrame failed to map surface";
|
|
return nullptr;
|
|
}
|
|
|
|
RefPtr<DrawTarget> target =
|
|
Factory::CreateDrawTargetForData(BackendType::CAIRO,
|
|
mapping.mData,
|
|
size,
|
|
mapping.mStride,
|
|
SurfaceFormat::B8G8R8A8);
|
|
if (!target) {
|
|
gfxWarning() << "RasterImage::CopyFrame failed in CreateDrawTargetForData";
|
|
return nullptr;
|
|
}
|
|
|
|
IntRect intFrameRect = frameRef->GetRect();
|
|
Rect rect(intFrameRect.x, intFrameRect.y,
|
|
intFrameRect.width, intFrameRect.height);
|
|
if (frameRef->IsSinglePixel()) {
|
|
target->FillRect(rect, ColorPattern(frameRef->SinglePixelColor()),
|
|
DrawOptions(1.0f, CompositionOp::OP_SOURCE));
|
|
} else {
|
|
RefPtr<SourceSurface> srcSurf = frameRef->GetSurface();
|
|
if (!srcSurf) {
|
|
RecoverFromInvalidFrames(mSize, aFlags);
|
|
return nullptr;
|
|
}
|
|
|
|
Rect srcRect(0, 0, intFrameRect.width, intFrameRect.height);
|
|
target->DrawSurface(srcSurf, srcRect, rect);
|
|
}
|
|
|
|
target->Flush();
|
|
surf->Unmap();
|
|
|
|
return surf.forget();
|
|
}
|
|
|
|
//******************************************************************************
|
|
/* [noscript] SourceSurface getFrame(in uint32_t aWhichFrame,
|
|
* in uint32_t aFlags); */
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
RasterImage::GetFrame(uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
return GetFrameInternal(mSize, aWhichFrame, aFlags).second().forget();
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
RasterImage::GetFrameAtSize(const IntSize& aSize,
|
|
uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
return GetFrameInternal(aSize, aWhichFrame, aFlags).second().forget();
|
|
}
|
|
|
|
Pair<DrawResult, RefPtr<SourceSurface>>
|
|
RasterImage::GetFrameInternal(const IntSize& aSize,
|
|
uint32_t aWhichFrame,
|
|
uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
|
|
|
|
if (aSize.IsEmpty()) {
|
|
return MakePair(DrawResult::BAD_ARGS, RefPtr<SourceSurface>());
|
|
}
|
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
|
return MakePair(DrawResult::BAD_ARGS, RefPtr<SourceSurface>());
|
|
}
|
|
|
|
if (mError) {
|
|
return MakePair(DrawResult::BAD_IMAGE, RefPtr<SourceSurface>());
|
|
}
|
|
|
|
// Get the frame. If it's not there, it's probably the caller's fault for
|
|
// not waiting for the data to be loaded from the network or not passing
|
|
// FLAG_SYNC_DECODE
|
|
DrawableFrameRef frameRef =
|
|
LookupFrame(GetRequestedFrameIndex(aWhichFrame), aSize, aFlags);
|
|
if (!frameRef) {
|
|
// The OS threw this frame away and we couldn't redecode it.
|
|
return MakePair(DrawResult::TEMPORARY_ERROR, RefPtr<SourceSurface>());
|
|
}
|
|
|
|
// If this frame covers the entire image, we can just reuse its existing
|
|
// surface.
|
|
RefPtr<SourceSurface> frameSurf;
|
|
if (!frameRef->NeedsPadding() &&
|
|
frameRef->GetSize() == aSize) {
|
|
frameSurf = frameRef->GetSurface();
|
|
}
|
|
|
|
// The image doesn't have a usable surface because it's been optimized away or
|
|
// because it's a partial update frame from an animation. Create one. (In this
|
|
// case we fall back to returning a surface at our intrinsic size, even if a
|
|
// different size was originally specified.)
|
|
if (!frameSurf) {
|
|
frameSurf = CopyFrame(aWhichFrame, aFlags);
|
|
}
|
|
|
|
if (!frameRef->IsImageComplete()) {
|
|
return MakePair(DrawResult::INCOMPLETE, Move(frameSurf));
|
|
}
|
|
|
|
return MakePair(DrawResult::SUCCESS, Move(frameSurf));
|
|
}
|
|
|
|
Pair<DrawResult, RefPtr<layers::Image>>
|
|
RasterImage::GetCurrentImage(ImageContainer* aContainer, uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aContainer);
|
|
|
|
DrawResult drawResult;
|
|
RefPtr<SourceSurface> surface;
|
|
Tie(drawResult, surface) =
|
|
GetFrameInternal(mSize, FRAME_CURRENT, aFlags | FLAG_ASYNC_NOTIFY);
|
|
if (!surface) {
|
|
// The OS threw out some or all of our buffer. We'll need to wait for the
|
|
// redecode (which was automatically triggered by GetFrame) to complete.
|
|
return MakePair(drawResult, RefPtr<layers::Image>());
|
|
}
|
|
|
|
CairoImage::Data cairoData;
|
|
GetWidth(&cairoData.mSize.width);
|
|
GetHeight(&cairoData.mSize.height);
|
|
cairoData.mSourceSurface = surface;
|
|
|
|
RefPtr<layers::Image> image =
|
|
aContainer->CreateImage(ImageFormat::CAIRO_SURFACE);
|
|
MOZ_ASSERT(image);
|
|
|
|
static_cast<CairoImage*>(image.get())->SetData(cairoData);
|
|
|
|
return MakePair(drawResult, Move(image));
|
|
}
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
RasterImage::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
int32_t maxTextureSize = aManager->GetMaxTextureSize();
|
|
if (!mHasSize ||
|
|
mSize.width > maxTextureSize ||
|
|
mSize.height > maxTextureSize) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
|
|
RasterImage::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aManager);
|
|
MOZ_ASSERT((aFlags & ~(FLAG_SYNC_DECODE |
|
|
FLAG_SYNC_DECODE_IF_FAST |
|
|
FLAG_ASYNC_NOTIFY))
|
|
== FLAG_NONE,
|
|
"Unsupported flag passed to GetImageContainer");
|
|
|
|
int32_t maxTextureSize = aManager->GetMaxTextureSize();
|
|
if (!mHasSize ||
|
|
mSize.width > maxTextureSize ||
|
|
mSize.height > maxTextureSize) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (IsUnlocked() && mProgressTracker) {
|
|
mProgressTracker->OnUnlockedDraw();
|
|
}
|
|
|
|
RefPtr<layers::ImageContainer> container = mImageContainer.get();
|
|
|
|
bool mustRedecode =
|
|
(aFlags & (FLAG_SYNC_DECODE | FLAG_SYNC_DECODE_IF_FAST)) &&
|
|
mLastImageContainerDrawResult != DrawResult::SUCCESS &&
|
|
mLastImageContainerDrawResult != DrawResult::BAD_IMAGE;
|
|
|
|
if (container && !mustRedecode) {
|
|
return container.forget();
|
|
}
|
|
|
|
// We need a new ImageContainer, so create one.
|
|
container = LayerManager::CreateImageContainer();
|
|
|
|
DrawResult drawResult;
|
|
RefPtr<layers::Image> image;
|
|
Tie(drawResult, image) = GetCurrentImage(container, aFlags);
|
|
if (!image) {
|
|
return nullptr;
|
|
}
|
|
|
|
// |image| holds a reference to a SourceSurface which in turn holds a lock on
|
|
// the current frame's VolatileBuffer, ensuring that it doesn't get freed as
|
|
// long as the layer system keeps this ImageContainer alive.
|
|
container->SetCurrentImageInTransaction(image);
|
|
|
|
mLastImageContainerDrawResult = drawResult;
|
|
mImageContainer = container;
|
|
|
|
return container.forget();
|
|
}
|
|
|
|
void
|
|
RasterImage::UpdateImageContainer()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
RefPtr<layers::ImageContainer> container = mImageContainer.get();
|
|
if (!container) {
|
|
return;
|
|
}
|
|
|
|
DrawResult drawResult;
|
|
RefPtr<layers::Image> image;
|
|
Tie(drawResult, image) = GetCurrentImage(container, FLAG_NONE);
|
|
if (!image) {
|
|
return;
|
|
}
|
|
|
|
mLastImageContainerDrawResult = drawResult;
|
|
nsAutoTArray<ImageContainer::NonOwningImage, 1> imageList;
|
|
imageList.AppendElement(ImageContainer::NonOwningImage(image));
|
|
container->SetCurrentImages(imageList);
|
|
}
|
|
|
|
size_t
|
|
RasterImage::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
return mSourceBuffer->SizeOfIncludingThisWithComputedFallback(aMallocSizeOf);
|
|
}
|
|
|
|
void
|
|
RasterImage::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
MallocSizeOf aMallocSizeOf) const
|
|
{
|
|
SurfaceCache::CollectSizeOfSurfaces(ImageKey(this), aCounters, aMallocSizeOf);
|
|
if (mAnim) {
|
|
mAnim->CollectSizeOfCompositingSurfaces(aCounters, aMallocSizeOf);
|
|
}
|
|
}
|
|
|
|
class OnAddedFrameRunnable : public nsRunnable
|
|
{
|
|
public:
|
|
OnAddedFrameRunnable(RasterImage* aImage,
|
|
uint32_t aNewFrameCount,
|
|
const IntRect& aNewRefreshArea)
|
|
: mImage(aImage)
|
|
, mNewFrameCount(aNewFrameCount)
|
|
, mNewRefreshArea(aNewRefreshArea)
|
|
{
|
|
MOZ_ASSERT(aImage);
|
|
}
|
|
|
|
NS_IMETHOD Run()
|
|
{
|
|
mImage->OnAddedFrame(mNewFrameCount, mNewRefreshArea);
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
RefPtr<RasterImage> mImage;
|
|
uint32_t mNewFrameCount;
|
|
IntRect mNewRefreshArea;
|
|
};
|
|
|
|
void
|
|
RasterImage::OnAddedFrame(uint32_t aNewFrameCount,
|
|
const IntRect& aNewRefreshArea)
|
|
{
|
|
if (!NS_IsMainThread()) {
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
new OnAddedFrameRunnable(this, aNewFrameCount, aNewRefreshArea);
|
|
NS_DispatchToMainThread(runnable);
|
|
return;
|
|
}
|
|
|
|
MOZ_ASSERT(aNewFrameCount <= mFrameCount + 1, "Skipped a frame?");
|
|
|
|
if (mError) {
|
|
return; // We're in an error state, possibly due to OOM. Bail.
|
|
}
|
|
|
|
if (aNewFrameCount > mFrameCount) {
|
|
mFrameCount = aNewFrameCount;
|
|
|
|
if (aNewFrameCount == 2) {
|
|
MOZ_ASSERT(mAnim, "Should already have animation state");
|
|
|
|
// We may be able to start animating.
|
|
if (mPendingAnimation && ShouldAnimate()) {
|
|
StartAnimation();
|
|
}
|
|
}
|
|
if (aNewFrameCount > 1) {
|
|
mAnim->UnionFirstFrameRefreshArea(aNewRefreshArea);
|
|
}
|
|
}
|
|
}
|
|
|
|
void
|
|
RasterImage::SetMetadata(const ImageMetadata& aMetadata,
|
|
bool aFromMetadataDecode)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mError) {
|
|
return;
|
|
}
|
|
|
|
if (aMetadata.HasSize()) {
|
|
IntSize size = aMetadata.GetSize();
|
|
if (size.width < 0 || size.height < 0) {
|
|
NS_WARNING("Image has negative intrinsic size");
|
|
DoError();
|
|
return;
|
|
}
|
|
|
|
MOZ_ASSERT(aMetadata.HasOrientation());
|
|
Orientation orientation = aMetadata.GetOrientation();
|
|
|
|
// If we already have a size, check the new size against the old one.
|
|
if (mHasSize && (size != mSize || orientation != mOrientation)) {
|
|
NS_WARNING("Image changed size or orientation on redecode! "
|
|
"This should not happen!");
|
|
DoError();
|
|
return;
|
|
}
|
|
|
|
// Set the size and flag that we have it.
|
|
mSize = size;
|
|
mOrientation = orientation;
|
|
mHasSize = true;
|
|
}
|
|
|
|
if (mHasSize && aMetadata.HasAnimation() && !mAnim) {
|
|
// We're becoming animated, so initialize animation stuff.
|
|
mAnim = MakeUnique<FrameAnimator>(this, mSize, mAnimationMode);
|
|
|
|
// We don't support discarding animated images (See bug 414259).
|
|
// Lock the image and throw away the key.
|
|
LockImage();
|
|
|
|
if (!aFromMetadataDecode) {
|
|
// The metadata decode reported that this image isn't animated, but we
|
|
// discovered that it actually was during the full decode. This is a
|
|
// rare failure that only occurs for corrupt images. To recover, we need
|
|
// to discard all existing surfaces and redecode.
|
|
RecoverFromInvalidFrames(mSize, DECODE_FLAGS_DEFAULT);
|
|
}
|
|
}
|
|
|
|
if (mAnim) {
|
|
mAnim->SetLoopCount(aMetadata.GetLoopCount());
|
|
mAnim->SetFirstFrameTimeout(aMetadata.GetFirstFrameTimeout());
|
|
}
|
|
|
|
if (aMetadata.HasHotspot()) {
|
|
IntPoint hotspot = aMetadata.GetHotspot();
|
|
|
|
nsCOMPtr<nsISupportsPRUint32> intwrapx =
|
|
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
|
|
nsCOMPtr<nsISupportsPRUint32> intwrapy =
|
|
do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID);
|
|
intwrapx->SetData(hotspot.x);
|
|
intwrapy->SetData(hotspot.y);
|
|
|
|
Set("hotspotX", intwrapx);
|
|
Set("hotspotY", intwrapy);
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::SetAnimationMode(uint16_t aAnimationMode)
|
|
{
|
|
if (mAnim) {
|
|
mAnim->SetAnimationMode(aAnimationMode);
|
|
}
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
}
|
|
|
|
//******************************************************************************
|
|
|
|
nsresult
|
|
RasterImage::StartAnimation()
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
|
|
|
// If we're not ready to animate, then set mPendingAnimation, which will cause
|
|
// us to start animating if and when we do become ready.
|
|
mPendingAnimation = !mAnim || GetNumFrames() < 2;
|
|
if (mPendingAnimation) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// A timeout of -1 means we should display this frame forever.
|
|
if (mAnim->GetTimeoutForFrame(GetCurrentFrameIndex()) < 0) {
|
|
mAnimationFinished = true;
|
|
return NS_ERROR_ABORT;
|
|
}
|
|
|
|
// We need to set the time that this initial frame was first displayed, as
|
|
// this is used in AdvanceFrame().
|
|
mAnim->InitAnimationFrameTimeIfNecessary();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
nsresult
|
|
RasterImage::StopAnimation()
|
|
{
|
|
MOZ_ASSERT(mAnimating, "Should be animating!");
|
|
|
|
nsresult rv = NS_OK;
|
|
if (mError) {
|
|
rv = NS_ERROR_FAILURE;
|
|
} else {
|
|
mAnim->SetAnimationFrameTime(TimeStamp());
|
|
}
|
|
|
|
mAnimating = false;
|
|
return rv;
|
|
}
|
|
|
|
//******************************************************************************
|
|
NS_IMETHODIMP
|
|
RasterImage::ResetAnimation()
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
mPendingAnimation = false;
|
|
|
|
if (mAnimationMode == kDontAnimMode || !mAnim ||
|
|
mAnim->GetCurrentAnimationFrameIndex() == 0) {
|
|
return NS_OK;
|
|
}
|
|
|
|
mAnimationFinished = false;
|
|
|
|
if (mAnimating) {
|
|
StopAnimation();
|
|
}
|
|
|
|
MOZ_ASSERT(mAnim, "Should have a FrameAnimator");
|
|
mAnim->ResetAnimation();
|
|
|
|
NotifyProgress(NoProgress, mAnim->GetFirstFrameRefreshArea());
|
|
|
|
// Start the animation again. It may not have been running before, if
|
|
// mAnimationFinished was true before entering this function.
|
|
EvaluateAnimation();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
// [notxpcom] void setAnimationStartTime ([const] in TimeStamp aTime);
|
|
NS_IMETHODIMP_(void)
|
|
RasterImage::SetAnimationStartTime(const TimeStamp& aTime)
|
|
{
|
|
if (mError || mAnimationMode == kDontAnimMode || mAnimating || !mAnim) {
|
|
return;
|
|
}
|
|
|
|
mAnim->SetAnimationFrameTime(aTime);
|
|
}
|
|
|
|
NS_IMETHODIMP_(float)
|
|
RasterImage::GetFrameIndex(uint32_t aWhichFrame)
|
|
{
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
|
|
return (aWhichFrame == FRAME_FIRST || !mAnim)
|
|
? 0.0f
|
|
: mAnim->GetCurrentAnimationFrameIndex();
|
|
}
|
|
|
|
NS_IMETHODIMP_(IntRect)
|
|
RasterImage::GetImageSpaceInvalidationRect(const IntRect& aRect)
|
|
{
|
|
return aRect;
|
|
}
|
|
|
|
nsresult
|
|
RasterImage::OnImageDataComplete(nsIRequest*, nsISupports*, nsresult aStatus,
|
|
bool aLastPart)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Record that we have all the data we're going to get now.
|
|
mHasSourceData = true;
|
|
|
|
// Let decoders know that there won't be any more data coming.
|
|
mSourceBuffer->Complete(aStatus);
|
|
|
|
// Allow a synchronous metadata decode if mSyncLoad was set, or if we're
|
|
// running on a single thread (in which case waiting for the async metadata
|
|
// decoder could delay this image's load event quite a bit), or if this image
|
|
// is transient.
|
|
bool canSyncDecodeMetadata = mSyncLoad || mTransient ||
|
|
DecodePool::NumberOfCores() < 2;
|
|
|
|
if (canSyncDecodeMetadata && !mHasSize) {
|
|
// We're loading this image synchronously, so it needs to be usable after
|
|
// this call returns. Since we haven't gotten our size yet, we need to do a
|
|
// synchronous metadata decode here.
|
|
DecodeMetadata(FLAG_SYNC_DECODE);
|
|
}
|
|
|
|
// Determine our final status, giving precedence to Necko failure codes. We
|
|
// check after running the metadata decode in case it triggered an error.
|
|
nsresult finalStatus = mError ? NS_ERROR_FAILURE : NS_OK;
|
|
if (NS_FAILED(aStatus)) {
|
|
finalStatus = aStatus;
|
|
}
|
|
|
|
// If loading failed, report an error.
|
|
if (NS_FAILED(finalStatus)) {
|
|
DoError();
|
|
}
|
|
|
|
Progress loadProgress = LoadCompleteProgress(aLastPart, mError, finalStatus);
|
|
|
|
if (!mHasSize && !mError) {
|
|
// We don't have our size yet, so we'll fire the load event in SetSize().
|
|
MOZ_ASSERT(!canSyncDecodeMetadata,
|
|
"Firing load async after metadata sync decode?");
|
|
NotifyProgress(FLAG_ONLOAD_BLOCKED);
|
|
mLoadProgress = Some(loadProgress);
|
|
return finalStatus;
|
|
}
|
|
|
|
NotifyForLoadEvent(loadProgress);
|
|
|
|
return finalStatus;
|
|
}
|
|
|
|
void
|
|
RasterImage::NotifyForLoadEvent(Progress aProgress)
|
|
{
|
|
MOZ_ASSERT(mHasSize || mError, "Need to know size before firing load event");
|
|
MOZ_ASSERT(!mHasSize ||
|
|
(mProgressTracker->GetProgress() & FLAG_SIZE_AVAILABLE),
|
|
"Should have notified that the size is available if we have it");
|
|
|
|
// If we encountered an error, make sure we notify for that as well.
|
|
if (mError) {
|
|
aProgress |= FLAG_HAS_ERROR;
|
|
}
|
|
|
|
// Notify our listeners, which will fire this image's load event.
|
|
NotifyProgress(aProgress);
|
|
}
|
|
|
|
nsresult
|
|
RasterImage::OnImageDataAvailable(nsIRequest*,
|
|
nsISupports*,
|
|
nsIInputStream* aInputStream,
|
|
uint64_t,
|
|
uint32_t aCount)
|
|
{
|
|
nsresult rv = mSourceBuffer->AppendFromInputStream(aInputStream, aCount);
|
|
MOZ_ASSERT(rv == NS_OK || rv == NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
if (MOZ_UNLIKELY(rv == NS_ERROR_OUT_OF_MEMORY)) {
|
|
DoError();
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
nsresult
|
|
RasterImage::SetSourceSizeHint(uint32_t aSizeHint)
|
|
{
|
|
return mSourceBuffer->ExpectLength(aSizeHint);
|
|
}
|
|
|
|
/********* Methods to implement lazy allocation of nsIProperties object *******/
|
|
NS_IMETHODIMP
|
|
RasterImage::Get(const char* prop, const nsIID& iid, void** result)
|
|
{
|
|
if (!mProperties) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
return mProperties->Get(prop, iid, result);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::Set(const char* prop, nsISupports* value)
|
|
{
|
|
if (!mProperties) {
|
|
mProperties = do_CreateInstance("@mozilla.org/properties;1");
|
|
}
|
|
if (!mProperties) {
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
}
|
|
return mProperties->Set(prop, value);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::Has(const char* prop, bool* _retval)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
|
if (!mProperties) {
|
|
*_retval = false;
|
|
return NS_OK;
|
|
}
|
|
return mProperties->Has(prop, _retval);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::Undefine(const char* prop)
|
|
{
|
|
if (!mProperties) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
return mProperties->Undefine(prop);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::GetKeys(uint32_t* count, char*** keys)
|
|
{
|
|
if (!mProperties) {
|
|
*count = 0;
|
|
*keys = nullptr;
|
|
return NS_OK;
|
|
}
|
|
return mProperties->GetKeys(count, keys);
|
|
}
|
|
|
|
void
|
|
RasterImage::Discard()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(CanDiscard(), "Asked to discard but can't");
|
|
MOZ_ASSERT(!mAnim, "Asked to discard for animated image");
|
|
|
|
// Delete all the decoded frames.
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
// Notify that we discarded.
|
|
if (mProgressTracker) {
|
|
mProgressTracker->OnDiscard();
|
|
}
|
|
}
|
|
|
|
bool
|
|
RasterImage::CanDiscard() {
|
|
return mHasSourceData && // ...have the source data...
|
|
!mAnim; // Can never discard animated images
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::StartDecoding()
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!mHasSize) {
|
|
mWantFullDecode = true;
|
|
return NS_OK;
|
|
}
|
|
|
|
return RequestDecodeForSize(mSize, FLAG_SYNC_DECODE_IF_FAST);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (!mHasSize) {
|
|
return NS_OK;
|
|
}
|
|
|
|
// Decide whether to sync decode images we can decode quickly. Here we are
|
|
// explicitly trading off flashing for responsiveness in the case that we're
|
|
// redecoding an image (see bug 845147).
|
|
bool shouldSyncDecodeIfFast =
|
|
!mHasBeenDecoded && (aFlags & FLAG_SYNC_DECODE_IF_FAST);
|
|
|
|
uint32_t flags = shouldSyncDecodeIfFast
|
|
? aFlags
|
|
: aFlags & ~FLAG_SYNC_DECODE_IF_FAST;
|
|
|
|
// Look up the first frame of the image, which will implicitly start decoding
|
|
// if it's not available right now.
|
|
LookupFrame(0, aSize, flags);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
static void
|
|
LaunchDecoder(Decoder* aDecoder,
|
|
RasterImage* aImage,
|
|
uint32_t aFlags,
|
|
bool aHaveSourceData)
|
|
{
|
|
if (aHaveSourceData) {
|
|
// If we have all the data, we can sync decode if requested.
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE) {
|
|
PROFILER_LABEL_PRINTF("DecodePool", "SyncDecodeIfPossible",
|
|
js::ProfileEntry::Category::GRAPHICS,
|
|
"%s", aImage->GetURIString().get());
|
|
DecodePool::Singleton()->SyncDecodeIfPossible(aDecoder);
|
|
return;
|
|
}
|
|
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE_IF_FAST) {
|
|
PROFILER_LABEL_PRINTF("DecodePool", "SyncDecodeIfSmall",
|
|
js::ProfileEntry::Category::GRAPHICS,
|
|
"%s", aImage->GetURIString().get());
|
|
DecodePool::Singleton()->SyncDecodeIfSmall(aDecoder);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// Perform an async decode. We also take this path if we don't have all the
|
|
// source data yet, since sync decoding is impossible in that situation.
|
|
DecodePool::Singleton()->AsyncDecode(aDecoder);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// If we don't have a size yet, we can't do any other decoding.
|
|
if (!mHasSize) {
|
|
mWantFullDecode = true;
|
|
return NS_OK;
|
|
}
|
|
|
|
// We're about to decode again, which may mean that some of the previous sizes
|
|
// we've decoded at aren't useful anymore. We can allow them to expire from
|
|
// the cache by unlocking them here. When the decode finishes, it will send an
|
|
// invalidation that will cause all instances of this image to redraw. If this
|
|
// image is locked, any surfaces that are still useful will become locked
|
|
// again when LookupFrame touches them, and the remainder will eventually
|
|
// expire.
|
|
SurfaceCache::UnlockSurfaces(ImageKey(this));
|
|
|
|
Maybe<IntSize> targetSize = mSize != aSize ? Some(aSize) : Nothing();
|
|
|
|
// Determine which flags we need to decode this image with.
|
|
DecoderFlags decoderFlags = DefaultDecoderFlags();
|
|
if (aFlags & FLAG_ASYNC_NOTIFY) {
|
|
decoderFlags |= DecoderFlags::ASYNC_NOTIFY;
|
|
}
|
|
if (mTransient) {
|
|
decoderFlags |= DecoderFlags::IMAGE_IS_TRANSIENT;
|
|
}
|
|
if (mHasBeenDecoded) {
|
|
decoderFlags |= DecoderFlags::IS_REDECODE;
|
|
}
|
|
|
|
// Create a decoder.
|
|
RefPtr<Decoder> decoder;
|
|
if (mAnim) {
|
|
decoder = DecoderFactory::CreateAnimationDecoder(mDecoderType, this,
|
|
mSourceBuffer, decoderFlags,
|
|
ToSurfaceFlags(aFlags),
|
|
mRequestedResolution);
|
|
} else {
|
|
decoder = DecoderFactory::CreateDecoder(mDecoderType, this, mSourceBuffer,
|
|
targetSize, decoderFlags,
|
|
ToSurfaceFlags(aFlags),
|
|
mRequestedSampleSize,
|
|
mRequestedResolution);
|
|
}
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
|
if (!decoder) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Add a placeholder for the first frame to the SurfaceCache so we won't
|
|
// trigger any more decoders with the same parameters.
|
|
InsertOutcome outcome =
|
|
SurfaceCache::InsertPlaceholder(ImageKey(this),
|
|
RasterSurfaceKey(aSize,
|
|
decoder->GetSurfaceFlags(),
|
|
/* aFrameNum = */ 0));
|
|
if (outcome != InsertOutcome::SUCCESS) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
if (mDecodeCount > sMaxDecodeCount) {
|
|
// Don't subtract out 0 from the histogram, because that causes its count
|
|
// to go negative, which is not kosher.
|
|
if (sMaxDecodeCount > 0) {
|
|
/*Telemetry::GetHistogramById(Telemetry::IMAGE_MAX_DECODE_COUNT)
|
|
->Subtract(sMaxDecodeCount);*/
|
|
}
|
|
sMaxDecodeCount = mDecodeCount;
|
|
}
|
|
|
|
// We're ready to decode; start the decoder.
|
|
LaunchDecoder(decoder, this, aFlags, mHasSourceData);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::DecodeMetadata(uint32_t aFlags)
|
|
{
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
MOZ_ASSERT(!mHasSize, "Should not do unnecessary metadata decodes");
|
|
|
|
// Create a decoder.
|
|
RefPtr<Decoder> decoder =
|
|
DecoderFactory::CreateMetadataDecoder(mDecoderType, this, mSourceBuffer,
|
|
mRequestedSampleSize,
|
|
mRequestedResolution);
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
|
if (!decoder) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// We're ready to decode; start the decoder.
|
|
LaunchDecoder(decoder, this, aFlags, mHasSourceData);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
RasterImage::RecoverFromInvalidFrames(const IntSize& aSize, uint32_t aFlags)
|
|
{
|
|
if (!mHasSize) {
|
|
return;
|
|
}
|
|
|
|
NS_WARNING("A RasterImage's frames became invalid. Attempting to recover...");
|
|
|
|
// Discard all existing frames, since they're probably all now invalid.
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
// Relock the image if it's supposed to be locked.
|
|
if (mLockCount > 0) {
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
}
|
|
|
|
// Animated images require some special handling, because we normally require
|
|
// that they never be discarded.
|
|
if (mAnim) {
|
|
Decode(mSize, aFlags | FLAG_SYNC_DECODE);
|
|
ResetAnimation();
|
|
return;
|
|
}
|
|
|
|
// For non-animated images, it's fine to recover using an async decode.
|
|
Decode(aSize, aFlags);
|
|
}
|
|
|
|
static bool
|
|
HaveSkia()
|
|
{
|
|
#ifdef MOZ_ENABLE_SKIA
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
bool
|
|
RasterImage::CanDownscaleDuringDecode(const IntSize& aSize, uint32_t aFlags)
|
|
{
|
|
// Check basic requirements: downscale-during-decode is enabled, Skia is
|
|
// available, this image isn't transient, we have all the source data and know
|
|
// our size, and the flags allow us to do it.
|
|
if (!mHasSize || mTransient || !HaveSkia() ||
|
|
!gfxPrefs::ImageDownscaleDuringDecodeEnabled() ||
|
|
!(aFlags & imgIContainer::FLAG_HIGH_QUALITY_SCALING)) {
|
|
return false;
|
|
}
|
|
|
|
// We don't downscale animated images during decode.
|
|
if (mAnim) {
|
|
return false;
|
|
}
|
|
|
|
// Never upscale.
|
|
if (aSize.width >= mSize.width || aSize.height >= mSize.height) {
|
|
return false;
|
|
}
|
|
|
|
// Zero or negative width or height is unacceptable.
|
|
if (aSize.width < 1 || aSize.height < 1) {
|
|
return false;
|
|
}
|
|
|
|
// There's no point in scaling if we can't store the result.
|
|
if (!SurfaceCache::CanHold(aSize)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
DrawResult
|
|
RasterImage::DrawInternal(DrawableFrameRef&& aFrameRef,
|
|
gfxContext* aContext,
|
|
const IntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
Filter aFilter,
|
|
uint32_t aFlags)
|
|
{
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
|
ImageRegion region(aRegion);
|
|
bool frameIsComplete = aFrameRef->IsImageComplete();
|
|
|
|
// By now we may have a frame with the requested size. If not, we need to
|
|
// adjust the drawing parameters accordingly.
|
|
IntSize finalSize = aFrameRef->GetImageSize();
|
|
bool couldRedecodeForBetterFrame = false;
|
|
if (finalSize != aSize) {
|
|
gfx::Size scale(double(aSize.width) / finalSize.width,
|
|
double(aSize.height) / finalSize.height);
|
|
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
|
|
region.Scale(1.0 / scale.width, 1.0 / scale.height);
|
|
|
|
couldRedecodeForBetterFrame = CanDownscaleDuringDecode(aSize, aFlags);
|
|
}
|
|
|
|
if (!aFrameRef->Draw(aContext, region, aFilter, aFlags)) {
|
|
RecoverFromInvalidFrames(aSize, aFlags);
|
|
return DrawResult::TEMPORARY_ERROR;
|
|
}
|
|
if (!frameIsComplete) {
|
|
return DrawResult::INCOMPLETE;
|
|
}
|
|
if (couldRedecodeForBetterFrame) {
|
|
return DrawResult::WRONG_SIZE;
|
|
}
|
|
return DrawResult::SUCCESS;
|
|
}
|
|
|
|
//******************************************************************************
|
|
/* [noscript] void draw(in gfxContext aContext,
|
|
* in Filter aFilter,
|
|
* [const] in gfxMatrix aUserSpaceToImageSpace,
|
|
* [const] in gfxRect aFill,
|
|
* [const] in IntRect aSubimage,
|
|
* [const] in IntSize aViewportSize,
|
|
* [const] in SVGImageContext aSVGContext,
|
|
* in uint32_t aWhichFrame,
|
|
* in uint32_t aFlags); */
|
|
NS_IMETHODIMP_(DrawResult)
|
|
RasterImage::Draw(gfxContext* aContext,
|
|
const IntSize& aSize,
|
|
const ImageRegion& aRegion,
|
|
uint32_t aWhichFrame,
|
|
Filter aFilter,
|
|
const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
|
|
uint32_t aFlags)
|
|
{
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
|
return DrawResult::BAD_ARGS;
|
|
}
|
|
|
|
if (mError) {
|
|
return DrawResult::BAD_IMAGE;
|
|
}
|
|
|
|
// Illegal -- you can't draw with non-default decode flags.
|
|
// (Disabling colorspace conversion might make sense to allow, but
|
|
// we don't currently.)
|
|
if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
|
|
return DrawResult::BAD_ARGS;
|
|
}
|
|
|
|
if (!aContext) {
|
|
return DrawResult::BAD_ARGS;
|
|
}
|
|
|
|
if (IsUnlocked() && mProgressTracker) {
|
|
mProgressTracker->OnUnlockedDraw();
|
|
}
|
|
|
|
// If we're not using Filter::GOOD, we shouldn't high-quality scale or
|
|
// downscale during decode.
|
|
uint32_t flags = aFilter == Filter::GOOD
|
|
? aFlags
|
|
: aFlags & ~FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
DrawableFrameRef ref =
|
|
LookupFrame(GetRequestedFrameIndex(aWhichFrame), aSize, flags);
|
|
if (!ref) {
|
|
// Getting the frame (above) touches the image and kicks off decoding.
|
|
if (mDrawStartTime.IsNull()) {
|
|
mDrawStartTime = TimeStamp::Now();
|
|
}
|
|
return DrawResult::NOT_READY;
|
|
}
|
|
|
|
auto result = DrawInternal(Move(ref), aContext, aSize,
|
|
aRegion, aFilter, flags);
|
|
|
|
return result;
|
|
}
|
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::LockImage()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
"Main thread to encourage serialization with UnlockImage");
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// Increment the lock count
|
|
mLockCount++;
|
|
|
|
// Lock this image's surfaces in the SurfaceCache.
|
|
if (mLockCount == 1) {
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::UnlockImage()
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
"Main thread to encourage serialization with LockImage");
|
|
if (mError) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
// It's an error to call this function if the lock count is 0
|
|
MOZ_ASSERT(mLockCount > 0,
|
|
"Calling UnlockImage with mLockCount == 0!");
|
|
if (mLockCount == 0) {
|
|
return NS_ERROR_ABORT;
|
|
}
|
|
|
|
// Decrement our lock count
|
|
mLockCount--;
|
|
|
|
// Unlock this image's surfaces in the SurfaceCache.
|
|
if (mLockCount == 0 ) {
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::RequestDiscard()
|
|
{
|
|
if (mDiscardable && // Enabled at creation time...
|
|
mLockCount == 0 && // ...not temporarily disabled...
|
|
CanDiscard()) {
|
|
Discard();
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
// Indempotent error flagging routine. If a decoder is open, shuts it down.
|
|
void
|
|
RasterImage::DoError()
|
|
{
|
|
// If we've flagged an error before, we have nothing to do
|
|
if (mError) {
|
|
return;
|
|
}
|
|
|
|
// We can't safely handle errors off-main-thread, so dispatch a worker to
|
|
// do it.
|
|
if (!NS_IsMainThread()) {
|
|
HandleErrorWorker::DispatchIfNeeded(this);
|
|
return;
|
|
}
|
|
|
|
// Put the container in an error state.
|
|
mError = true;
|
|
|
|
// Stop animation and release our FrameAnimator.
|
|
if (mAnimating) {
|
|
StopAnimation();
|
|
}
|
|
mAnim.release();
|
|
|
|
// Release all locks.
|
|
mLockCount = 0;
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
// Release all frames from the surface cache.
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
// Invalidate to get rid of any partially-drawn image content.
|
|
NotifyProgress(NoProgress, IntRect(0, 0, mSize.width, mSize.height));
|
|
|
|
MOZ_LOG(GetImgLog(), LogLevel::Error,
|
|
("RasterImage: [this=%p] Error detected for image\n", this));
|
|
}
|
|
|
|
/* static */ void
|
|
RasterImage::HandleErrorWorker::DispatchIfNeeded(RasterImage* aImage)
|
|
{
|
|
RefPtr<HandleErrorWorker> worker = new HandleErrorWorker(aImage);
|
|
NS_DispatchToMainThread(worker);
|
|
}
|
|
|
|
RasterImage::HandleErrorWorker::HandleErrorWorker(RasterImage* aImage)
|
|
: mImage(aImage)
|
|
{
|
|
MOZ_ASSERT(mImage, "Should have image");
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
RasterImage::HandleErrorWorker::Run()
|
|
{
|
|
mImage->DoError();
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
bool
|
|
RasterImage::ShouldAnimate()
|
|
{
|
|
return ImageResource::ShouldAnimate() && GetNumFrames() >= 2 &&
|
|
!mAnimationFinished;
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
NS_IMETHODIMP
|
|
RasterImage::GetFramesNotified(uint32_t* aFramesNotified)
|
|
{
|
|
NS_ENSURE_ARG_POINTER(aFramesNotified);
|
|
|
|
*aFramesNotified = mFramesNotified;
|
|
|
|
return NS_OK;
|
|
}
|
|
#endif
|
|
|
|
void
|
|
RasterImage::NotifyProgress(Progress aProgress,
|
|
const IntRect& aInvalidRect /* = IntRect() */,
|
|
SurfaceFlags aSurfaceFlags
|
|
/* = DefaultSurfaceFlags() */)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
// Ensure that we stay alive long enough to finish notifying.
|
|
RefPtr<RasterImage> image(this);
|
|
|
|
bool wasDefaultFlags = aSurfaceFlags == DefaultSurfaceFlags();
|
|
|
|
if (!aInvalidRect.IsEmpty() && wasDefaultFlags) {
|
|
// Update our image container since we're invalidating.
|
|
UpdateImageContainer();
|
|
}
|
|
|
|
// Tell the observers what happened.
|
|
image->mProgressTracker->SyncNotifyProgress(aProgress, aInvalidRect);
|
|
}
|
|
|
|
void
|
|
RasterImage::FinalizeDecoder(Decoder* aDecoder)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aDecoder);
|
|
MOZ_ASSERT(aDecoder->HasError() || !aDecoder->InFrame(),
|
|
"Finalizing a decoder in the middle of a frame");
|
|
|
|
bool wasMetadata = aDecoder->IsMetadataDecode();
|
|
bool done = aDecoder->GetDecodeDone();
|
|
|
|
// If the decoder detected an error, log it to the error console.
|
|
if (aDecoder->ShouldReportError() && !aDecoder->WasAborted()) {
|
|
ReportDecoderError(aDecoder);
|
|
}
|
|
|
|
// Record all the metadata the decoder gathered about this image.
|
|
SetMetadata(aDecoder->GetImageMetadata(), wasMetadata);
|
|
MOZ_ASSERT(mError || mHasSize || !aDecoder->HasSize(),
|
|
"SetMetadata should've gotten a size");
|
|
|
|
if (!wasMetadata && aDecoder->GetDecodeDone() && !aDecoder->WasAborted()) {
|
|
// Flag that we've been decoded before.
|
|
mHasBeenDecoded = true;
|
|
if (mAnim) {
|
|
mAnim->SetDoneDecoding(true);
|
|
}
|
|
}
|
|
|
|
// Send out any final notifications.
|
|
NotifyProgress(aDecoder->TakeProgress(),
|
|
aDecoder->TakeInvalidRect(),
|
|
aDecoder->GetSurfaceFlags());
|
|
|
|
if (!wasMetadata && aDecoder->ChunkCount()) {
|
|
/*Telemetry::Accumulate(Telemetry::IMAGE_DECODE_CHUNKS,
|
|
aDecoder->ChunkCount());*/
|
|
}
|
|
|
|
if (done) {
|
|
// Detect errors.
|
|
if (aDecoder->HasError() && !aDecoder->WasAborted()) {
|
|
DoError();
|
|
} else if (wasMetadata && !mHasSize) {
|
|
DoError();
|
|
}
|
|
|
|
// If we were waiting to fire the load event, go ahead and fire it now.
|
|
if (mLoadProgress && wasMetadata) {
|
|
NotifyForLoadEvent(*mLoadProgress);
|
|
mLoadProgress = Nothing();
|
|
NotifyProgress(FLAG_ONLOAD_UNBLOCKED);
|
|
}
|
|
}
|
|
|
|
// If we were a metadata decode and a full decode was requested, do it.
|
|
if (done && wasMetadata && mWantFullDecode) {
|
|
mWantFullDecode = false;
|
|
RequestDecodeForSize(mSize, DECODE_FLAGS_DEFAULT);
|
|
}
|
|
}
|
|
|
|
void
|
|
RasterImage::ReportDecoderError(Decoder* aDecoder)
|
|
{
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
if (consoleService && errorObject && !aDecoder->HasDecoderError()) {
|
|
nsAutoString msg(NS_LITERAL_STRING("Image corrupt or truncated."));
|
|
nsAutoString src;
|
|
if (GetURI()) {
|
|
nsCString uri;
|
|
if (GetURI()->GetSpecTruncatedTo1k(uri) == ImageURL::TruncatedTo1k) {
|
|
msg += NS_LITERAL_STRING(" URI in this note truncated due to length.");
|
|
}
|
|
src = NS_ConvertUTF8toUTF16(uri);
|
|
}
|
|
if (NS_SUCCEEDED(errorObject->InitWithWindowID(
|
|
msg,
|
|
src,
|
|
EmptyString(), 0, 0, nsIScriptError::errorFlag,
|
|
"Image", InnerWindowID()
|
|
))) {
|
|
consoleService->LogMessage(errorObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
already_AddRefed<imgIContainer>
|
|
RasterImage::Unwrap()
|
|
{
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
return self.forget();
|
|
}
|
|
|
|
void
|
|
RasterImage::PropagateUseCounters(nsIDocument*)
|
|
{
|
|
// No use counters.
|
|
}
|
|
|
|
IntSize
|
|
RasterImage::OptimalImageSizeForDest(const gfxSize& aDest, uint32_t aWhichFrame,
|
|
Filter aFilter, uint32_t aFlags)
|
|
{
|
|
MOZ_ASSERT(aDest.width >= 0 || ceil(aDest.width) <= INT32_MAX ||
|
|
aDest.height >= 0 || ceil(aDest.height) <= INT32_MAX,
|
|
"Unexpected destination size");
|
|
|
|
if (mSize.IsEmpty() || aDest.IsEmpty()) {
|
|
return IntSize(0, 0);
|
|
}
|
|
|
|
IntSize destSize(ceil(aDest.width), ceil(aDest.height));
|
|
|
|
if (aFilter == Filter::GOOD && CanDownscaleDuringDecode(destSize, aFlags)) {
|
|
return destSize;
|
|
}
|
|
|
|
// We can't scale to this size. Use our intrinsic size for now.
|
|
return mSize;
|
|
}
|
|
|
|
} // namespace image
|
|
} // namespace mozilla
|