Line data Source code
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/Move.h"
16 : #include "ISurfaceProvider.h"
17 :
18 : namespace mozilla {
19 : namespace image {
20 :
21 : enum class MatchType : uint8_t
22 : {
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.
29 : };
30 :
31 : /**
32 : * LookupResult is the return type of SurfaceCache's Lookup*() functions. It
33 : * combines a surface with relevant metadata tracked by SurfaceCache.
34 : */
35 206 : class MOZ_STACK_CLASS LookupResult
36 : {
37 : public:
38 80 : explicit LookupResult(MatchType aMatchType)
39 80 : : mMatchType(aMatchType)
40 : {
41 80 : MOZ_ASSERT(mMatchType == MatchType::NOT_FOUND ||
42 : mMatchType == MatchType::PENDING,
43 : "Only NOT_FOUND or PENDING make sense with no surface");
44 80 : }
45 :
46 5 : LookupResult(LookupResult&& aOther)
47 5 : : mSurface(Move(aOther.mSurface))
48 5 : , mMatchType(aOther.mMatchType)
49 5 : { }
50 :
51 121 : LookupResult(DrawableSurface&& aSurface, MatchType aMatchType)
52 121 : : mSurface(Move(aSurface))
53 121 : , mMatchType(aMatchType)
54 : {
55 121 : MOZ_ASSERT(!mSurface || !(mMatchType == MatchType::NOT_FOUND ||
56 : mMatchType == MatchType::PENDING),
57 : "Only NOT_FOUND or PENDING make sense with no surface");
58 121 : MOZ_ASSERT(mSurface || mMatchType == MatchType::NOT_FOUND ||
59 : mMatchType == MatchType::PENDING,
60 : "NOT_FOUND or PENDING do not make sense with a surface");
61 121 : }
62 :
63 3 : LookupResult& operator=(LookupResult&& aOther)
64 : {
65 3 : MOZ_ASSERT(&aOther != this, "Self-move-assignment is not supported");
66 3 : mSurface = Move(aOther.mSurface);
67 3 : mMatchType = aOther.mMatchType;
68 3 : return *this;
69 : }
70 :
71 354 : DrawableSurface& Surface() { return mSurface; }
72 : const DrawableSurface& Surface() const { return mSurface; }
73 :
74 : /// @return true if this LookupResult contains a surface.
75 248 : explicit operator bool() const { return bool(mSurface); }
76 :
77 : /// @return what kind of match this is (exact, substitute, etc.)
78 248 : MatchType Type() const { return mMatchType; }
79 :
80 : private:
81 : LookupResult(const LookupResult&) = delete;
82 :
83 : DrawableSurface mSurface;
84 : MatchType mMatchType;
85 : };
86 :
87 : } // namespace image
88 : } // namespace mozilla
89 :
90 : #endif // mozilla_image_LookupResult_h
|