void TextureImageEGL::EndUpdate() { NS_ASSERTION(!!mUpdateDrawTarget, "EndUpdate() without BeginUpdate()?"); //printf_stderr("EndUpdate: slow path"); // This is the slower path -- we didn't have any way to set up // a fast mapping between our cairo target surface and the GL // texture, so we have to upload data. RefPtr<gfx::SourceSurface> updateSurface = nullptr; RefPtr<gfx::DataSourceSurface> uploadImage = nullptr; gfx::IntSize updateSize(mUpdateRect.width, mUpdateRect.height); NS_ASSERTION(mUpdateDrawTarget->GetSize() == updateSize, "Upload image is the wrong size!"); updateSurface = mUpdateDrawTarget->Snapshot(); uploadImage = updateSurface->GetDataSurface(); if (!uploadImage) { return; } mGLContext->MakeCurrent(); mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); if (mTextureState != Valid) { NS_ASSERTION(mUpdateRect.x == 0 && mUpdateRect.y == 0 && mUpdateRect.Size() == mSize, "Bad initial update on non-created texture!"); mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, GLFormatForImage(mUpdateFormat), mUpdateRect.width, mUpdateRect.height, 0, GLFormatForImage(uploadImage->GetFormat()), GLTypeForImage(uploadImage->GetFormat()), uploadImage->GetData()); } else { mGLContext->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0, mUpdateRect.x, mUpdateRect.y, mUpdateRect.width, mUpdateRect.height, GLFormatForImage(uploadImage->GetFormat()), GLTypeForImage(uploadImage->GetFormat()), uploadImage->GetData()); } mUpdateDrawTarget = nullptr; mTextureState = Valid; return; // mTexture is bound }
void TextureImageEGL::Resize(const gfx::IntSize& aSize) { NS_ASSERTION(!mUpdateSurface, "Resize() while in update?"); if (mSize == aSize && mTextureState != Created) return; mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, GLFormatForImage(mUpdateFormat), aSize.width, aSize.height, 0, GLFormatForImage(mUpdateFormat), GLTypeForImage(mUpdateFormat), nullptr); mTextureState = Allocated; mSize = aSize; }
void TextureImageEGL::EndUpdate() { NS_ASSERTION(!!mUpdateSurface, "EndUpdate() without BeginUpdate()?"); //printf_stderr("EndUpdate: slow path"); // This is the slower path -- we didn't have any way to set up // a fast mapping between our cairo target surface and the GL // texture, so we have to upload data. // Undo the device offset that BeginUpdate set; doesn't much // matter for us here, but important if we ever do anything // directly with the surface. mUpdateSurface->SetDeviceOffset(gfxPoint(0, 0)); nsRefPtr<gfxImageSurface> uploadImage = nullptr; gfxIntSize updateSize(mUpdateRect.width, mUpdateRect.height); NS_ASSERTION(mUpdateSurface->GetType() == gfxSurfaceType::Image && mUpdateSurface->GetSize() == updateSize, "Upload image isn't an image surface when one is expected, or is wrong size!"); uploadImage = static_cast<gfxImageSurface*>(mUpdateSurface.get()); if (!uploadImage) { return; } mGLContext->MakeCurrent(); mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture); if (mTextureState != Valid) { NS_ASSERTION(mUpdateRect.x == 0 && mUpdateRect.y == 0 && mUpdateRect.Size() == gfx::ThebesIntSize(mSize), "Bad initial update on non-created texture!"); mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, GLFormatForImage(mUpdateFormat), mUpdateRect.width, mUpdateRect.height, 0, GLFormatForImage(uploadImage->Format()), GLTypeForImage(uploadImage->Format()), uploadImage->Data()); } else { mGLContext->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0, mUpdateRect.x, mUpdateRect.y, mUpdateRect.width, mUpdateRect.height, GLFormatForImage(uploadImage->Format()), GLTypeForImage(uploadImage->Format()), uploadImage->Data()); } mUpdateSurface = nullptr; mTextureState = Valid; return; // mTexture is bound }