Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/canvas/ImageBitmapRenderingContext.h
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#ifndef ImageBitmapRenderingContext_h
6
#define ImageBitmapRenderingContext_h
7
8
#include "nsICanvasRenderingContextInternal.h"
9
#include "nsWrapperCache.h"
10
11
namespace mozilla {
12
13
namespace gfx {
14
class DataSourceSurface;
15
class DrawTarget;
16
class SourceSurface;
17
}
18
19
namespace layers {
20
class Image;
21
class ImageContainer;
22
}
23
24
namespace dom {
25
26
/**
27
 * The purpose of ImageBitmapRenderingContext is to provide a faster and efficient
28
 * way to display ImageBitmap. Simply call TransferFromImageBitmap() then we'll transfer
29
 * the surface of ImageBitmap to this context and then to use it to display.
30
 *
31
 * See more details in spec: https://wiki.whatwg.org/wiki/OffscreenCanvas
32
 */
33
class ImageBitmapRenderingContext final :
34
  public nsICanvasRenderingContextInternal,
35
  public nsWrapperCache
36
{
37
  virtual ~ImageBitmapRenderingContext();
38
39
public:
40
  ImageBitmapRenderingContext();
41
42
  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
43
44
  // nsISupports interface + CC
45
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46
47
  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(ImageBitmapRenderingContext)
48
49
  void TransferImageBitmap(ImageBitmap& aImageBitmap);
50
  void TransferFromImageBitmap(ImageBitmap& aImageBitmap);
51
52
  // nsICanvasRenderingContextInternal
53
0
  virtual int32_t GetWidth() override { return mWidth; }
54
0
  virtual int32_t GetHeight() override { return mHeight; }
55
56
  NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override;
57
58
  NS_IMETHOD InitializeWithDrawTarget(nsIDocShell* aDocShell,
59
                                      NotNull<gfx::DrawTarget*> aTarget) override;
60
61
  virtual mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
62
  NS_IMETHOD GetInputStream(const char* aMimeType,
63
                            const char16_t* aEncoderOptions,
64
                            nsIInputStream** aStream) override;
65
66
  virtual already_AddRefed<mozilla::gfx::SourceSurface>
67
  GetSurfaceSnapshot(gfxAlphaType* aOutAlphaType) override;
68
69
  virtual void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override;
70
  virtual bool GetIsOpaque() override;
71
  NS_IMETHOD Reset() override;
72
  virtual already_AddRefed<Layer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
73
                                                 Layer* aOldLayer,
74
                                                 LayerManager* aManager) override;
75
  virtual void MarkContextClean() override;
76
77
  NS_IMETHOD Redraw(const gfxRect& aDirty) override;
78
  NS_IMETHOD SetIsIPC(bool aIsIPC) override;
79
80
  virtual void DidRefresh() override;
81
82
  virtual void MarkContextCleanForFrameCapture() override;
83
  virtual bool IsContextCleanForFrameCapture() override;
84
85
protected:
86
  already_AddRefed<gfx::DataSourceSurface> MatchWithIntrinsicSize();
87
  already_AddRefed<layers::Image> ClipToIntrinsicSize();
88
  int32_t mWidth;
89
  int32_t mHeight;
90
91
  RefPtr<layers::Image> mImage;
92
};
93
94
}
95
}
96
97
#endif /* ImageBitmapRenderingContext_h */