Bug 1322746 - Fix android blitting. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 22 Aug 2017 19:56:42 -0700
changeset 656969 3ccfa9e53f818c46e9bd68022f5646e381b4a717
parent 656968 f6210354e7d01001dace68ff1e3808e86e3e5e15
child 656970 ec715cff1c62838ffc6e67b25c9663eca8131013
push id77391
push userbmo:jgilbert@mozilla.com
push dateThu, 31 Aug 2017 22:47:58 +0000
reviewersdaoshengmu
bugs1322746
milestone57.0a1
Bug 1322746 - Fix android blitting. - r=daoshengmu MozReview-Commit-ID: F9qm5XtPUoE
gfx/gl/GLBlitHelper.cpp
gfx/gl/GLBlitHelper.h
--- a/gfx/gl/GLBlitHelper.cpp
+++ b/gfx/gl/GLBlitHelper.cpp
@@ -311,24 +311,24 @@ public:
 };
 
 // --
 
 DrawBlitProg::DrawBlitProg(const GLBlitHelper* const parent, const GLuint prog)
     : mParent(*parent)
     , mProg(prog)
     , mLoc_u1ForYFlip(mParent.mGL->fGetUniformLocation(mProg, "u1ForYFlip"))
-    , mLoc_uClipRect(mParent.mGL->fGetUniformLocation(mProg, "uClipRect"))
+    , mLoc_uSrcRect(mParent.mGL->fGetUniformLocation(mProg, "uSrcRect"))
     , mLoc_uTexSize0(mParent.mGL->fGetUniformLocation(mProg, "uTexSize0"))
     , mLoc_uTexSize1(mParent.mGL->fGetUniformLocation(mProg, "uTexSize1"))
     , mLoc_uDivisors(mParent.mGL->fGetUniformLocation(mProg, "uDivisors"))
     , mLoc_uColorMatrix(mParent.mGL->fGetUniformLocation(mProg, "uColorMatrix"))
 {
     MOZ_ASSERT(mLoc_u1ForYFlip != -1);
-    MOZ_ASSERT(mLoc_uClipRect != -1);
+    MOZ_ASSERT(mLoc_uSrcRect != -1);
     MOZ_ASSERT(mLoc_uTexSize0 != -1);
     if (mLoc_uColorMatrix != -1) {
         MOZ_ASSERT(mLoc_uTexSize1 != -1);
         MOZ_ASSERT(mLoc_uDivisors != -1);
     }
 }
 
 DrawBlitProg::~DrawBlitProg()
