Last active
January 31, 2019 14:34
-
-
Save fluffyemily/f399e589d6081aa3021c1aa5cfe4a2d6 to your computer and use it in GitHub Desktop.
Code to get a snapshot from a surface in Gecko.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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