Bug 1678656 - Don't rely on mPlanes to compute RenderTextureHost size, since it's only initialized when used with SWGL. r=jrmuizel

Differential Revision: https://phabricator.services.mozilla.com/D104141
This commit is contained in:
Matt Woodrow 2021-02-09 04:38:24 +00:00
Родитель 616bcf95fb
Коммит eaf110a595
9 изменённых файлов: 47 добавлений и 1 удалений

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

@ -323,6 +323,10 @@ size_t MacIOSurface::GetBytesPerRow(size_t plane) const {
return ::IOSurfaceGetBytesPerRowOfPlane(mIOSurfaceRef.get(), plane);
}
size_t MacIOSurface::GetAllocSize() const {
return ::IOSurfaceGetAllocSize(mIOSurfaceRef.get());
}
OSType MacIOSurface::GetPixelFormat() const {
return ::IOSurfaceGetPixelFormat(mIOSurfaceRef.get());
}

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

@ -96,6 +96,7 @@ class MacIOSurface final
size_t GetDevicePixelWidth(size_t plane = 0) const;
size_t GetDevicePixelHeight(size_t plane = 0) const;
size_t GetBytesPerRow(size_t plane = 0) const;
size_t GetAllocSize() const;
void Lock(bool aReadOnly = true);
void Unlock(bool aReadOnly = true);
bool IsLocked() const { return mIsLocked; }

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

@ -30,6 +30,8 @@ class RenderBufferTextureHostSWGL final : public RenderTextureHostSWGL {
void UnmapPlanes() override;
size_t Bytes() override { return BytesFromPlanes(); }
private:
virtual ~RenderBufferTextureHostSWGL();

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

@ -64,6 +64,20 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
bool EnsureD3D11Texture2D(ID3D11Device* aDevice);
bool LockInternal();
size_t Bytes() override {
size_t bytes = 0;
size_t bpp = GetPlaneCount() > 1
? (GetColorDepth() == gfx::ColorDepth::COLOR_8 ? 1 : 2)
: 4;
for (size_t i = 0; i < GetPlaneCount(); i++) {
gfx::IntSize size = GetSize(i);
bytes += size.width * size.height * bpp;
}
return bytes;
}
private:
virtual ~RenderDXGITextureHost();
@ -143,6 +157,18 @@ class RenderDXGIYCbCrTextureHost final : public RenderTextureHostSWGL {
return mTextures[aChannelIndex];
}
size_t Bytes() override {
size_t bytes = 0;
size_t bpp = mColorDepth == gfx::ColorDepth::COLOR_8 ? 1 : 2;
for (size_t i = 0; i < GetPlaneCount(); i++) {
gfx::IntSize size = GetSize(i);
bytes += size.width * size.height * bpp;
}
return bytes;
}
private:
virtual ~RenderDXGIYCbCrTextureHost();

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

@ -72,6 +72,10 @@ gfx::IntSize RenderMacIOSurfaceTextureHost::GetSize(
mSurface->GetDevicePixelHeight(aChannelIndex));
}
size_t RenderMacIOSurfaceTextureHost::Bytes() {
return mSurface->GetAllocSize();
}
wr::WrExternalImage RenderMacIOSurfaceTextureHost::Lock(
uint8_t aChannelIndex, gl::GLContext* aGL, wr::ImageRendering aRendering) {
if (mGL.get() != aGL) {

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

@ -34,6 +34,8 @@ class RenderMacIOSurfaceTextureHost final : public RenderTextureHostSWGL {
return this;
}
size_t Bytes() override;
MacIOSurface* GetSurface() { return mSurface; }
// RenderTextureHostSWGL

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

@ -37,6 +37,8 @@ class RenderSharedSurfaceTextureHostSWGL final : public RenderTextureHostSWGL {
void UnmapPlanes() override;
size_t Bytes() override { return BytesFromPlanes(); }
private:
virtual ~RenderSharedSurfaceTextureHostSWGL();

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

@ -58,7 +58,8 @@ class RenderTextureHostSWGL : public RenderTextureHost {
bool LockSWGLCompositeSurface(void* aContext,
wr::SWGLCompositeSurfaceInfo* aInfo);
size_t Bytes() override {
size_t BytesFromPlanes() {
NS_ASSERTION(mPlanes.size(), "Can't compute bytes without any planes");
size_t bytes = 0;
for (auto& plane : mPlanes) {
bytes += plane.mStride * plane.mSize.height;

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

@ -46,6 +46,10 @@ class RenderTextureHostWrapper final : public RenderTextureHostSWGL {
PlaneInfo& aPlaneInfo) override;
void UnmapPlanes() override;
// This is just a wrapper, so doesn't need to report the
// size of the wrapped object (which reports itself).
size_t Bytes() override { return 0; }
private:
~RenderTextureHostWrapper() override;