michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 et tw=78: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_ImageData_h michael@0: #define mozilla_dom_ImageData_h michael@0: michael@0: #include "nsIDOMCanvasRenderingContext2D.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/BindingUtils.h" michael@0: #include "mozilla/dom/TypedArray.h" michael@0: #include michael@0: michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsISupportsImpl.h" michael@0: #include "js/GCAPI.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ImageData MOZ_FINAL : public nsISupports michael@0: { michael@0: public: michael@0: ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData) michael@0: : mWidth(aWidth) michael@0: , mHeight(aHeight) michael@0: , mData(&aData) michael@0: { michael@0: MOZ_COUNT_CTOR(ImageData); michael@0: HoldData(); michael@0: } michael@0: michael@0: ~ImageData() michael@0: { michael@0: MOZ_COUNT_DTOR(ImageData); michael@0: DropData(); michael@0: } michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData) michael@0: michael@0: static ImageData* Constructor(const GlobalObject& aGlobal, michael@0: const uint32_t aWidth, michael@0: const uint32_t aHeight, michael@0: ErrorResult& aRv); michael@0: michael@0: static ImageData* Constructor(const GlobalObject& aGlobal, michael@0: const Uint8ClampedArray& aData, michael@0: const uint32_t aWidth, michael@0: const Optional& aHeight, michael@0: ErrorResult& aRv); michael@0: michael@0: uint32_t Width() const michael@0: { michael@0: return mWidth; michael@0: } michael@0: uint32_t Height() const michael@0: { michael@0: return mHeight; michael@0: } michael@0: void GetData(JSContext* cx, JS::MutableHandle aData) const michael@0: { michael@0: aData.set(GetDataObject()); michael@0: } michael@0: JSObject* GetDataObject() const michael@0: { michael@0: JS::ExposeObjectToActiveJS(mData); michael@0: return mData; michael@0: } michael@0: michael@0: JSObject* WrapObject(JSContext* cx); michael@0: michael@0: private: michael@0: void HoldData(); michael@0: void DropData(); michael@0: michael@0: ImageData() MOZ_DELETE; michael@0: michael@0: uint32_t mWidth, mHeight; michael@0: JS::Heap mData; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_ImageData_h