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"
18 struct GPUCanvasConfiguration
;
19 enum class GPUTextureFormat
: uint8_t;
25 class CanvasContext final
: public nsICanvasRenderingContextInternal
,
26 public nsWrapperCache
{
28 virtual ~CanvasContext();
32 // nsISupports interface + CC
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CanvasContext
)
38 JSObject
* WrapObject(JSContext
* aCx
,
39 JS::Handle
<JSObject
*> aGivenProto
) override
;
41 public: // nsICanvasRenderingContextInternal
42 int32_t GetWidth() override
{ return mWidth
; }
43 int32_t GetHeight() override
{ return mHeight
; }
45 NS_IMETHOD
SetDimensions(int32_t aWidth
, int32_t aHeight
) override
{
50 NS_IMETHOD
InitializeWithDrawTarget(
51 nsIDocShell
* aShell
, NotNull
<gfx::DrawTarget
*> aTarget
) override
{
55 bool UpdateWebRenderCanvasData(mozilla::nsDisplayListBuilder
* aBuilder
,
56 WebRenderCanvasData
* aCanvasData
) override
;
58 bool InitializeCanvasRenderer(nsDisplayListBuilder
* aBuilder
,
59 layers::CanvasRenderer
* aRenderer
) override
;
60 mozilla::UniquePtr
<uint8_t[]> GetImageBuffer(
61 int32_t* out_format
, gfx::IntSize
* out_imageSize
) override
;
62 NS_IMETHOD
GetInputStream(const char* aMimeType
,
63 const nsAString
& aEncoderOptions
,
64 nsIInputStream
** aStream
) override
;
65 already_AddRefed
<mozilla::gfx::SourceSurface
> GetSurfaceSnapshot(
66 gfxAlphaType
* aOutAlphaType
) override
;
68 void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue
) override
{}
69 bool GetIsOpaque() override
{ return true; }
71 void ResetBitmap() override
{ Unconfigure(); }
73 void MarkContextClean() override
{}
75 NS_IMETHOD
Redraw(const gfxRect
& aDirty
) override
{ return NS_OK
; }
77 void DidRefresh() override
{}
79 void MarkContextCleanForFrameCapture() override
{}
80 Watchable
<FrameCaptureState
>* GetFrameCaptureState() override
{
85 void Configure(const dom::GPUCanvasConfiguration
& aDesc
);
88 dom::GPUTextureFormat
GetPreferredFormat(Adapter
& aAdapter
) const;
89 RefPtr
<Texture
> GetCurrentTexture(ErrorResult
& aRv
);
90 void MaybeQueueSwapChainPresent();
91 void SwapChainPresent();
95 uint32_t mWidth
= 0, mHeight
= 0;
96 bool mPendingSwapChainPresent
= false;
98 RefPtr
<WebGPUChild
> mBridge
;
99 RefPtr
<Texture
> mTexture
;
100 gfx::SurfaceFormat mGfxFormat
= gfx::SurfaceFormat::R8G8B8A8
;
102 Maybe
<layers::RemoteTextureId
> mLastRemoteTextureId
;
103 Maybe
<layers::RemoteTextureOwnerId
> mRemoteTextureOwnerId
;
106 } // namespace webgpu
107 } // namespace mozilla
109 #endif // GPU_CanvasContext_H_