From c3983bf9cc7f9e5d67594f42f66e72ca5d5787ec Mon Sep 17 00:00:00 2001 From: Nicolas Silva Date: Mon, 31 Mar 2014 11:07:40 +0800 Subject: [PATCH] Bug 957560 - Fix new textures on windows (OMTC). r=mattwoodrow --- gfx/layers/client/CanvasClient.cpp | 35 ++++++++++++++----- gfx/layers/client/ContentClient.cpp | 5 --- gfx/layers/client/TextureClient.cpp | 8 +++-- gfx/layers/composite/ThebesLayerComposite.cpp | 1 - gfx/layers/d3d11/TextureD3D11.cpp | 18 +++++++--- gfx/layers/d3d9/TextureD3D9.cpp | 8 ++--- gfx/layers/ipc/ShadowLayers.cpp | 4 +++ gfx/thebes/gfxPlatform.cpp | 2 +- modules/libpref/src/init/all.js | 7 ++-- 9 files changed, 57 insertions(+), 31 deletions(-) diff --git a/gfx/layers/client/CanvasClient.cpp b/gfx/layers/client/CanvasClient.cpp index cc19ea6d23c..dddc829dd4c 100644 --- a/gfx/layers/client/CanvasClient.cpp +++ b/gfx/layers/client/CanvasClient.cpp @@ -65,12 +65,21 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) : gfxContentType::COLOR_ALPHA; gfxImageFormat format = gfxPlatform::GetPlatform()->OptimalFormatForContent(contentType); - mBuffer = CreateBufferTextureClient(gfx::ImageFormatToSurfaceFormat(format), - TEXTURE_FLAGS_DEFAULT, - gfxPlatform::GetPlatform()->GetPreferredCanvasBackend()); - MOZ_ASSERT(mBuffer->AsTextureClientSurface()); - mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize); - + mBuffer = CreateTextureClientForDrawing(gfx::ImageFormatToSurfaceFormat(format), + TEXTURE_FLAGS_DEFAULT, + gfxPlatform::GetPlatform()->GetPreferredCanvasBackend(), + aSize); + bool allocSuccess = false; + if (mBuffer->AsTextureClientSurface()) { + allocSuccess = mBuffer->AsTextureClientSurface()->AllocateForSurface(aSize); + } else { + MOZ_ASSERT(mBuffer->AsTextureClientDrawTarget()); + allocSuccess = mBuffer->AsTextureClientDrawTarget()->AllocateForSurface(aSize); + } + if (!allocSuccess) { + mBuffer = nullptr; + return; + } bufferCreated = true; } @@ -81,8 +90,18 @@ CanvasClient2D::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) bool updated = false; { // Restrict drawTarget to a scope so that terminates before Unlock. - nsRefPtr surface = - mBuffer->AsTextureClientSurface()->GetAsSurface(); + nsRefPtr surface; + if (mBuffer->AsTextureClientSurface()) { + surface = mBuffer->AsTextureClientSurface()->GetAsSurface(); + } else { + RefPtr dt + = mBuffer->AsTextureClientDrawTarget()->GetAsDrawTarget(); + if (dt) { + surface = gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(dt); + } + // the DrawTarget will be kept alive until mBuffer->Unlock() so it's + // OK to let go of dt before we destroy surface. + } if (surface) { aLayer->DeprecatedUpdateSurface(surface); updated = true; diff --git a/gfx/layers/client/ContentClient.cpp b/gfx/layers/client/ContentClient.cpp index cda7008e4f3..369a6970fe2 100644 --- a/gfx/layers/client/ContentClient.cpp +++ b/gfx/layers/client/ContentClient.cpp @@ -51,12 +51,7 @@ ContentClient::CreateContentClient(CompositableForwarder* aForwarder) bool useDoubleBuffering = false; bool useDeprecatedTextures = true; - // XXX We need support for gralloc with non-deprecated textures content before - // we can use them with FirefoxOS (bug 946720). We need the same locking for - // Windows. -#if !defined(XP_WIN) useDeprecatedTextures = gfxPlatform::GetPlatform()->UseDeprecatedTextures(); -#endif #ifdef XP_WIN if (backend == LayersBackend::LAYERS_D3D11) { diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index 1035ce1590e..aa977dfa104 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -282,6 +282,8 @@ TextureClient::CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator, aMoz2DBackend = gfxPlatform::GetPlatform()->GetContentBackend(); } + int32_t maxTextureSize = aAllocator->GetMaxTextureSize(); + RefPtr result; #ifdef XP_WIN @@ -290,9 +292,10 @@ TextureClient::CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator, (aMoz2DBackend == gfx::BackendType::DIRECT2D || aMoz2DBackend == gfx::BackendType::DIRECT2D1_1) && gfxWindowsPlatform::GetPlatform()->GetD2DDevice() && - !(aTextureFlags & TEXTURE_ALLOC_FALLBACK)) { - result = new TextureClientD3D11(aFormat, aTextureFlags); + if (aSizeHint.width <= maxTextureSize && aSizeHint.height <= maxTextureSize) { + result = new TextureClientD3D11(aFormat, aTextureFlags); + } } if (parentBackend == LayersBackend::LAYERS_D3D9 && aMoz2DBackend == gfx::BackendType::CAIRO && @@ -337,7 +340,6 @@ TextureClient::CreateTextureClientForDrawing(ISurfaceAllocator* aAllocator, if (!DisableGralloc(aFormat, aSizeHint)) { // Don't allow Gralloc texture clients to exceed the maximum texture size. // BufferTextureClients have code to handle tiling the surface client-side. - int32_t maxTextureSize = aAllocator->GetMaxTextureSize(); if (aSizeHint.width <= maxTextureSize && aSizeHint.height <= maxTextureSize) { result = new GrallocTextureClientOGL(aAllocator, aFormat, aMoz2DBackend, aTextureFlags); diff --git a/gfx/layers/composite/ThebesLayerComposite.cpp b/gfx/layers/composite/ThebesLayerComposite.cpp index 40b6102a9e0..7db09829d9e 100644 --- a/gfx/layers/composite/ThebesLayerComposite.cpp +++ b/gfx/layers/composite/ThebesLayerComposite.cpp @@ -132,7 +132,6 @@ ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect) EffectChain effectChain(this); LayerManagerComposite::AutoAddMaskEffect autoMaskEffect(mMaskLayer, effectChain); - nsIntRegion visibleRegion = GetEffectiveVisibleRegion(); TiledLayerProperties tiledLayerProps; diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp index 801cee68278..b5b01d1c7df 100644 --- a/gfx/layers/d3d11/TextureD3D11.cpp +++ b/gfx/layers/d3d11/TextureD3D11.cpp @@ -171,6 +171,10 @@ bool TextureClientD3D11::Lock(OpenMode aMode) { MOZ_ASSERT(!mIsLocked, "The Texture is already locked!"); + if (!mTexture) { + return false; + } + LockD3DTexture(mTexture.get()); mIsLocked = true; @@ -211,6 +215,10 @@ TextureClientD3D11::GetAsDrawTarget() return mDrawTarget; } + if (!mTexture) { + return nullptr; + } + mDrawTarget = Factory::CreateDrawTargetForD3D10Texture(mTexture, mFormat); return mDrawTarget; } @@ -221,7 +229,7 @@ TextureClientD3D11::AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlag mSize = aSize; ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device(); - CD3D10_TEXTURE2D_DESC newDesc(SurfaceFormatToDXGIFormat(mFormat), + CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1, D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE); @@ -329,10 +337,10 @@ DataTextureSourceD3D11::Update(DataSourceSurface* aSurface, nsIntRegion* aDestRegion, IntPoint* aSrcOffset) { - // Right now we only support null aDestRegion and aSrcOffset (which means) - // full surface update. Incremental update is only used on Mac so it is - // not clear that we ever will need to support it for D3D. - MOZ_ASSERT(!aDestRegion && !aSrcOffset); + // Right now we only support full surface update. If aDestRegion is provided, + // It will be ignered. Incremental update with a source offset is only used + // on Mac so it is not clear that we ever will need to support it for D3D. + MOZ_ASSERT(!aSrcOffset); MOZ_ASSERT(aSurface); if (!mCompositor || !mCompositor->GetDevice()) { diff --git a/gfx/layers/d3d9/TextureD3D9.cpp b/gfx/layers/d3d9/TextureD3D9.cpp index e8016e75b32..61d44133645 100644 --- a/gfx/layers/d3d9/TextureD3D9.cpp +++ b/gfx/layers/d3d9/TextureD3D9.cpp @@ -1061,10 +1061,10 @@ DataTextureSourceD3D9::Update(gfx::DataSourceSurface* aSurface, nsIntRegion* aDestRegion, gfx::IntPoint* aSrcOffset) { - // Right now we only support null aDestRegion and aSrcOffset (which means - // full surface update). Incremental update is only used on Mac so it is - // not clear that we ever will need to support it for D3D. - MOZ_ASSERT(!aDestRegion && !aSrcOffset); + // Right now we only support full surface update. If aDestRegion is provided, + // It will be ignered. Incremental update with a source offset is only used + // on Mac so it is not clear that we ever will need to support it for D3D. + MOZ_ASSERT(!aSrcOffset); if (!mCompositor || !mCompositor->device()) { NS_WARNING("No D3D device to update the texture."); diff --git a/gfx/layers/ipc/ShadowLayers.cpp b/gfx/layers/ipc/ShadowLayers.cpp index cc7600a985e..6d29d20ca6e 100644 --- a/gfx/layers/ipc/ShadowLayers.cpp +++ b/gfx/layers/ipc/ShadowLayers.cpp @@ -449,6 +449,10 @@ void ShadowLayerForwarder::RemoveTextureFromCompositable(CompositableClient* aCompositable, TextureClient* aTexture) { + MOZ_ASSERT(aCompositable); + MOZ_ASSERT(aCompositable->GetIPDLActor()); + MOZ_ASSERT(aTexture); + MOZ_ASSERT(aTexture->GetIPDLActor()); mTxn->AddEdit(OpRemoveTexture(nullptr, aCompositable->GetIPDLActor(), nullptr, aTexture->GetIPDLActor())); if (aTexture->GetFlags() & TEXTURE_DEALLOCATE_CLIENT) { diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp index 4f2b16b3581..bf2d1054e23 100644 --- a/gfx/thebes/gfxPlatform.cpp +++ b/gfx/thebes/gfxPlatform.cpp @@ -273,7 +273,7 @@ gfxPlatform::gfxPlatform() #ifdef XP_WIN // XXX - When 957560 is fixed, the pref can go away entirely mLayersUseDeprecated = - Preferences::GetBool("layers.use-deprecated-textures", true) + Preferences::GetBool("layers.use-deprecated-textures", false) && !gfxPrefs::LayersPreferOpenGL(); #else mLayersUseDeprecated = false; diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index b37ad139d74..20c7e280928 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -4002,13 +4002,12 @@ pref("layers.offmainthreadcomposition.enabled", false); // -1 -> default (match layout.frame_rate or 60 FPS) // 0 -> full-tilt mode: Recomposite even if not transaction occured. pref("layers.offmainthreadcomposition.frame-rate", -1); -// Whether to use the deprecated texture architecture rather than the new one. -#ifndef XP_WIN + +#ifdef XP_WIN // Asynchonous video compositing using the ImageBridge IPDL protocol. // requires off-main-thread compositing. // Never works on Windows, so no point pref'ing it on. -pref("layers.async-video.enabled",false); -pref("layers.use-deprecated-textures", true); +pref("layers.async-video.enabled", false); #endif #ifdef MOZ_X11