content/canvas/src/ImageData.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/ImageData.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 et tw=78: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_ImageData_h
    1.11 +#define mozilla_dom_ImageData_h
    1.12 +
    1.13 +#include "nsIDOMCanvasRenderingContext2D.h"
    1.14 +
    1.15 +#include "mozilla/Attributes.h"
    1.16 +#include "mozilla/dom/BindingUtils.h"
    1.17 +#include "mozilla/dom/TypedArray.h"
    1.18 +#include <stdint.h>
    1.19 +
    1.20 +#include "nsCycleCollectionParticipant.h"
    1.21 +#include "nsISupportsImpl.h"
    1.22 +#include "js/GCAPI.h"
    1.23 +
    1.24 +namespace mozilla {
    1.25 +namespace dom {
    1.26 +
    1.27 +class ImageData MOZ_FINAL : public nsISupports
    1.28 +{
    1.29 +public:
    1.30 +  ImageData(uint32_t aWidth, uint32_t aHeight, JSObject& aData)
    1.31 +    : mWidth(aWidth)
    1.32 +    , mHeight(aHeight)
    1.33 +    , mData(&aData)
    1.34 +  {
    1.35 +    MOZ_COUNT_CTOR(ImageData);
    1.36 +    HoldData();
    1.37 +  }
    1.38 +
    1.39 +  ~ImageData()
    1.40 +  {
    1.41 +    MOZ_COUNT_DTOR(ImageData);
    1.42 +    DropData();
    1.43 +  }
    1.44 +
    1.45 +  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1.46 +  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageData)
    1.47 +
    1.48 +  static ImageData* Constructor(const GlobalObject& aGlobal,
    1.49 +                                const uint32_t aWidth,
    1.50 +                                const uint32_t aHeight,
    1.51 +                                ErrorResult& aRv);
    1.52 +
    1.53 +  static ImageData* Constructor(const GlobalObject& aGlobal,
    1.54 +                                const Uint8ClampedArray& aData,
    1.55 +                                const uint32_t aWidth,
    1.56 +                                const Optional<uint32_t>& aHeight,
    1.57 +                                ErrorResult& aRv);
    1.58 +
    1.59 +  uint32_t Width() const
    1.60 +  {
    1.61 +    return mWidth;
    1.62 +  }
    1.63 +  uint32_t Height() const
    1.64 +  {
    1.65 +    return mHeight;
    1.66 +  }
    1.67 +  void GetData(JSContext* cx, JS::MutableHandle<JSObject*> aData) const
    1.68 +  {
    1.69 +    aData.set(GetDataObject());
    1.70 +  }
    1.71 +  JSObject* GetDataObject() const
    1.72 +  {
    1.73 +    JS::ExposeObjectToActiveJS(mData);
    1.74 +    return mData;
    1.75 +  }
    1.76 +
    1.77 +  JSObject* WrapObject(JSContext* cx);
    1.78 +
    1.79 +private:
    1.80 +  void HoldData();
    1.81 +  void DropData();
    1.82 +
    1.83 +  ImageData() MOZ_DELETE;
    1.84 +
    1.85 +  uint32_t mWidth, mHeight;
    1.86 +  JS::Heap<JSObject*> mData;
    1.87 +};
    1.88 +
    1.89 +} // namespace dom
    1.90 +} // namespace mozilla
    1.91 +
    1.92 +#endif // mozilla_dom_ImageData_h

mercurial