Skip to content

Instantly share code, notes, and snippets.

@fluffyemily
Last active January 31, 2019 14:34
Show Gist options
  • Select an option

  • Save fluffyemily/f399e589d6081aa3021c1aa5cfe4a2d6 to your computer and use it in GitHub Desktop.

Select an option

Save fluffyemily/f399e589d6081aa3021c1aa5cfe4a2d6 to your computer and use it in GitHub Desktop.
Code to get a snapshot from a surface in Gecko.
void RecvScreenPixels(Shmem&& aMem, const ScreenIntSize& aSize) {
MOZ_ASSERT(AndroidBridge::IsJavaUiThread());
const IntSize size(aSize.width, aSize.height);
RefPtr<DataSourceSurface> image = gfx::CreateDataSourceSurfaceFromData(
size,
SurfaceFormat::B8G8R8A8,
aMem.get<uint8_t>(),
StrideForFormatAndWidth(SurfaceFormat::B8G8R8A8, aSize.width));
RefPtr<DrawTarget> drawTarget = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
size, SurfaceFormat::B8G8R8A8);
Matrix mat = Matrix();
if (!mat.Invert()) {
NS_WARNING("Could not invert transform");
} else {
drawTarget->SetTransform(mat);
}
gfx::Rect drawRect(0, 0, aSize.width, aSize.height);
drawTarget->DrawSurface(image, drawRect, drawRect);
RefPtr<SourceSurface> snapshot = drawTarget->Snapshot();
RefPtr<DataSourceSurface> data = snapshot->GetDataSurface();
DataSourceSurface::ScopedMap* smap =
new DataSourceSurface::ScopedMap(data, DataSourceSurface::READ);
unit_8 *ret = smap->GetData();
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment