зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1755704 - Part 2. Implement stubbed out surface related WebGPU canvas methods. r=gfx-reviewers,lsalzman
This patch hooks up the improved CanvasManagerChild::GetSnapshot method to the WebGPU canvas context object in order to do readbacks for various DOM facing methods such as ConvertToBlob and for Firefox Screenshots. Differential Revision: https://phabricator.services.mozilla.com/D144309
This commit is contained in:
Родитель
382feb7053
Коммит
c55d373481
|
@ -5,9 +5,11 @@
|
|||
|
||||
#include "mozilla/dom/WebGPUBinding.h"
|
||||
#include "CanvasContext.h"
|
||||
#include "nsDisplayList.h"
|
||||
#include "gfxUtils.h"
|
||||
#include "LayerUserData.h"
|
||||
#include "nsDisplayList.h"
|
||||
#include "mozilla/dom/HTMLCanvasElement.h"
|
||||
#include "mozilla/gfx/CanvasManagerChild.h"
|
||||
#include "mozilla/layers/CompositableInProcessManager.h"
|
||||
#include "mozilla/layers/ImageDataSerializer.h"
|
||||
#include "mozilla/layers/LayersSurfaces.h"
|
||||
|
@ -124,5 +126,51 @@ void CanvasContext::SwapChainPresent() {
|
|||
}
|
||||
}
|
||||
|
||||
mozilla::UniquePtr<uint8_t[]> CanvasContext::GetImageBuffer(int32_t* aFormat) {
|
||||
gfxAlphaType any;
|
||||
RefPtr<gfx::SourceSurface> snapshot = GetSurfaceSnapshot(&any);
|
||||
if (!snapshot) {
|
||||
*aFormat = 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> dataSurface = snapshot->GetDataSurface();
|
||||
return gfxUtils::GetImageBuffer(dataSurface, /* aIsAlphaPremultiplied */ true,
|
||||
aFormat);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP CanvasContext::GetInputStream(const char* aMimeType,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) {
|
||||
gfxAlphaType any;
|
||||
RefPtr<gfx::SourceSurface> snapshot = GetSurfaceSnapshot(&any);
|
||||
if (!snapshot) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> dataSurface = snapshot->GetDataSurface();
|
||||
return gfxUtils::GetInputStream(dataSurface, /* aIsAlphaPremultiplied */ true,
|
||||
aMimeType, aEncoderOptions, aStream);
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::gfx::SourceSurface> CanvasContext::GetSurfaceSnapshot(
|
||||
gfxAlphaType* aOutAlphaType) {
|
||||
if (aOutAlphaType) {
|
||||
*aOutAlphaType = gfxAlphaType::Premult;
|
||||
}
|
||||
|
||||
auto* const cm = gfx::CanvasManagerChild::Get();
|
||||
if (!cm) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mBridge || !mBridge->IsOpen() || !mHandle) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return cm->GetSnapshot(cm->Id(), mBridge->Id(), mHandle, mGfxFormat,
|
||||
/* aPremultiply */ false, /* aYFlip */ false);
|
||||
}
|
||||
|
||||
} // namespace webgpu
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -54,20 +54,12 @@ class CanvasContext final : public nsICanvasRenderingContextInternal,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override {
|
||||
MOZ_CRASH("todo");
|
||||
}
|
||||
mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
|
||||
NS_IMETHOD GetInputStream(const char* aMimeType,
|
||||
const nsAString& aEncoderOptions,
|
||||
nsIInputStream** aStream) override {
|
||||
*aStream = nullptr;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsIInputStream** aStream) override;
|
||||
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
|
||||
gfxAlphaType* aOutAlphaType) override {
|
||||
return nullptr;
|
||||
}
|
||||
gfxAlphaType* aOutAlphaType) override;
|
||||
|
||||
void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override {}
|
||||
bool GetIsOpaque() override { return true; }
|
||||
|
|
Загрузка…
Ссылка в новой задаче