summaryrefslogtreecommitdiffstats
path: root/gfx/layers/CanvasRenderer.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/layers/CanvasRenderer.h
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/CanvasRenderer.h')
-rw-r--r--gfx/layers/CanvasRenderer.h153
1 files changed, 153 insertions, 0 deletions
diff --git a/gfx/layers/CanvasRenderer.h b/gfx/layers/CanvasRenderer.h
new file mode 100644
index 0000000000..ca3ae088cc
--- /dev/null
+++ b/gfx/layers/CanvasRenderer.h
@@ -0,0 +1,153 @@
+/* -*- 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/mozalloc.h" // for operator delete, etc
+#include "mozilla/WeakPtr.h" // for WeakPtr
+#include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
+
+class nsICanvasRenderingContextInternal;
+
+namespace mozilla {
+namespace layers {
+
+class ClientCanvasRenderer;
+class KnowsCompositor;
+class PersistentBufferProvider;
+class WebRenderCanvasRendererAsync;
+
+TextureType TexTypeForWebgl(KnowsCompositor*);
+
+struct CanvasRendererData final {
+ CanvasRendererData();
+ ~CanvasRendererData();
+
+ std::weak_ptr<nsICanvasRenderingContextInternal* const>
+ mContext; // weak_ptr to ptr (bug 1635644)
+
+ // 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;
+
+ nsICanvasRenderingContextInternal* GetContext() const {
+ const auto ptrToPtr = mContext.lock();
+ if (!ptrToPtr) return nullptr;
+ return *ptrToPtr;
+ }
+};
+
+// 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.
+//
+// ClientCanvasRenderer inherits ShareableCanvasRenderer and be used in
+// ClientCanvasLayer.
+// 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|
+// +-----+-----------------+
+// ^ ^
+// +-------------+ +-------+
+// | |
+// +--------------------+ +---------+-------------+
+// |ClientCanvasRenderer| |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; }
+
+ void SetDirty() { mDirty = true; }
+ void ResetDirty() { mDirty = false; }
+ bool IsDirty() const { return mDirty; }
+
+ virtual ClientCanvasRenderer* AsClientCanvasRenderer() { return nullptr; }
+ 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