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
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"
20 class nsIGlobalObject
;
22 struct JSStructuredCloneReader
;
23 struct JSStructuredCloneWriter
;
34 class ImageData final
: public nsISupports
{
35 ~ImageData() { DropData(); }
38 ImageData(uint32_t aWidth
, uint32_t aHeight
, JSObject
& aData
)
39 : mWidth(aWidth
), mHeight(aHeight
), mData(&aData
) {
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
,
51 static already_AddRefed
<ImageData
> Constructor(
52 const GlobalObject
& aGlobal
, const Uint8ClampedArray
& aData
,
53 const uint32_t aWidth
, const Optional
<uint32_t>& aHeight
,
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;
79 uint32_t mWidth
, mHeight
;
80 JS::Heap
<JSObject
*> mData
;
84 } // namespace mozilla
86 #endif // mozilla_dom_ImageData_h