TemporaryRef<TextureHost> CreateTextureHostOGL(uint64_t aID, const SurfaceDescriptor& aDesc, ISurfaceAllocator* aDeallocator, TextureFlags aFlags) { RefPtr<TextureHost> result; switch (aDesc.type()) { case SurfaceDescriptor::TSurfaceDescriptorShmem: case SurfaceDescriptor::TSurfaceDescriptorMemory: { result = CreateBackendIndependentTextureHost(aID, aDesc, aDeallocator, aFlags); break; } case SurfaceDescriptor::TSharedTextureDescriptor: { const SharedTextureDescriptor& desc = aDesc.get_SharedTextureDescriptor(); result = new SharedTextureHostOGL(aID, aFlags, desc.shareType(), desc.handle(), gfx::ToIntSize(desc.size()), desc.inverted()); break; } default: return nullptr; } return result.forget(); }
void SharedDeprecatedTextureHostOGL::SwapTexturesImpl(const SurfaceDescriptor& aImage, nsIntRegion* aRegion) { NS_ASSERTION(aImage.type() == SurfaceDescriptor::TSharedTextureDescriptor, "Invalid descriptor"); SharedTextureDescriptor texture = aImage.get_SharedTextureDescriptor(); SharedTextureHandle newHandle = texture.handle(); nsIntSize size = texture.size(); mSize = gfx::IntSize(size.width, size.height); if (texture.inverted()) { mFlags |= TEXTURE_NEEDS_Y_FLIP; } if (mSharedHandle && mSharedHandle != newHandle) { mGL->ReleaseSharedHandle(mShareType, mSharedHandle); } mShareType = texture.shareType(); mSharedHandle = newHandle; GLContext::SharedHandleDetails handleDetails; if (mSharedHandle && mGL->GetSharedHandleDetails(mShareType, mSharedHandle, handleDetails)) { mTextureTarget = handleDetails.mTarget; mFormat = handleDetails.mTextureFormat; } }
bool ShadowImageLayerOGL::Init(const SharedImage& aFront) { if (aFront.type() == SharedImage::TSurfaceDescriptor) { SurfaceDescriptor surface = aFront.get_SurfaceDescriptor(); if (surface.type() == SurfaceDescriptor::TSharedTextureDescriptor) { SharedTextureDescriptor texture = surface.get_SharedTextureDescriptor(); mSize = texture.size(); mSharedHandle = texture.handle(); mShareType = texture.shareType(); mInverted = texture.inverted(); } else { AutoOpenSurface autoSurf(OPEN_READ_ONLY, surface); mSize = autoSurf.Size(); mTexImage = gl()->CreateTextureImage(nsIntSize(mSize.width, mSize.height), autoSurf.ContentType(), LOCAL_GL_CLAMP_TO_EDGE, mForceSingleTile ? TextureImage::ForceSingleTile : TextureImage::NoFlags); } } else { YUVImage yuv = aFront.get_YUVImage(); AutoOpenSurface surfY(OPEN_READ_ONLY, yuv.Ydata()); AutoOpenSurface surfU(OPEN_READ_ONLY, yuv.Udata()); mSize = surfY.Size(); mCbCrSize = surfU.Size(); if (!mYUVTexture[0].IsAllocated()) { mYUVTexture[0].Allocate(gl()); mYUVTexture[1].Allocate(gl()); mYUVTexture[2].Allocate(gl()); } NS_ASSERTION(mYUVTexture[0].IsAllocated() && mYUVTexture[1].IsAllocated() && mYUVTexture[2].IsAllocated(), "Texture allocation failed!"); gl()->MakeCurrent(); SetClamping(gl(), mYUVTexture[0].GetTextureID()); SetClamping(gl(), mYUVTexture[1].GetTextureID()); SetClamping(gl(), mYUVTexture[2].GetTextureID()); return true; } return false; }
void ShadowImageLayerOGL::Swap(const SharedImage& aNewFront, SharedImage* aNewBack) { if (!mDestroyed) { if (aNewFront.type() == SharedImage::TSharedImageID) { // We are using ImageBridge protocol. The image data will be queried at render // time in the parent side. uint64_t newID = aNewFront.get_SharedImageID().id(); if (newID != mImageContainerID) { mImageContainerID = newID; mImageVersion = 0; } } else if (aNewFront.type() == SharedImage::TSurfaceDescriptor) { SurfaceDescriptor surface = aNewFront.get_SurfaceDescriptor(); if (surface.type() == SurfaceDescriptor::TSharedTextureDescriptor) { SharedTextureDescriptor texture = surface.get_SharedTextureDescriptor(); SharedTextureHandle newHandle = texture.handle(); mSize = texture.size(); mInverted = texture.inverted(); if (mSharedHandle && newHandle != mSharedHandle) gl()->ReleaseSharedHandle(mShareType, mSharedHandle); mSharedHandle = newHandle; mShareType = texture.shareType(); } else { AutoOpenSurface surf(OPEN_READ_ONLY, surface); gfxIntSize size = surf.Size(); if (mSize != size || !mTexImage || mTexImage->GetContentType() != surf.ContentType()) { Init(aNewFront); } // XXX this is always just ridiculously slow nsIntRegion updateRegion(nsIntRect(0, 0, size.width, size.height)); mTexImage->DirectUpdate(surf.Get(), updateRegion); } } else { const YUVImage& yuv = aNewFront.get_YUVImage(); UploadSharedYUVToTexture(yuv); } } *aNewBack = aNewFront; }
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(); }