1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GPU_CanvasContext_H_
7 #define GPU_CanvasContext_H_
9 #include "nsICanvasRenderingContextInternal.h"
10 #include "nsWrapperCache.h"
11 #include "ObjectModel.h"
12 #include "mozilla/layers/LayersTypes.h"
13 #include "mozilla/webrender/WebRenderAPI.h"
17 class OwningHTMLCanvasElementOrOffscreenCanvas
;
19 struct GPUCanvasConfiguration
;
20 enum class GPUTextureFormat
: uint8_t;
26 class CanvasContext final
: public nsICanvasRenderingContextInternal
,
27 public nsWrapperCache
{
29 virtual ~CanvasContext();
33 // nsISupports interface + CC
34 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
35 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CanvasContext
)
39 JSObject
* WrapObject(JSContext
* aCx
,
40 JS::Handle
<JSObject
*> aGivenProto
) override
;
42 public: // nsICanvasRenderingContextInternal
43 int32_t GetWidth() override
{ return mCanvasSize
.width
; }
44 int32_t GetHeight() override
{ return mCanvasSize
.height
; }
46 NS_IMETHOD
SetDimensions(int32_t aWidth
, int32_t aHeight
) override
;
47 NS_IMETHOD
InitializeWithDrawTarget(
48 nsIDocShell
* aShell
, NotNull
<gfx::DrawTarget
*> aTarget
) override
{
52 bool UpdateWebRenderCanvasData(mozilla::nsDisplayListBuilder
* aBuilder
,
53 WebRenderCanvasData
* aCanvasData
) override
;
55 bool InitializeCanvasRenderer(nsDisplayListBuilder
* aBuilder
,
56 layers::CanvasRenderer
* aRenderer
) override
;
57 mozilla::UniquePtr
<uint8_t[]> GetImageBuffer(
58 int32_t* out_format
, gfx::IntSize
* out_imageSize
) override
;
59 NS_IMETHOD
GetInputStream(const char* aMimeType
,
60 const nsAString
& aEncoderOptions
,
61 nsIInputStream
** aStream
) override
;
62 already_AddRefed
<mozilla::gfx::SourceSurface
> GetSurfaceSnapshot(
63 gfxAlphaType
* aOutAlphaType
) override
;
65 void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue
) override
{}
66 bool GetIsOpaque() override
{ return true; }
68 void ResetBitmap() override
{ Unconfigure(); }
70 void MarkContextClean() override
{}
72 NS_IMETHOD
Redraw(const gfxRect
& aDirty
) override
{ return NS_OK
; }
74 void DidRefresh() override
{}
76 void MarkContextCleanForFrameCapture() override
{}
77 Watchable
<FrameCaptureState
>* GetFrameCaptureState() override
{
81 Maybe
<layers::SurfaceDescriptor
> GetFrontBuffer(WebGLFramebufferJS
*,
85 void GetCanvas(dom::OwningHTMLCanvasElementOrOffscreenCanvas
&) const;
87 void Configure(const dom::GPUCanvasConfiguration
& aConfig
);
90 RefPtr
<Texture
> GetCurrentTexture(ErrorResult
& aRv
);
91 void MaybeQueueSwapChainPresent();
92 Maybe
<layers::SurfaceDescriptor
> SwapChainPresent();
94 void InvalidateCanvasContent();
97 gfx::IntSize mCanvasSize
;
98 std::unique_ptr
<dom::GPUCanvasConfiguration
> mConfig
;
99 bool mPendingSwapChainPresent
= false;
100 bool mWaitingCanvasRendererInitialized
= false;
102 RefPtr
<WebGPUChild
> mBridge
;
103 RefPtr
<Texture
> mTexture
;
104 gfx::SurfaceFormat mGfxFormat
= gfx::SurfaceFormat::R8G8B8A8
;
106 Maybe
<layers::RemoteTextureId
> mLastRemoteTextureId
;
107 Maybe
<layers::RemoteTextureOwnerId
> mRemoteTextureOwnerId
;
108 bool mUseExternalTextureInSwapChain
= false;
109 bool mNewTextureRequested
= false;
112 } // namespace webgpu
113 } // namespace mozilla
115 #endif // GPU_CanvasContext_H_