/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* 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/. */
void CanvasContext::GetCanvas(
dom::OwningHTMLCanvasElementOrOffscreenCanvas& aRetVal) const { if (mCanvasElement) {
aRetVal.SetAsHTMLCanvasElement() = mCanvasElement;
} elseif (mOffscreenCanvas) {
aRetVal.SetAsOffscreenCanvas() = mOffscreenCanvas;
} else {
MOZ_CRASH( "This should only happen briefly during CC Unlink, and no JS should " "happen then.");
}
}
// Bug 1864904: Failures in validation should throw a TypeError, per spec.
// these formats are guaranteed by the spec switch (aConfig.mFormat) { case dom::GPUTextureFormat::Rgba8unorm: case dom::GPUTextureFormat::Rgba8unorm_srgb:
mGfxFormat = gfx::SurfaceFormat::R8G8B8A8; break; case dom::GPUTextureFormat::Bgra8unorm: case dom::GPUTextureFormat::Bgra8unorm_srgb:
mGfxFormat = gfx::SurfaceFormat::B8G8R8A8; break; default:
NS_WARNING("Specified swap chain format is not supported"); return;
}
mConfig.reset(new dom::GPUCanvasConfiguration(aConfig));
mRemoteTextureOwnerId = Some(layers::RemoteTextureOwnerId::GetNext());
mUseExternalTextureInSwapChain =
aConfig.mDevice->mSupportExternalTextureInSwapChain &&
wgpu_client_use_external_texture_in_swapChain(
ConvertTextureFormat(aConfig.mFormat)); if (!gfx::gfxVars::AllowWebGPUPresentWithoutReadback()) {
mUseExternalTextureInSwapChain = false;
} #ifdef XP_WIN // When WebRender does not use hardware acceleration, disable external texture // in swap chain. Since compositor device might not exist. if (gfx::gfxVars::UseSoftwareWebRender() &&
!gfx::gfxVars::AllowSoftwareWebRenderD3D11()) {
mUseExternalTextureInSwapChain = false;
} #endif
mTexture = aConfig.mDevice->InitSwapChain(
mConfig.get(), mRemoteTextureOwnerId.ref(),
mUseExternalTextureInSwapChain, mGfxFormat, mCanvasSize); if (!mTexture) {
Unconfigure(); return;
}
mCanvasSize = newSize; if (mConfig) { constauto copy = dom::GPUCanvasConfiguration{
*mConfig}; // So we can't null it out on ourselves.
Configure(copy);
} return NS_OK;
}
RefPtr<Texture> CanvasContext::GetCurrentTexture(ErrorResult& aRv) { if (!mTexture) {
aRv.ThrowOperationError("Canvas not configured"); return nullptr;
}
auto* const cm = gfx::CanvasManagerChild::Get(); if (!cm) { return nullptr;
}
if (!mBridge || !mBridge->CanSend() || mRemoteTextureOwnerId.isNothing()) { return nullptr;
}
MOZ_ASSERT(mRemoteTextureOwnerId.isSome());
// The parent side needs to create a command encoder which will be submitted // and dropped right away so we create and release an encoder ID here.
RawId encoderId = ffi::wgpu_client_make_encoder_id(mBridge->GetClient());
RefPtr<gfx::SourceSurface> snapshot =
cm->GetSnapshot(cm->Id(), mBridge->Id(), mRemoteTextureOwnerId,
Some(encoderId), mGfxFormat, /* aPremultiply */ false, /* aYFlip */ false);
ffi::wgpu_client_free_command_encoder_id(mBridge->GetClient(), encoderId); return snapshot.forget();
}
Maybe<layers::SurfaceDescriptor> CanvasContext::GetFrontBuffer(
WebGLFramebufferJS*, constbool) { if (mPendingSwapChainPresent) { auto desc = SwapChainPresent();
MOZ_ASSERT(!mPendingSwapChainPresent); return desc;
} return Nothing();
}
void CanvasContext::ForceNewFrame() { if (!mCanvasElement && !mOffscreenCanvas) { return;
}
// Force a new frame to be built, which will execute the // `CanvasContextType::WebGPU` switch case in `CreateWebRenderCommands` and // populate the WR user data. if (mCanvasElement) {
mCanvasElement->InvalidateCanvas();
} elseif (mOffscreenCanvas) {
dom::OffscreenCanvasDisplayData data;
data.mSize = mCanvasSize;
data.mIsOpaque = false;
mOffscreenCanvas->UpdateDisplayData(data);
}
}
void CanvasContext::InvalidateCanvasContent() { if (!mCanvasElement && !mOffscreenCanvas) {
MOZ_ASSERT_UNREACHABLE("unexpected to be called"); return;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.