diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /gfx/layers/CanvasRenderer.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/CanvasRenderer.h')
-rw-r--r-- | gfx/layers/CanvasRenderer.h | 151 |
1 files changed, 151 insertions, 0 deletions
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 <memory> // for weak_ptr +#include <stdint.h> // 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<nsICanvasRenderingContextInternal> 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<RemoteTextureOwnerId> 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<PersistentBufferProvider> mReturnTo; + const RefPtr<gfx::SourceSurface> mSurf; /// non-null + + BorrowedSourceSurface(PersistentBufferProvider*, RefPtr<gfx::SourceSurface>); + ~BorrowedSourceSurface(); +}; + +// - + +class CanvasRenderer : public RefCounted<CanvasRenderer> { + 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<RemoteTextureOwnerId> 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<BorrowedSourceSurface> BorrowSnapshot( + bool requireAlphaPremult = true) const; + + void FirePreTransactionCallback() const; + void FireDidTransactionCallback() const; +}; + +} // namespace layers +} // namespace mozilla + +#endif |