/src/mozilla-central/image/LookupResult.h
Line | Count | Source (jump to first uncovered line) |
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 | | /** |
7 | | * LookupResult is the return type of SurfaceCache's Lookup*() functions. It |
8 | | * combines a surface with relevant metadata tracked by SurfaceCache. |
9 | | */ |
10 | | |
11 | | #ifndef mozilla_image_LookupResult_h |
12 | | #define mozilla_image_LookupResult_h |
13 | | |
14 | | #include "mozilla/Attributes.h" |
15 | | #include "mozilla/gfx/Point.h" // for IntSize |
16 | | #include "mozilla/Move.h" |
17 | | #include "ISurfaceProvider.h" |
18 | | |
19 | | namespace mozilla { |
20 | | namespace image { |
21 | | |
22 | | enum class MatchType : uint8_t |
23 | | { |
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. |
30 | | |
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 |
37 | | }; |
38 | | |
39 | | /** |
40 | | * LookupResult is the return type of SurfaceCache's Lookup*() functions. It |
41 | | * combines a surface with relevant metadata tracked by SurfaceCache. |
42 | | */ |
43 | | class MOZ_STACK_CLASS LookupResult |
44 | | { |
45 | | public: |
46 | | explicit LookupResult(MatchType aMatchType) |
47 | | : mMatchType(aMatchType) |
48 | 0 | { |
49 | 0 | MOZ_ASSERT(mMatchType == MatchType::NOT_FOUND || |
50 | 0 | mMatchType == MatchType::PENDING, |
51 | 0 | "Only NOT_FOUND or PENDING make sense with no surface"); |
52 | 0 | } |
53 | | |
54 | | LookupResult(LookupResult&& aOther) |
55 | | : mSurface(std::move(aOther.mSurface)) |
56 | | , mMatchType(aOther.mMatchType) |
57 | | , mSuggestedSize(aOther.mSuggestedSize) |
58 | 0 | { } |
59 | | |
60 | | LookupResult(DrawableSurface&& aSurface, MatchType aMatchType) |
61 | | : mSurface(std::move(aSurface)) |
62 | | , mMatchType(aMatchType) |
63 | 0 | { |
64 | 0 | MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND || |
65 | 0 | mMatchType == MatchType::PENDING), |
66 | 0 | "Only NOT_FOUND or PENDING make sense with no surface"); |
67 | 0 | MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND || |
68 | 0 | mMatchType == MatchType::PENDING, |
69 | 0 | "NOT_FOUND or PENDING do not make sense with a surface"); |
70 | 0 | } |
71 | | |
72 | | LookupResult(DrawableSurface&& aSurface, MatchType aMatchType, |
73 | | const gfx::IntSize& aSuggestedSize) |
74 | | : mSurface(std::move(aSurface)) |
75 | | , mMatchType(aMatchType) |
76 | | , mSuggestedSize(aSuggestedSize) |
77 | 0 | { |
78 | 0 | MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND || |
79 | 0 | mMatchType == MatchType::PENDING), |
80 | 0 | "Only NOT_FOUND or PENDING make sense with no surface"); |
81 | 0 | MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND || |
82 | 0 | mMatchType == MatchType::PENDING, |
83 | 0 | "NOT_FOUND or PENDING do not make sense with a surface"); |
84 | 0 | } |
85 | | |
86 | | LookupResult& operator=(LookupResult&& aOther) |
87 | 0 | { |
88 | 0 | MOZ_ASSERT(&aOther != this, "Self-move-assignment is not supported"); |
89 | 0 | mSurface = std::move(aOther.mSurface); |
90 | 0 | mMatchType = aOther.mMatchType; |
91 | 0 | mSuggestedSize = aOther.mSuggestedSize; |
92 | 0 | return *this; |
93 | 0 | } |
94 | | |
95 | 0 | DrawableSurface& Surface() { return mSurface; } |
96 | 0 | const DrawableSurface& Surface() const { return mSurface; } |
97 | 0 | const gfx::IntSize& SuggestedSize() const { return mSuggestedSize; } |
98 | | |
99 | | /// @return true if this LookupResult contains a surface. |
100 | 0 | explicit operator bool() const { return bool(mSurface); } |
101 | | |
102 | | /// @return what kind of match this is (exact, substitute, etc.) |
103 | 0 | MatchType Type() const { return mMatchType; } |
104 | | |
105 | | private: |
106 | | LookupResult(const LookupResult&) = delete; |
107 | | LookupResult& operator=(const LookupResult& aOther) = delete; |
108 | | |
109 | | DrawableSurface mSurface; |
110 | | MatchType mMatchType; |
111 | | |
112 | | /// mSuggestedSize will be the size of the returned surface if the result is |
113 | | /// SUBSTITUTE_BECAUSE_BEST. It will be empty for EXACT, and can contain a |
114 | | /// non-empty size possibly different from the returned surface (if any) for |
115 | | /// all other results. If non-empty, it will always be the size the caller |
116 | | /// should request any decodes at. |
117 | | gfx::IntSize mSuggestedSize; |
118 | | }; |
119 | | |
120 | | } // namespace image |
121 | | } // namespace mozilla |
122 | | |
123 | | #endif // mozilla_image_LookupResult_h |