Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 35279)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 35280)
@@ -371,5 +371,5 @@
 }
 
-static VBoxVHWATexture* vboxVHWATextureCreate(const QGLContext * pContext, const QRect & aRect, const VBoxVHWAColorFormat & aFormat, VBOXVHWAIMG_TYPE flags)
+static VBoxVHWATexture* vboxVHWATextureCreate(const QGLContext * pContext, const QRect & aRect, const VBoxVHWAColorFormat & aFormat, uint32_t bytesPerLine, VBOXVHWAIMG_TYPE flags)
 {
     const VBoxVHWAInfo & info = vboxVHWAGetSupportInfo(pContext);
@@ -378,18 +378,18 @@
     {
         VBOXQGLLOG(("VBoxVHWATextureNP2RectPBO\n"));
-        return new VBoxVHWATextureNP2RectPBO(aRect, aFormat, scaleFunc);
+        return new VBoxVHWATextureNP2RectPBO(aRect, aFormat, bytesPerLine, scaleFunc);
     }
     else if(info.getGlInfo().isTextureRectangleSupported())
     {
         VBOXQGLLOG(("VBoxVHWATextureNP2Rect\n"));
-        return new VBoxVHWATextureNP2Rect(aRect, aFormat, scaleFunc);
+        return new VBoxVHWATextureNP2Rect(aRect, aFormat, bytesPerLine, scaleFunc);
     }
     else if(info.getGlInfo().isTextureNP2Supported())
     {
         VBOXQGLLOG(("VBoxVHWATextureNP2\n"));
-        return new VBoxVHWATextureNP2(aRect, aFormat, scaleFunc);
+        return new VBoxVHWATextureNP2(aRect, aFormat, bytesPerLine, scaleFunc);
     }
     VBOXQGLLOG(("VBoxVHWATexture\n"));
-    return new VBoxVHWATexture(aRect, aFormat, scaleFunc);
+    return new VBoxVHWATexture(aRect, aFormat, bytesPerLine, scaleFunc);
 }
 
@@ -1435,5 +1435,5 @@
 
     VBOXQGL_CHECKERR(
-            glPixelStorei(GL_UNPACK_ROW_LENGTH, mRect.width()/mColorFormat.widthCompression());
+            glPixelStorei(GL_UNPACK_ROW_LENGTH, mBytesPerLine * 8 /mColorFormat.bitsPerPixelTex());
             );
 
@@ -1446,4 +1446,8 @@
                 address);
             );
+
+    VBOXQGL_CHECKERR(
+            glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
+            );
 }
 
@@ -1466,5 +1470,5 @@
 }
 
-VBoxVHWATexture::VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion) :
+VBoxVHWATexture::VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
             mAddress(NULL),
             mTexture(0),
@@ -1478,5 +1482,5 @@
     mBytesPerPixel = mColorFormat.bitsPerPixel()/8;
     mBytesPerPixelTex = mColorFormat.bitsPerPixelTex()/8;
-    mBytesPerLine = mBytesPerPixel * mRect.width();
+    mBytesPerLine = bytesPerLine ? bytesPerLine : mBytesPerPixel * mRect.width();
     GLsizei wdt = VBoxVHWASurfaceBase::makePowerOf2(mRect.width()/mColorFormat.widthCompression());
     GLsizei hgt = VBoxVHWASurfaceBase::makePowerOf2(mRect.height()/mColorFormat.heightCompression());
