LookupResult.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
  7. * combines a surface with relevant metadata tracked by SurfaceCache.
  8. */
  9. #ifndef mozilla_image_LookupResult_h
  10. #define mozilla_image_LookupResult_h
  11. #include "mozilla/Attributes.h"
  12. #include "mozilla/Move.h"
  13. #include "ISurfaceProvider.h"
  14. namespace mozilla {
  15. namespace image {
  16. enum class MatchType : uint8_t
  17. {
  18. NOT_FOUND, // No matching surface and no placeholder.
  19. PENDING, // Found a matching placeholder, but no surface.
  20. EXACT, // Found a surface that matches exactly.
  21. SUBSTITUTE_BECAUSE_NOT_FOUND, // No exact match, but found a similar one.
  22. SUBSTITUTE_BECAUSE_PENDING // Found a similar surface and a placeholder
  23. // for an exact match.
  24. };
  25. /**
  26. * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
  27. * combines a surface with relevant metadata tracked by SurfaceCache.
  28. */
  29. class MOZ_STACK_CLASS LookupResult
  30. {
  31. public:
  32. explicit LookupResult(MatchType aMatchType)
  33. : mMatchType(aMatchType)
  34. {
  35. MOZ_ASSERT(mMatchType == MatchType::NOT_FOUND ||
  36. mMatchType == MatchType::PENDING,
  37. "Only NOT_FOUND or PENDING make sense with no surface");
  38. }
  39. LookupResult(LookupResult&& aOther)
  40. : mSurface(Move(aOther.mSurface))
  41. , mMatchType(aOther.mMatchType)
  42. { }
  43. LookupResult(DrawableSurface&& aSurface, MatchType aMatchType)
  44. : mSurface(Move(aSurface))
  45. , mMatchType(aMatchType)
  46. {
  47. MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND ||
  48. mMatchType == MatchType::PENDING),
  49. "Only NOT_FOUND or PENDING make sense with no surface");
  50. MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND ||
  51. mMatchType == MatchType::PENDING,
  52. "NOT_FOUND or PENDING do not make sense with a surface");
  53. }
  54. LookupResult& operator=(LookupResult&& aOther)
  55. {
  56. MOZ_ASSERT(&aOther != this, "Self-move-assignment is not supported");
  57. mSurface = Move(aOther.mSurface);
  58. mMatchType = aOther.mMatchType;
  59. return *this;
  60. }
  61. DrawableSurface& Surface() { return mSurface; }
  62. const DrawableSurface& Surface() const { return mSurface; }
  63. /// @return true if this LookupResult contains a surface.
  64. explicit operator bool() const { return bool(mSurface); }
  65. /// @return what kind of match this is (exact, substitute, etc.)
  66. MatchType Type() const { return mMatchType; }
  67. private:
  68. LookupResult(const LookupResult&) = delete;
  69. DrawableSurface mSurface;
  70. MatchType mMatchType;
  71. };
  72. } // namespace image
  73. } // namespace mozilla
  74. #endif // mozilla_image_LookupResult_h