Skip to content

Commit

Permalink
Bug 1112476 - Support dumping texture data on the ClientLayerManager.…
Browse files Browse the repository at this point in the history
… r=mstange

--HG--
extra : rebase_source : 5d5cf3372993ca4af78e12236fc64836a56eff4b
  • Loading branch information
bgirard committed Dec 18, 2014
1 parent 2e80a88 commit d74cb4f
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 33 deletions.
34 changes: 34 additions & 0 deletions gfx/layers/TiledLayerBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ class TiledLayerBuffer
Iterator TilesBegin() { return mRetainedTiles.Elements(); }
Iterator TilesEnd() { return mRetainedTiles.Elements() + mRetainedTiles.Length(); }

void Dump(std::stringstream& aStream, const char* aPrefix, bool aDumpHtml);

protected:
// The implementor should call Update() to change
// the new valid region. This implementation will call
Expand Down Expand Up @@ -307,6 +309,38 @@ TiledLayerBuffer<Derived, Tile>::RemoveTile(int x, int y, Tile& aRemovedTile)
return false;
}

template<typename Derived, typename Tile> void
TiledLayerBuffer<Derived, Tile>::Dump(std::stringstream& aStream,
const char* aPrefix,
bool aDumpHtml)
{
nsIntRect visibleRect = GetValidRegion().GetBounds();
gfx::IntSize scaledTileSize = GetScaledTileSize();
for (int32_t x = visibleRect.x; x < visibleRect.x + visibleRect.width;) {
int32_t tileStartX = GetTileStart(x, scaledTileSize.width);
int32_t w = scaledTileSize.width - tileStartX;

for (int32_t y = visibleRect.y; y < visibleRect.y + visibleRect.height;) {
int32_t tileStartY = GetTileStart(y, scaledTileSize.height);
Tile tileTexture =
GetTile(nsIntPoint(RoundDownToTileEdge(x, scaledTileSize.width),
RoundDownToTileEdge(y, scaledTileSize.height)));
int32_t h = scaledTileSize.height - tileStartY;

aStream << "\n" << aPrefix << "Tile (x=" <<
RoundDownToTileEdge(x, scaledTileSize.width) << ", y=" <<
RoundDownToTileEdge(y, scaledTileSize.height) << "): ";
if (tileTexture != AsDerived().GetPlaceholderTile()) {
tileTexture.DumpTexture(aStream);
} else {
aStream << "empty tile";
}
y += h;
}
x += w;
}
}

template<typename Derived, typename Tile> void
TiledLayerBuffer<Derived, Tile>::Update(const nsIntRegion& aNewValidRegion,
const nsIntRegion& aPaintRegion)
Expand Down
11 changes: 11 additions & 0 deletions gfx/layers/client/ClientPaintedLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ ClientLayerManager::CreatePaintedLayerWithHint(PaintedLayerCreationHint aHint)
}
}

void
ClientPaintedLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
PaintedLayer::PrintInfo(aStream, aPrefix);
if (mContentClient) {
aStream << "\n";
nsAutoCString pfx(aPrefix);
pfx += " ";
mContentClient->PrintInfo(aStream, pfx.get());
}
}

}
}
4 changes: 3 additions & 1 deletion gfx/layers/client/ClientPaintedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class ClientPaintedLayer : public PaintedLayer,

protected:
void PaintThebes();


virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;

void DestroyBackBuffer()
{
mContentClient = nullptr;
Expand Down
12 changes: 12 additions & 0 deletions gfx/layers/client/ClientTiledPaintedLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,17 @@ ClientTiledPaintedLayer::RenderLayer()
EndPaint();
}

void
ClientTiledPaintedLayer::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
PaintedLayer::PrintInfo(aStream, aPrefix);
if (mContentClient) {
aStream << "\n";
nsAutoCString pfx(aPrefix);
pfx += " ";
mContentClient->PrintInfo(aStream, pfx.get());
}
}

} // mozilla
} // layers
2 changes: 2 additions & 0 deletions gfx/layers/client/ClientTiledPaintedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class ClientTiledPaintedLayer : public PaintedLayer,
protected:
~ClientTiledPaintedLayer();

virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix) MOZ_OVERRIDE;

public:
// Override name to distinguish it from ClientPaintedLayer in layer dumps
virtual const char* Name() const { return "TiledPaintedLayer"; }
Expand Down
14 changes: 14 additions & 0 deletions gfx/layers/client/CompositableClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mozilla/layers/TextureD3D11.h"
#include "mozilla/layers/TextureD3D9.h"
#endif
#include "gfxUtils.h"

namespace mozilla {
namespace layers {
Expand Down Expand Up @@ -258,5 +259,18 @@ CompositableClient::GetTextureClientRecycler()
return mTextureClientRecycler;
}

void
CompositableClient::DumpTextureClient(std::stringstream& aStream, TextureClient* aTexture)
{
if (!aTexture) {
return;
}
RefPtr<gfx::DataSourceSurface> dSurf = aTexture->GetAsSurface();
if (!dSurf) {
return;
}
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
}

} // namespace layers
} // namespace mozilla
1 change: 1 addition & 0 deletions gfx/layers/client/CompositableClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class CompositableClient

