Bug 1322746 - Remove video->canvas2d fastpath for SkiaGL. - r=lsalzman draft
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 31 Aug 2017 18:52:16 -0700
changeset 657070 2b9f528f3a4c08947b3996ac72a2da36acb9486e
parent 656975 b872159ba09dfc64852604a2f176e0382bdbf21a
child 729338 ddd97d9f091d9a4966d4da5cd1eb9727b75da1a8
push id77429
push userbmo:jgilbert@mozilla.com
push dateFri, 01 Sep 2017 01:59:13 +0000
reviewerslsalzman
bugs1322746
milestone57.0a1
Bug 1322746 - Remove video->canvas2d fastpath for SkiaGL. - r=lsalzman MozReview-Commit-ID: GjLnyS2lqDo
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5179,125 +5179,16 @@ CanvasRenderingContext2D::DrawImage(cons
     }
 
     srcSurf =
      CanvasImageCache::LookupCanvas(element, mCanvasElement, &imgSize, mIsSkiaGL);
   }
 
   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.
     uint32_t sfeFlags = nsLayoutUtils::SFE_WANT_FIRST_FRAME_IF_IMAGE |
                         nsLayoutUtils::SFE_NO_RASTERIZING_VECTORS;
 
     nsLayoutUtils::SurfaceFromElementResult res =
       CanvasRenderingContext2D::CachedSurfaceFromElement(element);