tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SurfaceFlags.h (2509B)


      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  NO_PREMULTIPLY_ALPHA = 1 << 0,
     22  NO_COLORSPACE_CONVERSION = 1 << 1,
     23  TO_SRGB_COLORSPACE = 1 << 2,
     24  RECORD_BLOB = 1 << 3,
     25 };
     26 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags)
     27 
     28 /**
     29 * @return the default set of surface flags.
     30 */
     31 inline SurfaceFlags DefaultSurfaceFlags() { return SurfaceFlags(); }
     32 
     33 /**
     34 * Given a set of imgIContainer FLAG_* flags, returns a set of SurfaceFlags with
     35 * the corresponding flags set.
     36 */
     37 inline SurfaceFlags ToSurfaceFlags(uint32_t aFlags) {
     38  SurfaceFlags flags = DefaultSurfaceFlags();
     39  if (aFlags & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA) {
     40    flags |= SurfaceFlags::NO_PREMULTIPLY_ALPHA;
     41  }
     42  if (aFlags & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) {
     43    flags |= SurfaceFlags::NO_COLORSPACE_CONVERSION;
     44  }
     45  if (aFlags & imgIContainer::FLAG_DECODE_TO_SRGB_COLORSPACE) {
     46    flags |= SurfaceFlags::TO_SRGB_COLORSPACE;
     47  }
     48  if (aFlags & imgIContainer::FLAG_RECORD_BLOB) {
     49    flags |= SurfaceFlags::RECORD_BLOB;
     50  }
     51  return flags;
     52 }
     53 
     54 /**
     55 * Given a set of SurfaceFlags, returns a set of imgIContainer FLAG_* flags with
     56 * the corresponding flags set.
     57 */
     58 inline uint32_t FromSurfaceFlags(SurfaceFlags aFlags) {
     59  uint32_t flags = imgIContainer::DECODE_FLAGS_DEFAULT;
     60  if (aFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA) {
     61    flags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
     62  }
     63  if (aFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
     64    flags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
     65  }
     66  if (aFlags & SurfaceFlags::TO_SRGB_COLORSPACE) {
     67    flags |= imgIContainer::FLAG_DECODE_TO_SRGB_COLORSPACE;
     68  }
     69  if (aFlags & SurfaceFlags::RECORD_BLOB) {
     70    flags |= imgIContainer::FLAG_RECORD_BLOB;
     71  }
     72  return flags;
     73 }
     74 
     75 }  // namespace image
     76 }  // namespace mozilla
     77 
     78 #endif  // mozilla_image_SurfaceFlags_h