From f7d12ccdaa9c5cfa2f62d69fba1aa94a49391ce5 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 1 May 2013 17:03:27 +1200 Subject: [PATCH] Bug 864287 - Add back code to readback IOSurface plugins when using BasicLayers. r=BenWa --- gfx/gl/GLContextProviderCGL.mm | 25 +++++++++++++++++++++++++ gfx/gl/GLContextProviderEGL.cpp | 7 +++++++ gfx/gl/GLContextProviderGLX.cpp | 7 +++++++ gfx/gl/GLContextProviderImpl.h | 3 +++ gfx/gl/GLContextProviderNull.cpp | 7 +++++++ gfx/gl/GLContextProviderWGL.cpp | 7 +++++++ gfx/layers/SharedTextureImage.h | 5 ++++- 7 files changed, 60 insertions(+), 1 deletion(-) diff --git a/gfx/gl/GLContextProviderCGL.mm b/gfx/gl/GLContextProviderCGL.mm index 8e3a03110f0..ff5b8bcba16 100644 --- a/gfx/gl/GLContextProviderCGL.mm +++ b/gfx/gl/GLContextProviderCGL.mm @@ -464,6 +464,31 @@ GLContextProviderCGL::CreateSharedHandle(GLContext::SharedTextureShareType share return (SharedTextureHandle)surf; } +already_AddRefed +GLContextProviderCGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle) +{ + MacIOSurface* surf = reinterpret_cast(sharedHandle); + surf->Lock(); + size_t bytesPerRow = surf->GetBytesPerRow(); + size_t ioWidth = surf->GetWidth(); + size_t ioHeight = surf->GetHeight(); + + unsigned char* ioData = (unsigned char*)surf->GetBaseAddress(); + + nsRefPtr imgSurface = + new gfxImageSurface(gfxIntSize(ioWidth, ioHeight), gfxASurface::ImageFormatARGB32); + + for (size_t i = 0; i < ioHeight; i++) { + memcpy(imgSurface->Data() + i * imgSurface->Stride(), + ioData + i * bytesPerRow, ioWidth * 4); + } + + surf->Unlock(); + + return imgSurface.forget(); +} + void GLContextProviderCGL::Shutdown() { diff --git a/gfx/gl/GLContextProviderEGL.cpp b/gfx/gl/GLContextProviderEGL.cpp index 20c3049e35f..fd927a5815d 100644 --- a/gfx/gl/GLContextProviderEGL.cpp +++ b/gfx/gl/GLContextProviderEGL.cpp @@ -2019,6 +2019,13 @@ GLContextProviderEGL::CreateSharedHandle(GLContext::SharedTextureShareType share return 0; } +already_AddRefed +GLContextProviderEGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle) +{ + return nullptr; +} + // Don't want a global context on Android as 1) share groups across 2 threads fail on many Tegra drivers (bug 759225) // and 2) some mobile devices have a very strict limit on global number of GL contexts (bug 754257) // and 3) each EGL context eats 750k on B2G (bug 813783) diff --git a/gfx/gl/GLContextProviderGLX.cpp b/gfx/gl/GLContextProviderGLX.cpp index 5eb5fdd9c19..ec36fee990d 100644 --- a/gfx/gl/GLContextProviderGLX.cpp +++ b/gfx/gl/GLContextProviderGLX.cpp @@ -1424,6 +1424,13 @@ GLContextProviderGLX::CreateSharedHandle(GLContext::SharedTextureShareType share return 0; } +already_AddRefed +GLContextProviderGLX::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle) +{ + return nullptr; +} + static nsRefPtr gGlobalContext[GLXLibrary::LIBS_MAX]; // TODO move that out of static initializaion static bool gUseContextSharing = getenv("MOZ_DISABLE_CONTEXT_SHARING_GLX") == 0; diff --git a/gfx/gl/GLContextProviderImpl.h b/gfx/gl/GLContextProviderImpl.h index cef25676d55..74a1af7657e 100644 --- a/gfx/gl/GLContextProviderImpl.h +++ b/gfx/gl/GLContextProviderImpl.h @@ -79,6 +79,9 @@ public: void* buffer, GLContext::SharedTextureBufferType bufferType); + static already_AddRefed GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle); + /** * Free any resources held by this Context Provider. */ diff --git a/gfx/gl/GLContextProviderNull.cpp b/gfx/gl/GLContextProviderNull.cpp index 7183544b156..72aeb23101e 100644 --- a/gfx/gl/GLContextProviderNull.cpp +++ b/gfx/gl/GLContextProviderNull.cpp @@ -30,6 +30,13 @@ GLContextProviderNull::CreateSharedHandle(GLContext::SharedTextureShareType shar return 0; } +already_AddRefed +GLContextProviderNull::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle) +{ + return nullptr; +} + GLContext* GLContextProviderNull::GetGlobalContext(ContextFlags) { diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp index e881b752eb0..9c8958a1e3f 100644 --- a/gfx/gl/GLContextProviderWGL.cpp +++ b/gfx/gl/GLContextProviderWGL.cpp @@ -695,6 +695,13 @@ GLContextProviderWGL::CreateSharedHandle(GLContext::SharedTextureShareType share return 0; } +already_AddRefed +GLContextProviderWGL::GetSharedHandleAsSurface(GLContext::SharedTextureShareType shareType, + SharedTextureHandle sharedHandle) +{ + return nullptr; +} + static nsRefPtr gGlobalContext[WGLLibrary::LIBS_MAX]; GLContext * diff --git a/gfx/layers/SharedTextureImage.h b/gfx/layers/SharedTextureImage.h index 2a42154cfcf..daa2b008f2f 100644 --- a/gfx/layers/SharedTextureImage.h +++ b/gfx/layers/SharedTextureImage.h @@ -8,6 +8,7 @@ #include "ImageContainer.h" #include "GLContext.h" +#include "GLContextProvider.h" // Split into a separate header from ImageLayers.h due to GLContext.h dependence // Implementation remains in ImageLayers.cpp @@ -30,7 +31,9 @@ public: gfxIntSize GetSize() { return mData.mSize; } - virtual already_AddRefed GetAsSurface() { return NULL; } + virtual already_AddRefed GetAsSurface() { + return gl::GLContextProvider::GetSharedHandleAsSurface(mData.mShareType, mData.mHandle); + } SharedTextureImage() : Image(NULL, SHARED_TEXTURE) {}