diff --git a/gfx/layers/d3d10/ThebesLayerD3D10.cpp b/gfx/layers/d3d10/ThebesLayerD3D10.cpp index 9d43039f416a..4acd6f1f9e35 100644 --- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp +++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -35,6 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ +#include "mozilla/layers/PLayers.h" #include "ThebesLayerD3D10.h" #include "gfxPlatform.h" @@ -456,6 +457,121 @@ ThebesLayerD3D10::CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode) } } } + +ShadowThebesLayerD3D10::ShadowThebesLayerD3D10(LayerManagerD3D10* aManager) + : ShadowThebesLayer(aManager, NULL) + , LayerD3D10(aManager) +{ + mImplData = static_cast(this); +} + +ShadowThebesLayerD3D10::~ShadowThebesLayerD3D10() +{ +} + +void +ShadowThebesLayerD3D10::SetFrontBuffer(const OptionalThebesBuffer& aNewFront, + const nsIntRegion& aValidRegion) +{ + NS_ABORT_IF_FALSE(OptionalThebesBuffer::Tnull_t == aNewFront.type(), + "Expected dummy front buffer initially"); +} + +void +ShadowThebesLayerD3D10::Swap( + const ThebesBuffer& aNewFront, const nsIntRegion& aUpdatedRegion, + ThebesBuffer* aNewBack, nsIntRegion* aNewBackValidRegion, + OptionalThebesBuffer* aReadOnlyFront, nsIntRegion* aFrontUpdatedRegion) +{ + nsRefPtr newBackBuffer = mTexture; + + mTexture = OpenForeign(mD3DManager->device(), aNewFront.buffer()); + NS_ABORT_IF_FALSE(mTexture, "Couldn't open foreign texture"); + + // The content process tracks back/front buffers on its own, so + // the newBack is in essence unused. + aNewBack->buffer() = aNewFront.buffer(); + + // The content process doesn't need to read back from the front + // buffer (yet). + *aReadOnlyFront = null_t(); + + // FIXME/bug 662109: synchronize using KeyedMutex +} + +void +ShadowThebesLayerD3D10::DestroyFrontBuffer() +{ +} + +void +ShadowThebesLayerD3D10::Disconnect() +{ +} + +void +ShadowThebesLayerD3D10::RenderLayer() +{ + if (!mTexture) { + return; + } + + // FIXME/bug 662109: synchronize using KeyedMutex + + nsRefPtr srView; + HRESULT hr = device()->CreateShaderResourceView(mTexture, NULL, getter_AddRefs(srView)); + if (FAILED(hr)) { + NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10."); + } + + + SetEffectTransformAndOpacity(); + + ID3D10EffectTechnique *technique = + effect()->GetTechniqueByName("RenderRGBLayerPremul"); + + effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(srView); + + nsIntRect textureRect = GetVisibleRegion().GetBounds(); + + nsIntRegionRectIterator iter(mVisibleRegion); + while (const nsIntRect *iterRect = iter.Next()) { + effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector( + ShaderConstantRectD3D10( + (float)iterRect->x, + (float)iterRect->y, + (float)iterRect->width, + (float)iterRect->height) + ); + + effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector( + ShaderConstantRectD3D10( + (float)(iterRect->x - textureRect.x) / (float)textureRect.width, + (float)(iterRect->y - textureRect.y) / (float)textureRect.height, + (float)iterRect->width / (float)textureRect.width, + (float)iterRect->height / (float)textureRect.height) + ); + + technique->GetPassByIndex(0)->Apply(0); + device()->Draw(4, 0); + } + + // FIXME/bug 662109: synchronize using KeyedMutex + + // Set back to default. + effect()->GetVariableByName("vTextureCoords")->AsVector()-> + SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f)); +} + +void +ShadowThebesLayerD3D10::Validate() +{ +} + +void +ShadowThebesLayerD3D10::LayerManagerDestroyed() +{ +} } /* namespace layers */ } /* namespace mozilla */ diff --git a/gfx/layers/d3d10/ThebesLayerD3D10.h b/gfx/layers/d3d10/ThebesLayerD3D10.h index 2b2d377bd428..95a987e4feb7 100644 --- a/gfx/layers/d3d10/ThebesLayerD3D10.h +++ b/gfx/layers/d3d10/ThebesLayerD3D10.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -101,6 +101,35 @@ private: const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion); }; +class ShadowThebesLayerD3D10 : public ShadowThebesLayer, + public LayerD3D10 +{ +public: + ShadowThebesLayerD3D10(LayerManagerD3D10* aManager); + virtual ~ShadowThebesLayerD3D10(); + + // ShadowThebesLayer impl + virtual void SetFrontBuffer(const OptionalThebesBuffer& aNewFront, + const nsIntRegion& aValidRegion); + virtual void + Swap(const ThebesBuffer& aNewFront, const nsIntRegion& aUpdatedRegion, + ThebesBuffer* aNewBack, nsIntRegion* aNewBackValidRegion, + OptionalThebesBuffer* aReadOnlyFront, nsIntRegion* aFrontUpdatedRegion); + virtual void DestroyFrontBuffer(); + + virtual void Disconnect(); + + /* LayerD3D10 implementation */ + virtual Layer* GetLayer() { return this; } + virtual void RenderLayer(); + virtual void Validate(); + virtual void LayerManagerDestroyed(); + +private: + /* Texture with our surface data */ + nsRefPtr mTexture; +}; + } /* layers */ } /* mozilla */ #endif /* GFX_THEBESLAYERD3D10_H */