void CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { GLScreenBuffer* screen = aLayer->mGLContext->Screen(); SurfaceStream* stream = screen->Stream(); bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); bool bufferCreated = false; if (isCrossProcess) { #ifdef MOZ_WIDGET_GONK SharedSurface* surf = stream->SwapConsumer(); if (!surf) { printf_stderr("surf is null post-SwapConsumer!\n"); return; } if (surf->Type() != SharedSurfaceType::Gralloc) { printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!"); MOZ_ASSERT(false); return; } SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf); GrallocTextureClientOGL* grallocTextureClient = static_cast<GrallocTextureClientOGL*>(grallocSurf->GetTextureClient()); // If IPDLActor is null means this TextureClient didn't AddTextureClient yet if (!grallocTextureClient->GetIPDLActor()) { grallocTextureClient->SetTextureFlags(mTextureInfo.mTextureFlags); AddTextureClient(grallocTextureClient); } if (grallocTextureClient->GetIPDLActor()) { GetForwarder()->UseTexture(this, grallocTextureClient); } #else printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!"); MOZ_ASSERT(false); #endif } else { if (!mBuffer) { StreamTextureClientOGL* textureClient = new StreamTextureClientOGL(mTextureInfo.mTextureFlags); textureClient->InitWith(stream); mBuffer = textureClient; bufferCreated = true; } if (bufferCreated && !AddTextureClient(mBuffer)) { mBuffer = nullptr; } if (mBuffer) { GetForwarder()->UseTexture(this, mBuffer); } } aLayer->Painted(); }
void CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { if (!mTextureClient) { mTextureClient = CreateTextureClient(TEXTURE_STREAM_GL); MOZ_ASSERT(mTextureClient, "Failed to create texture client"); } NS_ASSERTION(aLayer->mGLContext, "CanvasClientSurfaceStream should only be used with GL canvases"); // the content type won't be used mTextureClient->EnsureAllocated(aSize, gfxASurface::CONTENT_COLOR); GLScreenBuffer* screen = aLayer->mGLContext->Screen(); SurfaceStream* stream = screen->Stream(); bool isCrossProcess = !(XRE_GetProcessType() == GoannaProcessType_Default); if (isCrossProcess) { // swap staging -> consumer so we can send it to the compositor SharedSurface* surf = stream->SwapConsumer(); if (!surf) { printf_stderr("surf is null post-SwapConsumer!\n"); return; } #ifdef MOZ_WIDGET_GONK if (surf->Type() != SharedSurfaceType::Gralloc) { printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!"); return; } SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf); mTextureClient->SetDescriptor(grallocSurf->GetDescriptor()); #else printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!"); MOZ_ASSERT(false); #endif mNeedsUpdate = true; } else { SurfaceStreamHandle handle = stream->GetShareHandle(); SurfaceDescriptor *desc = mTextureClient->GetDescriptor(); if (desc->type() != SurfaceDescriptor::TSurfaceStreamDescriptor || desc->get_SurfaceStreamDescriptor().handle() != handle) { *desc = SurfaceStreamDescriptor(handle, false); // Ref this so the SurfaceStream doesn't disappear unexpectedly. The // Compositor will need to unref it when finished. aLayer->mGLContext->AddRef(); mNeedsUpdate = true; } } aLayer->Painted(); }
void ClientCanvasLayer::RenderLayer() { PROFILER_LABEL("ClientCanvasLayer", "Paint"); if (!IsDirty()) { return; } if (GetMaskLayer()) { ToClientLayer(GetMaskLayer())->RenderLayer(); } if (!mCanvasClient) { TextureFlags flags = TEXTURE_IMMEDIATE_UPLOAD; if (mNeedsYFlip) { flags |= TEXTURE_NEEDS_Y_FLIP; } bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); //Append TEXTURE_DEALLOCATE_CLIENT flag for streaming buffer under OOPC case if (isCrossProcess && mGLContext) { GLScreenBuffer* screen = mGLContext->Screen(); if (screen && screen->Stream()) { flags |= TEXTURE_DEALLOCATE_CLIENT; } } mCanvasClient = CanvasClient::CreateCanvasClient(GetCanvasClientType(), ClientManager(), flags); if (!mCanvasClient) { return; } if (HasShadow()) { mCanvasClient->Connect(); ClientManager()->Attach(mCanvasClient, this); } } FirePreTransactionCallback(); mCanvasClient->Update(gfx::IntSize(mBounds.width, mBounds.height), this); FireDidTransactionCallback(); ClientManager()->Hold(this); mCanvasClient->Updated(); mCanvasClient->OnTransaction(); }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (!mGLContext) return; GLScreenBuffer* screen = mGLContext->Screen(); SurfaceCaps caps; if (mGLFrontbuffer) { // The screen caps are irrelevant if we're using a separate frontbuffer. caps = mGLFrontbuffer->mHasAlpha ? SurfaceCaps::ForRGBA() : SurfaceCaps::ForRGB(); } else { MOZ_ASSERT(screen); caps = screen->mCaps; } MOZ_ASSERT(caps.alpha == aData.mHasAlpha); auto forwarder = ClientManager()->AsShadowForwarder(); mFlags = TextureFlags::ORIGIN_BOTTOM_LEFT; if (!aData.mIsGLAlphaPremult) { mFlags |= TextureFlags::NON_PREMULTIPLIED; } UniquePtr<SurfaceFactory> factory = GLScreenBuffer::CreateFactory(mGLContext, caps, forwarder, mFlags); if (mGLFrontbuffer) { // We're using a source other than the one in the default screen. // (SkiaGL) mFactory = Move(factory); if (!mFactory) { // Absolutely must have a factory here, so create a basic one mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps, mFlags); } } else { if (factory) screen->Morph(Move(factory)); } }
void CanvasClientWebGL::Update(gfx::IntSize aSize, BasicCanvasLayer* aLayer) { if (!mTextureClient) { mTextureClient = CreateTextureClient(TEXTURE_STREAM_GL); } NS_ASSERTION(aLayer->mGLContext, "CanvasClientWebGL should only be used with GL canvases"); // the content type won't be used mTextureClient->EnsureAllocated(aSize, gfxASurface::CONTENT_COLOR); GLScreenBuffer* screen = aLayer->mGLContext->Screen(); SurfaceStreamHandle handle = screen->Stream()->GetShareHandle(); mTextureClient->SetDescriptor(SurfaceStreamDescriptor(handle, false)); aLayer->Painted(); }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (mGLContext) { GLScreenBuffer* screen = mGLContext->Screen(); SurfaceStreamType streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread, screen->PreserveBuffer()); SurfaceFactory_GL* factory = nullptr; if (!mForceReadback) { if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) { if (mGLContext->GetContextType() == GLContextType::EGL) { bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); if (!isCrossProcess) { // [Basic/OGL Layers, OMTC] WebGL layer init. factory = SurfaceFactory_EGLImage::Create(mGLContext, screen->Caps()); } else { // [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing) #ifdef MOZ_WIDGET_GONK factory = new SurfaceFactory_Gralloc(mGLContext, screen->Caps(), ClientManager()->AsShadowForwarder()); #else // we could do readback here maybe NS_NOTREACHED("isCrossProcess but not on native B2G!"); #endif } } else { // [Basic Layers, OMTC] WebGL layer init. // Well, this *should* work... #ifdef XP_MACOSX factory = new SurfaceFactory_IOSurface(mGLContext, screen->Caps()); #else factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, screen->Caps()); #endif } } } if (factory) { screen->Morph(factory, streamType); } } }
void CanvasLayerOGL::Initialize(const Data& aData) { NS_ASSERTION(mCanvasSurface == nullptr, "BasicCanvasLayer::Initialize called twice!"); if (aData.mGLContext != nullptr && aData.mSurface != nullptr) { NS_WARNING("CanvasLayerOGL can't have both surface and WebGLContext"); return; } mOGLManager->MakeCurrent(); if (aData.mDrawTarget && aData.mDrawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED)) { mDrawTarget = aData.mDrawTarget; mNeedsYFlip = false; mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height); return; } else if (aData.mDrawTarget) { mDrawTarget = aData.mDrawTarget; mCanvasSurface = gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget); mNeedsYFlip = false; } else if (aData.mSurface) { mCanvasSurface = aData.mSurface; mNeedsYFlip = false; #if defined(GL_PROVIDER_GLX) if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) { gfxXlibSurface *xsurf = static_cast<gfxXlibSurface*>(aData.mSurface); mPixmap = xsurf->GetGLXPixmap(); if (mPixmap) { mLayerProgram = ShaderProgramFromContentType(aData.mSurface->GetContentType()); MakeTextureIfNeeded(gl(), mUploadTexture); } } #endif } else if (aData.mGLContext) { mGLContext = aData.mGLContext; NS_ASSERTION(mGLContext->IsOffscreen(), "Canvas GLContext must be offscreen."); mIsGLAlphaPremult = aData.mIsGLAlphaPremult; mNeedsYFlip = true; // [OGL Layers, MTC] WebGL layer init. GLScreenBuffer* screen = mGLContext->Screen(); SurfaceStreamType streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread, screen->PreserveBuffer()); SurfaceFactory_GL* factory = nullptr; if (!mForceReadback) { factory = new SurfaceFactory_GLTexture(mGLContext, gl(), screen->Caps()); } if (factory) { screen->Morph(factory, streamType); } } else { NS_WARNING("CanvasLayerOGL::Initialize called without surface or GL context!"); return; } mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height); // Check the maximum texture size supported by GL. glTexImage2D supports // images of up to 2 + GL_MAX_TEXTURE_SIZE GLint texSize = 0; gl()->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &texSize); MOZ_ASSERT(texSize != 0); if (mBounds.width > (2 + texSize) || mBounds.height > (2 + texSize)) { mDelayedUpdates = true; MakeTextureIfNeeded(gl(), mUploadTexture); // This should only ever occur with 2d canvas, WebGL can't already have a texture // of this size can it? NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget, "Invalid texture size when WebGL surface already exists at that size?"); } }
void DeprecatedCanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { if (!mDeprecatedTextureClient) { mDeprecatedTextureClient = CreateDeprecatedTextureClient(TEXTURE_STREAM_GL, aLayer->GetSurfaceMode() == SurfaceMode::SURFACE_OPAQUE ? gfxContentType::COLOR : gfxContentType::COLOR_ALPHA); MOZ_ASSERT(mDeprecatedTextureClient, "Failed to create texture client"); } NS_ASSERTION(aLayer->mGLContext, "CanvasClientSurfaceStream should only be used with GL canvases"); // the content type won't be used mDeprecatedTextureClient->EnsureAllocated(aSize, gfxContentType::COLOR); GLScreenBuffer* screen = aLayer->mGLContext->Screen(); SurfaceStream* stream = nullptr; if (aLayer->mStream) { stream = aLayer->mStream; stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory); stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height)); } else { stream = screen->Stream(); } bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); if (isCrossProcess) { // swap staging -> consumer so we can send it to the compositor SharedSurface* surf = stream->SwapConsumer(); if (!surf) { printf_stderr("surf is null post-SwapConsumer!\n"); return; } #ifdef MOZ_WIDGET_GONK if (surf->Type() != SharedSurfaceType::Gralloc) { printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!"); return; } SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf); //XXX todo //mDeprecatedTextureClient->SetDescriptor(grallocSurf->GetDescriptor()); #else printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!"); MOZ_ASSERT(false); #endif } else { SurfaceStreamHandle handle = stream->GetShareHandle(); mDeprecatedTextureClient->SetDescriptor(SurfaceStreamDescriptor(handle, false)); // Bug 894405 // // Ref this so the SurfaceStream doesn't disappear unexpectedly. The // Compositor will need to unref it when finished. aLayer->mGLContext->AddRef(); } aLayer->Painted(); }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (!mGLContext) return; GLScreenBuffer* screen = mGLContext->Screen(); SurfaceCaps caps; if (mGLFrontbuffer) { // The screen caps are irrelevant if we're using a separate frontbuffer. caps = mGLFrontbuffer->mHasAlpha ? SurfaceCaps::ForRGBA() : SurfaceCaps::ForRGB(); } else { MOZ_ASSERT(screen); caps = screen->mCaps; } MOZ_ASSERT(caps.alpha == aData.mHasAlpha); UniquePtr<SurfaceFactory> factory; if (!gfxPrefs::WebGLForceLayersReadback()) { switch (ClientManager()->AsShadowForwarder()->GetCompositorBackendType()) { case mozilla::layers::LayersBackend::LAYERS_OPENGL: { if (mGLContext->GetContextType() == GLContextType::EGL) { #ifdef MOZ_WIDGET_GONK TextureFlags flags = TextureFlags::DEALLOCATE_CLIENT | TextureFlags::ORIGIN_BOTTOM_LEFT; if (!aData.mIsGLAlphaPremult) { flags |= TextureFlags::NON_PREMULTIPLIED; } factory = MakeUnique<SurfaceFactory_Gralloc>(mGLContext, caps, flags, ClientManager()->AsShadowForwarder()); #else bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); if (!isCrossProcess) { // [Basic/OGL Layers, OMTC] WebGL layer init. factory = SurfaceFactory_EGLImage::Create(mGLContext, caps); } else { // we could do readback here maybe NS_NOTREACHED("isCrossProcess but not on native B2G!"); } #endif } else { // [Basic Layers, OMTC] WebGL layer init. // Well, this *should* work... #ifdef XP_MACOSX factory = SurfaceFactory_IOSurface::Create(mGLContext, caps); #else GLContext* nullConsGL = nullptr; // Bug 1050044. factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, nullConsGL, caps); #endif } break; } case mozilla::layers::LayersBackend::LAYERS_D3D11: { #ifdef XP_WIN if (mGLContext->IsANGLE() && DoesD3D11TextureSharingWork(gfxWindowsPlatform::GetPlatform()->GetD3D11Device())) { factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, caps); } #endif break; } default: break; } } if (mGLFrontbuffer) { // We're using a source other than the one in the default screen. // (SkiaGL) mFactory = Move(factory); if (!mFactory) { // Absolutely must have a factory here, so create a basic one mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps); } } else { if (factory) screen->Morph(Move(factory)); } }
void CanvasLayerD3D10::Initialize(const Data& aData) { NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!"); if (aData.mGLContext) { mGLContext = aData.mGLContext; NS_ASSERTION(mGLContext->IsOffscreen(), "Canvas GLContext must be offscreen."); mDataIsPremultiplied = aData.mIsGLAlphaPremult; mNeedsYFlip = true; GLScreenBuffer* screen = mGLContext->Screen(); SurfaceStreamType streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread, screen->PreserveBuffer()); SurfaceFactory_GL* factory = nullptr; if (!gfxPrefs::WebGLForceLayersReadback()) { if (mGLContext->IsANGLE()) { factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, device(), screen->Caps()); } } if (factory) { screen->Morph(factory, streamType); } } else if (aData.mDrawTarget) { mDrawTarget = aData.mDrawTarget; mNeedsYFlip = false; mDataIsPremultiplied = true; void *texture = mDrawTarget->GetNativeSurface(NativeSurfaceType::D3D10_TEXTURE); if (texture) { mTexture = static_cast<ID3D10Texture2D*>(texture); NS_ASSERTION(!aData.mGLContext, "CanvasLayer can't have both DrawTarget and WebGLContext/Surface"); mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height); device()->CreateShaderResourceView(mTexture, nullptr, getter_AddRefs(mSRView)); return; } // XXX we should store mDrawTarget and use it directly in UpdateSurface, // bypassing Thebes mSurface = mDrawTarget->Snapshot(); } else { NS_ERROR("CanvasLayer created without mSurface, mDrawTarget or mGLContext?"); } mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height); mIsD2DTexture = false; // Create a texture in case we need to readback. CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, mBounds.width, mBounds.height, 1, 1); desc.Usage = D3D10_USAGE_DYNAMIC; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; HRESULT hr = device()->CreateTexture2D(&desc, nullptr, getter_AddRefs(mTexture)); if (FAILED(hr)) { NS_WARNING("Failed to create texture for CanvasLayer!"); return; } device()->CreateShaderResourceView(mTexture, nullptr, getter_AddRefs(mUploadSRView)); }
void CanvasClientSurfaceStream::Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) { aLayer->mGLContext->MakeCurrent(); GLScreenBuffer* screen = aLayer->mGLContext->Screen(); SurfaceStream* stream = nullptr; if (aLayer->mStream) { stream = aLayer->mStream; // Copy our current surface to the current producer surface in our stream, then // call SwapProducer to make a new buffer ready. stream->CopySurfaceToProducer(aLayer->mTextureSurface, aLayer->mFactory); stream->SwapProducer(aLayer->mFactory, gfx::IntSize(aSize.width, aSize.height)); } else { stream = screen->Stream(); } bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); bool bufferCreated = false; if (isCrossProcess) { #ifdef MOZ_WIDGET_GONK SharedSurface* surf = stream->SwapConsumer(); if (!surf) { printf_stderr("surf is null post-SwapConsumer!\n"); return; } if (surf->Type() != SharedSurfaceType::Gralloc) { printf_stderr("Unexpected non-Gralloc SharedSurface in IPC path!"); MOZ_ASSERT(false); return; } SharedSurface_Gralloc* grallocSurf = SharedSurface_Gralloc::Cast(surf); RefPtr<GrallocTextureClientOGL> grallocTextureClient = static_cast<GrallocTextureClientOGL*>(grallocSurf->GetTextureClient()); // If IPDLActor is null means this TextureClient didn't AddTextureClient yet if (!grallocTextureClient->GetIPDLActor()) { grallocTextureClient->SetTextureFlags(mTextureInfo.mTextureFlags); AddTextureClient(grallocTextureClient); } if (grallocTextureClient->GetIPDLActor()) { UseTexture(grallocTextureClient); } if (mBuffer && CompositorChild::ChildProcessHasCompositor()) { // remove old buffer from CompositableHost RefPtr<AsyncTransactionTracker> tracker = new RemoveTextureFromCompositableTracker(); // Hold TextureClient until transaction complete. tracker->SetTextureClient(mBuffer); mBuffer->SetRemoveFromCompositableTracker(tracker); // RemoveTextureFromCompositableAsync() expects CompositorChild's presence. GetForwarder()->RemoveTextureFromCompositableAsync(tracker, this, mBuffer); } mBuffer = grallocTextureClient; #else printf_stderr("isCrossProcess, but not MOZ_WIDGET_GONK! Someone needs to write some code!"); MOZ_ASSERT(false); #endif } else { if (!mBuffer) { StreamTextureClientOGL* textureClient = new StreamTextureClientOGL(mTextureInfo.mTextureFlags); textureClient->InitWith(stream); mBuffer = textureClient; bufferCreated = true; } if (bufferCreated && !AddTextureClient(mBuffer)) { mBuffer = nullptr; } if (mBuffer) { GetForwarder()->UseTexture(this, mBuffer); } } aLayer->Painted(); }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (mGLContext) { GLScreenBuffer* screen = mGLContext->Screen(); SurfaceCaps caps; if (mStream) { // The screen caps are irrelevant if we're using a separate stream caps = aData.mHasAlpha ? SurfaceCaps::ForRGBA() : SurfaceCaps::ForRGB(); } else { caps = screen->mCaps; } MOZ_ASSERT(caps.alpha == aData.mHasAlpha); SurfaceStreamType streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread, screen->PreserveBuffer()); UniquePtr<SurfaceFactory> factory; if (!gfxPrefs::WebGLForceLayersReadback()) { switch (ClientManager()->AsShadowForwarder()->GetCompositorBackendType()) { case mozilla::layers::LayersBackend::LAYERS_OPENGL: { if (mGLContext->GetContextType() == GLContextType::EGL) { #ifdef MOZ_WIDGET_GONK factory = MakeUnique<SurfaceFactory_Gralloc>(mGLContext, caps, ClientManager()->AsShadowForwarder()); #else bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); if (!isCrossProcess) { // [Basic/OGL Layers, OMTC] WebGL layer init. factory = SurfaceFactory_EGLImage::Create(mGLContext, caps); } else { // we could do readback here maybe NS_NOTREACHED("isCrossProcess but not on native B2G!"); } #endif } else { // [Basic Layers, OMTC] WebGL layer init. // Well, this *should* work... #ifdef XP_MACOSX factory = SurfaceFactory_IOSurface::Create(mGLContext, caps); #else GLContext* nullConsGL = nullptr; // Bug 1050044. factory = MakeUnique<SurfaceFactory_GLTexture>(mGLContext, nullConsGL, caps); #endif } break; } case mozilla::layers::LayersBackend::LAYERS_D3D10: case mozilla::layers::LayersBackend::LAYERS_D3D11: { #ifdef XP_WIN if (mGLContext->IsANGLE()) { factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, caps); } #endif break; } default: break; } } if (mStream) { // We're using a stream other than the one in the default screen mFactory = Move(factory); if (!mFactory) { // Absolutely must have a factory here, so create a basic one mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps); } gfx::IntSize size = gfx::IntSize(aData.mSize.width, aData.mSize.height); mTextureSurface = SharedSurface_GLTexture::Create(mGLContext, mGLContext, mGLContext->GetGLFormats(), size, caps.alpha, aData.mTexID); SharedSurface* producer = mStream->SwapProducer(mFactory.get(), size); if (!producer) { // Fallback to basic factory mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps); producer = mStream->SwapProducer(mFactory.get(), size); MOZ_ASSERT(producer, "Failed to create initial canvas surface with basic factory"); } } else if (factory) { screen->Morph(Move(factory), streamType); } } }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (!mGLContext) return; GLScreenBuffer* screen = mGLContext->Screen(); SurfaceCaps caps; if (mGLFrontbuffer) { // The screen caps are irrelevant if we're using a separate frontbuffer. caps = mGLFrontbuffer->mHasAlpha ? SurfaceCaps::ForRGBA() : SurfaceCaps::ForRGB(); } else { MOZ_ASSERT(screen); caps = screen->mCaps; } MOZ_ASSERT(caps.alpha == aData.mHasAlpha); auto forwarder = ClientManager()->AsShadowForwarder(); mFlags = TextureFlags::ORIGIN_BOTTOM_LEFT; if (!aData.mIsGLAlphaPremult) { mFlags |= TextureFlags::NON_PREMULTIPLIED; } UniquePtr<SurfaceFactory> factory; if (!gfxPrefs::WebGLForceLayersReadback()) { switch (forwarder->GetCompositorBackendType()) { case mozilla::layers::LayersBackend::LAYERS_OPENGL: { #if defined(XP_MACOSX) factory = SurfaceFactory_IOSurface::Create(mGLContext, caps, forwarder, mFlags); #elif defined(MOZ_WIDGET_GONK) factory = MakeUnique<SurfaceFactory_Gralloc>(mGLContext, caps, forwarder, mFlags); #else if (mGLContext->GetContextType() == GLContextType::EGL) { bool isCrossProcess = (XRE_GetProcessType() != GeckoProcessType_Default); if (!isCrossProcess) { factory = SurfaceFactory_EGLImage::Create(mGLContext, caps, forwarder, mFlags); } } #endif break; } case mozilla::layers::LayersBackend::LAYERS_D3D11: { #ifdef XP_WIN if (mGLContext->IsANGLE() && DoesD3D11TextureSharingWork(gfxWindowsPlatform::GetPlatform()->GetD3D11Device())) { factory = SurfaceFactory_ANGLEShareHandle::Create(mGLContext, caps, forwarder, mFlags); } #endif break; } default: break; } } if (mGLFrontbuffer) { // We're using a source other than the one in the default screen. // (SkiaGL) mFactory = Move(factory); if (!mFactory) { // Absolutely must have a factory here, so create a basic one mFactory = MakeUnique<SurfaceFactory_Basic>(mGLContext, caps, mFlags); } } else { if (factory) screen->Morph(Move(factory)); } }
void ClientCanvasLayer::Initialize(const Data& aData) { CopyableCanvasLayer::Initialize(aData); mCanvasClient = nullptr; if (mGLContext) { GLScreenBuffer* screen = mGLContext->Screen(); SurfaceCaps caps = screen->Caps(); if (mStream) { // The screen caps are irrelevant if we're using a separate stream caps = GetContentFlags() & CONTENT_OPAQUE ? SurfaceCaps::ForRGB() : SurfaceCaps::ForRGBA(); } SurfaceStreamType streamType = SurfaceStream::ChooseGLStreamType(SurfaceStream::OffMainThread, screen->PreserveBuffer()); SurfaceFactory_GL* factory = nullptr; if (!gfxPrefs::WebGLForceLayersReadback()) { if (ClientManager()->AsShadowForwarder()->GetCompositorBackendType() == mozilla::layers::LayersBackend::LAYERS_OPENGL) { if (mGLContext->GetContextType() == GLContextType::EGL) { bool isCrossProcess = !(XRE_GetProcessType() == GeckoProcessType_Default); if (!isCrossProcess) { // [Basic/OGL Layers, OMTC] WebGL layer init. factory = SurfaceFactory_EGLImage::Create(mGLContext, caps); } else { // [Basic/OGL Layers, OOPC] WebGL layer init. (Out Of Process Compositing) #ifdef MOZ_WIDGET_GONK factory = new SurfaceFactory_Gralloc(mGLContext, caps, ClientManager()->AsShadowForwarder()); #else // we could do readback here maybe NS_NOTREACHED("isCrossProcess but not on native B2G!"); #endif } } else { // [Basic Layers, OMTC] WebGL layer init. // Well, this *should* work... #ifdef XP_MACOSX factory = new SurfaceFactory_IOSurface(mGLContext, caps); #else factory = new SurfaceFactory_GLTexture(mGLContext, nullptr, caps); #endif } } } if (mStream) { // We're using a stream other than the one in the default screen mFactory = factory; if (!mFactory) { // Absolutely must have a factory here, so create a basic one mFactory = new SurfaceFactory_Basic(mGLContext, caps); } gfx::IntSize size = gfx::IntSize(aData.mSize.width, aData.mSize.height); mTextureSurface = SharedSurface_GLTexture::Create(mGLContext, mGLContext, mGLContext->GetGLFormats(), size, caps.alpha, aData.mTexID); SharedSurface* producer = mStream->SwapProducer(mFactory, size); if (!producer) { // Fallback to basic factory delete mFactory; mFactory = new SurfaceFactory_Basic(mGLContext, caps); producer = mStream->SwapProducer(mFactory, size); MOZ_ASSERT(producer, "Failed to create initial canvas surface with basic factory"); } } else if (factory) { screen->Morph(factory, streamType); } } }