DecodedSurfaceProvider.h 2.6 KB

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