author Bas Schouten <>
Fri, 06 Mar 2015 02:37:12 +0100
changeset 250308 a0dcce4081087e2e1f9d6ec7ebf3b9e37b7dc619
parent 248614 1ce77cbf99f31888dafcd61c0499b1019e0e859c
child 250594 11aebde6e809d32c6b37e23de66fe9e674f5490c
permissions -rw-r--r--
Bug 1138934 - Make sure the white texture of a component alpha pair is fully uploaded when new. r=nical, a=lmandel This is slightly wasteful since this will also always upload the full black texture. The wastage here is so rare and generally so few though that I don't think it's worth adding plumming for the texture host to know if this is the texture on white of on black.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 */

/* Internal stuff needed by TypedEnum.h and TypedEnumBits.h. */

// NOTE: When we can assume C++11 enum class support and TypedEnum.h goes away,
// we should then consider folding TypedEnumInternal.h into TypedEnumBits.h.

#ifndef mozilla_TypedEnumInternal_h
#define mozilla_TypedEnumInternal_h

#include "mozilla/Attributes.h"

#if defined(__cplusplus)

#if defined(__clang__)
    * Per Clang documentation, "Note that marketing version numbers should not
    * be used to check for language features, as different vendors use different
    * numbering schemes. Instead, use the feature checking macros."
#  ifndef __has_extension
#    define __has_extension __has_feature /* compatibility, for older versions of clang */
#  endif
#  if __has_extension(cxx_strong_enums)
#    define MOZ_HAVE_CXX11_ENUM_TYPE
#  endif
#elif defined(__GNUC__)
#  if defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L
#    if MOZ_GCC_VERSION_AT_LEAST(4, 6, 3)
#      define MOZ_HAVE_CXX11_ENUM_TYPE
#    endif
#  endif
#elif defined(_MSC_VER)

namespace mozilla {

 * The problem that CastableTypedEnumResult aims to solve is that
 * typed enums are not convertible to bool, and there is no way to make them
 * be, yet user code wants to be able to write
 *   if (myFlags & Flags::SOME_PARTICULAR_FLAG)              (1)
 * There are different approaches to solving this. Most of them require
 * adapting user code. For example, we could implement operator! and have
 * the user write
 *   if (!!(myFlags & Flags::SOME_PARTICULAR_FLAG))          (2)
 * Or we could supply a IsNonZero() or Any() function returning whether
 * an enum value is nonzero, and have the user write
 *   if (Any(Flags & Flags::SOME_PARTICULAR_FLAG))           (3)
 * But instead, we choose to preserve the original user syntax (1) as it
 * is inherently more readable, and to ease porting existing code to typed
 * enums. We achieve this by having operator& and other binary bitwise
 * operators have as return type a class, CastableTypedEnumResult,
 * that wraps a typed enum but adds bool convertibility.
template<typename E>
class CastableTypedEnumResult
  const E mValue;

  explicit MOZ_CONSTEXPR CastableTypedEnumResult(E aValue)
    : mValue(aValue)

  MOZ_CONSTEXPR operator E() const { return mValue; }

  template<typename DestinationType>
  operator DestinationType() const { return DestinationType(mValue); }

  MOZ_CONSTEXPR bool operator !() const { return !bool(mValue); }

  // This get() method is used to implement a constructor in the
  // non-c++11 fallback path for MOZ_BEGIN_ENUM_CLASS, taking a
  // CastableTypedEnumResult. If we try to implement it using the
  // above conversion operator E(), then at least clang 3.3
  // (when forced to take the non-c++11 fallback path) compiles
  // this constructor to an infinite recursion. So we introduce this
  // get() method, that does exactly the same as the conversion operator,
  // to work around this.
  MOZ_CONSTEXPR E get() const { return mValue; }

} // namespace mozilla

#endif // __cplusplus

#endif // mozilla_TypedEnumInternal_h