content/canvas/public/nsICanvasRenderingContextInternal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/public/nsICanvasRenderingContextInternal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     1.4 +/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsICanvasRenderingContextInternal_h___
    1.10 +#define nsICanvasRenderingContextInternal_h___
    1.11 +
    1.12 +#include "mozilla/gfx/2D.h"
    1.13 +#include "nsISupports.h"
    1.14 +#include "nsIInputStream.h"
    1.15 +#include "nsIDocShell.h"
    1.16 +#include "mozilla/dom/HTMLCanvasElement.h"
    1.17 +#include "GraphicsFilter.h"
    1.18 +#include "mozilla/RefPtr.h"
    1.19 +
    1.20 +#define NS_ICANVASRENDERINGCONTEXTINTERNAL_IID \
    1.21 +{ 0x3cc9e801, 0x1806, 0x4ff6, \
    1.22 +  { 0x86, 0x14, 0xf9, 0xd0, 0xf4, 0xfb, 0x3b, 0x08 } }
    1.23 +
    1.24 +class gfxContext;
    1.25 +class gfxASurface;
    1.26 +class nsDisplayListBuilder;
    1.27 +
    1.28 +namespace mozilla {
    1.29 +namespace layers {
    1.30 +class CanvasLayer;
    1.31 +class LayerManager;
    1.32 +}
    1.33 +namespace ipc {
    1.34 +class Shmem;
    1.35 +}
    1.36 +namespace gfx {
    1.37 +class SourceSurface;
    1.38 +}
    1.39 +}
    1.40 +
    1.41 +class nsICanvasRenderingContextInternal : public nsISupports {
    1.42 +public:
    1.43 +  typedef mozilla::layers::CanvasLayer CanvasLayer;
    1.44 +  typedef mozilla::layers::LayerManager LayerManager;
    1.45 +
    1.46 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
    1.47 +
    1.48 +  void SetCanvasElement(mozilla::dom::HTMLCanvasElement* aParentCanvas)
    1.49 +  {
    1.50 +    mCanvasElement = aParentCanvas;
    1.51 +  }
    1.52 +  mozilla::dom::HTMLCanvasElement* GetParentObject() const
    1.53 +  {
    1.54 +    return mCanvasElement;
    1.55 +  }
    1.56 +
    1.57 +#ifdef DEBUG
    1.58 +    // Useful for testing
    1.59 +    virtual int32_t GetWidth() const = 0;
    1.60 +    virtual int32_t GetHeight() const = 0;
    1.61 +#endif
    1.62 +
    1.63 +  // Sets the dimensions of the canvas, in pixels.  Called
    1.64 +  // whenever the size of the element changes.
    1.65 +  NS_IMETHOD SetDimensions(int32_t width, int32_t height) = 0;
    1.66 +
    1.67 +  NS_IMETHOD InitializeWithSurface(nsIDocShell *docShell, gfxASurface *surface, int32_t width, int32_t height) = 0;
    1.68 +
    1.69 +  // Creates an image buffer. Returns null on failure.
    1.70 +  virtual void GetImageBuffer(uint8_t** aImageBuffer, int32_t* aFormat) = 0;
    1.71 +
    1.72 +  // Gives you a stream containing the image represented by this context.
    1.73 +  // The format is given in aMimeTime, for example "image/png".
    1.74 +  //
    1.75 +  // If the image format does not support transparency or aIncludeTransparency
    1.76 +  // is false, alpha will be discarded and the result will be the image
    1.77 +  // composited on black.
    1.78 +  NS_IMETHOD GetInputStream(const char *aMimeType,
    1.79 +                            const char16_t *aEncoderOptions,
    1.80 +                            nsIInputStream **aStream) = 0;
    1.81 +  
    1.82 +  // This gets an Azure SourceSurface for the canvas, this will be a snapshot
    1.83 +  // of the canvas at the time it was called.
    1.84 +  // If aPremultAlpha is provided, then it assumed the callee can handle
    1.85 +  // un-premultiplied surfaces, and *aPremultAlpha will be set to false
    1.86 +  // if one is returned.
    1.87 +  virtual mozilla::TemporaryRef<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(bool* aPremultAlpha = nullptr) = 0;
    1.88 +
    1.89 +  // If this context is opaque, the backing store of the canvas should
    1.90 +  // be created as opaque; all compositing operators should assume the
    1.91 +  // dst alpha is always 1.0.  If this is never called, the context
    1.92 +  // defaults to false (not opaque).
    1.93 +  NS_IMETHOD SetIsOpaque(bool isOpaque) = 0;
    1.94 +  virtual bool GetIsOpaque() = 0;
    1.95 +
    1.96 +  // Invalidate this context and release any held resources, in preperation
    1.97 +  // for possibly reinitializing with SetDimensions/InitializeWithSurface.
    1.98 +  NS_IMETHOD Reset() = 0;
    1.99 +
   1.100 +  // Return the CanvasLayer for this context, creating
   1.101 +  // one for the given layer manager if not available.
   1.102 +  virtual already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
   1.103 +                                                       CanvasLayer *aOldLayer,
   1.104 +                                                       LayerManager *aManager) = 0;
   1.105 +
   1.106 +  // Return true if the canvas should be forced to be "inactive" to ensure
   1.107 +  // it can be drawn to the screen even if it's too large to be blitted by
   1.108 +  // an accelerated CanvasLayer.
   1.109 +  virtual bool ShouldForceInactiveLayer(LayerManager *aManager) { return false; }
   1.110 +
   1.111 +  virtual void MarkContextClean() = 0;
   1.112 +
   1.113 +  // Redraw the dirty rectangle of this canvas.
   1.114 +  NS_IMETHOD Redraw(const gfxRect &dirty) = 0;
   1.115 +
   1.116 +  NS_IMETHOD SetContextOptions(JSContext* aCx, JS::Handle<JS::Value> aOptions) { return NS_OK; }
   1.117 +
   1.118 +  //
   1.119 +  // shmem support
   1.120 +  //
   1.121 +
   1.122 +  // If this context can be set to use Mozilla's Shmem segments as its backing
   1.123 +  // store, this will set it to that state. Note that if you have drawn
   1.124 +  // anything into this canvas before changing the shmem state, it will be
   1.125 +  // lost.
   1.126 +  NS_IMETHOD SetIsIPC(bool isIPC) = 0;
   1.127 +
   1.128 +protected:
   1.129 +  nsRefPtr<mozilla::dom::HTMLCanvasElement> mCanvasElement;
   1.130 +};
   1.131 +
   1.132 +namespace mozilla {
   1.133 +namespace dom {
   1.134 +
   1.135 +}
   1.136 +}
   1.137 +
   1.138 +NS_DEFINE_STATIC_IID_ACCESSOR(nsICanvasRenderingContextInternal,
   1.139 +                              NS_ICANVASRENDERINGCONTEXTINTERNAL_IID)
   1.140 +
   1.141 +#endif /* nsICanvasRenderingContextInternal_h___ */

mercurial