Backed out 5 changesets (bug 1600595) for causing webgl tests and reftests to time out.

CLOSED TREE

Backed out changeset 2f3a6a8e47bc (bug 1600595)
Backed out changeset c6712886b650 (bug 1600595)
Backed out changeset e905d5af4919 (bug 1600595)
Backed out changeset c497070467dd (bug 1600595)
Backed out changeset 27fd9a1b31f0 (bug 1600595)
This commit is contained in:
Mihai Alexandru Michis 2019-12-24 09:37:02 +02:00
parent fa5786e117
commit cd24fc1ebd
15 changed files with 177 additions and 314 deletions

View File

@ -83,10 +83,6 @@ namespace mozilla {
class Mutex;
namespace layers {
class TextureData;
}
namespace wr {
struct FontInstanceOptions;
struct FontInstancePlatformOptions;
@ -1899,15 +1895,6 @@ class GFX2D_API Factory {
static void SetSystemTextQuality(uint8_t aQuality);
static already_AddRefed<DataSourceSurface>
CreateBGRA8DataSourceSurfaceForD3D11Texture(ID3D11Texture2D* aSrcTexture);
static bool ReadbackSharedTexture(layers::TextureData* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
static bool ReadbackSharedTexture(DataSourceSurface* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
private:
static StaticRefPtr<ID2D1Device> mD2D1Device;
static StaticRefPtr<ID3D11Device> mD3D11Device;
@ -1917,14 +1904,6 @@ class GFX2D_API Factory {
static StaticRefPtr<ID2D1DeviceContext> mMTDC;
static StaticRefPtr<ID2D1DeviceContext> mOffMTDC;
static bool ReadbackSharedTexture(uint8_t* aDestData, int32_t aDestStride,
ID3D11Texture2D* aSrcTexture);
// DestTextureT can be TextureData or DataSourceSurface.
template <typename DestTextureT>
static bool ConvertSourceAndRetryReadback(DestTextureT* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture);
protected:
// This guards access to the singleton devices above, as well as the
// singleton devices in DrawTargetD2D1.
@ -1934,7 +1913,7 @@ class GFX2D_API Factory {
static StaticMutex mDTDependencyLock;
friend class DrawTargetD2D1;
#endif // WIN32
#endif
private:
static DrawEventRecorder* mRecorder;

View File

@ -45,8 +45,6 @@
# include "NativeFontResourceDWrite.h"
# include <d3d10_1.h>
# include "HelpersD2D.h"
# include "DXVA2Manager.h"
# include "mozilla/layers/TextureD3D11.h"
#endif
#include "DrawTargetCapture.h"
@ -64,8 +62,6 @@
#include "mozilla/CheckedInt.h"
#include "mozilla/layers/TextureClient.h"
#ifdef MOZ_ENABLE_FREETYPE
# include "ft2build.h"
# include FT_FREETYPE_H
@ -1165,186 +1161,6 @@ void Factory::SetGlobalEventRecorder(DrawEventRecorder* aRecorder) {
mRecorder = aRecorder;
}
#ifdef WIN32
/* static */
already_AddRefed<DataSourceSurface>
Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(
ID3D11Texture2D* aSrcTexture) {
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
RefPtr<gfx::DataSourceSurface> destTexture =
gfx::Factory::CreateDataSourceSurface(
IntSize(srcDesc.Width, srcDesc.Height), gfx::SurfaceFormat::B8G8R8A8);
if (NS_WARN_IF(!destTexture)) {
return nullptr;
}
if (!ReadbackSharedTexture(destTexture, aSrcTexture)) {
return nullptr;
}
return destTexture.forget();
}
/* static */
template <typename DestTextureT>
bool Factory::ConvertSourceAndRetryReadback(DestTextureT* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture) {
RefPtr<ID3D11Device> device;
aSrcTexture->GetDevice(getter_AddRefs(device));
if (!device) {
gfxWarning() << "Failed to get D3D11 device from source texture";
return false;
}
nsAutoCString error;
std::unique_ptr<DXVA2Manager> manager(
DXVA2Manager::CreateD3D11DXVA(nullptr, error, device));
if (!manager) {
gfxWarning() << "Failed to create DXVA2 manager!";
return false;
}
RefPtr<ID3D11Texture2D> newSrcTexture;
HRESULT hr =
manager->CopyToBGRATexture(aSrcTexture, getter_AddRefs(newSrcTexture));
if (FAILED(hr)) {
gfxWarning() << "Failed to copy to BGRA texture.";
return false;
}
return ReadbackSharedTexture(aDestCpuTexture, newSrcTexture);
}
/* static */
bool Factory::ReadbackSharedTexture(layers::TextureData* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture) {
layers::MappedTextureData mappedData;
if (!aDestCpuTexture->BorrowMappedData(mappedData)) {
gfxWarning() << "Could not access in-memory texture";
return false;
}
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
// Special case: If the source and destination have different formats and the
// destination is B8G8R8A8 then convert the source to B8G8R8A8 and readback.
if ((srcDesc.Format != DXGIFormat(mappedData.format)) &&
(mappedData.format == SurfaceFormat::B8G8R8A8)) {
return ConvertSourceAndRetryReadback(aDestCpuTexture, aSrcTexture);
}
if ((IntSize(srcDesc.Width, srcDesc.Height) != mappedData.size) ||
(srcDesc.Format != DXGIFormat(mappedData.format))) {
gfxWarning() << "Attempted readback between incompatible textures";
return false;
}
return ReadbackSharedTexture(mappedData.data, mappedData.stride, aSrcTexture);
}
/* static */
bool Factory::ReadbackSharedTexture(DataSourceSurface* aDestCpuTexture,
ID3D11Texture2D* aSrcTexture) {
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
// Special case: If the source and destination have different formats and the
// destination is B8G8R8A8 then convert the source to B8G8R8A8 and readback.
if ((srcDesc.Format != DXGIFormat(aDestCpuTexture->GetFormat())) &&
(aDestCpuTexture->GetFormat() == SurfaceFormat::B8G8R8A8)) {
return ConvertSourceAndRetryReadback(aDestCpuTexture, aSrcTexture);
}
if ((IntSize(srcDesc.Width, srcDesc.Height) != aDestCpuTexture->GetSize()) ||
(srcDesc.Format != DXGIFormat(aDestCpuTexture->GetFormat()))) {
gfxWarning() << "Attempted readback between incompatible textures";
return false;
}
gfx::DataSourceSurface::MappedSurface mappedSurface;
if (!aDestCpuTexture->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) {
return false;
}
bool ret = ReadbackSharedTexture(mappedSurface.mData, mappedSurface.mStride,
aSrcTexture);
aDestCpuTexture->Unmap();
return ret;
}
/* static */
bool Factory::ReadbackSharedTexture(uint8_t* aDestData, int32_t aDestStride,
ID3D11Texture2D* aSrcTexture) {
MOZ_ASSERT(aDestData && aDestStride && aSrcTexture);
RefPtr<ID3D11Device> device;
aSrcTexture->GetDevice(getter_AddRefs(device));
if (!device) {
gfxWarning() << "Failed to get D3D11 device from source texture";
return false;
}
RefPtr<ID3D11DeviceContext> context;
device->GetImmediateContext(getter_AddRefs(context));
if (!context) {
gfxWarning() << "Could not get an immediate D3D11 context";
return false;
}
RefPtr<IDXGIKeyedMutex> mutex;
HRESULT hr = aSrcTexture->QueryInterface(__uuidof(IDXGIKeyedMutex),
(void**)getter_AddRefs(mutex));
if (FAILED(hr) || !mutex) {
gfxWarning() << "Could not acquire source texture mutex";
return false;
}
layers::AutoTextureLock lock1(mutex, hr, 2000);
if (hr == WAIT_ABANDONED || hr == WAIT_TIMEOUT || FAILED(hr)) {
gfxWarning() << "Could not acquire DXGI surface lock in 2 seconds";
return false;
}
D3D11_TEXTURE2D_DESC srcDesc = {0};
aSrcTexture->GetDesc(&srcDesc);
srcDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
srcDesc.Usage = D3D11_USAGE_STAGING;
srcDesc.BindFlags = 0;
srcDesc.MiscFlags = 0;
srcDesc.MipLevels = 1;
RefPtr<ID3D11Texture2D> srcCpuTexture;
hr =
device->CreateTexture2D(&srcDesc, nullptr, getter_AddRefs(srcCpuTexture));
if (FAILED(hr)) {
gfxWarning() << "Could not create source texture for mapping";
return false;
}
context->CopyResource(srcCpuTexture, aSrcTexture);
D3D11_MAPPED_SUBRESOURCE srcMap;
hr = context->Map(srcCpuTexture, 0, D3D11_MAP_READ, 0, &srcMap);
if (FAILED(hr)) {
gfxWarning() << "Could not map source texture";
return false;
}
uint32_t width = srcDesc.Width;
uint32_t height = srcDesc.Height;
int bpp = BytesPerPixel(gfx::ToPixelFormat(srcDesc.Format));
for (int y = 0; y < height; y++) {
memcpy(aDestData + aDestStride * y,
(unsigned char*)(srcMap.pData) + srcMap.RowPitch * y, width * bpp);
}
context->Unmap(srcCpuTexture, 0);
return true;
}
#endif // WIN32
// static
void CriticalLogger::OutputMessage(const std::string& aString, int aLevel,
bool aNoNewline) {

View File

@ -126,16 +126,6 @@ static inline IntSize ToIntSize(const D2D1_SIZE_U& aSize) {
return IntSize(aSize.width, aSize.height);
}
static inline SurfaceFormat ToPixelFormat(const DXGI_FORMAT& aFormat) {
switch (aFormat) {
case DXGI_FORMAT_A8_UNORM:
case DXGI_FORMAT_R8_UNORM:
return SurfaceFormat::A8;
default:
return SurfaceFormat::B8G8R8A8;
}
}
static inline SurfaceFormat ToPixelFormat(const D2D1_PIXEL_FORMAT& aFormat) {
switch (aFormat.format) {
case DXGI_FORMAT_A8_UNORM:

View File

@ -18,8 +18,6 @@
# include "gfxPlatformGtk.h"
#endif
using mozilla::ipc::IShmemAllocator;
namespace mozilla {
namespace layers {
@ -31,7 +29,7 @@ class MemoryTextureData : public BufferTextureData {
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
IShmemAllocator* aAllocator);
LayersIPCChannel* aAllocator);
virtual TextureData* CreateSimilar(
LayersIPCChannel* aAllocator, LayersBackend aLayersBackend,
@ -69,7 +67,7 @@ class ShmemTextureData : public BufferTextureData {
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
IShmemAllocator* aAllocator);
LayersIPCChannel* aAllocator);
virtual TextureData* CreateSimilar(
LayersIPCChannel* aAllocator, LayersBackend aLayersBackend,
@ -112,12 +110,14 @@ bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat,
UsingX11Compositor() || aFormat == gfx::SurfaceFormat::UNKNOWN;
}
BufferTextureData* BufferTextureData::Create(
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
TextureFlags aFlags, TextureAllocationFlags aAllocFlags,
mozilla::ipc::IShmemAllocator* aAllocator, bool aIsSameProcess) {
if (!aAllocator || aIsSameProcess) {
BufferTextureData* BufferTextureData::Create(gfx::IntSize aSize,
gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend,
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
LayersIPCChannel* aAllocator) {
if (!aAllocator || aAllocator->IsSameProcess()) {
return MemoryTextureData::Create(aSize, aFormat, aMoz2DBackend,
aLayersBackend, aFlags, aAllocFlags,
aAllocator);
@ -433,7 +433,7 @@ MemoryTextureData* MemoryTextureData::Create(gfx::IntSize aSize,
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
IShmemAllocator* aAllocator) {
LayersIPCChannel* aAllocator) {
// Should have used CreateForYCbCr.
MOZ_ASSERT(aFormat != gfx::SurfaceFormat::YUV);
@ -497,7 +497,7 @@ ShmemTextureData* ShmemTextureData::Create(gfx::IntSize aSize,
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
IShmemAllocator* aAllocator) {
LayersIPCChannel* aAllocator) {
MOZ_ASSERT(aAllocator);
// Should have used CreateForYCbCr.
MOZ_ASSERT(aFormat != gfx::SurfaceFormat::YUV);

View File

@ -22,16 +22,13 @@ bool ComputeHasIntermediateBuffer(gfx::SurfaceFormat aFormat,
class BufferTextureData : public TextureData {
public:
// ShmemAllocator needs to implement IShmemAllocator and IsSameProcess,
// as done in LayersIPCChannel and ISurfaceAllocator.
template <typename ShmemAllocator>
static BufferTextureData* Create(gfx::IntSize aSize,
gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend,
LayersBackend aLayersBackend,
TextureFlags aFlags,
TextureAllocationFlags aAllocFlags,
ShmemAllocator aAllocator);
LayersIPCChannel* aAllocator);
static BufferTextureData* CreateForYCbCr(
KnowsCompositor* aAllocator, gfx::IntSize aYSize, uint32_t aYStride,
@ -72,12 +69,6 @@ class BufferTextureData : public TextureData {
gfx::SurfaceFormat GetFormat() const;
static BufferTextureData* Create(
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
TextureFlags aFlags, TextureAllocationFlags aAllocFlags,
mozilla::ipc::IShmemAllocator* aAllocator, bool aIsSameProcess);
static BufferTextureData* CreateInternal(LayersIPCChannel* aAllocator,
const BufferDescriptor& aDesc,
gfx::BackendType aMoz2DBackend,
@ -95,26 +86,6 @@ class BufferTextureData : public TextureData {
gfx::BackendType mMoz2DBackend;
};
template <typename ShmemAllocator>
inline BufferTextureData* BufferTextureData::Create(
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
TextureFlags aFlags, TextureAllocationFlags aAllocFlags,
ShmemAllocator aAllocator) {
return Create(aSize, aFormat, aMoz2DBackend, aLayersBackend, aFlags,
aAllocFlags, aAllocator, aAllocator->IsSameProcess());
}
// nullptr allocator specialization
template <>
inline BufferTextureData* BufferTextureData::Create(
gfx::IntSize aSize, gfx::SurfaceFormat aFormat,
gfx::BackendType aMoz2DBackend, LayersBackend aLayersBackend,
TextureFlags aFlags, TextureAllocationFlags aAllocFlags, std::nullptr_t) {
return Create(aSize, aFormat, aMoz2DBackend, aLayersBackend, aFlags,
aAllocFlags, nullptr, true);
}
} // namespace layers
} // namespace mozilla

View File

@ -67,14 +67,110 @@ TextureClient* D3D11ShareHandleImage::GetTextureClient(
already_AddRefed<gfx::SourceSurface>
D3D11ShareHandleImage::GetAsSourceSurface() {
RefPtr<ID3D11Texture2D> src = GetTexture();
if (!src) {
RefPtr<ID3D11Texture2D> texture = GetTexture();
if (!texture) {
gfxWarning() << "Cannot readback from shared texture because no texture is "
"available.";
return nullptr;
}
return gfx::Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture(src);
RefPtr<ID3D11Device> device;
texture->GetDevice(getter_AddRefs(device));
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
HRESULT hr;
if (desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM) {
nsAutoCString error;
std::unique_ptr<DXVA2Manager> manager(
DXVA2Manager::CreateD3D11DXVA(nullptr, error, device));
if (!manager) {
gfxWarning() << "Failed to create DXVA2 manager!";
return nullptr;
}
RefPtr<ID3D11Texture2D> outTexture;
hr = manager->CopyToBGRATexture(texture, getter_AddRefs(outTexture));
if (FAILED(hr)) {
gfxWarning() << "Failed to copy to BGRA texture.";
return nullptr;
}
texture = outTexture;
texture->GetDesc(&desc);
}
CD3D11_TEXTURE2D_DESC softDesc(desc.Format, desc.Width, desc.Height);
softDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
softDesc.BindFlags = 0;
softDesc.MiscFlags = 0;
softDesc.MipLevels = 1;
softDesc.Usage = D3D11_USAGE_STAGING;
RefPtr<ID3D11Texture2D> softTexture;
hr = device->CreateTexture2D(
&softDesc, NULL,
static_cast<ID3D11Texture2D**>(getter_AddRefs(softTexture)));
if (FAILED(hr)) {
NS_WARNING("Failed to create 2D staging texture.");
return nullptr;
}
RefPtr<ID3D11DeviceContext> context;
device->GetImmediateContext(getter_AddRefs(context));
if (!context) {
gfxCriticalError() << "Failed to get immediate context.";
return nullptr;
}
RefPtr<IDXGIKeyedMutex> mutex;
hr = texture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mutex));
if (SUCCEEDED(hr) && mutex) {
hr = mutex->AcquireSync(0, 2000);
if (hr != S_OK) {
NS_WARNING("Acquire sync didn't manage to return within 2 seconds.");
}
}
context->CopyResource(softTexture, texture);
if (SUCCEEDED(hr) && mutex) {
mutex->ReleaseSync(0);
}
RefPtr<gfx::DataSourceSurface> surface =
gfx::Factory::CreateDataSourceSurface(mSize,
gfx::SurfaceFormat::B8G8R8A8);
if (NS_WARN_IF(!surface)) {
return nullptr;
}
gfx::DataSourceSurface::MappedSurface mappedSurface;
if (!surface->Map(gfx::DataSourceSurface::WRITE, &mappedSurface)) {
return nullptr;
}
D3D11_MAPPED_SUBRESOURCE map;
hr = context->Map(softTexture, 0, D3D11_MAP_READ, 0, &map);
if (!SUCCEEDED(hr)) {
surface->Unmap();
return nullptr;
}
for (int y = 0; y < mSize.height; y++) {
memcpy(mappedSurface.mData + mappedSurface.mStride * y,
(unsigned char*)(map.pData) + map.RowPitch * y, mSize.width * 4);
}
context->Unmap(softTexture, 0);
surface->Unmap();
return surface.forget();
}
ID3D11Texture2D* D3D11ShareHandleImage::GetTexture() const { return mTexture; }

View File

@ -170,8 +170,8 @@ bool CompositorBridgeParentBase::AllocUnsafeShmem(
return PCompositorBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
}
bool CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem) {
return PCompositorBridgeParent::DeallocShmem(aShmem);
void CompositorBridgeParentBase::DeallocShmem(ipc::Shmem& aShmem) {
PCompositorBridgeParent::DeallocShmem(aShmem);
}
static inline MessageLoop* CompositorLoop() {

View File

@ -32,7 +32,7 @@
#include "mozilla/layers/CompositorOptions.h"
#include "mozilla/layers/CompositorVsyncSchedulerOwner.h"
#include "mozilla/layers/GeckoContentController.h"
#include "mozilla/layers/ISurfaceAllocator.h" // for IShmemAllocator
#include "mozilla/layers/ISurfaceAllocator.h" // for ShmemAllocator
#include "mozilla/layers/LayersMessages.h" // for TargetConfig
#include "mozilla/layers/MetricsSharingController.h"
#include "mozilla/layers/PCompositorBridgeTypes.h"
@ -106,7 +106,7 @@ struct ScopedLayerTreeRegistration {
class CompositorBridgeParentBase : public PCompositorBridgeParent,
public HostIPCAllocator,
public mozilla::ipc::IShmemAllocator,
public ShmemAllocator,
public MetricsSharingController {
friend class PCompositorBridgeParent;
@ -149,7 +149,7 @@ class CompositorBridgeParentBase : public PCompositorBridgeParent,
virtual void RegisterPayloads(LayerTransactionParent* aLayerTree,
const nsTArray<CompositionPayload>& aPayload) {}
IShmemAllocator* AsShmemAllocator() override { return this; }
ShmemAllocator* AsShmemAllocator() override { return this; }
CompositorBridgeParentBase* AsCompositorBridgeParentBase() override {
return this;
@ -170,14 +170,14 @@ class CompositorBridgeParentBase : public PCompositorBridgeParent,
void SendAsyncMessage(
const nsTArray<AsyncParentMessageData>& aMessage) override;
// IShmemAllocator
// ShmemAllocator
bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aType,
mozilla::ipc::Shmem* aShmem) override;
bool DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
void DeallocShmem(mozilla::ipc::Shmem& aShmem) override;
// MetricsSharingController
NS_IMETHOD_(MozExternalRefCountType) AddRef() override {

View File

@ -33,6 +33,7 @@ class CompositableForwarder;
class CompositorBridgeParentBase;
class TextureForwarder;
class ShmemAllocator;
class ShmemSectionAllocator;
class LegacySurfaceDescriptorAllocator;
class ClientIPCAllocator;
@ -73,7 +74,7 @@ class ISurfaceAllocator {
// down-casting
virtual mozilla::ipc::IShmemAllocator* AsShmemAllocator() { return nullptr; }
virtual ShmemAllocator* AsShmemAllocator() { return nullptr; }
virtual ShmemSectionAllocator* AsShmemSectionAllocator() { return nullptr; }
@ -155,6 +156,21 @@ class HostIPCAllocator : public ISurfaceAllocator {
bool mAboutToSendAsyncMessages = false;
};
/// An allocator can provide shared memory.
///
/// The allocated shmems can be deallocated on either process, as long as they
/// belong to the same channel.
class ShmemAllocator {
public:
virtual bool AllocShmem(size_t aSize,
mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual bool AllocUnsafeShmem(
size_t aSize, mozilla::ipc::SharedMemory::SharedMemoryType aShmType,
mozilla::ipc::Shmem* aShmem) = 0;
virtual void DeallocShmem(mozilla::ipc::Shmem& aShmem) = 0;
};
/// An allocator that can group allocations in bigger chunks of shared memory.
///
/// The allocated shmem sections can only be deallocated by the same allocator

View File

@ -18,7 +18,6 @@
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/Transport.h" // for Transport
#include "mozilla/media/MediaSystemResourceManagerParent.h" // for MediaSystemResourceManagerParent
#include "mozilla/layers/BufferTexture.h"
#include "mozilla/layers/CompositableTransactionParent.h"
#include "mozilla/layers/LayerManagerComposite.h"
#include "mozilla/layers/LayersMessages.h" // for EditReply
@ -404,11 +403,11 @@ bool ImageBridgeParent::AllocUnsafeShmem(
return PImageBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
}
bool ImageBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {
void ImageBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {
if (mClosed) {
return false;
return;
}
return PImageBridgeParent::DeallocShmem(aShmem);
PImageBridgeParent::DeallocShmem(aShmem);
}
bool ImageBridgeParent::IsSameProcess() const {
@ -587,40 +586,36 @@ mozilla::ipc::IPCResult ImageBridgeParent::RecvReadbackAsyncPluginSurface(
}
auto& textures = itTextures->value();
D3D11TextureData* displayTexData = textures->mDisplayTextureData.get();
MOZ_RELEASE_ASSERT(displayTexData);
if ((!displayTexData) || (!displayTexData->GetD3D11Texture())) {
NS_WARNING("Error in plugin display texture");
MOZ_RELEASE_ASSERT(textures->mDisplayTextureData);
RefPtr<DrawTarget> displayAsDT =
textures->mDisplayTextureData->BorrowDrawTarget();
RefPtr<SourceSurface> source = displayAsDT->Snapshot();
if (!source) {
return IPC_OK();
}
MOZ_ASSERT(displayTexData->GetSurfaceFormat() == SurfaceFormat::B8G8R8A8 ||
displayTexData->GetSurfaceFormat() == SurfaceFormat::B8G8R8X8);
SurfaceFormat format = source->GetFormat();
IntSize size = source->GetSize();
size_t length = ImageDataSerializer::ComputeRGBBufferSize(size, format);
RefPtr<ID3D11Device> device;
displayTexData->GetD3D11Texture()->GetDevice(getter_AddRefs(device));
if (!device) {
NS_WARNING("Failed to get D3D11 device for plugin display");
Shmem buffer;
if (!length ||
!AllocShmem(length, Shmem::SharedMemory::TYPE_BASIC, &buffer)) {
return IPC_OK();
}
UniquePtr<BufferTextureData> shmemTexData(BufferTextureData::Create(
displayTexData->GetSize(), displayTexData->GetSurfaceFormat(),
gfx::BackendType::SKIA, LayersBackend::LAYERS_NONE,
displayTexData->GetTextureFlags(), TextureAllocationFlags::ALLOC_DEFAULT,
this));
if (!shmemTexData) {
NS_WARNING("Could not create BufferTextureData");
RefPtr<DrawTarget> dt = Factory::CreateDrawTargetForData(
gfx::BackendType::CAIRO, buffer.get<uint8_t>(), size,
ImageDataSerializer::ComputeRGBStride(format, size.width), format);
if (!dt) {
DeallocShmem(buffer);
return IPC_OK();
}
if (!gfx::Factory::ReadbackSharedTexture(shmemTexData.get(),
displayTexData->GetD3D11Texture())) {
NS_WARNING("Failed to read plugin texture into Shmem");
return IPC_OK();
}
dt->CopySurface(source, IntRect(0, 0, size.width, size.height), IntPoint());
dt->Flush();
// Take the Shmem from the TextureData.
shmemTexData->Serialize(*aResult);
*aResult = SurfaceDescriptorBuffer(RGBDescriptor(size, format, true),
MemoryOrShmem(std::move(buffer)));
#endif // defined(OS_WIN)
return IPC_OK();
}

View File

@ -39,7 +39,7 @@ struct ImageCompositeNotificationInfo;
*/
class ImageBridgeParent final : public PImageBridgeParent,
public CompositableParentManager,
public mozilla::ipc::IShmemAllocator {
public ShmemAllocator {
public:
typedef nsTArray<CompositableOperation> EditArray;
typedef nsTArray<OpDestroy> OpDestroyArray;
@ -60,7 +60,7 @@ class ImageBridgeParent final : public PImageBridgeParent,
static bool CreateForContent(Endpoint<PImageBridgeParent>&& aEndpoint);
static void Shutdown();
IShmemAllocator* AsShmemAllocator() override { return this; }
ShmemAllocator* AsShmemAllocator() override { return this; }
void ActorDestroy(ActorDestroyReason aWhy) override;
@ -100,7 +100,7 @@ class ImageBridgeParent final : public PImageBridgeParent,
MessageLoop* GetMessageLoop() const { return mMessageLoop; }
// IShmemAllocator
// ShmemAllocator
bool AllocShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
@ -108,7 +108,7 @@ class ImageBridgeParent final : public PImageBridgeParent,
bool AllocUnsafeShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool DeallocShmem(ipc::Shmem& aShmem) override;
void DeallocShmem(ipc::Shmem& aShmem) override;
bool IsSameProcess() const override;

View File

@ -885,11 +885,11 @@ bool LayerTransactionParent::AllocUnsafeShmem(
return PLayerTransactionParent::AllocUnsafeShmem(aSize, aType, aShmem);
}
bool LayerTransactionParent::DeallocShmem(ipc::Shmem& aShmem) {
void LayerTransactionParent::DeallocShmem(ipc::Shmem& aShmem) {
if (!mIPCOpen || mDestroyed) {
return false;
return;
}
return PLayerTransactionParent::DeallocShmem(aShmem);
PLayerTransactionParent::DeallocShmem(aShmem);
}
bool LayerTransactionParent::IsSameProcess() const {

View File

@ -33,7 +33,7 @@ class CompositorBridgeParentBase;
class LayerTransactionParent final : public PLayerTransactionParent,
public CompositableParentManager,
public mozilla::ipc::IShmemAllocator {
public ShmemAllocator {
typedef nsTArray<Edit> EditArray;
typedef nsTArray<OpDestroy> OpDestroyArray;
typedef nsTArray<PluginWindowData> PluginsArray;
@ -61,7 +61,7 @@ class LayerTransactionParent final : public PLayerTransactionParent,
LayersObserverEpoch GetChildEpoch() const { return mChildEpoch; }
bool ShouldParentObserveEpoch();
IShmemAllocator* AsShmemAllocator() override { return this; }
ShmemAllocator* AsShmemAllocator() override { return this; }
bool AllocShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
@ -69,7 +69,7 @@ class LayerTransactionParent final : public PLayerTransactionParent,
bool AllocUnsafeShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool DeallocShmem(ipc::Shmem& aShmem) override;
void DeallocShmem(ipc::Shmem& aShmem) override;
bool IsSameProcess() const override;

View File

@ -134,11 +134,11 @@ bool VideoBridgeParent::AllocUnsafeShmem(
return PVideoBridgeParent::AllocUnsafeShmem(aSize, aType, aShmem);
}
bool VideoBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {
void VideoBridgeParent::DeallocShmem(ipc::Shmem& aShmem) {
if (mClosed) {
return false;
return;
}
return PVideoBridgeParent::DeallocShmem(aShmem);
PVideoBridgeParent::DeallocShmem(aShmem);
}
bool VideoBridgeParent::IsSameProcess() const {

View File

@ -18,7 +18,7 @@ class CompositorThreadHolder;
class VideoBridgeParent final : public PVideoBridgeParent,
public HostIPCAllocator,
public mozilla::ipc::IShmemAllocator {
public ShmemAllocator {
public:
~VideoBridgeParent();
@ -46,18 +46,18 @@ class VideoBridgeParent final : public PVideoBridgeParent,
const nsTArray<AsyncParentMessageData>& aMessage) override;
// ISurfaceAllocator
IShmemAllocator* AsShmemAllocator() override { return this; }
ShmemAllocator* AsShmemAllocator() override { return this; }
bool IsSameProcess() const override;
bool IPCOpen() const override { return !mClosed; }
// IShmemAllocator
// ShmemAllocator
bool AllocShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool AllocUnsafeShmem(size_t aSize, ipc::SharedMemory::SharedMemoryType aType,
ipc::Shmem* aShmem) override;
bool DeallocShmem(ipc::Shmem& aShmem) override;
void DeallocShmem(ipc::Shmem& aShmem) override;
private:
explicit VideoBridgeParent(VideoBridgeSource aSource);