ImageData.h 2.1 KB

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