mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-27 02:43:07 +00:00
Bug 1105834 - Part 2: Add layers.dump-texture feature. r=mstange
This commit is contained in:
parent
700fbb43f7
commit
a8501f4185
@ -327,17 +327,9 @@ print_stderr(std::stringstream& aStr)
|
||||
// we usually use std::stringstream to build up giant multi-line gobs
|
||||
// of output. So to avoid the truncation we find the newlines and
|
||||
// print the lines individually.
|
||||
char line[1024];
|
||||
while (!aStr.eof()) {
|
||||
aStr.getline(line, sizeof(line));
|
||||
if (!aStr.eof() || strlen(line) > 0) {
|
||||
printf_stderr("%s\n", line);
|
||||
}
|
||||
if (aStr.fail()) {
|
||||
// line was too long, skip to next newline
|
||||
aStr.clear();
|
||||
aStr.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
||||
}
|
||||
std::string line;
|
||||
while (std::getline(aStr, line)) {
|
||||
printf_stderr("%s\n", line.c_str());
|
||||
}
|
||||
#else
|
||||
printf_stderr("%s", aStr.str().c_str());
|
||||
|
@ -223,8 +223,7 @@ CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aText
|
||||
dSurf->GetSize(),
|
||||
dSurf->Stride(),
|
||||
dSurf->GetFormat());
|
||||
// TODO stream surface
|
||||
gfxUtils::DumpAsDataURI(dt, stderr);
|
||||
aStream << gfxUtils::GetAsDataURI(dt).get();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "SharedSurfaceEGL.h"
|
||||
#include "SharedSurfaceGL.h"
|
||||
#include "../opengl/CompositorOGL.h"
|
||||
#include "gfxUtils.h"
|
||||
|
||||
#ifdef MOZ_ENABLE_D3D10_LAYER
|
||||
#include "../d3d11/CompositorD3D11.h"
|
||||
@ -326,6 +327,18 @@ TextureHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
Unlock();
|
||||
}
|
||||
AppendToString(aStream, mFlags, " [flags=", "]");
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxPrefs::LayersDumpTexture()) {
|
||||
nsAutoCString pfx(aPrefix);
|
||||
pfx += " ";
|
||||
|
||||
aStream << "\n" << pfx.get() << "Surface: ";
|
||||
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
|
||||
if (dSurf) {
|
||||
aStream << gfxUtils::GetAsDataURI(dSurf).get();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TextureSource::TextureSource()
|
||||
|
@ -606,6 +606,14 @@ TiledContentHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
||||
aStream << aPrefix;
|
||||
aStream << nsPrintfCString("TiledContentHost (0x%p)", this).get();
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxPrefs::LayersDumpTexture()) {
|
||||
nsAutoCString pfx(aPrefix);
|
||||
pfx += " ";
|
||||
|
||||
Dump(aStream, pfx.get(), false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
@ -614,24 +622,37 @@ TiledContentHost::Dump(std::stringstream& aStream,
|
||||
const char* aPrefix,
|
||||
bool aDumpHtml)
|
||||
{
|
||||
TiledLayerBufferComposite::Iterator it = mTiledBuffer.TilesBegin();
|
||||
TiledLayerBufferComposite::Iterator stop = mTiledBuffer.TilesEnd();
|
||||
if (aDumpHtml) {
|
||||
aStream << "<ul>";
|
||||
}
|
||||
for (;it != stop; ++it) {
|
||||
aStream << aPrefix;
|
||||
aStream << (aDumpHtml ? "<li> <a href=" : "Tile ");
|
||||
if (it->IsPlaceholderTile()) {
|
||||
aStream << "empty tile";
|
||||
} else {
|
||||
DumpTextureHost(aStream, it->mTextureHost);
|
||||
DumpTextureHost(aStream, it->mTextureHostOnWhite);
|
||||
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;
|
||||
}
|
||||
aStream << (aDumpHtml ? " >Tile</a></li>" : " ");
|
||||
}
|
||||
if (aDumpHtml) {
|
||||
aStream << "</ul>";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include "gfx2DGlue.h"
|
||||
#include <ui/GraphicBuffer.h>
|
||||
#include "GrallocImages.h" // for GrallocImage
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/gfx/DataSurfaceHelpers.h"
|
||||
#include "mozilla/layers/GrallocTextureHost.h"
|
||||
#include "mozilla/layers/SharedBufferManagerParent.h"
|
||||
#include "EGLImageHelpers.h"
|
||||
@ -385,29 +387,45 @@ GrallocTextureHostOGL::GetRenderState()
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
GrallocTextureHostOGL::GetAsSurface() {
|
||||
return mTilingTextureSource ? mTilingTextureSource->GetAsSurface()
|
||||
: nullptr;
|
||||
if (mTilingTextureSource) {
|
||||
return mTilingTextureSource->GetAsSurface();
|
||||
} else {
|
||||
android::GraphicBuffer* graphicBuffer = GetGraphicBufferFromDesc(mGrallocHandle).get();
|
||||
uint8_t* grallocData;
|
||||
int32_t rv = graphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
|
||||
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
|
||||
gfx::Factory::CreateWrappingDataSourceSurface(grallocData,
|
||||
graphicBuffer->getStride() * android::bytesPerPixel(graphicBuffer->getPixelFormat()),
|
||||
GetSize(), GetFormat());
|
||||
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
|
||||
|
||||
graphicBuffer->unlock();
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
}
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
GrallocTextureSourceOGL::GetAsSurface() {
|
||||
if (!IsValid() || !gl()->MakeCurrent()) {
|
||||
if (!IsValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
GLuint tex = GetGLTexture();
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl()->fBindTexture(GetTextureTarget(), tex);
|
||||
if (!mEGLImage) {
|
||||
mEGLImage = EGLImageCreateFromNativeBuffer(gl(), mGraphicBuffer->getNativeBuffer());
|
||||
uint8_t* grallocData;
|
||||
int32_t rv = mGraphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
|
||||
if (rv) {
|
||||
return nullptr;
|
||||
}
|
||||
BindEGLImage();
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> surf =
|
||||
IsValid() ? ReadBackSurface(gl(), tex, false, GetFormat())
|
||||
: nullptr;
|
||||
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
|
||||
gfx::Factory::CreateWrappingDataSourceSurface(grallocData,
|
||||
mGraphicBuffer->getStride() * android::bytesPerPixel(mGraphicBuffer->getPixelFormat()),
|
||||
GetSize(), GetFormat());
|
||||
|
||||
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
|
||||
|
||||
mGraphicBuffer->unlock();
|
||||
|
||||
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
return surf.forget();
|
||||
}
|
||||
|
||||
|
@ -270,6 +270,7 @@ private:
|
||||
DECL_GFX_PREF(Live, "layers.flash-borders", FlashLayerBorders, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.draw-layer-info", DrawLayerInfo, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.dump", LayersDump, bool, false);
|
||||
DECL_GFX_PREF(Live, "layers.dump-texture", LayersDumpTexture, bool, false);
|
||||
|
||||
// 0 is "no change" for contrast, positive values increase it, negative values
|
||||
// decrease it until we hit mid gray at -1 contrast, after that it gets weird.
|
||||
|
@ -1110,14 +1110,15 @@ gfxUtils::GetColorForFrameNumber(uint64_t aFrameNumber)
|
||||
return colors[aFrameNumber % sNumFrameColors];
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
const nsACString& aMimeType,
|
||||
const nsAString& aOutputOptions,
|
||||
BinaryOrData aBinaryOrData,
|
||||
FILE* aFile)
|
||||
static nsresult
|
||||
EncodeSourceSurfaceInternal(SourceSurface* aSurface,
|
||||
const nsACString& aMimeType,
|
||||
const nsAString& aOutputOptions,
|
||||
gfxUtils::BinaryOrData aBinaryOrData,
|
||||
FILE* aFile,
|
||||
nsCString* aStrOut)
|
||||
{
|
||||
MOZ_ASSERT(aBinaryOrData == eDataURIEncode || aFile,
|
||||
MOZ_ASSERT(aBinaryOrData == gfxUtils::eDataURIEncode || aFile || aStrOut,
|
||||
"Copying binary encoding to clipboard not currently supported");
|
||||
|
||||
const IntSize size = aSurface->GetSize();
|
||||
@ -1130,8 +1131,8 @@ gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
if (aSurface->GetFormat() != SurfaceFormat::B8G8R8A8) {
|
||||
// FIXME bug 995807 (B8G8R8X8), bug 831898 (R5G6B5)
|
||||
dataSurface =
|
||||
CopySurfaceToDataSourceSurfaceWithFormat(aSurface,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat(aSurface,
|
||||
SurfaceFormat::B8G8R8A8);
|
||||
} else {
|
||||
dataSurface = aSurface->GetDataSurface();
|
||||
}
|
||||
@ -1214,7 +1215,7 @@ gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(!imgData.empty(), NS_ERROR_FAILURE);
|
||||
|
||||
if (aBinaryOrData == eBinaryEncode) {
|
||||
if (aBinaryOrData == gfxUtils::eBinaryEncode) {
|
||||
if (aFile) {
|
||||
fwrite(imgData.begin(), 1, imgSize, aFile);
|
||||
}
|
||||
@ -1247,6 +1248,8 @@ gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
}
|
||||
#endif
|
||||
fprintf(aFile, "%s", string.BeginReading());
|
||||
} else if (aStrOut) {
|
||||
*aStrOut = string;
|
||||
} else {
|
||||
nsCOMPtr<nsIClipboardHelper> clipboard(do_GetService("@mozilla.org/widget/clipboardhelper;1", &rv));
|
||||
if (clipboard) {
|
||||
@ -1256,6 +1259,27 @@ gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsCString
|
||||
EncodeSourceSurfaceAsPNGURI(SourceSurface* aSurface)
|
||||
{
|
||||
nsCString string;
|
||||
EncodeSourceSurfaceInternal(aSurface, NS_LITERAL_CSTRING("image/png"),
|
||||
EmptyString(), gfxUtils::eDataURIEncode,
|
||||
nullptr, &string);
|
||||
return string;
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
|
||||
const nsACString& aMimeType,
|
||||
const nsAString& aOutputOptions,
|
||||
BinaryOrData aBinaryOrData,
|
||||
FILE* aFile)
|
||||
{
|
||||
return EncodeSourceSurfaceInternal(aSurface, aMimeType, aOutputOptions,
|
||||
aBinaryOrData, aFile, nullptr);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
gfxUtils::WriteAsPNG(SourceSurface* aSurface, const nsAString& aFile)
|
||||
{
|
||||
@ -1337,6 +1361,12 @@ gfxUtils::DumpAsDataURI(SourceSurface* aSurface, FILE* aFile)
|
||||
EmptyString(), eDataURIEncode, aFile);
|
||||
}
|
||||
|
||||
/* static */ nsCString
|
||||
gfxUtils::GetAsDataURI(SourceSurface* aSurface)
|
||||
{
|
||||
return EncodeSourceSurfaceAsPNGURI(aSurface);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
gfxUtils::DumpAsDataURI(DrawTarget* aDT, FILE* aFile)
|
||||
{
|
||||
@ -1348,6 +1378,18 @@ gfxUtils::DumpAsDataURI(DrawTarget* aDT, FILE* aFile)
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ nsCString
|
||||
gfxUtils::GetAsDataURI(DrawTarget* aDT)
|
||||
{
|
||||
RefPtr<SourceSurface> surface = aDT->Snapshot();
|
||||
if (surface) {
|
||||
return EncodeSourceSurfaceAsPNGURI(surface);
|
||||
} else {
|
||||
NS_WARNING("Failed to get surface!");
|
||||
return nsCString("");
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
gfxUtils::CopyAsDataURI(SourceSurface* aSurface)
|
||||
{
|
||||
|
@ -281,6 +281,8 @@ public:
|
||||
static inline void DumpAsDataURI(DrawTarget* aDT) {
|
||||
DumpAsDataURI(aDT, stdout);
|
||||
}
|
||||
static nsCString GetAsDataURI(SourceSurface* aSourceSurface);
|
||||
static nsCString GetAsDataURI(DrawTarget* aDT);
|
||||
|
||||
/**
|
||||
* Copy to the clipboard as a PNG encoded Data URL.
|
||||
|
@ -3890,6 +3890,10 @@ pref("layers.acceleration.force-enabled", false);
|
||||
pref("layers.acceleration.draw-fps", false);
|
||||
|
||||
pref("layers.dump", false);
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
// If we're dumping layers, also dump the texture data
|
||||
pref("layers.dump-texture", false);
|
||||
#endif
|
||||
pref("layers.draw-borders", false);
|
||||
pref("layers.draw-tile-borders", false);
|
||||
pref("layers.draw-bigimage-borders", false);
|
||||
|
Loading…
Reference in New Issue
Block a user