@@ -2432,5 +2436,5 @@
     if (!reportedFormat.isValid())
     {
-        pCmd->SurfInfo.pitch = surf->bitsPerPixel() * surf->width() / 8;
+        pCmd->SurfInfo.pitch = surf->bytesPerLine();
         pCmd->SurfInfo.sizeX = surf->memSize();
         pCmd->SurfInfo.sizeY = 1;
@@ -2493,9 +2497,7 @@
     if (format.isValid())
     {
-        pCmd->SurfInfo.pitch = format.bitsPerPixel() * pCmd->SurfInfo.width / 8;
-//        pCmd->SurfInfo.pitch = ((pCmd->SurfInfo.pitch + 3) & (~3));
-        pCmd->SurfInfo.sizeX = format.bitsPerPixelMem() * pCmd->SurfInfo.width / 8;
-//        pCmd->SurfInfo.sizeX = ((pCmd->SurfInfo.sizeX + 3) & (~3));
-        pCmd->SurfInfo.sizeX *= pCmd->SurfInfo.height;
+        pCmd->SurfInfo.pitch = VBoxVHWATextureImage::calcBytesPerLine(format, pCmd->SurfInfo.width);
+        pCmd->SurfInfo.sizeX = VBoxVHWATextureImage::calcMemSize(format,
+                pCmd->SurfInfo.width, pCmd->SurfInfo.height);
         pCmd->SurfInfo.sizeY = 1;
         return VINF_SUCCESS;
@@ -3970,7 +3972,4 @@
         case FOURCC_AYUV:
             mBitsPerPixel = 32;
-#ifdef VBOX_WITH_WDDM
-            mBitsPerPixelMem = 32;
-#endif
             mWidthCompression = 1;
             break;
@@ -3978,14 +3977,8 @@
         case FOURCC_YUY2:
             mBitsPerPixel = 16;
-#ifdef VBOX_WITH_WDDM
-            mBitsPerPixelMem = 16;
-#endif
             mWidthCompression = 2;
             break;
         case FOURCC_YV12:
             mBitsPerPixel = 8;
-#ifdef VBOX_WITH_WDDM
-            mBitsPerPixelMem = 12;
-#endif
             mWidthCompression = 4;
             break;
@@ -3994,7 +3987,4 @@
             mBitsPerPixel = 0;
             mBitsPerPixelTex = 0;
-#ifdef VBOX_WITH_WDDM
-            mBitsPerPixelMem = 0;
-#endif
             mWidthCompression = 0;
             break;
@@ -4006,7 +3996,4 @@
     mBitsPerPixel = bitsPerPixel;
     mBitsPerPixelTex = bitsPerPixel;
-#ifdef VBOX_WITH_WDDM
-    mBitsPerPixelMem = bitsPerPixel;
-#endif
     mDataFormat = 0;
     switch (bitsPerPixel)
@@ -4066,7 +4053,4 @@
             mBitsPerPixel = 0;
             mBitsPerPixelTex = 0;
-#ifdef VBOX_WITH_WDDM
-            mBitsPerPixelMem = 0;
-#endif
             break;
     }
@@ -5383,4 +5367,42 @@
 }
 
+/* static */
+uint32_t VBoxVHWATextureImage::calcBytesPerLine(const VBoxVHWAColorFormat & format, int width)
+{
+    uint32_t pitch = (format.bitsPerPixel() * width + 7)/8;
+    switch (format.fourcc())
+    {
+        case FOURCC_YV12:
+            /* make sure the color components pitch is multiple of 8
+             * where 8 is 2 (for color component width is Y width / 2) * 4 for 4byte texture format */
+            pitch = (pitch + 7) & ~7;
+            break;
+        default:
+            pitch = (pitch + 3) & ~3;
+            break;
+    }
+    return pitch;
+}
+
+/* static */
+uint32_t VBoxVHWATextureImage::calcMemSize(const VBoxVHWAColorFormat & format, int width, int height)
+{
+    uint32_t pitch = calcBytesPerLine(format, width);
+    switch (format.fourcc())
+    {
+        case FOURCC_YV12:
+            /* we have 3 separate planes here
+             * Y - pitch x height
+             * U - pitch/2 x height/2
+             * V - pitch/2 x height/2
+             * */
+            return 3 * pitch * height / 2;
+            break;
+        default:
+            return pitch * height;
+            break;
+    }
+}
+
 VBoxVHWATextureImage::VBoxVHWATextureImage(const QRect &size, const VBoxVHWAColorFormat &format, class VBoxVHWAGlProgramMngr * aMgr, VBOXVHWAIMG_TYPE flags) :
         mVisibleDisplay(0),
