mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 12:25:53 +00:00
Bug 1322746 - Remove video->canvas2d fastpath for SkiaGL. - r=lsalzman
MozReview-Commit-ID: GjLnyS2lqDo
This commit is contained in:
parent
ac5c9e25a2
commit
db7d828d70
@ -5184,115 +5184,6 @@ CanvasRenderingContext2D::DrawImage(const CanvasImageSource& aImage,
|
||||
|
||||
nsLayoutUtils::DirectDrawInfo drawInfo;
|
||||
|
||||
#ifdef USE_SKIA_GPU
|
||||
if (mRenderingMode == RenderingMode::OpenGLBackendMode &&
|
||||
mIsSkiaGL &&
|
||||
!srcSurf &&
|
||||
aImage.IsHTMLVideoElement() &&
|
||||
AllowOpenGLCanvas()) {
|
||||
mozilla::gl::GLContext* gl = gfxPlatform::GetPlatform()->GetSkiaGLGlue()->GetGLContext();
|
||||
MOZ_ASSERT(gl);
|
||||
|
||||
HTMLVideoElement* video = &aImage.GetAsHTMLVideoElement();
|
||||
if (!video) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (video->ContainsRestrictedContent()) {
|
||||
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t readyState;
|
||||
if (NS_SUCCEEDED(video->GetReadyState(&readyState)) &&
|
||||
readyState < nsIDOMHTMLMediaElement::HAVE_CURRENT_DATA) {
|
||||
// still loading, just return
|
||||
return;
|
||||
}
|
||||
|
||||
// If it doesn't have a principal, just bail
|
||||
nsCOMPtr<nsIPrincipal> principal = video->GetCurrentVideoPrincipal();
|
||||
if (!principal) {
|
||||
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
mozilla::layers::ImageContainer* container = video->GetImageContainer();
|
||||
if (!container) {
|
||||
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
AutoLockImage lockImage(container);
|
||||
layers::Image* srcImage = lockImage.GetImage();
|
||||
if (!srcImage) {
|
||||
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
if (!gl->MakeCurrent()) {
|
||||
aError.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return;
|
||||
}
|
||||
GLuint videoTexture = 0;
|
||||
gl->fGenTextures(1, &videoTexture);
|
||||
// skiaGL expect upload on drawing, and uses texture 0 for texturing,
|
||||
// so we must active texture 0 and bind the texture for it.
|
||||
gl->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
const gl::ScopedBindTexture scopeBindTexture(gl, videoTexture);
|
||||
|
||||
gl->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGB, srcImage->GetSize().width, srcImage->GetSize().height, 0, LOCAL_GL_RGB, LOCAL_GL_UNSIGNED_SHORT_5_6_5, nullptr);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
||||
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
||||
|
||||
const auto destOrigin = gl::OriginPos::BottomLeft;
|
||||
bool ok = false;
|
||||
do {
|
||||
const gl::ScopedFramebufferForTexture autoFBForTex(gl, videoTexture);
|
||||
if (!autoFBForTex.IsComplete()) {
|
||||
MOZ_ASSERT(false, "ScopedFramebufferForTexture not complete.");
|
||||
break;
|
||||
}
|
||||
const gl::ScopedBindFramebuffer bindFB(gl, autoFBForTex.FB());
|
||||
ok = gl->BlitHelper()->BlitImageToFramebuffer(srcImage, srcImage->GetSize(),
|
||||
destOrigin);
|
||||
} while (false);
|
||||
if (ok) {
|
||||
NativeSurface texSurf;
|
||||
texSurf.mType = NativeSurfaceType::OPENGL_TEXTURE;
|
||||
texSurf.mFormat = SurfaceFormat::R5G6B5_UINT16;
|
||||
texSurf.mSize.width = srcImage->GetSize().width;
|
||||
texSurf.mSize.height = srcImage->GetSize().height;
|
||||
texSurf.mSurface = (void*)((uintptr_t)videoTexture);
|
||||
|
||||
srcSurf = mTarget->CreateSourceSurfaceFromNativeSurface(texSurf);
|
||||
if (!srcSurf) {
|
||||
gl->fDeleteTextures(1, &videoTexture);
|
||||
}
|
||||
imgSize.width = srcImage->GetSize().width;
|
||||
imgSize.height = srcImage->GetSize().height;
|
||||
|
||||
int32_t displayWidth = video->VideoWidth();
|
||||
int32_t displayHeight = video->VideoHeight();
|
||||
aSw *= (double)imgSize.width / (double)displayWidth;
|
||||
aSh *= (double)imgSize.height / (double)displayHeight;
|
||||
} else {
|
||||
gl->fDeleteTextures(1, &videoTexture);
|
||||
}
|
||||
}
|
||||
|
||||
srcImage = nullptr;
|
||||
|
||||
if (mCanvasElement) {
|
||||
CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement,
|
||||
principal, false,
|
||||
video->GetCORSMode() != CORS_NONE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!srcSurf) {
|
||||
// The canvas spec says that drawImage should draw the first frame
|
||||
// of animated images. We also don't want to rasterize vector images.
|
||||
|
Loading…
Reference in New Issue
Block a user