DecodedSurfaceProvider.h (3095B)
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 : public ISurfaceProvider, 25 public IDecodingTask { 26 public: 27 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodedSurfaceProvider, override) 28 29 DecodedSurfaceProvider(NotNull<RasterImage*> aImage, 30 const SurfaceKey& aSurfaceKey, 31 NotNull<Decoder*> aDecoder); 32 33 ////////////////////////////////////////////////////////////////////////////// 34 // ISurfaceProvider implementation. 35 ////////////////////////////////////////////////////////////////////////////// 36 37 public: 38 bool IsFinished() const override; 39 size_t LogicalSizeInBytes() const override; 40 41 protected: 42 DrawableFrameRef DrawableRef(size_t aFrame) override; 43 bool IsLocked() const override { return bool(mLockRef); } 44 void SetLocked(bool aLocked) override; 45 46 ////////////////////////////////////////////////////////////////////////////// 47 // IDecodingTask implementation. 48 ////////////////////////////////////////////////////////////////////////////// 49 50 public: 51 void Run() override; 52 bool ShouldPreferSyncRun() const override; 53 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; } 57 58 ////////////////////////////////////////////////////////////////////////////// 59 // WebRenderImageProvider implementation. 60 ////////////////////////////////////////////////////////////////////////////// 61 62 public: 63 nsresult UpdateKey(layers::RenderRootStateManager* aManager, 64 wr::IpcResourceUpdateQueue& aResources, 65 wr::ImageKey& aKey) override; 66 67 private: 68 virtual ~DecodedSurfaceProvider(); 69 70 void DropImageReference(); 71 void CheckForNewSurface(); 72 void FinishDecoding(); 73 74 /// The image associated with our decoder. Dropped after decoding. 75 RefPtr<RasterImage> mImage; 76 77 /// Mutex protecting access to mDecoder. 78 Mutex mMutex MOZ_UNANNOTATED; 79 80 /// The decoder that will generate our surface. Dropped after decoding. 81 RefPtr<Decoder> mDecoder; 82 83 /// Our surface. Initially null until it's generated by the decoder. 84 RefPtr<imgFrame> mSurface; 85 86 /// A drawable reference to our service; used for locking. 87 DrawableFrameRef mLockRef; 88 }; 89 90 } // namespace image 91 } // namespace mozilla 92 93 #endif // mozilla_image_DecodedSurfaceProvider_h