@@ -5392,11 +5414,13 @@
         mbNotIntersected(false)
 {
-    mpTex[0] = vboxVHWATextureCreate(NULL, size, format, flags);
+    uint32_t pitch = calcBytesPerLine(format, size.width());
+
+    mpTex[0] = vboxVHWATextureCreate(NULL, size, format, pitch, flags);
     mColorFormat = format;
     if(mColorFormat.fourcc() == FOURCC_YV12)
     {
         QRect rect(size.x()/2,size.y()/2,size.width()/2,size.height()/2);
-        mpTex[1] = vboxVHWATextureCreate(NULL, rect, format, flags);
-        mpTex[2] = vboxVHWATextureCreate(NULL, rect, format, flags);
+        mpTex[1] = vboxVHWATextureCreate(NULL, rect, format, pitch/2, flags);
+        mpTex[2] = vboxVHWATextureCreate(NULL, rect, format, pitch/2, flags);
         mcTex = 3;
     }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 35279)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 35280)
@@ -233,7 +233,4 @@
     uint32_t bitsPerPixel() const { return mBitsPerPixel; }
     uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; }
-#ifdef VBOX_WITH_WDDM
-    uint32_t bitsPerPixelMem() const { return mBitsPerPixelMem; }
-#endif
     void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const;
     uint32_t widthCompression() const {return mWidthCompression;}
@@ -271,7 +268,4 @@
     uint32_t mBitsPerPixel;
     uint32_t mBitsPerPixelTex;
-#ifdef VBOX_WITH_WDDM
-    uint32_t mBitsPerPixelMem;
-#endif
     uint32_t mWidthCompression;
     uint32_t mHeightCompression;
@@ -293,5 +287,5 @@
             mScaleFuncttion(GL_NEAREST)
 {}
-    VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion);
+    VBoxVHWATexture(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion);
     virtual ~VBoxVHWATexture();
     virtual void init(uchar *pvMem);
@@ -349,6 +343,6 @@
 public:
     VBoxVHWATextureNP2() : VBoxVHWATexture() {}
-    VBoxVHWATextureNP2(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion) :
-        VBoxVHWATexture(aRect, aFormat, scaleFuncttion){
+    VBoxVHWATextureNP2(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
+        VBoxVHWATexture(aRect, aFormat, bytesPerLine, scaleFuncttion){
         mTexRect = QRect(0, 0, aRect.width()/aFormat.widthCompression(), aRect.height()/aFormat.heightCompression());
     }
@@ -359,6 +353,6 @@
 public:
     VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
-    VBoxVHWATextureNP2Rect(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion) :
-        VBoxVHWATextureNP2(aRect, aFormat, scaleFuncttion){}
+    VBoxVHWATextureNP2Rect(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
+        VBoxVHWATextureNP2(aRect, aFormat, bytesPerLine, scaleFuncttion){}
 
     virtual void texCoord(int x, int y);
@@ -375,6 +369,6 @@
         mPBO(0)
     {}
-    VBoxVHWATextureNP2RectPBO(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion) :
-        VBoxVHWATextureNP2Rect(aRect, aFormat, scaleFuncttion),
+    VBoxVHWATextureNP2RectPBO(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
+        VBoxVHWATextureNP2Rect(aRect, aFormat, bytesPerLine, scaleFuncttion),
         mPBO(0)
     {}
@@ -398,6 +392,6 @@
         mcbOffset(0)
     {}
-    VBoxVHWATextureNP2RectPBOMapped(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, GLint scaleFuncttion) :
-            VBoxVHWATextureNP2RectPBO(aRect, aFormat, scaleFuncttion),
+    VBoxVHWATextureNP2RectPBOMapped(const QRect & aRect, const VBoxVHWAColorFormat &aFormat, uint32_t bytesPerLine, GLint scaleFuncttion) :
+            VBoxVHWATextureNP2RectPBO(aRect, aFormat, bytesPerLine, scaleFuncttion),
             mpMappedAllignedBuffer(NULL),
             mcbOffset(0)
@@ -529,4 +523,7 @@
     const VBoxVHWAColorKey* srcCKey() { return mpSrcCKey; }
     bool notIntersectedMode() { return mbNotIntersected; }
+
+    static uint32_t calcBytesPerLine(const VBoxVHWAColorFormat & format, int width);
+    static uint32_t calcMemSize(const VBoxVHWAColorFormat & format, int width, int height);
 
 #ifdef DEBUG_misha
