ImageWrapper.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #ifndef mozilla_image_ImageWrapper_h
  6. #define mozilla_image_ImageWrapper_h
  7. #include "mozilla/MemoryReporting.h"
  8. #include "Image.h"
  9. namespace mozilla {
  10. namespace image {
  11. /**
  12. * Abstract superclass for Images that wrap other Images.
  13. */
  14. class ImageWrapper : public Image
  15. {
  16. public:
  17. NS_DECL_ISUPPORTS
  18. NS_DECL_IMGICONTAINER
  19. // Inherited methods from Image.
  20. virtual already_AddRefed<ProgressTracker> GetProgressTracker() override;
  21. virtual size_t
  22. SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const override;
  23. virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
  24. MallocSizeOf aMallocSizeOf) const override;
  25. virtual void IncrementAnimationConsumers() override;
  26. virtual void DecrementAnimationConsumers() override;
  27. #ifdef DEBUG
  28. virtual uint32_t GetAnimationConsumers() override;
  29. #endif
  30. virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
  31. nsISupports* aContext,
  32. nsIInputStream* aInStr,
  33. uint64_t aSourceOffset,
  34. uint32_t aCount) override;
  35. virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
  36. nsISupports* aContext,
  37. nsresult aStatus,
  38. bool aLastPart) override;
  39. virtual void OnSurfaceDiscarded() override;
  40. virtual void SetInnerWindowID(uint64_t aInnerWindowId) override;
  41. virtual uint64_t InnerWindowID() const override;
  42. virtual bool HasError() override;
  43. virtual void SetHasError() override;
  44. virtual ImageURL* GetURI() override;
  45. protected:
  46. explicit ImageWrapper(Image* aInnerImage)
  47. : mInnerImage(aInnerImage)
  48. {
  49. MOZ_ASSERT(aInnerImage, "Need an image to wrap");
  50. }
  51. virtual ~ImageWrapper() { }
  52. /**
  53. * Returns a weak reference to the inner image wrapped by this ImageWrapper.
  54. */
  55. Image* InnerImage() const { return mInnerImage.get(); }
  56. void SetInnerImage(Image* aInnerImage)
  57. {
  58. MOZ_ASSERT(aInnerImage, "Need an image to wrap");
  59. mInnerImage = aInnerImage;
  60. }
  61. private:
  62. RefPtr<Image> mInnerImage;
  63. };
  64. } // namespace image
  65. } // namespace mozilla
  66. #endif // mozilla_image_ImageWrapper_h