Backed out 3 changesets (bug 1105834) for non-unified bustage

Backed out changeset 33592fd41f1f (bug 1105834)
Backed out changeset c3e505887e9f (bug 1105834)
Backed out changeset 6aad17f431d1 (bug 1105834)
This commit is contained in:
Wes Kocher 2014-12-08 17:15:46 -08:00
parent 280a38ff20
commit 99f09b4b90
13 changed files with 156 additions and 308 deletions

View File

@ -9,41 +9,11 @@
#include "DataSurfaceHelpers.h"
#include "Logging.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/PodOperations.h"
#include "Tools.h"
namespace mozilla {
namespace gfx {
uint8_t*
DataAtOffset(DataSourceSurface* aSurface, IntPoint aPoint)
{
if (!SurfaceContainsPoint(aSurface, aPoint)) {
MOZ_CRASH("sample position needs to be inside surface!");
}
MOZ_ASSERT(Factory::CheckSurfaceSize(aSurface->GetSize()),
"surface size overflows - this should have been prevented when the surface was created");
uint8_t* data = aSurface->GetData() + aPoint.y * aSurface->Stride() +
aPoint.x * BytesPerPixel(aSurface->GetFormat());
if (data < aSurface->GetData()) {
MOZ_CRASH("out-of-range data access");
}
return data;
}
// This check is safe against integer overflow.
bool
SurfaceContainsPoint(SourceSurface* aSurface, const IntPoint& aPoint)
{
IntSize size = aSurface->GetSize();
return aPoint.x >= 0 && aPoint.x < size.width &&
aPoint.y >= 0 && aPoint.y < size.height;
}
void
ConvertBGRXToBGRA(uint8_t* aData, const IntSize &aSize, int32_t aStride)
{
@ -226,57 +196,5 @@ BufferSizeFromStrideAndHeight(int32_t aStride,
return requiredBytes.value();
}
/**
* aSrcRect: Rect relative to the aSrc surface
* aDestPoint: Point inside aDest surface
*/
void
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
IntRect aSrcRect, IntPoint aDestPoint)
{
if (aSrcRect.Overflows() ||
IntRect(aDestPoint, aSrcRect.Size()).Overflows()) {
MOZ_CRASH("we should never be getting invalid rects at this point");
}
MOZ_ASSERT(aSrc->GetFormat() == aDest->GetFormat(), "different surface formats");
MOZ_ASSERT(IntRect(IntPoint(), aSrc->GetSize()).Contains(aSrcRect), "source rect too big for source surface");
MOZ_ASSERT(IntRect(IntPoint(), aDest->GetSize()).Contains(aSrcRect - aSrcRect.TopLeft() + aDestPoint), "dest surface too small");
if (aSrcRect.IsEmpty()) {
return;
}
uint8_t* sourceData = DataAtOffset(aSrc, aSrcRect.TopLeft());
uint32_t sourceStride = aSrc->Stride();
uint8_t* destData = DataAtOffset(aDest, aDestPoint);
uint32_t destStride = aDest->Stride();
if (BytesPerPixel(aSrc->GetFormat()) == 4) {
for (int32_t y = 0; y < aSrcRect.height; y++) {
PodCopy((int32_t*)destData, (int32_t*)sourceData, aSrcRect.width);
sourceData += sourceStride;
destData += destStride;
}
} else if (BytesPerPixel(aSrc->GetFormat()) == 1) {
for (int32_t y = 0; y < aSrcRect.height; y++) {
PodCopy(destData, sourceData, aSrcRect.width);
sourceData += sourceStride;
destData += destStride;
}
}
}
TemporaryRef<DataSourceSurface>
CreateDataSourceSurfaceByCloning(DataSourceSurface* aSource)
{
RefPtr<DataSourceSurface> copy =
Factory::CreateDataSourceSurface(aSource->GetSize(), aSource->GetFormat());
if (copy) {
CopyRect(aSource, copy, IntRect(IntPoint(), aSource->GetSize()), IntPoint());
}
return copy.forget();
}
}
}

View File

