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
*,
84 already_AddRefed
<layers::FwdTransactionTracker
> UseCompositableForwarder(
85 layers::CompositableForwarder
* aForwarder
) override
;
87 bool IsOffscreenCanvas() { return !!mOffscreenCanvas
; }
90 void GetCanvas(dom::OwningHTMLCanvasElementOrOffscreenCanvas
&) const;
92 void Configure(const dom::GPUCanvasConfiguration
& aConfig
);
95 RefPtr
<Texture
> GetCurrentTexture(ErrorResult
& aRv
);
96 void MaybeQueueSwapChainPresent();
97 Maybe
<layers::SurfaceDescriptor
> SwapChainPresent();
99 void InvalidateCanvasContent();
102 gfx::IntSize mCanvasSize
;
103 std::unique_ptr
<dom::GPUCanvasConfiguration
> mConfig
;
104 bool mPendingSwapChainPresent
= false;
105 bool mWaitingCanvasRendererInitialized
= false;
107 RefPtr
<WebGPUChild
> mBridge
;
108 RefPtr
<Texture
> mTexture
;
109 gfx::SurfaceFormat mGfxFormat
= gfx::SurfaceFormat::R8G8B8A8
;
111 Maybe
<layers::RemoteTextureId
> mLastRemoteTextureId
;
112 Maybe
<layers::RemoteTextureOwnerId
> mRemoteTextureOwnerId
;
113 RefPtr
<layers::FwdTransactionTracker
> mFwdTransactionTracker
;
114 bool mUseExternalTextureInSwapChain
= false;
115 bool mNewTextureRequested
= false;
118 } // namespace webgpu
119 } // namespace mozilla
121 #endif // GPU_CanvasContext_H_