2011-08-09 19:38:26 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00: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-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
#ifndef GFX_LAYERMANAGERD3D10_H
|
|
|
|
#define GFX_LAYERMANAGERD3D10_H
|
|
|
|
|
|
|
|
#include "Layers.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <d3d10_1.h>
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2014-04-10 08:49:49 +00:00
|
|
|
#include "mozilla/gfx/UserData.h"
|
2010-09-30 22:53:49 +00:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
|
2011-02-05 02:30:00 +00:00
|
|
|
#include "ReadbackManagerD3D10.h"
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2011-08-09 19:38:26 +00:00
|
|
|
class DummyRoot;
|
2011-01-12 04:51:27 +00:00
|
|
|
class Nv3DVUtils;
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
/**
|
|
|
|
* This structure is used to pass rectangles to our shader constant. We can use
|
|
|
|
* this for passing rectangular areas to SetVertexShaderConstant. In the format
|
|
|
|
* of a 4 component float(x,y,width,height). Our vertex shader can then use
|
|
|
|
* this to construct rectangular positions from the 0,0-1,1 quad that we source
|
|
|
|
* it with.
|
|
|
|
*/
|
|
|
|
struct ShaderConstantRectD3D10
|
|
|
|
{
|
|
|
|
float mX, mY, mWidth, mHeight;
|
|
|
|
ShaderConstantRectD3D10(float aX, float aY, float aWidth, float aHeight)
|
|
|
|
: mX(aX), mY(aY), mWidth(aWidth), mHeight(aHeight)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// For easy passing to SetVertexShaderConstantF.
|
|
|
|
operator float* () { return &mX; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2011-08-09 19:38:26 +00:00
|
|
|
* This is the LayerManager used for Direct3D 10. For now this will
|
|
|
|
* render on the main thread.
|
|
|
|
*
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 09:20:52 +00:00
|
|
|
* For the time being, LayerManagerD3D10 forwards layers
|
|
|
|
* transactions.
|
2010-09-30 22:53:49 +00:00
|
|
|
*/
|
2013-05-29 21:59:24 +00:00
|
|
|
class LayerManagerD3D10 : public LayerManager {
|
2014-04-10 08:49:49 +00:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
typedef mozilla::gfx::IntSize IntSize;
|
|
|
|
typedef mozilla::gfx::SurfaceFormat SurfaceFormat;
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
public:
|
|
|
|
LayerManagerD3D10(nsIWidget *aWidget);
|
|
|
|
virtual ~LayerManagerD3D10();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
2013-04-10 14:02:44 +00:00
|
|
|
* return True is initialization was succesful, false when it was not.
|
2010-09-30 22:53:49 +00:00
|
|
|
*/
|
2013-04-10 14:02:44 +00:00
|
|
|
bool Initialize(bool force = false, HRESULT* aHresultPtr = nullptr);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LayerManager implementation.
|
|
|
|
*/
|
2010-10-19 19:08:31 +00:00
|
|
|
virtual void Destroy();
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
virtual void SetRoot(Layer *aLayer);
|
|
|
|
|
2011-01-19 08:27:54 +00:00
|
|
|
virtual void BeginTransaction();
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-19 08:27:54 +00:00
|
|
|
virtual void BeginTransactionWithTarget(gfxContext* aTarget);
|
|
|
|
|
2012-08-13 10:10:10 +00:00
|
|
|
virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
struct CallbackInfo {
|
|
|
|
DrawThebesLayerCallback Callback;
|
|
|
|
void *CallbackData;
|
|
|
|
};
|
|
|
|
|
2011-01-19 08:27:54 +00:00
|
|
|
virtual void EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 13:20:42 +00:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags = END_DEFAULT);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
const CallbackInfo &GetCallbackInfo() { return mCurrentCallbackInfo; }
|
|
|
|
|
2011-07-08 10:42:21 +00:00
|
|
|
// D3D10 guarantees textures can be at least this size
|
|
|
|
enum {
|
|
|
|
MAX_TEXTURE_SIZE = 8192
|
|
|
|
};
|
2013-12-20 16:46:29 +00:00
|
|
|
virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize)
|
2011-07-08 10:42:21 +00:00
|
|
|
{
|
2013-12-20 16:46:29 +00:00
|
|
|
return aSize <= gfx::IntSize(MAX_TEXTURE_SIZE, MAX_TEXTURE_SIZE);
|
2011-07-08 10:42:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
virtual int32_t GetMaxTextureSize() const
|
2012-05-22 23:15:16 +00:00
|
|
|
{
|
|
|
|
return MAX_TEXTURE_SIZE;
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:53:49 +00: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-05 02:30:00 +00:00
|
|
|
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer();
|
|
|
|
|
2014-04-10 08:49:49 +00:00
|
|
|
virtual TemporaryRef<DrawTarget>
|
|
|
|
CreateOptimalDrawTarget(const IntSize &aSize,
|
|
|
|
SurfaceFormat aSurfaceFormat);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2014-04-10 08:49:49 +00:00
|
|
|
virtual TemporaryRef<DrawTarget>
|
|
|
|
CreateOptimalMaskDrawTarget(const IntSize &aSize);
|
2012-06-26 02:43:31 +00:00
|
|
|
|
2011-06-24 17:41:18 +00:00
|
|
|
virtual TemporaryRef<mozilla::gfx::DrawTarget>
|
2013-12-20 16:46:29 +00:00
|
|
|
CreateDrawTarget(const gfx::IntSize &aSize,
|
2011-06-24 17:41:18 +00:00
|
|
|
mozilla::gfx::SurfaceFormat aFormat);
|
|
|
|
|
2014-01-23 18:26:41 +00:00
|
|
|
virtual LayersBackend GetBackendType() { return LayersBackend::LAYERS_D3D10; }
|
2010-09-30 22:53:49 +00:00
|
|
|
virtual void GetBackendName(nsAString& name) { name.AssignLiteral("Direct3D 10"); }
|
|
|
|
|
2011-01-20 02:47:47 +00:00
|
|
|
virtual const char* Name() const { return "D3D10"; }
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
// Public helpers
|
|
|
|
|
|
|
|
ID3D10Device1 *device() const { return mDevice; }
|
|
|
|
|
|
|
|
ID3D10Effect *effect() const { return mEffect; }
|
2012-07-18 01:53:28 +00:00
|
|
|
IDXGISwapChain *SwapChain() const
|
|
|
|
{
|
|
|
|
return mSwapChain;
|
|
|
|
}
|
2011-02-05 02:30:00 +00:00
|
|
|
ReadbackManagerD3D10 *readbackManager();
|
|
|
|
|
2012-04-11 16:17:40 +00:00
|
|
|
void SetupInputAssembler();
|
2010-09-30 22:53:49 +00:00
|
|
|
void SetViewport(const nsIntSize &aViewport);
|
|
|
|
const nsIntSize &GetViewport() { return mViewport; }
|
|
|
|
|
2011-01-12 04:51:27 +00:00
|
|
|
/**
|
|
|
|
* Return pointer to the Nv3DVUtils instance
|
|
|
|
*/
|
|
|
|
Nv3DVUtils *GetNv3DVUtils() { return mNv3DVUtils; }
|
|
|
|
|
2011-07-13 15:58:17 +00:00
|
|
|
static void ReportFailure(const nsACString &aMsg, HRESULT aCode);
|
2011-01-12 00:52:25 +00:00
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
private:
|
|
|
|
void SetupPipeline();
|
|
|
|
void UpdateRenderTarget();
|
|
|
|
void VerifyBufferSize();
|
2011-02-05 02:30:00 +00:00
|
|
|
void EnsureReadbackManager();
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2012-08-13 10:10:10 +00:00
|
|
|
void Render(EndTransactionFlags aFlags);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
nsRefPtr<ID3D10Device1> mDevice;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Effect> mEffect;
|
|
|
|
nsRefPtr<ID3D10InputLayout> mInputLayout;
|
|
|
|
nsRefPtr<ID3D10Buffer> mVertexBuffer;
|
2011-02-05 02:30:00 +00:00
|
|
|
nsRefPtr<ReadbackManagerD3D10> mReadbackManager;
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
nsRefPtr<ID3D10RenderTargetView> mRTView;
|
|
|
|
|
|
|
|
nsRefPtr<IDXGISwapChain> mSwapChain;
|
|
|
|
|
|
|
|
nsIWidget *mWidget;
|
|
|
|
|
2013-09-15 22:30:11 +00:00
|
|
|
bool mDisableSequenceForNextFrame;
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
CallbackInfo mCurrentCallbackInfo;
|
|
|
|
|
|
|
|
nsIntSize mViewport;
|
|
|
|
|
2011-01-12 04:51:27 +00:00
|
|
|
/* Nv3DVUtils instance */
|
|
|
|
nsAutoPtr<Nv3DVUtils> mNv3DVUtils;
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
/*
|
2013-07-20 08:48:55 +00:00
|
|
|
* Context target, nullptr when drawing directly to our swap chain.
|
2010-09-30 22:53:49 +00:00
|
|
|
*/
|
|
|
|
nsRefPtr<gfxContext> mTarget;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies the content of our backbuffer to the set transaction target.
|
|
|
|
*/
|
|
|
|
void PaintToTarget();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* General information and tree management for OGL layers.
|
|
|
|
*/
|
|
|
|
class LayerD3D10
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
LayerD3D10(LayerManagerD3D10 *aManager);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
virtual LayerD3D10 *GetFirstChildD3D10() { return nullptr; }
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
void SetFirstChild(LayerD3D10 *aParent);
|
|
|
|
|
|
|
|
virtual Layer* GetLayer() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This will render a child layer to whatever render target is currently
|
2010-11-08 09:06:15 +00:00
|
|
|
* active.
|
2010-09-30 22:53:49 +00:00
|
|
|
*/
|
2010-11-08 09:06:15 +00:00
|
|
|
virtual void RenderLayer() = 0;
|
2010-09-30 22:53:49 +00:00
|
|
|
virtual void Validate() {}
|
|
|
|
|
|
|
|
ID3D10Device1 *device() const { return mD3DManager->device(); }
|
|
|
|
ID3D10Effect *effect() const { return mD3DManager->effect(); }
|
|
|
|
|
|
|
|
/* Called by the layer manager when it's destroyed */
|
|
|
|
virtual void LayerManagerDestroyed() {}
|
2010-11-08 09:06:15 +00:00
|
|
|
|
2011-01-12 04:51:27 +00:00
|
|
|
/**
|
|
|
|
* Return pointer to the Nv3DVUtils instance. Calls equivalent method in LayerManager.
|
|
|
|
*/
|
|
|
|
Nv3DVUtils *GetNv3DVUtils() { return mD3DManager->GetNv3DVUtils(); }
|
|
|
|
|
2012-02-15 23:34:23 +00:00
|
|
|
/*
|
|
|
|
* Returns a shader resource view of 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, it will contain the size of the texture.
|
|
|
|
*/
|
2013-12-20 16:46:29 +00:00
|
|
|
virtual already_AddRefed<ID3D10ShaderResourceView> GetAsTexture(gfx::IntSize* aSize)
|
2012-02-15 23:34:23 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-02-15 23:34:23 +00:00
|
|
|
}
|
2011-01-12 04:51:27 +00:00
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
void SetEffectTransformAndOpacity()
|
|
|
|
{
|
|
|
|
Layer* layer = GetLayer();
|
2014-01-25 01:49:19 +00:00
|
|
|
const gfx::Matrix4x4& transform = layer->GetEffectiveTransform();
|
|
|
|
void* raw = &const_cast<gfx::Matrix4x4&>(transform)._11;
|
2010-11-08 09:06:15 +00:00
|
|
|
effect()->GetVariableByName("mLayerTransform")->SetRawValue(raw, 0, 64);
|
|
|
|
effect()->GetVariableByName("fLayerOpacity")->AsScalar()->SetFloat(layer->GetEffectiveOpacity());
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
protected:
|
2012-02-15 23:34:23 +00:00
|
|
|
/*
|
|
|
|
* Finds a texture for this layer's mask layer (if it has one) and sets it
|
|
|
|
* as an input to the shaders.
|
2012-03-01 17:29:30 +00:00
|
|
|
* Returns SHADER_MASK if a texture is loaded, SHADER_NO_MASK if there was no
|
|
|
|
* mask layer, or a texture for the mask layer could not be loaded.
|
2012-02-15 23:34:23 +00:00
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t LoadMaskTexture();
|
2012-03-01 17:29:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Select a shader technique using a combination of the following flags.
|
|
|
|
* Not all combinations of flags are supported, and might cause an error,
|
|
|
|
* check the fx file to see which shaders exist. In particular, aFlags should
|
|
|
|
* include any combination of the 0x20 bit = 0 flags OR one of the 0x20 bit = 1
|
|
|
|
* flags. Mask flags can be used in either case.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
ID3D10EffectTechnique* SelectShader(uint8_t aFlags);
|
|
|
|
const static uint8_t SHADER_NO_MASK = 0;
|
|
|
|
const static uint8_t SHADER_MASK = 0x1;
|
|
|
|
const static uint8_t SHADER_MASK_3D = 0x2;
|
2012-03-01 17:29:30 +00:00
|
|
|
// 0x20 bit = 0
|
2012-08-22 15:56:38 +00:00
|
|
|
const static uint8_t SHADER_RGB = 0;
|
|
|
|
const static uint8_t SHADER_RGBA = 0x4;
|
|
|
|
const static uint8_t SHADER_NON_PREMUL = 0;
|
|
|
|
const static uint8_t SHADER_PREMUL = 0x8;
|
|
|
|
const static uint8_t SHADER_LINEAR = 0;
|
|
|
|
const static uint8_t SHADER_POINT = 0x10;
|
2012-03-01 17:29:30 +00:00
|
|
|
// 0x20 bit = 1
|
2012-08-22 15:56:38 +00:00
|
|
|
const static uint8_t SHADER_YCBCR = 0x20;
|
|
|
|
const static uint8_t SHADER_COMPONENT_ALPHA = 0x24;
|
|
|
|
const static uint8_t SHADER_SOLID = 0x28;
|
2012-02-15 23:34:23 +00:00
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
LayerManagerD3D10 *mD3DManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
|
|
|
|
#endif /* GFX_LAYERMANAGERD3D9_H */
|