Bug 1839076 - Remove duplicate prefs from mobile.js r=geckoview-reviewers,amejiamarmol
[gecko.git] / image / DecodedSurfaceProvider.h
blob07e722daa6edc21bf3916751d9a89921b09dc84b
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 //////////////////////////////////////////////////////////////////////////////
59 // WebRenderImageProvider implementation.
60 //////////////////////////////////////////////////////////////////////////////
62 public:
63 nsresult UpdateKey(layers::RenderRootStateManager* aManager,
64 wr::IpcResourceUpdateQueue& aResources,
65 wr::ImageKey& aKey) override;
67 private:
68 virtual ~DecodedSurfaceProvider();
70 void DropImageReference();
71 void CheckForNewSurface();
72 void FinishDecoding();
74 /// The image associated with our decoder. Dropped after decoding.
75 RefPtr<RasterImage> mImage;
77 /// Mutex protecting access to mDecoder.
78 Mutex mMutex MOZ_UNANNOTATED;
80 /// The decoder that will generate our surface. Dropped after decoding.
81 RefPtr<Decoder> mDecoder;
83 /// Our surface. Initially null until it's generated by the decoder.
84 RefPtr<imgFrame> mSurface;
86 /// A drawable reference to our service; used for locking.
87 DrawableFrameRef mLockRef;
90 } // namespace image
91 } // namespace mozilla
93 #endif // mozilla_image_DecodedSurfaceProvider_h