Backed out 3 changesets (bug 1765816, bug 1755704) for causing bp hybrid bustages. CLOSED TREE

Backed out changeset 505897037daf (bug 1765816)
Backed out changeset bc4e2999a2a7 (bug 1755704)
Backed out changeset 26b11a2833b0 (bug 1755704)
This commit is contained in:
Molnar Sandor 2022-04-22 18:03:57 +03:00
Родитель 395df0c9f2
Коммит 86256102b3
12 изменённых файлов: 46 добавлений и 166 удалений

Просмотреть файл

@ -252,14 +252,12 @@ OffscreenCanvasDisplayHelper::GetSurfaceSnapshot() {
Maybe<int32_t> childId;
HTMLCanvasElement* canvasElement;
RefPtr<gfx::SourceSurface> surface;
layers::CompositableHandle handle;
{
MutexAutoLock lock(mMutex);
hasAlpha = !mData.mIsOpaque;
isAlphaPremult = mData.mIsAlphaPremult;
originPos = mData.mOriginPos;
handle = mData.mHandle;
managerId = mContextManagerId;
childId = mContextChildId;
canvasElement = mCanvasElement;
@ -313,9 +311,7 @@ OffscreenCanvasDisplayHelper::GetSurfaceSnapshot() {
// We don't have a usable surface, and the context lives in the compositor
// process.
return gfx::CanvasManagerChild::Get()->GetSnapshot(
managerId.value(), childId.value(), handle,
hasAlpha ? gfx::SurfaceFormat::R8G8B8A8 : gfx::SurfaceFormat::R8G8B8X8,
hasAlpha && !isAlphaPremult, originPos == gl::OriginPos::BottomLeft);
managerId.value(), childId.value(), hasAlpha);
}
// If we don't have any protocol IDs, or an existing surface, it is possible

Просмотреть файл

@ -9,7 +9,6 @@
#include "mozilla/dom/Document.h"
#include "mozilla/PresShell.h"
#include "nsRefreshDriver.h"
#include "ImageContainer.h"
nsICanvasRenderingContextInternal::nsICanvasRenderingContextInternal() =
default;
@ -73,12 +72,3 @@ void nsICanvasRenderingContextInternal::DoSecurityCheck(
mOffscreenCanvas->SetWriteOnly();
}
}
already_AddRefed<mozilla::layers::Image>
nsICanvasRenderingContextInternal::GetAsImage() {
RefPtr<mozilla::gfx::SourceSurface> snapshot = GetFrontBufferSnapshot(true);
if (!snapshot) {
return nullptr;
}
return mozilla::MakeAndAddRef<mozilla::layers::SourceSurfaceImage>(snapshot);
}

Просмотреть файл

@ -146,7 +146,9 @@ class nsICanvasRenderingContextInternal : public nsISupports,
// for possibly reinitializing with SetDimensions/InitializeWithSurface.
NS_IMETHOD Reset() = 0;
virtual already_AddRefed<mozilla::layers::Image> GetAsImage();
virtual already_AddRefed<mozilla::layers::Image> GetAsImage() {
return nullptr;
}
virtual bool UpdateWebRenderCanvasData(
mozilla::nsDisplayListBuilder* aBuilder,

Просмотреть файл

@ -5,11 +5,9 @@
#include "mozilla/dom/WebGPUBinding.h"
#include "CanvasContext.h"
#include "gfxUtils.h"
#include "LayerUserData.h"
#include "nsDisplayList.h"
#include "LayerUserData.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"
@ -80,7 +78,6 @@ void CanvasContext::Configure(const dom::GPUCanvasConfiguration& aDesc) {
} else if (mOffscreenCanvas) {
dom::OffscreenCanvasDisplayData data;
data.mSize = {mWidth, mHeight};
data.mIsOpaque = false;
data.mHandle = mHandle;
mOffscreenCanvas->UpdateDisplayData(data);
}
@ -126,51 +123,5 @@ 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,12 +54,20 @@ class CanvasContext final : public nsICanvasRenderingContextInternal,
return NS_OK;
}
mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override;
mozilla::UniquePtr<uint8_t[]> GetImageBuffer(int32_t* aFormat) override {
MOZ_CRASH("todo");
}
NS_IMETHOD GetInputStream(const char* aMimeType,
const nsAString& aEncoderOptions,
nsIInputStream** aStream) override;
nsIInputStream** aStream) override {
*aStream = nullptr;
return NS_ERROR_NOT_IMPLEMENTED;
}
already_AddRefed<mozilla::gfx::SourceSurface> GetSurfaceSnapshot(
gfxAlphaType* aOutAlphaType) override;
gfxAlphaType* aOutAlphaType) override {
return nullptr;
}
void SetOpaqueValueFromOpaqueAttr(bool aOpaqueAttrValue) override {}
bool GetIsOpaque() override { return true; }

Просмотреть файл

