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/. */
7 * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
8 * combines a surface with relevant metadata tracked by SurfaceCache.
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"
22 enum class MatchType
: uint8_t
24 NOT_FOUND
, // No matching surface and no placeholder.
25 PENDING
, // Found a matching placeholder, but no surface.
26 EXACT
, // Found a surface that matches exactly.
27 SUBSTITUTE_BECAUSE_NOT_FOUND
, // No exact match, but found a similar one.
28 SUBSTITUTE_BECAUSE_PENDING
, // Found a similar surface and a placeholder
29 // for an exact match.
31 /* No exact match, but this should be considered an exact match for purposes
32 * of deciding whether or not to request a new decode. This is because the
33 * cache has determined that callers require too many size variants of this
34 * image. It determines the set of sizes which best represent the image, and
35 * will only suggest decoding of unavailable sizes from that set. */
36 SUBSTITUTE_BECAUSE_BEST
40 * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
41 * combines a surface with relevant metadata tracked by SurfaceCache.
43 class MOZ_STACK_CLASS LookupResult
46 explicit LookupResult(MatchType aMatchType
)
47 : mMatchType(aMatchType
)
49 MOZ_ASSERT(mMatchType
== MatchType::NOT_FOUND
||
50 mMatchType
== MatchType::PENDING
,
51 "Only NOT_FOUND or PENDING make sense with no surface");
54 LookupResult(LookupResult
&& aOther
)
55 : mSurface(Move(aOther
.mSurface
))
56 , mMatchType(aOther
.mMatchType
)
57 , mSuggestedSize(aOther
.mSuggestedSize
)
60 LookupResult(DrawableSurface
&& aSurface
, MatchType aMatchType
)
61 : mSurface(Move(aSurface
))
62 , mMatchType(aMatchType
)
64 MOZ_ASSERT(!mSurface
|| !(mMatchType
== MatchType::NOT_FOUND
||
65 mMatchType
== MatchType::PENDING
),
66 "Only NOT_FOUND or PENDING make sense with no surface");
67 MOZ_ASSERT(mSurface
|| mMatchType
== MatchType::NOT_FOUND
||
68 mMatchType
== MatchType::PENDING
,
69 "NOT_FOUND or PENDING do not make sense with a surface");
72 LookupResult(DrawableSurface
&& aSurface
, MatchType aMatchType
,
73 const gfx::IntSize
& aSuggestedSize
)
74 : mSurface(Move(aSurface
))
75 , mMatchType(aMatchType
)
76 , mSuggestedSize(aSuggestedSize
)
78 MOZ_ASSERT(!mSurface
|| !(mMatchType
== MatchType::NOT_FOUND
||
79 mMatchType
== MatchType::PENDING
),
80 "Only NOT_FOUND or PENDING make sense with no surface");
81 MOZ_ASSERT(mSurface
|| mMatchType
== MatchType::NOT_FOUND
||
82 mMatchType
== MatchType::PENDING
,
83 "NOT_FOUND or PENDING do not make sense with a surface");
86 LookupResult
& operator=(LookupResult
&& aOther
)
88 MOZ_ASSERT(&aOther
!= this, "Self-move-assignment is not supported");
89 mSurface
= Move(aOther
.mSurface
);
90 mMatchType
= aOther
.mMatchType
;
91 mSuggestedSize
= aOther
.mSuggestedSize
;
95 DrawableSurface
& Surface() { return mSurface
; }
96 const DrawableSurface
& Surface() const { return mSurface
; }
97 const gfx::IntSize
& SuggestedSize() const { return mSuggestedSize
; }
99 /// @return true if this LookupResult contains a surface.
100 explicit operator bool() const { return bool(mSurface
); }
102 /// @return what kind of match this is (exact, substitute, etc.)
103 MatchType
Type() const { return mMatchType
; }
106 LookupResult(const LookupResult
&) = delete;
107 LookupResult
& operator=(const LookupResult
& aOther
) = delete;
109 DrawableSurface mSurface
;
110 MatchType mMatchType
;
112 /// If given, the size the caller should request a decode at. This may or may
113 /// not match the size the caller requested from the cache.
114 gfx::IntSize mSuggestedSize
;
118 } // namespace mozilla
120 #endif // mozilla_image_LookupResult_h