dom/canvas/ImageData.h
author Carsten "Tomcat" Book <cbook@mozilla.com>
Mon, 12 Jan 2015 14:48:15 +0100
changeset 223354 a7f64e53893ef5d4bed1996acce1e0d459b8df8d
parent 223334 12dd1ad43923ac63fa00cdf1484991d5624c4daf
child 223555 3bff2bbe6677f590c280c380202f138ba2a020af
permissions -rw-r--r--
Backed out 12 changesets (bug 1096328) for M11 and M5 Test failures on a CLOSED TREE Backed out changeset 12dd1ad43923 (bug 1096328) Backed out changeset 4a067de94f22 (bug 1096328) Backed out changeset 676112a4f092 (bug 1096328) Backed out changeset e2e64e751ece (bug 1096328) Backed out changeset 9ed945e9a8a5 (bug 1096328) Backed out changeset 47be69b84be5 (bug 1096328) Backed out changeset d6e68ba4846d (bug 1096328) Backed out changeset 899d8cd8c4e8 (bug 1096328) Backed out changeset 55c831086864 (bug 1096328) Backed out changeset 6005fd357342 (bug 1096328) Backed out changeset 0f330a5dd346 (bug 1096328) Backed out changeset c37e10cff765 (bug 1096328)

/* -*- 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 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);

  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() = delete;

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

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_ImageData_h