Bumping manifests a=b2g-bump
[gecko.git] / layout / svg / SVGImageContext.h
blobc6265e0bc2d280c2665d125f54bd08dbd3e48562
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef MOZILLA_SVGCONTEXT_H_
7 #define MOZILLA_SVGCONTEXT_H_
9 #include "mozilla/Maybe.h"
10 #include "SVGPreserveAspectRatio.h"
12 namespace mozilla {
14 // SVG image-specific rendering context. For imgIContainer::Draw.
15 // Used to pass information such as
16 // - viewport information from CSS, and
17 // - overridden attributes from an SVG <image> element
18 // to the image's internal SVG document when it's drawn.
19 class SVGImageContext
21 public:
22 SVGImageContext()
23 : mGlobalOpacity(1.0)
24 { }
26 SVGImageContext(nsIntSize aViewportSize,
27 Maybe<SVGPreserveAspectRatio> aPreserveAspectRatio,
28 gfxFloat aOpacity = 1.0)
29 : mViewportSize(aViewportSize)
30 , mPreserveAspectRatio(aPreserveAspectRatio)
31 , mGlobalOpacity(aOpacity)
32 { }
34 const nsIntSize& GetViewportSize() const {
35 return mViewportSize;
38 const Maybe<SVGPreserveAspectRatio>& GetPreserveAspectRatio() const {
39 return mPreserveAspectRatio;
42 gfxFloat GetGlobalOpacity() const {
43 return mGlobalOpacity;
46 bool operator==(const SVGImageContext& aOther) const {
47 return mViewportSize == aOther.mViewportSize &&
48 mPreserveAspectRatio == aOther.mPreserveAspectRatio &&
49 mGlobalOpacity == aOther.mGlobalOpacity;
52 bool operator!=(const SVGImageContext& aOther) const {
53 return !(*this == aOther);
56 uint32_t Hash() const {
57 return HashGeneric(mViewportSize.width,
58 mViewportSize.height,
59 mPreserveAspectRatio.map(HashPAR).valueOr(0),
60 HashBytes(&mGlobalOpacity, sizeof(gfxFloat)));
63 private:
64 static uint32_t HashPAR(const SVGPreserveAspectRatio& aPAR) {
65 return aPAR.Hash();
68 nsIntSize mViewportSize;
69 Maybe<SVGPreserveAspectRatio> mPreserveAspectRatio;
70 gfxFloat mGlobalOpacity;
73 } // namespace mozilla
75 #endif // MOZILLA_SVGCONTEXT_H_