@@ -346,19 +346,19 @@ DrawBlitProg::Draw(const BaseArgs& args,
     const auto& gl = mParent.mGL;
 
     const SaveRestoreCurrentProgram oldProg(gl);
     gl->fUseProgram(mProg);
 
     // --
 
     gl->fUniform1f(mLoc_u1ForYFlip, args.yFlip ? 1 : 0);
-    gl->fUniform4f(mLoc_uClipRect,
-                   args.clipRect.x, args.clipRect.y,
-                   args.clipRect.width, args.clipRect.height);
+    gl->fUniform4f(mLoc_uSrcRect,
+                   args.srcRect.x, args.srcRect.y,
+                   args.srcRect.width, args.srcRect.height);
     gl->fUniform2f(mLoc_uTexSize0, args.texSize0.width, args.texSize0.height);
 
     MOZ_ASSERT(bool(argsYUV) == (mLoc_uColorMatrix != -1));
     if (argsYUV) {
         gl->fUniform2f(mLoc_uTexSize1, argsYUV->texSize1.width, argsYUV->texSize1.height);
         gl->fUniform2f(mLoc_uDivisors, argsYUV->divisors.width, argsYUV->divisors.height);
         const auto& colorMatrix = gfxUtils::YuvToRgbMatrix4x4ColumnMajor(argsYUV->colorSpace);
         gl->fUniformMatrix4fv(mLoc_uColorMatrix, 1, false, colorMatrix);
@@ -424,32 +424,32 @@ GLBlitHelper::GLBlitHelper(GLContext* co
         #else                                                                \n\
             #define ATTRIBUTE attribute                                      \n\
             #define VARYING varying                                          \n\
         #endif                                                               \n\
                                                                              \n\
         ATTRIBUTE vec2 aVert;                                                \n\
                                                                              \n\
         uniform float u1ForYFlip;                                            \n\
-        uniform vec4 uClipRect;                                              \n\
+        uniform vec4 uSrcRect;                                               \n\
         uniform vec2 uTexSize0;                                              \n\
         uniform vec2 uTexSize1;                                              \n\
         uniform vec2 uDivisors;                                              \n\
                                                                              \n\
         VARYING vec2 vTexCoord0;                                             \n\
         VARYING vec2 vTexCoord1;                                             \n\
                                                                              \n\
         void main(void)                                                      \n\
         {                                                                    \n\
             vec2 vertPos = aVert * 2.0 - 1.0;                                \n\
             gl_Position = vec4(vertPos, 0.0, 1.0);                           \n\
                                                                              \n\
             vec2 texCoord = aVert;                                           \n\
             texCoord.y = abs(u1ForYFlip - texCoord.y);                       \n\
-            texCoord = texCoord * uClipRect.zw + uClipRect.xy;               \n\
+            texCoord = texCoord * uSrcRect.zw + uSrcRect.xy;                 \n\
                                                                              \n\
             vTexCoord0 = texCoord / uTexSize0;                               \n\
             vTexCoord1 = texCoord / (uTexSize1 * uDivisors);                 \n\
         }                                                                    \n\
     ";
 
     const char* const parts[] = {
         mDrawBlitProg_VersionLine.get(),
@@ -583,17 +583,18 @@ GLBlitHelper::BlitImageToFramebuffer(lay
                                      OriginPos destOrigin)
 {
     switch (srcImage->GetFormat()) {
     case ImageFormat::PLANAR_YCBCR:
         return BlitImage(static_cast<PlanarYCbCrImage*>(srcImage), destSize, destOrigin);
 
 #ifdef MOZ_WIDGET_ANDROID
     case ImageFormat::SURFACE_TEXTURE:
-        return BlitImage(static_cast<layers::SurfaceTextureImage*>(srcImage));
+        return BlitImage(static_cast<layers::SurfaceTextureImage*>(srcImage), destSize,
+                         destOrigin);
 
     case ImageFormat::EGLIMAGE:
         return BlitImage(static_cast<layers::EGLImageImage*>(srcImage), destSize,
                          destOrigin);
 #endif
 #ifdef XP_MACOSX
     case ImageFormat::MAC_IOSURFACE:
         return BlitImage(srcImage->AsMacIOSurfaceImage(), destSize, destOrigin);
@@ -614,28 +615,29 @@ GLBlitHelper::BlitImageToFramebuffer(lay
         return false;
     }
 }
 
 // -------------------------------------
 
 #ifdef MOZ_WIDGET_ANDROID
 bool
-GLBlitHelper::BlitImage(layers::SurfaceTextureImage* srcImage)
+GLBlitHelper::BlitImage(layers::SurfaceTextureImage* srcImage, const gfx::IntSize&,
+                        const OriginPos) const
 {
     // FIXME
     const auto& srcOrigin = srcImage->GetOriginPos();
     (void)srcOrigin;
     gfxCriticalError() << "BlitImage(SurfaceTextureImage) not implemented.";
     return false;
 }
 
 bool
 GLBlitHelper::BlitImage(layers::EGLImageImage* const srcImage,
-                        const gfx::IntSize& destSize, const OriginPos destOrigin)
+                        const gfx::IntSize& destSize, const OriginPos destOrigin) const
 {
     const EGLImage eglImage = srcImage->GetImage();
     const EGLSync eglSync = srcImage->GetSync();
     if (eglSync) {
         EGLint status = sEGLLibrary.fClientWaitSync(EGL_DISPLAY(), eglSync, 0, LOCAL_EGL_FOREVER);
         if (status != LOCAL_EGL_CONDITION_SATISFIED) {
             return false;
         }
@@ -646,19 +648,19 @@ GLBlitHelper::BlitImage(layers::EGLImage
 
     const ScopedSaveMultiTex saveTex(mGL, 1, LOCAL_GL_TEXTURE_2D);
     mGL->fBindTexture(LOCAL_GL_TEXTURE_2D, tex);
     mGL->TexParams_SetClampNoMips();
     mGL->fEGLImageTargetTexture2D(LOCAL_GL_TEXTURE_2D, eglImage);
 
     const auto& srcOrigin = srcImage->GetOriginPos();
     const bool yFlip = destOrigin != srcOrigin;
-    const gfx::IntRect clipRect(0, 0, 1, 1);
-    const gfx::IntSize texSizeDivisor(1, 1);
-    const DrawBlitProg::DrawArgs baseArgs = { destSize, yFlip, clipRect, texSizeDivisor };
+    const gfx::IntRect srcRect(0, 0, 1, 1);
+    const gfx::IntSize srcSize(1, 1);
+    const DrawBlitProg::BaseArgs baseArgs = { destSize, yFlip, srcRect, srcSize };
 
     const auto& prog = GetDrawBlitProg({kFragHeader_Tex2D, kFragBody_RGBA});
     MOZ_RELEASE_ASSERT(prog);
     prog->Draw(baseArgs);
 
     mGL->fDeleteTextures(1, &tex);
     return true;
 }
--- a/gfx/gl/GLBlitHelper.h
+++ b/gfx/gl/GLBlitHelper.h
@@ -42,17 +42,17 @@ bool
 GuessDivisors(const gfx::IntSize& ySize, const gfx::IntSize& uvSize,
               gfx::IntSize* const out_divisors);
 
 class DrawBlitProg final
 {
     const GLBlitHelper& mParent;
     const GLuint mProg;
     const GLint mLoc_u1ForYFlip;
-    const GLint mLoc_uClipRect;
+    const GLint mLoc_uSrcRect;
     const GLint mLoc_uTexSize0;
     const GLint mLoc_uTexSize1;
     const GLint mLoc_uDivisors;
     const GLint mLoc_uColorMatrix;
 
 public:
     struct Key final {
         const char* fragHeader;
@@ -66,17 +66,17 @@ public:
     };
 
     DrawBlitProg(const GLBlitHelper* parent, GLuint prog);
     ~DrawBlitProg();
 
     struct BaseArgs final {
         gfx::IntSize destSize;
         bool yFlip;
-        gfx::IntRect clipRect;
+        gfx::IntRect srcRect;
         gfx::IntSize texSize0;
     };
     struct YUVArgs final {
         gfx::IntSize texSize1;
         gfx::IntSize divisors;
         YUVColorSpace colorSpace;
     };
 
@@ -125,18 +125,20 @@ class GLBlitHelper final
 private:
     const DrawBlitProg* CreateDrawBlitProg(const DrawBlitProg::Key& key) const;
 public:
 
     bool BlitImage(layers::PlanarYCbCrImage* yuvImage, const gfx::IntSize& destSize,
                    OriginPos destOrigin);
 #ifdef MOZ_WIDGET_ANDROID
     // Blit onto the current FB.
-    bool BlitImage(layers::SurfaceTextureImage* stImage);
-    bool BlitImage(layers::EGLImageImage* eglImage);
+    bool BlitImage(layers::SurfaceTextureImage* stImage, const gfx::IntSize& destSize,
+                   OriginPos destOrigin) const;
+    bool BlitImage(layers::EGLImageImage* eglImage, const gfx::IntSize& destSize,
+                   OriginPos destOrigin) const;
 #endif
 #ifdef XP_MACOSX
     bool BlitImage(layers::MacIOSurfaceImage* srcImage, const gfx::IntSize& destSize,
                    OriginPos destOrigin) const;
 #endif
 
     explicit GLBlitHelper(GLContext* gl);
 public: