gecko-dev/gfx/tests/gtest/TextureHelper.h
Jean-Yves Avenard 5de404e405 Bug 1595994 - P1D. Properly serialize display size when sending image over IPC. r=mattwoodrow
The code always assumed that the size of the image with the Y plane dimensions, which, while often the case, isn't correct.
We remove the assertions that the display offset was always (0,0) and properly carry the actual data over IPC.

Remoting the theora decoder and enabling fast video copy exposed several other related issues in the various D3D11 image types.
Various WPT uses theora YUV44 images (because we do not support YUV444 H264 ones). Those images are made of 32 pixels planes with a display size set to 20 pixels. Prior P1D the backend image was a ShareYCbCrPlanar image which correctly handled the size settings.

Like the image serializer, the various D3D11 images always assumed that the Y plane size was the image size.

This however expose existing issues where the offset position of the display is completely ignored for some image type. See bug 1669054

All those problems explain why sometimes we displayed more pixels than we should have.

Depends on D91914

Differential Revision: https://phabricator.services.mozilla.com/D92233
2020-10-20 23:30:04 +00:00

162 lines
5.2 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
#include <vector>
#include "Types.h"
#include "gfxImageSurface.h"
#include "gfxPlatform.h"
#include "mozilla/RefPtr.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/layers/BufferTexture.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/TextureClient.h"
#include "mozilla/layers/TextureHost.h"
#ifdef XP_WIN
# include "IMFYCbCrImage.h"
# include "mozilla/gfx/DeviceManagerDx.h"
# include "mozilla/layers/D3D11YCbCrImage.h"
# include "mozilla/layers/TextureD3D11.h"
# include "mozilla/layers/TextureDIB.h"
#endif
namespace mozilla {
namespace layers {
using gfx::BackendType;
using gfx::IntSize;
using gfx::SurfaceFormat;
/**
* Create a YCbCrTextureClient according to the given backend.
*/
static already_AddRefed<TextureClient> CreateYCbCrTextureClientWithBackend(
LayersBackend aLayersBackend) {
TextureData* data = nullptr;
IntSize size = IntSize(200, 150);
IntSize ySize = IntSize(400, 300);
RefPtr<gfxImageSurface> ySurface =
new gfxImageSurface(ySize, SurfaceFormat::A8);
RefPtr<gfxImageSurface> cbSurface =
new gfxImageSurface(size, SurfaceFormat::A8);
RefPtr<gfxImageSurface> crSurface =
new gfxImageSurface(size, SurfaceFormat::A8);
PlanarYCbCrData clientData;
clientData.mYChannel = ySurface->Data();
clientData.mCbChannel = cbSurface->Data();
clientData.mCrChannel = crSurface->Data();
clientData.mYSize = ySurface->GetSize();
clientData.mPicSize = ySurface->GetSize();
clientData.mCbCrSize = cbSurface->GetSize();
clientData.mYStride = ySurface->Stride();
clientData.mCbCrStride = cbSurface->Stride();
clientData.mStereoMode = StereoMode::MONO;
clientData.mYSkip = 0;
clientData.mCbSkip = 0;
clientData.mCrSkip = 0;
clientData.mCrSkip = 0;
clientData.mPicX = 0;
clientData.mPicX = 0;
// Create YCbCrTexture for basic backend.
if (aLayersBackend == LayersBackend::LAYERS_BASIC) {
return TextureClient::CreateForYCbCr(
nullptr, clientData.GetPictureRect(), clientData.mYSize,
clientData.mYStride, clientData.mCbCrSize, clientData.mCbCrStride,
StereoMode::MONO, gfx::ColorDepth::COLOR_8, gfx::YUVColorSpace::BT601,
gfx::ColorRange::LIMITED, TextureFlags::DEALLOCATE_CLIENT);
}
#ifdef XP_WIN
RefPtr<ID3D11Device> device = DeviceManagerDx::Get()->GetImageDevice();
if (device && aLayersBackend == LayersBackend::LAYERS_D3D11) {
DXGIYCbCrTextureAllocationHelper helper(clientData, TextureFlags::DEFAULT,
device);
RefPtr<TextureClient> texture = helper.Allocate(nullptr);
return texture.forget();
}
#endif
if (data) {
return MakeAndAddRef<TextureClient>(data, TextureFlags::DEALLOCATE_CLIENT,
nullptr);
}
return nullptr;
}
/**
* Create a TextureClient according to the given backend.
*/
static already_AddRefed<TextureClient> CreateTextureClientWithBackend(
LayersBackend aLayersBackend) {
TextureData* data = nullptr;
SurfaceFormat format = gfxPlatform::GetPlatform()->Optimal2DFormatForContent(
gfxContentType::COLOR_ALPHA);
BackendType moz2DBackend =
gfxPlatform::GetPlatform()->GetContentBackendFor(aLayersBackend);
TextureAllocationFlags allocFlags = TextureAllocationFlags::ALLOC_DEFAULT;
IntSize size = IntSize(400, 300);
TextureFlags textureFlags = TextureFlags::DEALLOCATE_CLIENT;
if (!gfx::Factory::AllowedSurfaceSize(size)) {
return nullptr;
}
#ifdef XP_WIN
if (aLayersBackend == LayersBackend::LAYERS_D3D11 &&
(moz2DBackend == BackendType::DIRECT2D ||
moz2DBackend == BackendType::DIRECT2D1_1)) {
// Create D3D11TextureData.
data = D3D11TextureData::Create(size, format, allocFlags);
} else if (!data && format == SurfaceFormat::B8G8R8X8 &&
moz2DBackend == BackendType::CAIRO) {
// Create DIBTextureData.
data = DIBTextureData::Create(size, format, nullptr);
}
#endif
if (!data && aLayersBackend == LayersBackend::LAYERS_BASIC) {
// Create BufferTextureData.
data = BufferTextureData::Create(size, format, moz2DBackend, aLayersBackend,
textureFlags, allocFlags, nullptr);
}
if (data) {
return MakeAndAddRef<TextureClient>(data, textureFlags, nullptr);
}
return nullptr;
}
/**
* Create a TextureHost according to the given TextureClient.
*/
already_AddRefed<TextureHost> CreateTextureHostWithBackend(
TextureClient* aClient, ISurfaceAllocator* aDeallocator,
LayersBackend& aLayersBackend) {
if (!aClient) {
return nullptr;
}
// client serialization
SurfaceDescriptor descriptor;
ReadLockDescriptor readLock = null_t();
RefPtr<TextureHost> textureHost;
aClient->ToSurfaceDescriptor(descriptor);
wr::MaybeExternalImageId id = Nothing();
return TextureHost::Create(descriptor, readLock, aDeallocator, aLayersBackend,
aClient->GetFlags(), id);
}
} // namespace layers
} // namespace mozilla