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/. */
7 * An ISurfaceProvider implemented for single-frame decoded surfaces.
10 #ifndef mozilla_image_DecodedSurfaceProvider_h
11 #define mozilla_image_DecodedSurfaceProvider_h
13 #include "IDecodingTask.h"
14 #include "ISurfaceProvider.h"
15 #include "SurfaceCache.h"
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
{
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 //////////////////////////////////////////////////////////////////////////////
38 bool IsFinished() const override
;
39 size_t LogicalSizeInBytes() const override
;
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 //////////////////////////////////////////////////////////////////////////////
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
; }
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.
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
;
82 } // namespace mozilla
84 #endif // mozilla_image_DecodedSurfaceProvider_h