2011-08-09 23:38:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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-10-01 02:53:49 +04:00
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
#include <algorithm>
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
#include "LayerManagerD3D10.h"
|
|
|
|
#include "LayerManagerD3D10Effect.h"
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#include "gfxD2DSurface.h"
|
2011-02-09 22:28:39 +03:00
|
|
|
#include "gfxFailure.h"
|
2010-10-01 02:53:49 +04:00
|
|
|
#include "cairo-win32.h"
|
|
|
|
#include "dxgi.h"
|
|
|
|
|
|
|
|
#include "ContainerLayerD3D10.h"
|
|
|
|
#include "ThebesLayerD3D10.h"
|
|
|
|
#include "ColorLayerD3D10.h"
|
|
|
|
#include "CanvasLayerD3D10.h"
|
2011-02-05 05:30:00 +03:00
|
|
|
#include "ReadbackLayerD3D10.h"
|
2010-10-01 02:53:49 +04:00
|
|
|
#include "ImageLayerD3D10.h"
|
2011-08-09 23:38:26 +04:00
|
|
|
#include "mozilla/layers/PLayerChild.h"
|
2012-07-24 23:01:09 +04:00
|
|
|
#include "mozilla/WidgetUtils.h"
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2011-01-12 07:51:27 +03:00
|
|
|
#include "../d3d9/Nv3DVUtils.h"
|
|
|
|
|
2011-03-02 23:50:36 +03:00
|
|
|
#include "gfxCrashReporterUtils.h"
|
2013-09-18 03:21:30 +04:00
|
|
|
#include "nsWindowsHelpers.h"
|
2012-10-15 10:19:13 +04:00
|
|
|
#ifdef MOZ_METRO
|
|
|
|
#include "DXGI1_2.h"
|
|
|
|
#endif
|
2011-03-02 23:50:36 +03:00
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
using namespace std;
|
2012-11-22 06:40:57 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-06-24 21:41:18 +04:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
typedef HRESULT (WINAPI*D3D10CreateEffectFromMemoryFunc)(
|
|
|
|
void *pData,
|
|
|
|
SIZE_T DataLength,
|
|
|
|
UINT FXFlags,
|
|
|
|
ID3D10Device *pDevice,
|
|
|
|
ID3D10EffectPool *pEffectPool,
|
|
|
|
ID3D10Effect **ppEffect
|
|
|
|
);
|
|
|
|
|
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
float position[2];
|
|
|
|
};
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
// {592BF306-0EED-4F76-9D03-A0846450F472}
|
|
|
|
static const GUID sDeviceAttachments =
|
|
|
|
{ 0x592bf306, 0xeed, 0x4f76, { 0x9d, 0x3, 0xa0, 0x84, 0x64, 0x50, 0xf4, 0x72 } };
|
|
|
|
// {716AEDB1-C9C3-4B4D-8332-6F65D44AF6A8}
|
|
|
|
static const GUID sLayerManagerCount =
|
|
|
|
{ 0x716aedb1, 0xc9c3, 0x4b4d, { 0x83, 0x32, 0x6f, 0x65, 0xd4, 0x4a, 0xf6, 0xa8 } };
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
cairo_user_data_key_t gKeyD3D10Texture;
|
|
|
|
|
|
|
|
LayerManagerD3D10::LayerManagerD3D10(nsIWidget *aWidget)
|
|
|
|
: mWidget(aWidget)
|
2013-09-16 02:30:11 +04:00
|
|
|
, mDisableSequenceForNextFrame(false)
|
2010-10-01 02:53:49 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
struct DeviceAttachments
|
|
|
|
{
|
|
|
|
nsRefPtr<ID3D10Effect> mEffect;
|
|
|
|
nsRefPtr<ID3D10InputLayout> mInputLayout;
|
|
|
|
nsRefPtr<ID3D10Buffer> mVertexBuffer;
|
|
|
|
nsRefPtr<ReadbackManagerD3D10> mReadbackManager;
|
|
|
|
};
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
LayerManagerD3D10::~LayerManagerD3D10()
|
|
|
|
{
|
2011-02-05 05:30:00 +03:00
|
|
|
if (mDevice) {
|
|
|
|
int referenceCount = 0;
|
|
|
|
UINT size = sizeof(referenceCount);
|
|
|
|
HRESULT hr = mDevice->GetPrivateData(sLayerManagerCount, &size, &referenceCount);
|
|
|
|
NS_ASSERTION(SUCCEEDED(hr), "Reference count not found on device.");
|
|
|
|
referenceCount--;
|
|
|
|
mDevice->SetPrivateData(sLayerManagerCount, sizeof(referenceCount), &referenceCount);
|
|
|
|
|
|
|
|
if (!referenceCount) {
|
|
|
|
DeviceAttachments *attachments;
|
|
|
|
size = sizeof(attachments);
|
|
|
|
mDevice->GetPrivateData(sDeviceAttachments, &size, &attachments);
|
|
|
|
// No LayerManagers left for this device. Clear out interfaces stored which
|
|
|
|
// hold a reference to the device.
|
2013-07-20 12:48:55 +04:00
|
|
|
mDevice->SetPrivateData(sDeviceAttachments, 0, nullptr);
|
2011-02-05 05:30:00 +03:00
|
|
|
|
|
|
|
delete attachments;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 23:08:31 +04:00
|
|
|
Destroy();
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
2013-05-07 06:04:02 +04:00
|
|
|
static inline void
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(HRESULT* aHresultPtr, HRESULT aHresult)
|
|
|
|
{
|
|
|
|
if (aHresultPtr) {
|
|
|
|
*aHresultPtr = aHresult;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
bool
|
2013-04-10 18:02:44 +04:00
|
|
|
LayerManagerD3D10::Initialize(bool force, HRESULT* aHresultPtr)
|
2010-10-01 02:53:49 +04:00
|
|
|
{
|
2012-02-28 01:33:19 +04:00
|
|
|
ScopedGfxFeatureReporter reporter("D3D10 Layers", force);
|
2011-03-02 23:50:36 +03:00
|
|
|
|
2013-04-10 18:02:44 +04:00
|
|
|
HRESULT hr = E_UNEXPECTED;
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2011-01-12 07:51:27 +03:00
|
|
|
/* Create an Nv3DVUtils instance */
|
|
|
|
if (!mNv3DVUtils) {
|
|
|
|
mNv3DVUtils = new Nv3DVUtils();
|
|
|
|
if (!mNv3DVUtils) {
|
|
|
|
NS_WARNING("Could not create a new instance of Nv3DVUtils.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Nv3DVUtils object */
|
|
|
|
if (mNv3DVUtils) {
|
|
|
|
mNv3DVUtils->Initialize();
|
|
|
|
}
|
|
|
|
|
2011-01-07 01:07:12 +03:00
|
|
|
mDevice = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
|
|
|
|
if (!mDevice) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, hr);
|
2011-01-07 01:07:12 +03:00
|
|
|
return false;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-12 07:51:27 +03:00
|
|
|
/*
|
|
|
|
* Do some post device creation setup
|
|
|
|
*/
|
|
|
|
if (mNv3DVUtils) {
|
2013-07-20 12:48:55 +04:00
|
|
|
IUnknown* devUnknown = nullptr;
|
2011-01-12 07:51:27 +03:00
|
|
|
if (mDevice) {
|
|
|
|
mDevice->QueryInterface(IID_IUnknown, (void **)&devUnknown);
|
|
|
|
}
|
|
|
|
mNv3DVUtils->SetDeviceInfo(devUnknown);
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
int referenceCount = 0;
|
|
|
|
UINT size = sizeof(referenceCount);
|
|
|
|
// If this isn't there yet it'll fail, count will remain 0, which is correct.
|
|
|
|
mDevice->GetPrivateData(sLayerManagerCount, &size, &referenceCount);
|
|
|
|
referenceCount++;
|
|
|
|
mDevice->SetPrivateData(sLayerManagerCount, sizeof(referenceCount), &referenceCount);
|
|
|
|
|
|
|
|
DeviceAttachments *attachments;
|
|
|
|
size = sizeof(DeviceAttachments*);
|
|
|
|
if (FAILED(mDevice->GetPrivateData(sDeviceAttachments, &size, &attachments))) {
|
|
|
|
attachments = new DeviceAttachments;
|
|
|
|
mDevice->SetPrivateData(sDeviceAttachments, sizeof(attachments), &attachments);
|
|
|
|
|
2013-04-10 18:02:44 +04:00
|
|
|
SetLastError(0);
|
2010-10-01 02:53:49 +04:00
|
|
|
D3D10CreateEffectFromMemoryFunc createEffect = (D3D10CreateEffectFromMemoryFunc)
|
2013-04-10 18:02:44 +04:00
|
|
|
GetProcAddress(LoadLibraryA("d3d10_1.dll"), "D3D10CreateEffectFromMemory");
|
2010-10-01 02:53:49 +04:00
|
|
|
if (!createEffect) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, HRESULT_FROM_WIN32(GetLastError()));
|
2010-10-01 02:53:49 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = createEffect((void*)g_main,
|
|
|
|
sizeof(g_main),
|
|
|
|
D3D10_EFFECT_SINGLE_THREADED,
|
|
|
|
mDevice,
|
2013-07-20 12:48:55 +04:00
|
|
|
nullptr,
|
2010-10-01 02:53:49 +04:00
|
|
|
getter_AddRefs(mEffect));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, hr);
|
2010-10-01 02:53:49 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
attachments->mEffect = mEffect;
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
D3D10_INPUT_ELEMENT_DESC layout[] =
|
|
|
|
{
|
|
|
|
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
|
|
|
|
};
|
|
|
|
D3D10_PASS_DESC passDesc;
|
|
|
|
mEffect->GetTechniqueByName("RenderRGBLayerPremul")->GetPassByIndex(0)->
|
|
|
|
GetDesc(&passDesc);
|
|
|
|
|
|
|
|
hr = mDevice->CreateInputLayout(layout,
|
|
|
|
sizeof(layout) / sizeof(D3D10_INPUT_ELEMENT_DESC),
|
|
|
|
passDesc.pIAInputSignature,
|
|
|
|
passDesc.IAInputSignatureSize,
|
|
|
|
getter_AddRefs(mInputLayout));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, hr);
|
2010-10-01 02:53:49 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
attachments->mInputLayout = mInputLayout;
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
Vertex vertices[] = { {0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}, {1.0, 1.0} };
|
|
|
|
CD3D10_BUFFER_DESC bufferDesc(sizeof(vertices), D3D10_BIND_VERTEX_BUFFER);
|
|
|
|
D3D10_SUBRESOURCE_DATA data;
|
|
|
|
data.pSysMem = (void*)vertices;
|
|
|
|
|
|
|
|
hr = mDevice->CreateBuffer(&bufferDesc, &data, getter_AddRefs(mVertexBuffer));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, hr);
|
2010-10-01 02:53:49 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
attachments->mVertexBuffer = mVertexBuffer;
|
|
|
|
} else {
|
|
|
|
mEffect = attachments->mEffect;
|
|
|
|
mVertexBuffer = attachments->mVertexBuffer;
|
|
|
|
mInputLayout = attachments->mInputLayout;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDXGIDevice> dxgiDevice;
|
|
|
|
nsRefPtr<IDXGIAdapter> dxgiAdapter;
|
|
|
|
|
|
|
|
mDevice->QueryInterface(dxgiDevice.StartAssignment());
|
|
|
|
dxgiDevice->GetAdapter(getter_AddRefs(dxgiAdapter));
|
2012-07-18 05:53:28 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_METRO
|
2013-03-01 01:10:17 +04:00
|
|
|
if (IsRunningInWindowsMetro()) {
|
2012-07-18 05:53:28 +04:00
|
|
|
nsRefPtr<IDXGIFactory2> dxgiFactory;
|
|
|
|
dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.StartAssignment()));
|
|
|
|
|
|
|
|
nsIntRect rect;
|
|
|
|
mWidget->GetClientBounds(rect);
|
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 swapDesc = { 0 };
|
|
|
|
// Automatically detect the width and the height from the winrt CoreWindow
|
|
|
|
swapDesc.Width = rect.width;
|
|
|
|
swapDesc.Height = rect.height;
|
|
|
|
// This is the most common swapchain format
|
|
|
|
swapDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
swapDesc.Stereo = false;
|
|
|
|
// Don't use multi-sampling
|
|
|
|
swapDesc.SampleDesc.Count = 1;
|
|
|
|
swapDesc.SampleDesc.Quality = 0;
|
|
|
|
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
// Use double buffering to enable flip
|
|
|
|
swapDesc.BufferCount = 2;
|
2013-09-16 02:30:11 +04:00
|
|
|
swapDesc.Scaling = DXGI_SCALING_NONE;
|
2012-07-18 05:53:28 +04:00
|
|
|
// All Metro style apps must use this SwapEffect
|
|
|
|
swapDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
2011-01-08 08:39:15 +03:00
|
|
|
swapDesc.Flags = 0;
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2012-07-18 05:53:28 +04:00
|
|
|
/**
|
|
|
|
* Create a swap chain, this swap chain will contain the backbuffer for
|
|
|
|
* the window we draw to. The front buffer is the full screen front
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
nsRefPtr<IDXGISwapChain1> swapChain1;
|
|
|
|
hr = dxgiFactory->CreateSwapChainForCoreWindow(
|
2012-09-07 23:51:02 +04:00
|
|
|
dxgiDevice, (IUnknown *)mWidget->GetNativeData(NS_NATIVE_ICOREWINDOW),
|
2012-07-18 05:53:28 +04:00
|
|
|
&swapDesc, nullptr, getter_AddRefs(swapChain1));
|
|
|
|
if (FAILED(hr)) {
|
2013-04-10 18:02:44 +04:00
|
|
|
SetHRESULT(aHresultPtr, hr);
|
|
|
|
return false;
|
2012-07-18 05:53:28 +04:00
|
|
|
}
|
|
|
|
mSwapChain = swapChain1;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
nsRefPtr<IDXGIFactory> dxgiFactory;
|
|
|
|
dxgiAdapter->GetParent(IID_PPV_ARGS(dxgiFactory.StartAssignment()));
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2012-07-18 05:53:28 +04:00
|
|
|
DXGI_SWAP_CHAIN_DESC swapDesc;
|
|
|
|
::ZeroMemory(&swapDesc, sizeof(swapDesc));
|
|
|
|
swapDesc.BufferDesc.Width = 0;
|
|
|
|
swapDesc.BufferDesc.Height = 0;
|
|
|
|
swapDesc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
swapDesc.BufferDesc.RefreshRate.Numerator = 60;
|
|
|
|
swapDesc.BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
swapDesc.SampleDesc.Count = 1;
|
|
|
|
swapDesc.SampleDesc.Quality = 0;
|
|
|
|
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
swapDesc.BufferCount = 1;
|
|
|
|
swapDesc.OutputWindow = (HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW);
|
|
|
|
swapDesc.Windowed = TRUE;
|
|
|
|
// We don't really need this flag, however it seems on some NVidia hardware
|
|
|
|
// smaller area windows do not present properly without this flag. This flag
|
|
|
|
// should have no negative consequences by itself. See bug 613790. This flag
|
|
|
|
// is broken on optimus devices. As a temporary solution we don't set it
|
|
|
|
// there, the only way of reliably detecting we're on optimus is looking for
|
|
|
|
// the DLL. See Bug 623807.
|
|
|
|
if (gfxWindowsPlatform::IsOptimus()) {
|
|
|
|
swapDesc.Flags = 0;
|
|
|
|
} else {
|
|
|
|
swapDesc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
|
|
|
|
}
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2012-07-18 05:53:28 +04:00
|
|
|
/**
|
|
|
|
* Create a swap chain, this swap chain will contain the backbuffer for
|
|
|
|
* the window we draw to. The front buffer is the full screen front
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
hr = dxgiFactory->CreateSwapChain(dxgiDevice, &swapDesc, getter_AddRefs(mSwapChain));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need this because we don't want DXGI to respond to Alt+Enter.
|
|
|
|
dxgiFactory->MakeWindowAssociation(swapDesc.OutputWindow, DXGI_MWA_NO_WINDOW_CHANGES);
|
|
|
|
}
|
2010-10-08 20:02:39 +04:00
|
|
|
|
2011-03-02 23:50:36 +03:00
|
|
|
reporter.SetSuccessful();
|
2010-10-01 02:53:49 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-19 23:08:31 +04:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::Destroy()
|
|
|
|
{
|
|
|
|
if (!IsDestroyed()) {
|
|
|
|
if (mRoot) {
|
|
|
|
static_cast<LayerD3D10*>(mRoot->ImplData())->LayerManagerDestroyed();
|
|
|
|
}
|
2011-08-09 23:38:26 +04:00
|
|
|
// XXX need to be careful here about surface destruction
|
|
|
|
// racing with share-to-chrome message
|
2010-10-19 23:08:31 +04:00
|
|
|
}
|
|
|
|
LayerManager::Destroy();
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::SetRoot(Layer *aRoot)
|
|
|
|
{
|
|
|
|
mRoot = aRoot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManagerD3D10::BeginTransaction()
|
|
|
|
{
|
2012-08-16 01:55:38 +04:00
|
|
|
mInTransaction = true;
|
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
MOZ_LAYERS_LOG(("[----- BeginTransaction"));
|
|
|
|
Log();
|
|
|
|
#endif
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManagerD3D10::BeginTransactionWithTarget(gfxContext* aTarget)
|
|
|
|
{
|
2012-08-16 01:55:38 +04:00
|
|
|
mInTransaction = true;
|
2010-10-01 02:53:49 +04:00
|
|
|
mTarget = aTarget;
|
|
|
|
}
|
|
|
|
|
2011-01-19 11:27:54 +03:00
|
|
|
bool
|
2012-08-13 14:10:10 +04:00
|
|
|
LayerManagerD3D10::EndEmptyTransaction(EndTransactionFlags aFlags)
|
2011-01-19 11:27:54 +03:00
|
|
|
{
|
2012-08-16 01:55:38 +04:00
|
|
|
mInTransaction = false;
|
|
|
|
|
2011-01-19 11:27:54 +03:00
|
|
|
if (!mRoot)
|
|
|
|
return false;
|
|
|
|
|
2012-08-13 14:10:10 +04:00
|
|
|
EndTransaction(nullptr, nullptr, aFlags);
|
2011-01-19 11:27:54 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-14 03:14:07 +03:00
|
|
|
void
|
2010-10-01 02:53:49 +04:00
|
|
|
LayerManagerD3D10::EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 17:20:42 +04:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags)
|
2010-10-01 02:53:49 +04:00
|
|
|
{
|
2012-08-16 01:55:38 +04:00
|
|
|
mInTransaction = false;
|
|
|
|
|
2011-09-26 17:20:42 +04:00
|
|
|
if (mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) {
|
2011-02-10 11:58:11 +03:00
|
|
|
mCurrentCallbackInfo.Callback = aCallback;
|
|
|
|
mCurrentCallbackInfo.CallbackData = aCallbackData;
|
|
|
|
|
2012-10-03 09:55:50 +04:00
|
|
|
if (aFlags & END_NO_COMPOSITE) {
|
|
|
|
// Apply pending tree updates before recomputing effective
|
|
|
|
// properties.
|
|
|
|
mRoot->ApplyPendingUpdatesToSubtree();
|
|
|
|
}
|
|
|
|
|
2011-02-10 11:58:11 +03:00
|
|
|
// The results of our drawing always go directly into a pixel buffer,
|
|
|
|
// so we don't need to pass any global transform here.
|
|
|
|
mRoot->ComputeEffectiveTransforms(gfx3DMatrix());
|
2010-11-08 12:06:15 +03:00
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
MOZ_LAYERS_LOG((" ----- (beginning paint)"));
|
|
|
|
Log();
|
|
|
|
#endif
|
|
|
|
|
2012-08-13 14:10:10 +04:00
|
|
|
Render(aFlags);
|
2012-07-30 18:20:58 +04:00
|
|
|
mCurrentCallbackInfo.Callback = nullptr;
|
|
|
|
mCurrentCallbackInfo.CallbackData = nullptr;
|
2011-02-10 11:58:11 +03:00
|
|
|
}
|
2010-11-08 12:06:15 +03:00
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
|
|
|
Log();
|
|
|
|
MOZ_LAYERS_LOG(("]----- EndTransaction"));
|
|
|
|
#endif
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mTarget = nullptr;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ThebesLayer>
|
|
|
|
LayerManagerD3D10::CreateThebesLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ThebesLayer> layer = new ThebesLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ContainerLayer>
|
|
|
|
LayerManagerD3D10::CreateContainerLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ContainerLayer> layer = new ContainerLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ImageLayer>
|
|
|
|
LayerManagerD3D10::CreateImageLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ImageLayer> layer = new ImageLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ColorLayer>
|
|
|
|
LayerManagerD3D10::CreateColorLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ColorLayer> layer = new ColorLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<CanvasLayer>
|
|
|
|
LayerManagerD3D10::CreateCanvasLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<CanvasLayer> layer = new CanvasLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
already_AddRefed<ReadbackLayer>
|
|
|
|
LayerManagerD3D10::CreateReadbackLayer()
|
|
|
|
{
|
|
|
|
nsRefPtr<ReadbackLayer> layer = new ReadbackLayerD3D10(this);
|
|
|
|
return layer.forget();
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
static void ReleaseTexture(void *texture)
|
|
|
|
{
|
|
|
|
static_cast<ID3D10Texture2D*>(texture)->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
LayerManagerD3D10::CreateOptimalSurface(const gfxIntSize &aSize,
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormat aFormat)
|
2010-10-01 02:53:49 +04:00
|
|
|
{
|
2013-09-25 00:45:13 +04:00
|
|
|
if ((aFormat != gfxImageFormatRGB24 &&
|
|
|
|
aFormat != gfxImageFormatARGB32)) {
|
2010-10-01 02:53:49 +04:00
|
|
|
return LayerManager::CreateOptimalSurface(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
2012-11-10 23:14:13 +04:00
|
|
|
desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2013-07-20 12:48:55 +04:00
|
|
|
HRESULT hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(texture));
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create new texture for CreateOptimalSurface!");
|
|
|
|
return LayerManager::CreateOptimalSurface(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxD2DSurface> surface =
|
2013-09-25 00:45:13 +04:00
|
|
|
new gfxD2DSurface(texture, aFormat == gfxImageFormatRGB24 ?
|
|
|
|
GFX_CONTENT_COLOR : GFX_CONTENT_COLOR_ALPHA);
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
if (!surface || surface->CairoStatus()) {
|
|
|
|
return LayerManager::CreateOptimalSurface(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->SetData(&gKeyD3D10Texture,
|
|
|
|
texture.forget().get(),
|
|
|
|
ReleaseTexture);
|
|
|
|
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
2012-06-26 06:43:31 +04:00
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
LayerManagerD3D10::CreateOptimalMaskSurface(const gfxIntSize &aSize)
|
|
|
|
{
|
2013-09-25 00:45:13 +04:00
|
|
|
return CreateOptimalSurface(aSize, gfxImageFormatARGB32);
|
2012-06-26 06:43:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-24 21:41:18 +04:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
LayerManagerD3D10::CreateDrawTarget(const IntSize &aSize,
|
|
|
|
SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
if ((aFormat != FORMAT_B8G8R8A8 &&
|
2012-07-25 04:45:58 +04:00
|
|
|
aFormat != FORMAT_B8G8R8X8) ||
|
2012-07-31 10:30:10 +04:00
|
|
|
gfxPlatform::GetPlatform()->GetPreferredCanvasBackend() != BACKEND_DIRECT2D) {
|
2011-06-24 21:41:18 +04:00
|
|
|
return LayerManager::CreateDrawTarget(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> texture;
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, aSize.width, aSize.height, 1, 1);
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
|
2013-07-20 12:48:55 +04:00
|
|
|
HRESULT hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(texture));
|
2011-06-24 21:41:18 +04:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create new texture for CreateOptimalSurface!");
|
|
|
|
return LayerManager::CreateDrawTarget(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<DrawTarget> surface =
|
|
|
|
Factory::CreateDrawTargetForD3D10Texture(texture, aFormat);
|
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
return LayerManager::CreateDrawTarget(aSize, aFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
ReadbackManagerD3D10*
|
|
|
|
LayerManagerD3D10::readbackManager()
|
|
|
|
{
|
|
|
|
EnsureReadbackManager();
|
|
|
|
return mReadbackManager;
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::SetViewport(const nsIntSize &aViewport)
|
|
|
|
{
|
|
|
|
mViewport = aViewport;
|
|
|
|
|
|
|
|
D3D10_VIEWPORT viewport;
|
|
|
|
viewport.MaxDepth = 1.0f;
|
|
|
|
viewport.MinDepth = 0;
|
|
|
|
viewport.Width = aViewport.width;
|
|
|
|
viewport.Height = aViewport.height;
|
|
|
|
viewport.TopLeftX = 0;
|
|
|
|
viewport.TopLeftY = 0;
|
|
|
|
|
|
|
|
mDevice->RSSetViewports(1, &viewport);
|
|
|
|
|
|
|
|
gfx3DMatrix projection;
|
|
|
|
/*
|
|
|
|
* Matrix to transform to viewport space ( <-1.0, 1.0> topleft,
|
|
|
|
* <1.0, -1.0> bottomright)
|
|
|
|
*/
|
|
|
|
projection._11 = 2.0f / aViewport.width;
|
|
|
|
projection._22 = -2.0f / aViewport.height;
|
2011-08-03 07:04:20 +04:00
|
|
|
projection._33 = 0.0f;
|
2010-10-01 02:53:49 +04:00
|
|
|
projection._41 = -1.0f;
|
|
|
|
projection._42 = 1.0f;
|
|
|
|
projection._44 = 1.0f;
|
|
|
|
|
|
|
|
HRESULT hr = mEffect->GetVariableByName("mProjection")->
|
|
|
|
SetRawValue(&projection._11, 0, 64);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to set projection matrix.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 20:17:40 +04:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::SetupInputAssembler()
|
|
|
|
{
|
|
|
|
mDevice->IASetInputLayout(mInputLayout);
|
|
|
|
|
|
|
|
UINT stride = sizeof(Vertex);
|
|
|
|
UINT offset = 0;
|
|
|
|
ID3D10Buffer *buffer = mVertexBuffer;
|
|
|
|
mDevice->IASetVertexBuffers(0, 1, &buffer, &stride, &offset);
|
|
|
|
mDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::SetupPipeline()
|
|
|
|
{
|
|
|
|
VerifyBufferSize();
|
|
|
|
UpdateRenderTarget();
|
|
|
|
|
|
|
|
nsIntRect rect;
|
|
|
|
mWidget->GetClientBounds(rect);
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = mEffect->GetVariableByName("vTextureCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to set Texture Coordinates.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3D10RenderTargetView *view = mRTView;
|
2013-07-20 12:48:55 +04:00
|
|
|
mDevice->OMSetRenderTargets(1, &view, nullptr);
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2012-04-11 20:17:40 +04:00
|
|
|
SetupInputAssembler();
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
SetViewport(nsIntSize(rect.width, rect.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManagerD3D10::UpdateRenderTarget()
|
|
|
|
{
|
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 13:20:52 +04:00
|
|
|
if (mRTView || !mSwapChain) {
|
2010-10-01 02:53:49 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> backBuf;
|
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 13:20:52 +04:00
|
|
|
hr = mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)backBuf.StartAssignment());
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
2013-07-20 12:48:55 +04:00
|
|
|
mDevice->CreateRenderTargetView(backBuf, nullptr, getter_AddRefs(mRTView));
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManagerD3D10::VerifyBufferSize()
|
|
|
|
{
|
|
|
|
nsIntRect rect;
|
|
|
|
mWidget->GetClientBounds(rect);
|
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
if (mSwapChain) {
|
|
|
|
DXGI_SWAP_CHAIN_DESC swapDesc;
|
|
|
|
mSwapChain->GetDesc(&swapDesc);
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2011-08-09 23:38:26 +04:00
|
|
|
if (swapDesc.BufferDesc.Width == rect.width &&
|
|
|
|
swapDesc.BufferDesc.Height == rect.height) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mRTView = nullptr;
|
2013-09-18 03:21:30 +04:00
|
|
|
if (IsRunningInWindowsMetro()) {
|
2012-07-05 04:36:37 +04:00
|
|
|
mSwapChain->ResizeBuffers(2, rect.width, rect.height,
|
|
|
|
DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
0);
|
2013-09-16 02:30:11 +04:00
|
|
|
mDisableSequenceForNextFrame = true;
|
2013-09-18 03:21:30 +04:00
|
|
|
} else if (gfxWindowsPlatform::IsOptimus()) {
|
|
|
|
mSwapChain->ResizeBuffers(1, rect.width, rect.height,
|
|
|
|
DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
0);
|
2011-08-09 23:38:26 +04:00
|
|
|
} else {
|
|
|
|
mSwapChain->ResizeBuffers(1, rect.width, rect.height,
|
|
|
|
DXGI_FORMAT_B8G8R8A8_UNORM,
|
|
|
|
DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE);
|
|
|
|
}
|
|
|
|
}
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
2011-02-05 05:30:00 +03:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::EnsureReadbackManager()
|
|
|
|
{
|
|
|
|
if (mReadbackManager) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceAttachments *attachments;
|
|
|
|
UINT size = sizeof(DeviceAttachments*);
|
|
|
|
if (FAILED(mDevice->GetPrivateData(sDeviceAttachments, &size, &attachments))) {
|
|
|
|
// Strange! This shouldn't happen ... return a readback manager for this
|
|
|
|
// layer manager only.
|
|
|
|
mReadbackManager = new ReadbackManagerD3D10();
|
|
|
|
gfx::LogFailure(NS_LITERAL_CSTRING("Couldn't get device attachments for device."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attachments->mReadbackManager) {
|
|
|
|
mReadbackManager = attachments->mReadbackManager;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mReadbackManager = new ReadbackManagerD3D10();
|
|
|
|
attachments->mReadbackManager = mReadbackManager;
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
void
|
2012-08-13 14:10:10 +04:00
|
|
|
LayerManagerD3D10::Render(EndTransactionFlags aFlags)
|
2010-10-01 02:53:49 +04:00
|
|
|
{
|
2011-02-10 11:58:11 +03:00
|
|
|
static_cast<LayerD3D10*>(mRoot->ImplData())->Validate();
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2012-08-13 14:10:10 +04:00
|
|
|
if (aFlags & END_NO_COMPOSITE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
SetupPipeline();
|
|
|
|
|
|
|
|
float black[] = { 0, 0, 0, 0 };
|
|
|
|
device()->ClearRenderTargetView(mRTView, black);
|
|
|
|
|
|
|
|
nsIntRect rect;
|
|
|
|
mWidget->GetClientBounds(rect);
|
|
|
|
|
2011-02-10 11:58:11 +03:00
|
|
|
const nsIntRect *clipRect = mRoot->GetClipRect();
|
|
|
|
D3D10_RECT r;
|
|
|
|
if (clipRect) {
|
|
|
|
r.left = (LONG)clipRect->x;
|
|
|
|
r.top = (LONG)clipRect->y;
|
|
|
|
r.right = (LONG)(clipRect->x + clipRect->width);
|
|
|
|
r.bottom = (LONG)(clipRect->y + clipRect->height);
|
|
|
|
} else {
|
|
|
|
r.left = r.top = 0;
|
|
|
|
r.right = rect.width;
|
|
|
|
r.bottom = rect.height;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
2011-02-10 11:58:11 +03:00
|
|
|
device()->RSSetScissorRects(1, &r);
|
|
|
|
|
|
|
|
static_cast<LayerD3D10*>(mRoot->ImplData())->RenderLayer();
|
2010-10-01 02:53:49 +04:00
|
|
|
|
2013-04-09 21:37:56 +04:00
|
|
|
// See bug 630197 - we have some reasons to believe if an earlier call
|
|
|
|
// returned an error, the upcoming present call may raise an exception.
|
|
|
|
// This will check if any of the calls done recently has returned an error
|
|
|
|
// and bails on composition. On the -next- frame we will then abandon
|
|
|
|
// hardware acceleration from gfxWindowsPlatform::VerifyD2DDevice.
|
|
|
|
// This might not be the 'optimal' solution but it will help us assert
|
|
|
|
// whether our thoughts of the causes of the issues are correct.
|
|
|
|
if (FAILED(mDevice->GetDeviceRemovedReason())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
if (mTarget) {
|
|
|
|
PaintToTarget();
|
|
|
|
} else {
|
2013-09-16 02:30:11 +04:00
|
|
|
mSwapChain->Present(0, mDisableSequenceForNextFrame ? DXGI_PRESENT_DO_NOT_SEQUENCE : 0);
|
|
|
|
mDisableSequenceForNextFrame = false;
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
2013-11-27 11:32:19 +04:00
|
|
|
RecordFrame();
|
|
|
|
PostPresent();
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LayerManagerD3D10::PaintToTarget()
|
|
|
|
{
|
|
|
|
nsRefPtr<ID3D10Texture2D> backBuf;
|
|
|
|
|
|
|
|
mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)backBuf.StartAssignment());
|
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC bbDesc;
|
|
|
|
backBuf->GetDesc(&bbDesc);
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC softDesc(bbDesc.Format, bbDesc.Width, bbDesc.Height);
|
|
|
|
softDesc.MipLevels = 1;
|
|
|
|
softDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
|
|
|
|
softDesc.Usage = D3D10_USAGE_STAGING;
|
|
|
|
softDesc.BindFlags = 0;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> readTexture;
|
|
|
|
|
2013-07-20 12:48:55 +04:00
|
|
|
HRESULT hr = device()->CreateTexture2D(&softDesc, nullptr, getter_AddRefs(readTexture));
|
2011-11-03 23:10:10 +04:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
ReportFailure(NS_LITERAL_CSTRING("LayerManagerD3D10::PaintToTarget(): Failed to create texture"),
|
|
|
|
hr);
|
|
|
|
return;
|
|
|
|
}
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
device()->CopyResource(readTexture, backBuf);
|
|
|
|
|
|
|
|
D3D10_MAPPED_TEXTURE2D map;
|
|
|
|
readTexture->Map(0, D3D10_MAP_READ, 0, &map);
|
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> tmpSurface =
|
|
|
|
new gfxImageSurface((unsigned char*)map.pData,
|
|
|
|
gfxIntSize(bbDesc.Width, bbDesc.Height),
|
|
|
|
map.RowPitch,
|
2013-09-25 00:45:13 +04:00
|
|
|
gfxImageFormatARGB32);
|
2010-10-01 02:53:49 +04:00
|
|
|
|
|
|
|
mTarget->SetSource(tmpSurface);
|
2010-10-19 23:08:27 +04:00
|
|
|
mTarget->SetOperator(gfxContext::OPERATOR_OVER);
|
2010-10-01 02:53:49 +04:00
|
|
|
mTarget->Paint();
|
2010-10-19 23:08:27 +04:00
|
|
|
|
|
|
|
readTexture->Unmap(0);
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
|
2011-01-12 03:52:25 +03:00
|
|
|
void
|
|
|
|
LayerManagerD3D10::ReportFailure(const nsACString &aMsg, HRESULT aCode)
|
|
|
|
{
|
|
|
|
// We could choose to abort here when hr == E_OUTOFMEMORY.
|
|
|
|
nsCString msg;
|
|
|
|
msg.Append(aMsg);
|
|
|
|
msg.AppendLiteral(" Error code: ");
|
2012-08-22 19:56:38 +04:00
|
|
|
msg.AppendInt(uint32_t(aCode));
|
2011-01-12 03:52:25 +03:00
|
|
|
NS_WARNING(msg.BeginReading());
|
2011-02-09 22:28:39 +03:00
|
|
|
|
|
|
|
gfx::LogFailure(msg);
|
2011-01-12 03:52:25 +03:00
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
LayerD3D10::LayerD3D10(LayerManagerD3D10 *aManager)
|
|
|
|
: mD3DManager(aManager)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-01 21:29:30 +04:00
|
|
|
ID3D10EffectTechnique*
|
2012-08-22 19:56:38 +04:00
|
|
|
LayerD3D10::SelectShader(uint8_t aFlags)
|
2012-03-01 21:29:30 +04:00
|
|
|
{
|
|
|
|
switch (aFlags) {
|
|
|
|
case (SHADER_RGBA | SHADER_NON_PREMUL | SHADER_LINEAR | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerNonPremulMask");
|
|
|
|
case (SHADER_RGBA | SHADER_NON_PREMUL | SHADER_LINEAR | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerNonPremul");
|
|
|
|
case (SHADER_RGBA | SHADER_NON_PREMUL | SHADER_POINT | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerNonPremulPoint");
|
|
|
|
case (SHADER_RGBA | SHADER_NON_PREMUL | SHADER_POINT | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerNonPremulPointMask");
|
|
|
|
case (SHADER_RGBA | SHADER_PREMUL | SHADER_LINEAR | SHADER_MASK_3D):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerPremulMask3D");
|
|
|
|
case (SHADER_RGBA | SHADER_PREMUL | SHADER_LINEAR | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerPremulMask");
|
|
|
|
case (SHADER_RGBA | SHADER_PREMUL | SHADER_LINEAR | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerPremul");
|
|
|
|
case (SHADER_RGBA | SHADER_PREMUL | SHADER_POINT | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerPremulPointMask");
|
|
|
|
case (SHADER_RGBA | SHADER_PREMUL | SHADER_POINT | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBALayerPremulPoint");
|
|
|
|
case (SHADER_RGB | SHADER_PREMUL | SHADER_POINT | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBLayerPremulPointMask");
|
|
|
|
case (SHADER_RGB | SHADER_PREMUL | SHADER_POINT | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBLayerPremulPoint");
|
|
|
|
case (SHADER_RGB | SHADER_PREMUL | SHADER_LINEAR | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBLayerPremulMask");
|
|
|
|
case (SHADER_RGB | SHADER_PREMUL | SHADER_LINEAR | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderRGBLayerPremul");
|
|
|
|
case (SHADER_SOLID | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderSolidColorLayerMask");
|
|
|
|
case (SHADER_SOLID | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderSolidColorLayer");
|
|
|
|
case (SHADER_COMPONENT_ALPHA | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderComponentAlphaLayerMask");
|
|
|
|
case (SHADER_COMPONENT_ALPHA | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderComponentAlphaLayer");
|
|
|
|
case (SHADER_YCBCR | SHADER_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderYCbCrLayerMask");
|
|
|
|
case (SHADER_YCBCR | SHADER_NO_MASK):
|
|
|
|
return effect()->GetTechniqueByName("RenderYCbCrLayer");
|
|
|
|
default:
|
|
|
|
NS_ERROR("Invalid shader.");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-03-01 21:29:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t
|
2012-03-01 21:29:30 +04:00
|
|
|
LayerD3D10::LoadMaskTexture()
|
2012-02-16 03:34:23 +04:00
|
|
|
{
|
|
|
|
if (Layer* maskLayer = GetLayer()->GetMaskLayer()) {
|
|
|
|
gfxIntSize size;
|
|
|
|
nsRefPtr<ID3D10ShaderResourceView> maskSRV =
|
|
|
|
static_cast<LayerD3D10*>(maskLayer->ImplData())->GetAsTexture(&size);
|
|
|
|
|
|
|
|
if (!maskSRV) {
|
2012-03-01 21:29:30 +04:00
|
|
|
return SHADER_NO_MASK;
|
2012-02-16 03:34:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxMatrix maskTransform;
|
2012-03-01 21:29:30 +04:00
|
|
|
bool maskIs2D = maskLayer->GetEffectiveTransform().CanDraw2D(&maskTransform);
|
Backout 61fd66629c4f, 7c8121f8d3af & 2a2e9cf8fd41 (bug 539356), e31a5e6545d3 (bug 761884), 85fa80bd9792, a284ccb25b83, 2865904db9fc, 34e07b09c426, e9b3d41e0360, cef00ebcd6c8, f943b729ac14 & 783f298401b6 (bug 539356), 330a086f1570 (bug 741682), d80219c8842c (bug 739671), e8c96b4fd4da, 313af486e68d, 0adc41ff56dc, 0cd288a38085, f1d43208825c, 4859876972f3, eec8ef3ebe48, f7f29fcd1845, 6079b229d306, f23c3a7e7ce0, 9824458a41e2 & 6748b5496059 (bug 539356) for mochitest-4 orange & talos regressions on multiple platforms
2012-06-11 13:08:32 +04:00
|
|
|
NS_ASSERTION(maskIs2D, "How did we end up with a 3D transform here?!");
|
2012-03-01 21:29:30 +04:00
|
|
|
gfxRect bounds = gfxRect(gfxPoint(), size);
|
|
|
|
bounds = maskTransform.TransformBounds(bounds);
|
2012-02-16 03:34:23 +04:00
|
|
|
|
|
|
|
effect()->GetVariableByName("vMaskQuad")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
|
|
|
(float)bounds.x,
|
|
|
|
(float)bounds.y,
|
|
|
|
(float)bounds.width,
|
|
|
|
(float)bounds.height)
|
|
|
|
);
|
|
|
|
|
|
|
|
effect()->GetVariableByName("tMask")->AsShaderResource()->SetResource(maskSRV);
|
2012-03-01 21:29:30 +04:00
|
|
|
return SHADER_MASK;
|
2012-02-16 03:34:23 +04:00
|
|
|
}
|
|
|
|
|
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 13:20:52 +04:00
|
|
|
return SHADER_NO_MASK;
|
2011-08-09 23:38:26 +04:00
|
|
|
}
|
|
|
|
|
2010-10-01 02:53:49 +04:00
|
|
|
}
|
|
|
|
}
|