Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/SurfaceFlags.h
Line
Count
Source (jump to first uncovered line)
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
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags)
26
27
/**
28
 * @return the default set of surface flags.
29
 */
30
inline SurfaceFlags
31
DefaultSurfaceFlags()
32
0
{
33
0
  return SurfaceFlags();
34
0
}
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
ToSurfaceFlags(uint32_t aFlags)
42
0
{
43
0
  SurfaceFlags flags = DefaultSurfaceFlags();
44
0
  if (aFlags & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA) {
45
0
    flags |= SurfaceFlags::NO_PREMULTIPLY_ALPHA;
46
0
  }
47
0
  if (aFlags & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) {
48
0
    flags |= SurfaceFlags::NO_COLORSPACE_CONVERSION;
49
0
  }
50
0
  return flags;
51
0
}
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
FromSurfaceFlags(SurfaceFlags aFlags)
59
0
{
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
0
  }
64
0
  if (aFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
65
0
    flags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
66
0
  }
67
0
  return flags;
68
0
}
69
70
} // namespace image
71
} // namespace mozilla
72
73
#endif // mozilla_image_SurfaceFlags_h