diff --git a/dom/canvas/WebGLContext.cpp b/dom/canvas/WebGLContext.cpp index d69a43167573..94b5e578b2df 100644 --- a/dom/canvas/WebGLContext.cpp +++ b/dom/canvas/WebGLContext.cpp @@ -661,6 +661,7 @@ CreateOffscreen(GLContext* gl, baseCaps.alpha = options.alpha; baseCaps.antialias = options.antialias; baseCaps.depth = options.depth; + baseCaps.premultAlpha = options.premultipliedAlpha; baseCaps.preserve = options.preserveDrawingBuffer; baseCaps.stencil = options.stencil; @@ -1421,10 +1422,15 @@ WebGLContext::PresentScreenBuffer() if (!mShouldPresent) { return false; } + MOZ_ASSERT(!mBackbufferNeedsClear); gl->MakeCurrent(); - MOZ_ASSERT(!mBackbufferNeedsClear); - if (!gl->PublishFrame()) { + + auto screen = gl->Screen(); + MOZ_ASSERT(screen); + + auto size = screen->Size(); + if (!screen->PublishFrame(size)) { ForceLoseContext(); return false; } diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp index f671d87471ba..e8980906d5a4 100644 --- a/gfx/gl/GLContext.cpp +++ b/gfx/gl/GLContext.cpp @@ -1992,26 +1992,6 @@ GLContext::AssembleOffscreenFBs(const GLuint colorMSRB, } - -bool -GLContext::PublishFrame() -{ - MOZ_ASSERT(mScreen); - - return mScreen->PublishFrame(OffscreenSize()); -} - -SharedSurface* -GLContext::RequestFrame() -{ - MOZ_ASSERT(mScreen); - MOZ_CRASH("Not anymore!"); - - return nullptr; -} - - - void GLContext::ClearSafely() { diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h index bc41796dd42c..3ff89afe3e7b 100644 --- a/gfx/gl/GLContext.h +++ b/gfx/gl/GLContext.h @@ -3529,9 +3529,6 @@ public: return mScreen.get(); } - bool PublishFrame(); - SharedSurface* RequestFrame(); - /* Clear to transparent black, with 0 depth and stencil, * while preserving current ClearColor etc. values. * Useful for resizing offscreen buffers. diff --git a/gfx/gl/GLReadTexImageHelper.cpp b/gfx/gl/GLReadTexImageHelper.cpp index e153b0ba00ef..2b72cc139f75 100644 --- a/gfx/gl/GLReadTexImageHelper.cpp +++ b/gfx/gl/GLReadTexImageHelper.cpp @@ -192,8 +192,11 @@ GetActualReadFormats(GLContext* gl, break; } case LOCAL_GL_BGRA: { - if (destType == LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV) + if (destType == LOCAL_GL_UNSIGNED_BYTE || + destType == LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV) + { fallback = false; + } break; } } diff --git a/gfx/gl/GLScreenBuffer.cpp b/gfx/gl/GLScreenBuffer.cpp index a4f6bba46f9e..ff6fc56a2acc 100755 --- a/gfx/gl/GLScreenBuffer.cpp +++ b/gfx/gl/GLScreenBuffer.cpp @@ -6,6 +6,7 @@ #include "GLScreenBuffer.h" #include +#include "CompositorTypes.h" #include "GLContext.h" #include "GLBlitHelper.h" #include "GLReadTexImageHelper.h" @@ -43,11 +44,19 @@ GLScreenBuffer::Create(GLContext* gl, #ifdef MOZ_WIDGET_GONK /* On B2G, we want a Gralloc factory, and we want one right at the start */ + auto allocator = caps.surfaceAllocator; if (!factory && - caps.surfaceAllocator && + allocator && XRE_GetProcessType() != GeckoProcessType_Default) { - factory = MakeUnique(gl, caps); + layers::TextureFlags flags = TextureFlags::DEALLOCATE_CLIENT | + TextureFlags::NEEDS_Y_FLIP; + if (!caps.premultAlpha) { + flags |= TextureFlags::NON_PREMULTIPLIED; + } + + factory = MakeUnique(gl, caps, flags, + allocator); } #endif #ifdef XP_MACOSX diff --git a/gfx/gl/GLUploadHelpers.cpp b/gfx/gl/GLUploadHelpers.cpp index fc36719b9f25..25b325a5afcf 100644 --- a/gfx/gl/GLUploadHelpers.cpp +++ b/gfx/gl/GLUploadHelpers.cpp @@ -430,6 +430,7 @@ UploadImageDataToTexture(GLContext* gl, MOZ_ASSERT(gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA || gl->GetPreferredARGB32Format() == LOCAL_GL_RGBA); + switch (aFormat) { case SurfaceFormat::B8G8R8A8: if (gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA) { @@ -457,6 +458,32 @@ UploadImageDataToTexture(GLContext* gl, } internalFormat = LOCAL_GL_RGBA; break; + case SurfaceFormat::R8G8B8A8: + if (gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA) { + format = LOCAL_GL_BGRA; + type = LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV; + surfaceFormat = SurfaceFormat::B8G8R8A8; + } else { + format = LOCAL_GL_RGBA; + type = LOCAL_GL_UNSIGNED_BYTE; + surfaceFormat = SurfaceFormat::R8G8B8A8; + } + internalFormat = LOCAL_GL_RGBA; + break; + case SurfaceFormat::R8G8B8X8: + // Treat RGBX surfaces as RGBA except for the surface + // format used. + if (gl->GetPreferredARGB32Format() == LOCAL_GL_BGRA) { + format = LOCAL_GL_BGRA; + type = LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV; + surfaceFormat = SurfaceFormat::B8G8R8X8; + } else { + format = LOCAL_GL_RGBA; + type = LOCAL_GL_UNSIGNED_BYTE; + surfaceFormat = SurfaceFormat::R8G8B8X8; + } + internalFormat = LOCAL_GL_RGBA; + break; case SurfaceFormat::R5G6B5: internalFormat = format = LOCAL_GL_RGB; type = LOCAL_GL_UNSIGNED_SHORT_5_6_5; diff --git a/gfx/gl/SharedSurfaceGralloc.cpp b/gfx/gl/SharedSurfaceGralloc.cpp index 0ece2ab1dcf0..5a48c62ba332 100644 --- a/gfx/gl/SharedSurfaceGralloc.cpp +++ b/gfx/gl/SharedSurfaceGralloc.cpp @@ -37,16 +37,13 @@ using namespace android; SurfaceFactory_Gralloc::SurfaceFactory_Gralloc(GLContext* prodGL, const SurfaceCaps& caps, + layers::TextureFlags flags, layers::ISurfaceAllocator* allocator) : SurfaceFactory(prodGL, SharedSurfaceType::Gralloc, caps) + , mFlags(flags) + , mAllocator(allocator) { - if (caps.surfaceAllocator) { - allocator = caps.surfaceAllocator; - } - - MOZ_ASSERT(allocator); - - mAllocator = allocator; + MOZ_ASSERT(mAllocator); } /*static*/ UniquePtr @@ -54,6 +51,7 @@ SharedSurface_Gralloc::Create(GLContext* prodGL, const GLFormats& formats, const gfx::IntSize& size, bool hasAlpha, + layers::TextureFlags flags, ISurfaceAllocator* allocator) { GLLibraryEGL* egl = &sEGLLibrary; @@ -77,7 +75,7 @@ SharedSurface_Gralloc::Create(GLContext* prodGL, allocator, gfx::ImageFormatToSurfaceFormat(format), gfx::BackendType::NONE, // we don't need to use it with a DrawTarget - layers::TextureFlags::DEFAULT); + flags); if (!grallocTC->AllocateForGLRendering(size)) { return Move(ret); diff --git a/gfx/gl/SharedSurfaceGralloc.h b/gfx/gl/SharedSurfaceGralloc.h index e32b5e3e2420..1b486ba9e5e7 100644 --- a/gfx/gl/SharedSurfaceGralloc.h +++ b/gfx/gl/SharedSurfaceGralloc.h @@ -6,6 +6,7 @@ #ifndef SHARED_SURFACE_GRALLOC_H_ #define SHARED_SURFACE_GRALLOC_H_ +#include "mozilla/layers/CompositorTypes.h" #include "mozilla/layers/LayersSurfaces.h" #include "SharedSurface.h" @@ -27,6 +28,7 @@ public: const GLFormats& formats, const gfx::IntSize& size, bool hasAlpha, + layers::TextureFlags flags, layers::ISurfaceAllocator* allocator); static SharedSurface_Gralloc* Cast(SharedSurface* surf) { @@ -77,20 +79,22 @@ class SurfaceFactory_Gralloc : public SurfaceFactory { protected: + const layers::TextureFlags mFlags; RefPtr mAllocator; public: SurfaceFactory_Gralloc(GLContext* prodGL, const SurfaceCaps& caps, - layers::ISurfaceAllocator* allocator = nullptr); + layers::TextureFlags flags, + layers::ISurfaceAllocator* allocator); virtual UniquePtr CreateShared(const gfx::IntSize& size) MOZ_OVERRIDE { bool hasAlpha = mReadCaps.alpha; UniquePtr ret; if (mAllocator) { - ret = SharedSurface_Gralloc::Create(mGL, mFormats, size, - hasAlpha, mAllocator); + ret = SharedSurface_Gralloc::Create(mGL, mFormats, size, hasAlpha, + mFlags, mAllocator); } return Move(ret); } diff --git a/gfx/gl/SurfaceTypes.cpp b/gfx/gl/SurfaceTypes.cpp index 24db5840da05..dfe37bc490b8 100644 --- a/gfx/gl/SurfaceTypes.cpp +++ b/gfx/gl/SurfaceTypes.cpp @@ -30,6 +30,7 @@ SurfaceCaps::operator=(const SurfaceCaps& other) depth = other.depth; stencil = other.stencil; antialias = other.antialias; + premultAlpha = other.premultAlpha; preserve = other.preserve; surfaceAllocator = other.surfaceAllocator; @@ -46,6 +47,7 @@ SurfaceCaps::Clear() depth = false; stencil = false; antialias = false; + premultAlpha = false; preserve = false; surfaceAllocator = nullptr; } diff --git a/gfx/gl/SurfaceTypes.h b/gfx/gl/SurfaceTypes.h index c1f342eb98be..e6808003d973 100644 --- a/gfx/gl/SurfaceTypes.h +++ b/gfx/gl/SurfaceTypes.h @@ -25,6 +25,7 @@ struct SurfaceCaps MOZ_FINAL bool bpp16; bool depth, stencil; bool antialias; + bool premultAlpha; bool preserve; // The surface allocator that we want to create this diff --git a/gfx/layers/client/CanvasClient.cpp b/gfx/layers/client/CanvasClient.cpp index e0352a9136bb..a0ddef576971 100644 --- a/gfx/layers/client/CanvasClient.cpp +++ b/gfx/layers/client/CanvasClient.cpp @@ -48,7 +48,7 @@ CanvasClient::CreateCanvasClient(CanvasClientType aType, switch (aType) { case CanvasClientTypeShSurf: - return new CanvasClientShSurf(aForwarder, aFlags); + return new CanvasClientSharedSurface(aForwarder, aFlags); case CanvasClientGLContext: aFlags |= TextureFlags::DEALLOCATE_CLIENT; @@ -240,8 +240,8 @@ CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) //////////////////////////////////////////////////////////////////////// -CanvasClientShSurf::CanvasClientShSurf(CompositableForwarder* aLayerForwarder, - TextureFlags aFlags) +CanvasClientSharedSurface::CanvasClientSharedSurface(CompositableForwarder* aLayerForwarder, + TextureFlags aFlags) : CanvasClient(aLayerForwarder, aFlags) { } @@ -250,10 +250,8 @@ CanvasClientShSurf::CanvasClientShSurf(CompositableForwarder* aLayerForwarder, // Accelerated backends static TemporaryRef -TexClientFromShSurf(SharedSurface* surf, TextureFlags baseFlags) +TexClientFromShSurf(SharedSurface* surf, TextureFlags flags) { - TextureFlags flags = baseFlags | TextureFlags::DEALLOCATE_CLIENT; - switch (surf->mType) { case SharedSurfaceType::Basic: return nullptr; @@ -264,7 +262,7 @@ TexClientFromShSurf(SharedSurface* surf, TextureFlags baseFlags) #endif default: - return new ShSurfTexClient(flags, surf); + return new SharedSurfaceTextureClient(flags, surf); } } @@ -284,16 +282,18 @@ class TexClientFactory const gfx::IntSize mSize; const gfx::BackendType mBackendType; const TextureFlags mBaseTexFlags; + const LayersBackend mLayersBackend; public: TexClientFactory(ISurfaceAllocator* allocator, bool hasAlpha, const gfx::IntSize& size, gfx::BackendType backendType, - TextureFlags baseTexFlags) + TextureFlags baseTexFlags, LayersBackend layersBackend) : mAllocator(allocator) , mHasAlpha(hasAlpha) , mSize(size) , mBackendType(backendType) , mBaseTexFlags(baseTexFlags) + , mLayersBackend(layersBackend) { } @@ -312,11 +312,20 @@ public: } TemporaryRef CreateR8G8B8AX8() { - // For now, assume that all RGBA formats are broken. - RefPtr ret = CreateB8G8R8AX8(); + RefPtr ret; - if (ret) { - ret->AddFlags(TextureFlags::RB_SWAPPED); + bool areRGBAFormatsBroken = mLayersBackend == LayersBackend::LAYERS_BASIC; + if (!areRGBAFormatsBroken) { + gfx::SurfaceFormat format = mHasAlpha ? gfx::SurfaceFormat::R8G8B8A8 + : gfx::SurfaceFormat::R8G8B8X8; + ret = Create(format); + } + + if (!ret) { + ret = CreateB8G8R8AX8(); + if (ret) { + ret->AddFlags(TextureFlags::RB_SWAPPED); + } } return ret.forget(); @@ -329,7 +338,7 @@ TexClientFromReadback(SharedSurface* src, ISurfaceAllocator* allocator, { auto backendType = gfx::BackendType::CAIRO; TexClientFactory factory(allocator, src->mHasAlpha, src->mSize, backendType, - baseFlags); + baseFlags, layersBackend); RefPtr texClient; @@ -389,8 +398,10 @@ TexClientFromReadback(SharedSurface* src, ISurfaceAllocator* allocator, // RB_SWAPPED doesn't work with D3D11. (bug 1051010) // RB_SWAPPED doesn't work with Basic. (bug ???????) - bool layersNeedsManualSwap = layersBackend == LayersBackend::LAYERS_D3D11 || - layersBackend == LayersBackend::LAYERS_BASIC; + // RB_SWAPPED doesn't work with D3D9. (bug ???????) + bool layersNeedsManualSwap = layersBackend == LayersBackend::LAYERS_BASIC || + layersBackend == LayersBackend::LAYERS_D3D9 || + layersBackend == LayersBackend::LAYERS_D3D11; if (texClient->HasFlags(TextureFlags::RB_SWAPPED) && layersNeedsManualSwap) { @@ -413,7 +424,7 @@ TexClientFromReadback(SharedSurface* src, ISurfaceAllocator* allocator, //////////////////////////////////////// void -CanvasClientShSurf::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) +CanvasClientSharedSurface::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { aLayer->mGLContext->MakeCurrent(); GLScreenBuffer* screen = aLayer->mGLContext->Screen(); @@ -424,7 +435,6 @@ CanvasClientShSurf::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) } mFront = screen->Front(); - if (!mFront) return; diff --git a/gfx/layers/client/CanvasClient.h b/gfx/layers/client/CanvasClient.h index a0ff6defec2c..bed3c5eea6eb 100644 --- a/gfx/layers/client/CanvasClient.h +++ b/gfx/layers/client/CanvasClient.h @@ -142,7 +142,7 @@ private: // Used for GL canvases where we don't need to do any readback, i.e., with a // GL backend. -class CanvasClientShSurf : public CanvasClient +class CanvasClientSharedSurface : public CanvasClient { private: RefPtr mFront; @@ -151,8 +151,8 @@ private: RefPtr mFrontTex; public: - CanvasClientShSurf(CompositableForwarder* aLayerForwarder, - TextureFlags aFlags); + CanvasClientSharedSurface(CompositableForwarder* aLayerForwarder, + TextureFlags aFlags); virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE { return TextureInfo(CompositableType::IMAGE); @@ -168,7 +168,7 @@ public: ClientCanvasLayer* aLayer) MOZ_OVERRIDE; virtual void OnDetach() MOZ_OVERRIDE { - CanvasClientShSurf::Clear(); + CanvasClientSharedSurface::Clear(); } }; diff --git a/gfx/layers/client/ClientCanvasLayer.cpp b/gfx/layers/client/ClientCanvasLayer.cpp index 2bb7407efa2c..9a0604e312ae 100644 --- a/gfx/layers/client/ClientCanvasLayer.cpp +++ b/gfx/layers/client/ClientCanvasLayer.cpp @@ -77,8 +77,14 @@ ClientCanvasLayer::Initialize(const Data& aData) case mozilla::layers::LayersBackend::LAYERS_OPENGL: { if (mGLContext->GetContextType() == GLContextType::EGL) { #ifdef MOZ_WIDGET_GONK + TextureFlags flags = TextureFlags::DEALLOCATE_CLIENT | + TextureFlags::NEEDS_Y_FLIP; + if (!aData.mIsGLAlphaPremult) { + flags |= TextureFlags::NON_PREMULTIPLIED; + } factory = MakeUnique(mGLContext, caps, + flags, ClientManager()->AsShadowForwarder()); #else bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); diff --git a/gfx/layers/client/ClientCanvasLayer.h b/gfx/layers/client/ClientCanvasLayer.h index 0e8470937b97..0e88a0649c13 100644 --- a/gfx/layers/client/ClientCanvasLayer.h +++ b/gfx/layers/client/ClientCanvasLayer.h @@ -102,7 +102,7 @@ protected: friend class CanvasClient2D; friend class DeprecatedCanvasClientSurfaceStream; friend class CanvasClientSurfaceStream; - friend class CanvasClientShSurf; + friend class CanvasClientSharedSurface; }; } } diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp index cc2e078218be..3bdc1bda9e1f 100644 --- a/gfx/layers/client/TextureClient.cpp +++ b/gfx/layers/client/TextureClient.cpp @@ -861,9 +861,10 @@ StreamTextureClient::IsAllocated() const } //////////////////////////////////////////////////////////////////////// -// ShSurfTexClient +// SharedSurfaceTextureClient -ShSurfTexClient::ShSurfTexClient(TextureFlags aFlags, gl::SharedSurface* surf) +SharedSurfaceTextureClient::SharedSurfaceTextureClient(TextureFlags aFlags, + gl::SharedSurface* surf) : TextureClient(aFlags) , mIsLocked(false) , mSurf(surf) @@ -872,15 +873,15 @@ ShSurfTexClient::ShSurfTexClient(TextureFlags aFlags, gl::SharedSurface* surf) mSurf->Fence(); } -ShSurfTexClient::~ShSurfTexClient() +SharedSurfaceTextureClient::~SharedSurfaceTextureClient() { // the data is owned externally. } bool -ShSurfTexClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) +SharedSurfaceTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) { - aOutDescriptor = ShSurfDescriptor((uintptr_t)mSurf); + aOutDescriptor = SharedSurfaceDescriptor((uintptr_t)mSurf); return true; } diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h index 00cc59841fff..9fca55700816 100644 --- a/gfx/layers/client/TextureClient.h +++ b/gfx/layers/client/TextureClient.h @@ -682,13 +682,13 @@ protected: /** * A TextureClient implementation to share SharedSurfaces. */ -class ShSurfTexClient : public TextureClient +class SharedSurfaceTextureClient : public TextureClient { public: - explicit ShSurfTexClient(TextureFlags aFlags, gl::SharedSurface* surf); + SharedSurfaceTextureClient(TextureFlags aFlags, gl::SharedSurface* surf); protected: - ~ShSurfTexClient(); + ~SharedSurfaceTextureClient(); public: // Boilerplate start diff --git a/gfx/layers/composite/TextureHost.cpp b/gfx/layers/composite/TextureHost.cpp index 2125c92b88d7..b1e6d9cd84d8 100644 --- a/gfx/layers/composite/TextureHost.cpp +++ b/gfx/layers/composite/TextureHost.cpp @@ -203,8 +203,8 @@ TextureHost::Create(const SurfaceDescriptor& aDesc, case SurfaceDescriptor::TSurfaceStreamDescriptor: return new StreamTextureHost(aFlags, aDesc.get_SurfaceStreamDescriptor()); - case SurfaceDescriptor::TShSurfDescriptor: - return new ShSurfTexHost(aFlags, aDesc.get_ShSurfDescriptor()); + case SurfaceDescriptor::TSharedSurfaceDescriptor: + return new SharedSurfaceTextureHost(aFlags, aDesc.get_SharedSurfaceDescriptor()); case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) { @@ -1089,9 +1089,10 @@ ShSurfToTexSource(gl::SharedSurface* abstractSurf, Compositor* compositor) } //////////////////////////////////////////////////////////////////////////////// -// ShSurfTexHost +// SharedSurfaceTextureHost -ShSurfTexHost::ShSurfTexHost(TextureFlags aFlags, const ShSurfDescriptor& aDesc) +SharedSurfaceTextureHost::SharedSurfaceTextureHost(TextureFlags aFlags, + const SharedSurfaceDescriptor& aDesc) : TextureHost(aFlags) , mIsLocked(false) , mSurf((gl::SharedSurface*)aDesc.surf()) @@ -1101,21 +1102,21 @@ ShSurfTexHost::ShSurfTexHost(TextureFlags aFlags, const ShSurfDescriptor& aDesc) } gfx::SurfaceFormat -ShSurfTexHost::GetFormat() const +SharedSurfaceTextureHost::GetFormat() const { MOZ_ASSERT(mTexSource); return mTexSource->GetFormat(); } gfx::IntSize -ShSurfTexHost::GetSize() const +SharedSurfaceTextureHost::GetSize() const { MOZ_ASSERT(mTexSource); return mTexSource->GetSize(); } void -ShSurfTexHost::EnsureTexSource() +SharedSurfaceTextureHost::EnsureTexSource() { MOZ_ASSERT(mIsLocked); diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h index 714e408da8c7..d462e4b13132 100644 --- a/gfx/layers/composite/TextureHost.h +++ b/gfx/layers/composite/TextureHost.h @@ -50,7 +50,7 @@ class CompositableBackendSpecificData; class CompositableParentManager; class SurfaceDescriptor; class SurfaceStreamDescriptor; -class ShSurfDescriptor; +class SharedSurfaceDescriptor; class ISurfaceAllocator; class TextureHostOGL; class TextureSourceOGL; @@ -620,12 +620,12 @@ protected: /** * A TextureHost for SharedSurfaces */ -class ShSurfTexHost : public TextureHost +class SharedSurfaceTextureHost : public TextureHost { public: - ShSurfTexHost(TextureFlags aFlags, const ShSurfDescriptor& aDesc); + SharedSurfaceTextureHost(TextureFlags aFlags, const ShSurfDescriptor& aDesc); - virtual ~ShSurfTexHost() {}; + virtual ~SharedSurfaceTextureHost() {}; virtual void DeallocateDeviceData() MOZ_OVERRIDE {}; @@ -667,7 +667,7 @@ public: virtual gfx::IntSize GetSize() const MOZ_OVERRIDE; #ifdef MOZ_LAYERS_HAVE_LOG - virtual const char* Name() { return "ShSurfTexHost"; } + virtual const char* Name() { return "SharedSurfaceTextureHost"; } #endif protected: diff --git a/gfx/layers/d3d10/CanvasLayerD3D10.cpp b/gfx/layers/d3d10/CanvasLayerD3D10.cpp index 01eabf55a966..47ac7eb04ac2 100644 --- a/gfx/layers/d3d10/CanvasLayerD3D10.cpp +++ b/gfx/layers/d3d10/CanvasLayerD3D10.cpp @@ -118,10 +118,13 @@ CanvasLayerD3D10::UpdateSurface() } if (mGLContext) { - SharedSurface* surf = mGLContext->RequestFrame(); - if (!surf) { + auto screen = mGLContext->Screen(); + MOZ_ASSERT(screen); + + SharedSurface* surf = screen->Front()->Surf(); + if (!surf) return; - } + surf->WaitSync(); switch (surf->mType) { case SharedSurfaceType::EGLSurfaceANGLE: { diff --git a/gfx/layers/d3d9/CanvasLayerD3D9.cpp b/gfx/layers/d3d9/CanvasLayerD3D9.cpp index 6f9cd6aa30d9..0597139eb780 100644 --- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp +++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp @@ -80,9 +80,13 @@ CanvasLayerD3D9::UpdateSurface() RefPtr surface; if (mGLContext) { - SharedSurface* surf = mGLContext->RequestFrame(); + auto screen = mGLContext->Screen(); + MOZ_ASSERT(screen); + + SharedSurface* surf = screen->Front()->Surf(); if (!surf) - return; + return; + surf->WaitSync(); SharedSurface_Basic* shareSurf = SharedSurface_Basic::Cast(surf); surface = shareSurf->GetData(); diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh index e80cdf39f245..a9376d1d9e8c 100644 --- a/gfx/layers/ipc/LayersSurfaces.ipdlh +++ b/gfx/layers/ipc/LayersSurfaces.ipdlh @@ -81,7 +81,7 @@ struct SurfaceStreamDescriptor { bool yflip; }; -struct ShSurfDescriptor { +struct SharedSurfaceDescriptor { uintptr_t surf; }; @@ -113,7 +113,7 @@ union SurfaceDescriptor { SurfaceStreamDescriptor; SurfaceDescriptorMacIOSurface; NewSurfaceDescriptorGralloc; - ShSurfDescriptor; + SharedSurfaceDescriptor; null_t; }; diff --git a/gfx/layers/moz.build b/gfx/layers/moz.build index 72348387a0d7..8e09e7162a26 100644 --- a/gfx/layers/moz.build +++ b/gfx/layers/moz.build @@ -17,6 +17,7 @@ EXPORTS += [ 'client/ClientTiledPaintedLayer.h', 'composite/CompositableHost.h', 'composite/ImageHost.h', + 'CompositorTypes.h', 'CopyableCanvasLayer.h', 'D3D9SurfaceImage.h', 'FrameMetrics.h', @@ -33,6 +34,7 @@ EXPORTS += [ 'LayerScope.h', 'LayersLogging.h', 'LayerSorter.h', + 'LayersTypes.h', 'LayerTreeInvalidation.h', 'opengl/Composer2D.h', 'opengl/OGLShaderProgram.h', @@ -98,7 +100,7 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows': SOURCES += [ 'd3d11/CompositorD3D11.cpp', 'd3d11/ReadbackManagerD3D11.cpp', - ] + ] if CONFIG['MOZ_ENABLE_DIRECT2D1_1']: DEFINES['USE_D2D1_1'] = True diff --git a/gfx/layers/opengl/GrallocTextureClient.cpp b/gfx/layers/opengl/GrallocTextureClient.cpp index da91baa6c870..5623ab8a6a8a 100644 --- a/gfx/layers/opengl/GrallocTextureClient.cpp +++ b/gfx/layers/opengl/GrallocTextureClient.cpp @@ -12,6 +12,7 @@ #include "mozilla/layers/ISurfaceAllocator.h" #include "mozilla/layers/ShadowLayerUtilsGralloc.h" #include "gfx2DGlue.h" +#include "SharedSurfaceGralloc.h" namespace mozilla { namespace layers { @@ -112,7 +113,7 @@ GrallocTextureClientOGL::WaitForBufferOwnership() #if ANDROID_VERSION == 17 fence->waitForever(1000, "GrallocTextureClientOGL::Lock"); // 1000 is what Android uses. It is warning timeout ms. - // This timeous is removed since ANDROID_VERSION 18. + // This timeous is removed since ANDROID_VERSION 18. #else fence->waitForever("GrallocTextureClientOGL::Lock"); #endif @@ -346,6 +347,29 @@ GrallocTextureClientOGL::GetBufferSize() const return 0; } +/*static*/ TemporaryRef +GrallocTextureClientOGL::FromShSurf(gl::SharedSurface* abstractSurf, + TextureFlags flags) +{ + auto surf = gl::SharedSurface_Gralloc::Cast(abstractSurf); + + RefPtr ret = surf->GetTextureClient(); + + TextureFlags mask = TextureFlags::NEEDS_Y_FLIP | + TextureFlags::RB_SWAPPED | + TextureFlags::NON_PREMULTIPLIED; + TextureFlags required = flags & mask; + TextureFlags present = ret->GetFlags() & mask; + + if (present != required) { + printf_stderr("Present flags: 0x%x. Required: 0x%x.\n", + (uint32_t)present, + (uint32_t)required); + MOZ_CRASH("Flag requirement mismatch."); + } + return ret.forget(); +} + } // namesapace layers } // namesapace mozilla diff --git a/gfx/layers/opengl/GrallocTextureClient.h b/gfx/layers/opengl/GrallocTextureClient.h index 040a6214d868..8d5cf2663105 100644 --- a/gfx/layers/opengl/GrallocTextureClient.h +++ b/gfx/layers/opengl/GrallocTextureClient.h @@ -118,6 +118,9 @@ public: CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT, TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const MOZ_OVERRIDE; + static TemporaryRef FromShSurf(gl::SharedSurface* surf, + TextureFlags flags); + protected: /** * Unfortunately, until bug 879681 is fixed we need to use a GrallocBufferActor.