Bug 1585126 [wpt PR 19411] - Support clamp() in CSSNumericValue.parse(), a=testonly
[gecko.git] / image / LookupResult.h
blobacd29d43c734230576932ce363524b79b02e4c19
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/. */
6 /**
7 * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
8 * combines a surface with relevant metadata tracked by SurfaceCache.
9 */
11 #ifndef mozilla_image_LookupResult_h
12 #define mozilla_image_LookupResult_h
14 #include "mozilla/Attributes.h"
15 #include "mozilla/gfx/Point.h" // for IntSize
16 #include "mozilla/Move.h"
17 #include "ISurfaceProvider.h"
19 namespace mozilla {
20 namespace image {
22 enum class MatchType : uint8_t {
23 NOT_FOUND, // No matching surface and no placeholder.
24 PENDING, // Found a matching placeholder, but no surface.
25 EXACT, // Found a surface that matches exactly.
26 SUBSTITUTE_BECAUSE_NOT_FOUND, // No exact match, but found a similar one.
27 SUBSTITUTE_BECAUSE_PENDING, // Found a similar surface and a placeholder
28 // for an exact match.
30 /* No exact match, but this should be considered an exact match for purposes
31 * of deciding whether or not to request a new decode. This is because the
32 * cache has determined that callers require too many size variants of this
33 * image. It determines the set of sizes which best represent the image, and
34 * will only suggest decoding of unavailable sizes from that set. */
35 SUBSTITUTE_BECAUSE_BEST
38 /**
39 * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
40 * combines a surface with relevant metadata tracked by SurfaceCache.
42 class MOZ_STACK_CLASS LookupResult {
43 public:
44 explicit LookupResult(MatchType aMatchType) : mMatchType(aMatchType) {
45 MOZ_ASSERT(
46 mMatchType == MatchType::NOT_FOUND || mMatchType == MatchType::PENDING,
47 "Only NOT_FOUND or PENDING make sense with no surface");
50 LookupResult(LookupResult&& aOther)
51 : mSurface(std::move(aOther.mSurface)),
52 mMatchType(aOther.mMatchType),
53 mSuggestedSize(aOther.mSuggestedSize) {}
55 LookupResult(DrawableSurface&& aSurface, MatchType aMatchType)
56 : mSurface(std::move(aSurface)), mMatchType(aMatchType) {
57 MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND ||
58 mMatchType == MatchType::PENDING),
59 "Only NOT_FOUND or PENDING make sense with no surface");
60 MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND ||
61 mMatchType == MatchType::PENDING,
62 "NOT_FOUND or PENDING do not make sense with a surface");
65 LookupResult(MatchType aMatchType, const gfx::IntSize& aSuggestedSize)
66 : mMatchType(aMatchType), mSuggestedSize(aSuggestedSize) {
67 MOZ_ASSERT(
68 mMatchType == MatchType::NOT_FOUND || mMatchType == MatchType::PENDING,
69 "Only NOT_FOUND or PENDING make sense with no surface");
72 LookupResult(DrawableSurface&& aSurface, MatchType aMatchType,
73 const gfx::IntSize& aSuggestedSize)
74 : mSurface(std::move(aSurface)),
75 mMatchType(aMatchType),
76 mSuggestedSize(aSuggestedSize) {
77 MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND ||
78 mMatchType == MatchType::PENDING),
79 "Only NOT_FOUND or PENDING make sense with no surface");
80 MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND ||
81 mMatchType == MatchType::PENDING,
82 "NOT_FOUND or PENDING do not make sense with a surface");
85 LookupResult& operator=(LookupResult&& aOther) {
86 MOZ_ASSERT(&aOther != this, "Self-move-assignment is not supported");
87 mSurface = std::move(aOther.mSurface);
88 mMatchType = aOther.mMatchType;
89 mSuggestedSize = aOther.mSuggestedSize;
90 return *this;
93 DrawableSurface& Surface() { return mSurface; }
94 const DrawableSurface& Surface() const { return mSurface; }
95 const gfx::IntSize& SuggestedSize() const { return mSuggestedSize; }
97 /// @return true if this LookupResult contains a surface.
98 explicit operator bool() const { return bool(mSurface); }
100 /// @return what kind of match this is (exact, substitute, etc.)
101 MatchType Type() const { return mMatchType; }
103 private:
104 LookupResult(const LookupResult&) = delete;
105 LookupResult& operator=(const LookupResult& aOther) = delete;
107 DrawableSurface mSurface;
108 MatchType mMatchType;
110 /// mSuggestedSize will be the size of the returned surface if the result is
111 /// SUBSTITUTE_BECAUSE_BEST. It will be empty for EXACT, and can contain a
112 /// non-empty size possibly different from the returned surface (if any) for
113 /// all other results. If non-empty, it will always be the size the caller
114 /// should request any decodes at.
115 gfx::IntSize mSuggestedSize;
118 } // namespace image
119 } // namespace mozilla
121 #endif // mozilla_image_LookupResult_h