TextureClientRecycleAllocator* GetTextureClientRecycler();

static void DumpTextureClient(std::stringstream& aStream, TextureClient* aTexture);
protected:
CompositableChild* mCompositableChild;
CompositableForwarder* mForwarder;
Expand Down
23 changes: 23 additions & 0 deletions gfx/layers/client/ContentClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ ContentClient::EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates)
OnTransaction();
}

void
ContentClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
aStream << aPrefix;
aStream << nsPrintfCString("ContentClient (0x%p)", this).get();

if (profiler_feature_active("displaylistdump")) {
nsAutoCString pfx(aPrefix);
pfx += " ";

Dump(aStream, pfx.get(), false);
}
}

// We pass a null pointer for the ContentClient Forwarder argument, which means
// this client will not have a ContentHost on the other side.
ContentClientBasic::ContentClientBasic()
Expand Down Expand Up @@ -401,6 +415,15 @@ ContentClientRemoteBuffer::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion)
mFrontAndBackBufferDiffer = true;
}

void
ContentClientRemoteBuffer::Dump(std::stringstream& aStream,
const char* aPrefix,
bool aDumpHtml)
{
// TODO We should combine the OnWhite/OnBlack here an just output a single image.
CompositableClient::DumpTextureClient(aStream, mTextureClient);
}

void
ContentClientDoubleBuffered::DestroyFrontBuffer()
{
Expand Down
9 changes: 9 additions & 0 deletions gfx/layers/client/ContentClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class ContentClient : public CompositableClient
virtual ~ContentClient()
{}

virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);

virtual void Dump(std::stringstream& aStream,
const char* aPrefix="",
bool aDumpHtml=false) {};

virtual void Clear() = 0;
virtual RotatedContentBuffer::PaintState BeginPaintBuffer(PaintedLayer* aLayer,
Expand Down Expand Up @@ -208,6 +213,10 @@ class ContentClientRemoteBuffer : public ContentClientRemote
mTextureClientOnWhite = nullptr;
}

virtual void Dump(std::stringstream& aStream,
const char* aPrefix="",
bool aDumpHtml=false) MOZ_OVERRIDE;

virtual PaintState BeginPaintBuffer(PaintedLayer* aLayer,
uint32_t aFlags) MOZ_OVERRIDE
{
Expand Down
40 changes: 40 additions & 0 deletions gfx/layers/client/TextureClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "mozilla/layers/PTextureChild.h"
#include "SharedSurface.h"
#include "GLContext.h"
#include "mozilla/gfx/DataSurfaceHelpers.h" // for CreateDataSourceSurfaceByCloning
#include "nsPrintfCString.h" // for nsPrintfCString
#include "LayersLogging.h" // for AppendToString
#include "gfxUtils.h" // for gfxUtils::GetAsLZ4Base64Str

#ifdef XP_WIN
#include "mozilla/layers/TextureD3D9.h"
Expand Down Expand Up @@ -572,6 +576,28 @@ TextureClient::ShouldDeallocateInDestructor() const
return !IsSharedWithCompositor() || (GetFlags() & TextureFlags::DEALLOCATE_CLIENT);
}

void
TextureClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
aStream << aPrefix;
aStream << nsPrintfCString("TextureClient (0x%p)", this).get();
AppendToString(aStream, GetSize(), " [size=", "]");
AppendToString(aStream, GetFormat(), " [format=", "]");
AppendToString(aStream, mFlags, " [flags=", "]");

#ifdef MOZ_DUMP_PAINTING
if (gfxPrefs::LayersDumpTexture() || profiler_feature_active("layersdump")) {
nsAutoCString pfx(aPrefix);
pfx += " ";

aStream << "\n" << pfx.get() << "Surface: ";
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
if (dSurf) {
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
}
}
#endif
}
bool
ShmemTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aDescriptor)
{
Expand Down Expand Up @@ -866,6 +892,20 @@ BufferTextureClient::GetLockedData() const
return serializer.GetData();
}

TemporaryRef<gfx::DataSourceSurface>
BufferTextureClient::GetAsSurface()
{
ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
MOZ_ASSERT(serializer.IsValid());

RefPtr<gfx::DataSourceSurface> wrappingSurf =
gfx::Factory::CreateWrappingDataSourceSurface(serializer.GetData(),
serializer.GetStride(),
serializer.GetSize(),
serializer.GetFormat());
return gfx::CreateDataSourceSurfaceByCloning(wrappingSurf);
}

////////////////////////////////////////////////////////////////////////
// SharedSurfaceTextureClient

Expand Down
6 changes: 6 additions & 0 deletions gfx/layers/client/TextureClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class TextureClient
return gfx::SurfaceFormat::UNKNOWN;
}

virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() { return nullptr; }

virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);

