summaryrefslogtreecommitdiffstats
path: root/gfx/layers/ipc/CanvasChild.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /gfx/layers/ipc/CanvasChild.h
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/layers/ipc/CanvasChild.h')
-rw-r--r--gfx/layers/ipc/CanvasChild.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/gfx/layers/ipc/CanvasChild.h b/gfx/layers/ipc/CanvasChild.h
new file mode 100644
index 0000000000..ca5b864008
--- /dev/null
+++ b/gfx/layers/ipc/CanvasChild.h
@@ -0,0 +1,152 @@
+/* -*- 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 https://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_layers_CanvasChild_h
+#define mozilla_layers_CanvasChild_h
+
+#include "mozilla/gfx/RecordedEvent.h"
+#include "mozilla/ipc/CrossProcessSemaphore.h"
+#include "mozilla/layers/PCanvasChild.h"
+#include "mozilla/layers/SourceSurfaceSharedData.h"
+#include "nsRefPtrHashtable.h"
+#include "nsTArray.h"
+
+namespace mozilla {
+
+namespace gfx {
+class SourceSurface;
+}
+
+namespace layers {
+class CanvasDrawEventRecorder;
+
+class CanvasChild final : public PCanvasChild {
+ public:
+ NS_INLINE_DECL_REFCOUNTING(CanvasChild)
+
+ explicit CanvasChild(Endpoint<PCanvasChild>&& aEndpoint);
+
+ /**
+ * @returns true if remote canvas has been deactivated due to failure.
+ */
+ static bool Deactivated() { return mDeactivated; }
+
+ ipc::IPCResult RecvNotifyDeviceChanged();
+
+ ipc::IPCResult RecvDeactivate();
+
+ /**
+ * Ensures that the DrawEventRecorder has been created.
+ *
+ * @params aTextureType the TextureType to create in the CanvasTranslator.
+ */
+ void EnsureRecorder(TextureType aTextureType);
+
+ /**
+ * Send a messsage to our CanvasParent to resume translation.
+ */
+ void ResumeTranslation();
+
+ /**
+ * Clean up IPDL actor.
+ */
+ void Destroy();
+
+ /**
+ * Called when a RecordedTextureData is write locked.
+ */
+ void OnTextureWriteLock();
+
+ /**
+ * Called when a RecordedTextureData is forwarded to the compositor.
+ */
+ void OnTextureForwarded();
+
+ /**
+ * @returns true if we should be caching data surfaces in the GPU process.
+ */
+ bool ShouldCacheDataSurface() const {
+ return mTransactionsSinceGetDataSurface < kCacheDataSurfaceThreshold;
+ }
+
+ /**
+ * Ensures that we have sent a begin transaction event, since the last
+ * end transaction.
+ */
+ void EnsureBeginTransaction();
+
+ /**
+ * Send an end transaction event to indicate the end of events for this frame.
+ */
+ void EndTransaction();
+
+ /**
+ * @returns true if the canvas IPC classes have not been used for some time
+ * and can be cleaned up.
+ */
+ bool ShouldBeCleanedUp() const;
+
+ /**
+ * Create a DrawTargetRecording for a canvas texture.
+ * @param aSize size for the DrawTarget
+ * @param aFormat SurfaceFormat for the DrawTarget
+ * @returns newly created DrawTargetRecording
+ */
+ already_AddRefed<gfx::DrawTarget> CreateDrawTarget(
+ gfx::IntSize aSize, gfx::SurfaceFormat aFormat);
+
+ /**
+ * Record an event for processing by the CanvasParent's CanvasTranslator.
+ * @param aEvent the event to record
+ */
+ void RecordEvent(const gfx::RecordedEvent& aEvent);
+
+ /**
+ * Wrap the given surface, so that we can provide a DataSourceSurface if
+ * required.
+ * @param aSurface the SourceSurface to wrap
+ * @returns a SourceSurface that can provide a DataSourceSurface if required
+ */
+ already_AddRefed<gfx::SourceSurface> WrapSurface(
+ const RefPtr<gfx::SourceSurface>& aSurface);
+
+ /**
+ * Get DataSourceSurface from the translated equivalent version of aSurface in
+ * the GPU process.
+ * @param aSurface the SourceSurface in this process for which we need a
+ * DataSourceSurface
+ * @returns a DataSourceSurface created from data for aSurface retrieve from
+ * GPU process
+ */
+ already_AddRefed<gfx::DataSourceSurface> GetDataSurface(
+ const gfx::SourceSurface* aSurface);
+
+ protected:
+ void ActorDestroy(ActorDestroyReason aWhy) final;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CanvasChild);
+
+ ~CanvasChild() final;
+
+ static const uint32_t kCacheDataSurfaceThreshold = 10;
+
+ static bool mDeactivated;
+
+ RefPtr<CanvasDrawEventRecorder> mRecorder;
+ TextureType mTextureType = TextureType::Unknown;
+ uint32_t mLastWriteLockCheckpoint = 0;
+ uint32_t mTransactionsSinceGetDataSurface = kCacheDataSurfaceThreshold;
+ TimeStamp mLastNonEmptyTransaction = TimeStamp::NowLoRes();
+ std::vector<RefPtr<gfx::SourceSurface>> mLastTransactionExternalSurfaces;
+ bool mIsInTransaction = false;
+ bool mHasOutstandingWriteLock = false;
+};
+
+} // namespace layers
+} // namespace mozilla
+
+#endif // mozilla_layers_CanvasChild_h