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 "ImageContainer.h"
11 #include "gfxTypes.h"
12 #include "mozilla/gfx/Point.h"
13 #include "nsCOMPtr.h"
14 #include <cstdint>
15 
16 class imgIContainer;
17 class imgIRequest;
18 class nsIPrincipal;
19 class nsLayoutUtils;
20 
21 namespace mozilla {
22 
23 namespace dom {
24 class CanvasRenderingContext2D;
25 }
26 
27 namespace gfx {
28 class SourceSurface;
29 }
30 
31 struct DirectDrawInfo {
32   /* imgIContainer to directly draw to a context */
33   nsCOMPtr<imgIContainer> mImgContainer;
34   /* which frame to draw */
35   uint32_t mWhichFrame;
36   /* imgIContainer flags to use when drawing */
37   uint32_t mDrawingFlags;
38 };
39 
40 struct SurfaceFromElementResult {
41   friend class mozilla::dom::CanvasRenderingContext2D;
42   friend class ::nsLayoutUtils;
43 
44   /* If SFEResult contains a valid surface, it either mLayersImage or
45    * mSourceSurface will be non-null, and GetSourceSurface() will not be null.
46    *
47    * For valid surfaces, mSourceSurface may be null if mLayersImage is
48    * non-null, but GetSourceSurface() will create mSourceSurface from
49    * mLayersImage when called.
50    */
51 
52   /* Video elements (at least) often are already decoded as layers::Images. */
53   RefPtr<mozilla::layers::Image> mLayersImage;
54 
55  protected:
56   /* GetSourceSurface() fills this and returns its non-null value if this
57    * SFEResult was successful. */
58   RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
59 
60  public:
61   /* Contains info for drawing when there is no mSourceSurface. */
62   DirectDrawInfo mDrawInfo;
63 
64   /* The size of the surface */
65   mozilla::gfx::IntSize mSize;
66   /* The size the surface is intended to be rendered at */
67   mozilla::gfx::IntSize mIntrinsicSize;
68   /* The principal associated with the element whose surface was returned.
69      If there is a surface, this will never be null. */
70   nsCOMPtr<nsIPrincipal> mPrincipal;
71   /* The image request, if the element is an nsIImageLoadingContent */
72   nsCOMPtr<imgIRequest> mImageRequest;
73   /* True if cross-origins redirects have been done in order to load this
74    * resource */
75   bool mHadCrossOriginRedirects;
76   /* Whether the element was "write only", that is, the bits should not be
77    * exposed to content */
78   bool mIsWriteOnly;
79   /* Whether the element was still loading.  Some consumers need to handle
80      this case specially. */
81   bool mIsStillLoading;
82   /* Whether the element has a valid size. */
83   bool mHasSize;
84   /* Whether the element used CORS when loading. */
85   bool mCORSUsed;
86 
87   gfxAlphaType mAlphaType;
88 
89   // Methods:
90 
91   SurfaceFromElementResult();
92 
93   // Gets mSourceSurface, or makes a SourceSurface from mLayersImage.
94   const RefPtr<mozilla::gfx::SourceSurface>& GetSourceSurface();
95 };
96 
97 }  // namespace mozilla
98 
99 #endif  // mozilla_SurfaceFromElementResult_h
100