dom/canvas/ImageData.h
author Nick Alexander <nalexander@mozilla.com>
Tue, 18 Nov 2014 17:28:47 -0600
changeset 226083 6a35dcdb17d6e080d1349d0aabe16cd41d1cf517
parent 217828 1c197ac16fbcddd61f6f8713ca4ef92df1e4487f
child 227830 cfc484f4f6a40aca213908ef68d5c4038b295194
permissions -rw-r--r--
Bug 1086693 - Part 2: Generate and build Android SDK JNI wrappers. r=gps, a=lsblakk

/* -*- 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"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/TypedArray.h"
#include <stdint.h>

#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include "js/GCAPI.h"

namespace mozilla {
namespace dom {

class ImageData MOZ_FINAL : public nsISupports
{
  ~ImageData()
  {
    MOZ_COUNT_DTOR(ImageData);
    DropData();
  }

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)

  static ImageData* Constructor(const GlobalObject& aGlobal,
                                const uint32_t aWidth,
                                const uint32_t aHeight,
                                ErrorResult& aRv);

  static ImageData* Constructor(const GlobalObject& aGlobal,
                                const Uint8ClampedArray& aData,
                                const uint32_t aWidth,
                                const Optional<uint32_t>& aHeight,
                                ErrorResult& aRv);

  uint32_t Width() const
  {
    return mWidth;
  }
  uint32_t Height() const
  {
    return mHeight;
  }
  void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const
  {
    aData.set(GetDataObject());
  }
  JSObject* GetDataObject() const
  {
    JS::ExposeObjectToActiveJS(mData);
    return mData;
  }

  JSObject* WrapObject(JSContext* cx);

private:
  void HoldData();
  void DropData();

  ImageData() MOZ_DELETE;

  uint32_t mWidth, mHeight;
  JS::Heap<JSObject*> mData;
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_ImageData_h