From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- dom/webgpu/CanvasContext.h | 108 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 dom/webgpu/CanvasContext.h (limited to 'dom/webgpu/CanvasContext.h') diff --git a/dom/webgpu/CanvasContext.h b/dom/webgpu/CanvasContext.h new file mode 100644 index 0000000000..e9d3dba3c0 --- /dev/null +++ b/dom/webgpu/CanvasContext.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef GPU_CanvasContext_H_ +#define GPU_CanvasContext_H_ + +#include "nsICanvasRenderingContextInternal.h" +#include "nsWrapperCache.h" +#include "ObjectModel.h" +#include "mozilla/layers/LayersTypes.h" +#include "mozilla/webrender/WebRenderAPI.h" + +namespace mozilla { +namespace dom { +class OwningHTMLCanvasElementOrOffscreenCanvas; +class Promise; +struct GPUCanvasConfiguration; +enum class GPUTextureFormat : uint8_t; +} // namespace dom +namespace webgpu { +class Adapter; +class Texture; + +class CanvasContext final : public nsICanvasRenderingContextInternal, + public nsWrapperCache { + private: + virtual ~CanvasContext(); + void Cleanup(); + + public: + // nsISupports interface + CC + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(CanvasContext) + + CanvasContext(); + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + public: // nsICanvasRenderingContextInternal + int32_t GetWidth() override { return mCanvasSize.width; } + int32_t GetHeight() override { return mCanvasSize.height; } + + NS_IMETHOD SetDimensions(int32_t aWidth, int32_t aHeight) override; + NS_IMETHOD InitializeWithDrawTarget( + nsIDocShell* aShell, NotNull aTarget) override { + return NS_OK; + } + + bool UpdateWebRenderCanvasData(mozilla::nsDisplayListBuilder* aBuilder, + WebRenderCanvasData* aCanvasData) override; + + bool InitializeCanvasRenderer(nsDisplayListBuilder* aBuilder, + layers::CanvasRenderer* aRenderer) override; + mozilla::UniquePtr GetImageBuffer( + int32_t* out_format, gfx::IntSize* out_imageSize) override; + NS_IMETHOD GetInputStream(const char* aMimeType, + const nsAString& aEncoderOptions, + nsIInputStream** aStream) override; + already_AddRefed GetSurfaceSnapshot( + gfxAlphaType* aOutAlphaType) override; + + void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override {} + bool GetIsOpaque() override { return true; } + + void ResetBitmap() override { Unconfigure(); } + + void MarkContextClean() override {} + + NS_IMETHOD Redraw(const gfxRect& aDirty) override { return NS_OK; } + + void DidRefresh() override {} + + void MarkContextCleanForFrameCapture() override {} + Watchable* GetFrameCaptureState() override { + return nullptr; + } + + public: + void GetCanvas(dom::OwningHTMLCanvasElementOrOffscreenCanvas&) const; + + void Configure(const dom::GPUCanvasConfiguration& aDesc); + void Unconfigure(); + + RefPtr GetCurrentTexture(ErrorResult& aRv); + void MaybeQueueSwapChainPresent(); + void SwapChainPresent(); + void ForceNewFrame(); + + private: + gfx::IntSize mCanvasSize; + std::unique_ptr mConfig; + bool mPendingSwapChainPresent = false; + + RefPtr mBridge; + RefPtr mTexture; + gfx::SurfaceFormat mGfxFormat = gfx::SurfaceFormat::R8G8B8A8; + + Maybe mLastRemoteTextureId; + Maybe mRemoteTextureOwnerId; +}; + +} // namespace webgpu +} // namespace mozilla + +#endif // GPU_CanvasContext_H_ -- cgit v1.2.3