@ -70,36 +70,6 @@ BufferSizeFromStrideAndHeight(int32_t aStride,
int32_t aHeight,
int32_t aExtraBytes = 0);
/**
* Copy aSrcRect from aSrc to aDest starting at aDestPoint.
*/
void
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
IntRect aSrcRect, IntPoint aDestPoint);
/**
* Create a non aliasing copy of aSource. This creates a new DataSourceSurface
* using the factory and copies the bits.
*
* @return a dss allocated by Factory that contains a copy a aSource.
*/
TemporaryRef<DataSourceSurface>
CreateDataSourceSurfaceByCloning(DataSourceSurface* aSource);
/**
* Return the byte at aPoint.
*/
uint8_t*
DataAtOffset(DataSourceSurface* aSurface, IntPoint aPoint);
/**
* Check if aPoint is contained by the surface.
*
* @returns true if and only if aPoint is inside the surface.
*/
bool
SurfaceContainsPoint(SourceSurface* aSurface, const IntPoint& aPoint);
}
}

View File

@ -180,16 +180,101 @@ NS_lround(double x)
return x >= 0.0 ? int32_t(x + 0.5) : int32_t(x - 0.5);
}
// This check is safe against integer overflow.
static bool
SurfaceContainsPoint(SourceSurface* aSurface, const IntPoint& aPoint)
{
IntSize size = aSurface->GetSize();
return aPoint.x >= 0 && aPoint.x < size.width &&
aPoint.y >= 0 && aPoint.y < size.height;
}
static uint8_t*
DataAtOffset(DataSourceSurface* aSurface, IntPoint aPoint)
{
if (!SurfaceContainsPoint(aSurface, aPoint)) {
MOZ_CRASH("sample position needs to be inside surface!");
}
MOZ_ASSERT(Factory::CheckSurfaceSize(aSurface->GetSize()),
"surface size overflows - this should have been prevented when the surface was created");
uint8_t* data = aSurface->GetData() + aPoint.y * aSurface->Stride() +
aPoint.x * BytesPerPixel(aSurface->GetFormat());
if (data < aSurface->GetData()) {
MOZ_CRASH("out-of-range data access");
}
return data;
}
static bool
IntRectOverflows(const IntRect& aRect)
{
CheckedInt<int32_t> xMost = aRect.x;
xMost += aRect.width;
CheckedInt<int32_t> yMost = aRect.y;
yMost += aRect.height;
return !xMost.isValid() || !yMost.isValid();
}
/**
* aSrcRect: Rect relative to the aSrc surface
* aDestPoint: Point inside aDest surface
*/
static void
CopyRect(DataSourceSurface* aSrc, DataSourceSurface* aDest,
IntRect aSrcRect, IntPoint aDestPoint)
{
if (IntRectOverflows(aSrcRect) ||
IntRectOverflows(IntRect(aDestPoint, aSrcRect.Size()))) {
MOZ_CRASH("we should never be getting invalid rects at this point");
}
MOZ_ASSERT(aSrc->GetFormat() == aDest->GetFormat(), "different surface formats");
MOZ_ASSERT(IntRect(IntPoint(), aSrc->GetSize()).Contains(aSrcRect), "source rect too big for source surface");
MOZ_ASSERT(IntRect(IntPoint(), aDest->GetSize()).Contains(aSrcRect - aSrcRect.TopLeft() + aDestPoint), "dest surface too small");
if (aSrcRect.IsEmpty()) {
return;
}
uint8_t* sourceData = DataAtOffset(aSrc, aSrcRect.TopLeft());
uint32_t sourceStride = aSrc->Stride();
uint8_t* destData = DataAtOffset(aDest, aDestPoint);
uint32_t destStride = aDest->Stride();
if (BytesPerPixel(aSrc->GetFormat()) == 4) {
for (int32_t y = 0; y < aSrcRect.height; y++) {
PodCopy((int32_t*)destData, (int32_t*)sourceData, aSrcRect.width);
sourceData += sourceStride;
destData += destStride;
}
} else if (BytesPerPixel(aSrc->GetFormat()) == 1) {
for (int32_t y = 0; y < aSrcRect.height; y++) {
PodCopy(destData, sourceData, aSrcRect.width);
sourceData += sourceStride;
destData += destStride;
}
}
}
TemporaryRef<DataSourceSurface>
CloneAligned(DataSourceSurface* aSource)
{
return CreateDataSourceSurfaceByCloning(aSource);
RefPtr<DataSourceSurface> copy =
Factory::CreateDataSourceSurface(aSource->GetSize(), aSource->GetFormat());
if (copy) {
CopyRect(aSource, copy, IntRect(IntPoint(), aSource->GetSize()), IntPoint());
}
return copy.forget();
}
static void
FillRectWithPixel(DataSourceSurface *aSurface, const IntRect &aFillRect, IntPoint aPixelPos)
{
MOZ_ASSERT(!aFillRect.Overflows());
MOZ_ASSERT(!IntRectOverflows(aFillRect));
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aFillRect),
"aFillRect needs to be completely inside the surface");
MOZ_ASSERT(SurfaceContainsPoint(aSurface, aPixelPos),
@ -222,8 +307,8 @@ FillRectWithVerticallyRepeatingHorizontalStrip(DataSourceSurface *aSurface,
const IntRect &aFillRect,
const IntRect &aSampleRect)
{
MOZ_ASSERT(!aFillRect.Overflows());
MOZ_ASSERT(!aSampleRect.Overflows());
MOZ_ASSERT(!IntRectOverflows(aFillRect));
MOZ_ASSERT(!IntRectOverflows(aSampleRect));
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aFillRect),
"aFillRect needs to be completely inside the surface");
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aSampleRect),
@ -250,8 +335,8 @@ FillRectWithHorizontallyRepeatingVerticalStrip(DataSourceSurface *aSurface,
const IntRect &aFillRect,
const IntRect &aSampleRect)
{
MOZ_ASSERT(!aFillRect.Overflows());
MOZ_ASSERT(!aSampleRect.Overflows());
MOZ_ASSERT(!IntRectOverflows(aFillRect));
MOZ_ASSERT(!IntRectOverflows(aSampleRect));
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aFillRect),
"aFillRect needs to be completely inside the surface");
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aSampleRect),
@ -282,7 +367,7 @@ FillRectWithHorizontallyRepeatingVerticalStrip(DataSourceSurface *aSurface,
static void
DuplicateEdges(DataSourceSurface* aSurface, const IntRect &aFromRect)
{
MOZ_ASSERT(!aFromRect.Overflows());
MOZ_ASSERT(!IntRectOverflows(aFromRect));
MOZ_ASSERT(IntRect(IntPoint(), aSurface->GetSize()).Contains(aFromRect),
"aFromRect needs to be completely inside the surface");
@ -390,7 +475,7 @@ GetDataSurfaceInRect(SourceSurface *aSurface,
{
MOZ_ASSERT(aSurface ? aSurfaceRect.Size() == aSurface->GetSize() : aSurfaceRect.IsEmpty());
if (aSurfaceRect.Overflows() || aDestRect.Overflows()) {
if (IntRectOverflows(aSurfaceRect) || IntRectOverflows(aDestRect)) {
// We can't rely on the intersection calculations below to make sense when
// XMost() or YMost() overflow. Bail out.
return nullptr;
@ -545,7 +630,7 @@ FilterNodeSoftware::Draw(DrawTarget* aDrawTarget,
}
IntRect outputRect = GetOutputRectInRect(renderIntRect);
if (outputRect.Overflows()) {
if (IntRectOverflows(outputRect)) {
#ifdef DEBUG_DUMP_SURFACES
printf("output rect overflowed, not painting anything\n");
printf("</pre>\n");
@ -596,7 +681,7 @@ FilterNodeSoftware::GetOutput(const IntRect &aRect)
{
MOZ_ASSERT(GetOutputRectInRect(aRect).Contains(aRect));
if (aRect.Overflows()) {
if (IntRectOverflows(aRect)) {
return nullptr;
}
@ -626,7 +711,7 @@ FilterNodeSoftware::RequestRect(const IntRect &aRect)
void
FilterNodeSoftware::RequestInputRect(uint32_t aInputEnumIndex, const IntRect &aRect)
{
if (aRect.Overflows()) {
if (IntRectOverflows(aRect)) {
return;
}
@ -659,7 +744,7 @@ FilterNodeSoftware::GetInputDataSourceSurface(uint32_t aInputEnumIndex,
ConvolveMatrixEdgeMode aEdgeMode,
const IntRect *aTransparencyPaddedSourceRect)
{
if (aRect.Overflows()) {
if (IntRectOverflows(aRect)) {
return nullptr;
}
@ -774,7 +859,7 @@ IntRect
FilterNodeSoftware::GetInputRectInRect(uint32_t aInputEnumIndex,
const IntRect &aInRect)
{
if (aInRect.Overflows()) {
if (IntRectOverflows(aInRect)) {
return IntRect();
}

View File

@ -91,14 +91,6 @@ struct IntRectTyped :
IntRectTyped<UnknownUnits> ToUnknownRect() const {
return IntRectTyped<UnknownUnits>(this->x, this->y, this->width, this->height);
}
bool Overflows() const {
CheckedInt<int32_t> xMost = this->x;
xMost += this->width;
CheckedInt<int32_t> yMost = this->y;
yMost += this->height;
return !xMost.isValid() || !yMost.isValid();
}
};
typedef IntRectTyped<UnknownUnits> IntRect;

View File

@ -327,9 +327,17 @@ 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.
std::string line;
while (std::getline(aStr, line)) {
printf_stderr("%s\n", line.c_str());
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');
}
}
#else
printf_stderr("%s", aStr.str().c_str());

View File

@ -218,7 +218,13 @@ CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aText
if (!dSurf) {
return;
}
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
gfxPlatform *platform = gfxPlatform::GetPlatform();
RefPtr<gfx::DrawTarget> dt = platform->CreateDrawTargetForData(dSurf->GetData(),
dSurf->GetSize(),
dSurf->Stride(),
dSurf->GetFormat());
// TODO stream surface
gfxUtils::DumpAsDataURI(dt, stderr);
}
#endif

View File

@ -27,7 +27,6 @@
#include "SharedSurfaceEGL.h"
#include "SharedSurfaceGL.h"
#include "../opengl/CompositorOGL.h"
#include "gfxUtils.h"
#ifdef MOZ_ENABLE_D3D10_LAYER
#include "../d3d11/CompositorD3D11.h"
@ -327,18 +326,6 @@ 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::GetAsLZ4Base64Str(dSurf).get();
}
}
#endif
}
TextureSource::TextureSource()

View File

@ -606,14 +606,6 @@ 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
@ -622,37 +614,24 @@ 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;
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);
}
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;
aStream << (aDumpHtml ? " >Tile</a></li>" : " ");
}
if (aDumpHtml) {
aStream << "</ul>";
}
}
#endif

View File

@ -8,7 +8,6 @@
#include "gfx2DGlue.h"
#include <ui/GraphicBuffer.h>
#include "GrallocImages.h" // for GrallocImage
#include "mozilla/gfx/DataSurfaceHelpers.h"
#include "mozilla/layers/GrallocTextureHost.h"
#include "mozilla/layers/SharedBufferManagerParent.h"
#include "EGLImageHelpers.h"
@ -386,45 +385,29 @@ GrallocTextureHostOGL::GetRenderState()
TemporaryRef<gfx::DataSourceSurface>
GrallocTextureHostOGL::GetAsSurface() {
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 =
Factory::CreateWrappingDataSourceSurface(grallocData,
graphicBuffer->getStride() * android::bytesPerPixel(graphicBuffer->getPixelFormat()),
GetSize(), GetFormat());
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
graphicBuffer->unlock();
return surf.forget();
}
return mTilingTextureSource ? mTilingTextureSource->GetAsSurface()
: nullptr;
}
TemporaryRef<gfx::DataSourceSurface>
GrallocTextureSourceOGL::GetAsSurface() {
if (!IsValid()) {
if (!IsValid() || !gl()->MakeCurrent()) {
return nullptr;
}
uint8_t* grallocData;
int32_t rv = mGraphicBuffer->lock(GRALLOC_USAGE_SW_READ_OFTEN, reinterpret_cast<void**>(&grallocData));
if (rv) {
return nullptr;
GLuint tex = GetGLTexture();
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
gl()->fBindTexture(GetTextureTarget(), tex);
if (!mEGLImage) {
mEGLImage = EGLImageCreateFromNativeBuffer(gl(), mGraphicBuffer->getNativeBuffer());
}
BindEGLImage();
RefPtr<gfx::DataSourceSurface> grallocTempSurf =
Factory::CreateWrappingDataSourceSurface(grallocData,
mGraphicBuffer->getStride() * android::bytesPerPixel(mGraphicBuffer->getPixelFormat()),
GetSize(), GetFormat());
RefPtr<gfx::DataSourceSurface> surf = CreateDataSourceSurfaceByCloning(grallocTempSurf);
mGraphicBuffer->unlock();
RefPtr<gfx::DataSourceSurface> surf =
IsValid() ? ReadBackSurface(gl(), tex, false, GetFormat())
: nullptr;
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
return surf.forget();
}

View File

@ -270,7 +270,6 @@ 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.

View File

@ -43,10 +43,6 @@ using namespace mozilla::gfx;
#include "DeprecatedPremultiplyTables.h"
#undef compress
#include "mozilla/Compression.h"
using namespace mozilla::Compression;
extern "C" {
/**
@ -1114,15 +1110,14 @@ gfxUtils::GetColorForFrameNumber(uint64_t aFrameNumber)
return colors[aFrameNumber % sNumFrameColors];
}
static nsresult
EncodeSourceSurfaceInternal(SourceSurface* aSurface,
const nsACString& aMimeType,
const nsAString& aOutputOptions,
gfxUtils::BinaryOrData aBinaryOrData,
FILE* aFile,
nsCString* aStrOut)
/* static */ nsresult
gfxUtils::EncodeSourceSurface(SourceSurface* aSurface,
const nsACString& aMimeType,
const nsAString& aOutputOptions,
BinaryOrData aBinaryOrData,
FILE* aFile)
{
MOZ_ASSERT(aBinaryOrData == gfxUtils::eDataURIEncode || aFile || aStrOut,
MOZ_ASSERT(aBinaryOrData == eDataURIEncode || aFile,
"Copying binary encoding to clipboard not currently supported");
const IntSize size = aSurface->GetSize();
@ -1135,8 +1130,8 @@ EncodeSourceSurfaceInternal(SourceSurface* aSurface,
if (aSurface->GetFormat() != SurfaceFormat::B8G8R8A8) {
// FIXME bug 995807 (B8G8R8X8), bug 831898 (R5G6B5)
dataSurface =
gfxUtils::CopySurfaceToDataSourceSurfaceWithFormat(aSurface,
SurfaceFormat::B8G8R8A8);
CopySurfaceToDataSourceSurfaceWithFormat(aSurface,
SurfaceFormat::B8G8R8A8);
} else {
dataSurface = aSurface->GetDataSurface();
}
@ -1219,7 +1214,7 @@ EncodeSourceSurfaceInternal(SourceSurface* aSurface,
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(!imgData.empty(), NS_ERROR_FAILURE);
if (aBinaryOrData == gfxUtils::eBinaryEncode) {
if (aBinaryOrData == eBinaryEncode) {
if (aFile) {
fwrite(imgData.begin(), 1, imgSize, aFile);
}
@ -1252,8 +1247,6 @@ EncodeSourceSurfaceInternal(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) {
@ -1263,27 +1256,6 @@ EncodeSourceSurfaceInternal(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)
{
@ -1365,12 +1337,6 @@ 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)
{
@ -1382,44 +1348,6 @@ gfxUtils::DumpAsDataURI(DrawTarget* aDT, FILE* aFile)
}
}
/* static */ nsCString
gfxUtils::GetAsLZ4Base64Str(DataSourceSurface* aSourceSurface)
{
int32_t dataSize = aSourceSurface->GetSize().height * aSourceSurface->Stride();
auto compressedData = MakeUnique<char[]>(LZ4::maxCompressedSize(dataSize));
if (compressedData) {
int nDataSize = LZ4::compress((char*)aSourceSurface->GetData(),
dataSize,
compressedData.get());
if (nDataSize > 0) {
nsCString encodedImg;
nsresult rv = Base64Encode(Substring(compressedData.get(), nDataSize), encodedImg);
if (rv == NS_OK) {
nsCString string("");
string.AppendPrintf("data:image/lz4bgra;base64,%i,%i,%i,",
aSourceSurface->GetSize().width,
aSourceSurface->Stride(),
aSourceSurface->GetSize().height);
string.Append(encodedImg);
return string;
}
}
}
return nsCString("");
}
/* 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)
{

View File

@ -281,9 +281,6 @@ public:
static inline void DumpAsDataURI(DrawTarget* aDT) {
DumpAsDataURI(aDT, stdout);
}
static nsCString GetAsDataURI(SourceSurface* aSourceSurface);
static nsCString GetAsDataURI(DrawTarget* aDT);
static nsCString GetAsLZ4Base64Str(DataSourceSurface* aSourceSurface);
/**
* Copy to the clipboard as a PNG encoded Data URL.

View File

@ -3894,10 +3894,6 @@ 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);