2013-04-06 01:14:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-06-30 20:27:03 +03:00
|
|
|
#include "ClippedImage.h"
|
|
|
|
|
2016-07-01 03:27:00 +03:00
|
|
|
#include <algorithm>
|
2014-07-29 01:27:40 +04:00
|
|
|
#include <cmath>
|
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 <new> // Workaround for bug in VS10; see bug 981264.
|
2014-08-23 00:12:38 +04:00
|
|
|
#include <utility>
|
2014-07-29 01:27:40 +04:00
|
|
|
|
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 "ImageRegion.h"
|
|
|
|
#include "Orientation.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "gfxContext.h"
|
2013-04-06 01:14:32 +04:00
|
|
|
#include "gfxDrawable.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "gfxUtils.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"
|
2020-07-12 19:38:26 +03:00
|
|
|
#include "mozilla/SVGImageContext.h"
|
2023-03-27 10:20:25 +03:00
|
|
|
|
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"
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2014-07-10 19:00:31 +04:00
|
|
|
|
|
|
|
using namespace gfx;
|
2016-07-01 03:27:00 +03:00
|
|
|
using std::max;
|
2014-07-10 19:00:31 +04:00
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
namespace image {
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
class ClippedImageCachedSurface {
|
|
|
|
public:
|
2015-06-17 17:00:52 +03:00
|
|
|
ClippedImageCachedSurface(already_AddRefed<SourceSurface> aSurface,
|
2014-08-23 00:12:38 +04:00
|
|
|
const nsIntSize& aSize,
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& aSVGContext, float aFrame,
|
|
|
|
uint32_t aFlags, ImgDrawResult aDrawResult)
|
2013-04-26 02:58:32 +04:00
|
|
|
: mSurface(aSurface),
|
2014-08-23 00:12:38 +04:00
|
|
|
mSize(aSize),
|
2015-10-01 21:31:41 +03:00
|
|
|
mSVGContext(aSVGContext),
|
2013-04-26 02:58:32 +04:00
|
|
|
mFrame(aFrame),
|
|
|
|
mFlags(aFlags),
|
2015-10-01 21:31:41 +03:00
|
|
|
mDrawResult(aDrawResult) {
|
2013-04-26 02:58:32 +04:00
|
|
|
MOZ_ASSERT(mSurface, "Must have a valid surface");
|
|
|
|
}
|
|
|
|
|
2022-07-14 19:03:25 +03:00
|
|
|
bool Matches(const nsIntSize& aSize, const SVGImageContext& aSVGContext,
|
|
|
|
float aFrame, uint32_t aFlags) const {
|
2014-08-23 00:12:38 +04:00
|
|
|
return mSize == aSize && mSVGContext == aSVGContext && mFrame == aFrame &&
|
2013-04-26 02:58:32 +04:00
|
|
|
mFlags == aFlags;
|
|
|
|
}
|
|
|
|
|
2015-10-01 21:31:41 +03:00
|
|
|
already_AddRefed<SourceSurface> Surface() const {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surf(mSurface);
|
2015-05-01 16:14:16 +03:00
|
|
|
return surf.forget();
|
2013-05-07 21:47:42 +04:00
|
|
|
}
|
2013-04-26 02:58:32 +04:00
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult GetDrawResult() const { return mDrawResult; }
|
2015-10-01 21:31:41 +03:00
|
|
|
|
|
|
|
bool NeedsRedraw() const {
|
2017-12-11 18:37:59 +03:00
|
|
|
return mDrawResult != ImgDrawResult::SUCCESS &&
|
|
|
|
mDrawResult != ImgDrawResult::BAD_IMAGE;
|
2015-10-01 21:31:41 +03:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> mSurface;
|
2014-08-23 00:12:38 +04:00
|
|
|
const nsIntSize mSize;
|
2022-07-14 19:03:25 +03:00
|
|
|
SVGImageContext mSVGContext;
|
2014-08-23 00:12:38 +04:00
|
|
|
const float mFrame;
|
|
|
|
const uint32_t mFlags;
|
2017-12-11 18:37:59 +03:00
|
|
|
const ImgDrawResult mDrawResult;
|
2013-04-26 02:58:32 +04:00
|
|
|
};
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
class DrawSingleTileCallback : public gfxDrawingCallback {
|
|
|
|
public:
|
|
|
|
DrawSingleTileCallback(ClippedImage* aImage, const nsIntSize& aSize,
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& aSVGContext,
|
2013-04-06 01:14:32 +04:00
|
|
|
uint32_t aWhichFrame, uint32_t aFlags, float aOpacity)
|
|
|
|
: mImage(aImage),
|
2014-08-23 00:12:38 +04:00
|
|
|
mSize(aSize),
|
2013-04-06 01:14:32 +04:00
|
|
|
mSVGContext(aSVGContext),
|
|
|
|
mWhichFrame(aWhichFrame),
|
|
|
|
mFlags(aFlags),
|
2017-12-11 18:37:59 +03:00
|
|
|
mDrawResult(ImgDrawResult::NOT_READY),
|
2017-01-03 08:53:22 +03:00
|
|
|
mOpacity(aOpacity) {
|
2013-04-06 01:14:32 +04:00
|
|
|
MOZ_ASSERT(mImage, "Must have an image to clip");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool operator()(gfxContext* aContext, const gfxRect& aFillRect,
|
2016-05-25 19:01:18 +03:00
|
|
|
const SamplingFilter aSamplingFilter,
|
2017-11-06 06:37:28 +03:00
|
|
|
const gfxMatrix& aTransform) override {
|
2014-08-23 00:12:38 +04:00
|
|
|
MOZ_ASSERT(aTransform.IsIdentity(),
|
|
|
|
"Caller is probably CreateSamplingRestrictedDrawable, "
|
|
|
|
"which should not happen");
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
// Draw the image. |gfxCallbackDrawable| always calls this function with
|
|
|
|
// arguments that guarantee we never tile.
|
2015-10-01 21:31:41 +03:00
|
|
|
mDrawResult = mImage->DrawSingleTile(
|
|
|
|
aContext, mSize, ImageRegion::Create(aFillRect), mWhichFrame,
|
2017-01-03 08:53:22 +03:00
|
|
|
aSamplingFilter, mSVGContext, mFlags, mOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult GetDrawResult() { return mDrawResult; }
|
2015-10-01 21:31:41 +03:00
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ClippedImage> mImage;
|
2014-08-23 00:12:38 +04:00
|
|
|
const nsIntSize mSize;
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& mSVGContext;
|
2014-08-23 00:12:38 +04:00
|
|
|
const uint32_t mWhichFrame;
|
|
|
|
const uint32_t mFlags;
|
2017-12-11 18:37:59 +03:00
|
|
|
ImgDrawResult mDrawResult;
|
2017-01-03 08:53:22 +03:00
|
|
|
float mOpacity;
|
2013-04-06 01:14:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
ClippedImage::ClippedImage(Image* aImage, nsIntRect aClip,
|
2016-03-08 10:54:13 +03:00
|
|
|
const Maybe<nsSize>& aSVGViewportSize)
|
2013-04-06 01:14:32 +04:00
|
|
|
: ImageWrapper(aImage), mClip(aClip) {
|
|
|
|
MOZ_ASSERT(aImage != nullptr, "ClippedImage requires an existing Image");
|
2016-03-08 10:54:13 +03:00
|
|
|
MOZ_ASSERT_IF(aSVGViewportSize,
|
|
|
|
aImage->GetType() == imgIContainer::TYPE_VECTOR);
|
|
|
|
if (aSVGViewportSize) {
|
|
|
|
mSVGViewportSize =
|
|
|
|
Some(aSVGViewportSize->ToNearestPixels(AppUnitsPerCSSPixel()));
|
|
|
|
}
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
ClippedImage::~ClippedImage() {}
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
bool ClippedImage::ShouldClip() {
|
2015-04-04 22:57:00 +03:00
|
|
|
// We need to evaluate the clipping region against the image's width and
|
|
|
|
// height once they're available to determine if it's valid and whether we
|
|
|
|
// actually need to do any work. We may fail if the image's width and height
|
|
|
|
// aren't available yet, in which case we'll try again later.
|
2014-08-14 02:39:41 +04:00
|
|
|
if (mShouldClip.isNothing()) {
|
2013-04-06 01:14:32 +04:00
|
|
|
int32_t width, height;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker =
|
2014-11-15 07:10:47 +03:00
|
|
|
InnerImage()->GetProgressTracker();
|
2013-04-06 01:14:32 +04:00
|
|
|
if (InnerImage()->HasError()) {
|
2015-04-04 22:57:00 +03:00
|
|
|
// If there's a problem with the inner image we'll let it handle
|
|
|
|
// everything.
|
2014-08-14 02:39:41 +04:00
|
|
|
mShouldClip.emplace(false);
|
2016-03-08 10:54:13 +03:00
|
|
|
} else if (mSVGViewportSize && !mSVGViewportSize->IsEmpty()) {
|
|
|
|
// Clamp the clipping region to the size of the SVG viewport.
|
|
|
|
nsIntRect svgViewportRect(nsIntPoint(0, 0), *mSVGViewportSize);
|
|
|
|
|
|
|
|
mClip = mClip.Intersect(svgViewportRect);
|
|
|
|
|
|
|
|
// If the clipping region is the same size as the SVG viewport size
|
|
|
|
// we don't have to do anything.
|
|
|
|
mShouldClip.emplace(!mClip.IsEqualInterior(svgViewportRect));
|
2013-04-06 01:14:32 +04:00
|
|
|
} else if (NS_SUCCEEDED(InnerImage()->GetWidth(&width)) && width > 0 &&
|
|
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&height)) && height > 0) {
|
|
|
|
// Clamp the clipping region to the size of the underlying image.
|
|
|
|
mClip = mClip.Intersect(nsIntRect(0, 0, width, height));
|
|
|
|
|
|
|
|
// If the clipping region is the same size as the underlying image we
|
|
|
|
// don't have to do anything.
|
2015-04-04 22:57:00 +03:00
|
|
|
mShouldClip.emplace(
|
|
|
|
!mClip.IsEqualInterior(nsIntRect(0, 0, width, height)));
|
2015-01-25 10:16:46 +03:00
|
|
|
} else if (progressTracker &&
|
|
|
|
!(progressTracker->GetProgress() & FLAG_LOAD_COMPLETE)) {
|
2013-04-06 01:14:32 +04:00
|
|
|
// The image just hasn't finished loading yet. We don't yet know whether
|
2015-04-04 22:57:00 +03:00
|
|
|
// clipping with be needed or not for now. Just return without memorizing
|
2013-04-06 01:14:32 +04:00
|
|
|
// anything.
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// We have a fully loaded image without a clearly defined width and
|
|
|
|
// height. This can happen with SVG images.
|
2014-08-14 02:39:41 +04:00
|
|
|
mShouldClip.emplace(false);
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-14 02:39:41 +04:00
|
|
|
MOZ_ASSERT(mShouldClip.isSome(), "Should have computed a result");
|
|
|
|
return *mShouldClip;
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ClippedImage::GetWidth(int32_t* aWidth) {
|
|
|
|
if (!ShouldClip()) {
|
|
|
|
return InnerImage()->GetWidth(aWidth);
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:29:56 +03:00
|
|
|
*aWidth = mClip.Width();
|
2013-04-06 01:14:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ClippedImage::GetHeight(int32_t* aHeight) {
|
|
|
|
if (!ShouldClip()) {
|
|
|
|
return InnerImage()->GetHeight(aHeight);
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:29:56 +03:00
|
|
|
*aHeight = mClip.Height();
|
2013-04-06 01:14:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ClippedImage::GetIntrinsicSize(nsSize* aSize) {
|
|
|
|
if (!ShouldClip()) {
|
|
|
|
return InnerImage()->GetIntrinsicSize(aSize);
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:29:56 +03:00
|
|
|
*aSize = nsSize(mClip.Width(), mClip.Height());
|
2013-04-06 01:14:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-03 02:28:21 +03:00
|
|
|
Maybe<AspectRatio> ClippedImage::GetIntrinsicRatio() {
|
2013-04-06 01:14:32 +04:00
|
|
|
if (!ShouldClip()) {
|
2019-05-03 02:28:21 +03:00
|
|
|
return InnerImage()->GetIntrinsicRatio();
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2019-05-03 02:28:21 +03:00
|
|
|
return Some(AspectRatio::FromSize(mClip.Width(), mClip.Height()));
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
2013-04-06 01:14:32 +04:00
|
|
|
ClippedImage::GetFrame(uint32_t aWhichFrame, uint32_t aFlags) {
|
2023-03-25 15:16:43 +03:00
|
|
|
RefPtr<SourceSurface> surface;
|
2023-03-27 10:23:36 +03:00
|
|
|
std::tie(std::ignore, surface) = GetFrameInternal(
|
|
|
|
mClip.Size(), SVGImageContext(), Nothing(), aWhichFrame, aFlags, 1.0);
|
2015-10-01 21:31:41 +03:00
|
|
|
return surface.forget();
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2015-09-19 23:34:09 +03:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
|
|
|
|
ClippedImage::GetFrameAtSize(const IntSize& aSize, uint32_t aWhichFrame,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
// XXX(seth): It'd be nice to support downscale-during-decode for this case,
|
|
|
|
// but right now we just fall back to the intrinsic size.
|
|
|
|
return GetFrame(aWhichFrame, aFlags);
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
std::pair<ImgDrawResult, RefPtr<SourceSurface>> ClippedImage::GetFrameInternal(
|
2022-07-14 19:03:25 +03:00
|
|
|
const nsIntSize& aSize, const SVGImageContext& aSVGContext,
|
2021-05-13 19:24:07 +03:00
|
|
|
const Maybe<ImageIntRegion>& aRegion, uint32_t aWhichFrame, uint32_t aFlags,
|
|
|
|
float aOpacity) {
|
2013-04-06 01:14:32 +04:00
|
|
|
if (!ShouldClip()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surface = InnerImage()->GetFrame(aWhichFrame, aFlags);
|
2020-03-17 15:42:12 +03:00
|
|
|
return std::make_pair(
|
|
|
|
surface ? ImgDrawResult::SUCCESS : ImgDrawResult::NOT_READY,
|
|
|
|
std::move(surface));
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
float frameToDraw = InnerImage()->GetFrameIndex(aWhichFrame);
|
2015-10-01 21:31:41 +03:00
|
|
|
if (!mCachedSurface ||
|
|
|
|
!mCachedSurface->Matches(aSize, aSVGContext, frameToDraw, aFlags) ||
|
|
|
|
mCachedSurface->NeedsRedraw()) {
|
2013-04-26 02:58:32 +04:00
|
|
|
// Create a surface to draw into.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> target =
|
2014-08-23 00:12:38 +04:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
|
2019-11-12 21:22:33 +03:00
|
|
|
IntSize(aSize.width, aSize.height), SurfaceFormat::OS_RGBA);
|
2016-04-12 22:18:11 +03:00
|
|
|
if (!target || !target->IsValid()) {
|
2014-05-31 14:26:04 +04:00
|
|
|
NS_ERROR("Could not create a DrawTarget");
|
2020-03-17 15:42:12 +03:00
|
|
|
return std::make_pair(ImgDrawResult::TEMPORARY_ERROR,
|
|
|
|
RefPtr<SourceSurface>());
|
2014-05-31 14:26:04 +04:00
|
|
|
}
|
2013-10-16 05:00:30 +04:00
|
|
|
|
2023-02-21 10:28:25 +03:00
|
|
|
gfxContext ctx(target);
|
2013-04-26 02:58:32 +04:00
|
|
|
|
|
|
|
// Create our callback.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawSingleTileCallback> drawTileCallback =
|
2017-01-03 08:53:22 +03:00
|
|
|
new DrawSingleTileCallback(this, aSize, aSVGContext, aWhichFrame,
|
|
|
|
aFlags, aOpacity);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxDrawable> drawable =
|
2014-08-23 00:12:38 +04:00
|
|
|
new gfxCallbackDrawable(drawTileCallback, aSize);
|
2013-04-26 02:58:32 +04:00
|
|
|
|
|
|
|
// Actually draw. The callback will end up invoking DrawSingleTile.
|
2023-02-21 10:28:25 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(&ctx, drawable, SizeDouble(aSize),
|
2014-08-23 00:12:38 +04:00
|
|
|
ImageRegion::Create(aSize),
|
2019-11-12 21:22:33 +03:00
|
|
|
SurfaceFormat::OS_RGBA, SamplingFilter::LINEAR,
|
2014-08-23 00:12:38 +04:00
|
|
|
imgIContainer::FLAG_CLAMP);
|
2013-04-26 02:58:32 +04:00
|
|
|
|
|
|
|
// Cache the resulting surface.
|
2015-10-17 13:53:28 +03:00
|
|
|
mCachedSurface = MakeUnique<ClippedImageCachedSurface>(
|
|
|
|
target->Snapshot(), aSize, aSVGContext, frameToDraw, aFlags,
|
|
|
|
drawTileCallback->GetDrawResult());
|
2013-04-26 02:58:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mCachedSurface, "Should have a cached surface now");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<SourceSurface> surface = mCachedSurface->Surface();
|
2020-03-17 15:42:12 +03:00
|
|
|
return std::make_pair(mCachedSurface->GetDrawResult(), std::move(surface));
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2015-05-13 10:23:44 +03:00
|
|
|
NS_IMETHODIMP_(bool)
|
2021-09-06 01:36:45 +03:00
|
|
|
ClippedImage::IsImageContainerAvailable(WindowRenderer* aRenderer,
|
2015-05-13 10:23:44 +03:00
|
|
|
uint32_t aFlags) {
|
|
|
|
if (!ShouldClip()) {
|
2021-09-06 01:36:45 +03:00
|
|
|
return InnerImage()->IsImageContainerAvailable(aRenderer, aFlags);
|
2015-05-13 10:23:44 +03:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-11-27 14:47:36 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
|
|
|
ClippedImage::GetImageProvider(WindowRenderer* aRenderer,
|
|
|
|
const gfx::IntSize& aSize,
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& aSVGContext,
|
2021-11-27 14:47:36 +03:00
|
|
|
const Maybe<ImageIntRegion>& aRegion,
|
|
|
|
uint32_t aFlags,
|
|
|
|
WebRenderImageProvider** aProvider) {
|
|
|
|
// XXX(seth): We currently don't have a way of clipping the result of
|
|
|
|
// GetImageContainer. We work around this by always returning null, but if it
|
|
|
|
// ever turns out that ClippedImage is widely used on codepaths that can
|
|
|
|
// actually benefit from GetImageContainer, it would be a good idea to fix
|
|
|
|
// that method for performance reasons.
|
|
|
|
|
|
|
|
if (!ShouldClip()) {
|
|
|
|
return InnerImage()->GetImageProvider(aRenderer, aSize, aSVGContext,
|
|
|
|
aRegion, aFlags, aProvider);
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:48:21 +03:00
|
|
|
return ImgDrawResult::NOT_SUPPORTED;
|
2017-11-17 14:45:26 +03:00
|
|
|
}
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
static bool MustCreateSurface(gfxContext* aContext, const nsIntSize& aSize,
|
|
|
|
const ImageRegion& aRegion,
|
|
|
|
const uint32_t aFlags) {
|
|
|
|
gfxRect imageRect(0, 0, aSize.width, aSize.height);
|
|
|
|
bool willTile = !imageRect.Contains(aRegion.Rect()) &&
|
2013-04-06 01:14:32 +04:00
|
|
|
!(aFlags & imgIContainer::FLAG_CLAMP);
|
2014-08-23 00:12:38 +04:00
|
|
|
bool willResample = aContext->CurrentMatrix().HasNonIntegerTranslation() &&
|
|
|
|
(willTile || !aRegion.RestrictionContains(imageRect));
|
2013-04-06 01:14:32 +04:00
|
|
|
return willTile || willResample;
|
|
|
|
}
|
|
|
|
|
2017-12-11 18:37:59 +03:00
|
|
|
NS_IMETHODIMP_(ImgDrawResult)
|
2013-04-06 01:14:32 +04:00
|
|
|
ClippedImage::Draw(gfxContext* aContext, const nsIntSize& aSize,
|
2014-08-23 00:12:38 +04:00
|
|
|
const ImageRegion& aRegion, uint32_t aWhichFrame,
|
2016-05-25 19:01:18 +03:00
|
|
|
SamplingFilter aSamplingFilter,
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& aSVGContext, uint32_t aFlags,
|
2017-01-03 08:53:22 +03:00
|
|
|
float aOpacity) {
|
2013-04-06 01:14:32 +04:00
|
|
|
if (!ShouldClip()) {
|
2014-08-23 00:12:38 +04:00
|
|
|
return InnerImage()->Draw(aContext, aSize, aRegion, aWhichFrame,
|
2017-01-03 08:53:22 +03:00
|
|
|
aSamplingFilter, aSVGContext, aFlags, aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for tiling. If we need to tile then we need to create a
|
|
|
|
// gfxCallbackDrawable to handle drawing for us.
|
2014-08-23 00:12:38 +04:00
|
|
|
if (MustCreateSurface(aContext, aSize, aRegion, aFlags)) {
|
2013-04-06 01:14:32 +04:00
|
|
|
// Create a temporary surface containing a single tile of this image.
|
|
|
|
// GetFrame will call DrawSingleTile internally.
|
2023-03-27 10:20:25 +03:00
|
|
|
auto [result, surface] = GetFrameInternal(aSize, aSVGContext, Nothing(),
|
|
|
|
aWhichFrame, aFlags, aOpacity);
|
2015-02-05 00:50:56 +03:00
|
|
|
if (!surface) {
|
2017-12-11 18:37:59 +03:00
|
|
|
MOZ_ASSERT(result != ImgDrawResult::SUCCESS);
|
2015-10-01 21:31:41 +03:00
|
|
|
return result;
|
2015-02-05 00:50:56 +03:00
|
|
|
}
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
// Create a drawable from that surface.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxSurfaceDrawable> drawable =
|
2014-08-23 00:12:38 +04:00
|
|
|
new gfxSurfaceDrawable(surface, aSize);
|
2013-04-06 01:14:32 +04:00
|
|
|
|
|
|
|
// Draw.
|
2017-06-28 18:41:21 +03:00
|
|
|
gfxUtils::DrawPixelSnapped(aContext, drawable, SizeDouble(aSize), aRegion,
|
2019-11-12 21:22:33 +03:00
|
|
|
SurfaceFormat::OS_RGBA, aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2015-10-01 21:31:41 +03:00
|
|
|
return result;
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
return DrawSingleTile(aContext, aSize, aRegion, aWhichFrame, aSamplingFilter,
|
2017-01-03 08:53:22 +03:00
|
|
|
aSVGContext, aFlags, aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ImgDrawResult ClippedImage::DrawSingleTile(
|
2014-08-23 00:12:38 +04:00
|
|
|
gfxContext* aContext, const nsIntSize& aSize, const ImageRegion& aRegion,
|
2016-05-25 19:01:18 +03:00
|
|
|
uint32_t aWhichFrame, SamplingFilter aSamplingFilter,
|
2022-07-14 19:03:25 +03:00
|
|
|
const SVGImageContext& aSVGContext, uint32_t aFlags, float aOpacity) {
|
2014-08-23 00:12:38 +04:00
|
|
|
MOZ_ASSERT(!MustCreateSurface(aContext, aSize, aRegion, aFlags),
|
|
|
|
"Shouldn't need to create a surface");
|
|
|
|
|
2017-12-21 00:46:28 +03:00
|
|
|
gfxRect clip(mClip.X(), mClip.Y(), mClip.Width(), mClip.Height());
|
2014-08-23 00:12:38 +04:00
|
|
|
nsIntSize size(aSize), innerSize(aSize);
|
2016-03-08 10:54:13 +03:00
|
|
|
bool needScale = false;
|
|
|
|
if (mSVGViewportSize && !mSVGViewportSize->IsEmpty()) {
|
|
|
|
innerSize = *mSVGViewportSize;
|
|
|
|
needScale = true;
|
|
|
|
} else if (NS_SUCCEEDED(InnerImage()->GetWidth(&innerSize.width)) &&
|
|
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&innerSize.height))) {
|
|
|
|
needScale = true;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"If ShouldClip() led us to draw then we should never get here");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needScale) {
|
2017-08-14 15:29:56 +03:00
|
|
|
double scaleX = aSize.width / clip.Width();
|
|
|
|
double scaleY = aSize.height / clip.Height();
|
2015-04-04 22:57:00 +03:00
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
// Map the clip and size to the scale requested by the caller.
|
|
|
|
clip.Scale(scaleX, scaleY);
|
|
|
|
size = innerSize;
|
|
|
|
size.Scale(scaleX, scaleY);
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
// We restrict our drawing to only the clipping region, and translate so that
|
|
|
|
// the clipping region is placed at the position the caller expects.
|
|
|
|
ImageRegion region(aRegion);
|
2017-12-21 00:46:28 +03:00
|
|
|
region.MoveBy(clip.X(), clip.Y());
|
2014-08-23 00:12:38 +04:00
|
|
|
region = region.Intersect(clip);
|
|
|
|
|
|
|
|
gfxContextMatrixAutoSaveRestore saveMatrix(aContext);
|
2017-12-21 00:46:28 +03:00
|
|
|
aContext->Multiply(gfxMatrix::Translation(-clip.X(), -clip.Y()));
|
2013-04-06 01:14:32 +04:00
|
|
|
|
2016-06-22 23:34:07 +03:00
|
|
|
auto unclipViewport = [&](const SVGImageContext& aOldContext) {
|
|
|
|
// Map the viewport to the inner image. Note that we don't take the aSize
|
|
|
|
// parameter of imgIContainer::Draw into account, just the clipping region.
|
|
|
|
// The size in pixels at which the output will ultimately be drawn is
|
|
|
|
// irrelevant here since the purpose of the SVG viewport size is to
|
|
|
|
// determine what *region* of the SVG document will be drawn.
|
2017-01-09 22:12:02 +03:00
|
|
|
SVGImageContext context(aOldContext);
|
2017-01-30 16:25:00 +03:00
|
|
|
auto oldViewport = aOldContext.GetViewportSize();
|
|
|
|
if (oldViewport) {
|
|
|
|
CSSIntSize newViewport;
|
|
|
|
newViewport.width =
|
2017-08-14 15:29:56 +03:00
|
|
|
ceil(oldViewport->width * double(innerSize.width) / mClip.Width());
|
2017-01-30 16:25:00 +03:00
|
|
|
newViewport.height =
|
2017-08-14 15:29:56 +03:00
|
|
|
ceil(oldViewport->height * double(innerSize.height) / mClip.Height());
|
2017-01-30 16:25:00 +03:00
|
|
|
context.SetViewportSize(Some(newViewport));
|
|
|
|
}
|
2017-01-09 22:12:02 +03:00
|
|
|
return context;
|
2016-06-22 23:34:07 +03:00
|
|
|
};
|
|
|
|
|
2014-08-23 00:12:38 +04:00
|
|
|
return InnerImage()->Draw(aContext, size, region, aWhichFrame,
|
2022-07-14 19:03:25 +03:00
|
|
|
aSamplingFilter, unclipViewport(aSVGContext),
|
2017-01-03 08:53:22 +03:00
|
|
|
aFlags, aOpacity);
|
2013-04-06 01:14:32 +04:00
|
|
|
}
|
|
|
|
|
2013-04-26 02:58:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ClippedImage::RequestDiscard() {
|
|
|
|
// We're very aggressive about discarding.
|
|
|
|
mCachedSurface = nullptr;
|
|
|
|
|
|
|
|
return InnerImage()->RequestDiscard();
|
|
|
|
}
|
|
|
|
|
2013-08-25 11:19:42 +04:00
|
|
|
NS_IMETHODIMP_(Orientation)
|
|
|
|
ClippedImage::GetOrientation() {
|
|
|
|
// XXX(seth): This should not actually be here; this is just to work around a
|
|
|
|
// what appears to be a bug in MSVC's linker.
|
|
|
|
return InnerImage()->GetOrientation();
|
|
|
|
}
|
|
|
|
|
2015-04-04 22:57:00 +03:00
|
|
|
nsIntSize ClippedImage::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:40 +04:00
|
|
|
if (!ShouldClip()) {
|
2016-05-25 19:01:18 +03:00
|
|
|
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame,
|
|
|
|
aSamplingFilter, aFlags);
|
2014-07-29 01:27:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t imgWidth, imgHeight;
|
2016-03-08 10:54:13 +03:00
|
|
|
bool needScale = false;
|
2016-07-01 03:27:00 +03:00
|
|
|
bool forceUniformScaling = false;
|
2016-03-08 10:54:13 +03:00
|
|
|
if (mSVGViewportSize && !mSVGViewportSize->IsEmpty()) {
|
|
|
|
imgWidth = mSVGViewportSize->width;
|
|
|
|
imgHeight = mSVGViewportSize->height;
|
|
|
|
needScale = true;
|
2016-07-01 03:27:00 +03:00
|
|
|
forceUniformScaling = (aFlags & imgIContainer::FLAG_FORCE_UNIFORM_SCALING);
|
2016-03-08 10:54:13 +03:00
|
|
|
} else if (NS_SUCCEEDED(InnerImage()->GetWidth(&imgWidth)) &&
|
|
|
|
NS_SUCCEEDED(InnerImage()->GetHeight(&imgHeight))) {
|
|
|
|
needScale = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needScale) {
|
2014-07-29 01:27:40 +04:00
|
|
|
// To avoid ugly sampling artifacts, ClippedImage needs the image size to
|
|
|
|
// be chosen such that the clipping region lies on pixel boundaries.
|
|
|
|
|
2015-04-04 22:57:00 +03:00
|
|
|
// First, we select a scale that's good for ClippedImage. An integer
|
|
|
|
// multiple of the size of the clipping region is always fine.
|
2017-08-14 15:29:56 +03:00
|
|
|
IntSize scale = IntSize::Ceil(aDest.width / mClip.Width(),
|
|
|
|
aDest.height / mClip.Height());
|
2014-07-29 01:27:40 +04:00
|
|
|
|
2016-07-01 03:27:00 +03:00
|
|
|
if (forceUniformScaling) {
|
|
|
|
scale.width = scale.height = max(scale.height, scale.width);
|
|
|
|
}
|
|
|
|
|
2014-07-29 01:27:40 +04:00
|
|
|
// Determine the size we'd prefer to render the inner image at, and ask the
|
|
|
|
// inner image what size we should actually use.
|
2019-09-11 23:57:17 +03:00
|
|
|
gfxSize desiredSize(double(imgWidth) * scale.width,
|
|
|
|
double(imgHeight) * scale.height);
|
2014-07-29 01:27:40 +04:00
|
|
|
nsIntSize innerDesiredSize = InnerImage()->OptimalImageSizeForDest(
|
2016-05-25 19:01:18 +03:00
|
|
|
desiredSize, aWhichFrame, aSamplingFilter, aFlags);
|
2014-07-29 01:27:40 +04:00
|
|
|
|
|
|
|
// To get our final result, we take the inner image's desired size and
|
|
|
|
// determine how large the clipped region would be at that scale. (Again, we
|
|
|
|
// ensure an integer multiple of the size of the clipping region.)
|
2016-07-26 17:48:30 +03:00
|
|
|
IntSize finalScale =
|
|
|
|
IntSize::Ceil(double(innerDesiredSize.width) / imgWidth,
|
|
|
|
double(innerDesiredSize.height) / imgHeight);
|
2014-07-29 01:27:40 +04:00
|
|
|
return mClip.Size() * finalScale;
|
|
|
|
}
|
2016-03-08 10:54:13 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(false,
|
|
|
|
"If ShouldClip() led us to draw then we should never get here");
|
2016-05-25 19:01:18 +03:00
|
|
|
return InnerImage()->OptimalImageSizeForDest(aDest, aWhichFrame,
|
|
|
|
aSamplingFilter, aFlags);
|
2014-07-29 01:27:40 +04:00
|
|
|
}
|
|
|
|
|
2014-06-27 03:02:04 +04:00
|
|
|
NS_IMETHODIMP_(nsIntRect)
|
|
|
|
ClippedImage::GetImageSpaceInvalidationRect(const nsIntRect& aRect) {
|
|
|
|
if (!ShouldClip()) {
|
|
|
|
return InnerImage()->GetImageSpaceInvalidationRect(aRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect rect(InnerImage()->GetImageSpaceInvalidationRect(aRect));
|
|
|
|
rect = rect.Intersect(mClip);
|
2017-12-21 00:46:28 +03:00
|
|
|
rect.MoveBy(-mClip.X(), -mClip.Y());
|
2014-06-27 03:02:04 +04:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2013-04-06 01:14:32 +04:00
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|