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(); }
// static TemporaryRef<TextureHost> TextureHost::Create(const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator, TextureFlags aFlags) { switch (aDesc.type()) { case SurfaceDescriptor::TSurfaceDescriptorShmem: case SurfaceDescriptor::TSurfaceDescriptorMemory: return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags); case SurfaceDescriptor::TSharedTextureDescriptor: case SurfaceDescriptor::TNewSurfaceDescriptorGralloc: return CreateTextureHostOGL(aDesc, aDeallocator, aFlags); case SurfaceDescriptor::TSurfaceStreamDescriptor: return new StreamTextureHost(aFlags, aDesc.get_SurfaceStreamDescriptor()); case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: if (Compositor::GetBackend() == LayersBackend::LAYERS_OPENGL) { return CreateTextureHostOGL(aDesc, aDeallocator, aFlags); } else { return CreateTextureHostBasic(aDesc, aDeallocator, aFlags); } #ifdef MOZ_X11 case SurfaceDescriptor::TSurfaceDescriptorX11: { const SurfaceDescriptorX11& desc = aDesc.get_SurfaceDescriptorX11(); RefPtr<TextureHost> result = new X11TextureHost(aFlags, desc); return result; } #endif #ifdef XP_WIN case SurfaceDescriptor::TSurfaceDescriptorD3D9: case SurfaceDescriptor::TSurfaceDescriptorDIB: return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags); case SurfaceDescriptor::TSurfaceDescriptorD3D10: if (Compositor::GetBackend() == LayersBackend::LAYERS_D3D9) { return CreateTextureHostD3D9(aDesc, aDeallocator, aFlags); } else { return CreateTextureHostD3D11(aDesc, aDeallocator, aFlags); } #endif default: MOZ_CRASH("Unsupported Surface type"); } }
TemporaryRef<TextureHost> CreateTextureHostOGL(const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator, TextureFlags aFlags) { RefPtr<TextureHost> result; switch (aDesc.type()) { case SurfaceDescriptor::TSurfaceDescriptorShmem: case SurfaceDescriptor::TSurfaceDescriptorMemory: { result = CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags); break; } case SurfaceDescriptor::TSharedTextureDescriptor: { const SharedTextureDescriptor& desc = aDesc.get_SharedTextureDescriptor(); result = new SharedTextureHostOGL(aFlags, desc.shareType(), desc.handle(), desc.size(), desc.inverted()); break; } case SurfaceDescriptor::TSurfaceStreamDescriptor: { const SurfaceStreamDescriptor& desc = aDesc.get_SurfaceStreamDescriptor(); result = new StreamTextureHostOGL(aFlags, desc); break; } #ifdef XP_MACOSX case SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: { const SurfaceDescriptorMacIOSurface& desc = aDesc.get_SurfaceDescriptorMacIOSurface(); result = new MacIOSurfaceTextureHostOGL(aFlags, desc); break; } #endif #ifdef MOZ_WIDGET_GONK case SurfaceDescriptor::TNewSurfaceDescriptorGralloc: { const NewSurfaceDescriptorGralloc& desc = aDesc.get_NewSurfaceDescriptorGralloc(); result = new GrallocTextureHostOGL(aFlags, desc); break; } #endif default: return nullptr; } return result.forget(); }
void SurfaceStreamHostOGL::UpdateImpl(const SurfaceDescriptor& aImage, nsIntRegion* aRegion, nsIntPoint* aOffset) { MOZ_ASSERT(aImage.type() == SurfaceDescriptor::TSurfaceStreamDescriptor, "Invalid descriptor"); // Bug 894405 // // The SurfaceStream's GLContext was refed before being passed up to us, so // we need to ensure it gets unrefed when we are finished. const SurfaceStreamDescriptor& streamDesc = aImage.get_SurfaceStreamDescriptor(); SurfaceStream *stream = SurfaceStream::FromHandle(streamDesc.handle()); if (stream == mStream) { return; } mStream = stream; MOZ_ASSERT(mStream); mStreamGL = dont_AddRef(mStream->GLContext()); }