summaryrefslogtreecommitdiffstats
path: root/dom/canvas/SourceSurfaceWebgl.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/SourceSurfaceWebgl.h
parentInitial commit. (diff)
downloadfirefox-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 'dom/canvas/SourceSurfaceWebgl.h')
-rw-r--r--dom/canvas/SourceSurfaceWebgl.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/dom/canvas/SourceSurfaceWebgl.h b/dom/canvas/SourceSurfaceWebgl.h
new file mode 100644
index 0000000000..ab70f6280e
--- /dev/null
+++ b/dom/canvas/SourceSurfaceWebgl.h
@@ -0,0 +1,72 @@
+/* -*- 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 MOZILLA_GFX_SOURCESURFACEWEBGL_H_
+#define MOZILLA_GFX_SOURCESURFACEWEBGL_H_
+
+#include "mozilla/gfx/2D.h"
+#include "mozilla/WeakPtr.h"
+
+namespace mozilla::gfx {
+
+class DrawTargetWebgl;
+class TextureHandle;
+
+// SourceSurfaceWebgl holds WebGL resources that can be used to efficiently
+// copy snapshot data between multiple DrawTargetWebgls. It also takes care
+// of copy-on-write behavior when the owner target is modified or destructs.
+class SourceSurfaceWebgl : public DataSourceSurface {
+ public:
+ MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceWebgl, override)
+
+ explicit SourceSurfaceWebgl(DrawTargetWebgl* aDT);
+ SourceSurfaceWebgl(
+ const RefPtr<TextureHandle>& aHandle,
+ const RefPtr<typename DrawTargetWebgl::SharedContext>& aSharedContext);
+ virtual ~SourceSurfaceWebgl();
+
+ SurfaceType GetType() const override { return SurfaceType::WEBGL; }
+ IntSize GetSize() const override { return mSize; }
+ SurfaceFormat GetFormat() const override { return mFormat; }
+
+ uint8_t* GetData() override;
+ int32_t Stride() override;
+
+ bool Map(MapType aType, MappedSurface* aMappedSurface) override;
+ void Unmap() override;
+
+ bool HasReadData() const { return !!mData; }
+
+ already_AddRefed<SourceSurface> ExtractSubrect(const IntRect& aRect) override;
+
+ private:
+ friend class DrawTargetWebgl;
+
+ bool EnsureData();
+
+ void DrawTargetWillChange(bool aNeedHandle);
+
+ void GiveTexture(RefPtr<TextureHandle> aHandle);
+
+ void OnUnlinkTexture(typename DrawTargetWebgl::SharedContext* aContext);
+
+ DrawTargetWebgl* GetTarget() const { return mDT.get(); }
+
+ SurfaceFormat mFormat = SurfaceFormat::UNKNOWN;
+ IntSize mSize;
+ // Any data that has been read back from the WebGL context for mapping.
+ RefPtr<DataSourceSurface> mData;
+ // The draw target that currently owns the texture for this surface.
+ WeakPtr<DrawTargetWebgl> mDT;
+ // The actual shared context that any WebGL resources belong to.
+ WeakPtr<typename DrawTargetWebgl::SharedContext> mSharedContext;
+ // If this snapshot has been copied into a cached texture handle.
+ RefPtr<TextureHandle> mHandle;
+};
+
+} // namespace mozilla::gfx
+
+#endif /* MOZILLA_GFX_SOURCESURFACEWEBGL_H_ */