Skip to content

Commit ac80010

Browse files
author
sotaro
committed
Bug 1948175 - Add byte stride delivery to PCanvasManagerChild::SendGetSnapshot() r=gfx-reviewers,lsalzman
On macOS, ComputeRGBStride() uses alignment of 32 bytes. Differential Revision: https://phabricator.services.mozilla.com/D238150
1 parent f259cb2 commit ac80010

File tree

7 files changed

+14
-6
lines changed

7 files changed

+14
-6
lines changed

dom/canvas/WebGLIpdl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@ struct IPDLParamTraits<mozilla::webgl::FrontBufferSnapshotIpc> final {
127127

128128
static void Write(IPC::MessageWriter* const writer, IProtocol* actor, T& in) {
129129
WriteParam(writer, in.surfSize);
130+
WriteParam(writer, in.byteStride);
130131
WriteIPDLParam(writer, actor, std::move(in.shmem));
131132
}
132133

133134
static bool Read(IPC::MessageReader* const reader, IProtocol* actor,
134135
T* const out) {
135136
return ReadParam(reader, &out->surfSize) &&
137+
ReadParam(reader, &out->byteStride) &&
136138
ReadIPDLParam(reader, actor, &out->shmem);
137139
}
138140
};

dom/canvas/WebGLParent.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,15 @@ IPCResult WebGLParent::GetFrontBufferSnapshot(
147147
if (maybeSize) {
148148
const auto& surfSize = *maybeSize;
149149
const auto byteSize = 4 * surfSize.x * surfSize.y;
150+
const auto byteStride = 4 * surfSize.x;
150151

151152
auto shmem = webgl::RaiiShmem::Alloc(aProtocol, byteSize);
152153
if (!shmem) {
153154
NS_WARNING("Failed to alloc shmem for RecvGetFrontBufferSnapshot.");
154155
return false;
155156
}
156157
const auto range = shmem.ByteRange();
157-
*ret = {surfSize, Some(shmem.Extract())};
158+
*ret = {surfSize, byteStride, Some(shmem.Extract())};
158159

159160
if (!mHost->FrontBufferSnapshotInto(Some(range))) {
160161
gfxCriticalNote << "WebGLParent::RecvGetFrontBufferSnapshot: "

dom/canvas/WebGLTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,7 @@ struct GetUniformData final {
894894

895895
struct FrontBufferSnapshotIpc final {
896896
uvec2 surfSize = {};
897+
size_t byteStride = 0;
897898
Maybe<mozilla::ipc::Shmem> shmem = {};
898899
};
899900

dom/webgpu/ipc/WebGPUParent.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,8 @@ static void ReadbackSnapshotCallback(uint8_t* userdata,
12471247

12481248
ipc::IPCResult WebGPUParent::GetFrontBufferSnapshot(
12491249
IProtocol* aProtocol, const layers::RemoteTextureOwnerId& aOwnerId,
1250-
const RawId& aCommandEncoderId, Maybe<Shmem>& aShmem, gfx::IntSize& aSize) {
1250+
const RawId& aCommandEncoderId, Maybe<Shmem>& aShmem, gfx::IntSize& aSize,
1251+
uint32_t& aByteStride) {
12511252
const auto& lookup = mPresentationDataMap.find(aOwnerId);
12521253
if (lookup == mPresentationDataMap.end()) {
12531254
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
@@ -1259,6 +1260,7 @@ ipc::IPCResult WebGPUParent::GetFrontBufferSnapshot(
12591260
aSize = data->mDesc.size();
12601261
uint32_t stride = layers::ImageDataSerializer::ComputeRGBStride(
12611262
data->mDesc.format(), aSize.width);
1263+
aByteStride = stride;
12621264
uint32_t len = data->mDesc.size().height * stride;
12631265
Shmem shmem;
12641266
if (!AllocShmem(len, &shmem)) {

dom/webgpu/ipc/WebGPUParent.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class WebGPUParent final : public PWebGPUParent, public SupportsWeakPtr {
135135

136136
ipc::IPCResult GetFrontBufferSnapshot(
137137
IProtocol* aProtocol, const layers::RemoteTextureOwnerId& aOwnerId,
138-
const RawId& aCommandEncoderId, Maybe<Shmem>& aShmem,
139-
gfx::IntSize& aSize);
138+
const RawId& aCommandEncoderId, Maybe<Shmem>& aShmem, gfx::IntSize& aSize,
139+
uint32_t& aByteStride);
140140

141141
void ActorDestroy(ActorDestroyReason aWhy) override;
142142

gfx/ipc/CanvasManagerChild.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ already_AddRefed<DataSourceSurface> CanvasManagerChild::GetSnapshot(
255255
}
256256

257257
IntSize size(res.surfSize.x, res.surfSize.y);
258-
CheckedInt32 stride = CheckedInt32(size.width) * sizeof(uint32_t);
258+
CheckedInt32 stride = CheckedInt32(res.byteStride);
259259
if (!stride.isValid()) {
260260
return nullptr;
261261
}

gfx/ipc/CanvasManagerParent.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ mozilla::ipc::IPCResult CanvasManagerParent::RecvGetSnapshot(
221221
if (aCommandEncoderId.isNothing()) {
222222
return IPC_FAIL(this, "invalid CommandEncoderId");
223223
}
224+
uint32_t stride = 0;
224225
mozilla::ipc::IPCResult rv = webgpu->GetFrontBufferSnapshot(
225-
this, *aOwnerId, *aCommandEncoderId, buffer.shmem, size);
226+
this, *aOwnerId, *aCommandEncoderId, buffer.shmem, size, stride);
226227
if (!rv) {
227228
return rv;
228229
}
229230
buffer.surfSize.x = static_cast<uint32_t>(size.width);
230231
buffer.surfSize.y = static_cast<uint32_t>(size.height);
232+
buffer.byteStride = stride;
231233
} break;
232234
default:
233235
return IPC_FAIL(this, "unsupported protocol");

0 commit comments

Comments
 (0)