Bug 648484, part 8: Implement a very basic shadow thebes layer for D3D10, only enough to support the upcoming WindowLayer. r=Bas

This commit is contained in:
Chris Jones 2011-07-06 13:29:27 -04:00
Родитель 22f7db5a6c
Коммит 065d10e894
2 изменённых файлов: 147 добавлений и 2 удалений

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

@ -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 ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -35,6 +35,7 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "mozilla/layers/PLayers.h"
#include "ThebesLayerD3D10.h" #include "ThebesLayerD3D10.h"
#include "gfxPlatform.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<LayerD3D10*>(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<ID3D10Texture2D> 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<ID3D10ShaderResourceView> 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 layers */
} /* namespace mozilla */ } /* namespace mozilla */

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

@ -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 ***** * ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -101,6 +101,35 @@ private:
const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion); 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<ID3D10Texture2D> mTexture;
};
} /* layers */ } /* layers */
} /* mozilla */ } /* mozilla */
#endif /* GFX_THEBESLAYERD3D10_H */ #endif /* GFX_THEBESLAYERD3D10_H */