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