2010-05-24 08:28:51 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
#ifndef GFX_LAYERMANAGERD3D9_H
|
|
|
|
#define GFX_LAYERMANAGERD3D9_H
|
|
|
|
|
|
|
|
#include "Layers.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <d3d9.h>
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
#include "DeviceManagerD3D9.h"
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class LayerD3D9;
|
|
|
|
class ThebesLayerD3D9;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the LayerManager used for Direct3D 9. For now this will render on
|
|
|
|
* the main thread.
|
|
|
|
*/
|
2013-05-29 14:59:24 -07:00
|
|
|
class LayerManagerD3D9 : public LayerManager {
|
2010-05-24 08:28:51 -07:00
|
|
|
public:
|
|
|
|
LayerManagerD3D9(nsIWidget *aWidget);
|
|
|
|
virtual ~LayerManagerD3D9();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initializes the layer manager, this is when the layer manager will
|
|
|
|
* actually access the device and attempt to create the swap chain used
|
|
|
|
* to draw to the window. If this method fails the device cannot be used.
|
|
|
|
* This function is not threadsafe.
|
|
|
|
*
|
|
|
|
* \return True is initialization was succesful, false when it was not.
|
|
|
|
*/
|
2012-02-27 13:33:19 -08:00
|
|
|
bool Initialize(bool force = false);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
/*
|
2010-05-28 20:27:03 -07:00
|
|
|
* Sets the clipping region for this layer manager. This is important on
|
2010-05-24 08:28:51 -07:00
|
|
|
* windows because using OGL we no longer have GDI's native clipping. Therefor
|
|
|
|
* widget must tell us what part of the screen is being invalidated,
|
|
|
|
* and we should clip to this.
|
|
|
|
*
|
|
|
|
* \param aClippingRegion Region to clip to. Setting an empty region
|
|
|
|
* will disable clipping.
|
|
|
|
*/
|
|
|
|
void SetClippingRegion(const nsIntRegion& aClippingRegion);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* LayerManager implementation.
|
|
|
|
*/
|
2010-09-15 15:15:49 -07:00
|
|
|
virtual void Destroy();
|
|
|
|
|
2011-01-19 00:27:54 -08:00
|
|
|
virtual void BeginTransaction();
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2011-01-19 00:27:54 -08:00
|
|
|
virtual void BeginTransactionWithTarget(gfxContext* aTarget);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
void EndConstruction();
|
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT);
|
2011-01-19 00:27:54 -08:00
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
struct CallbackInfo {
|
|
|
|
DrawThebesLayerCallback Callback;
|
|
|
|
void *CallbackData;
|
|
|
|
};
|
|
|
|
|
2011-01-19 00:27:54 -08:00
|
|
|
virtual void EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 06:20:42 -07:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags = END_DEFAULT);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
const CallbackInfo &GetCallbackInfo() { return mCurrentCallbackInfo; }
|
|
|
|
|
|
|
|
void SetRoot(Layer* aLayer);
|
2010-05-28 20:27:03 -07:00
|
|
|
|
2013-12-20 08:46:29 -08:00
|
|
|
virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize)
|
2011-07-08 03:42:21 -07:00
|
|
|
{
|
|
|
|
if (!mDeviceManager)
|
|
|
|
return false;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t maxSize = mDeviceManager->GetMaxTextureSize();
|
2013-12-20 08:46:29 -08:00
|
|
|
return aSize <= gfx::IntSize(maxSize, maxSize);
|
2011-07-08 03:42:21 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual int32_t GetMaxTextureSize() const
|
2012-05-22 16:15:16 -07:00
|
|
|
{
|
|
|
|
return mDeviceManager->GetMaxTextureSize();
|
|
|
|
}
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
virtual already_AddRefed<ThebesLayer> CreateThebesLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<ContainerLayer> CreateContainerLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<ImageLayer> CreateImageLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<ColorLayer> CreateColorLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
|
|
|
|
|
2011-02-16 14:43:30 -08:00
|
|
|
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer();
|
|
|
|
|
2014-01-23 10:26:41 -08:00
|
|
|
virtual LayersBackend GetBackendType() { return LayersBackend::LAYERS_D3D9; }
|
2010-09-03 11:01:05 -07:00
|
|
|
virtual void GetBackendName(nsAString& name) { name.AssignLiteral("Direct3D 9"); }
|
2010-09-15 15:16:02 -07:00
|
|
|
bool DeviceWasRemoved() { return deviceManager()->DeviceWasRemoved(); }
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper methods.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetClippingEnabled(bool aEnabled);
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
void SetShaderMode(DeviceManagerD3D9::ShaderMode aMode,
|
|
|
|
Layer* aMask, bool aIs2D = true)
|
|
|
|
{ mDeviceManager->SetShaderMode(aMode, aMask, aIs2D); }
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2010-08-10 16:32:45 -07:00
|
|
|
IDirect3DDevice9 *device() const { return mDeviceManager->device(); }
|
|
|
|
DeviceManagerD3D9 *deviceManager() const { return mDeviceManager; }
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2010-08-26 13:44:53 -07:00
|
|
|
/**
|
|
|
|
* Return pointer to the Nv3DVUtils instance. Re-direct to mDeviceManager.
|
|
|
|
*/
|
2013-07-20 01:48:55 -07:00
|
|
|
Nv3DVUtils *GetNv3DVUtils() { return mDeviceManager ? mDeviceManager->GetNv3DVUtils() : nullptr; }
|
2010-08-26 13:44:53 -07:00
|
|
|
|
2010-09-02 20:50:29 -07:00
|
|
|
virtual const char* Name() const { return "D3D9"; }
|
|
|
|
|
2010-10-08 09:02:53 -07:00
|
|
|
void ReportFailure(const nsACString &aMsg, HRESULT aCode);
|
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
bool CompositingDisabled() { return mCompositingDisabled; }
|
|
|
|
void SetCompositingDisabled(bool aCompositingDisabled) { mCompositingDisabled = aCompositingDisabled; }
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
private:
|
2010-09-15 15:15:56 -07:00
|
|
|
/* Device manager instance for this layer manager */
|
|
|
|
nsRefPtr<DeviceManagerD3D9> mDeviceManager;
|
2010-08-10 16:32:45 -07:00
|
|
|
|
|
|
|
/* Swap chain associated with this layer manager */
|
|
|
|
nsRefPtr<SwapChainD3D9> mSwapChain;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
/* Widget associated with this layer manager */
|
|
|
|
nsIWidget *mWidget;
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-05-28 20:27:03 -07:00
|
|
|
/*
|
2013-07-20 01:48:55 -07:00
|
|
|
* Context target, nullptr when drawing directly to our swap chain.
|
2010-05-24 08:28:51 -07:00
|
|
|
*/
|
|
|
|
nsRefPtr<gfxContext> mTarget;
|
|
|
|
|
|
|
|
/* Callback info for current transaction */
|
|
|
|
CallbackInfo mCurrentCallbackInfo;
|
2010-05-28 20:27:03 -07:00
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
/*
|
|
|
|
* Region we're clipping our current drawing to.
|
|
|
|
*/
|
|
|
|
nsIntRegion mClippingRegion;
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2011-01-19 00:27:54 -08:00
|
|
|
/*
|
|
|
|
* Device reset count at last paint. Whenever this changes, we need to
|
|
|
|
* do a full layer tree update.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mDeviceResetCount;
|
2011-01-19 00:27:54 -08:00
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
/*
|
|
|
|
* True if we should only be drawing layer contents, not
|
|
|
|
* compositing them to the target.
|
|
|
|
*/
|
|
|
|
bool mCompositingDisabled;
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
/*
|
|
|
|
* Render the current layer tree to the active target.
|
|
|
|
*/
|
|
|
|
void Render();
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
/*
|
|
|
|
* Setup the pipeline.
|
|
|
|
*/
|
|
|
|
void SetupPipeline();
|
2010-08-10 16:32:45 -07:00
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
/*
|
|
|
|
* Copies the content of our backbuffer to the set transaction target.
|
|
|
|
*/
|
|
|
|
void PaintToTarget();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General information and tree management for OGL layers.
|
|
|
|
*/
|
|
|
|
class LayerD3D9
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LayerD3D9(LayerManagerD3D9 *aManager);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
virtual LayerD3D9 *GetFirstChildD3D9() { return nullptr; }
|
2010-05-24 08:28:51 -07:00
|
|
|
|
|
|
|
void SetFirstChild(LayerD3D9 *aParent);
|
|
|
|
|
|
|
|
virtual Layer* GetLayer() = 0;
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
virtual void RenderLayer() = 0;
|
2010-05-24 08:28:51 -07:00
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
/**
|
2010-09-14 03:56:39 -07:00
|
|
|
/* This function may be used on device resets to clear all VRAM resources
|
|
|
|
* that a layer might be using.
|
|
|
|
*/
|
|
|
|
virtual void CleanResources() {}
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
IDirect3DDevice9 *device() const { return mD3DManager->device(); }
|
2010-09-15 15:15:49 -07:00
|
|
|
|
|
|
|
/* Called by the layer manager when it's destroyed */
|
|
|
|
virtual void LayerManagerDestroyed() {}
|
2010-10-08 09:02:53 -07:00
|
|
|
|
|
|
|
void ReportFailure(const nsACString &aMsg, HRESULT aCode) {
|
|
|
|
return mD3DManager->ReportFailure(aMsg, aCode);
|
|
|
|
}
|
2010-11-08 01:06:15 -08:00
|
|
|
|
|
|
|
void SetShaderTransformAndOpacity()
|
|
|
|
{
|
|
|
|
Layer* layer = GetLayer();
|
2014-01-24 17:49:19 -08:00
|
|
|
const gfx::Matrix4x4& transform = layer->GetEffectiveTransform();
|
2010-11-08 01:06:15 -08:00
|
|
|
device()->SetVertexShaderConstantF(CBmLayerTransform, &transform._11, 4);
|
|
|
|
|
|
|
|
float opacity[4];
|
|
|
|
/*
|
|
|
|
* We always upload a 4 component float, but the shader will use only the
|
|
|
|
* first component since it's declared as a 'float'.
|
|
|
|
*/
|
|
|
|
opacity[0] = layer->GetEffectiveOpacity();
|
|
|
|
device()->SetPixelShaderConstantF(CBfLayerOpacity, opacity, 1);
|
|
|
|
}
|
|
|
|
|
2012-03-06 13:07:48 -08:00
|
|
|
/*
|
|
|
|
* Returns a texture containing the contents of this
|
|
|
|
* layer. Will try to return an existing texture if possible, or a temporary
|
|
|
|
* one if not. It is the callee's responsibility to release the shader
|
|
|
|
* resource view. Will return null if a texture could not be constructed.
|
|
|
|
* The texture will not be transformed, i.e., it will be in the same coord
|
|
|
|
* space as this.
|
|
|
|
* Any layer that can be used as a mask layer should override this method.
|
|
|
|
* If aSize is non-null and a texture is successfully returned, aSize will
|
|
|
|
* contain the size of the texture.
|
|
|
|
*/
|
2013-12-20 08:46:29 -08:00
|
|
|
virtual already_AddRefed<IDirect3DTexture9> GetAsTexture(gfx::IntSize* aSize)
|
2012-03-06 13:07:48 -08:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-03-06 13:07:48 -08:00
|
|
|
}
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
protected:
|
|
|
|
LayerManagerD3D9 *mD3DManager;
|
|
|
|
};
|
|
|
|
|
2011-07-04 06:15:05 -07:00
|
|
|
/*
|
|
|
|
* RAII helper for locking D3D9 textures.
|
|
|
|
*/
|
|
|
|
class LockTextureRectD3D9
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LockTextureRectD3D9(IDirect3DTexture9* aTexture)
|
|
|
|
: mTexture(aTexture)
|
|
|
|
{
|
2013-07-20 01:48:55 -07:00
|
|
|
mLockResult = mTexture->LockRect(0, &mR, nullptr, 0);
|
2011-07-04 06:15:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
~LockTextureRectD3D9()
|
|
|
|
{
|
|
|
|
mTexture->UnlockRect(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasLock() {
|
|
|
|
return SUCCEEDED(mLockResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DLOCKED_RECT GetLockRect()
|
|
|
|
{
|
|
|
|
return mR;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
LockTextureRectD3D9 (const LockTextureRectD3D9&);
|
|
|
|
LockTextureRectD3D9& operator= (const LockTextureRectD3D9&);
|
|
|
|
|
|
|
|
IDirect3DTexture9* mTexture;
|
|
|
|
D3DLOCKED_RECT mR;
|
|
|
|
HRESULT mLockResult;
|
|
|
|
};
|
|
|
|
|
2010-05-24 08:28:51 -07:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
|
|
|
|
#endif /* GFX_LAYERMANAGERD3D9_H */
|