Bug 626602. Part 5: Implement ReadbackLayers for D3D9. r=bas

This commit is contained in:
Robert O'Callahan 2011-02-16 16:43:30 -06:00
Родитель 61ef3671f5
Коммит 1075475ab2
6 изменённых файлов: 131 добавлений и 15 удалений

Просмотреть файл

@ -38,6 +38,8 @@
#include "ContainerLayerD3D9.h" #include "ContainerLayerD3D9.h"
#include "gfxUtils.h" #include "gfxUtils.h"
#include "nsRect.h" #include "nsRect.h"
#include "ThebesLayerD3D9.h"
#include "ReadbackProcessor.h"
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
@ -179,6 +181,9 @@ ContainerLayerD3D9::RenderLayer()
device()->GetScissorRect(&containerClipRect); device()->GetScissorRect(&containerClipRect);
ReadbackProcessor readback;
readback.BuildUpdates(this);
nsIntRect visibleRect = mVisibleRegion.GetBounds(); nsIntRect visibleRect = mVisibleRegion.GetBounds();
PRBool useIntermediate = UseIntermediateSurface(); PRBool useIntermediate = UseIntermediateSurface();
@ -319,7 +324,11 @@ ContainerLayerD3D9::RenderLayer()
device()->SetScissorRect(&r); device()->SetScissorRect(&r);
} }
if (layerToRender->GetLayer()->GetType() == TYPE_THEBES) {
static_cast<ThebesLayerD3D9*>(layerToRender)->RenderThebesLayer(&readback);
} else {
layerToRender->RenderLayer(); layerToRender->RenderLayer();
}
if (clipRect && !useIntermediate) { if (clipRect && !useIntermediate) {
// In this situation we've set a new scissor rect and we will continue // In this situation we've set a new scissor rect and we will continue

Просмотреть файл

@ -42,6 +42,7 @@
#include "ImageLayerD3D9.h" #include "ImageLayerD3D9.h"
#include "ColorLayerD3D9.h" #include "ColorLayerD3D9.h"
#include "CanvasLayerD3D9.h" #include "CanvasLayerD3D9.h"
#include "ReadbackLayerD3D9.h"
#include "gfxWindowsPlatform.h" #include "gfxWindowsPlatform.h"
#include "nsIGfxInfo.h" #include "nsIGfxInfo.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
@ -232,6 +233,13 @@ LayerManagerD3D9::CreateCanvasLayer()
return layer.forget(); return layer.forget();
} }
already_AddRefed<ReadbackLayer>
LayerManagerD3D9::CreateReadbackLayer()
{
nsRefPtr<ReadbackLayer> layer = new ReadbackLayerD3D9(this);
return layer.forget();
}
already_AddRefed<ImageContainer> already_AddRefed<ImageContainer>
LayerManagerD3D9::CreateImageContainer() LayerManagerD3D9::CreateImageContainer()
{ {

Просмотреть файл

@ -149,6 +149,8 @@ public:
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer(); virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer();
virtual already_AddRefed<ImageContainer> CreateImageContainer(); virtual already_AddRefed<ImageContainer> CreateImageContainer();
virtual LayersBackend GetBackendType() { return LAYERS_D3D9; } virtual LayersBackend GetBackendType() { return LAYERS_D3D9; }

Просмотреть файл

@ -0,0 +1,65 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* ***** 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) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Robert O'Callahan <rocallahan@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 ***** */
#ifndef GFX_READBACKLAYERD3D9_H
#define GFX_READBACKLAYERD3D9_H
#include "LayerManagerD3D9.h"
#include "ReadbackLayer.h"
namespace mozilla {
namespace layers {
class THEBES_API ReadbackLayerD3D9 :
public ReadbackLayer,
public LayerD3D9
{
public:
ReadbackLayerD3D9(LayerManagerD3D9 *aManager)
: ReadbackLayer(aManager, NULL),
LayerD3D9(aManager)
{
mImplData = static_cast<LayerD3D9*>(this);
}
virtual Layer* GetLayer() { return this; }
virtual void RenderLayer() {}
};
} /* layers */
} /* mozilla */
#endif /* GFX_READBACKLAYERD3D9_H */

Просмотреть файл

@ -41,6 +41,7 @@
#include "gfxWindowsPlatform.h" #include "gfxWindowsPlatform.h"
#include "gfxTeeSurface.h" #include "gfxTeeSurface.h"
#include "gfxUtils.h" #include "gfxUtils.h"
#include "ReadbackProcessor.h"
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
@ -201,7 +202,7 @@ ThebesLayerD3D9::RenderVisibleRegion()
} }
void void
ThebesLayerD3D9::RenderLayer() ThebesLayerD3D9::RenderThebesLayer(ReadbackProcessor* aReadback)
{ {
if (mVisibleRegion.IsEmpty()) { if (mVisibleRegion.IsEmpty()) {
return; return;
@ -219,22 +220,30 @@ ThebesLayerD3D9::RenderLayer()
return; return;
} }
if (!mValidRegion.IsEqual(mVisibleRegion)) { 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;
drawRegion.Sub(mVisibleRegion, mValidRegion);
drawRegion.Or(drawRegion, readbackRegion);
// NS_ASSERTION(mVisibleRegion.Contains(region), "Bad readback region!");
if (!drawRegion.IsEmpty()) {
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo(); LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
if (!cbInfo.Callback) { if (!cbInfo.Callback) {
NS_ERROR("D3D9 should never need to update ThebesLayers in an empty transaction"); NS_ERROR("D3D9 should never need to update ThebesLayers in an empty transaction");
return; return;
} }
/* We use the bounds of the visible region because we draw the bounds of DrawRegion(drawRegion, mode, readbackUpdates);
* this region when we draw this entire texture. We have to make sure that
* the areas that aren't filled with content get their background drawn.
* This is an issue for opaque surfaces, which otherwise won't get their
* background painted.
*/
nsIntRegion region;
region.Sub(mVisibleRegion, mValidRegion);
DrawRegion(region, mode);
mValidRegion = mVisibleRegion; mValidRegion = mVisibleRegion;
} }
@ -407,7 +416,8 @@ FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
} }
void void
ThebesLayerD3D9::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode) ThebesLayerD3D9::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode,
const nsTArray<ReadbackProcessor::Update>& aReadbackUpdates)
{ {
HRESULT hr; HRESULT hr;
nsIntRect visibleRect = mVisibleRegion.GetBounds(); nsIntRect visibleRect = mVisibleRegion.GetBounds();
@ -480,6 +490,22 @@ ThebesLayerD3D9::DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode)
LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo(); LayerManagerD3D9::CallbackInfo cbInfo = mD3DManager->GetCallbackInfo();
cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData); cbInfo.Callback(this, context, aRegion, nsIntRegion(), cbInfo.CallbackData);
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);
}
}
nsAutoTArray<IDirect3DTexture9*,2> srcTextures; nsAutoTArray<IDirect3DTexture9*,2> srcTextures;
nsAutoTArray<IDirect3DTexture9*,2> destTextures; nsAutoTArray<IDirect3DTexture9*,2> destTextures;
switch (aMode) switch (aMode)

