2001-03-10 04:11:54 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// Must #include ImageLogging.h before any IPDL-generated files or other files
|
|
|
|
// that #include prlog.h
|
2014-04-15 22:02:23 +04:00
|
|
|
#include "RasterImage.h"
|
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <utility>
|
|
|
|
|
2018-02-13 14:43:31 +03:00
|
|
|
#include "DecodePool.h"
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "FrameAnimator.h"
|
|
|
|
#include "GeckoProfiler.h"
|
2016-06-29 23:43:19 +03:00
|
|
|
#include "IDecodingTask.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "ImageLogging.h"
|
2014-08-23 00:12:38 +04:00
|
|
|
#include "ImageRegion.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "Layers.h"
|
2015-07-01 04:57:03 +03:00
|
|
|
#include "LookupResult.h"
|
2020-04-17 05:57:30 +03:00
|
|
|
#include "OrientedImage.h"
|
2015-01-16 02:11:36 +03:00
|
|
|
#include "SourceBuffer.h"
|
2014-09-20 01:53:29 +04:00
|
|
|
#include "SurfaceCache.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "gfx2DGlue.h"
|
2007-03-21 02:56:50 +03:00
|
|
|
#include "gfxContext.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2015-01-19 01:02:13 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-01-20 02:46:55 +03:00
|
|
|
#include "mozilla/Likely.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "mozilla/SizeOfState.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_image.h"
|
2012-01-11 12:23:07 +04:00
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-08-12 09:50:33 +03:00
|
|
|
#include "mozilla/Tuple.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2012-04-04 01:57:22 +04:00
|
|
|
#include "mozilla/gfx/Scale.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsPresContext.h"
|
2018-09-15 19:47:04 +03:00
|
|
|
#include "nsProperties.h"
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "prenv.h"
|
|
|
|
#include "prsystem.h"
|
2021-10-18 02:00:47 +03:00
|
|
|
#include "WindowRenderer.h"
|
2012-10-04 00:36:26 +04:00
|
|
|
|
2014-07-10 19:00:31 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace gfx;
|
|
|
|
using namespace layers;
|
|
|
|
|
|
|
|
namespace image {
|
2014-10-16 00:52:20 +04:00
|
|
|
|
2014-07-29 01:27:39 +04:00
|
|
|
using std::ceil;
|
2014-10-16 00:52:20 +04:00
|
|
|
using std::min;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifndef DEBUG
|
2020-04-01 00:16:39 +03:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer)
|
2010-09-08 04:34:18 +04:00
|
|
|
#else
|
2020-04-01 00:16:39 +03:00
|
|
|
NS_IMPL_ISUPPORTS(RasterImage, imgIContainer, imgIContainerDebug)
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2001-03-24 05:44:26 +03:00
|
|
|
//******************************************************************************
|
2018-06-06 03:42:56 +03:00
|
|
|
RasterImage::RasterImage(nsIURI* aURI /* = nullptr */)
|
2018-04-13 16:01:28 +03:00
|
|
|
: ImageResource(aURI), // invoke superclass's constructor
|
|
|
|
mSize(0, 0),
|
|
|
|
mLockCount(0),
|
2018-06-14 08:21:37 +03:00
|
|
|
mDecoderType(DecoderType::UNKNOWN),
|
2018-04-13 16:01:28 +03:00
|
|
|
mDecodeCount(0),
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
2018-04-13 16:01:28 +03:00
|
|
|
mFramesNotified(0),
|
2010-09-08 04:34:18 +04:00
|
|
|
#endif
|
2020-10-01 16:22:49 +03:00
|
|
|
mSourceBuffer(MakeNotNull<SourceBuffer*>()) {
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2001-03-24 05:44:26 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::~RasterImage() {
|
2015-01-16 02:11:36 +03:00
|
|
|
// Make sure our SourceBuffer is marked as complete. This will ensure that any
|
|
|
|
// outstanding decoders terminate.
|
|
|
|
if (!mSourceBuffer->IsComplete()) {
|
|
|
|
mSourceBuffer->Complete(NS_ERROR_ABORT);
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Release all frames from the surface cache.
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2016-05-03 19:07:45 +03:00
|
|
|
|
|
|
|
// Record Telemetry.
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_COUNT, mDecodeCount);
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2013-02-13 07:00:03 +04:00
|
|
|
nsresult RasterImage::Init(const char* aMimeType, uint32_t aFlags) {
|
2009-09-13 02:44:18 +04:00
|
|
|
// We don't support re-initialization
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mInitialized) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Not sure an error can happen before init, but be safe
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2015-07-15 04:16:31 +03:00
|
|
|
// We want to avoid redecodes for transient images.
|
2015-09-20 02:21:05 +03:00
|
|
|
MOZ_ASSERT_IF(aFlags & INIT_FLAG_TRANSIENT,
|
|
|
|
!(aFlags & INIT_FLAG_DISCARDABLE));
|
2008-01-19 11:10:26 +03:00
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
// Store initialization data
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreDiscardable(!!(aFlags & INIT_FLAG_DISCARDABLE));
|
|
|
|
StoreWantFullDecode(!!(aFlags & INIT_FLAG_DECODE_IMMEDIATELY));
|
|
|
|
StoreTransient(!!(aFlags & INIT_FLAG_TRANSIENT));
|
|
|
|
StoreSyncLoad(!!(aFlags & INIT_FLAG_SYNC_LOAD));
|
2015-01-19 01:02:13 +03:00
|
|
|
|
2015-07-21 19:42:30 +03:00
|
|
|
// 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);
|
2015-07-23 08:39:48 +03:00
|
|
|
mDecoderType = DecoderFactory::GetDecoderType(aMimeType);
|
|
|
|
if (mDecoderType == DecoderType::UNKNOWN) {
|
2015-07-21 19:42:30 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Lock this image's surfaces in the SurfaceCache if we're not discardable.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadDiscardable()) {
|
2015-03-18 05:40:17 +03:00
|
|
|
mLockCount++;
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
// Mark us as initialized
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:15 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-17 02:25:43 +04:00
|
|
|
RasterImage::RequestRefresh(const TimeStamp& aTime) {
|
2014-05-08 22:37:39 +04:00
|
|
|
if (HadRecentRefresh(aTime)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-04 00:20:15 +04:00
|
|
|
EvaluateAnimation();
|
|
|
|
|
|
|
|
if (!mAnimating) {
|
2011-11-10 01:39:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-20 04:20:13 +03:00
|
|
|
RefreshResult res;
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2020-04-20 06:38:27 +03:00
|
|
|
res = mFrameAnimator->RequestRefresh(*mAnimationState, aTime);
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
2020-04-20 06:03:35 +03:00
|
|
|
#ifdef DEBUG
|
2020-04-20 06:38:40 +03:00
|
|
|
if (res.mFrameAdvanced) {
|
2011-11-10 01:39:16 +04:00
|
|
|
mFramesNotified++;
|
2020-04-20 06:38:40 +03:00
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
#endif
|
|
|
|
|
2020-04-20 06:38:40 +03:00
|
|
|
// 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).
|
|
|
|
if (!res.mDirtyRect.IsEmpty() || res.mFrameAdvanced) {
|
2021-10-06 17:41:17 +03:00
|
|
|
auto dirtyRect = OrientedIntRect::FromUnknownRect(res.mDirtyRect);
|
2020-04-17 05:57:30 +03:00
|
|
|
NotifyProgress(NoProgress, dirtyRect);
|
2013-07-15 22:38:59 +04:00
|
|
|
}
|
|
|
|
|
2016-07-20 04:20:13 +03:00
|
|
|
if (res.mAnimationFinished) {
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreAnimationFinished(true);
|
2013-07-15 22:38:59 +04:00
|
|
|
EvaluateAnimation();
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2011-11-10 01:39:15 +04:00
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetWidth(int32_t* aWidth) {
|
2008-03-20 08:54:30 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aWidth);
|
2002-10-08 01:49:33 +04:00
|
|
|
|
2010-10-07 02:18:52 +04:00
|
|
|
if (mError) {
|
|
|
|
*aWidth = 0;
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-07 02:18:52 +04:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
*aWidth = mSize.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetHeight(int32_t* aHeight) {
|
2008-03-20 08:54:30 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aHeight);
|
2002-10-08 01:49:33 +04:00
|
|
|
|
2010-10-07 02:18:52 +04:00
|
|
|
if (mError) {
|
|
|
|
*aHeight = 0;
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-07 02:18:52 +04:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
*aHeight = mSize.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-02 03:17:24 +04:00
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
//******************************************************************************
|
|
|
|
nsresult RasterImage::GetNativeSizes(nsTArray<IntSize>& aNativeSizes) const {
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-04-17 05:57:30 +03:00
|
|
|
aNativeSizes.Clear();
|
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
if (mNativeSizes.IsEmpty()) {
|
2020-04-17 05:57:30 +03:00
|
|
|
aNativeSizes.AppendElement(mSize.ToUnknownSize());
|
2017-03-22 16:05:36 +03:00
|
|
|
} else {
|
2020-04-17 05:57:30 +03:00
|
|
|
for (const auto& size : mNativeSizes) {
|
|
|
|
aNativeSizes.AppendElement(size.ToUnknownSize());
|
|
|
|
}
|
2017-03-22 16:05:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-11 07:38:34 +04:00
|
|
|
//******************************************************************************
|
2017-09-05 14:58:44 +03:00
|
|
|
size_t RasterImage::GetNativeSizesLength() const {
|
2020-12-09 21:14:55 +03:00
|
|
|
if (mError || !LoadHasSize()) {
|
2017-09-05 14:58:44 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mNativeSizes.IsEmpty()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mNativeSizes.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
2013-01-11 07:38:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::GetIntrinsicSize(nsSize* aSize) {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2013-01-11 07:38:34 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-01-11 07:38:34 +04:00
|
|
|
|
|
|
|
*aSize = nsSize(nsPresContext::CSSPixelsToAppUnits(mSize.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(mSize.height));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//******************************************************************************
|
2019-05-03 02:28:21 +03:00
|
|
|
Maybe<AspectRatio> RasterImage::GetIntrinsicRatio() {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2019-05-03 02:28:21 +03:00
|
|
|
return Nothing();
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-01-11 07:38:34 +04:00
|
|
|
|
2019-05-03 02:28:21 +03:00
|
|
|
return Some(AspectRatio::FromSize(mSize.width, mSize.height));
|
2013-01-11 07:38:34 +04:00
|
|
|
}
|
2001-03-10 04:11:54 +03:00
|
|
|
|
2013-08-25 11:19:42 +04:00
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
RasterImage::GetOrientation() { return mOrientation; }
|
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
NS_IMETHODIMP_(Resolution)
|
|
|
|
RasterImage::GetResolution() { return mResolution; }
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetType(uint16_t* aType) {
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
|
2015-03-19 17:12:52 +03:00
|
|
|
*aType = imgIContainer::TYPE_RASTER;
|
2010-08-14 08:09:49 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-27 04:24:33 +03:00
|
|
|
NS_IMETHODIMP
|
2021-10-29 00:36:30 +03:00
|
|
|
RasterImage::GetProducerId(uint32_t* aId) {
|
2021-10-27 04:24:33 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aId);
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
*aId = ImageResource::GetImageProducerId();
|
2021-10-27 04:24:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
LookupResult RasterImage::LookupFrameInternal(const OrientedIntSize& aSize,
|
2016-08-18 10:06:41 +03:00
|
|
|
uint32_t aFlags,
|
2018-10-13 08:31:02 +03:00
|
|
|
PlaybackType aPlaybackType,
|
|
|
|
bool aMarkUsed) {
|
2016-08-18 10:06:41 +03:00
|
|
|
if (mAnimationState && aPlaybackType == PlaybackType::eAnimated) {
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mFrameAnimator);
|
2015-08-15 03:56:44 +03:00
|
|
|
MOZ_ASSERT(ToSurfaceFlags(aFlags) == DefaultSurfaceFlags(),
|
|
|
|
"Can't composite frames with non-default surface flags");
|
2018-10-13 08:31:02 +03:00
|
|
|
return mFrameAnimator->GetCompositedFrame(*mAnimationState, aMarkUsed);
|
2015-01-07 12:40:23 +03:00
|
|
|
}
|
2014-11-27 00:22:10 +03:00
|
|
|
|
2015-10-06 03:06:34 +03:00
|
|
|
SurfaceFlags surfaceFlags = ToSurfaceFlags(aFlags);
|
2015-01-19 01:02:14 +03:00
|
|
|
|
2016-03-08 04:17:16 +03:00
|
|
|
// We don't want any substitution for sync decodes, and substitution would be
|
|
|
|
// illegal when high quality downscaling is disabled, so we use
|
2015-10-06 03:06:34 +03:00
|
|
|
// SurfaceCache::Lookup in this case.
|
2016-03-08 04:17:16 +03:00
|
|
|
if ((aFlags & FLAG_SYNC_DECODE) || !(aFlags & FLAG_HIGH_QUALITY_SCALING)) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return SurfaceCache::Lookup(
|
|
|
|
ImageKey(this),
|
2020-04-17 05:57:30 +03:00
|
|
|
RasterSurfaceKey(aSize.ToUnknownSize(), surfaceFlags,
|
|
|
|
PlaybackType::eStatic),
|
2018-10-13 08:31:02 +03:00
|
|
|
aMarkUsed);
|
2015-01-19 01:02:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We'll return the best match we can find to the requested frame.
|
|
|
|
return SurfaceCache::LookupBestMatch(
|
|
|
|
ImageKey(this),
|
2020-04-17 05:57:30 +03:00
|
|
|
RasterSurfaceKey(aSize.ToUnknownSize(), surfaceFlags,
|
|
|
|
PlaybackType::eStatic),
|
|
|
|
aMarkUsed);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
LookupResult RasterImage::LookupFrame(const OrientedIntSize& aSize,
|
2020-04-17 05:57:30 +03:00
|
|
|
uint32_t aFlags,
|
2018-10-13 08:31:02 +03:00
|
|
|
PlaybackType aPlaybackType,
|
2018-10-13 08:31:03 +03:00
|
|
|
bool aMarkUsed) {
|
2014-11-27 00:22:10 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-10-06 03:06:34 +03:00
|
|
|
// If we're opaque, we don't need to care about premultiplied alpha, because
|
|
|
|
// that can only matter for frames with transparency.
|
|
|
|
if (IsOpaque()) {
|
|
|
|
aFlags &= ~FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
|
|
|
|
}
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
OrientedIntSize requestedSize =
|
|
|
|
CanDownscaleDuringDecode(aSize, aFlags) ? aSize : mSize;
|
2015-10-30 02:37:42 +03:00
|
|
|
if (requestedSize.IsEmpty()) {
|
2017-11-17 14:45:27 +03:00
|
|
|
// Can't decode to a surface of zero size.
|
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-10-30 02:37:42 +03:00
|
|
|
}
|
2014-09-13 05:29:27 +04:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
LookupResult result =
|
2018-10-13 08:31:02 +03:00
|
|
|
LookupFrameInternal(requestedSize, aFlags, aPlaybackType, aMarkUsed);
|
2014-11-28 06:56:00 +03:00
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!result && !LoadHasSize()) {
|
2015-01-19 01:02:13 +03:00
|
|
|
// We can't request a decode without knowing our intrinsic size. Give up.
|
2017-11-17 14:45:27 +03:00
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-01-19 01:02:13 +03:00
|
|
|
}
|
|
|
|
|
2018-11-08 20:45:50 +03:00
|
|
|
const bool syncDecode = aFlags & FLAG_SYNC_DECODE;
|
|
|
|
const bool avoidRedecode = aFlags & FLAG_AVOID_REDECODE_FOR_SIZE;
|
2015-07-20 04:39:44 +03:00
|
|
|
if (result.Type() == MatchType::NOT_FOUND ||
|
2018-11-08 20:45:50 +03:00
|
|
|
(result.Type() == MatchType::SUBSTITUTE_BECAUSE_NOT_FOUND &&
|
|
|
|
!avoidRedecode) ||
|
|
|
|
(syncDecode && !avoidRedecode && !result)) {
|
2015-07-20 04:39:40 +03:00
|
|
|
// We don't have a copy of this frame, and there's no decoder working on
|
2015-07-20 04:39:44 +03:00
|
|
|
// one. (Or we're sync decoding and the existing decoder hasn't even started
|
|
|
|
// yet.) Trigger decoding so it'll be available next time.
|
2016-08-18 10:06:41 +03:00
|
|
|
MOZ_ASSERT(aPlaybackType != PlaybackType::eAnimated ||
|
2019-07-22 05:10:14 +03:00
|
|
|
StaticPrefs::image_mem_animated_discardable_AtStartup() ||
|
2016-08-18 10:06:41 +03:00
|
|
|
!mAnimationState || mAnimationState->KnownFrameCount() < 1,
|
2016-07-19 09:26:58 +03:00
|
|
|
"Animated frames should be locked");
|
2014-09-27 05:50:24 +04:00
|
|
|
|
2017-09-05 14:58:45 +03:00
|
|
|
// The surface cache may suggest the preferred size we are supposed to
|
|
|
|
// decode at. This should only happen if we accept substitutions.
|
|
|
|
if (!result.SuggestedSize().IsEmpty()) {
|
2018-11-08 20:45:50 +03:00
|
|
|
MOZ_ASSERT(!syncDecode && (aFlags & FLAG_HIGH_QUALITY_SCALING));
|
2021-10-06 17:41:17 +03:00
|
|
|
requestedSize = OrientedIntSize::FromUnknownSize(result.SuggestedSize());
|
2017-09-05 14:58:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
bool ranSync = false, failed = false;
|
|
|
|
Decode(requestedSize, aFlags, aPlaybackType, ranSync, failed);
|
|
|
|
if (failed) {
|
|
|
|
result.SetFailedToRequestDecode();
|
|
|
|
}
|
2014-09-27 05:50:24 +04:00
|
|
|
|
2016-12-22 22:15:41 +03:00
|
|
|
// If we can or did sync decode, we should already have the frame.
|
2018-11-08 20:45:50 +03:00
|
|
|
if (ranSync || syncDecode) {
|
2018-10-13 08:31:02 +03:00
|
|
|
result =
|
|
|
|
LookupFrameInternal(requestedSize, aFlags, aPlaybackType, aMarkUsed);
|
2015-01-12 17:35:17 +03:00
|
|
|
}
|
2013-04-05 02:05:19 +04:00
|
|
|
}
|
2009-11-13 02:18:40 +03:00
|
|
|
|
2015-07-01 04:57:03 +03:00
|
|
|
if (!result) {
|
2015-01-19 01:02:14 +03:00
|
|
|
// We still weren't able to get a frame. Give up.
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2015-01-19 01:02:14 +03:00
|
|
|
}
|
|
|
|
|
2015-01-12 06:28:02 +03:00
|
|
|
// 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.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadAllSourceData() && syncDecode) {
|
2016-08-18 03:50:31 +03:00
|
|
|
result.Surface()->WaitUntilFinished();
|
2015-01-12 06:28:02 +03:00
|
|
|
}
|
|
|
|
|
2016-04-01 20:44:17 +03:00
|
|
|
// If we could have done some decoding in this function we need to check if
|
|
|
|
// that decoding encountered an error and hence aborted the surface. We want
|
|
|
|
// to avoid calling IsAborted if we weren't passed any sync decode flag
|
|
|
|
// because IsAborted acquires the monitor for the imgFrame.
|
|
|
|
if (aFlags & (FLAG_SYNC_DECODE | FLAG_SYNC_DECODE_IF_FAST) &&
|
2016-08-18 03:50:31 +03:00
|
|
|
result.Surface()->IsAborted()) {
|
2018-05-30 22:15:35 +03:00
|
|
|
DrawableSurface tmp = std::move(result.Surface());
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2016-04-01 20:44:17 +03:00
|
|
|
}
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
return result;
|
2009-11-13 02:18:40 +03:00
|
|
|
}
|
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
bool RasterImage::IsOpaque() {
|
|
|
|
if (mError) {
|
2013-02-05 02:22:30 +04:00
|
|
|
return false;
|
|
|
|
}
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
Progress progress = mProgressTracker->GetProgress();
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
// If we haven't yet finished decoding, the safe answer is "not opaque".
|
|
|
|
if (!(progress & FLAG_DECODE_COMPLETE)) {
|
2013-02-05 02:22:30 +04:00
|
|
|
return false;
|
2014-11-25 10:42:43 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2014-11-25 10:42:43 +03:00
|
|
|
// Other, we're opaque if FLAG_HAS_TRANSPARENCY is not set.
|
|
|
|
return !(progress & FLAG_HAS_TRANSPARENCY);
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
}
|
|
|
|
|
2016-08-23 05:15:38 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::WillDrawOpaqueNow() {
|
|
|
|
if (!IsOpaque()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-04-06 12:00:36 +03:00
|
|
|
if (mAnimationState) {
|
2019-07-22 05:10:14 +03:00
|
|
|
if (!StaticPrefs::image_mem_animated_discardable_AtStartup()) {
|
2017-04-06 12:00:36 +03:00
|
|
|
// We never discard frames of animated images.
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
if (mAnimationState->GetCompositedFrameInvalid()) {
|
|
|
|
// We're not going to draw anything at all.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-08-23 05:15:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are not locked our decoded data could get discard at any time (ie
|
|
|
|
// between the call to this function and when we are asked to draw), so we
|
|
|
|
// have to return false if we are unlocked.
|
2017-06-30 04:09:44 +03:00
|
|
|
if (mLockCount == 0) {
|
2016-08-23 05:15:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LookupResult result = SurfaceCache::LookupBestMatch(
|
|
|
|
ImageKey(this),
|
2021-10-06 17:41:17 +03:00
|
|
|
RasterSurfaceKey(mSize.ToUnknownSize(), DefaultSurfaceFlags(),
|
2020-04-17 05:57:30 +03:00
|
|
|
PlaybackType::eStatic),
|
2018-10-13 08:31:02 +03:00
|
|
|
/* aMarkUsed = */ false);
|
2016-08-23 05:15:38 +03:00
|
|
|
MatchType matchType = result.Type();
|
|
|
|
if (matchType == MatchType::NOT_FOUND || matchType == MatchType::PENDING ||
|
|
|
|
!result.Surface()->IsFinished()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-16 11:06:06 +03:00
|
|
|
void RasterImage::OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) {
|
2015-02-01 02:29:48 +03:00
|
|
|
MOZ_ASSERT(mProgressTracker);
|
2015-01-08 11:04:31 +03:00
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
bool animatedFramesDiscarded =
|
|
|
|
mAnimationState && aSurfaceKey.Playback() == PlaybackType::eAnimated;
|
|
|
|
|
2017-08-15 03:26:40 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> eventTarget;
|
|
|
|
if (mProgressTracker) {
|
|
|
|
eventTarget = mProgressTracker->GetEventTarget();
|
|
|
|
} else {
|
|
|
|
eventTarget = do_GetMainThread();
|
|
|
|
}
|
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
RefPtr<RasterImage> image = this;
|
2017-08-15 03:26:40 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2017-03-25 10:16:21 +03:00
|
|
|
NS_NewRunnableFunction("RasterImage::OnSurfaceDiscarded", [=]() -> void {
|
|
|
|
image->OnSurfaceDiscardedInternal(animatedFramesDiscarded);
|
2017-08-15 03:26:40 +03:00
|
|
|
});
|
|
|
|
eventTarget->Dispatch(ev.forget(), NS_DISPATCH_NORMAL);
|
2017-03-25 10:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RasterImage::OnSurfaceDiscardedInternal(bool aAnimatedFramesDiscarded) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (aAnimatedFramesDiscarded && mAnimationState) {
|
2019-07-22 05:10:14 +03:00
|
|
|
MOZ_ASSERT(StaticPrefs::image_mem_animated_discardable_AtStartup());
|
2021-10-29 00:36:30 +03:00
|
|
|
ReleaseImageContainer();
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
IntRect rect = mAnimationState->UpdateState(this, mSize.ToUnknownSize());
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
auto dirtyRect = OrientedIntRect::FromUnknownRect(rect);
|
2020-04-17 05:57:30 +03:00
|
|
|
NotifyProgress(NoProgress, dirtyRect);
|
2017-03-16 11:06:04 +03:00
|
|
|
}
|
|
|
|
|
2017-03-25 10:16:21 +03:00
|
|
|
if (mProgressTracker) {
|
|
|
|
mProgressTracker->OnDiscard();
|
|
|
|
}
|
2014-11-28 06:55:57 +03:00
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetAnimated(bool* aAnimated) {
|
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aAnimated);
|
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
// If we have an AnimationState, we can know for sure.
|
|
|
|
if (mAnimationState) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAnimated = true;
|
2009-10-07 08:39:30 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we need to have been decoded to know for sure, since if we were
|
2016-07-19 09:26:58 +03:00
|
|
|
// decoded at least once mAnimationState 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.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasBeenDecoded()) {
|
2009-10-07 08:39:30 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-10-07 08:39:30 +04:00
|
|
|
|
|
|
|
// We know for sure
|
2011-10-17 18:59:28 +04:00
|
|
|
*aAnimated = false;
|
2009-10-07 08:39:30 +04:00
|
|
|
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-05-17 21:42:20 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(int32_t)
|
|
|
|
RasterImage::GetFirstFrameDelay() {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2013-05-17 21:42:20 +04:00
|
|
|
return -1;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-17 21:42:20 +04:00
|
|
|
|
|
|
|
bool animated = false;
|
2015-03-31 20:49:00 +03:00
|
|
|
if (NS_FAILED(GetAnimated(&animated)) || !animated) {
|
2013-05-17 21:42:20 +04:00
|
|
|
return -1;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-17 21:42:20 +04:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mAnimationState, "Animated images should have an AnimationState");
|
2016-07-19 23:51:01 +03:00
|
|
|
return mAnimationState->FirstFrameTimeout().AsEncodedValueDeprecated();
|
2013-05-17 21:42:20 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2012-08-22 19:56:38 +04:00
|
|
|
RasterImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
|
2020-04-17 05:57:30 +03:00
|
|
|
return GetFrameAtSize(mSize.ToUnknownSize(), aWhichFrame, aFlags);
|
2015-09-19 23:34:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
RasterImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) {
|
2021-04-14 12:00:13 +03:00
|
|
|
AutoProfilerImagePaintMarker PROFILER_RAII(this);
|
2017-08-02 01:08:02 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NotifyDrawingObservers();
|
|
|
|
#endif
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
auto result =
|
|
|
|
GetFrameInternal(aSize, Nothing(), Nothing(), aWhichFrame, aFlags);
|
|
|
|
return mozilla::Get<2>(result).forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tuple<ImgDrawResult, IntSize, RefPtr<SourceSurface>>
|
|
|
|
RasterImage::GetFrameInternal(const IntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
const Maybe<ImageIntRegion>& aRegion,
|
|
|
|
uint32_t aWhichFrame, uint32_t aFlags) {
|
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE);
|
2021-10-26 18:04:34 +03:00
|
|
|
|
2021-10-27 04:24:36 +03:00
|
|
|
auto size = OrientedIntSize::FromUnknownSize(aSize);
|
2021-10-26 18:04:34 +03:00
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
if (aSize.IsEmpty() || aWhichFrame > FRAME_MAX_VALUE) {
|
|
|
|
return MakeTuple(ImgDrawResult::BAD_ARGS, aSize, RefPtr<SourceSurface>());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mError) {
|
|
|
|
return MakeTuple(ImgDrawResult::BAD_IMAGE, aSize, RefPtr<SourceSurface>());
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
// 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
|
2016-08-18 10:06:41 +03:00
|
|
|
// FLAG_SYNC_DECODE.
|
2021-10-06 17:41:17 +03:00
|
|
|
LookupResult result = LookupFrame(size, aFlags, ToPlaybackType(aWhichFrame),
|
|
|
|
/* aMarkUsed = */ true);
|
2021-10-29 00:36:30 +03:00
|
|
|
|
|
|
|
// The surface cache may have suggested we use a different size than the
|
|
|
|
// given size in the future. This may or may not be accompanied by an
|
|
|
|
// actual surface, depending on what it has in its cache.
|
|
|
|
auto suggestedSize = OrientedIntSize::FromUnknownSize(result.SuggestedSize());
|
|
|
|
if (suggestedSize.IsEmpty()) {
|
|
|
|
suggestedSize = size;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT_IF(result.Type() == MatchType::SUBSTITUTE_BECAUSE_BEST,
|
|
|
|
suggestedSize != size);
|
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
if (!result) {
|
2014-09-27 05:50:24 +04:00
|
|
|
// The OS threw this frame away and we couldn't redecode it.
|
2021-10-29 00:36:30 +03:00
|
|
|
return MakeTuple(ImgDrawResult::TEMPORARY_ERROR,
|
|
|
|
suggestedSize.ToUnknownSize(), RefPtr<SourceSurface>());
|
2021-10-26 18:04:34 +03:00
|
|
|
}
|
2017-11-17 14:45:26 +03:00
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
RefPtr<SourceSurface> surface = result.Surface()->GetSourceSurface();
|
|
|
|
if (!result.Surface()->IsFinished()) {
|
|
|
|
return MakeTuple(ImgDrawResult::INCOMPLETE, suggestedSize.ToUnknownSize(),
|
|
|
|
std::move(surface));
|
|
|
|
}
|
2021-10-26 16:28:25 +03:00
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
return MakeTuple(ImgDrawResult::SUCCESS, suggestedSize.ToUnknownSize(),
|
|
|
|
std::move(surface));
|
2021-10-26 18:04:34 +03:00
|
|
|
}
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
Tuple<ImgDrawResult, IntSize> RasterImage::GetImageContainerSize(
|
|
|
|
WindowRenderer* aRenderer, const IntSize& aRequestedSize, uint32_t aFlags) {
|
2021-10-27 04:24:33 +03:00
|
|
|
if (!LoadHasSize()) {
|
2021-10-29 00:36:30 +03:00
|
|
|
return MakeTuple(ImgDrawResult::NOT_READY, IntSize(0, 0));
|
2021-10-27 04:24:33 +03:00
|
|
|
}
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
if (aRequestedSize.IsEmpty()) {
|
|
|
|
return MakeTuple(ImgDrawResult::BAD_ARGS, IntSize(0, 0));
|
2021-10-27 04:24:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// We check the minimum size because while we support downscaling, we do not
|
|
|
|
// support upscaling. If aRequestedSize > mSize, we will never give a larger
|
|
|
|
// surface than mSize. If mSize > aRequestedSize, and mSize > maxTextureSize,
|
|
|
|
// we still want to use image containers if aRequestedSize <= maxTextureSize.
|
|
|
|
int32_t maxTextureSize = aRenderer->GetMaxTextureSize();
|
2021-10-29 00:36:30 +03:00
|
|
|
if (min(mSize.width, aRequestedSize.width) > maxTextureSize ||
|
|
|
|
min(mSize.height, aRequestedSize.height) > maxTextureSize) {
|
|
|
|
return MakeTuple(ImgDrawResult::NOT_SUPPORTED, IntSize(0, 0));
|
2021-10-27 04:24:33 +03:00
|
|
|
}
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
auto requestedSize = OrientedIntSize::FromUnknownSize(aRequestedSize);
|
|
|
|
if (!CanDownscaleDuringDecode(requestedSize, aFlags)) {
|
|
|
|
return MakeTuple(ImgDrawResult::SUCCESS, mSize.ToUnknownSize());
|
2021-10-27 04:24:33 +03:00
|
|
|
}
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
return MakeTuple(ImgDrawResult::SUCCESS, aRequestedSize);
|
|
|
|
}
|
2021-10-27 04:24:33 +03:00
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
RasterImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
return LoadHasSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
|
|
|
RasterImage::GetImageContainerAtSize(WindowRenderer* aRenderer,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
const Maybe<ImageIntRegion>& aRegion,
|
|
|
|
uint32_t aFlags,
|
|
|
|
layers::ImageContainer** aOutContainer) {
|
|
|
|
// We do not pass in the given SVG context because in theory it could differ
|
|
|
|
// between calls, but actually have no impact on the actual contents of the
|
|
|
|
// image container.
|
|
|
|
return GetImageContainerImpl(aRenderer, aSize, Nothing(), Nothing(), aFlags,
|
|
|
|
aOutContainer);
|
2021-10-27 04:24:31 +03:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:10:04 +03:00
|
|
|
size_t RasterImage::SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const {
|
|
|
|
return mSourceBuffer->SizeOfIncludingThisWithComputedFallback(
|
|
|
|
aState.mMallocSizeOf);
|
2012-02-20 07:51:48 +04:00
|
|
|
}
|
2011-07-18 17:20:27 +04:00
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
void RasterImage::CollectSizeOfSurfaces(
|
|
|
|
nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const {
|
|
|
|
SurfaceCache::CollectSizeOfSurfaces(ImageKey(this), aCounters, aMallocSizeOf);
|
|
|
|
ImageResource::CollectSizeOfSurfaces(aCounters, aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
bool RasterImage::SetMetadata(const ImageMetadata& aMetadata,
|
|
|
|
bool aFromMetadataDecode) {
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2015-09-24 02:53:40 +03:00
|
|
|
return true;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
mResolution = aMetadata.GetResolution();
|
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
if (aMetadata.HasSize()) {
|
2021-10-06 17:41:17 +03:00
|
|
|
auto metadataSize = aMetadata.GetSize();
|
2020-04-17 05:57:30 +03:00
|
|
|
if (metadataSize.width < 0 || metadataSize.height < 0) {
|
2015-08-18 20:19:28 +03:00
|
|
|
NS_WARNING("Image has negative intrinsic size");
|
|
|
|
DoError();
|
2015-09-24 02:53:40 +03:00
|
|
|
return true;
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(aMetadata.HasOrientation());
|
|
|
|
Orientation orientation = aMetadata.GetOrientation();
|
|
|
|
|
|
|
|
// If we already have a size, check the new size against the old one.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadHasSize() &&
|
2021-10-06 17:41:17 +03:00
|
|
|
(metadataSize != mSize || orientation != mOrientation)) {
|
2015-08-14 10:37:13 +03:00
|
|
|
NS_WARNING(
|
|
|
|
"Image changed size or orientation on redecode! "
|
|
|
|
"This should not happen!");
|
|
|
|
DoError();
|
2015-09-24 02:53:40 +03:00
|
|
|
return true;
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the size and flag that we have it.
|
|
|
|
mOrientation = orientation;
|
2021-10-06 17:41:17 +03:00
|
|
|
mSize = metadataSize;
|
2020-04-17 05:57:30 +03:00
|
|
|
mNativeSizes.Clear();
|
|
|
|
for (const auto& nativeSize : aMetadata.GetNativeSizes()) {
|
2021-10-06 17:41:17 +03:00
|
|
|
mNativeSizes.AppendElement(nativeSize);
|
2020-04-17 05:57:30 +03:00
|
|
|
}
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreHasSize(true);
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadHasSize() && aMetadata.HasAnimation() && !mAnimationState) {
|
2015-08-14 10:37:13 +03:00
|
|
|
// We're becoming animated, so initialize animation stuff.
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState.emplace(mAnimationMode);
|
2021-10-06 17:41:17 +03:00
|
|
|
mFrameAnimator = MakeUnique<FrameAnimator>(this, mSize.ToUnknownSize());
|
2015-08-14 10:37:13 +03:00
|
|
|
|
2019-07-22 05:10:14 +03:00
|
|
|
if (!StaticPrefs::image_mem_animated_discardable_AtStartup()) {
|
2017-03-27 08:17:52 +03:00
|
|
|
// We don't support discarding animated images (See bug 414259).
|
|
|
|
// Lock the image and throw away the key.
|
|
|
|
LockImage();
|
|
|
|
}
|
2015-08-14 10:37:13 +03:00
|
|
|
|
|
|
|
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.
|
2015-09-24 02:53:40 +03:00
|
|
|
return false;
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetLoopCount(aMetadata.GetLoopCount());
|
|
|
|
mAnimationState->SetFirstFrameTimeout(aMetadata.GetFirstFrameTimeout());
|
2016-07-20 03:14:30 +03:00
|
|
|
|
|
|
|
if (aMetadata.HasLoopLength()) {
|
|
|
|
mAnimationState->SetLoopLength(aMetadata.GetLoopLength());
|
|
|
|
}
|
2016-07-20 09:35:41 +03:00
|
|
|
if (aMetadata.HasFirstFrameRefreshArea()) {
|
|
|
|
mAnimationState->SetFirstFrameRefreshArea(
|
|
|
|
aMetadata.GetFirstFrameRefreshArea());
|
|
|
|
}
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aMetadata.HasHotspot()) {
|
2020-04-17 05:57:30 +03:00
|
|
|
// NOTE(heycam): We shouldn't have any image formats that support both
|
|
|
|
// orientation and hotspots, so we assert that rather than add code
|
|
|
|
// to orient the hotspot point correctly.
|
2021-04-11 20:39:12 +03:00
|
|
|
MOZ_ASSERT(mOrientation.IsIdentity(), "Would need to orient hotspot point");
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2020-04-01 00:16:39 +03:00
|
|
|
auto hotspot = aMetadata.GetHotspot();
|
|
|
|
mHotspot.x = std::max(std::min(hotspot.x, mSize.width - 1), 0);
|
|
|
|
mHotspot.y = std::max(std::min(hotspot.y, mSize.height - 1), 0);
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
2015-09-24 02:53:40 +03:00
|
|
|
|
|
|
|
return true;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2013-07-15 22:38:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::SetAnimationMode(uint16_t aAnimationMode) {
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
|
|
|
mAnimationState->SetAnimationMode(aAnimationMode);
|
2013-07-15 22:38:59 +04:00
|
|
|
}
|
|
|
|
return SetAnimationModeInternal(aAnimationMode);
|
|
|
|
}
|
|
|
|
|
2001-04-26 11:11:52 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult RasterImage::StartAnimation() {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(ShouldAnimate(), "Should not animate!");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
// If we're not ready to animate, then set mPendingAnimation, which will cause
|
|
|
|
// us to start animating if and when we do become ready.
|
2020-12-09 21:14:55 +03:00
|
|
|
StorePendingAnimation(!mAnimationState ||
|
|
|
|
mAnimationState->KnownFrameCount() < 1);
|
|
|
|
if (LoadPendingAnimation()) {
|
2014-11-27 00:22:10 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2016-07-20 02:22:34 +03:00
|
|
|
// Don't bother to animate if we're displaying the first frame forever.
|
2016-08-18 10:06:41 +03:00
|
|
|
if (mAnimationState->GetCurrentAnimationFrameIndex() == 0 &&
|
2016-07-19 23:51:01 +03:00
|
|
|
mAnimationState->FirstFrameTimeout() == FrameTimeout::Forever()) {
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreAnimationFinished(true);
|
2013-09-20 16:12:10 +04:00
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
|
2015-01-08 00:07:23 +03:00
|
|
|
// We need to set the time that this initial frame was first displayed, as
|
|
|
|
// this is used in AdvanceFrame().
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->InitAnimationFrameTimeIfNecessary();
|
2013-03-30 00:14:19 +04:00
|
|
|
|
2001-03-10 04:11:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-03-14 02:33:11 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
nsresult RasterImage::StopAnimation() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mAnimating, "Should be animating!");
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mError) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
} else {
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->SetAnimationFrameTime(TimeStamp());
|
2013-09-20 16:12:10 +04:00
|
|
|
}
|
2013-09-04 00:20:15 +04:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
mAnimating = false;
|
|
|
|
return rv;
|
2001-03-10 04:11:54 +03:00
|
|
|
}
|
|
|
|
|
2007-03-21 02:56:50 +03:00
|
|
|
//******************************************************************************
|
2010-08-14 08:09:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::ResetAnimation() {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
StorePendingAnimation(false);
|
2014-11-27 00:22:10 +03:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationMode == kDontAnimMode || !mAnimationState ||
|
|
|
|
mAnimationState->GetCurrentAnimationFrameIndex() == 0) {
|
2007-03-21 02:56:50 +03:00
|
|
|
return NS_OK;
|
2014-11-27 00:22:10 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreAnimationFinished(false);
|
2011-04-01 01:05:31 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mAnimating) {
|
2010-09-08 04:33:02 +04:00
|
|
|
StopAnimation();
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
MOZ_ASSERT(mAnimationState, "Should have AnimationState");
|
2018-02-28 21:34:52 +03:00
|
|
|
MOZ_ASSERT(mFrameAnimator, "Should have FrameAnimator");
|
|
|
|
mFrameAnimator->ResetAnimation(*mAnimationState);
|
2013-06-18 00:49:04 +04:00
|
|
|
|
2020-04-17 05:57:30 +03:00
|
|
|
IntRect area = mAnimationState->FirstFrameRefreshArea();
|
2021-10-06 17:41:17 +03:00
|
|
|
NotifyProgress(NoProgress, OrientedIntRect::FromUnknownRect(area));
|
2007-03-21 02:56:50 +03:00
|
|
|
|
2013-09-20 16:12:10 +04:00
|
|
|
// Start the animation again. It may not have been running before, if
|
|
|
|
// mAnimationFinished was true before entering this function.
|
|
|
|
EvaluateAnimation();
|
2010-09-08 04:33:02 +04:00
|
|
|
|
2008-03-20 08:54:30 +03:00
|
|
|
return NS_OK;
|
2007-03-21 02:56:50 +03:00
|
|
|
}
|
|
|
|
|
2013-05-18 00:57:20 +04:00
|
|
|
//******************************************************************************
|
|
|
|
NS_IMETHODIMP_(void)
|
2014-06-17 02:25:43 +04:00
|
|
|
RasterImage::SetAnimationStartTime(const TimeStamp& aTime) {
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mError || mAnimationMode == kDontAnimMode || mAnimating ||
|
|
|
|
!mAnimationState) {
|
2013-05-18 00:57:20 +04:00
|
|
|
return;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-05-18 00:57:20 +04:00
|
|
|
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState->SetAnimationFrameTime(aTime);
|
2013-05-18 00:57:20 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:20 +04:00
|
|
|
NS_IMETHODIMP_(float)
|
|
|
|
RasterImage::GetFrameIndex(uint32_t aWhichFrame) {
|
|
|
|
MOZ_ASSERT(aWhichFrame <= FRAME_MAX_VALUE, "Invalid argument");
|
2016-07-19 09:26:58 +03:00
|
|
|
return (aWhichFrame == FRAME_FIRST || !mAnimationState)
|
2013-04-26 02:58:20 +04:00
|
|
|
? 0.0f
|
2016-07-19 09:26:58 +03:00
|
|
|
: mAnimationState->GetCurrentAnimationFrameIndex();
|
2013-04-26 02:58:20 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 18:04:57 +03:00
|
|
|
NS_IMETHODIMP_(IntRect)
|
|
|
|
RasterImage::GetImageSpaceInvalidationRect(const IntRect& aRect) {
|
2020-04-17 05:57:30 +03:00
|
|
|
// Note that we do not transform aRect into an UnorientedIntRect, since
|
|
|
|
// RasterImage::NotifyProgress notifies all consumers of the image using
|
|
|
|
// OrientedIntRect values. (This is unlike OrientedImage, which notifies
|
|
|
|
// using inner image coordinates.)
|
2014-06-27 03:02:04 +04:00
|
|
|
return aRect;
|
|
|
|
}
|
|
|
|
|
2021-11-24 14:25:41 +03:00
|
|
|
nsresult RasterImage::OnImageDataComplete(nsIRequest*, nsresult aStatus,
|
|
|
|
bool aLastPart) {
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Record that we have all the data we're going to get now.
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreAllSourceData(true);
|
2013-02-14 06:41:10 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Let decoders know that there won't be any more data coming.
|
|
|
|
mSourceBuffer->Complete(aStatus);
|
2015-01-11 22:43:32 +03:00
|
|
|
|
2015-07-23 08:39:51 +03:00
|
|
|
// 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 =
|
2020-12-09 21:14:55 +03:00
|
|
|
LoadSyncLoad() || LoadTransient() || DecodePool::NumberOfCores() < 2;
|
2015-07-09 01:52:51 +03:00
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (canSyncDecodeMetadata && !LoadHasSize()) {
|
2015-06-30 12:37:58 +03:00
|
|
|
// 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
|
2015-07-23 08:39:51 +03:00
|
|
|
// synchronous metadata decode here.
|
|
|
|
DecodeMetadata(FLAG_SYNC_DECODE);
|
2015-01-11 22:43:32 +03:00
|
|
|
}
|
2015-01-11 16:34:20 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Determine our final status, giving precedence to Necko failure codes. We
|
2015-07-23 08:39:51 +03:00
|
|
|
// check after running the metadata decode in case it triggered an error.
|
2015-01-16 02:11:36 +03:00
|
|
|
nsresult finalStatus = mError ? NS_ERROR_FAILURE : NS_OK;
|
|
|
|
if (NS_FAILED(aStatus)) {
|
2015-01-12 21:17:52 +03:00
|
|
|
finalStatus = aStatus;
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// If loading failed, report an error.
|
|
|
|
if (NS_FAILED(finalStatus)) {
|
|
|
|
DoError();
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
2015-01-12 12:20:23 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
Progress loadProgress = LoadCompleteProgress(aLastPart, mError, finalStatus);
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize() && !mError) {
|
2015-06-30 12:37:58 +03:00
|
|
|
// We don't have our size yet, so we'll fire the load event in SetSize().
|
2015-07-23 08:39:51 +03:00
|
|
|
MOZ_ASSERT(!canSyncDecodeMetadata,
|
|
|
|
"Firing load async after metadata sync decode?");
|
2015-06-30 12:37:58 +03:00
|
|
|
mLoadProgress = Some(loadProgress);
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
NotifyForLoadEvent(loadProgress);
|
|
|
|
|
|
|
|
return finalStatus;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasterImage::NotifyForLoadEvent(Progress aProgress) {
|
2020-12-09 21:14:55 +03:00
|
|
|
MOZ_ASSERT(LoadHasSize() || mError,
|
2020-10-01 16:22:49 +03:00
|
|
|
"Need to know size before firing load event");
|
2015-01-16 02:11:36 +03:00
|
|
|
MOZ_ASSERT(
|
2020-12-09 21:14:55 +03:00
|
|
|
!LoadHasSize() || (mProgressTracker->GetProgress() & FLAG_SIZE_AVAILABLE),
|
2015-01-16 02:11:36 +03:00
|
|
|
"Should have notified that the size is available if we have it");
|
2015-01-20 02:46:55 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
// If we encountered an error, make sure we notify for that as well.
|
|
|
|
if (mError) {
|
|
|
|
aProgress |= FLAG_HAS_ERROR;
|
|
|
|
}
|
2015-06-26 05:57:00 +03:00
|
|
|
|
2015-06-30 12:37:58 +03:00
|
|
|
// Notify our listeners, which will fire this image's load event.
|
|
|
|
NotifyProgress(aProgress);
|
2013-02-14 06:41:10 +04:00
|
|
|
}
|
|
|
|
|
2021-11-24 14:25:41 +03:00
|
|
|
nsresult RasterImage::OnImageDataAvailable(nsIRequest*,
|
2015-08-01 04:10:29 +03:00
|
|
|
nsIInputStream* aInputStream,
|
2012-12-18 02:05:18 +04:00
|
|
|
uint64_t, uint32_t aCount) {
|
2015-08-01 04:10:29 +03:00
|
|
|
nsresult rv = mSourceBuffer->AppendFromInputStream(aInputStream, aCount);
|
2020-12-09 21:14:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && !LoadSomeSourceData()) {
|
|
|
|
StoreSomeSourceData(true);
|
|
|
|
if (!LoadSyncLoad()) {
|
2016-11-28 16:42:55 +03:00
|
|
|
// Create an async metadata decoder and verify we succeed in doing so.
|
|
|
|
rv = DecodeMetadata(DECODE_FLAGS_DEFAULT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 17:09:35 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2015-08-01 04:10:29 +03:00
|
|
|
DoError();
|
|
|
|
}
|
2012-12-18 02:05:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
nsresult RasterImage::SetSourceSizeHint(uint32_t aSizeHint) {
|
2018-05-09 16:31:07 +03:00
|
|
|
if (aSizeHint == 0) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = mSourceBuffer->ExpectLength(aSizeHint);
|
|
|
|
if (rv == NS_ERROR_OUT_OF_MEMORY) {
|
|
|
|
// Flush memory, try to get some back, and try again.
|
|
|
|
rv = nsMemory::HeapMinimize(true);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mSourceBuffer->ExpectLength(aSizeHint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2010-06-25 22:21:40 +04:00
|
|
|
}
|
|
|
|
|
2020-04-01 00:16:39 +03:00
|
|
|
nsresult RasterImage::GetHotspotX(int32_t* aX) {
|
|
|
|
*aX = mHotspot.x;
|
|
|
|
return NS_OK;
|
2020-03-30 07:44:01 +03:00
|
|
|
}
|
|
|
|
|
2020-04-01 00:16:39 +03:00
|
|
|
nsresult RasterImage::GetHotspotY(int32_t* aY) {
|
|
|
|
*aY = mHotspot.y;
|
|
|
|
return NS_OK;
|
2007-06-22 00:45:49 +04:00
|
|
|
}
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2014-11-28 06:56:00 +03:00
|
|
|
void RasterImage::Discard() {
|
2013-03-02 03:17:24 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-11-28 06:55:57 +03:00
|
|
|
MOZ_ASSERT(CanDiscard(), "Asked to discard but can't");
|
2019-07-22 05:10:14 +03:00
|
|
|
MOZ_ASSERT(!mAnimationState ||
|
|
|
|
StaticPrefs::image_mem_animated_discardable_AtStartup(),
|
2017-03-27 08:17:52 +03:00
|
|
|
"Asked to discard for animated image");
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2015-01-08 00:07:23 +03:00
|
|
|
// Delete all the decoded frames.
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
2007-10-19 04:36:34 +04:00
|
|
|
|
2017-03-16 11:06:04 +03:00
|
|
|
if (mAnimationState) {
|
2021-10-29 00:36:30 +03:00
|
|
|
ReleaseImageContainer();
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
IntRect rect = mAnimationState->UpdateState(this, mSize.ToUnknownSize());
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
auto dirtyRect = OrientedIntRect::FromUnknownRect(rect);
|
2020-04-17 05:57:30 +03:00
|
|
|
NotifyProgress(NoProgress, dirtyRect);
|
2017-03-16 11:06:04 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Notify that we discarded.
|
2014-11-28 06:56:00 +03:00
|
|
|
if (mProgressTracker) {
|
2014-11-15 07:10:47 +03:00
|
|
|
mProgressTracker->OnDiscard();
|
2014-11-27 00:22:10 +03:00
|
|
|
}
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
bool RasterImage::CanDiscard() {
|
2020-12-09 21:14:55 +03:00
|
|
|
return LoadAllSourceData() &&
|
2017-03-27 08:17:52 +03:00
|
|
|
// Can discard animated images if the pref is set
|
2019-07-22 05:10:14 +03:00
|
|
|
(!mAnimationState ||
|
|
|
|
StaticPrefs::image_mem_animated_discardable_AtStartup());
|
2014-01-22 03:19:22 +04:00
|
|
|
}
|
|
|
|
|
2015-10-29 08:57:43 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-21 20:34:14 +03:00
|
|
|
RasterImage::StartDecoding(uint32_t aFlags, uint32_t aWhichFrame) {
|
2015-10-30 02:37:42 +03:00
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize()) {
|
|
|
|
StoreWantFullDecode(true);
|
2015-10-30 02:37:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-28 02:30:17 +03:00
|
|
|
uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST |
|
|
|
|
FLAG_HIGH_QUALITY_SCALING;
|
2020-04-17 05:57:30 +03:00
|
|
|
return RequestDecodeForSize(mSize.ToUnknownSize(), flags, aWhichFrame);
|
2015-01-19 01:02:13 +03:00
|
|
|
}
|
|
|
|
|
2019-05-21 20:34:14 +03:00
|
|
|
bool RasterImage::StartDecodingWithResult(uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
2016-12-23 10:07:45 +03:00
|
|
|
if (mError) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize()) {
|
|
|
|
StoreWantFullDecode(true);
|
2016-12-23 10:07:45 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-28 02:30:17 +03:00
|
|
|
uint32_t flags = (aFlags & FLAG_ASYNC_NOTIFY) | FLAG_SYNC_DECODE_IF_FAST |
|
|
|
|
FLAG_HIGH_QUALITY_SCALING;
|
2021-10-06 17:41:17 +03:00
|
|
|
LookupResult result = RequestDecodeForSizeInternal(mSize, flags, aWhichFrame);
|
2020-04-21 00:04:45 +03:00
|
|
|
DrawableSurface surface = std::move(result.Surface());
|
2016-12-23 10:07:45 +03:00
|
|
|
return surface && surface->IsFinished();
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
imgIContainer::DecodeResult RasterImage::RequestDecodeWithResult(
|
|
|
|
uint32_t aFlags, uint32_t aWhichFrame) {
|
2018-11-08 20:45:50 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mError) {
|
2020-04-21 00:04:45 +03:00
|
|
|
return imgIContainer::DECODE_REQUEST_FAILED;
|
2018-11-08 20:45:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = aFlags | FLAG_ASYNC_NOTIFY;
|
2021-10-06 17:41:17 +03:00
|
|
|
LookupResult result = RequestDecodeForSizeInternal(mSize, flags, aWhichFrame);
|
2020-04-21 00:04:45 +03:00
|
|
|
DrawableSurface surface = std::move(result.Surface());
|
|
|
|
if (surface && surface->IsFinished()) {
|
|
|
|
return imgIContainer::DECODE_SURFACE_AVAILABLE;
|
|
|
|
}
|
|
|
|
if (result.GetFailedToRequestDecode()) {
|
|
|
|
return imgIContainer::DECODE_REQUEST_FAILED;
|
|
|
|
}
|
|
|
|
return imgIContainer::DECODE_REQUESTED;
|
2018-11-08 20:45:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-19 01:02:13 +03:00
|
|
|
NS_IMETHODIMP
|
2019-05-21 20:34:14 +03:00
|
|
|
RasterImage::RequestDecodeForSize(const IntSize& aSize, uint32_t aFlags,
|
|
|
|
uint32_t aWhichFrame) {
|
2015-01-19 01:02:13 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mError) {
|
2015-01-12 12:20:23 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
2015-01-19 01:02:13 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
RequestDecodeForSizeInternal(OrientedIntSize::FromUnknownSize(aSize), aFlags,
|
|
|
|
aWhichFrame);
|
2016-12-23 10:07:45 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
LookupResult RasterImage::RequestDecodeForSizeInternal(
|
2021-10-06 17:41:17 +03:00
|
|
|
const OrientedIntSize& aSize, uint32_t aFlags, uint32_t aWhichFrame) {
|
2016-12-23 10:07:45 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2019-05-21 20:34:14 +03:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
2020-04-21 00:04:45 +03:00
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2019-05-21 20:34:14 +03:00
|
|
|
}
|
|
|
|
|
2016-12-23 10:07:45 +03:00
|
|
|
if (mError) {
|
2020-04-21 00:04:45 +03:00
|
|
|
LookupResult result = LookupResult(MatchType::NOT_FOUND);
|
|
|
|
result.SetFailedToRequestDecode();
|
|
|
|
return result;
|
2016-12-23 10:07:45 +03:00
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize()) {
|
|
|
|
StoreWantFullDecode(true);
|
2020-04-21 00:04:45 +03:00
|
|
|
return LookupResult(MatchType::NOT_FOUND);
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-02-03 08:40:35 +03:00
|
|
|
// 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 =
|
2020-12-09 21:14:55 +03:00
|
|
|
!LoadHasBeenDecoded() && (aFlags & FLAG_SYNC_DECODE_IF_FAST);
|
2015-02-03 08:40:35 +03:00
|
|
|
|
|
|
|
uint32_t flags =
|
|
|
|
shouldSyncDecodeIfFast ? aFlags : aFlags & ~FLAG_SYNC_DECODE_IF_FAST;
|
2015-01-19 01:02:13 +03:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
// Perform a frame lookup, which will implicitly start decoding if needed.
|
2020-04-21 00:04:45 +03:00
|
|
|
return LookupFrame(aSize, flags, ToPlaybackType(aWhichFrame),
|
|
|
|
/* aMarkUsed = */ false);
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 23:43:19 +03:00
|
|
|
static bool LaunchDecodingTask(IDecodingTask* aTask, RasterImage* aImage,
|
|
|
|
uint32_t aFlags, bool aHaveSourceData) {
|
2015-07-23 08:39:51 +03:00
|
|
|
if (aHaveSourceData) {
|
2017-03-23 02:37:33 +03:00
|
|
|
nsCString uri(aImage->GetURIString());
|
|
|
|
|
2015-07-23 08:39:51 +03:00
|
|
|
// If we have all the data, we can sync decode if requested.
|
|
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
DecodePool::Singleton()->SyncRunIfPossible(aTask, uri);
|
2016-12-22 22:15:41 +03:00
|
|
|
return true;
|
2015-07-23 08:39:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlags & imgIContainer::FLAG_SYNC_DECODE_IF_FAST) {
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
return DecodePool::Singleton()->SyncRunIfPreferred(aTask, uri);
|
2015-07-23 08:39:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2016-06-29 23:43:19 +03:00
|
|
|
DecodePool::Singleton()->AsyncRun(aTask);
|
2016-12-22 22:15:41 +03:00
|
|
|
return false;
|
2015-07-23 08:39:51 +03:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
void RasterImage::Decode(const OrientedIntSize& aSize, uint32_t aFlags,
|
2020-04-21 00:04:45 +03:00
|
|
|
PlaybackType aPlaybackType, bool& aOutRanSync,
|
|
|
|
bool& aOutFailed) {
|
2015-07-23 08:39:51 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mError) {
|
2020-04-21 00:04:45 +03:00
|
|
|
aOutFailed = true;
|
|
|
|
return;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// If we don't have a size yet, we can't do any other decoding.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize()) {
|
|
|
|
StoreWantFullDecode(true);
|
2020-04-21 00:04:45 +03:00
|
|
|
return;
|
2015-01-12 21:17:52 +03:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:21:05 +03:00
|
|
|
// 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.
|
2016-07-02 08:33:58 +03:00
|
|
|
SurfaceCache::UnlockEntries(ImageKey(this));
|
2015-07-23 08:39:51 +03:00
|
|
|
|
2015-08-15 03:56:44 +03:00
|
|
|
// Determine which flags we need to decode this image with.
|
|
|
|
DecoderFlags decoderFlags = DefaultDecoderFlags();
|
|
|
|
if (aFlags & FLAG_ASYNC_NOTIFY) {
|
|
|
|
decoderFlags |= DecoderFlags::ASYNC_NOTIFY;
|
|
|
|
}
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadTransient()) {
|
2015-08-15 03:56:44 +03:00
|
|
|
decoderFlags |= DecoderFlags::IMAGE_IS_TRANSIENT;
|
|
|
|
}
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadHasBeenDecoded()) {
|
2015-08-15 03:56:44 +03:00
|
|
|
decoderFlags |= DecoderFlags::IS_REDECODE;
|
|
|
|
}
|
2017-09-05 14:58:45 +03:00
|
|
|
if ((aFlags & FLAG_SYNC_DECODE) || !(aFlags & FLAG_HIGH_QUALITY_SCALING)) {
|
|
|
|
// Used SurfaceCache::Lookup instead of SurfaceCache::LookupBestMatch. That
|
|
|
|
// means the caller can handle a differently sized surface to be returned
|
|
|
|
// at any point.
|
|
|
|
decoderFlags |= DecoderFlags::CANNOT_SUBSTITUTE;
|
|
|
|
}
|
2015-08-15 03:56:44 +03:00
|
|
|
|
2015-10-06 03:06:34 +03:00
|
|
|
SurfaceFlags surfaceFlags = ToSurfaceFlags(aFlags);
|
|
|
|
if (IsOpaque()) {
|
|
|
|
// If there's no transparency, it doesn't matter whether we premultiply
|
|
|
|
// alpha or not.
|
|
|
|
surfaceFlags &= ~SurfaceFlags::NO_PREMULTIPLY_ALPHA;
|
|
|
|
}
|
|
|
|
|
2015-03-17 23:56:49 +03:00
|
|
|
// Create a decoder.
|
2016-06-26 10:09:24 +03:00
|
|
|
RefPtr<IDecodingTask> task;
|
2018-02-09 16:51:28 +03:00
|
|
|
nsresult rv;
|
|
|
|
bool animated = mAnimationState && aPlaybackType == PlaybackType::eAnimated;
|
|
|
|
if (animated) {
|
2018-02-28 21:34:52 +03:00
|
|
|
size_t currentFrame = mAnimationState->GetCurrentAnimationFrameIndex();
|
2018-02-09 16:51:28 +03:00
|
|
|
rv = DecoderFactory::CreateAnimationDecoder(
|
2021-10-06 17:41:17 +03:00
|
|
|
mDecoderType, WrapNotNull(this), mSourceBuffer, mSize.ToUnknownSize(),
|
|
|
|
decoderFlags, surfaceFlags, currentFrame, getter_AddRefs(task));
|
2018-02-09 16:51:28 +03:00
|
|
|
} else {
|
2021-10-06 17:41:17 +03:00
|
|
|
rv = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
|
|
|
|
mSourceBuffer, mSize.ToUnknownSize(),
|
|
|
|
aSize.ToUnknownSize(), decoderFlags,
|
|
|
|
surfaceFlags, getter_AddRefs(task));
|
2018-02-09 16:51:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rv == NS_ERROR_ALREADY_INITIALIZED) {
|
|
|
|
// We raced with an already pending decoder, and it finished before we
|
|
|
|
// managed to insert the new decoder. Pretend we did a sync call to make
|
|
|
|
// the caller lookup in the surface cache again.
|
|
|
|
MOZ_ASSERT(!task);
|
2020-04-21 00:04:45 +03:00
|
|
|
aOutRanSync = true;
|
|
|
|
return;
|
2018-02-09 16:51:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (animated) {
|
2017-06-01 10:19:55 +03:00
|
|
|
// We pass false for aAllowInvalidation because we may be asked to use
|
|
|
|
// async notifications. Any potential invalidation here will be sent when
|
|
|
|
// RequestRefresh is called, or NotifyDecodeComplete.
|
2017-05-04 05:20:35 +03:00
|
|
|
#ifdef DEBUG
|
2020-04-17 05:57:30 +03:00
|
|
|
IntRect rect =
|
2017-05-04 05:20:35 +03:00
|
|
|
#endif
|
2021-10-06 17:41:17 +03:00
|
|
|
mAnimationState->UpdateState(this, mSize.ToUnknownSize(), false);
|
2017-05-04 05:20:35 +03:00
|
|
|
MOZ_ASSERT(rect.IsEmpty());
|
2015-08-14 10:37:13 +03:00
|
|
|
}
|
2015-07-23 08:39:51 +03:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2018-02-09 16:51:28 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
MOZ_ASSERT(!task);
|
2020-04-21 00:04:45 +03:00
|
|
|
aOutFailed = true;
|
|
|
|
return;
|
2015-03-17 23:56:49 +03:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:51:28 +03:00
|
|
|
MOZ_ASSERT(task);
|
2015-07-23 08:39:51 +03:00
|
|
|
mDecodeCount++;
|
2015-01-12 21:17:52 +03:00
|
|
|
|
2015-07-23 08:39:51 +03:00
|
|
|
// We're ready to decode; start the decoder.
|
2020-12-09 21:14:55 +03:00
|
|
|
aOutRanSync = LaunchDecodingTask(task, this, aFlags, LoadAllSourceData());
|
2015-07-23 08:39:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::DecodeMetadata(uint32_t aFlags) {
|
|
|
|
if (mError) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
MOZ_ASSERT(!LoadHasSize(), "Should not do unnecessary metadata decodes");
|
2015-07-23 08:39:51 +03:00
|
|
|
|
|
|
|
// Create a decoder.
|
2016-06-27 07:50:43 +03:00
|
|
|
RefPtr<IDecodingTask> task = DecoderFactory::CreateMetadataDecoder(
|
|
|
|
mDecoderType, WrapNotNull(this), mSourceBuffer);
|
2015-07-23 08:39:51 +03:00
|
|
|
|
|
|
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
2016-06-26 10:09:24 +03:00
|
|
|
if (!task) {
|
2015-07-23 08:39:51 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're ready to decode; start the decoder.
|
2020-12-09 21:14:55 +03:00
|
|
|
LaunchDecodingTask(task, this, aFlags, LoadAllSourceData());
|
2015-01-16 02:11:36 +03:00
|
|
|
return NS_OK;
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
void RasterImage::RecoverFromInvalidFrames(const OrientedIntSize& aSize,
|
2015-08-18 20:19:14 +03:00
|
|
|
uint32_t aFlags) {
|
2020-12-09 21:14:55 +03:00
|
|
|
if (!LoadHasSize()) {
|
2015-02-04 03:38:36 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-18 20:19:14 +03:00
|
|
|
NS_WARNING("A RasterImage's frames became invalid. Attempting to recover...");
|
2015-02-04 03:38:36 +03:00
|
|
|
|
|
|
|
// Discard all existing frames, since they're probably all now invalid.
|
|
|
|
SurfaceCache::RemoveImage(ImageKey(this));
|
|
|
|
|
2015-08-14 06:39:54 +03:00
|
|
|
// Relock the image if it's supposed to be locked.
|
|
|
|
if (mLockCount > 0) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2020-04-21 00:04:45 +03:00
|
|
|
bool unused1, unused2;
|
|
|
|
|
2015-02-04 03:38:36 +03:00
|
|
|
// Animated images require some special handling, because we normally require
|
|
|
|
// that they never be discarded.
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
2021-10-06 17:41:17 +03:00
|
|
|
Decode(mSize, aFlags | FLAG_SYNC_DECODE, PlaybackType::eAnimated, unused1,
|
|
|
|
unused2);
|
2015-02-04 03:38:36 +03:00
|
|
|
ResetAnimation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For non-animated images, it's fine to recover using an async decode.
|
2020-04-21 00:04:45 +03:00
|
|
|
Decode(aSize, aFlags, PlaybackType::eStatic, unused1, unused2);
|
2015-02-04 03:38:36 +03:00
|
|
|
}
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
bool RasterImage::CanDownscaleDuringDecode(const OrientedIntSize& aSize,
|
2015-04-21 18:04:57 +03:00
|
|
|
uint32_t aFlags) {
|
2015-09-20 02:21:05 +03:00
|
|
|
// 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.
|
2021-07-30 02:29:43 +03:00
|
|
|
if (!LoadHasSize() || LoadTransient() ||
|
2019-06-26 06:24:21 +03:00
|
|
|
!StaticPrefs::image_downscale_during_decode_enabled() ||
|
2015-01-19 01:02:14 +03:00
|
|
|
!(aFlags & imgIContainer::FLAG_HIGH_QUALITY_SCALING)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't downscale animated images during decode.
|
2016-07-19 09:26:58 +03:00
|
|
|
if (mAnimationState) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Never upscale.
|
2021-10-06 17:41:17 +03:00
|
|
|
if (aSize.width >= mSize.width || aSize.height >= mSize.height) {
|
2015-01-19 01:02:14 +03:00
|
|
|
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.
|
2020-04-17 05:57:30 +03:00
|
|
|
if (!SurfaceCache::CanHold(aSize.ToUnknownSize())) {
|
2015-01-19 01:02:14 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-18 03:50:31 +03:00
|
|
|
ImgDrawResult RasterImage::DrawInternal(DrawableSurface&& aSurface,
|
2015-09-20 02:20:56 +03:00
|
|
|
gfxContext* aContext,
|
2021-10-06 17:41:17 +03:00
|
|
|
const OrientedIntSize& aSize,
|
2015-09-20 02:20:56 +03:00
|
|
|
const ImageRegion& aRegion,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags, float aOpacity) {
|
2014-09-13 05:29:27 +04:00
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion region(aRegion);
|
2016-08-18 03:50:31 +03:00
|
|
|
bool frameIsFinished = aSurface->IsFinished();
|
2014-08-23 00:12:38 +04:00
|
|
|
|
2021-04-14 12:00:13 +03:00
|
|
|
AutoProfilerImagePaintMarker PROFILER_RAII(this);
|
2017-06-15 01:11:48 +03:00
|
|
|
#ifdef DEBUG
|
2017-08-02 01:08:02 +03:00
|
|
|
NotifyDrawingObservers();
|
2017-06-15 01:11:48 +03:00
|
|
|
#endif
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
// By now we may have a frame with the requested size. If not, we need to
|
|
|
|
// adjust the drawing parameters accordingly.
|
2019-03-15 20:29:02 +03:00
|
|
|
IntSize finalSize = aSurface->GetSize();
|
2015-02-05 00:50:56 +03:00
|
|
|
bool couldRedecodeForBetterFrame = false;
|
2020-04-17 05:57:30 +03:00
|
|
|
if (finalSize != aSize.ToUnknownSize()) {
|
2014-11-27 00:22:10 +03:00
|
|
|
gfx::Size scale(double(aSize.width) / finalSize.width,
|
|
|
|
double(aSize.height) / finalSize.height);
|
2014-08-23 00:12:38 +04:00
|
|
|
aContext->Multiply(gfxMatrix::Scaling(scale.width, scale.height));
|
|
|
|
region.Scale(1.0 / scale.width, 1.0 / scale.height);
|
2015-02-05 00:50:56 +03:00
|
|
|
|
2015-09-20 02:21:05 +03:00
|
|
|
couldRedecodeForBetterFrame = CanDownscaleDuringDecode(aSize, aFlags);
|
2014-08-23 00:12:38 +04:00
|
|
|
}
|
|
|
|
|
2017-01-03 08:53:22 +03:00
|
|
|
if (!aSurface->Draw(aContext, region, aSamplingFilter, aFlags, aOpacity)) {
|
2015-08-18 20:19:14 +03:00
|
|
|
RecoverFromInvalidFrames(aSize, aFlags);
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::TEMPORARY_ERROR;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2016-03-24 03:31:42 +03:00
|
|
|
if (!frameIsFinished) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::INCOMPLETE;
|
2015-02-04 03:38:36 +03:00
|
|
|
}
|
2015-02-05 00:50:56 +03:00
|
|
|
if (couldRedecodeForBetterFrame) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::WRONG_SIZE;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::SUCCESS;
|
2012-04-04 01:57:22 +04:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2014-08-23 00:12:38 +04:00
|
|
|
RasterImage::Draw(gfxContext* aContext, const IntSize& aSize,
|
|
|
|
const ImageRegion& aRegion, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2014-08-23 00:12:38 +04:00
|
|
|
const Maybe<SVGImageContext>& /*aSVGContext - ignored*/,
|
2017-01-03 08:53:22 +03:00
|
|
|
uint32_t aFlags, float aOpacity) {
|
2015-03-31 20:49:00 +03:00
|
|
|
if (aWhichFrame > FRAME_MAX_VALUE) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2013-03-11 05:43:37 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_IMAGE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2011-01-13 04:45:13 +03:00
|
|
|
// Illegal -- you can't draw with non-default decode flags.
|
|
|
|
// (Disabling colorspace conversion might make sense to allow, but
|
|
|
|
// we don't currently.)
|
2015-08-15 03:56:44 +03:00
|
|
|
if (ToSurfaceFlags(aFlags) != DefaultSurfaceFlags()) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2011-01-13 04:45:13 +03:00
|
|
|
|
2015-02-05 00:50:56 +03:00
|
|
|
if (!aContext) {
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::BAD_ARGS;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2017-06-30 04:09:44 +03:00
|
|
|
if (mAnimationConsumers == 0) {
|
2016-11-17 09:25:53 +03:00
|
|
|
SendOnUnlockedDraw(aFlags);
|
2013-02-25 04:59:22 +04:00
|
|
|
}
|
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
// If we're not using SamplingFilter::GOOD, we shouldn't high-quality scale or
|
2015-10-06 03:12:46 +03:00
|
|
|
// downscale during decode.
|
2016-05-25 19:01:18 +03:00
|
|
|
uint32_t flags = aSamplingFilter == SamplingFilter::GOOD
|
2015-01-19 01:02:14 +03:00
|
|
|
? aFlags
|
|
|
|
: aFlags & ~FLAG_HIGH_QUALITY_SCALING;
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
auto size = OrientedIntSize::FromUnknownSize(aSize);
|
2020-04-17 05:57:30 +03:00
|
|
|
LookupResult result = LookupFrame(size, flags, ToPlaybackType(aWhichFrame),
|
2018-10-13 08:31:03 +03:00
|
|
|
/* aMarkUsed = */ true);
|
2017-11-17 14:45:27 +03:00
|
|
|
if (!result) {
|
2014-11-27 00:22:10 +03:00
|
|
|
// Getting the frame (above) touches the image and kicks off decoding.
|
2015-01-16 02:11:36 +03:00
|
|
|
if (mDrawStartTime.IsNull()) {
|
|
|
|
mDrawStartTime = TimeStamp::Now();
|
|
|
|
}
|
2017-12-11 18:37:59 +03:00
|
|
|
return ImgDrawResult::NOT_READY;
|
2009-09-13 02:44:18 +04:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
bool shouldRecordTelemetry =
|
2017-11-17 14:45:27 +03:00
|
|
|
!mDrawStartTime.IsNull() && result.Surface()->IsFinished();
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
ImgDrawResult drawResult =
|
|
|
|
DrawInternal(std::move(result.Surface()), aContext, size, aRegion,
|
|
|
|
aSamplingFilter, flags, aOpacity);
|
2014-02-25 07:37:51 +04:00
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
if (shouldRecordTelemetry) {
|
2011-08-11 03:12:08 +04:00
|
|
|
TimeDuration drawLatency = TimeStamp::Now() - mDrawStartTime;
|
2015-01-16 02:11:36 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_ON_DRAW_LATENCY,
|
|
|
|
int32_t(drawLatency.ToMicroseconds()));
|
2011-08-11 03:12:08 +04:00
|
|
|
mDrawStartTime = TimeStamp();
|
|
|
|
}
|
2012-04-04 01:57:22 +04:00
|
|
|
|
2017-11-17 14:45:27 +03:00
|
|
|
return drawResult;
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::LockImage() {
|
2013-09-28 22:28:43 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with UnlockImage");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Increment the lock count
|
|
|
|
mLockCount++;
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Lock this image's surfaces in the SurfaceCache.
|
|
|
|
if (mLockCount == 1) {
|
|
|
|
SurfaceCache::LockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-09-13 02:44:18 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-14 08:09:49 +04:00
|
|
|
RasterImage::UnlockImage() {
|
2013-09-28 22:28:43 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(),
|
|
|
|
"Main thread to encourage serialization with LockImage");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// It's an error to call this function if the lock count is 0
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mLockCount > 0, "Calling UnlockImage with mLockCount == 0!");
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mLockCount == 0) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return NS_ERROR_ABORT;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
|
|
|
// Decrement our lock count
|
|
|
|
mLockCount--;
|
|
|
|
|
2014-11-27 00:22:10 +03:00
|
|
|
// Unlock this image's surfaces in the SurfaceCache.
|
2015-01-07 12:40:23 +03:00
|
|
|
if (mLockCount == 0) {
|
2014-11-27 00:22:10 +03:00
|
|
|
SurfaceCache::UnlockImage(ImageKey(this));
|
|
|
|
}
|
|
|
|
|
2007-10-19 04:36:34 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
//******************************************************************************
|
2015-08-05 02:17:36 +03:00
|
|
|
|
2012-03-10 10:29:28 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::RequestDiscard() {
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadDiscardable() && // Enabled at creation time...
|
|
|
|
mLockCount == 0 && // ...not temporarily disabled...
|
2014-11-28 06:56:00 +03:00
|
|
|
CanDiscard()) {
|
2014-11-28 06:55:57 +03:00
|
|
|
Discard();
|
2012-03-10 10:29:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-09-12 12:00:52 +03:00
|
|
|
// Idempotent error flagging routine. If a decoder is open, shuts it down.
|
2010-08-14 08:09:49 +04:00
|
|
|
void RasterImage::DoError() {
|
2009-09-13 02:44:18 +04:00
|
|
|
// If we've flagged an error before, we have nothing to do
|
2015-03-31 20:49:00 +03:00
|
|
|
if (mError) {
|
2009-09-13 02:44:18 +04:00
|
|
|
return;
|
2015-03-31 20:49:00 +03:00
|
|
|
}
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-03-31 20:49:00 +03:00
|
|
|
// We can't safely handle errors off-main-thread, so dispatch a worker to
|
|
|
|
// do it.
|
2013-09-13 01:40:16 +04:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
HandleErrorWorker::DispatchIfNeeded(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put the container in an error state.
|
2011-10-17 18:59:28 +04:00
|
|
|
mError = true;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-05-07 19:25:12 +03:00
|
|
|
// Stop animation and release our FrameAnimator.
|
|
|
|
if (mAnimating) {
|
|
|
|
StopAnimation();
|
|
|
|
}
|
2016-07-19 09:26:58 +03:00
|
|
|
mAnimationState = Nothing();
|
|
|
|
mFrameAnimator = nullptr;
|
2015-05-07 19:25:12 +03:00
|
|
|
|
|
|
|
// 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.
|
2021-10-06 17:41:17 +03:00
|
|
|
auto dirtyRect = OrientedIntRect({0, 0}, mSize);
|
2020-04-17 05:57:30 +03:00
|
|
|
NotifyProgress(NoProgress, dirtyRect);
|
2015-05-07 19:25:12 +03:00
|
|
|
|
2015-11-16 20:21:00 +03:00
|
|
|
MOZ_LOG(gImgLog, LogLevel::Error,
|
2015-07-21 19:42:27 +03:00
|
|
|
("RasterImage: [this=%p] Error detected for image\n", this));
|
2007-10-19 04:36:34 +04:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:58 +03:00
|
|
|
/* static */
|
|
|
|
void RasterImage::HandleErrorWorker::DispatchIfNeeded(RasterImage* aImage) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HandleErrorWorker> worker = new HandleErrorWorker(aImage);
|
2015-01-16 02:11:36 +03:00
|
|
|
NS_DispatchToMainThread(worker);
|
2013-09-13 01:40:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RasterImage::HandleErrorWorker::HandleErrorWorker(RasterImage* aImage)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("image::RasterImage::HandleErrorWorker"), mImage(aImage) {
|
2013-09-13 01:40:16 +04:00
|
|
|
MOZ_ASSERT(mImage, "Should have image");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RasterImage::HandleErrorWorker::Run() {
|
|
|
|
mImage->DoError();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
bool RasterImage::ShouldAnimate() {
|
2016-07-28 03:12:25 +03:00
|
|
|
return ImageResource::ShouldAnimate() && mAnimationState &&
|
2020-12-09 21:14:55 +03:00
|
|
|
mAnimationState->KnownFrameCount() >= 1 && !LoadAnimationFinished();
|
2010-09-08 04:33:02 +04:00
|
|
|
}
|
|
|
|
|
2010-09-08 04:34:18 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
2015-03-31 20:49:00 +03:00
|
|
|
RasterImage::GetFramesNotified(uint32_t* aFramesNotified) {
|
2010-09-08 04:34:18 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aFramesNotified);
|
|
|
|
|
|
|
|
*aFramesNotified = mFramesNotified;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
void RasterImage::NotifyProgress(
|
2020-04-17 05:57:30 +03:00
|
|
|
Progress aProgress,
|
2021-10-06 17:41:17 +03:00
|
|
|
const OrientedIntRect& aInvalidRect /* = OrientedIntRect() */,
|
2016-07-28 03:12:25 +03:00
|
|
|
const Maybe<uint32_t>& aFrameCount /* = Nothing() */,
|
2020-04-17 05:57:30 +03:00
|
|
|
DecoderFlags aDecoderFlags /* = DefaultDecoderFlags() */,
|
|
|
|
SurfaceFlags aSurfaceFlags /* = DefaultSurfaceFlags() */) {
|
2015-01-12 21:17:52 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Ensure that we stay alive long enough to finish notifying.
|
2016-07-28 00:04:21 +03:00
|
|
|
RefPtr<RasterImage> image = this;
|
2013-01-19 01:47:18 +04:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
OrientedIntRect invalidRect = aInvalidRect;
|
2014-11-10 23:37:35 +03:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) {
|
|
|
|
// We may have decoded new animation frames; update our animation state.
|
|
|
|
MOZ_ASSERT_IF(aFrameCount && *aFrameCount > 1, mAnimationState || mError);
|
|
|
|
if (mAnimationState && aFrameCount) {
|
|
|
|
mAnimationState->UpdateKnownFrameCount(*aFrameCount);
|
|
|
|
}
|
2016-07-28 03:12:25 +03:00
|
|
|
|
2016-08-18 10:06:41 +03:00
|
|
|
// If we should start animating right now, do so.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (mAnimationState && aFrameCount == Some(1u) && LoadPendingAnimation() &&
|
2016-08-18 10:06:41 +03:00
|
|
|
ShouldAnimate()) {
|
|
|
|
StartAnimation();
|
|
|
|
}
|
2020-05-04 21:49:13 +03:00
|
|
|
|
|
|
|
if (mAnimationState) {
|
2021-10-06 17:41:17 +03:00
|
|
|
IntRect rect = mAnimationState->UpdateState(this, mSize.ToUnknownSize());
|
2020-05-04 21:49:13 +03:00
|
|
|
|
|
|
|
invalidRect.UnionRect(invalidRect,
|
2021-10-06 17:41:17 +03:00
|
|
|
OrientedIntRect::FromUnknownRect(rect));
|
2020-05-04 21:49:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-29 00:36:30 +03:00
|
|
|
const bool wasDefaultFlags = aSurfaceFlags == DefaultSurfaceFlags();
|
|
|
|
|
|
|
|
if (!invalidRect.IsEmpty() && wasDefaultFlags) {
|
|
|
|
// Update our image container since we're invalidating.
|
|
|
|
UpdateImageContainer(Some(invalidRect.ToUnknownRect()));
|
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Tell the observers what happened.
|
2021-10-06 17:41:17 +03:00
|
|
|
image->mProgressTracker->SyncNotifyProgress(aProgress,
|
|
|
|
invalidRect.ToUnknownRect());
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
2013-02-02 05:06:34 +04:00
|
|
|
|
2016-08-03 03:22:41 +03:00
|
|
|
void RasterImage::NotifyDecodeComplete(
|
|
|
|
const DecoderFinalStatus& aStatus, const ImageMetadata& aMetadata,
|
|
|
|
const DecoderTelemetry& aTelemetry, Progress aProgress,
|
2021-10-06 17:41:17 +03:00
|
|
|
const OrientedIntRect& aInvalidRect, const Maybe<uint32_t>& aFrameCount,
|
2016-08-03 03:22:41 +03:00
|
|
|
DecoderFlags aDecoderFlags, SurfaceFlags aSurfaceFlags) {
|
2015-01-16 02:11:36 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-31 17:29:15 +03:00
|
|
|
|
|
|
|
// If the decoder detected an error, log it to the error console.
|
2016-09-21 14:13:08 +03:00
|
|
|
if (aStatus.mShouldReportError) {
|
2016-08-03 03:22:41 +03:00
|
|
|
ReportDecoderError();
|
2015-07-31 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Record all the metadata the decoder gathered about this image.
|
2016-08-03 03:12:36 +03:00
|
|
|
bool metadataOK = SetMetadata(aMetadata, aStatus.mWasMetadataDecode);
|
2015-09-24 02:53:40 +03:00
|
|
|
if (!metadataOK) {
|
|
|
|
// This indicates a serious error that requires us to discard all existing
|
|
|
|
// surfaces and redecode to recover. We'll drop the results from this
|
|
|
|
// decoder on the floor, since they aren't valid.
|
2021-10-06 17:41:17 +03:00
|
|
|
RecoverFromInvalidFrames(mSize, FromSurfaceFlags(aSurfaceFlags));
|
2015-09-24 02:53:40 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
MOZ_ASSERT(mError || LoadHasSize() || !aMetadata.HasSize(),
|
2015-08-18 20:19:22 +03:00
|
|
|
"SetMetadata should've gotten a size");
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-21 14:13:08 +03:00
|
|
|
if (!aStatus.mWasMetadataDecode && aStatus.mFinished) {
|
2015-07-31 17:29:15 +03:00
|
|
|
// Flag that we've been decoded before.
|
2020-12-09 21:14:55 +03:00
|
|
|
StoreHasBeenDecoded(true);
|
2015-07-31 17:29:15 +03:00
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:36 +03:00
|
|
|
// Send out any final notifications.
|
2016-08-18 10:06:41 +03:00
|
|
|
NotifyProgress(aProgress, aInvalidRect, aFrameCount, aDecoderFlags,
|
|
|
|
aSurfaceFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-05-04 21:46:53 +03:00
|
|
|
if (!(aDecoderFlags & DecoderFlags::FIRST_FRAME_ONLY)) {
|
|
|
|
// We may have decoded new animation frames; update our animation state.
|
|
|
|
MOZ_ASSERT_IF(aFrameCount && *aFrameCount > 1, mAnimationState || mError);
|
|
|
|
if (mAnimationState && aFrameCount) {
|
|
|
|
mAnimationState->UpdateKnownFrameCount(*aFrameCount);
|
|
|
|
}
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2020-05-04 21:46:53 +03:00
|
|
|
// If we should start animating right now, do so.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (mAnimationState && aFrameCount == Some(1u) && LoadPendingAnimation() &&
|
2020-05-04 21:46:53 +03:00
|
|
|
ShouldAnimate()) {
|
|
|
|
StartAnimation();
|
|
|
|
}
|
|
|
|
|
2020-12-09 21:14:55 +03:00
|
|
|
if (mAnimationState && LoadHasBeenDecoded()) {
|
2020-05-04 21:46:53 +03:00
|
|
|
// We've finished a full decode of all animation frames and our
|
|
|
|
// AnimationState has been notified about them all, so let it know not to
|
|
|
|
// expect anymore.
|
|
|
|
mAnimationState->NotifyDecodeComplete();
|
2020-04-17 05:57:30 +03:00
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
IntRect rect = mAnimationState->UpdateState(this, mSize.ToUnknownSize());
|
2020-05-04 21:46:53 +03:00
|
|
|
|
|
|
|
if (!rect.IsEmpty()) {
|
2021-10-06 17:41:17 +03:00
|
|
|
auto dirtyRect = OrientedIntRect::FromUnknownRect(rect);
|
2020-05-04 21:46:53 +03:00
|
|
|
NotifyProgress(NoProgress, dirtyRect);
|
|
|
|
}
|
2017-04-06 12:00:36 +03:00
|
|
|
}
|
2016-07-28 03:12:25 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
// Do some telemetry if this isn't a metadata decode.
|
|
|
|
if (!aStatus.mWasMetadataDecode) {
|
|
|
|
if (aTelemetry.mChunkCount) {
|
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_CHUNKS,
|
|
|
|
aTelemetry.mChunkCount);
|
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
if (aStatus.mFinished) {
|
2015-01-16 02:11:36 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IMAGE_DECODE_TIME,
|
2016-08-03 02:34:23 +03:00
|
|
|
int32_t(aTelemetry.mDecodeTime.ToMicroseconds()));
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2018-07-04 15:50:02 +03:00
|
|
|
if (aTelemetry.mSpeedHistogram && aTelemetry.mBytesDecoded) {
|
2016-08-03 02:45:22 +03:00
|
|
|
Telemetry::Accumulate(*aTelemetry.mSpeedHistogram, aTelemetry.Speed());
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-26 21:18:37 +03:00
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
// Only act on errors if we have no usable frames from the decoder.
|
|
|
|
if (aStatus.mHadError &&
|
|
|
|
(!mAnimationState || mAnimationState->KnownFrameCount() == 0)) {
|
|
|
|
DoError();
|
2020-12-09 21:14:55 +03:00
|
|
|
} else if (aStatus.mWasMetadataDecode && !LoadHasSize()) {
|
2016-09-26 21:18:37 +03:00
|
|
|
DoError();
|
|
|
|
}
|
2015-06-30 12:37:58 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
// XXX(aosmond): Can we get this far without mFinished == true?
|
|
|
|
if (aStatus.mFinished && aStatus.mWasMetadataDecode) {
|
2015-06-30 12:37:58 +03:00
|
|
|
// If we were waiting to fire the load event, go ahead and fire it now.
|
2016-09-26 21:18:37 +03:00
|
|
|
if (mLoadProgress) {
|
2015-06-30 12:37:58 +03:00
|
|
|
NotifyForLoadEvent(*mLoadProgress);
|
|
|
|
mLoadProgress = Nothing();
|
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
|
2016-09-26 21:18:37 +03:00
|
|
|
// If we were a metadata decode and a full decode was requested, do it.
|
2020-12-09 21:14:55 +03:00
|
|
|
if (LoadWantFullDecode()) {
|
|
|
|
StoreWantFullDecode(false);
|
2021-10-06 17:41:17 +03:00
|
|
|
RequestDecodeForSizeInternal(
|
|
|
|
mSize, DECODE_FLAGS_DEFAULT | FLAG_HIGH_QUALITY_SCALING,
|
|
|
|
FRAME_CURRENT);
|
2016-09-26 21:18:37 +03:00
|
|
|
}
|
2015-01-16 02:11:36 +03:00
|
|
|
}
|
2013-01-19 01:47:18 +04:00
|
|
|
}
|
|
|
|
|
2016-08-03 03:22:41 +03:00
|
|
|
void RasterImage::ReportDecoderError() {
|
2015-07-31 17:29:15 +03:00
|
|
|
nsCOMPtr<nsIConsoleService> consoleService =
|
|
|
|
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIScriptError> errorObject =
|
|
|
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID);
|
|
|
|
|
2016-07-11 10:34:50 +03:00
|
|
|
if (consoleService && errorObject) {
|
2015-07-31 17:29:15 +03:00
|
|
|
nsAutoString msg(u"Image corrupt or truncated."_ns);
|
|
|
|
nsAutoString src;
|
|
|
|
if (GetURI()) {
|
2018-06-06 03:42:56 +03:00
|
|
|
nsAutoCString uri;
|
|
|
|
if (!GetSpecTruncatedTo1k(uri)) {
|
2015-07-31 17:29:15 +03:00
|
|
|
msg += u" URI in this note truncated due to length."_ns;
|
|
|
|
}
|
2020-09-02 12:54:37 +03:00
|
|
|
CopyUTF8toUTF16(uri, src);
|
2015-07-31 17:29:15 +03:00
|
|
|
}
|
2020-09-23 18:17:15 +03:00
|
|
|
if (NS_SUCCEEDED(errorObject->InitWithWindowID(msg, src, u""_ns, 0, 0,
|
|
|
|
nsIScriptError::errorFlag,
|
2015-07-31 17:29:15 +03:00
|
|
|
"Image", InnerWindowID()))) {
|
|
|
|
consoleService->LogMessage(errorObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 07:50:26 +04:00
|
|
|
already_AddRefed<imgIContainer> RasterImage::Unwrap() {
|
|
|
|
nsCOMPtr<imgIContainer> self(this);
|
|
|
|
return self.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void RasterImage::PropagateUseCounters(dom::Document*) {
|
2015-06-03 20:42:07 +03:00
|
|
|
// No use counters.
|
|
|
|
}
|
|
|
|
|
2014-07-29 01:27:39 +04:00
|
|
|
IntSize RasterImage::OptimalImageSizeForDest(const gfxSize& aDest,
|
|
|
|
uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
|
|
|
uint32_t aFlags) {
|
2014-07-29 01:27:39 +04:00
|
|
|
MOZ_ASSERT(aDest.width >= 0 || ceil(aDest.width) <= INT32_MAX ||
|
|
|
|
aDest.height >= 0 || ceil(aDest.height) <= INT32_MAX,
|
|
|
|
"Unexpected destination size");
|
|
|
|
|
2014-09-17 03:18:49 +04:00
|
|
|
if (mSize.IsEmpty() || aDest.IsEmpty()) {
|
2015-04-21 18:04:57 +03:00
|
|
|
return IntSize(0, 0);
|
2014-07-29 01:27:39 +04:00
|
|
|
}
|
|
|
|
|
2020-04-17 05:57:30 +03:00
|
|
|
auto dest = OrientedIntSize::FromUnknownSize(
|
|
|
|
IntSize::Ceil(aDest.width, aDest.height));
|
2014-07-29 01:27:39 +04:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
if (aSamplingFilter == SamplingFilter::GOOD &&
|
2021-10-06 17:41:17 +03:00
|
|
|
CanDownscaleDuringDecode(dest, aFlags)) {
|
2020-04-17 05:57:30 +03:00
|
|
|
return dest.ToUnknownSize();
|
2014-07-29 01:27:39 +04:00
|
|
|
}
|
|
|
|
|
2015-09-20 02:20:56 +03:00
|
|
|
// We can't scale to this size. Use our intrinsic size for now.
|
2020-04-17 05:57:30 +03:00
|
|
|
return mSize.ToUnknownSize();
|
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:49 +04:00
|
|
|
} // namespace mozilla
|