Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / dom / canvas / ImageData.h
blob71a1e803758b69ea073915a321dfe063420fe3eb
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 public:
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;
42 private:
43 JS::Heap<JSObject*> mData;
45 public:
46 ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
47 : mWidth(aWidth), mHeight(aHeight), mData(&aData) {
48 HoldData();
51 static already_AddRefed<ImageData> Constructor(const GlobalObject& aGlobal,
52 const uint32_t aWidth,
53 const uint32_t aHeight,
54 ErrorResult& aRv);
56 static already_AddRefed<ImageData> Constructor(
57 const GlobalObject& aGlobal, const Uint8ClampedArray& aData,
58 const uint32_t aWidth, const Optional<uint32_t>& aHeight,
59 ErrorResult& aRv);
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;
78 private:
79 void HoldData();
80 void DropData();
82 ImageData() = delete;
83 ~ImageData() { DropData(); }
86 } // namespace dom
87 } // namespace mozilla
89 #endif // mozilla_dom_ImageData_h