Bug 1718535 [wpt PR 29519] - [Credentialless] Fix flaky reporting-subresource-corp...
[gecko.git] / image / DecodedSurfaceProvider.h
blob2e21805dadcd45a698e320d46807ce630ba299c2
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 * An ISurfaceProvider implemented for single-frame decoded surfaces.
8 */
10 #ifndef mozilla_image_DecodedSurfaceProvider_h
11 #define mozilla_image_DecodedSurfaceProvider_h
13 #include "IDecodingTask.h"
14 #include "ISurfaceProvider.h"
15 #include "SurfaceCache.h"
17 namespace mozilla {
18 namespace image {
20 /**
21 * An ISurfaceProvider that manages the decoding of a single-frame image and
22 * stores the resulting surface.
24 class DecodedSurfaceProvider final : public ISurfaceProvider,
25 public IDecodingTask {
26 public:
27 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodedSurfaceProvider, override)
29 DecodedSurfaceProvider(NotNull<RasterImage*> aImage,
30 const SurfaceKey& aSurfaceKey,
31 NotNull<Decoder*> aDecoder);
33 //////////////////////////////////////////////////////////////////////////////
34 // ISurfaceProvider implementation.
35 //////////////////////////////////////////////////////////////////////////////
37 public:
38 bool IsFinished() const override;
39 size_t LogicalSizeInBytes() const override;
41 protected:
42 DrawableFrameRef DrawableRef(size_t aFrame) override;
43 bool IsLocked() const override { return bool(mLockRef); }
44 void SetLocked(bool aLocked) override;
46 //////////////////////////////////////////////////////////////////////////////
47 // IDecodingTask implementation.
48 //////////////////////////////////////////////////////////////////////////////
50 public:
51 void Run() override;
52 bool ShouldPreferSyncRun() const override;
54 // Full decodes are low priority compared to metadata decodes because they
55 // don't block layout or page load.
56 TaskPriority Priority() const override { return TaskPriority::eLow; }
58 private:
59 virtual ~DecodedSurfaceProvider();
61 void DropImageReference();
62 void CheckForNewSurface();
63 void FinishDecoding();
65 /// The image associated with our decoder. Dropped after decoding.
66 RefPtr<RasterImage> mImage;
68 /// Mutex protecting access to mDecoder.
69 Mutex mMutex;
71 /// The decoder that will generate our surface. Dropped after decoding.
72 RefPtr<Decoder> mDecoder;
74 /// Our surface. Initially null until it's generated by the decoder.
75 RefPtr<imgFrame> mSurface;
77 /// A drawable reference to our service; used for locking.
78 DrawableFrameRef mLockRef;
81 } // namespace image
82 } // namespace mozilla
84 #endif // mozilla_image_DecodedSurfaceProvider_h