From ef063fb0d4a6eecae13ecd2b915d1137bb60f4db Mon Sep 17 00:00:00 2001 From: Phil Ringnalda Date: Thu, 12 Dec 2013 23:33:50 -0800 Subject: [PATCH] Back out b6f9dbc91dc4 (bug 947038) for Cipc crashes --- dom/ipc/TabChild.cpp | 5 - gfx/layers/basic/BasicCompositor.cpp | 155 ++++++++++++++++++ gfx/layers/client/ContentClient.cpp | 5 - gfx/layers/composite/TextureHost.cpp | 8 + gfx/layers/composite/ThebesLayerComposite.cpp | 1 - gfx/thebes/gfxPlatform.cpp | 20 --- gfx/thebes/gfxPlatform.h | 5 +- widget/xpwidgets/nsBaseWidget.cpp | 2 - 8 files changed, 164 insertions(+), 37 deletions(-) diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 7e88a30e1b88..8306641297ff 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -72,7 +72,6 @@ #include "APZCCallbackHelper.h" #include "nsILoadContext.h" #include "ipc/nsGUIEventIPC.h" -#include "gfxPlatform.h" #ifdef DEBUG #include "PCOMContentPermissionRequestChild.h" @@ -2282,10 +2281,6 @@ TabChild::InitRenderingState() NS_WARNING("failed to properly allocate layer transaction"); return false; } - - // Track which compositor backend is in use (see bug 947038). This can - // be removed when deprecated textures are removed. - gfxPlatform::GetPlatform()->SetCompositorBackend(mTextureFactoryIdentifier.mParentBackend); } else { // Pushing transactions to the parent content. shadowManager = remoteFrame->SendPLayerTransactionConstructor(); diff --git a/gfx/layers/basic/BasicCompositor.cpp b/gfx/layers/basic/BasicCompositor.cpp index 0bc966af4163..cc934831b3b8 100644 --- a/gfx/layers/basic/BasicCompositor.cpp +++ b/gfx/layers/basic/BasicCompositor.cpp @@ -63,6 +63,161 @@ public: RefPtr mSurface; }; +/** + * Texture source and host implementaion for software compositing. + */ +class DeprecatedTextureHostBasic : public DeprecatedTextureHost + , public TextureSourceBasic +{ +public: + DeprecatedTextureHostBasic() + : mCompositor(nullptr) + {} + + SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; } + + virtual IntSize GetSize() const MOZ_OVERRIDE { return mSize; } + + virtual TextureSourceBasic* AsSourceBasic() MOZ_OVERRIDE { return this; } + + SourceSurface *GetSurface() MOZ_OVERRIDE { return mSurface; } + + virtual void SetCompositor(Compositor* aCompositor) + { + mCompositor = static_cast(aCompositor); + } + + virtual const char *Name() { return "DeprecatedTextureHostBasic"; } + +protected: + virtual void UpdateImpl(const SurfaceDescriptor& aImage, + nsIntRegion *aRegion, + nsIntPoint*) MOZ_OVERRIDE + { + AutoOpenSurface surf(OPEN_READ_ONLY, aImage); + nsRefPtr surface = ShadowLayerForwarder::OpenDescriptor(OPEN_READ_ONLY, aImage); + nsRefPtr image = surface->GetAsImageSurface(); + mFormat = ImageFormatToSurfaceFormat(image->Format()); + mSize = IntSize(image->Width(), image->Height()); + mSurface = Factory::CreateWrappingDataSourceSurface(image->Data(), + image->Stride(), + mSize, + mFormat); + } + + virtual bool EnsureSurface() { + return true; + } + + virtual bool Lock() MOZ_OVERRIDE { + return EnsureSurface(); + } + + virtual TemporaryRef GetAsSurface() MOZ_OVERRIDE { + if (!mSurface) { + return nullptr; + } + return mSurface->GetDataSurface(); + } + + BasicCompositor *mCompositor; + RefPtr mSurface; + IntSize mSize; + SurfaceFormat mFormat; +}; + +void +DeserializerToPlanarYCbCrImageData(YCbCrImageDataDeserializer& aDeserializer, PlanarYCbCrData& aData) +{ + aData.mYChannel = aDeserializer.GetYData(); + aData.mYStride = aDeserializer.GetYStride(); + aData.mYSize = aDeserializer.GetYSize(); + aData.mCbChannel = aDeserializer.GetCbData(); + aData.mCrChannel = aDeserializer.GetCrData(); + aData.mCbCrStride = aDeserializer.GetCbCrStride(); + aData.mCbCrSize = aDeserializer.GetCbCrSize(); + aData.mPicSize = aDeserializer.GetYSize(); +} + +class YCbCrDeprecatedTextureHostBasic : public DeprecatedTextureHostBasic +{ +public: + virtual void UpdateImpl(const SurfaceDescriptor& aImage, + nsIntRegion *aRegion, + nsIntPoint*) MOZ_OVERRIDE + { + MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TYCbCrImage); + mSurface = nullptr; + ConvertImageToRGB(aImage); + } + + virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage, + nsIntRegion* aRegion) MOZ_OVERRIDE + { + MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TYCbCrImage); + mSurface = nullptr; + } + + virtual bool EnsureSurface() MOZ_OVERRIDE + { + if (mSurface) { + return true; + } + if (!mBuffer) { + return false; + } + return ConvertImageToRGB(*mBuffer); + } + + bool ConvertImageToRGB(const SurfaceDescriptor& aImage) + { + YCbCrImageDataDeserializer deserializer(aImage.get_YCbCrImage().data().get()); + PlanarYCbCrData data; + DeserializerToPlanarYCbCrImageData(deserializer, data); + + gfxImageFormat format = gfxImageFormatRGB24; + gfxIntSize size; + gfxUtils::GetYCbCrToRGBDestFormatAndSize(data, format, size); + if (size.width > PlanarYCbCrImage::MAX_DIMENSION || + size.height > PlanarYCbCrImage::MAX_DIMENSION) { + NS_ERROR("Illegal image dest width or height"); + return false; + } + + mSize = ToIntSize(size); + mFormat = (format == gfxImageFormatRGB24) + ? FORMAT_B8G8R8X8 + : FORMAT_B8G8R8A8; + + RefPtr surface = Factory::CreateDataSourceSurface(mSize, mFormat); + gfxUtils::ConvertYCbCrToRGB(data, format, size, + surface->GetData(), + surface->Stride()); + + mSurface = surface; + return true; + } +}; + +TemporaryRef +CreateBasicDeprecatedTextureHost(SurfaceDescriptorType aDescriptorType, + uint32_t aTextureHostFlags, + uint32_t aTextureFlags) +{ + RefPtr result = nullptr; + if (aDescriptorType == SurfaceDescriptor::TYCbCrImage) { + result = new YCbCrDeprecatedTextureHostBasic(); + } else { + MOZ_ASSERT(aDescriptorType == SurfaceDescriptor::TShmem || + aDescriptorType == SurfaceDescriptor::TMemoryImage, + "We can only support Shmem currently"); + result = new DeprecatedTextureHostBasic(); + } + + result->SetFlags(aTextureFlags); + return result.forget(); +} + BasicCompositor::BasicCompositor(nsIWidget *aWidget) : mWidget(aWidget) { diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index 157c01970fcf..544784812d91 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -58,11 +58,6 @@ ContentClient::CreateContentClient(CompositableForwarder* aForwarder) useDeprecatedTextures = gfxPlatform::GetPlatform()->UseDeprecatedTextures(); #endif - // Always use new textures for the basic compositor. - if (backend == LAYERS_BASIC) { - useDeprecatedTextures = false; - } - #ifdef XP_WIN if (backend == LAYERS_D3D11) { useDoubleBuffering = !!gfxWindowsPlatform::GetPlatform()->GetD2DDevice(); diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 4caeb0b8030a..5e4da901d9ac 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -84,6 +84,10 @@ TextureHost::AsTextureHost(PTextureParent* actor) TemporaryRef CreateDeprecatedTextureHostOGL(SurfaceDescriptorType aDescriptorType, uint32_t aDeprecatedTextureHostFlags, uint32_t aTextureFlags); +// implemented in BasicCompositor.cpp +TemporaryRef CreateBasicDeprecatedTextureHost(SurfaceDescriptorType aDescriptorType, + uint32_t aDeprecatedTextureHostFlags, + uint32_t aTextureFlags); #ifdef XP_WIN TemporaryRef CreateDeprecatedTextureHostD3D9(SurfaceDescriptorType aDescriptorType, @@ -123,6 +127,10 @@ DeprecatedTextureHost::CreateDeprecatedTextureHost(SurfaceDescriptorType aDescri aDeprecatedTextureHostFlags, aTextureFlags); #endif + case LAYERS_BASIC: + return CreateBasicDeprecatedTextureHost(aDescriptorType, + aDeprecatedTextureHostFlags, + aTextureFlags); default: MOZ_CRASH("Couldn't create texture host"); } diff --git a/gfx/layers/composite/ThebesLayerComposite.cpp b/gfx/layers/composite/ThebesLayerComposite.cpp index 7a9cc3f00c45..1f35533634d0 100644 --- a/gfx/layers/composite/ThebesLayerComposite.cpp +++ b/gfx/layers/composite/ThebesLayerComposite.cpp @@ -138,7 +138,6 @@ ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect) mBuffer->SetPaintWillResample(MayResample()); - mBuffer->SetCompositor(mCompositeManager->GetCompositor()); mBuffer->Composite(effectChain, GetEffectiveOpacity(), transform, diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 89c74cc2c52e..b563f75429e4 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -281,7 +281,6 @@ gfxPlatform::gfxPlatform() , mDrawLayerBorders(false) , mDrawTileBorders(false) , mDrawBigImageBorders(false) - , mCompositorBackend(LAYERS_NONE) { mUseHarfBuzzScripts = UNINITIALIZED_VALUE; mAllowDownloadableFonts = UNINITIALIZED_VALUE; @@ -2214,22 +2213,3 @@ gfxPlatform::ComponentAlphaEnabled() InitLayersAccelerationPrefs(); return sComponentAlphaEnabled; } - -void -gfxPlatform::SetCompositorBackend(mozilla::layers::LayersBackend backend) -{ - // The compositor backend should always be the same after one has been chosen. - MOZ_ASSERT(mCompositorBackend == LAYERS_NONE || mCompositorBackend == backend); - if (mCompositorBackend == LAYERS_NONE) { - mCompositorBackend = backend; - } -} - -bool -gfxPlatform::UseDeprecatedTextures() const -{ - if (mCompositorBackend == LAYERS_BASIC) { - return false; - } - return mLayersUseDeprecated; -} diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index 64d138698558..27ff830fd51e 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -20,7 +20,6 @@ #include "mozilla/RefPtr.h" #include "GfxInfoCollector.h" -#include "mozilla/layers/LayersTypes.h" #include "mozilla/layers/CompositorTypes.h" #ifdef XP_OS2 @@ -620,8 +619,7 @@ public: * This method should not be called from the compositor thread. */ bool PreferMemoryOverShmem() const; - bool UseDeprecatedTextures() const; - void SetCompositorBackend(mozilla::layers::LayersBackend backend); + bool UseDeprecatedTextures() const { return mLayersUseDeprecated; } protected: gfxPlatform(); @@ -738,7 +736,6 @@ private: bool mDrawLayerBorders; bool mDrawTileBorders; bool mDrawBigImageBorders; - mozilla::layers::LayersBackend mCompositorBackend; }; #endif /* GFX_PLATFORM_H */ diff --git a/widget/xpwidgets/nsBaseWidget.cpp b/widget/xpwidgets/nsBaseWidget.cpp index f8f4ce68d058..1916ced3277d 100644 --- a/widget/xpwidgets/nsBaseWidget.cpp +++ b/widget/xpwidgets/nsBaseWidget.cpp @@ -988,8 +988,6 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight) ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier); WindowUsesOMTC(); - gfxPlatform::GetPlatform()->SetCompositorBackend(textureFactoryIdentifier.mParentBackend); - mLayerManager = lm; return; }