2010-05-24 15:28:51 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Corporation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Bas Schouten <bschouten@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-07-04 13:15:05 +00:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
|
|
|
#include "ShadowBufferD3D9.h"
|
|
|
|
|
2010-05-24 15:28:51 +00:00
|
|
|
#include "ThebesLayerD3D9.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
2010-07-13 22:19:45 +00:00
|
|
|
#include "gfxWindowsPlatform.h"
|
2011-01-03 01:48:09 +00:00
|
|
|
#include "gfxTeeSurface.h"
|
|
|
|
#include "gfxUtils.h"
|
2011-02-16 22:43:30 +00:00
|
|
|
#include "ReadbackProcessor.h"
|
2010-07-13 22:19:45 +00:00
|
|
|
|
2010-05-24 15:28:51 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
ThebesLayerD3D9::ThebesLayerD3D9(LayerManagerD3D9 *aManager)
|
|
|
|
: ThebesLayer(aManager, NULL)
|
|
|
|
, LayerD3D9(aManager)
|
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerD3D9*>(this);
|
2010-09-14 10:56:39 +00:00
|
|
|
aManager->deviceManager()->mLayersWithResources.AppendElement(this);
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ThebesLayerD3D9::~ThebesLayerD3D9()
|
|
|
|
{
|
2010-09-15 22:15:56 +00:00
|
|
|
if (mD3DManager) {
|
2010-09-14 10:56:39 +00:00
|
|
|
mD3DManager->deviceManager()->mLayersWithResources.RemoveElement(this);
|
2010-09-03 18:07:59 +00:00
|
|
|
}
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 02:08:48 +00:00
|
|
|
/**
|
|
|
|
* Retention threshold - amount of pixels intersection required to enable
|
|
|
|
* layer content retention. This is a guesstimate. Profiling could be done to
|
|
|
|
* figure out the optimal threshold.
|
|
|
|
*/
|
|
|
|
#define RETENTION_THRESHOLD 16384
|
2010-05-24 15:28:51 +00:00
|
|
|
|
|
|
|
void
|
2011-01-03 01:48:09 +00:00
|
|
|
ThebesLayerD3D9::InvalidateRegion(const nsIntRegion &aRegion)
|
2010-05-24 15:28:51 +00:00
|
|
|
{
|
2011-01-03 01:48:09 +00:00
|
|
|
mValidRegion.Sub(mValidRegion, aRegion);
|
|
|
|
}
|
2010-07-02 02:08:48 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
void
|
|
|
|
ThebesLayerD3D9::CopyRegion(IDirect3DTexture9* aSrc, const nsIntPoint &aSrcOffset,
|
|
|
|
IDirect3DTexture9* aDest, const nsIntPoint &aDestOffset,
|
2011-06-22 12:11:27 +00:00
|
|
|
const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion)
|
2011-01-03 01:48:09 +00:00
|
|
|
{
|
2010-07-02 02:08:48 +00:00
|
|
|
nsRefPtr<IDirect3DSurface9> srcSurface, dstSurface;
|
2011-01-03 01:48:09 +00:00
|
|
|
aSrc->GetSurfaceLevel(0, getter_AddRefs(srcSurface));
|
|
|
|
aDest->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
2010-07-02 02:08:48 +00:00
|
|
|
|
|
|
|
nsIntRegion retainedRegion;
|
2011-01-03 01:48:09 +00:00
|
|
|
nsIntRegionRectIterator iter(aCopyRegion);
|
2010-07-02 02:08:48 +00:00
|
|
|
const nsIntRect *r;
|
|
|
|
while ((r = iter.Next())) {
|
|
|
|
if (r->width * r->height > RETENTION_THRESHOLD) {
|
|
|
|
RECT oldRect, newRect;
|
|
|
|
|
|
|
|
// Calculate the retained rectangle's position on the old and the new
|
2011-06-22 12:11:27 +00:00
|
|
|
// surface.
|
|
|
|
oldRect.left = r->x - aSrcOffset.x;
|
|
|
|
oldRect.top = r->y - aSrcOffset.y;
|
|
|
|
oldRect.right = oldRect.left + r->width;
|
|
|
|
oldRect.bottom = oldRect.top + r->height;
|
|
|
|
|
|
|
|
newRect.left = r->x - aDestOffset.x;
|
|
|
|
newRect.top = r->y - aDestOffset.y;
|
|
|
|
newRect.right = newRect.left + r->width;
|
|
|
|
newRect.bottom = newRect.top + r->height;
|
2010-07-02 02:08:48 +00:00
|
|
|
|
|
|
|
// Copy data from our old texture to the new one
|
|
|
|
HRESULT hr = device()->
|
|
|
|
StretchRect(srcSurface, &oldRect, dstSurface, &newRect, D3DTEXF_NONE);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
retainedRegion.Or(retainedRegion, *r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Areas which were valid and were retained are still valid
|
2011-01-03 01:48:09 +00:00
|
|
|
aValidRegion->And(*aValidRegion, retainedRegion);
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
static PRUint64 RectArea(const nsIntRect& aRect)
|
2010-05-24 15:28:51 +00:00
|
|
|
{
|
2011-01-03 01:48:09 +00:00
|
|
|
return aRect.width*PRUint64(aRect.height);
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-03 01:48:09 +00:00
|
|
|
ThebesLayerD3D9::UpdateTextures(SurfaceMode aMode)
|
2010-05-24 15:28:51 +00:00
|
|
|
{
|
2010-05-31 23:29:37 +00:00
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
if (HaveTextures(aMode)) {
|
2011-04-19 03:07:23 +00:00
|
|
|
if (!mTextureRect.IsEqualInterior(visibleRect)) {
|
2011-01-03 01:48:09 +00:00
|
|
|
nsRefPtr<IDirect3DTexture9> oldTexture = mTexture;
|
|
|
|
nsRefPtr<IDirect3DTexture9> oldTextureOnWhite = mTextureOnWhite;
|
|
|
|
|
|
|
|
NS_ASSERTION(mTextureRect.Contains(mValidRegion.GetBounds()),
|
|
|
|
"How can we have valid data outside the texture?");
|
|
|
|
nsIntRegion retainRegion;
|
|
|
|
// The region we want to retain is the valid data that is inside
|
|
|
|
// the new visible region
|
|
|
|
retainRegion.And(mValidRegion, mVisibleRegion);
|
|
|
|
|
|
|
|
CreateNewTextures(gfxIntSize(visibleRect.width, visibleRect.height), aMode);
|
|
|
|
|
|
|
|
// If our texture creation failed this can mean a device reset is pending and we
|
|
|
|
// should silently ignore the failure. In the future when device failures
|
|
|
|
// are properly handled we should test for the type of failure and gracefully
|
|
|
|
// handle different failures. See bug 569081.
|
|
|
|
if (!HaveTextures(aMode)) {
|
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
} else {
|
|
|
|
CopyRegion(oldTexture, mTextureRect.TopLeft(), mTexture, visibleRect.TopLeft(),
|
2011-06-22 12:11:27 +00:00
|
|
|
retainRegion, &mValidRegion);
|
2011-01-03 01:48:09 +00:00
|
|
|
if (aMode == SURFACE_COMPONENT_ALPHA) {
|
|
|
|
CopyRegion(oldTextureOnWhite, mTextureRect.TopLeft(), mTextureOnWhite, visibleRect.TopLeft(),
|
2011-06-22 12:11:27 +00:00
|
|
|
retainRegion, &mValidRegion);
|
2011-01-03 01:48:09 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-13 22:19:45 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
mTextureRect = visibleRect;
|
2010-07-13 22:19:45 +00:00
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
} else {
|
|
|
|
CreateNewTextures(gfxIntSize(visibleRect.width, visibleRect.height), aMode);
|
|
|
|
mTextureRect = visibleRect;
|
|
|
|
|
|
|
|
NS_ASSERTION(mValidRegion.IsEmpty(), "Someone forgot to empty the region");
|
2010-07-13 22:19:45 +00:00
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
}
|
2010-07-13 22:19:45 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
void
|
2011-03-31 21:33:46 +00:00
|
|
|
ThebesLayerD3D9::RenderRegion(const nsIntRegion& aRegion)
|
2011-01-03 01:48:09 +00:00
|
|
|
{
|
2011-03-31 21:33:46 +00:00
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
2010-09-12 19:38:47 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
const nsIntRect *iterRect;
|
|
|
|
while ((iterRect = iter.Next())) {
|
|
|
|
device()->SetVertexShaderConstantF(CBvLayerQuad,
|
|
|
|
ShaderConstantRect(iterRect->x,
|
|
|
|
iterRect->y,
|
|
|
|
iterRect->width,
|
|
|
|
iterRect->height),
|
|
|
|
1);
|
|
|
|
|
|
|
|
device()->SetVertexShaderConstantF(CBvTextureCoords,
|
|
|
|
ShaderConstantRect(
|
|
|
|
(float)(iterRect->x - mTextureRect.x) / (float)mTextureRect.width,
|
|
|
|
(float)(iterRect->y - mTextureRect.y) / (float)mTextureRect.height,
|
|
|
|
(float)iterRect->width / (float)mTextureRect.width,
|
|
|
|
(float)iterRect->height / (float)mTextureRect.height), 1);
|
|
|
|
|
|
|
|
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-16 22:43:30 +00:00
|
|
|
ThebesLayerD3D9::RenderThebesLayer(ReadbackProcessor* aReadback)
|
2011-01-03 01:48:09 +00:00
|
|
|
{
|
|
|
|
if (mVisibleRegion.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-09-27 04:57:40 +00:00
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
nsIntRect newTextureRect = mVisibleRegion.GetBounds();
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
SurfaceMode mode = GetSurfaceMode();
|
|
|
|
if (mode == SURFACE_COMPONENT_ALPHA &&
|
|
|
|
(!mParent || !mParent->SupportsComponentAlphaChildren())) {
|
|
|
|
mode = SURFACE_SINGLE_CHANNEL_ALPHA;
|
|
|
|
}
|
2011-03-31 21:33:46 +00:00
|
|
|
// If we have a transform that requires resampling of our texture, then
|
|
|
|
// we need to make sure we don't sample pixels that haven't been drawn.
|
|
|
|
// We clamp sample coordinates to the texture rect, but when the visible region
|
|
|
|
// doesn't fill the entire texture rect we need to make sure we draw all the
|
|
|
|
// pixels in the texture rect anyway in case they get sampled.
|
|
|
|
nsIntRegion neededRegion = mVisibleRegion;
|
2011-04-19 03:07:23 +00:00
|
|
|
if (!neededRegion.GetBounds().IsEqualInterior(newTextureRect) ||
|
2011-03-31 21:33:46 +00:00
|
|
|
neededRegion.GetNumRects() > 1) {
|
|
|
|
gfxMatrix transform2d;
|
|
|
|
if (!GetEffectiveTransform().Is2D(&transform2d) ||
|
|
|
|
transform2d.HasNonIntegerTranslation()) {
|
|
|
|
neededRegion = newTextureRect;
|
|
|
|
if (mode == SURFACE_OPAQUE) {
|
|
|
|
// We're going to paint outside the visible region, but layout hasn't
|
|
|
|
// promised that it will paint opaquely there, so we'll have to
|
|
|
|
// treat this layer as transparent.
|
|
|
|
mode = SURFACE_SINGLE_CHANNEL_ALPHA;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
VerifyContentType(mode);
|
|
|
|
UpdateTextures(mode);
|
|
|
|
if (!HaveTextures(mode)) {
|
|
|
|
NS_WARNING("Texture creation failed");
|
|
|
|
return;
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
2010-07-02 02:08:48 +00:00
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
nsTArray<ReadbackProcessor::Update> readbackUpdates;
|
|
|
|
nsIntRegion readbackRegion;
|
|
|
|
if (aReadback && UsedForReadback()) {
|
|
|
|
aReadback->GetThebesLayerUpdates(this, &readbackUpdates, &readbackRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because updates to D3D9 ThebesLayers are rendered with the CPU, we don't
|
|
|
|
// have to do readback from D3D9 surfaces. Instead we make sure that any area
|
|
|
|
// needed for readback is included in the drawRegion we ask layout to render.
|
|
|
|
// Then the readback areas we need can be copied out of the temporary
|
|
|
|
// destinationSurface in DrawRegion.
|
|
|
|
nsIntRegion drawRegion;
|
2011-03-31 21:33:46 +00:00
|
|
|
drawRegion.Sub(neededRegion, mValidRegion);
|
2011-02-16 22:43:30 +00:00
|
|
|
drawRegion.Or(drawRegion, readbackRegion);
|
|
|
|
// NS_ASSERTION(mVisibleRegion.Contains(region), "Bad readback region!");
|
|
|
|
|
|
|
|
if (!drawRegion.IsEmpty()) {
|
2011-01-19 08:27:54 +00:00
|
|
|
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
|
|
|
|
if (!cbInfo.Callback) {
|
|
|
|
NS_ERROR("D3D9 should never need to update ThebesLayers in an empty transaction");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
DrawRegion(drawRegion, mode, readbackUpdates);
|
2010-05-29 03:27:03 +00:00
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
mValidRegion = neededRegion;
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
2010-05-29 03:27:03 +00:00
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
SetShaderTransformAndOpacity();
|
2010-05-24 15:28:51 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
if (mode == SURFACE_COMPONENT_ALPHA) {
|
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::COMPONENTLAYERPASS1);
|
|
|
|
device()->SetTexture(0, mTexture);
|
|
|
|
device()->SetTexture(1, mTextureOnWhite);
|
|
|
|
device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ZERO);
|
|
|
|
device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
|
2011-03-31 21:33:46 +00:00
|
|
|
RenderRegion(neededRegion);
|
2011-01-03 01:48:09 +00:00
|
|
|
|
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::COMPONENTLAYERPASS2);
|
|
|
|
device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
|
|
|
|
device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
|
2011-03-31 21:33:46 +00:00
|
|
|
RenderRegion(neededRegion);
|
2011-01-03 01:48:09 +00:00
|
|
|
|
|
|
|
// Restore defaults
|
|
|
|
device()->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
|
|
|
|
device()->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
|
|
|
device()->SetTexture(1, NULL);
|
|
|
|
} else {
|
|
|
|
mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBALAYER);
|
|
|
|
device()->SetTexture(0, mTexture);
|
2011-03-31 21:33:46 +00:00
|
|
|
RenderRegion(neededRegion);
|
2010-09-08 03:27:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set back to default.
|
2010-10-01 22:24:58 +00:00
|
|
|
device()->SetVertexShaderConstantF(CBvTextureCoords,
|
|
|
|
ShaderConstantRect(0, 0, 1.0f, 1.0f),
|
|
|
|
1);
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerD3D9::CleanResources()
|
|
|
|
{
|
|
|
|
mTexture = nsnull;
|
2011-01-03 01:48:09 +00:00
|
|
|
mTextureOnWhite = nsnull;
|
2011-01-04 01:37:13 +00:00
|
|
|
mValidRegion.SetEmpty();
|
2010-05-24 15:28:51 +00:00
|
|
|
}
|
|
|
|
|
2010-09-15 22:15:49 +00:00
|
|
|
void
|
|
|
|
ThebesLayerD3D9::LayerManagerDestroyed()
|
|
|
|
{
|
|
|
|
mD3DManager->deviceManager()->mLayersWithResources.RemoveElement(this);
|
|
|
|
mD3DManager = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-05-24 15:28:51 +00:00
|
|
|
Layer*
|
|
|
|
ThebesLayerD3D9::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
ThebesLayerD3D9::IsEmpty()
|
|
|
|
{
|
|
|
|
return !mTexture;
|
|
|
|
}
|
|
|
|
|
2010-09-12 19:38:47 +00:00
|
|
|
void
|
2011-01-03 01:48:09 +00:00
|
|
|
ThebesLayerD3D9::VerifyContentType(SurfaceMode aMode)
|
2010-09-12 19:38:47 +00:00
|
|
|
{
|
2011-01-03 01:48:09 +00:00
|
|
|
if (!mTexture)
|
|
|
|
return;
|
|
|
|
|
|
|
|
D3DSURFACE_DESC desc;
|
|
|
|
mTexture->GetLevelDesc(0, &desc);
|
|
|
|
|
|
|
|
switch (aMode) {
|
|
|
|
case SURFACE_OPAQUE:
|
|
|
|
if (desc.Format == D3DFMT_X8R8G8B8 && !mTextureOnWhite)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_SINGLE_CHANNEL_ALPHA:
|
|
|
|
if (desc.Format == D3DFMT_A8R8G8B8 && !mTextureOnWhite)
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_COMPONENT_ALPHA:
|
|
|
|
if (mTextureOnWhite) {
|
|
|
|
NS_ASSERTION(desc.Format == D3DFMT_X8R8G8B8, "Wrong format for component alpha texture");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The new format isn't compatible with the old texture(s), toss out the old
|
|
|
|
// texture(s).
|
|
|
|
mTexture = nsnull;
|
|
|
|
mTextureOnWhite = nsnull;
|
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
class OpaqueRenderer {
|
|
|
|
public:
|
|
|
|
OpaqueRenderer(const nsIntRegion& aUpdateRegion) :
|
|
|
|
mUpdateRegion(aUpdateRegion), mDC(NULL) {}
|
2011-01-10 22:24:10 +00:00
|
|
|
~OpaqueRenderer() { End(); }
|
2011-06-22 12:11:27 +00:00
|
|
|
already_AddRefed<gfxWindowsSurface> Begin(LayerD3D9* aLayer);
|
2011-01-03 01:48:09 +00:00
|
|
|
void End();
|
|
|
|
IDirect3DTexture9* GetTexture() { return mTmpTexture; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsIntRegion& mUpdateRegion;
|
|
|
|
nsRefPtr<IDirect3DTexture9> mTmpTexture;
|
|
|
|
nsRefPtr<IDirect3DSurface9> mSurface;
|
|
|
|
HDC mDC;
|
|
|
|
};
|
|
|
|
|
|
|
|
already_AddRefed<gfxWindowsSurface>
|
2011-06-22 12:11:27 +00:00
|
|
|
OpaqueRenderer::Begin(LayerD3D9* aLayer)
|
2011-01-03 01:48:09 +00:00
|
|
|
{
|
|
|
|
nsIntRect bounds = mUpdateRegion.GetBounds();
|
|
|
|
|
|
|
|
HRESULT hr = aLayer->device()->
|
2011-06-22 12:11:27 +00:00
|
|
|
CreateTexture(bounds.width, bounds.height, 1, 0, D3DFMT_X8R8G8B8,
|
2011-01-03 01:48:09 +00:00
|
|
|
D3DPOOL_SYSTEMMEM, getter_AddRefs(mTmpTexture), NULL);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
aLayer->ReportFailure(NS_LITERAL_CSTRING("Failed to create temporary texture in system memory."), hr);
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mTmpTexture->GetSurfaceLevel(0, getter_AddRefs(mSurface));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
// Uh-oh, bail.
|
|
|
|
NS_WARNING("Failed to get texture surface level.");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mSurface->GetDC(&mDC);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to get device context for texture surface.");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxWindowsSurface> result = new gfxWindowsSurface(mDC);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OpaqueRenderer::End()
|
|
|
|
{
|
2011-01-10 22:24:10 +00:00
|
|
|
if (mSurface && mDC) {
|
|
|
|
mSurface->ReleaseDC(mDC);
|
|
|
|
mSurface = NULL;
|
|
|
|
mDC = NULL;
|
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
|
2011-06-22 12:11:27 +00:00
|
|
|
const nsIntPoint& aOffset, const gfxRGBA& aColor)
|
2011-01-03 01:48:09 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(aSurface);
|
|
|
|
ctx->Translate(-gfxPoint(aOffset.x, aOffset.y));
|
|
|
|
gfxUtils::ClipToRegion(ctx, aRegion);
|
|
|
|
ctx->SetColor(aColor);
|
|
|
|
ctx->Paint();
|
2010-09-12 19:38:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-11 00:36:05 +00:00
|
|
|
void
|
2011-02-16 22:43:30 +00:00
|
|
|
ThebesLayerD3D9::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode,
|
|
|
|
const nsTArray<ReadbackProcessor::Update>& aReadbackUpdates)
|
2010-08-11 00:36:05 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> destinationSurface;
|
2011-01-03 01:48:09 +00:00
|
|
|
nsIntRect bounds = aRegion.GetBounds();
|
2010-08-11 00:36:05 +00:00
|
|
|
nsRefPtr<IDirect3DTexture9> tmpTexture;
|
2011-01-03 01:48:09 +00:00
|
|
|
OpaqueRenderer opaqueRenderer(aRegion);
|
|
|
|
OpaqueRenderer opaqueRendererOnWhite(aRegion);
|
|
|
|
|
|
|
|
switch (aMode)
|
|
|
|
{
|
|
|
|
case SURFACE_OPAQUE:
|
2011-06-22 12:11:27 +00:00
|
|
|
destinationSurface = opaqueRenderer.Begin(this);
|
2011-01-03 01:48:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_SINGLE_CHANNEL_ALPHA: {
|
2011-06-22 12:11:27 +00:00
|
|
|
hr = device()->CreateTexture(bounds.width, bounds.height, 1,
|
2011-01-03 01:48:09 +00:00
|
|
|
0, D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_SYSTEMMEM, getter_AddRefs(tmpTexture), NULL);
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
ReportFailure(NS_LITERAL_CSTRING("Failed to create temporary texture in system memory."), hr);
|
|
|
|
return;
|
|
|
|
}
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
// XXX - We may consider retaining a SYSTEMMEM texture texture the size
|
|
|
|
// of our DEFAULT texture and then use UpdateTexture and add dirty rects
|
|
|
|
// to update in a single call.
|
|
|
|
nsRefPtr<gfxWindowsSurface> dest = new gfxWindowsSurface(
|
2011-06-22 12:11:27 +00:00
|
|
|
gfxIntSize(bounds.width, bounds.height), gfxASurface::ImageFormatARGB32);
|
2011-01-03 01:48:09 +00:00
|
|
|
// If the contents of this layer don't require component alpha in the
|
|
|
|
// end of rendering, it's safe to enable Cleartype since all the Cleartype
|
|
|
|
// glyphs must be over (or under) opaque pixels.
|
|
|
|
dest->SetSubpixelAntialiasingEnabled(!(mContentFlags & CONTENT_COMPONENT_ALPHA));
|
|
|
|
destinationSurface = dest.forget();
|
|
|
|
break;
|
2010-08-11 00:36:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
case SURFACE_COMPONENT_ALPHA: {
|
2011-06-22 12:11:27 +00:00
|
|
|
nsRefPtr<gfxWindowsSurface> onBlack = opaqueRenderer.Begin(this);
|
|
|
|
nsRefPtr<gfxWindowsSurface> onWhite = opaqueRendererOnWhite.Begin(this);
|
2011-01-10 22:07:49 +00:00
|
|
|
if (onBlack && onWhite) {
|
2011-06-22 12:11:27 +00:00
|
|
|
FillSurface(onBlack, aRegion, bounds.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0));
|
|
|
|
FillSurface(onWhite, aRegion, bounds.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0));
|
2011-01-10 22:07:49 +00:00
|
|
|
gfxASurface* surfaces[2] = { onBlack.get(), onWhite.get() };
|
|
|
|
destinationSurface = new gfxTeeSurface(surfaces, NS_ARRAY_LENGTH(surfaces));
|
|
|
|
// Using this surface as a source will likely go horribly wrong, since
|
|
|
|
// only the onBlack surface will really be used, so alpha information will
|
|
|
|
// be incorrect.
|
|
|
|
destinationSurface->SetAllowUseAsSource(PR_FALSE);
|
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
break;
|
2010-08-11 00:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 22:24:10 +00:00
|
|
|
if (!destinationSurface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(destinationSurface);
|
|
|
|
context->Translate(gfxPoint(-bounds.x, -bounds.y));
|
|
|
|
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
|
|
|
|
cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-02-16 22:43:30 +00:00
|
|
|
for (PRUint32 i = 0; i < aReadbackUpdates.Length(); ++i) {
|
|
|
|
NS_ASSERTION(aMode == SURFACE_OPAQUE,
|
|
|
|
"Transparent surfaces should not be used for readback");
|
|
|
|
const ReadbackProcessor::Update& update = aReadbackUpdates[i];
|
|
|
|
nsIntPoint offset = update.mLayer->GetBackgroundLayerOffset();
|
|
|
|
nsRefPtr<gfxContext> ctx =
|
|
|
|
update.mLayer->GetSink()->BeginUpdate(update.mUpdateRect + offset,
|
|
|
|
update.mSequenceCounter);
|
|
|
|
if (ctx) {
|
|
|
|
ctx->Translate(gfxPoint(offset.x, offset.y));
|
|
|
|
ctx->SetSource(destinationSurface, gfxPoint(bounds.x, bounds.y));
|
|
|
|
ctx->Paint();
|
|
|
|
update.mLayer->GetSink()->EndUpdate(ctx, update.mUpdateRect + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
nsAutoTArray<IDirect3DTexture9*,2> srcTextures;
|
|
|
|
nsAutoTArray<IDirect3DTexture9*,2> destTextures;
|
|
|
|
switch (aMode)
|
|
|
|
{
|
|
|
|
case SURFACE_OPAQUE:
|
|
|
|
opaqueRenderer.End();
|
|
|
|
srcTextures.AppendElement(opaqueRenderer.GetTexture());
|
|
|
|
destTextures.AppendElement(mTexture);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SURFACE_SINGLE_CHANNEL_ALPHA: {
|
2011-07-04 13:15:05 +00:00
|
|
|
LockTextureRectD3D9 textureLock(tmpTexture);
|
|
|
|
if (!textureLock.HasLock()) {
|
|
|
|
NS_WARNING("Failed to lock ThebesLayer tmpTexture texture.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
D3DLOCKED_RECT r = textureLock.GetLockRect();
|
2011-01-03 01:48:09 +00:00
|
|
|
|
|
|
|
nsRefPtr<gfxImageSurface> imgSurface =
|
|
|
|
new gfxImageSurface((unsigned char *)r.pBits,
|
2011-06-22 12:11:27 +00:00
|
|
|
bounds.Size(),
|
2011-01-03 01:48:09 +00:00
|
|
|
r.Pitch,
|
|
|
|
gfxASurface::ImageFormatARGB32);
|
|
|
|
|
2011-01-04 20:59:00 +00:00
|
|
|
if (destinationSurface) {
|
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(imgSurface);
|
|
|
|
context->SetSource(destinationSurface);
|
|
|
|
context->SetOperator(gfxContext::OPERATOR_SOURCE);
|
|
|
|
context->Paint();
|
|
|
|
}
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
imgSurface = NULL;
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
srcTextures.AppendElement(tmpTexture);
|
|
|
|
destTextures.AppendElement(mTexture);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
case SURFACE_COMPONENT_ALPHA: {
|
|
|
|
opaqueRenderer.End();
|
|
|
|
opaqueRendererOnWhite.End();
|
|
|
|
srcTextures.AppendElement(opaqueRenderer.GetTexture());
|
|
|
|
destTextures.AppendElement(mTexture);
|
|
|
|
srcTextures.AppendElement(opaqueRendererOnWhite.GetTexture());
|
|
|
|
destTextures.AppendElement(mTextureOnWhite);
|
|
|
|
break;
|
|
|
|
}
|
2010-08-11 00:36:05 +00:00
|
|
|
}
|
2011-01-03 01:48:09 +00:00
|
|
|
NS_ASSERTION(srcTextures.Length() == destTextures.Length(), "Mismatched lengths");
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-06-22 12:11:27 +00:00
|
|
|
// Copy to the texture.
|
2011-01-03 01:48:09 +00:00
|
|
|
for (PRUint32 i = 0; i < srcTextures.Length(); ++i) {
|
|
|
|
nsRefPtr<IDirect3DSurface9> srcSurface;
|
|
|
|
nsRefPtr<IDirect3DSurface9> dstSurface;
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
destTextures[i]->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
|
|
|
|
srcTextures[i]->GetSurfaceLevel(0, getter_AddRefs(srcSurface));
|
2010-08-11 00:36:05 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
|
|
|
const nsIntRect *iterRect;
|
|
|
|
while ((iterRect = iter.Next())) {
|
|
|
|
RECT rect;
|
2011-06-22 12:11:27 +00:00
|
|
|
rect.left = iterRect->x - bounds.x;
|
|
|
|
rect.top = iterRect->y - bounds.y;
|
|
|
|
rect.right = iterRect->XMost() - bounds.x;
|
|
|
|
rect.bottom = iterRect->YMost() - bounds.y;
|
2011-02-19 03:51:10 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
POINT point;
|
2011-06-22 12:11:27 +00:00
|
|
|
point.x = iterRect->x - visibleRect.x;
|
|
|
|
point.y = iterRect->y - visibleRect.y;
|
2011-01-03 01:48:09 +00:00
|
|
|
device()->UpdateSurface(srcSurface, &rect, dstSurface, &point);
|
|
|
|
}
|
2010-08-11 00:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-03 01:48:09 +00:00
|
|
|
ThebesLayerD3D9::CreateNewTextures(const gfxIntSize &aSize,
|
|
|
|
SurfaceMode aMode)
|
2010-08-11 00:36:05 +00:00
|
|
|
{
|
2011-01-03 01:48:09 +00:00
|
|
|
if (aSize.width == 0 || aSize.height == 0) {
|
2010-08-11 00:36:05 +00:00
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
2011-02-16 22:32:13 +00:00
|
|
|
|
2010-08-11 00:36:05 +00:00
|
|
|
mTexture = nsnull;
|
2011-01-03 01:48:09 +00:00
|
|
|
mTextureOnWhite = nsnull;
|
2011-06-22 12:11:27 +00:00
|
|
|
device()->CreateTexture(aSize.width, aSize.height, 1,
|
2011-01-04 01:37:10 +00:00
|
|
|
D3DUSAGE_RENDERTARGET,
|
|
|
|
aMode != SURFACE_SINGLE_CHANNEL_ALPHA ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8,
|
|
|
|
D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
|
|
|
|
if (aMode == SURFACE_COMPONENT_ALPHA) {
|
2011-06-22 12:11:27 +00:00
|
|
|
device()->CreateTexture(aSize.width, aSize.height, 1,
|
2011-01-03 01:48:09 +00:00
|
|
|
D3DUSAGE_RENDERTARGET,
|
2011-01-04 01:37:10 +00:00
|
|
|
D3DFMT_X8R8G8B8,
|
|
|
|
D3DPOOL_DEFAULT, getter_AddRefs(mTextureOnWhite), NULL);
|
2010-08-11 00:36:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-04 13:15:05 +00:00
|
|
|
ShadowThebesLayerD3D9::ShadowThebesLayerD3D9(LayerManagerD3D9 *aManager)
|
|
|
|
: ShadowThebesLayer(aManager, nsnull)
|
|
|
|
, LayerD3D9(aManager)
|
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerD3D9*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowThebesLayerD3D9::~ShadowThebesLayerD3D9()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::SetFrontBuffer(const OptionalThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aValidRegion)
|
|
|
|
{
|
|
|
|
if (!mBuffer) {
|
|
|
|
mBuffer = new ShadowBufferD3D9(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(OptionalThebesBuffer::Tnull_t == aNewFront.type(),
|
|
|
|
"Only one system-memory buffer expected");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::Swap(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aUpdatedRegion,
|
|
|
|
ThebesBuffer* aNewBack,
|
|
|
|
nsIntRegion* aNewBackValidRegion,
|
|
|
|
OptionalThebesBuffer* aReadOnlyFront,
|
|
|
|
nsIntRegion* aFrontUpdatedRegion)
|
|
|
|
{
|
|
|
|
if (mBuffer) {
|
|
|
|
nsRefPtr<gfxASurface> surf = ShadowLayerForwarder::OpenDescriptor(aNewFront.buffer());
|
|
|
|
mBuffer->Upload(surf, GetVisibleRegion().GetBounds());
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewBack = aNewFront;
|
|
|
|
*aNewBackValidRegion = mValidRegion;
|
|
|
|
*aReadOnlyFront = null_t();
|
|
|
|
aFrontUpdatedRegion->SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::DestroyFrontBuffer()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::Disconnect()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ShadowThebesLayerD3D9::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
ShadowThebesLayerD3D9::IsEmpty()
|
|
|
|
{
|
|
|
|
return !mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::RenderThebesLayer()
|
|
|
|
{
|
|
|
|
if (!mBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(mBuffer, "should have a buffer here");
|
|
|
|
|
|
|
|
mBuffer->RenderTo(mD3DManager, GetEffectiveVisibleRegion());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::CleanResources()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerD3D9::LayerManagerDestroyed()
|
|
|
|
{
|
|
|
|
mD3DManager->deviceManager()->mLayersWithResources.RemoveElement(this);
|
|
|
|
mD3DManager = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-05-24 15:28:51 +00:00
|
|
|
} /* namespace layers */
|
2010-05-31 23:29:37 +00:00
|
|
|
} /* namespace mozilla */
|