2011-08-09 12:38:26 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
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-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
#include "ContainerLayerD3D10.h"
|
|
|
|
|
2011-02-04 18:30:00 -08:00
|
|
|
#include "ThebesLayerD3D10.h"
|
|
|
|
#include "ReadbackProcessor.h"
|
|
|
|
|
2014-01-27 12:25:19 -08:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
ContainerLayerD3D10::ContainerLayerD3D10(LayerManagerD3D10 *aManager)
|
2013-07-20 01:48:55 -07:00
|
|
|
: ContainerLayer(aManager, nullptr)
|
2010-09-30 15:53:49 -07:00
|
|
|
, LayerD3D10(aManager)
|
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerD3D10*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContainerLayerD3D10::~ContainerLayerD3D10()
|
|
|
|
{
|
|
|
|
while (mFirstChild) {
|
|
|
|
RemoveChild(mFirstChild);
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 03:52:55 -07:00
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
Layer*
|
|
|
|
ContainerLayerD3D10::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerD3D10*
|
|
|
|
ContainerLayerD3D10::GetFirstChildD3D10()
|
|
|
|
{
|
|
|
|
if (!mFirstChild) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
|
|
|
return static_cast<LayerD3D10*>(mFirstChild->ImplData());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-08 01:06:15 -08:00
|
|
|
ContainerLayerD3D10::RenderLayer()
|
2010-09-30 15:53:49 -07:00
|
|
|
{
|
|
|
|
float renderTargetOffset[] = { 0, 0 };
|
|
|
|
|
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
2010-11-08 01:06:15 -08:00
|
|
|
float opacity = GetEffectiveOpacity();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useIntermediate = UseIntermediateSurface();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
nsRefPtr<ID3D10RenderTargetView> previousRTView;
|
|
|
|
nsRefPtr<ID3D10Texture2D> renderTexture;
|
|
|
|
nsRefPtr<ID3D10RenderTargetView> rtView;
|
|
|
|
float previousRenderTargetOffset[2];
|
|
|
|
nsIntSize previousViewportSize;
|
|
|
|
|
|
|
|
gfx3DMatrix oldViewMatrix;
|
|
|
|
|
|
|
|
if (useIntermediate) {
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->OMGetRenderTargets(1, getter_AddRefs(previousRTView), nullptr);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
D3D10_TEXTURE2D_DESC desc;
|
|
|
|
memset(&desc, 0, sizeof(D3D10_TEXTURE2D_DESC));
|
|
|
|
desc.ArraySize = 1;
|
|
|
|
desc.MipLevels = 1;
|
|
|
|
desc.Width = visibleRect.width;
|
|
|
|
desc.Height = visibleRect.height;
|
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
|
2011-10-12 18:01:30 -07:00
|
|
|
HRESULT hr;
|
2013-07-20 01:48:55 -07:00
|
|
|
hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(renderTexture));
|
2011-10-12 18:01:30 -07:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("Failed to create new texture for ContainerLayerD3D10!"),
|
|
|
|
hr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-20 01:48:55 -07:00
|
|
|
hr = device()->CreateRenderTargetView(renderTexture, nullptr, getter_AddRefs(rtView));
|
2011-10-12 18:01:30 -07:00
|
|
|
NS_ASSERTION(SUCCEEDED(hr), "Failed to create render target view for ContainerLayerD3D10!");
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2011-01-27 21:34:33 -08:00
|
|
|
effect()->GetVariableByName("vRenderTargetOffset")->
|
|
|
|
GetRawValue(previousRenderTargetOffset, 0, 8);
|
|
|
|
|
2013-07-29 03:35:48 -07:00
|
|
|
previousViewportSize = mD3DManager->GetViewport();
|
|
|
|
|
2011-01-27 21:34:33 -08:00
|
|
|
if (mVisibleRegion.GetNumRects() != 1 || !(GetContentFlags() & CONTENT_OPAQUE)) {
|
2014-01-27 12:25:19 -08:00
|
|
|
Matrix4x4 transform3D = GetEffectiveTransform();
|
|
|
|
Matrix transform;
|
2011-01-27 21:34:33 -08:00
|
|
|
// If we have an opaque ancestor layer, then we can be sure that
|
|
|
|
// all the pixels we draw into are either opaque already or will be
|
|
|
|
// covered by something opaque. Otherwise copying up the background is
|
|
|
|
// not safe.
|
|
|
|
if (mSupportsComponentAlphaChildren) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool is2d = transform3D.Is2D(&transform);
|
2011-01-27 21:34:33 -08:00
|
|
|
NS_ASSERTION(is2d, "Transform should be 2d when mSupportsComponentAlphaChildren.");
|
|
|
|
|
|
|
|
// Copy background up from below. This applies any 2D transform that is
|
|
|
|
// applied to use relative to our parent, and compensates for the offset
|
|
|
|
// that was applied on our parent's rendering.
|
|
|
|
D3D10_BOX srcBox;
|
2014-01-27 12:25:19 -08:00
|
|
|
srcBox.left = std::max<int32_t>(visibleRect.x + int32_t(transform._31) - int32_t(previousRenderTargetOffset[0]), 0);
|
|
|
|
srcBox.top = std::max<int32_t>(visibleRect.y + int32_t(transform._32) - int32_t(previousRenderTargetOffset[1]), 0);
|
2013-07-29 03:35:48 -07:00
|
|
|
srcBox.right = std::min<int32_t>(srcBox.left + visibleRect.width, previousViewportSize.width);
|
|
|
|
srcBox.bottom = std::min<int32_t>(srcBox.top + visibleRect.height, previousViewportSize.height);
|
2011-01-27 21:34:33 -08:00
|
|
|
srcBox.back = 1;
|
|
|
|
srcBox.front = 0;
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Resource> srcResource;
|
|
|
|
previousRTView->GetResource(getter_AddRefs(srcResource));
|
|
|
|
|
|
|
|
device()->CopySubresourceRegion(renderTexture, 0,
|
|
|
|
0, 0, 0,
|
|
|
|
srcResource, 0,
|
|
|
|
&srcBox);
|
|
|
|
} else {
|
|
|
|
float black[] = { 0, 0, 0, 0};
|
|
|
|
device()->ClearRenderTargetView(rtView, black);
|
|
|
|
}
|
|
|
|
}
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
ID3D10RenderTargetView *rtViewPtr = rtView;
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->OMSetRenderTargets(1, &rtViewPtr, nullptr);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
renderTargetOffset[0] = (float)visibleRect.x;
|
|
|
|
renderTargetOffset[1] = (float)visibleRect.y;
|
|
|
|
effect()->GetVariableByName("vRenderTargetOffset")->
|
|
|
|
SetRawValue(renderTargetOffset, 0, 8);
|
|
|
|
|
|
|
|
mD3DManager->SetViewport(nsIntSize(visibleRect.Size()));
|
|
|
|
}
|
2011-02-24 23:44:22 -08:00
|
|
|
|
|
|
|
D3D10_RECT oldD3D10Scissor;
|
|
|
|
UINT numRects = 1;
|
|
|
|
device()->RSGetScissorRects(&numRects, &oldD3D10Scissor);
|
|
|
|
// Convert scissor to an nsIntRect. D3D10_RECT's are exclusive
|
|
|
|
// on the bottom and right values.
|
|
|
|
nsIntRect oldScissor(oldD3D10Scissor.left,
|
|
|
|
oldD3D10Scissor.top,
|
|
|
|
oldD3D10Scissor.right - oldD3D10Scissor.left,
|
|
|
|
oldD3D10Scissor.bottom - oldD3D10Scissor.top);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2011-10-06 14:24:32 -07:00
|
|
|
nsAutoTArray<Layer*, 12> children;
|
|
|
|
SortChildrenBy3DZOrder(children);
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
/*
|
|
|
|
* Render this container's contents.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < children.Length(); i++) {
|
2011-10-06 14:24:32 -07:00
|
|
|
LayerD3D10* layerToRender = static_cast<LayerD3D10*>(children.ElementAt(i)->ImplData());
|
2010-11-29 21:51:56 -08:00
|
|
|
|
2011-02-24 23:44:22 -08:00
|
|
|
if (layerToRender->GetLayer()->GetEffectiveVisibleRegion().IsEmpty()) {
|
2010-11-29 21:51:56 -08:00
|
|
|
continue;
|
|
|
|
}
|
2014-07-30 11:36:15 -07:00
|
|
|
|
2011-02-24 23:44:22 -08:00
|
|
|
nsIntRect scissorRect =
|
2014-09-10 12:59:00 -07:00
|
|
|
RenderTargetPixel::ToUntyped(layerToRender->GetLayer()->CalculateScissorRect(RenderTargetPixel::FromUntyped(oldScissor)));
|
2011-02-24 23:44:22 -08:00
|
|
|
if (scissorRect.IsEmpty()) {
|
|
|
|
continue;
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
|
|
|
|
2011-02-24 23:44:22 -08:00
|
|
|
D3D10_RECT d3drect;
|
|
|
|
d3drect.left = scissorRect.x;
|
|
|
|
d3drect.top = scissorRect.y;
|
2011-03-24 18:57:09 -07:00
|
|
|
d3drect.right = scissorRect.x + scissorRect.width;
|
|
|
|
d3drect.bottom = scissorRect.y + scissorRect.height;
|
2011-02-24 23:44:22 -08:00
|
|
|
device()->RSSetScissorRects(1, &d3drect);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
2011-02-24 23:44:22 -08:00
|
|
|
layerToRender->RenderLayer();
|
2010-09-30 15:53:49 -07:00
|
|
|
}
|
2011-05-22 17:27:03 -07:00
|
|
|
|
2011-02-24 23:44:22 -08:00
|
|
|
device()->RSSetScissorRects(1, &oldD3D10Scissor);
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
if (useIntermediate) {
|
|
|
|
mD3DManager->SetViewport(previousViewportSize);
|
|
|
|
ID3D10RenderTargetView *rtView = previousRTView;
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->OMSetRenderTargets(1, &rtView, nullptr);
|
2010-09-30 15:53:49 -07:00
|
|
|
effect()->GetVariableByName("vRenderTargetOffset")->
|
|
|
|
SetRawValue(previousRenderTargetOffset, 0, 8);
|
|
|
|
|
2010-11-08 01:06:15 -08:00
|
|
|
SetEffectTransformAndOpacity();
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
ID3D10EffectTechnique *technique;
|
2012-02-15 15:34:25 -08:00
|
|
|
if (LoadMaskTexture()) {
|
|
|
|
if (GetTransform().CanDraw2D()) {
|
2012-03-01 09:29:30 -08:00
|
|
|
technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_MASK);
|
2012-02-15 15:34:25 -08:00
|
|
|
} else {
|
2012-03-01 09:29:30 -08:00
|
|
|
technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_MASK_3D);
|
2012-02-15 15:34:25 -08:00
|
|
|
}
|
|
|
|
} else {
|
2012-03-01 09:29:30 -08:00
|
|
|
technique = SelectShader(SHADER_RGBA | SHADER_PREMUL | SHADER_NO_MASK);
|
2012-02-15 15:34:25 -08:00
|
|
|
}
|
2010-09-30 15:53:49 -07:00
|
|
|
|
|
|
|
effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
|
|
|
(float)visibleRect.x,
|
|
|
|
(float)visibleRect.y,
|
|
|
|
(float)visibleRect.width,
|
|
|
|
(float)visibleRect.height)
|
|
|
|
);
|
|
|
|
|
|
|
|
technique->GetPassByIndex(0)->Apply(0);
|
|
|
|
|
|
|
|
ID3D10ShaderResourceView *view;
|
2013-07-20 01:48:55 -07:00
|
|
|
device()->CreateShaderResourceView(renderTexture, nullptr, &view);
|
2010-09-30 15:53:49 -07:00
|
|
|
device()->PSSetShaderResources(0, 1, &view);
|
|
|
|
device()->Draw(4, 0);
|
|
|
|
view->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContainerLayerD3D10::LayerManagerDestroyed()
|
|
|
|
{
|
|
|
|
while (mFirstChild) {
|
|
|
|
GetFirstChildD3D10()->LayerManagerDestroyed();
|
|
|
|
RemoveChild(mFirstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContainerLayerD3D10::Validate()
|
|
|
|
{
|
2011-01-27 21:34:33 -08:00
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mSupportsComponentAlphaChildren = false;
|
2011-01-27 21:34:33 -08:00
|
|
|
|
|
|
|
if (UseIntermediateSurface()) {
|
2014-01-27 12:25:19 -08:00
|
|
|
Matrix4x4 transform3D = GetEffectiveTransform();
|
|
|
|
Matrix transform;
|
2011-01-27 21:34:33 -08:00
|
|
|
|
|
|
|
if (mVisibleRegion.GetNumRects() == 1 && (GetContentFlags() & CONTENT_OPAQUE)) {
|
|
|
|
// don't need a background, we're going to paint all opaque stuff
|
2011-10-17 07:59:28 -07:00
|
|
|
mSupportsComponentAlphaChildren = true;
|
2011-01-27 21:34:33 -08:00
|
|
|
} else {
|
|
|
|
if (HasOpaqueAncestorLayer(this) &&
|
2014-01-27 12:25:19 -08:00
|
|
|
transform3D.Is2D(&transform) && !ThebesMatrix(transform).HasNonIntegerTranslation() &&
|
2011-01-27 21:34:33 -08:00
|
|
|
GetParent()->GetEffectiveVisibleRegion().GetBounds().Contains(visibleRect))
|
|
|
|
{
|
|
|
|
// In this case we can copy up the background. See RenderLayer.
|
2011-10-17 07:59:28 -07:00
|
|
|
mSupportsComponentAlphaChildren = true;
|
2011-01-27 21:34:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mSupportsComponentAlphaChildren = (GetContentFlags() & CONTENT_OPAQUE) ||
|
|
|
|
(mParent && mParent->SupportsComponentAlphaChildren());
|
|
|
|
}
|
|
|
|
|
2011-02-04 18:30:00 -08:00
|
|
|
ReadbackProcessor readback;
|
|
|
|
readback.BuildUpdates(this);
|
|
|
|
|
2010-09-30 15:53:49 -07:00
|
|
|
Layer *layer = GetFirstChild();
|
|
|
|
while (layer) {
|
2011-02-04 18:30:00 -08:00
|
|
|
if (layer->GetType() == TYPE_THEBES) {
|
|
|
|
static_cast<ThebesLayerD3D10*>(layer)->Validate(&readback);
|
|
|
|
} else {
|
|
|
|
static_cast<LayerD3D10*>(layer->ImplData())->Validate();
|
|
|
|
}
|
2010-09-30 15:53:49 -07:00
|
|
|
layer = layer->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|