2012-03-16 02:44:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ImageData_h
|
|
|
|
#define mozilla_dom_ImageData_h
|
|
|
|
|
|
|
|
#include "nsIDOMCanvasRenderingContext2D.h"
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2014-01-28 05:04:40 -08:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2012-03-16 02:44:08 -07:00
|
|
|
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-02-26 13:36:35 -08:00
|
|
|
#include "nsISupportsImpl.h"
|
2013-09-08 20:28:48 -07:00
|
|
|
#include "js/GCAPI.h"
|
2012-03-16 02:44:08 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
class ImageData MOZ_FINAL : public nsISupports
|
2012-03-16 02:44:08 -07:00
|
|
|
{
|
2014-06-26 06:30:49 -07:00
|
|
|
~ImageData()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ImageData);
|
|
|
|
DropData();
|
|
|
|
}
|
|
|
|
|
2012-03-16 02:44:08 -07:00
|
|
|
public:
|
|
|
|
ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
|
|
|
|
: mWidth(aWidth)
|
|
|
|
, mHeight(aHeight)
|
|
|
|
, mData(&aData)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ImageData);
|
|
|
|
HoldData();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData)
|
|
|
|
|
2014-08-27 15:43:55 -07:00
|
|
|
static already_AddRefed<ImageData>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const uint32_t aWidth,
|
|
|
|
const uint32_t aHeight,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
static already_AddRefed<ImageData>
|
|
|
|
Constructor(const GlobalObject& aGlobal,
|
|
|
|
const Uint8ClampedArray& aData,
|
|
|
|
const uint32_t aWidth,
|
|
|
|
const Optional<uint32_t>& aHeight,
|
|
|
|
ErrorResult& aRv);
|
2014-01-28 05:04:40 -08:00
|
|
|
|
2012-10-22 10:08:52 -07:00
|
|
|
uint32_t Width() const
|
2012-03-16 02:44:08 -07:00
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
2012-10-22 10:08:52 -07:00
|
|
|
uint32_t Height() const
|
2012-03-16 02:44:08 -07:00
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
2014-06-11 13:26:52 -07:00
|
|
|
void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const
|
2012-06-13 08:14:15 -07:00
|
|
|
{
|
2014-06-11 13:26:52 -07:00
|
|
|
aData.set(GetDataObject());
|
2012-06-13 08:14:15 -07:00
|
|
|
}
|
2012-10-22 10:08:52 -07:00
|
|
|
JSObject* GetDataObject() const
|
2012-03-16 02:44:08 -07:00
|
|
|
{
|
2013-09-08 20:28:48 -07:00
|
|
|
JS::ExposeObjectToActiveJS(mData);
|
2012-03-16 02:44:08 -07:00
|
|
|
return mData;
|
|
|
|
}
|
|
|
|
|
2015-01-08 13:56:42 -08:00
|
|
|
bool WrapObject(JSContext* aCx, JS::MutableHandle<JSObject*> aReflector);
|
2012-10-22 10:08:52 -07:00
|
|
|
|
2012-03-16 02:44:08 -07:00
|
|
|
private:
|
|
|
|
void HoldData();
|
|
|
|
void DropData();
|
|
|
|
|
2015-01-06 15:35:02 -08:00
|
|
|
ImageData() = delete;
|
2012-03-16 02:44:08 -07:00
|
|
|
|
|
|
|
uint32_t mWidth, mHeight;
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Heap<JSObject*> mData;
|
2012-03-16 02:44:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_ImageData_h
|