/**
* Copies a rectangle from this texture client to a position in aTarget.
* It is assumed that the necessary locks are in place; so this should at
Expand Down Expand Up @@ -584,6 +588,8 @@ class BufferTextureClient : public TextureClient
gfx::IntSize aCbCrSize,
StereoMode aStereoMode) MOZ_OVERRIDE;

virtual TemporaryRef<gfx::DataSourceSurface> GetAsSurface() MOZ_OVERRIDE;

virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE { return mFormat; }

// XXX - Bug 908196 - Make Allocate(uint32_t) and GetBufferSize() protected.
Expand Down
22 changes: 22 additions & 0 deletions gfx/layers/client/TiledContentClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,5 +1598,27 @@ ClientTiledLayerBuffer::ProgressiveUpdate(nsIntRegion& aValidRegion,
return isBufferChanged;
}

void
TiledContentClient::PrintInfo(std::stringstream& aStream, const char* aPrefix)
{
aStream << aPrefix;
aStream << nsPrintfCString("TiledContentClient (0x%p)", this).get();

if (profiler_feature_active("displaylistdump")) {
nsAutoCString pfx(aPrefix);
pfx += " ";

Dump(aStream, pfx.get(), false);
}
}

void
TiledContentClient::Dump(std::stringstream& aStream,
const char* aPrefix,
bool aDumpHtml)
{
mTiledBuffer.Dump(aStream, aPrefix, aDumpHtml);
}

}
}
11 changes: 11 additions & 0 deletions gfx/layers/client/TiledContentClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ struct TileClient
*/
void Flip();

void DumpTexture(std::stringstream& aStream) {
// TODO We should combine the OnWhite/OnBlack here an just output a single image.
CompositableClient::DumpTextureClient(aStream, mFrontBuffer);
}

/**
* Returns an unlocked TextureClient that can be used for writing new
* data to the tile. This may flip the front-buffer to the back-buffer if
Expand Down Expand Up @@ -527,6 +532,12 @@ class TiledContentClient : public CompositableClient
mLowPrecisionTiledBuffer.Release();
}

virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);

virtual void Dump(std::stringstream& aStream,
const char* aPrefix="",
bool aDumpHtml=false);

public:
virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE
{
Expand Down
33 changes: 1 addition & 32 deletions gfx/layers/composite/TiledContentHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,38 +642,7 @@ TiledContentHost::Dump(std::stringstream& aStream,
const char* aPrefix,
bool aDumpHtml)
{
nsIntRect visibleRect = mTiledBuffer.GetValidRegion().GetBounds();
gfx::IntSize scaledTileSize = mTiledBuffer.GetScaledTileSize();
for (int32_t x = visibleRect.x; x < visibleRect.x + visibleRect.width;) {
int32_t tileStartX = mTiledBuffer.GetTileStart(x, scaledTileSize.width);
int32_t w = scaledTileSize.width - tileStartX;
if (x + w > visibleRect.x + visibleRect.width) {
w = visibleRect.x + visibleRect.width - x;
}

for (int32_t y = visibleRect.y; y < visibleRect.y + visibleRect.height;) {
int32_t tileStartY = mTiledBuffer.GetTileStart(y, scaledTileSize.height);
TileHost tileTexture = mTiledBuffer.
GetTile(nsIntPoint(mTiledBuffer.RoundDownToTileEdge(x, scaledTileSize.width),
mTiledBuffer.RoundDownToTileEdge(y, scaledTileSize.height)));
int32_t h = scaledTileSize.height - tileStartY;
if (y + h > visibleRect.y + visibleRect.height) {
h = visibleRect.y + visibleRect.height - y;
}

aStream << "\n" << aPrefix << "Tile (x=" <<
mTiledBuffer.RoundDownToTileEdge(x, scaledTileSize.width) << ", y=" <<
mTiledBuffer.RoundDownToTileEdge(y, scaledTileSize.height) << "): ";
if (tileTexture != mTiledBuffer.GetPlaceholderTile()) {
DumpTextureHost(aStream, tileTexture.mTextureHost);
// TODO We should combine the OnWhite/OnBlack here an just output a single image.
} else {
aStream << "empty tile";
}
y += h;
}
x += w;
}
mTiledBuffer.Dump(aStream, aPrefix, aDumpHtml);
}

} // namespace
Expand Down
5 changes: 5 additions & 0 deletions gfx/layers/composite/TiledContentHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ class TileHost {
}
}

void DumpTexture(std::stringstream& aStream) {
// TODO We should combine the OnWhite/OnBlack here an just output a single image.
CompositableHost::DumpTextureHost(aStream, mTextureHost);
}

RefPtr<gfxSharedReadLock> mSharedLock;
CompositableTextureHostRef mTextureHost;
CompositableTextureHostRef mTextureHostOnWhite;
Expand Down
6 changes: 6 additions & 0 deletions gfx/layers/opengl/MacIOSurfaceTextureClientOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,11 @@ MacIOSurfaceTextureClientOGL::GetSize() const
return gfx::IntSize(mSurface->GetDevicePixelWidth(), mSurface->GetDevicePixelHeight());
}

TemporaryRef<gfx::DataSourceSurface>
MacIOSurfaceTextureClientOGL::GetAsSurface()
{
RefPtr<gfx::SourceSurface> surf = mSurface->GetAsSurface();
return surf->GetDataSurface();
}
}
}
Loading

0 comments on commit d74cb4f

Please sign in to comment.