Просмотреть файл

@ -41,10 +41,13 @@
#include "Layers.h" #include "Layers.h"
#include "LayerManagerD3D9.h" #include "LayerManagerD3D9.h"
#include "gfxImageSurface.h" #include "gfxImageSurface.h"
#include "ReadbackProcessor.h"
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
class ReadbackProcessor;
class ThebesLayerD3D9 : public ThebesLayer, class ThebesLayerD3D9 : public ThebesLayer,
public LayerD3D9 public LayerD3D9
{ {
@ -58,10 +61,12 @@ public:
/* LayerD3D9 implementation */ /* LayerD3D9 implementation */
Layer* GetLayer(); Layer* GetLayer();
virtual PRBool IsEmpty(); virtual PRBool IsEmpty();
virtual void RenderLayer(); virtual void RenderLayer() { RenderThebesLayer(nsnull); }
virtual void CleanResources(); virtual void CleanResources();
virtual void LayerManagerDestroyed(); virtual void LayerManagerDestroyed();
void RenderThebesLayer(ReadbackProcessor* aReadback);
private: private:
/* /*
* D3D9 texture * D3D9 texture
@ -96,7 +101,8 @@ private:
void RenderVisibleRegion(); void RenderVisibleRegion();
/* Have a region of our layer drawn */ /* Have a region of our layer drawn */
void DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode); void DrawRegion(nsIntRegion &aRegion, SurfaceMode aMode,
const nsTArray<ReadbackProcessor::Update>& aReadbackUpdates);
/* Create a new texture */ /* Create a new texture */
void CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode); void CreateNewTextures(const gfxIntSize &aSize, SurfaceMode aMode);