2010-09-30 22:53:49 +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 ***** */
|
|
|
|
|
|
|
|
#include "ThebesLayerD3D10.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#ifdef CAIRO_HAS_D2D_SURFACE
|
|
|
|
#include "gfxD2DSurface.h"
|
|
|
|
#endif
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
#include "gfxTeeSurface.h"
|
|
|
|
#include "gfxUtils.h"
|
2011-02-05 02:30:00 +00:00
|
|
|
#include "ReadbackLayer.h"
|
|
|
|
#include "ReadbackProcessor.h"
|
2011-01-28 05:34:31 +00:00
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
ThebesLayerD3D10::ThebesLayerD3D10(LayerManagerD3D10 *aManager)
|
|
|
|
: ThebesLayer(aManager, NULL)
|
|
|
|
, LayerD3D10(aManager)
|
2011-03-31 21:33:46 +00:00
|
|
|
, mCurrentSurfaceMode(SURFACE_OPAQUE)
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerD3D10*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThebesLayerD3D10::~ThebesLayerD3D10()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
|
void
|
|
|
|
|
2011-01-28 05:34:25 +00:00
|
|
|
ThebesLayerD3D10::InvalidateRegion(const nsIntRegion &aRegion)
|
|
|
|
{
|
|
|
|
mValidRegion.Sub(mValidRegion, aRegion);
|
|
|
|
}
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-28 05:34:25 +00:00
|
|
|
void ThebesLayerD3D10::CopyRegion(ID3D10Texture2D* aSrc, const nsIntPoint &aSrcOffset,
|
|
|
|
ID3D10Texture2D* aDest, const nsIntPoint &aDestOffset,
|
2011-02-08 20:40:34 +00:00
|
|
|
const nsIntRegion &aCopyRegion, nsIntRegion* aValidRegion,
|
|
|
|
float aXRes, float aYRes)
|
2011-01-28 05:34:25 +00:00
|
|
|
{
|
2010-09-30 22:53:49 +00:00
|
|
|
nsIntRegion retainedRegion;
|
2011-01-28 05:34:25 +00:00
|
|
|
nsIntRegionRectIterator iter(aCopyRegion);
|
2010-09-30 22:53:49 +00:00
|
|
|
const nsIntRect *r;
|
|
|
|
while ((r = iter.Next())) {
|
|
|
|
if (r->width * r->height > RETENTION_THRESHOLD) {
|
|
|
|
// Calculate the retained rectangle's position on the old and the new
|
2011-02-08 20:40:34 +00:00
|
|
|
// surface. We need to scale these rectangles since the visible
|
|
|
|
// region is in unscaled units, and the texture size has been scaled.
|
2010-09-30 22:53:49 +00:00
|
|
|
D3D10_BOX box;
|
2011-02-08 20:40:34 +00:00
|
|
|
box.left = UINT(floor((r->x - aSrcOffset.x) * aXRes));
|
|
|
|
box.top = UINT(floor((r->y - aSrcOffset.y) * aYRes));
|
|
|
|
box.right = box.left + UINT(ceil(r->width * aXRes));
|
|
|
|
box.bottom = box.top + UINT(ceil(r->height * aYRes));
|
2011-01-28 05:34:25 +00:00
|
|
|
box.back = 1;
|
2010-09-30 22:53:49 +00:00
|
|
|
box.front = 0;
|
|
|
|
|
2011-01-28 05:34:25 +00:00
|
|
|
device()->CopySubresourceRegion(aDest, 0,
|
2011-02-08 20:40:34 +00:00
|
|
|
UINT(floor((r->x - aDestOffset.x) * aXRes)),
|
|
|
|
UINT(floor((r->y - aDestOffset.y) * aYRes)),
|
2010-09-30 22:53:49 +00:00
|
|
|
0,
|
2011-01-28 05:34:25 +00:00
|
|
|
aSrc, 0,
|
2010-09-30 22:53:49 +00:00
|
|
|
&box);
|
|
|
|
|
2010-12-02 18:44:18 +00:00
|
|
|
retainedRegion.Or(retainedRegion, *r);
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Areas which were valid and were retained are still valid
|
2011-01-28 05:34:25 +00:00
|
|
|
aValidRegion->And(*aValidRegion, retainedRegion);
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-08 09:06:15 +00:00
|
|
|
ThebesLayerD3D10::RenderLayer()
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
if (!mTexture) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-11-08 09:06:15 +00:00
|
|
|
SetEffectTransformAndOpacity();
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
ID3D10EffectTechnique *technique;
|
2011-03-31 21:33:46 +00:00
|
|
|
switch (mCurrentSurfaceMode) {
|
|
|
|
case SURFACE_COMPONENT_ALPHA:
|
2011-01-28 05:34:31 +00:00
|
|
|
technique = effect()->GetTechniqueByName("RenderComponentAlphaLayer");
|
2011-03-31 21:33:46 +00:00
|
|
|
break;
|
|
|
|
case SURFACE_OPAQUE:
|
2010-09-30 22:53:49 +00:00
|
|
|
technique = effect()->GetTechniqueByName("RenderRGBLayerPremul");
|
2011-03-31 21:33:46 +00:00
|
|
|
break;
|
|
|
|
case SURFACE_SINGLE_CHANNEL_ALPHA:
|
2010-09-30 22:53:49 +00:00
|
|
|
technique = effect()->GetTechniqueByName("RenderRGBALayerPremul");
|
2011-03-31 21:33:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_ERROR("Unknown mode");
|
|
|
|
return;
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRegionRectIterator iter(mVisibleRegion);
|
|
|
|
|
|
|
|
const nsIntRect *iterRect;
|
|
|
|
if (mSRView) {
|
|
|
|
effect()->GetVariableByName("tRGB")->AsShaderResource()->SetResource(mSRView);
|
|
|
|
}
|
2011-01-28 05:34:31 +00:00
|
|
|
if (mSRViewOnWhite) {
|
|
|
|
effect()->GetVariableByName("tRGBWhite")->AsShaderResource()->SetResource(mSRViewOnWhite);
|
|
|
|
}
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
while ((iterRect = iter.Next())) {
|
|
|
|
effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
|
|
|
(float)iterRect->x,
|
|
|
|
(float)iterRect->y,
|
|
|
|
(float)iterRect->width,
|
|
|
|
(float)iterRect->height)
|
|
|
|
);
|
|
|
|
|
|
|
|
effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
|
|
|
|
ShaderConstantRectD3D10(
|
2011-03-31 21:33:46 +00:00
|
|
|
(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)
|
2010-09-30 22:53:49 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
technique->GetPassByIndex(0)->Apply(0);
|
|
|
|
device()->Draw(4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set back to default.
|
|
|
|
effect()->GetVariableByName("vTextureCoords")->AsVector()->
|
|
|
|
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-02-05 02:30:00 +00:00
|
|
|
ThebesLayerD3D10::Validate(ReadbackProcessor *aReadback)
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
if (mVisibleRegion.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
nsIntRect newTextureRect = mVisibleRegion.GetBounds();
|
|
|
|
|
2011-01-28 05:34:31 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mCurrentSurfaceMode = mode;
|
2011-01-28 05:34:31 +00:00
|
|
|
|
|
|
|
VerifyContentType(mode);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-02-08 20:40:34 +00:00
|
|
|
float xres, yres;
|
|
|
|
GetDesiredResolutions(xres, yres);
|
|
|
|
|
|
|
|
// If our resolution changed, we need new sized textures, delete the old ones.
|
|
|
|
if (ResolutionChanged(xres, yres)) {
|
|
|
|
mTexture = nsnull;
|
|
|
|
mTextureOnWhite = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-02-05 02:30:00 +00:00
|
|
|
nsTArray<ReadbackProcessor::Update> readbackUpdates;
|
|
|
|
nsIntRegion readbackRegion;
|
|
|
|
if (aReadback && UsedForReadback()) {
|
|
|
|
aReadback->GetThebesLayerUpdates(this, &readbackUpdates, &readbackRegion);
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:34:25 +00:00
|
|
|
if (mTexture) {
|
2011-04-19 03:07:23 +00:00
|
|
|
if (!mTextureRect.IsEqualInterior(newTextureRect)) {
|
2011-01-28 05:34:25 +00:00
|
|
|
nsRefPtr<ID3D10Texture2D> oldTexture = mTexture;
|
2011-01-28 05:34:31 +00:00
|
|
|
mTexture = nsnull;
|
|
|
|
nsRefPtr<ID3D10Texture2D> oldTextureOnWhite = mTextureOnWhite;
|
|
|
|
mTextureOnWhite = nsnull;
|
2011-01-28 05:34:25 +00:00
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
nsIntRegion retainRegion = mTextureRect;
|
2011-01-28 05:34:25 +00:00
|
|
|
// Old visible region will become the region that is covered by both the
|
|
|
|
// old and the new visible region.
|
|
|
|
retainRegion.And(retainRegion, mVisibleRegion);
|
|
|
|
// No point in retaining parts which were not valid.
|
|
|
|
retainRegion.And(retainRegion, mValidRegion);
|
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
CreateNewTextures(gfxIntSize(newTextureRect.width, newTextureRect.height), mode);
|
|
|
|
|
2011-01-28 05:34:25 +00:00
|
|
|
nsIntRect largeRect = retainRegion.GetLargestRectangle();
|
|
|
|
|
2011-02-08 20:40:34 +00:00
|
|
|
// If we had no hardware texture before, have no retained area larger than
|
|
|
|
// the retention threshold or the requested resolution has changed,
|
|
|
|
// we're not retaining and are done here. 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.
|
2011-01-28 05:34:25 +00:00
|
|
|
if (!oldTexture || !mTexture ||
|
2011-02-08 20:40:34 +00:00
|
|
|
largeRect.width * largeRect.height < RETENTION_THRESHOLD ||
|
|
|
|
ResolutionChanged(xres, yres)) {
|
2011-01-28 05:34:25 +00:00
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
} else {
|
2011-03-31 21:33:46 +00:00
|
|
|
CopyRegion(oldTexture, mTextureRect.TopLeft(),
|
|
|
|
mTexture, newTextureRect.TopLeft(),
|
2011-02-08 20:40:34 +00:00
|
|
|
retainRegion, &mValidRegion,
|
|
|
|
xres, yres);
|
2011-01-28 05:34:31 +00:00
|
|
|
if (oldTextureOnWhite) {
|
2011-03-31 21:33:46 +00:00
|
|
|
CopyRegion(oldTextureOnWhite, mTextureRect.TopLeft(),
|
|
|
|
mTextureOnWhite, newTextureRect.TopLeft(),
|
2011-02-08 20:40:34 +00:00
|
|
|
retainRegion, &mValidRegion,
|
|
|
|
xres, yres);
|
2011-01-28 05:34:31 +00:00
|
|
|
}
|
2011-01-28 05:34:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-31 21:33:46 +00:00
|
|
|
mTextureRect = newTextureRect;
|
2011-01-28 05:34:25 +00:00
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (!mTexture || (mode == SURFACE_COMPONENT_ALPHA && !mTextureOnWhite)) {
|
2011-03-31 21:33:46 +00:00
|
|
|
CreateNewTextures(gfxIntSize(newTextureRect.width, newTextureRect.height), mode);
|
2010-09-30 22:53:49 +00:00
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
nsIntRegion drawRegion;
|
|
|
|
drawRegion.Sub(neededRegion, mValidRegion);
|
|
|
|
|
|
|
|
if (!drawRegion.IsEmpty()) {
|
2011-01-19 08:27:54 +00:00
|
|
|
LayerManagerD3D10::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
|
|
|
|
if (!cbInfo.Callback) {
|
|
|
|
NS_ERROR("D3D10 should never need to update ThebesLayers in an empty transaction");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
DrawRegion(drawRegion, mode);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-02-05 02:30:00 +00:00
|
|
|
if (readbackUpdates.Length() > 0) {
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
|
2011-03-31 21:33:46 +00:00
|
|
|
newTextureRect.width, newTextureRect.height,
|
2011-02-05 02:30:00 +00:00
|
|
|
1, 1, 0, D3D10_USAGE_STAGING,
|
|
|
|
D3D10_CPU_ACCESS_READ);
|
|
|
|
|
|
|
|
nsRefPtr<ID3D10Texture2D> readbackTexture;
|
|
|
|
device()->CreateTexture2D(&desc, NULL, getter_AddRefs(readbackTexture));
|
|
|
|
device()->CopyResource(readbackTexture, mTexture);
|
|
|
|
|
|
|
|
for (int i = 0; i < readbackUpdates.Length(); i++) {
|
|
|
|
mD3DManager->readbackManager()->PostTask(readbackTexture,
|
|
|
|
&readbackUpdates[i],
|
2011-03-31 21:33:46 +00:00
|
|
|
gfxPoint(newTextureRect.x, newTextureRect.y));
|
2011-02-05 02:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-31 21:33:46 +00:00
|
|
|
mValidRegion = neededRegion;
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerD3D10::LayerManagerDestroyed()
|
|
|
|
{
|
|
|
|
mD3DManager = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ThebesLayerD3D10::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-28 05:34:31 +00:00
|
|
|
ThebesLayerD3D10::VerifyContentType(SurfaceMode aMode)
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
if (mD2DSurface) {
|
2011-01-28 05:34:31 +00:00
|
|
|
gfxASurface::gfxContentType type = aMode != SURFACE_SINGLE_CHANNEL_ALPHA ?
|
2010-09-30 22:53:49 +00:00
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA;
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (type != mD2DSurface->GetContentType()) {
|
2010-09-30 22:53:49 +00:00
|
|
|
mD2DSurface = new gfxD2DSurface(mTexture, type);
|
|
|
|
|
|
|
|
if (!mD2DSurface || mD2DSurface->CairoStatus()) {
|
|
|
|
NS_WARNING("Failed to create surface for ThebesLayerD3D10.");
|
|
|
|
mD2DSurface = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
2011-01-28 05:34:31 +00:00
|
|
|
|
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aMode != SURFACE_COMPONENT_ALPHA && mTextureOnWhite) {
|
|
|
|
// If we've transitioned away from component alpha, we can delete those resources.
|
|
|
|
mD2DSurfaceOnWhite = nsnull;
|
|
|
|
mSRViewOnWhite = nsnull;
|
|
|
|
mTextureOnWhite = nsnull;
|
2010-09-30 22:53:49 +00:00
|
|
|
mValidRegion.SetEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
static void
|
|
|
|
FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
|
2011-02-08 20:40:34 +00:00
|
|
|
const nsIntPoint& aOffset, const gfxRGBA& aColor,
|
|
|
|
float aXRes, float aYRes)
|
2011-01-28 05:34:31 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(aSurface);
|
2011-02-08 20:40:34 +00:00
|
|
|
ctx->Scale(aXRes, aYRes);
|
2011-01-28 05:34:31 +00:00
|
|
|
ctx->Translate(-gfxPoint(aOffset.x, aOffset.y));
|
|
|
|
gfxUtils::PathFromRegion(ctx, aRegion);
|
|
|
|
ctx->SetColor(aColor);
|
|
|
|
ctx->Fill();
|
|
|
|
}
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
void
|
2011-02-08 20:40:34 +00:00
|
|
|
ThebesLayerD3D10::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode)
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
|
|
|
|
|
|
|
if (!mD2DSurface) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-08 20:40:34 +00:00
|
|
|
float xres, yres;
|
|
|
|
GetDesiredResolutions(xres, yres);
|
|
|
|
aRegion.ExtendForScaling(xres, yres);
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
nsRefPtr<gfxASurface> destinationSurface;
|
|
|
|
|
|
|
|
if (aMode == SURFACE_COMPONENT_ALPHA) {
|
2011-02-08 20:40:34 +00:00
|
|
|
FillSurface(mD2DSurface, aRegion, visibleRect.TopLeft(), gfxRGBA(0.0, 0.0, 0.0, 1.0), xres, yres);
|
|
|
|
FillSurface(mD2DSurfaceOnWhite, aRegion, visibleRect.TopLeft(), gfxRGBA(1.0, 1.0, 1.0, 1.0), xres, yres);
|
2011-01-28 05:34:31 +00:00
|
|
|
gfxASurface* surfaces[2] = { mD2DSurface.get(), mD2DSurfaceOnWhite.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);
|
|
|
|
} else {
|
|
|
|
destinationSurface = mD2DSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxContext> context = new gfxContext(destinationSurface);
|
2011-02-08 20:40:34 +00:00
|
|
|
// Draw content scaled at our current resolution.
|
|
|
|
context->Scale(xres, yres);
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
|
|
|
context->Translate(gfxPoint(-visibleRect.x, -visibleRect.y));
|
|
|
|
context->NewPath();
|
|
|
|
const nsIntRect *iterRect;
|
|
|
|
while ((iterRect = iter.Next())) {
|
|
|
|
context->Rectangle(gfxRect(iterRect->x, iterRect->y, iterRect->width, iterRect->height));
|
|
|
|
}
|
|
|
|
context->Clip();
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (aMode == SURFACE_SINGLE_CHANNEL_ALPHA) {
|
2010-09-30 22:53:49 +00:00
|
|
|
context->SetOperator(gfxContext::OPERATOR_CLEAR);
|
|
|
|
context->Paint();
|
|
|
|
context->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
}
|
|
|
|
|
2011-01-16 02:30:05 +00:00
|
|
|
mD2DSurface->SetSubpixelAntialiasingEnabled(!(mContentFlags & CONTENT_COMPONENT_ALPHA));
|
|
|
|
|
2010-09-30 22:53:49 +00:00
|
|
|
LayerManagerD3D10::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
|
|
|
|
cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-01-28 05:34:31 +00:00
|
|
|
ThebesLayerD3D10::CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode)
|
2010-09-30 22:53:49 +00:00
|
|
|
{
|
|
|
|
if (aSize.width == 0 || aSize.height == 0) {
|
|
|
|
// Nothing to do.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-08 20:40:34 +00:00
|
|
|
// Scale the requested size (in unscaled units) to the actual
|
|
|
|
// texture size we require.
|
|
|
|
gfxIntSize scaledSize;
|
|
|
|
float xres, yres;
|
|
|
|
GetDesiredResolutions(xres, yres);
|
|
|
|
scaledSize.width = PRInt32(ceil(aSize.width * xres));
|
|
|
|
scaledSize.height = PRInt32(ceil(aSize.height * yres));
|
|
|
|
|
|
|
|
CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, scaledSize.width, scaledSize.height, 1, 1);
|
2010-09-30 22:53:49 +00:00
|
|
|
desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
|
|
|
|
desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
|
2011-01-28 05:34:31 +00:00
|
|
|
HRESULT hr;
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (!mTexture) {
|
|
|
|
hr = device()->CreateTexture2D(&desc, NULL, getter_AddRefs(mTexture));
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create new texture for ThebesLayerD3D10!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = device()->CreateShaderResourceView(mTexture, NULL, getter_AddRefs(mSRView));
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10.");
|
|
|
|
}
|
|
|
|
|
|
|
|
mD2DSurface = new gfxD2DSurface(mTexture, aMode != SURFACE_SINGLE_CHANNEL_ALPHA ?
|
|
|
|
gfxASurface::CONTENT_COLOR : gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
|
|
|
|
if (!mD2DSurface || mD2DSurface->CairoStatus()) {
|
|
|
|
NS_WARNING("Failed to create surface for ThebesLayerD3D10.");
|
|
|
|
mD2DSurface = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
2010-09-30 22:53:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (aMode == SURFACE_COMPONENT_ALPHA && !mTextureOnWhite) {
|
|
|
|
hr = device()->CreateTexture2D(&desc, NULL, getter_AddRefs(mTextureOnWhite));
|
2010-09-30 22:53:49 +00:00
|
|
|
|
2011-01-28 05:34:31 +00:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create new texture for ThebesLayerD3D10!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = device()->CreateShaderResourceView(mTextureOnWhite, NULL, getter_AddRefs(mSRViewOnWhite));
|
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to create shader resource view for ThebesLayerD3D10.");
|
|
|
|
}
|
|
|
|
|
|
|
|
mD2DSurfaceOnWhite = new gfxD2DSurface(mTextureOnWhite, gfxASurface::CONTENT_COLOR);
|
|
|
|
|
|
|
|
if (!mD2DSurfaceOnWhite || mD2DSurfaceOnWhite->CairoStatus()) {
|
|
|
|
NS_WARNING("Failed to create surface for ThebesLayerD3D10.");
|
|
|
|
mD2DSurfaceOnWhite = nsnull;
|
|
|
|
return;
|
|
|
|
}
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
2011-02-08 20:40:34 +00:00
|
|
|
|
|
|
|
mXResolution = xres;
|
|
|
|
mYResolution = yres;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerD3D10::GetDesiredResolutions(float& aXRes, float& aYRes)
|
|
|
|
{
|
|
|
|
const gfx3DMatrix& transform = GetLayer()->GetEffectiveTransform();
|
|
|
|
gfxMatrix transform2d;
|
|
|
|
if (transform.Is2D(&transform2d)) {
|
|
|
|
gfxSize scale = transform2d.ScaleFactors(PR_TRUE);
|
|
|
|
//Scale factors are normalized to a power of 2 to reduce the number of resolution changes
|
|
|
|
aXRes = gfxUtils::ClampToScaleFactor(scale.width);
|
|
|
|
aYRes = gfxUtils::ClampToScaleFactor(scale.height);
|
|
|
|
} else {
|
|
|
|
aXRes = 1.0;
|
|
|
|
aYRes = 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ThebesLayerD3D10::ResolutionChanged(float aXRes, float aYRes)
|
|
|
|
{
|
|
|
|
return aXRes != mXResolution ||
|
|
|
|
aYRes != mYResolution;
|
2010-09-30 22:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace layers */
|
|
|
|
} /* namespace mozilla */
|