Bug 1105834 - Part 3: Add lz4 support. r=jrmuizel

This commit is contained in:
Benoit Girard 2014-12-08 14:42:33 -05:00
Родитель 0deff0ecd6
Коммит 993c64ba00
4 изменённых файлов: 33 добавлений и 7 удалений

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

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

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

@ -335,7 +335,7 @@ TextureHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
aStream << "\n" << pfx.get() << "Surface: "; aStream << "\n" << pfx.get() << "Surface: ";
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface(); RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
if (dSurf) { if (dSurf) {
aStream << gfxUtils::GetAsDataURI(dSurf).get(); aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
} }
} }
#endif #endif

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

@ -43,6 +43,10 @@ using namespace mozilla::gfx;
#include "DeprecatedPremultiplyTables.h" #include "DeprecatedPremultiplyTables.h"
#undef compress
#include "mozilla/Compression.h"
using namespace mozilla::Compression;
extern "C" { extern "C" {
/** /**
@ -1378,6 +1382,32 @@ 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 /* static */ nsCString
gfxUtils::GetAsDataURI(DrawTarget* aDT) gfxUtils::GetAsDataURI(DrawTarget* aDT)
{ {

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

@ -283,6 +283,7 @@ public:
} }
static nsCString GetAsDataURI(SourceSurface* aSourceSurface); static nsCString GetAsDataURI(SourceSurface* aSourceSurface);
static nsCString GetAsDataURI(DrawTarget* aDT); static nsCString GetAsDataURI(DrawTarget* aDT);
static nsCString GetAsLZ4Base64Str(DataSourceSurface* aSourceSurface);
/** /**
* Copy to the clipboard as a PNG encoded Data URL. * Copy to the clipboard as a PNG encoded Data URL.