From 9e3c08db40b8916968b9f30096c7be3f00ce9647 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:44:51 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- gfx/layers/CanvasRenderer.h | 151 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 gfx/layers/CanvasRenderer.h (limited to 'gfx/layers/CanvasRenderer.h') diff --git a/gfx/layers/CanvasRenderer.h b/gfx/layers/CanvasRenderer.h new file mode 100644 index 0000000000..e2c69e95cc --- /dev/null +++ b/gfx/layers/CanvasRenderer.h @@ -0,0 +1,151 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* 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 GFX_CANVASRENDERER_H +#define GFX_CANVASRENDERER_H + +#include // for weak_ptr +#include // for uint32_t +#include "GLContextTypes.h" // for GLContext +#include "gfxContext.h" // for gfxContext, etc +#include "gfxTypes.h" +#include "gfxPlatform.h" // for gfxImageFormat +#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc +#include "mozilla/Preferences.h" // for Preferences +#include "mozilla/RefPtr.h" // for RefPtr +#include "mozilla/gfx/2D.h" // for DrawTarget +#include "mozilla/Maybe.h" +#include "mozilla/mozalloc.h" // for operator delete, etc +#include "mozilla/WeakPtr.h" // for WeakPtr +#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc +#include "nsICanvasRenderingContextInternal.h" + +namespace mozilla { +namespace layers { + +class KnowsCompositor; +class PersistentBufferProvider; +class WebRenderCanvasRendererAsync; + +TextureType TexTypeForWebgl(KnowsCompositor*); + +struct CanvasRendererData final { + CanvasRendererData(); + ~CanvasRendererData(); + + WeakPtr mContext; + + // The size of the canvas content + gfx::IntSize mSize = {0, 0}; + + bool mDoPaintCallbacks = false; + bool mIsOpaque = true; + bool mIsAlphaPremult = true; + + gl::OriginPos mOriginPos = gl::OriginPos::TopLeft; + + // Used in remote texture push callback + Maybe mRemoteTextureOwnerIdOfPushCallback = Nothing(); + + nsICanvasRenderingContextInternal* GetContext() const { + return mContext.get(); + } +}; + +// Based class which used for canvas rendering. There are many derived classes +// for different purposes. such as: +// +// ShareableCanvasRenderer provides IPC capabilities that allow sending canvas +// content over IPC. This is pure virtual class because the IPC handling is +// different in different LayerManager. So that we have following classes +// inherit ShareableCanvasRenderer. +// +// WebRenderCanvasRenderer inherits ShareableCanvasRenderer and provides all +// functionality that WebRender uses. +// WebRenderCanvasRendererAsync inherits WebRenderCanvasRenderer and be used in +// layers-free mode of WebRender. +// +// class diagram: +// +// +--------------+ +// |CanvasRenderer| +// +-------+------+ +// ^ +// | +// +-----------+-----------+ +// |ShareableCanvasRenderer| +// +-----+-----------------+ +// ^ +// | +// +-----------+-----------+ +// |WebRenderCanvasRenderer| +// +-----------+-----------+ +// ^ +// | +// +-------------+--------------+ +// |WebRenderCanvasRendererAsync| +// +----------------------------+ + +class BorrowedSourceSurface final { + public: + const WeakPtr mReturnTo; + const RefPtr mSurf; /// non-null + + BorrowedSourceSurface(PersistentBufferProvider*, RefPtr); + ~BorrowedSourceSurface(); +}; + +// - + +class CanvasRenderer : public RefCounted { + friend class CanvasRendererSourceSurface; + + public: + MOZ_DECLARE_REFCOUNTED_TYPENAME(CanvasRenderer) + + private: + bool mDirty = false; + + protected: + CanvasRendererData mData; + + public: + explicit CanvasRenderer(); + virtual ~CanvasRenderer(); + + public: + virtual void Initialize(const CanvasRendererData&); + virtual bool IsDataValid(const CanvasRendererData&) const; + + virtual void ClearCachedResources() {} + virtual void DisconnectClient() {} + + const gfx::IntSize& GetSize() const { return mData.mSize; } + bool IsOpaque() const { return mData.mIsOpaque; } + bool YIsDown() const { return mData.mOriginPos == gl::OriginPos::TopLeft; } + Maybe GetRemoteTextureOwnerIdOfPushCallback() { + return mData.mRemoteTextureOwnerIdOfPushCallback; + } + + void SetDirty() { mDirty = true; } + void ResetDirty() { mDirty = false; } + bool IsDirty() const { return mDirty; } + + virtual WebRenderCanvasRendererAsync* AsWebRenderCanvasRendererAsync() { + return nullptr; + } + + std::shared_ptr BorrowSnapshot( + bool requireAlphaPremult = true) const; + + void FirePreTransactionCallback() const; + void FireDidTransactionCallback() const; +}; + +} // namespace layers +} // namespace mozilla + +#endif -- cgit v1.2.3