зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1105834 - Part 3: Add lz4 support. r=jrmuizel
This commit is contained in:
Родитель
0deff0ecd6
Коммит
993c64ba00
|
@ -218,12 +218,7 @@ CompositableHost::DumpTextureHost(std::stringstream& aStream, TextureHost* aText
|
|||
if (!dSurf) {
|
||||
return;
|
||||
}
|
||||
gfxPlatform *platform = gfxPlatform::GetPlatform();
|
||||
RefPtr<gfx::DrawTarget> dt = platform->CreateDrawTargetForData(dSurf->GetData(),
|
||||
dSurf->GetSize(),
|
||||
dSurf->Stride(),
|
||||
dSurf->GetFormat());
|
||||
aStream << gfxUtils::GetAsDataURI(dt).get();
|
||||
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@ TextureHost::PrintInfo(std::stringstream& aStream, const char* aPrefix)
|
|||
aStream << "\n" << pfx.get() << "Surface: ";
|
||||
RefPtr<gfx::DataSourceSurface> dSurf = GetAsSurface();
|
||||
if (dSurf) {
|
||||
aStream << gfxUtils::GetAsDataURI(dSurf).get();
|
||||
aStream << gfxUtils::GetAsLZ4Base64Str(dSurf).get();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -43,6 +43,10 @@ using namespace mozilla::gfx;
|
|||
|
||||
#include "DeprecatedPremultiplyTables.h"
|
||||
|
||||
#undef compress
|
||||
#include "mozilla/Compression.h"
|
||||
|
||||
using namespace mozilla::Compression;
|
||||
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
|
||||
gfxUtils::GetAsDataURI(DrawTarget* aDT)
|
||||
{
|
||||
|
|
|
@ -283,6 +283,7 @@ public:
|
|||
}
|
||||
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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче