Ensure that the software compositor never uses deprecated textures (bug 947038, r=mattwoodrow).

This commit is contained in:
David Anderson 2013-12-12 20:29:14 -08:00
Родитель a324b39e7f
Коммит f853c97cb8
8 изменённых файлов: 37 добавлений и 164 удалений

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

@ -72,6 +72,7 @@
#include "APZCCallbackHelper.h"
#include "nsILoadContext.h"
#include "ipc/nsGUIEventIPC.h"
#include "gfxPlatform.h"
#ifdef DEBUG
#include "PCOMContentPermissionRequestChild.h"
@ -2281,6 +2282,10 @@ 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();

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

@ -63,161 +63,6 @@ public:
RefPtr<gfx::DataSourceSurface> 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<BasicCompositor*>(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<gfxASurface> surface = ShadowLayerForwarder::OpenDescriptor(OPEN_READ_ONLY, aImage);
nsRefPtr<gfxImageSurface> 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<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE {
if (!mSurface) {
return nullptr;
}
return mSurface->GetDataSurface();
}
BasicCompositor *mCompositor;
RefPtr<SourceSurface> 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<uint8_t>());
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<DataSourceSurface> surface = Factory::CreateDataSourceSurface(mSize, mFormat);
gfxUtils::ConvertYCbCrToRGB(data, format, size,
surface->GetData(),
surface->Stride());
mSurface = surface;
return true;
}
};
TemporaryRef<DeprecatedTextureHost>
CreateBasicDeprecatedTextureHost(SurfaceDescriptorType aDescriptorType,
uint32_t aTextureHostFlags,
uint32_t aTextureFlags)
{
RefPtr<DeprecatedTextureHost> 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)
{

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

@ -58,6 +58,11 @@ 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();

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

@ -84,10 +84,6 @@ TextureHost::AsTextureHost(PTextureParent* actor)
TemporaryRef<DeprecatedTextureHost> CreateDeprecatedTextureHostOGL(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags);
// implemented in BasicCompositor.cpp
TemporaryRef<DeprecatedTextureHost> CreateBasicDeprecatedTextureHost(SurfaceDescriptorType aDescriptorType,
uint32_t aDeprecatedTextureHostFlags,
uint32_t aTextureFlags);
#ifdef XP_WIN
TemporaryRef<DeprecatedTextureHost> CreateDeprecatedTextureHostD3D9(SurfaceDescriptorType aDescriptorType,
@ -127,10 +123,6 @@ DeprecatedTextureHost::CreateDeprecatedTextureHost(SurfaceDescriptorType aDescri
aDeprecatedTextureHostFlags,
aTextureFlags);
#endif
case LAYERS_BASIC:
return CreateBasicDeprecatedTextureHost(aDescriptorType,
aDeprecatedTextureHostFlags,
aTextureFlags);
default:
MOZ_CRASH("Couldn't create texture host");
}

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

@ -138,6 +138,7 @@ ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect)
mBuffer->SetPaintWillResample(MayResample());
mBuffer->SetCompositor(mCompositeManager->GetCompositor());
mBuffer->Composite(effectChain,
GetEffectiveOpacity(),
transform,

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

@ -281,6 +281,7 @@ gfxPlatform::gfxPlatform()
, mDrawLayerBorders(false)
, mDrawTileBorders(false)
, mDrawBigImageBorders(false)
, mCompositorBackend(LAYERS_NONE)
{
mUseHarfBuzzScripts = UNINITIALIZED_VALUE;
mAllowDownloadableFonts = UNINITIALIZED_VALUE;
@ -2213,3 +2214,22 @@ 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;
}

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

@ -20,6 +20,7 @@
#include "mozilla/RefPtr.h"
#include "GfxInfoCollector.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/layers/CompositorTypes.h"
#ifdef XP_OS2
@ -619,7 +620,8 @@ public:
* This method should not be called from the compositor thread.
*/
bool PreferMemoryOverShmem() const;
bool UseDeprecatedTextures() const { return mLayersUseDeprecated; }
bool UseDeprecatedTextures() const;
void SetCompositorBackend(mozilla::layers::LayersBackend backend);
protected:
gfxPlatform();
@ -736,6 +738,7 @@ private:
bool mDrawLayerBorders;
bool mDrawTileBorders;
bool mDrawBigImageBorders;
mozilla::layers::LayersBackend mCompositorBackend;
};
#endif /* GFX_PLATFORM_H */

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

@ -988,6 +988,8 @@ void nsBaseWidget::CreateCompositor(int aWidth, int aHeight)
ImageBridgeChild::IdentifyCompositorTextureHost(textureFactoryIdentifier);
WindowUsesOMTC();
gfxPlatform::GetPlatform()->SetCompositorBackend(textureFactoryIdentifier.mParentBackend);
mLayerManager = lm;
return;
}