gecko-dev/gfx/ipc/CanvasManagerChild.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 строки
2.6 KiB
C
Исходник Обычный вид История

/* -*- 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 _include_gfx_ipc_CanvasManagerChild_h__
#define _include_gfx_ipc_CanvasManagerChild_h__
#include "mozilla/Atomics.h"
#include "mozilla/gfx/PCanvasManagerChild.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/ThreadLocal.h"
#include <set>
namespace mozilla {
namespace dom {
class CanvasRenderingContext2D;
class ThreadSafeWorkerRef;
class WorkerPrivate;
} // namespace dom
namespace layers {
class CanvasChild;
class ActiveResourceTracker;
} // namespace layers
namespace webgpu {
class WebGPUChild;
} // namespace webgpu
namespace gfx {
class DataSourceSurface;
class CanvasManagerChild final : public PCanvasManagerChild {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CanvasManagerChild, override);
explicit CanvasManagerChild(uint32_t aId);
uint32_t Id() const { return mId; }
already_AddRefed<DataSourceSurface> GetSnapshot(
uint32_t aManagerId, int32_t aProtocolId,
const Maybe<RemoteTextureOwnerId>& aOwnerId, SurfaceFormat aFormat,
bool aPremultiply, bool aYFlip);
void ActorDestroy(ActorDestroyReason aReason) override;
static CanvasManagerChild* Get();
static CanvasManagerChild* MaybeGet();
static void Shutdown();
static bool CreateParent(
mozilla::ipc::Endpoint<PCanvasManagerParent>&& aEndpoint);
void AddShutdownObserver(dom::CanvasRenderingContext2D* aCanvas);
void RemoveShutdownObserver(dom::CanvasRenderingContext2D* aCanvas);
bool IsCanvasActive() { return mActive; }
void EndCanvasTransaction();
void ClearCachedResources();
void DeactivateCanvas();
Bug 1829026 - Update CanvasTranslator to work with DrawTargetWebgl. r=aosmond This adds the necessary infrastructure for CanvasTranslator to allocate DrawTargetWebgl instead of just allocating TextureData, and to use RemoteTextureMap to handle sending the DrawTargetWebgl frames to the compositor. This optimizes snapshot transport to use fewer copies to and from shmems when we know the snapshot contents can be sourced from a shmem. This adds a blocking mechanism separate from deactivation so that existing DrawTargetWebgls can continue processing events while denying further ones from being created in the event that allocating further DrawTargetWebgls might cause problems, but so that we don't disrupt canvases that are already in flight. PersistentBufferProviderAccelerated still remains the buffer provider for the new setup, but just allocates a single RecordedTextureData internally. Since DrawTargetWebgl already does its own swap chain management internally, we do not want to use the multiple texture client strategy that PersistentBufferProviderShared does. This adds a fallback mechanism such that if DrawTargetWebgl allocation fails, a TextureData is allocated instead that still sends results to RemoteTextureMap. This has the advantage that we don't need to synchronously block in the content process to verify if acceleration succeeded, as the costs of such blocking are rather extreme and we must still produce the rendered frame to ensure the user sees the correct result if the speculative acceleration failed. It then notifies the content process asynchronously via the refresh mechanism to try to recreate a non-accelerated buffer provider when it is ready. There is one additional hitch in RemoteTextureMap that we need to add a mechanism to deal with the setup of the RemoteTextureOwner. When display list building initially needs to get the remote texture, the RemoteTextureOwner might not exist yet. In this case, we need to add a block to ensure we wait for that to occur so that we do not render an erroneous result. Previously, this block was handled in ClientWebGLContext. Since that is no longer used, the block must be reinstated somewhere else until a non-blocking mechanism for display list building to proceed with a stub texture host wrapper can be implemented. Currently this leaves the gfx.canvas.remote and gfx.canvas.accelerated prefs as separate toggles rather than trying to lump everything into one mechanism. While this may be desirable in the future, currently Direct2D remote canvas is a separate acceleration mechanism that needs to co-exist with the WebGL acceleration, and so being able to toggle both on or off for testing is desirable. Differential Revision: https://phabricator.services.mozilla.com/D194352
2023-12-18 21:10:46 +03:00
void BlockCanvas();
RefPtr<layers::CanvasChild> GetCanvasChild();
RefPtr<webgpu::WebGPUChild> GetWebGPUChild();
layers::ActiveResourceTracker* GetActiveResourceTracker();
private:
~CanvasManagerChild();
void DestroyInternal();
void Destroy();
RefPtr<mozilla::dom::ThreadSafeWorkerRef> mWorkerRef;
RefPtr<layers::CanvasChild> mCanvasChild;
RefPtr<webgpu::WebGPUChild> mWebGPUChild;
UniquePtr<layers::ActiveResourceTracker> mActiveResourceTracker;
std::set<dom::CanvasRenderingContext2D*> mActiveCanvas;
const uint32_t mId;
bool mActive = true;
Bug 1829026 - Update CanvasTranslator to work with DrawTargetWebgl. r=aosmond This adds the necessary infrastructure for CanvasTranslator to allocate DrawTargetWebgl instead of just allocating TextureData, and to use RemoteTextureMap to handle sending the DrawTargetWebgl frames to the compositor. This optimizes snapshot transport to use fewer copies to and from shmems when we know the snapshot contents can be sourced from a shmem. This adds a blocking mechanism separate from deactivation so that existing DrawTargetWebgls can continue processing events while denying further ones from being created in the event that allocating further DrawTargetWebgls might cause problems, but so that we don't disrupt canvases that are already in flight. PersistentBufferProviderAccelerated still remains the buffer provider for the new setup, but just allocates a single RecordedTextureData internally. Since DrawTargetWebgl already does its own swap chain management internally, we do not want to use the multiple texture client strategy that PersistentBufferProviderShared does. This adds a fallback mechanism such that if DrawTargetWebgl allocation fails, a TextureData is allocated instead that still sends results to RemoteTextureMap. This has the advantage that we don't need to synchronously block in the content process to verify if acceleration succeeded, as the costs of such blocking are rather extreme and we must still produce the rendered frame to ensure the user sees the correct result if the speculative acceleration failed. It then notifies the content process asynchronously via the refresh mechanism to try to recreate a non-accelerated buffer provider when it is ready. There is one additional hitch in RemoteTextureMap that we need to add a mechanism to deal with the setup of the RemoteTextureOwner. When display list building initially needs to get the remote texture, the RemoteTextureOwner might not exist yet. In this case, we need to add a block to ensure we wait for that to occur so that we do not render an erroneous result. Previously, this block was handled in ClientWebGLContext. Since that is no longer used, the block must be reinstated somewhere else until a non-blocking mechanism for display list building to proceed with a stub texture host wrapper can be implemented. Currently this leaves the gfx.canvas.remote and gfx.canvas.accelerated prefs as separate toggles rather than trying to lump everything into one mechanism. While this may be desirable in the future, currently Direct2D remote canvas is a separate acceleration mechanism that needs to co-exist with the WebGL acceleration, and so being able to toggle both on or off for testing is desirable. Differential Revision: https://phabricator.services.mozilla.com/D194352
2023-12-18 21:10:46 +03:00
bool mBlocked = false;
static MOZ_THREAD_LOCAL(CanvasManagerChild*) sLocalManager;
static Atomic<uint32_t> sNextId;
};
} // namespace gfx
} // namespace mozilla
#endif // _include_gfx_ipc_CanvasManagerChild_h__