SurfaceFromElementResult.h (3345B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_SurfaceFromElementResult_h 8 #define mozilla_SurfaceFromElementResult_h 9 10 #include <cstdint> 11 12 #include "ImageContainer.h" 13 #include "gfxTypes.h" 14 #include "mozilla/gfx/Point.h" 15 #include "nsCOMPtr.h" 16 17 class imgIContainer; 18 class imgIRequest; 19 class nsIPrincipal; 20 class nsLayoutUtils; 21 22 namespace mozilla { 23 24 namespace dom { 25 class CanvasRenderingContext2D; 26 class ImageBitmap; 27 } // namespace dom 28 29 namespace gfx { 30 class SourceSurface; 31 } 32 33 struct DirectDrawInfo { 34 /* imgIContainer to directly draw to a context */ 35 nsCOMPtr<imgIContainer> mImgContainer; 36 /* which frame to draw */ 37 uint32_t mWhichFrame; 38 /* imgIContainer flags to use when drawing */ 39 uint32_t mDrawingFlags; 40 }; 41 42 struct SurfaceFromElementResult { 43 friend class mozilla::dom::CanvasRenderingContext2D; 44 friend class mozilla::dom::ImageBitmap; 45 friend class ::nsLayoutUtils; 46 47 /* If SFEResult contains a valid surface, it either mLayersImage or 48 * mSourceSurface will be non-null, and GetSourceSurface() will not be null. 49 * 50 * For valid surfaces, mSourceSurface may be null if mLayersImage is 51 * non-null, but GetSourceSurface() will create mSourceSurface from 52 * mLayersImage when called. 53 */ 54 55 /* Video elements (at least) often are already decoded as layers::Images. */ 56 RefPtr<mozilla::layers::Image> mLayersImage; 57 58 protected: 59 /* GetSourceSurface() fills this and returns its non-null value if this 60 * SFEResult was successful. */ 61 RefPtr<mozilla::gfx::SourceSurface> mSourceSurface; 62 63 public: 64 /* Contains info for drawing when there is no mSourceSurface. */ 65 DirectDrawInfo mDrawInfo; 66 67 /* The size of the surface */ 68 mozilla::gfx::IntSize mSize; 69 /* The size the surface is intended to be rendered at */ 70 mozilla::gfx::IntSize mIntrinsicSize; 71 /* The crop rect of the surface, indicating what subset is valid. This will 72 * always be Nothing() unless SFE_ALLOW_UNCROPPED is set. */ 73 mozilla::Maybe<mozilla::gfx::IntRect> mCropRect; 74 /* The principal associated with the element whose surface was returned. 75 If there is a surface, this will never be null. */ 76 nsCOMPtr<nsIPrincipal> mPrincipal; 77 /* The image request, if the element is an nsIImageLoadingContent */ 78 nsCOMPtr<imgIRequest> mImageRequest; 79 /* True if cross-origins redirects have been done in order to load this 80 * resource */ 81 bool mHadCrossOriginRedirects; 82 /* Whether the element was "write only", that is, the bits should not be 83 * exposed to content */ 84 bool mIsWriteOnly; 85 /* Whether the element was still loading. Some consumers need to handle 86 this case specially. */ 87 bool mIsStillLoading; 88 /* Whether the element has a valid size. */ 89 bool mHasSize; 90 /* Whether the element used CORS when loading. */ 91 bool mCORSUsed; 92 93 gfxAlphaType mAlphaType; 94 95 // Methods: 96 97 SurfaceFromElementResult(); 98 99 // Gets mSourceSurface, or makes a SourceSurface from mLayersImage. 100 const RefPtr<mozilla::gfx::SourceSurface>& GetSourceSurface(); 101 }; 102 103 } // namespace mozilla 104 105 #endif // mozilla_SurfaceFromElementResult_h