Line data Source code
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/. */
5 :
6 : #ifndef mozilla_image_SurfaceFlags_h
7 : #define mozilla_image_SurfaceFlags_h
8 :
9 : #include "imgIContainer.h"
10 : #include "mozilla/TypedEnumBits.h"
11 :
12 : namespace mozilla {
13 : namespace image {
14 :
15 : /**
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.
19 : */
20 : enum class SurfaceFlags : uint8_t
21 : {
22 : NO_PREMULTIPLY_ALPHA = 1 << 0,
23 : NO_COLORSPACE_CONVERSION = 1 << 1
24 : };
25 110 : MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags)
26 :
27 : /**
28 : * @return the default set of surface flags.
29 : */
30 : inline SurfaceFlags
31 507 : DefaultSurfaceFlags()
32 : {
33 507 : return SurfaceFlags();
34 : }
35 :
36 : /**
37 : * Given a set of imgIContainer FLAG_* flags, returns a set of SurfaceFlags with
38 : * the corresponding flags set.
39 : */
40 : inline SurfaceFlags
41 109 : ToSurfaceFlags(uint32_t aFlags)
42 : {
43 109 : SurfaceFlags flags = DefaultSurfaceFlags();
44 109 : if (aFlags & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA) {
45 0 : flags |= SurfaceFlags::NO_PREMULTIPLY_ALPHA;
46 : }
47 109 : if (aFlags & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) {
48 0 : flags |= SurfaceFlags::NO_COLORSPACE_CONVERSION;
49 : }
50 109 : return flags;
51 : }
52 :
53 : /**
54 : * Given a set of SurfaceFlags, returns a set of imgIContainer FLAG_* flags with
55 : * the corresponding flags set.
56 : */
57 : inline uint32_t
58 0 : FromSurfaceFlags(SurfaceFlags aFlags)
59 : {
60 0 : uint32_t flags = imgIContainer::DECODE_FLAGS_DEFAULT;
61 0 : if (aFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA) {
62 0 : flags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
63 : }
64 0 : if (aFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
65 0 : flags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
66 : }
67 0 : return flags;
68 : }
69 :
70 : } // namespace image
71 : } // namespace mozilla
72 :
73 : #endif // mozilla_image_SurfaceFlags_h
|