image/SurfaceFlags.h
author Drew Willcoxon <adw@mozilla.com>
Fri, 09 Mar 2018 18:54:17 -0800
changeset 766943 c61f5f5ead48c78a80c80db5c489bdc7cfaf8175
parent 296028 4f0530d695b6898a865e61b0bfaa39761a815f6e
child 489668 cbb8fdf1daf98a15f7d57f6b08d273bdf96aa1a0
child 694109 98e2b4ee9775a2a2b5cc1bb8a390bfe901814f38
permissions -rw-r--r--
Back out bug 1426216 (show search suggestions above history in urlbar in some cases) and follow-ups on release. r=Mossop, a=ritu There are four bugs that need to be backed out: 1. https://hg.mozilla.org/releases/mozilla-release/rev/152720a4efe7 (bug 1432716) 2. https://hg.mozilla.org/releases/mozilla-release/rev/84a24eb373fa (bug 1432263) 3. https://hg.mozilla.org/releases/mozilla-release/rev/4d423fdc33dd (bug 1429974) 4. https://hg.mozilla.org/releases/mozilla-release/rev/440dbdb51f94 (bug 1426216) The original bug implementing the problematic feature (pref migration + UI) is 4, and the others are improvements to it.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_image_SurfaceFlags_h
#define mozilla_image_SurfaceFlags_h

#include "imgIContainer.h"
#include "mozilla/TypedEnumBits.h"

namespace mozilla {
namespace image {

/**
 * Flags that change the output a decoder generates. Because different
 * combinations of these flags result in logically different surfaces, these
 * flags must be taken into account in SurfaceCache lookups.
 */
enum class SurfaceFlags : uint8_t
{
  NO_PREMULTIPLY_ALPHA     = 1 << 0,
  NO_COLORSPACE_CONVERSION = 1 << 1
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(SurfaceFlags)

/**
 * @return the default set of surface flags.
 */
inline SurfaceFlags
DefaultSurfaceFlags()
{
  return SurfaceFlags();
}

/**
 * Given a set of imgIContainer FLAG_* flags, returns a set of SurfaceFlags with
 * the corresponding flags set.
 */
inline SurfaceFlags
ToSurfaceFlags(uint32_t aFlags)
{
  SurfaceFlags flags = DefaultSurfaceFlags();
  if (aFlags & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA) {
    flags |= SurfaceFlags::NO_PREMULTIPLY_ALPHA;
  }
  if (aFlags & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) {
    flags |= SurfaceFlags::NO_COLORSPACE_CONVERSION;
  }
  return flags;
}

/**
 * Given a set of SurfaceFlags, returns a set of imgIContainer FLAG_* flags with
 * the corresponding flags set.
 */
inline uint32_t
FromSurfaceFlags(SurfaceFlags aFlags)
{
  uint32_t flags = imgIContainer::DECODE_FLAGS_DEFAULT;
  if (aFlags & SurfaceFlags::NO_PREMULTIPLY_ALPHA) {
    flags |= imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA;
  }
  if (aFlags & SurfaceFlags::NO_COLORSPACE_CONVERSION) {
    flags |= imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION;
  }
  return flags;
}

} // namespace image
} // namespace mozilla

#endif // mozilla_image_SurfaceFlags_h