author Jeff Gilbert <>
Wed, 12 Apr 2017 02:55:23 -0700
changeset 403458 f0e8fd36b730c776f054d462e0375081288c6ff0
parent 403427 27c85d8a0ce5524b338e5aea8e491df6af7f7ac3
child 413770 5b713fb1cd98370f0bd7645f848e5972c2f198dc
permissions -rw-r--r--
Bug 1355763 - Add gfxAlphaType for specifying opaque/premult/non-premult. - r=daoshengmu MozReview-Commit-ID: Jzr8aPYlEcO

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

#ifndef ImageBitmapRenderingContext_h
#define ImageBitmapRenderingContext_h

#include "nsICanvasRenderingContextInternal.h"
#include "nsWrapperCache.h"

namespace mozilla {

namespace gfx {
class DataSourceSurface;
class DrawTarget;
class SourceSurface;

namespace layers {
class Image;
class ImageContainer;

namespace dom {

 * The purpose of ImageBitmapRenderingContext is to provide a faster and efficient
 * way to display ImageBitmap. Simply call TransferFromImageBitmap() then we'll transfer
 * the surface of ImageBitmap to this context and then to use it to display.
 * See more details in spec:
class ImageBitmapRenderingContext final :
  public nsICanvasRenderingContextInternal,
  public nsWrapperCache
  virtual ~ImageBitmapRenderingContext();


  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;

  // nsISupports interface + CC


  void TransferImageBitmap(ImageBitmap& aImageBitmap);
  void TransferFromImageBitmap(ImageBitmap& aImageBitmap);

  // nsICanvasRenderingContextInternal
  virtual int32_t GetWidth() const override;
  virtual int32_t GetHeight() const override;

  NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;

  NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aDocShell,
                                      NotNull<gfx::DrawTarget*> aTarget) override;

  virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
  NS_IMETHOD GetInputStream(const char* aMimeType,
                            const char16_t* aEncoderOptions,
                            nsIInputStream** aStream) override;

  virtual already_AddRefed<mozilla::gfx::SourceSurface>
  GetSurfaceSnapshot(gfxAlphaType* aOutAlphaType) override;

  NS_IMETHOD SetIsOpaque(bool aIsOpaque) override;
  virtual bool GetIsOpaque() override;
  NS_IMETHOD Reset() override;
  virtual already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                                 Layer* aOldLayer,
                                                 LayerManager* aManager,
                                                 bool aMirror = false) override;
  virtual void MarkContextClean() override;

  NS_IMETHOD Redraw(const gfxRect& aDirty) override;
  NS_IMETHOD SetIsIPC(bool aIsIPC) override;

  virtual void DidRefresh() override;

  virtual void MarkContextCleanForFrameCapture() override;
  virtual bool IsContextCleanForFrameCapture() override;

  already_AddRefed<gfx::DataSourceSurface> MatchWithIntrinsicSize();
  already_AddRefed<layers::Image> ClipToIntrinsicSize();
  int32_t mWidth;
  int32_t mHeight;

  RefPtr<layers::Image> mImage;


#endif /* ImageBitmapRenderingContext_h */