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_image_SurfaceFlags_h
7 #define mozilla_image_SurfaceFlags_h
9 #include "imgIContainer.h"
10 #include "mozilla/TypedEnumBits.h"
16 * Flags that change the output a decoder generates. Because different
17 * combinations of these flags result in logically different surfaces, these
18 * flags must be taken into account in SurfaceCache lookups.
20 enum class SurfaceFlags
: uint8_t
22 NO_PREMULTIPLY_ALPHA
= 1 << 0,
23 NO_COLORSPACE_CONVERSION
= 1 << 1
25 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags
)
28 * @return the default set of surface flags.
33 return SurfaceFlags();
37 * Given a set of imgIContainer FLAG_* flags, returns a set of SurfaceFlags with
38 * the corresponding flags set.
41 ToSurfaceFlags(uint32_t aFlags
)
43 SurfaceFlags flags
= DefaultSurfaceFlags();
44 if (aFlags
& imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA
) {
45 flags
|= SurfaceFlags::NO_PREMULTIPLY_ALPHA
;
47 if (aFlags
& imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION
) {
48 flags
|= SurfaceFlags::NO_COLORSPACE_CONVERSION
;
54 * Given a set of SurfaceFlags, returns a set of imgIContainer FLAG_* flags with
55 * the corresponding flags set.
58 FromSurfaceFlags(SurfaceFlags aFlags
)
60 uint32_t flags
= imgIContainer::DECODE_FLAGS_DEFAULT
;
61 if (aFlags
& SurfaceFlags::NO_PREMULTIPLY_ALPHA
) {
62 flags
|= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA
;
64 if (aFlags
& SurfaceFlags::NO_COLORSPACE_CONVERSION
) {
65 flags
|= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION
;
71 } // namespace mozilla
73 #endif // mozilla_image_SurfaceFlags_h