Bug 1732409 let fake:true getUserMedia() parameter override loopback prefs r=jib
[gecko.git] / dom / canvas / ImageData.h
blob80b4f09a3bf10c0914ae193238d0c8cc99eff0a8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 et tw=78: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ImageData_h
8 #define mozilla_dom_ImageData_h
10 #include <cstdint>
11 #include <utility>
12 #include "js/RootingAPI.h"
13 #include "mozilla/AlreadyAddRefed.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/dom/TypedArray.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsISupports.h"
19 class JSObject;
20 class nsIGlobalObject;
21 struct JSContext;
22 struct JSStructuredCloneReader;
23 struct JSStructuredCloneWriter;
25 namespace mozilla {
26 class ErrorResult;
28 namespace dom {
30 class GlobalObject;
31 template <typename T>
32 class Optional;
34 class ImageData final : public nsISupports {
35 ~ImageData() { DropData(); }
37 public:
38 ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
39 : mWidth(aWidth), mHeight(aHeight), mData(&aData) {
40 HoldData();
43 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
44 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData)
46 static already_AddRefed<ImageData> Constructor(const GlobalObject& aGlobal,
47 const uint32_t aWidth,
48 const uint32_t aHeight,
49 ErrorResult& aRv);
51 static already_AddRefed<ImageData> Constructor(
52 const GlobalObject& aGlobal, const Uint8ClampedArray& aData,
53 const uint32_t aWidth, const Optional<uint32_t>& aHeight,
54 ErrorResult& aRv);
56 uint32_t Width() const { return mWidth; }
57 uint32_t Height() const { return mHeight; }
58 void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const {
59 aData.set(GetDataObject());
61 JSObject* GetDataObject() const { return mData; }
63 bool WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto,
64 JS::MutableHandle<JSObject*> aReflector);
66 //[Serializable] implementation
67 static already_AddRefed<ImageData> ReadStructuredClone(
68 JSContext* aCx, nsIGlobalObject* aGlobal,
69 JSStructuredCloneReader* aReader);
70 bool WriteStructuredClone(JSContext* aCx,
71 JSStructuredCloneWriter* aWriter) const;
73 private:
74 void HoldData();
75 void DropData();
77 ImageData() = delete;
79 uint32_t mWidth, mHeight;
80 JS::Heap<JSObject*> mData;
83 } // namespace dom
84 } // namespace mozilla
86 #endif // mozilla_dom_ImageData_h