Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "ImageWrapper.h" |
michael@0 | 7 | #include "mozilla/gfx/2D.h" |
michael@0 | 8 | #include "mozilla/RefPtr.h" |
michael@0 | 9 | #include "Orientation.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/MemoryReporting.h" |
michael@0 | 12 | |
michael@0 | 13 | using mozilla::gfx::DataSourceSurface; |
michael@0 | 14 | using mozilla::gfx::SourceSurface; |
michael@0 | 15 | using mozilla::layers::LayerManager; |
michael@0 | 16 | using mozilla::layers::ImageContainer; |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | namespace image { |
michael@0 | 20 | |
michael@0 | 21 | // Inherited methods from Image. |
michael@0 | 22 | |
michael@0 | 23 | nsresult |
michael@0 | 24 | ImageWrapper::Init(const char* aMimeType, uint32_t aFlags) |
michael@0 | 25 | { |
michael@0 | 26 | return mInnerImage->Init(aMimeType, aFlags); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | already_AddRefed<imgStatusTracker> |
michael@0 | 30 | ImageWrapper::GetStatusTracker() |
michael@0 | 31 | { |
michael@0 | 32 | return mInnerImage->GetStatusTracker(); |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | nsIntRect |
michael@0 | 36 | ImageWrapper::FrameRect(uint32_t aWhichFrame) |
michael@0 | 37 | { |
michael@0 | 38 | return mInnerImage->FrameRect(aWhichFrame); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | uint32_t |
michael@0 | 42 | ImageWrapper::SizeOfData() |
michael@0 | 43 | { |
michael@0 | 44 | return mInnerImage->SizeOfData(); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | size_t |
michael@0 | 48 | ImageWrapper::HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const |
michael@0 | 49 | { |
michael@0 | 50 | return mInnerImage->HeapSizeOfSourceWithComputedFallback(aMallocSizeOf); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | size_t |
michael@0 | 54 | ImageWrapper::HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const |
michael@0 | 55 | { |
michael@0 | 56 | return mInnerImage->HeapSizeOfDecodedWithComputedFallback(aMallocSizeOf); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | size_t |
michael@0 | 60 | ImageWrapper::NonHeapSizeOfDecoded() const |
michael@0 | 61 | { |
michael@0 | 62 | return mInnerImage->NonHeapSizeOfDecoded(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | size_t |
michael@0 | 66 | ImageWrapper::OutOfProcessSizeOfDecoded() const |
michael@0 | 67 | { |
michael@0 | 68 | return mInnerImage->OutOfProcessSizeOfDecoded(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | void |
michael@0 | 72 | ImageWrapper::IncrementAnimationConsumers() |
michael@0 | 73 | { |
michael@0 | 74 | MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization " |
michael@0 | 75 | "with DecrementAnimationConsumers"); |
michael@0 | 76 | mInnerImage->IncrementAnimationConsumers(); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void |
michael@0 | 80 | ImageWrapper::DecrementAnimationConsumers() |
michael@0 | 81 | { |
michael@0 | 82 | MOZ_ASSERT(NS_IsMainThread(), "Main thread only to encourage serialization " |
michael@0 | 83 | "with IncrementAnimationConsumers"); |
michael@0 | 84 | mInnerImage->DecrementAnimationConsumers(); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | #ifdef DEBUG |
michael@0 | 88 | uint32_t |
michael@0 | 89 | ImageWrapper::GetAnimationConsumers() |
michael@0 | 90 | { |
michael@0 | 91 | return mInnerImage->GetAnimationConsumers(); |
michael@0 | 92 | } |
michael@0 | 93 | #endif |
michael@0 | 94 | |
michael@0 | 95 | nsresult |
michael@0 | 96 | ImageWrapper::OnImageDataAvailable(nsIRequest* aRequest, |
michael@0 | 97 | nsISupports* aContext, |
michael@0 | 98 | nsIInputStream* aInStr, |
michael@0 | 99 | uint64_t aSourceOffset, |
michael@0 | 100 | uint32_t aCount) |
michael@0 | 101 | { |
michael@0 | 102 | return mInnerImage->OnImageDataAvailable(aRequest, aContext, aInStr, |
michael@0 | 103 | aSourceOffset, aCount); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | nsresult |
michael@0 | 107 | ImageWrapper::OnImageDataComplete(nsIRequest* aRequest, |
michael@0 | 108 | nsISupports* aContext, |
michael@0 | 109 | nsresult aStatus, |
michael@0 | 110 | bool aLastPart) |
michael@0 | 111 | { |
michael@0 | 112 | return mInnerImage->OnImageDataComplete(aRequest, aContext, aStatus, aLastPart); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | nsresult |
michael@0 | 116 | ImageWrapper::OnNewSourceData() |
michael@0 | 117 | { |
michael@0 | 118 | return mInnerImage->OnNewSourceData(); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | void |
michael@0 | 122 | ImageWrapper::SetInnerWindowID(uint64_t aInnerWindowId) |
michael@0 | 123 | { |
michael@0 | 124 | mInnerImage->SetInnerWindowID(aInnerWindowId); |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | uint64_t |
michael@0 | 128 | ImageWrapper::InnerWindowID() const |
michael@0 | 129 | { |
michael@0 | 130 | return mInnerImage->InnerWindowID(); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | bool |
michael@0 | 134 | ImageWrapper::HasError() |
michael@0 | 135 | { |
michael@0 | 136 | return mInnerImage->HasError(); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | void |
michael@0 | 140 | ImageWrapper::SetHasError() |
michael@0 | 141 | { |
michael@0 | 142 | mInnerImage->SetHasError(); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | ImageURL* |
michael@0 | 146 | ImageWrapper::GetURI() |
michael@0 | 147 | { |
michael@0 | 148 | return mInnerImage->GetURI(); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | // Methods inherited from XPCOM interfaces. |
michael@0 | 152 | |
michael@0 | 153 | NS_IMPL_ISUPPORTS(ImageWrapper, imgIContainer) |
michael@0 | 154 | |
michael@0 | 155 | NS_IMETHODIMP |
michael@0 | 156 | ImageWrapper::GetWidth(int32_t* aWidth) |
michael@0 | 157 | { |
michael@0 | 158 | return mInnerImage->GetWidth(aWidth); |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | NS_IMETHODIMP |
michael@0 | 162 | ImageWrapper::GetHeight(int32_t* aHeight) |
michael@0 | 163 | { |
michael@0 | 164 | return mInnerImage->GetHeight(aHeight); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | NS_IMETHODIMP |
michael@0 | 168 | ImageWrapper::GetIntrinsicSize(nsSize* aSize) |
michael@0 | 169 | { |
michael@0 | 170 | return mInnerImage->GetIntrinsicSize(aSize); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | NS_IMETHODIMP |
michael@0 | 174 | ImageWrapper::GetIntrinsicRatio(nsSize* aSize) |
michael@0 | 175 | { |
michael@0 | 176 | return mInnerImage->GetIntrinsicRatio(aSize); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | NS_IMETHODIMP_(Orientation) |
michael@0 | 180 | ImageWrapper::GetOrientation() |
michael@0 | 181 | { |
michael@0 | 182 | return mInnerImage->GetOrientation(); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | NS_IMETHODIMP |
michael@0 | 186 | ImageWrapper::GetType(uint16_t* aType) |
michael@0 | 187 | { |
michael@0 | 188 | return mInnerImage->GetType(aType); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | NS_IMETHODIMP_(uint16_t) |
michael@0 | 192 | ImageWrapper::GetType() |
michael@0 | 193 | { |
michael@0 | 194 | return mInnerImage->GetType(); |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | NS_IMETHODIMP |
michael@0 | 198 | ImageWrapper::GetAnimated(bool* aAnimated) |
michael@0 | 199 | { |
michael@0 | 200 | return mInnerImage->GetAnimated(aAnimated); |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | NS_IMETHODIMP_(TemporaryRef<SourceSurface>) |
michael@0 | 204 | ImageWrapper::GetFrame(uint32_t aWhichFrame, |
michael@0 | 205 | uint32_t aFlags) |
michael@0 | 206 | { |
michael@0 | 207 | return mInnerImage->GetFrame(aWhichFrame, aFlags); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | NS_IMETHODIMP_(bool) |
michael@0 | 211 | ImageWrapper::FrameIsOpaque(uint32_t aWhichFrame) |
michael@0 | 212 | { |
michael@0 | 213 | return mInnerImage->FrameIsOpaque(aWhichFrame); |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | NS_IMETHODIMP |
michael@0 | 217 | ImageWrapper::GetImageContainer(LayerManager* aManager, ImageContainer** _retval) |
michael@0 | 218 | { |
michael@0 | 219 | return mInnerImage->GetImageContainer(aManager, _retval); |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | NS_IMETHODIMP |
michael@0 | 223 | ImageWrapper::Draw(gfxContext* aContext, |
michael@0 | 224 | GraphicsFilter aFilter, |
michael@0 | 225 | const gfxMatrix& aUserSpaceToImageSpace, |
michael@0 | 226 | const gfxRect& aFill, |
michael@0 | 227 | const nsIntRect& aSubimage, |
michael@0 | 228 | const nsIntSize& aViewportSize, |
michael@0 | 229 | const SVGImageContext* aSVGContext, |
michael@0 | 230 | uint32_t aWhichFrame, |
michael@0 | 231 | uint32_t aFlags) |
michael@0 | 232 | { |
michael@0 | 233 | return mInnerImage->Draw(aContext, aFilter, aUserSpaceToImageSpace, aFill, |
michael@0 | 234 | aSubimage, aViewportSize, aSVGContext, aWhichFrame, |
michael@0 | 235 | aFlags); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | NS_IMETHODIMP |
michael@0 | 239 | ImageWrapper::RequestDecode() |
michael@0 | 240 | { |
michael@0 | 241 | return mInnerImage->RequestDecode(); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | NS_IMETHODIMP |
michael@0 | 245 | ImageWrapper::StartDecoding() |
michael@0 | 246 | { |
michael@0 | 247 | return mInnerImage->StartDecoding(); |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | bool |
michael@0 | 251 | ImageWrapper::IsDecoded() |
michael@0 | 252 | { |
michael@0 | 253 | return mInnerImage->IsDecoded(); |
michael@0 | 254 | } |
michael@0 | 255 | |
michael@0 | 256 | NS_IMETHODIMP |
michael@0 | 257 | ImageWrapper::LockImage() |
michael@0 | 258 | { |
michael@0 | 259 | MOZ_ASSERT(NS_IsMainThread(), |
michael@0 | 260 | "Main thread to encourage serialization with UnlockImage"); |
michael@0 | 261 | return mInnerImage->LockImage(); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | NS_IMETHODIMP |
michael@0 | 265 | ImageWrapper::UnlockImage() |
michael@0 | 266 | { |
michael@0 | 267 | MOZ_ASSERT(NS_IsMainThread(), |
michael@0 | 268 | "Main thread to encourage serialization with LockImage"); |
michael@0 | 269 | return mInnerImage->UnlockImage(); |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | NS_IMETHODIMP |
michael@0 | 273 | ImageWrapper::RequestDiscard() |
michael@0 | 274 | { |
michael@0 | 275 | return mInnerImage->RequestDiscard(); |
michael@0 | 276 | } |
michael@0 | 277 | |
michael@0 | 278 | NS_IMETHODIMP_(void) |
michael@0 | 279 | ImageWrapper::RequestRefresh(const mozilla::TimeStamp& aTime) |
michael@0 | 280 | { |
michael@0 | 281 | return mInnerImage->RequestRefresh(aTime); |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | NS_IMETHODIMP |
michael@0 | 285 | ImageWrapper::GetAnimationMode(uint16_t* aAnimationMode) |
michael@0 | 286 | { |
michael@0 | 287 | return mInnerImage->GetAnimationMode(aAnimationMode); |
michael@0 | 288 | } |
michael@0 | 289 | |
michael@0 | 290 | NS_IMETHODIMP |
michael@0 | 291 | ImageWrapper::SetAnimationMode(uint16_t aAnimationMode) |
michael@0 | 292 | { |
michael@0 | 293 | return mInnerImage->SetAnimationMode(aAnimationMode); |
michael@0 | 294 | } |
michael@0 | 295 | |
michael@0 | 296 | NS_IMETHODIMP |
michael@0 | 297 | ImageWrapper::ResetAnimation() |
michael@0 | 298 | { |
michael@0 | 299 | return mInnerImage->ResetAnimation(); |
michael@0 | 300 | } |
michael@0 | 301 | |
michael@0 | 302 | NS_IMETHODIMP_(float) |
michael@0 | 303 | ImageWrapper::GetFrameIndex(uint32_t aWhichFrame) |
michael@0 | 304 | { |
michael@0 | 305 | return mInnerImage->GetFrameIndex(aWhichFrame); |
michael@0 | 306 | } |
michael@0 | 307 | |
michael@0 | 308 | NS_IMETHODIMP_(int32_t) |
michael@0 | 309 | ImageWrapper::GetFirstFrameDelay() |
michael@0 | 310 | { |
michael@0 | 311 | return mInnerImage->GetFirstFrameDelay(); |
michael@0 | 312 | } |
michael@0 | 313 | |
michael@0 | 314 | NS_IMETHODIMP_(void) |
michael@0 | 315 | ImageWrapper::SetAnimationStartTime(const mozilla::TimeStamp& aTime) |
michael@0 | 316 | { |
michael@0 | 317 | mInnerImage->SetAnimationStartTime(aTime); |
michael@0 | 318 | } |
michael@0 | 319 | |
michael@0 | 320 | } // namespace image |
michael@0 | 321 | } // namespace mozilla |