ImageWrapper.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. #include "ImageWrapper.h"
  6. #include "mozilla/gfx/2D.h"
  7. #include "mozilla/RefPtr.h"
  8. #include "Orientation.h"
  9. #include "mozilla/MemoryReporting.h"
  10. namespace mozilla {
  11. using gfx::DataSourceSurface;
  12. using gfx::IntSize;
  13. using gfx::SamplingFilter;
  14. using gfx::SourceSurface;
  15. using layers::LayerManager;
  16. using layers::ImageContainer;
  17. namespace image {
  18. // Inherited methods from Image.
  19. already_AddRefed<ProgressTracker>
  20. ImageWrapper::GetProgressTracker()
  21. {
  22. return mInnerImage->GetProgressTracker();
  23. }
  24. size_t
  25. ImageWrapper::SizeOfSourceWithComputedFallback(MallocSizeOf aMallocSizeOf) const
  26. {
  27. return mInnerImage->SizeOfSourceWithComputedFallback(aMallocSizeOf);
  28. }
  29. void
  30. ImageWrapper::CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
  31. MallocSizeOf aMallocSizeOf) const
  32. {
  33. mInnerImage->CollectSizeOfSurfaces(aCounters, aMallocSizeOf);
  34. }
  35. void
  36. ImageWrapper::IncrementAnimationConsumers()
  37. {
  38. MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
  39. "with DecrementAnimationConsumers");
  40. mInnerImage->IncrementAnimationConsumers();
  41. }
  42. void
  43. ImageWrapper::DecrementAnimationConsumers()
  44. {
  45. MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization "
  46. "with IncrementAnimationConsumers");
  47. mInnerImage->DecrementAnimationConsumers();
  48. }
  49. #ifdef DEBUG
  50. uint32_t
  51. ImageWrapper::GetAnimationConsumers()
  52. {
  53. return mInnerImage->GetAnimationConsumers();
  54. }
  55. #endif
  56. nsresult
  57. ImageWrapper::OnImageDataAvailable(nsIRequest* aRequest,
  58. nsISupports* aContext,
  59. nsIInputStream* aInStr,
  60. uint64_t aSourceOffset,
  61. uint32_t aCount)
  62. {
  63. return mInnerImage->OnImageDataAvailable(aRequest, aContext, aInStr,
  64. aSourceOffset, aCount);
  65. }
  66. nsresult
  67. ImageWrapper::OnImageDataComplete(nsIRequest* aRequest,
  68. nsISupports* aContext,
  69. nsresult aStatus,
  70. bool aLastPart)
  71. {
  72. return mInnerImage->OnImageDataComplete(aRequest, aContext, aStatus,
  73. aLastPart);
  74. }
  75. void
  76. ImageWrapper::OnSurfaceDiscarded()
  77. {
  78. return mInnerImage->OnSurfaceDiscarded();
  79. }
  80. void
  81. ImageWrapper::SetInnerWindowID(uint64_t aInnerWindowId)
  82. {
  83. mInnerImage->SetInnerWindowID(aInnerWindowId);
  84. }
  85. uint64_t
  86. ImageWrapper::InnerWindowID() const
  87. {
  88. return mInnerImage->InnerWindowID();
  89. }
  90. bool
  91. ImageWrapper::HasError()
  92. {
  93. return mInnerImage->HasError();
  94. }
  95. void
  96. ImageWrapper::SetHasError()
  97. {
  98. mInnerImage->SetHasError();
  99. }
  100. ImageURL*
  101. ImageWrapper::GetURI()
  102. {
  103. return mInnerImage->GetURI();
  104. }
  105. // Methods inherited from XPCOM interfaces.
  106. NS_IMPL_ISUPPORTS(ImageWrapper, imgIContainer)
  107. NS_IMETHODIMP
  108. ImageWrapper::GetWidth(int32_t* aWidth)
  109. {
  110. return mInnerImage->GetWidth(aWidth);
  111. }
  112. NS_IMETHODIMP
  113. ImageWrapper::GetHeight(int32_t* aHeight)
  114. {
  115. return mInnerImage->GetHeight(aHeight);
  116. }
  117. NS_IMETHODIMP
  118. ImageWrapper::GetIntrinsicSize(nsSize* aSize)
  119. {
  120. return mInnerImage->GetIntrinsicSize(aSize);
  121. }
  122. NS_IMETHODIMP
  123. ImageWrapper::GetIntrinsicRatio(AspectRatio* aRatio)
  124. {
  125. return mInnerImage->GetIntrinsicRatio(aRatio);
  126. }
  127. NS_IMETHODIMP_(Orientation)
  128. ImageWrapper::GetOrientation()
  129. {
  130. return mInnerImage->GetOrientation();
  131. }
  132. NS_IMETHODIMP
  133. ImageWrapper::GetType(uint16_t* aType)
  134. {
  135. return mInnerImage->GetType(aType);
  136. }
  137. NS_IMETHODIMP
  138. ImageWrapper::GetAnimated(bool* aAnimated)
  139. {
  140. return mInnerImage->GetAnimated(aAnimated);
  141. }
  142. NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
  143. ImageWrapper::GetFrame(uint32_t aWhichFrame,
  144. uint32_t aFlags)
  145. {
  146. return mInnerImage->GetFrame(aWhichFrame, aFlags);
  147. }
  148. NS_IMETHODIMP_(already_AddRefed<SourceSurface>)
  149. ImageWrapper::GetFrameAtSize(const IntSize& aSize,
  150. uint32_t aWhichFrame,
  151. uint32_t aFlags)
  152. {
  153. return mInnerImage->GetFrameAtSize(aSize, aWhichFrame, aFlags);
  154. }
  155. NS_IMETHODIMP_(bool)
  156. ImageWrapper::WillDrawOpaqueNow()
  157. {
  158. return mInnerImage->WillDrawOpaqueNow();
  159. }
  160. NS_IMETHODIMP_(bool)
  161. ImageWrapper::IsImageContainerAvailable(LayerManager* aManager, uint32_t aFlags)
  162. {
  163. return mInnerImage->IsImageContainerAvailable(aManager, aFlags);
  164. }
  165. NS_IMETHODIMP_(already_AddRefed<ImageContainer>)
  166. ImageWrapper::GetImageContainer(LayerManager* aManager, uint32_t aFlags)
  167. {
  168. return mInnerImage->GetImageContainer(aManager, aFlags);
  169. }
  170. NS_IMETHODIMP_(DrawResult)
  171. ImageWrapper::Draw(gfxContext* aContext,
  172. const nsIntSize& aSize,
  173. const ImageRegion& aRegion,
  174. uint32_t aWhichFrame,
  175. SamplingFilter aSamplingFilter,
  176. const Maybe<SVGImageContext>& aSVGContext,
  177. uint32_t aFlags)
  178. {
  179. return mInnerImage->Draw(aContext, aSize, aRegion, aWhichFrame,
  180. aSamplingFilter, aSVGContext, aFlags);
  181. }
  182. NS_IMETHODIMP
  183. ImageWrapper::StartDecoding()
  184. {
  185. return mInnerImage->StartDecoding();
  186. }
  187. NS_IMETHODIMP
  188. ImageWrapper::RequestDecodeForSize(const nsIntSize& aSize, uint32_t aFlags)
  189. {
  190. return mInnerImage->RequestDecodeForSize(aSize, aFlags);
  191. }
  192. NS_IMETHODIMP
  193. ImageWrapper::LockImage()
  194. {
  195. MOZ_ASSERT(NS_IsMainThread(),
  196. "Main thread to encourage serialization with UnlockImage");
  197. return mInnerImage->LockImage();
  198. }
  199. NS_IMETHODIMP
  200. ImageWrapper::UnlockImage()
  201. {
  202. MOZ_ASSERT(NS_IsMainThread(),
  203. "Main thread to encourage serialization with LockImage");
  204. return mInnerImage->UnlockImage();
  205. }
  206. NS_IMETHODIMP
  207. ImageWrapper::RequestDiscard()
  208. {
  209. return mInnerImage->RequestDiscard();
  210. }
  211. NS_IMETHODIMP_(void)
  212. ImageWrapper::RequestRefresh(const TimeStamp& aTime)
  213. {
  214. return mInnerImage->RequestRefresh(aTime);
  215. }
  216. NS_IMETHODIMP
  217. ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode)
  218. {
  219. return mInnerImage->GetAnimationMode(aAnimationMode);
  220. }
  221. NS_IMETHODIMP
  222. ImageWrapper::SetAnimationMode(uint16_t aAnimationMode)
  223. {
  224. return mInnerImage->SetAnimationMode(aAnimationMode);
  225. }
  226. NS_IMETHODIMP
  227. ImageWrapper::ResetAnimation()
  228. {
  229. return mInnerImage->ResetAnimation();
  230. }
  231. NS_IMETHODIMP_(float)
  232. ImageWrapper::GetFrameIndex(uint32_t aWhichFrame)
  233. {
  234. return mInnerImage->GetFrameIndex(aWhichFrame);
  235. }
  236. NS_IMETHODIMP_(int32_t)
  237. ImageWrapper::GetFirstFrameDelay()
  238. {
  239. return mInnerImage->GetFirstFrameDelay();
  240. }
  241. NS_IMETHODIMP_(void)
  242. ImageWrapper::SetAnimationStartTime(const TimeStamp& aTime)
  243. {
  244. mInnerImage->SetAnimationStartTime(aTime);
  245. }
  246. void
  247. ImageWrapper::PropagateUseCounters(nsIDocument* aParentDocument)
  248. {
  249. mInnerImage->PropagateUseCounters(aParentDocument);
  250. }
  251. nsIntSize
  252. ImageWrapper::OptimalImageSizeForDest(const gfxSize& aDest,
  253. uint32_t aWhichFrame,
  254. SamplingFilter aSamplingFilter,
  255. uint32_t aFlags)
  256. {
  257. return mInnerImage->OptimalImageSizeForDest(aDest, aWhichFrame,
  258. aSamplingFilter, aFlags);
  259. }
  260. NS_IMETHODIMP_(nsIntRect)
  261. ImageWrapper::GetImageSpaceInvalidationRect(const nsIntRect& aRect)
  262. {
  263. return mInnerImage->GetImageSpaceInvalidationRect(aRect);
  264. }
  265. already_AddRefed<imgIContainer>
  266. ImageWrapper::Unwrap()
  267. {
  268. return mInnerImage->Unwrap();
  269. }
  270. } // namespace image
  271. } // namespace mozilla