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
{
36 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
37 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData
)
39 const uint32_t mWidth
;
40 const uint32_t mHeight
;
43 JS::Heap
<JSObject
*> mData
;
46 ImageData(uint32_t aWidth
, uint32_t aHeight
, JSObject
& aData
)
47 : mWidth(aWidth
), mHeight(aHeight
), mData(&aData
) {
51 static already_AddRefed
<ImageData
> Constructor(const GlobalObject
& aGlobal
,
52 const uint32_t aWidth
,
53 const uint32_t aHeight
,
56 static already_AddRefed
<ImageData
> Constructor(
57 const GlobalObject
& aGlobal
, const Uint8ClampedArray
& aData
,
58 const uint32_t aWidth
, const Optional
<uint32_t>& aHeight
,
61 uint32_t Width() const { return mWidth
; }
62 uint32_t Height() const { return mHeight
; }
63 void GetData(JSContext
* cx
, JS::MutableHandle
<JSObject
*> aData
) const {
64 aData
.set(GetDataObject());
66 JSObject
* GetDataObject() const { return mData
; }
68 bool WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
,
69 JS::MutableHandle
<JSObject
*> aReflector
);
71 //[Serializable] implementation
72 static already_AddRefed
<ImageData
> ReadStructuredClone(
73 JSContext
* aCx
, nsIGlobalObject
* aGlobal
,
74 JSStructuredCloneReader
* aReader
);
75 bool WriteStructuredClone(JSContext
* aCx
,
76 JSStructuredCloneWriter
* aWriter
) const;
83 ~ImageData() { DropData(); }
87 } // namespace mozilla
89 #endif // mozilla_dom_ImageData_h