Bug 1516095 [wpt PR 14643] - Update wpt metadata, a=testonly
[gecko.git] / image / LookupResult.h
blob1e90a625f8dc1683a831d5ff2dded44d10cffddc
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(DrawableSurface&& aSurface, MatchType aMatchType,
66 const gfx::IntSize& aSuggestedSize)
67 : mSurface(std::move(aSurface)),
68 mMatchType(aMatchType),
69 mSuggestedSize(aSuggestedSize) {
70 MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND ||
71 mMatchType == MatchType::PENDING),
72 "Only NOT_FOUND or PENDING make sense with no surface");
73 MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND ||
74 mMatchType == MatchType::PENDING,
75 "NOT_FOUND or PENDING do not make sense with a surface");
78 LookupResult& operator=(LookupResult&& aOther) {
79 MOZ_ASSERT(&aOther != this, "Self-move-assignment is not supported");
80 mSurface = std::move(aOther.mSurface);
81 mMatchType = aOther.mMatchType;
82 mSuggestedSize = aOther.mSuggestedSize;
83 return *this;
86 DrawableSurface& Surface() { return mSurface; }
87 const DrawableSurface& Surface() const { return mSurface; }
88 const gfx::IntSize& SuggestedSize() const { return mSuggestedSize; }
90 /// @return true if this LookupResult contains a surface.
91 explicit operator bool() const { return bool(mSurface); }
93 /// @return what kind of match this is (exact, substitute, etc.)
94 MatchType Type() const { return mMatchType; }
96 private:
97 LookupResult(const LookupResult&) = delete;
98 LookupResult& operator=(const LookupResult& aOther) = delete;
100 DrawableSurface mSurface;
101 MatchType mMatchType;
103 /// mSuggestedSize will be the size of the returned surface if the result is
104 /// SUBSTITUTE_BECAUSE_BEST. It will be empty for EXACT, and can contain a
105 /// non-empty size possibly different from the returned surface (if any) for
106 /// all other results. If non-empty, it will always be the size the caller
107 /// should request any decodes at.
108 gfx::IntSize mSuggestedSize;
111 } // namespace image
112 } // namespace mozilla
114 #endif // mozilla_image_LookupResult_h