@ -640,36 +640,6 @@ static void PresentCallback(ffi::WGPUBufferMapAsyncStatus status,
delete req;
}
ipc::IPCResult WebGPUParent::GetFrontBufferSnapshot(
IProtocol* aProtocol, const CompositableHandle& aHandle,
Maybe<Shmem>& aShmem, gfx::IntSize& aSize) {
const auto& lookup = mCanvasMap.find(aHandle.Value());
if (lookup == mCanvasMap.end()) {
return IPC_OK();
}
RefPtr<PresentationData> data = lookup->second.get();
aSize = data->mTextureHost->GetSize();
uint32_t stride =
aSize.width * BytesPerPixel(data->mTextureHost->GetFormat());
uint32_t len = data->mRowCount * stride;
Shmem shmem;
if (!AllocShmem(len, ipc::Shmem::SharedMemory::TYPE_BASIC, &shmem)) {
return IPC_OK();
}
uint8_t* dst = shmem.get<uint8_t>();
uint8_t* src = data->mTextureHost->GetBuffer();
for (uint32_t row = 0; row < data->mRowCount; ++row) {
memcpy(dst, src, stride);
src += data->mTargetPitch;
dst += stride;
}
aShmem.emplace(std::move(shmem));
return IPC_OK();
}
ipc::IPCResult WebGPUParent::RecvSwapChainPresent(
const CompositableHandle& aHandle, RawId aTextureId,
RawId aCommandEncoderId) {

Просмотреть файл

@ -11,7 +11,8 @@
#include "WebGPUTypes.h"
#include "base/timer.h"
namespace mozilla::webgpu {
namespace mozilla {
namespace webgpu {
class ErrorBuffer;
class PresentationData;
@ -89,11 +90,6 @@ class WebGPUParent final : public PWebGPUParent {
ipc::IPCResult RecvDevicePopErrorScope(
RawId aSelfId, DevicePopErrorScopeResolver&& aResolver);
ipc::IPCResult GetFrontBufferSnapshot(IProtocol* aProtocol,
const CompositableHandle& aHandle,
Maybe<Shmem>& aShmem,
gfx::IntSize& aSize);
void ActorDestroy(ActorDestroyReason aWhy) override;
private:
@ -113,6 +109,7 @@ class WebGPUParent final : public PWebGPUParent {
std::unordered_map<uint64_t, ErrorScopeStack> mErrorScopeMap;
};
} // namespace mozilla::webgpu
} // namespace webgpu
} // namespace mozilla
#endif // WEBGPU_PARENT_H_

Просмотреть файл

@ -144,15 +144,13 @@ RefPtr<webgpu::WebGPUChild> CanvasManagerChild::GetWebGPUChild() {
}
already_AddRefed<DataSourceSurface> CanvasManagerChild::GetSnapshot(
uint32_t aManagerId, int32_t aProtocolId,
const layers::CompositableHandle& aHandle, SurfaceFormat aFormat,
bool aPremultiply, bool aYFlip) {
uint32_t aManagerId, int32_t aProtocolId, bool aHasAlpha) {
if (!CanSend()) {
return nullptr;
}
webgl::FrontBufferSnapshotIpc res;
if (!SendGetSnapshot(aManagerId, aProtocolId, aHandle, &res)) {
if (!SendGetSnapshot(aManagerId, aProtocolId, &res)) {
return nullptr;
}
@ -180,7 +178,7 @@ already_AddRefed<DataSourceSurface> CanvasManagerChild::GetSnapshot(
}
SurfaceFormat format =
IsOpaque(aFormat) ? SurfaceFormat::B8G8R8X8 : SurfaceFormat::B8G8R8A8;
aHasAlpha ? SurfaceFormat::B8G8R8A8 : SurfaceFormat::B8G8R8X8;
RefPtr<DataSourceSurface> surface =
Factory::CreateDataSourceSurfaceWithStride(size, format, stride.value(),
/* aZero */ false);
@ -194,32 +192,21 @@ already_AddRefed<DataSourceSurface> CanvasManagerChild::GetSnapshot(
return nullptr;
}
// The buffer we may readback from the canvas could be R8G8B8A8, not
// premultiplied, and/or has its rows iverted. For the general case, we want
// surfaces represented as premultiplied B8G8R8A8, with its rows ordered top
// to bottom. Given this path is used for screenshots/SurfaceFromElement,
// that's the representation we need.
if (aYFlip) {
if (aPremultiply) {
if (!PremultiplyYFlipData(res.shmem->get<uint8_t>(), stride.value(),
aFormat, map.GetData(), map.GetStride(), format,
size)) {
return nullptr;
}
} else {
if (!SwizzleYFlipData(res.shmem->get<uint8_t>(), stride.value(), aFormat,
map.GetData(), map.GetStride(), format, size)) {
return nullptr;
}
}
} else if (aPremultiply) {
if (!PremultiplyData(res.shmem->get<uint8_t>(), stride.value(), aFormat,
map.GetData(), map.GetStride(), format, size)) {
// The buffer we read back from WebGL is R8G8B8A8, not premultiplied and has
// its rows inverted. For the general case, we want surfaces represented as
// premultiplied B8G8R8A8, with its rows ordered top to bottom. Given this
// path is used for screenshots/SurfaceFromElement, that's the representation
// we need.
if (aHasAlpha) {
if (!PremultiplyYFlipData(res.shmem->get<uint8_t>(), stride.value(),
SurfaceFormat::R8G8B8A8, map.GetData(),
map.GetStride(), format, size)) {
return nullptr;
}
} else {
if (!SwizzleData(res.shmem->get<uint8_t>(), stride.value(), aFormat,
map.GetData(), map.GetStride(), format, size)) {
if (!SwizzleYFlipData(res.shmem->get<uint8_t>(), stride.value(),
SurfaceFormat::R8G8B8X8, map.GetData(),
map.GetStride(), format, size)) {
return nullptr;
}
}

Просмотреть файл

@ -8,7 +8,6 @@
#include "mozilla/Atomics.h"
#include "mozilla/gfx/PCanvasManagerChild.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/ThreadLocal.h"
namespace mozilla {
@ -30,10 +29,9 @@ class CanvasManagerChild final : public PCanvasManagerChild {
explicit CanvasManagerChild(uint32_t aId);
uint32_t Id() const { return mId; }
already_AddRefed<DataSourceSurface> GetSnapshot(
uint32_t aManagerId, int32_t aProtocolId,
const layers::CompositableHandle& aHandle, SurfaceFormat aFormat,
bool aPremultiply, bool aYFlip);
already_AddRefed<DataSourceSurface> GetSnapshot(uint32_t aManagerId,
int32_t aProtocolId,
bool aHasAlpha);
void ActorDestroy(ActorDestroyReason aReason) override;
static CanvasManagerChild* Get();

Просмотреть файл

@ -111,7 +111,7 @@ mozilla::ipc::IPCResult CanvasManagerParent::RecvInitialize(
mozilla::ipc::IPCResult CanvasManagerParent::RecvGetSnapshot(
const uint32_t& aManagerId, const int32_t& aProtocolId,
const CompositableHandle& aHandle, webgl::FrontBufferSnapshotIpc* aResult) {
webgl::FrontBufferSnapshotIpc* aResult) {
if (!aManagerId) {
return IPC_FAIL(this, "invalid id");
}
@ -129,33 +129,16 @@ mozilla::ipc::IPCResult CanvasManagerParent::RecvGetSnapshot(
return IPC_FAIL(this, "invalid actor");
}
if (actor->GetSide() != mozilla::ipc::Side::ParentSide) {
if (actor->GetProtocolId() != ProtocolId::PWebGLMsgStart ||
actor->GetSide() != mozilla::ipc::Side::ParentSide) {
return IPC_FAIL(this, "unsupported actor");
}
RefPtr<dom::WebGLParent> webgl = static_cast<dom::WebGLParent*>(actor);
webgl::FrontBufferSnapshotIpc buffer;
switch (actor->GetProtocolId()) {
case ProtocolId::PWebGLMsgStart: {
RefPtr<dom::WebGLParent> webgl = static_cast<dom::WebGLParent*>(actor);
mozilla::ipc::IPCResult rv = webgl->GetFrontBufferSnapshot(&buffer, this);
if (!rv) {
return rv;
}
} break;
case ProtocolId::PWebGPUMsgStart: {
RefPtr<webgpu::WebGPUParent> webgpu =
static_cast<webgpu::WebGPUParent*>(actor);
IntSize size;
mozilla::ipc::IPCResult rv =
webgpu->GetFrontBufferSnapshot(this, aHandle, buffer.shmem, size);
if (!rv) {
return rv;
}
buffer.surfSize.x = static_cast<uint32_t>(size.width);
buffer.surfSize.y = static_cast<uint32_t>(size.height);
} break;
default:
return IPC_FAIL(this, "unsupported protocol");
mozilla::ipc::IPCResult rv = webgl->GetFrontBufferSnapshot(&buffer, this);
if (!rv) {
return rv;
}
*aResult = std::move(buffer);

Просмотреть файл

@ -30,7 +30,6 @@ class CanvasManagerParent final : public PCanvasManagerParent {
mozilla::ipc::IPCResult RecvInitialize(const uint32_t& aId);
mozilla::ipc::IPCResult RecvGetSnapshot(
const uint32_t& aManagerId, const int32_t& aProtocolId,
const CompositableHandle& aHandle,
webgl::FrontBufferSnapshotIpc* aResult);
private:

Просмотреть файл

@ -8,7 +8,6 @@
include protocol PWebGL;
include protocol PWebGPU;
using mozilla::layers::CompositableHandle from "mozilla/layers/LayersTypes.h";
using mozilla::webgl::FrontBufferSnapshotIpc from "mozilla/dom/WebGLIpdl.h";
namespace mozilla {
@ -40,7 +39,7 @@ parent:
// intended to be used by the main thread in the content process to block
// reading without having to block on the worker thread that owns the context
// instance.
sync GetSnapshot(uint32_t aManagerId, int32_t aProtocolId, CompositableHandle aHandle) returns (FrontBufferSnapshotIpc ret);
sync GetSnapshot(uint32_t aManagerId, int32_t aProtocolId) returns (FrontBufferSnapshotIpc ret);
};
} // gfx