|
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/. */ |
|
6 |
|
7 #ifndef mozilla_dom_ImageData_h |
|
8 #define mozilla_dom_ImageData_h |
|
9 |
|
10 #include "nsIDOMCanvasRenderingContext2D.h" |
|
11 |
|
12 #include "mozilla/Attributes.h" |
|
13 #include "mozilla/dom/BindingUtils.h" |
|
14 #include "mozilla/dom/TypedArray.h" |
|
15 #include <stdint.h> |
|
16 |
|
17 #include "nsCycleCollectionParticipant.h" |
|
18 #include "nsISupportsImpl.h" |
|
19 #include "js/GCAPI.h" |
|
20 |
|
21 namespace mozilla { |
|
22 namespace dom { |
|
23 |
|
24 class ImageData MOZ_FINAL : public nsISupports |
|
25 { |
|
26 public: |
|
27 ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData) |
|
28 : mWidth(aWidth) |
|
29 , mHeight(aHeight) |
|
30 , mData(&aData) |
|
31 { |
|
32 MOZ_COUNT_CTOR(ImageData); |
|
33 HoldData(); |
|
34 } |
|
35 |
|
36 ~ImageData() |
|
37 { |
|
38 MOZ_COUNT_DTOR(ImageData); |
|
39 DropData(); |
|
40 } |
|
41 |
|
42 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
43 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData) |
|
44 |
|
45 static ImageData* Constructor(const GlobalObject& aGlobal, |
|
46 const uint32_t aWidth, |
|
47 const uint32_t aHeight, |
|
48 ErrorResult& aRv); |
|
49 |
|
50 static ImageData* Constructor(const GlobalObject& aGlobal, |
|
51 const Uint8ClampedArray& aData, |
|
52 const uint32_t aWidth, |
|
53 const Optional<uint32_t>& aHeight, |
|
54 ErrorResult& aRv); |
|
55 |
|
56 uint32_t Width() const |
|
57 { |
|
58 return mWidth; |
|
59 } |
|
60 uint32_t Height() const |
|
61 { |
|
62 return mHeight; |
|
63 } |
|
64 void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const |
|
65 { |
|
66 aData.set(GetDataObject()); |
|
67 } |
|
68 JSObject* GetDataObject() const |
|
69 { |
|
70 JS::ExposeObjectToActiveJS(mData); |
|
71 return mData; |
|
72 } |
|
73 |
|
74 JSObject* WrapObject(JSContext* cx); |
|
75 |
|
76 private: |
|
77 void HoldData(); |
|
78 void DropData(); |
|
79 |
|
80 ImageData() MOZ_DELETE; |
|
81 |
|
82 uint32_t mWidth, mHeight; |
|
83 JS::Heap<JSObject*> mData; |
|
84 }; |
|
85 |
|
86 } // namespace dom |
|
87 } // namespace mozilla |
|
88 |
|
89 #endif // mozilla_dom_ImageData_h |