Changeset 25257 in vbox
- Timestamp:
- Dec 9, 2009 12:11:25 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 55782
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp
r25242 r25257 341 341 {} 342 342 343 // virtual ~VBoxVHWAGlShaderComponent();344 345 343 346 344 int init(); 347 // virtual int initUniforms(class VBoxVHWAGlProgram * pProgram){}348 // void uninit();349 345 350 346 const char * contents() { return mSource.constData(); } … … 359 355 int VBoxVHWAGlShaderComponent::init() 360 356 { 361 // Assert(!isInitialized());362 357 if(isInitialized()) 363 358 return VINF_ALREADY_INITIALIZED; … … 1817 1812 if(buf) 1818 1813 { 1819 // updateBuffer((uchar*)buf, &mRect);1820 1814 memcpy(buf, mAddress, memSize()); 1821 1815 … … 1827 1821 } 1828 1822 1829 #if 0 1830 void VBoxVHWASurfaceBase::synch(const QRect * aRect) 1831 { 1832 synchFB(aRect); 1833 synchTex(aRect); 1834 synchMem(aRect); 1835 } 1836 1837 void VBoxVHWASurfaceBase::synchFB(const QRect * pRect) 1838 { 1839 Assert(isYInverted()); 1840 1841 if(pRect) 1842 { 1843 Assert(mRect.contains(*pRect)); 1844 } 1845 1846 synchTexMem(pRect); 1847 1848 if(mUpdateTex2FBRect.isClear()) 1849 return; 1850 1851 if(pRect && !mUpdateTex2FBRect.rect().intersects(*pRect)) 1852 return; 1853 1854 mState->makeCurrent(this); 1823 uchar* VBoxVHWATextureNP2RectPBOMapped::mapAlignedBuffer() 1824 { 1825 Assert(!mpMappedAllignedBuffer); 1826 if(!mpMappedAllignedBuffer) 1827 { 1828 VBOXQGL_CHECKERR( 1829 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO); 1830 ); 1831 1832 uchar* buf; 1833 VBOXQGL_CHECKERR( 1834 buf = (uchar*)vboxglMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_READ_WRITE); 1835 ); 1836 1837 Assert(buf); 1838 1839 VBOXQGL_CHECKERR( 1840 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 1841 ); 1842 1843 mpMappedAllignedBuffer = (uchar*)alignBuffer(buf); 1844 1845 mcbOffset = calcOffset(buf, mpMappedAllignedBuffer); 1846 } 1847 return mpMappedAllignedBuffer; 1848 } 1849 1850 void VBoxVHWATextureNP2RectPBOMapped::unmapBuffer() 1851 { 1852 Assert(mpMappedAllignedBuffer); 1853 if(mpMappedAllignedBuffer) 1854 { 1855 VBOXQGL_CHECKERR( 1856 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO); 1857 ); 1858 1859 bool unmapped; 1860 VBOXQGL_CHECKERR( 1861 unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); 1862 ); 1863 1864 Assert(unmapped); 1865 1866 VBOXQGL_CHECKERR( 1867 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 1868 ); 1869 1870 mpMappedAllignedBuffer = NULL; 1871 } 1872 } 1873 1874 void VBoxVHWATextureNP2RectPBOMapped::load() 1875 { 1876 VBoxVHWATextureNP2Rect::load(); 1855 1877 1856 1878 VBOXQGL_CHECKERR( 1857 glBindTexture(GL_TEXTURE_2D, mTexture); 1858 ); 1859 1860 VBoxVHWAGlProgramMngr * pMngr = getGlProgramMngr(); 1861 pMngr->stopCurrentProgram(); 1862 1863 doTex2FB(&mUpdateTex2FBRect.rect(), &mUpdateTex2FBRect.rect()); 1864 1865 mUpdateTex2FBRect.clear(); 1866 Assert(mUpdateTex2FBRect.isClear()); 1867 } 1868 1869 void VBoxVHWASurfaceBase::synchMem(const QRect * pRect) 1870 { 1871 if(pRect) 1872 { 1873 Assert(mRect.contains(*pRect)); 1874 } 1875 1876 if(mUpdateFB2MemRect.isClear()) 1877 return; 1878 1879 if(pRect && !mUpdateFB2MemRect.rect().intersects(*pRect)) 1880 return; 1881 1882 mState->makeYInvertedCurrent(this); 1883 // mState->makeCurrent(this); 1884 1885 uchar * address = pointAddress(mUpdateFB2MemRect.rect().x(), mUpdateFB2MemRect.rect().y()); 1879 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO); 1880 ); 1886 1881 1887 1882 VBOXQGL_CHECKERR( 1888 glPixelStorei(GL_PACK_ROW_LENGTH, mRect.width()); 1889 ); 1883 vboxglBufferData(GL_PIXEL_UNPACK_BUFFER, mcbActualBufferSize, NULL, GL_STREAM_DRAW); 1884 ); 1885 1886 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 1887 } 1888 1889 void VBoxVHWATextureNP2RectPBOMapped::doUpdate(uchar * pAddress, const QRect * pRect) 1890 { 1891 Q_UNUSED(pAddress); 1892 Q_UNUSED(pRect); 1893 1890 1894 VBOXQGL_CHECKERR( 1891 glReadPixels( 1892 mUpdateFB2MemRect.rect().x(), 1893 mUpdateFB2MemRect.rect().y(), 1894 mUpdateFB2MemRect.rect().width(), 1895 mUpdateFB2MemRect.rect().height(), 1896 mColorFormat.format(), 1897 mColorFormat.type(), 1898 address); 1899 ); 1900 1901 mUpdateFB2MemRect.clear(); 1902 Assert(mUpdateFB2TexRect.isClear()); 1903 } 1904 1905 int VBoxVHWASurfaceBase::performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt) 1906 { 1907 // pDstCKey = NULL; 1908 // pSrcCKey = NULL; 1909 1910 GLuint tex = pSrcSurface->textureSynched(pSrcRect); 1911 1912 if(pDstCKey) 1913 { 1914 synchTex(pDstRect); 1915 } 1916 1917 mState->makeCurrent(this, blt); 1918 1919 VBoxVHWAGlProgramMngr * pMngr = getGlProgramMngr(); 1920 VBoxVHWAGlProgramVHWA * pProgram = pMngr->getProgram(pSrcCKey != NULL, &pSrcSurface->colorFormat(), &colorFormat()); 1921 if(pProgram) 1922 { 1923 if(pSrcCKey != NULL) 1924 { 1925 pProgram->start(); 1926 setCKey(pProgram, &pSrcSurface->colorFormat(), pSrcCKey); 1927 1928 vboxglActiveTexture(GL_TEXTURE0); 1929 } 1930 } 1931 else 1932 { 1933 pMngr->stopCurrentProgram(); 1934 } 1935 1936 // if(blt) 1937 { 1895 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPBO); 1896 ); 1897 1898 if(mpMappedAllignedBuffer) 1899 { 1900 bool unmapped; 1938 1901 VBOXQGL_CHECKERR( 1939 glBindTexture(GL_TEXTURE_2D, tex);1902 unmapped = vboxglUnmapBuffer(GL_PIXEL_UNPACK_BUFFER); 1940 1903 ); 1941 1904 1942 //TODO: setup strething params 1943 GLsizei wdt = pSrcSurface->mTexRect.width(); 1944 GLsizei hgt = pSrcSurface->mTexRect.height(); 1945 1946 VBOXQGL_CHECKERR( 1947 glMatrixMode(GL_TEXTURE); 1948 ); 1949 VBOXQGL_CHECKERR( 1950 glPushMatrix(); 1951 ); 1952 1953 VBoxGLWidget::doSetupMatrix(QSize(wdt, hgt), true); 1954 VBOXQGL_CHECKERR( 1955 glMatrixMode(GL_MODELVIEW); 1956 ); 1957 1958 doTex2FB(pDstRect, pSrcRect); 1959 1960 VBOXQGL_CHECKERR( 1961 glMatrixMode(GL_TEXTURE); 1962 ); 1963 VBOXQGL_CHECKERR( 1964 glPopMatrix(); 1965 ); 1966 VBOXQGL_CHECKERR( 1967 glMatrixMode(GL_MODELVIEW); 1968 ); 1969 } 1970 // else 1971 // { 1972 // 1973 // } 1974 1975 /* if dst color key */ 1976 /* setup ckey shader */ 1977 if(pDstCKey) 1978 { 1979 VBOXQGL_CHECKERR( 1980 glBindTexture(GL_TEXTURE_2D, mTexture); 1981 ); 1982 pProgram = pMngr->getProgram(true, NULL, NULL); 1983 /* setup ckey values*/ 1984 setCKey(pProgram, &colorFormat(), pDstCKey); 1985 pProgram->start(); 1986 doTex2FB(pDstRect, pDstRect); 1987 } 1988 1989 return VINF_SUCCESS; 1990 } 1991 1992 int VBoxVHWASurfaceBase::overlay(VBoxVHWASurfaceBase * pOverlaySurface) 1993 { 1994 VBOXQGLLOG(("overlay src(0x%x) ", pOverlaySurface)); 1995 VBOXQGLLOG_QRECT("dst: ", &pOverlaySurface->mTargRect, "\n"); 1996 VBOXQGLLOG_QRECT("src: ", &pOverlaySurface->mSrcRect, "\n"); 1997 VBOXQGLLOG_METHODTIME("time:"); 1998 1999 Assert(!pOverlaySurface->isHidden()); 2000 2001 if(pOverlaySurface->isHidden()) 2002 { 2003 VBOXQGLLOG(("!!!hidden!!!\n")); 2004 return VINF_SUCCESS; 2005 } 2006 2007 const QRect * pSrcRect = &pOverlaySurface->mSrcRect; 2008 const QRect * pDstRect = &pOverlaySurface->mTargRect; 2009 const VBoxVHWAColorKey * pSrcCKey = pOverlaySurface->srcOverlayCKey(); 2010 /* we use src (overlay) surface to maintain overridden dst ckey info 2011 * to allow multiple overlays have different overridden dst keys for one primary surface */ 2012 /* non-null dstOverlayCKey for overlay would mean the overlay surface contains the overridden 2013 * dst ckey value in defaultDstOverlayCKey 2014 * this allows the NULL to be a valid overridden value as well */ 2015 const VBoxVHWAColorKey * pDstCKey = pOverlaySurface->dstOverlayCKey() ? pOverlaySurface->defaultDstOverlayCKey() : dstOverlayCKey(); 2016 2017 return performBlt(pDstRect, pOverlaySurface, pSrcRect, pDstCKey, pSrcCKey, false); 2018 } 2019 2020 int VBoxVHWASurfaceBase::blt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey) 2021 { 2022 if(pDstRect) 2023 { 2024 Assert(mRect.contains(*pDstRect)); 2025 } 2026 else 2027 { 2028 pDstRect = &mRect; 2029 } 2030 2031 if(pSrcRect) 2032 { 2033 Assert(pSrcSurface->mRect.contains(*pSrcRect)); 2034 } 2035 else 2036 { 2037 pSrcRect = &pSrcSurface->mRect; 2038 } 2039 2040 if(!pSrcCKey) 2041 pSrcCKey = pSrcSurface->srcBltCKey(); 2042 if(!pDstCKey) 2043 pDstCKey = dstBltCKey(); 2044 2045 VBOXQGLLOG(("blt dst(0x%x), src(0x%x)", this, pSrcSurface)); 2046 VBOXQGLLOG_QRECT("dst: ", pDstRect, "\n"); 2047 VBOXQGLLOG_QRECT("src: ", pSrcRect, "\n"); 2048 VBOXQGLLOG_METHODTIME("time:"); 2049 int rc = performBlt(pDstRect, pSrcSurface, pSrcRect, pDstCKey, pSrcCKey, true); 2050 2051 mUpdateFB2TexRect.add(*pDstRect); 2052 Assert(!mUpdateFB2TexRect.isClear()); 2053 Assert(mRect.contains(mUpdateFB2TexRect.rect())); 2054 // synchTexture(pDstRect); 2055 mUpdateFB2MemRect.add(*pDstRect); 2056 Assert(!mUpdateFB2MemRect.isClear()); 2057 Assert(mRect.contains(mUpdateFB2MemRect.rect())); 2058 2059 return rc; 2060 } 2061 #endif 1905 Assert(unmapped); 1906 1907 mpMappedAllignedBuffer = NULL; 1908 } 1909 1910 VBoxVHWATextureNP2Rect::doUpdate((uchar *)mcbOffset, &mRect); 1911 1912 VBOXQGL_CHECKERR( 1913 vboxglBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 1914 ); 1915 } 1916 2062 1917 void VBoxVHWASurfaceBase::doTex2FB(const QRect * pDstRect, const QRect * pSrcRect) 2063 1918 { … … 2068 1923 tx2++; ty2++;bx2++; by2++; 2069 1924 2070 #if 1 2071 // VBOXQGL_CHECKERR( 2072 VBOXQGLLOG_QRECT("texRect: ", &mpTex[0]->texRect(), "\n"); 2073 glBegin(GL_QUADS); 2074 // glTexCoord2d(((double)tx1)/mpTex[0]->texRect().width(), ((double)ty1)/mpTex[0]->texRect().height()); 2075 // glVertex2i(bx1, by1); 2076 // glTexCoord2d(((double)tx1)/mpTex[0]->texRect().width(), ((double)ty2)/mpTex[0]->texRect().height()); 2077 // glVertex2i(bx1, by2); 2078 // glTexCoord2d(((double)tx2)/mpTex[0]->texRect().width(), ((double)ty2)/mpTex[0]->texRect().height()); 2079 // glVertex2i(bx2, by2); 2080 // glTexCoord2d(((double)tx2)/mpTex[0]->texRect().width(), ((double)ty1)/mpTex[0]->texRect().height()); 2081 // glVertex2i(bx2, by1); 2082 mpTex[0]->texCoord(tx1, ty1); 2083 glVertex2i(bx1, by1); 2084 mpTex[0]->texCoord(tx1, ty2); 2085 glVertex2i(bx1, by2); 2086 mpTex[0]->texCoord(tx2, ty2); 2087 glVertex2i(bx2, by2); 2088 mpTex[0]->texCoord(tx2, ty1); 2089 glVertex2i(bx2, by1); 2090 2091 glEnd(); 2092 // ); 2093 #else 2094 glBegin(GL_QUADS); 2095 glTexCoord2d(0.0, 0.0); 2096 glVertex2i(0, 0); 2097 glTexCoord2d(0.0, 1.0); 2098 glVertex2i(0, mRect.height()); 2099 glTexCoord2d(1.0, 1.0); 2100 glVertex2i(mRect.width(), mRect.height()); 2101 glTexCoord2d(1.0, 0.0); 2102 glVertex2i(mRect.width(), 0); 2103 glEnd(); 2104 #endif 1925 VBOXQGLLOG_QRECT("texRect: ", &mpTex[0]->texRect(), "\n"); 1926 glBegin(GL_QUADS); 1927 mpTex[0]->texCoord(tx1, ty1); 1928 glVertex2i(bx1, by1); 1929 mpTex[0]->texCoord(tx1, ty2); 1930 glVertex2i(bx1, by2); 1931 mpTex[0]->texCoord(tx2, ty2); 1932 glVertex2i(bx2, by2); 1933 mpTex[0]->texCoord(tx2, ty1); 1934 glVertex2i(bx2, by1); 1935 glEnd(); 2105 1936 } 2106 1937 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h
r25171 r25257 192 192 public: 193 193 194 // VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);195 194 VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b); 196 195 VBoxVHWAColorFormat(uint32_t fourcc); … … 203 202 uint32_t bitsPerPixel() const { return mBitsPerPixel; } 204 203 uint32_t bitsPerPixelTex() const { return mBitsPerPixelTex; } 205 // uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }206 204 void pixel2Normalized(uint32_t pix, float *r, float *g, float *b) const; 207 205 uint32_t widthCompression() const {return mWidthCompression;} … … 225 223 uint32_t mBitsPerPixel; 226 224 uint32_t mBitsPerPixelTex; 227 // uint32_t mBitsPerPixelDd;228 225 uint32_t mWidthCompression; 229 226 uint32_t mHeightCompression; … … 311 308 { 312 309 public: 313 VBoxVHWATextureNP2RectPBO() : VBoxVHWATextureNP2Rect() {} 310 VBoxVHWATextureNP2RectPBO() : 311 VBoxVHWATextureNP2Rect(), 312 mPBO(0) 313 {} 314 314 VBoxVHWATextureNP2RectPBO(const QRect & aRect, const VBoxVHWAColorFormat &aFormat) : 315 VBoxVHWATextureNP2Rect(aRect, aFormat){} 315 VBoxVHWATextureNP2Rect(aRect, aFormat), 316 mPBO(0) 317 {} 318 316 319 virtual ~VBoxVHWATextureNP2RectPBO(); 317 320 … … 320 323 virtual void load(); 321 324 virtual void doUpdate(uchar * pAddress, const QRect * pRect); 322 private:323 325 GLuint mPBO; 326 }; 327 328 class VBoxVHWATextureNP2RectPBOMapped : public VBoxVHWATextureNP2RectPBO 329 { 330 public: 331 VBoxVHWATextureNP2RectPBOMapped() : 332 VBoxVHWATextureNP2RectPBO(), 333 mpMappedAllignedBuffer(NULL), 334 mcbAllignedBufferSize(0), 335 mcbOffset(0) 336 {} 337 VBoxVHWATextureNP2RectPBOMapped(const QRect & aRect, const VBoxVHWAColorFormat &aFormat) : 338 VBoxVHWATextureNP2RectPBO(aRect, aFormat), 339 mpMappedAllignedBuffer(NULL), 340 mcbOffset(0) 341 { 342 mcbAllignedBufferSize = alignSize((size_t)memSize()); 343 mcbActualBufferSize = mcbAllignedBufferSize + 0x1fff; 344 } 345 346 uchar* mapAlignedBuffer(); 347 void unmapBuffer(); 348 size_t alignedBufferSize() { return mcbAllignedBufferSize; } 349 350 static size_t alignSize(size_t size) 351 { 352 size_t alSize = size & ~((size_t)0xfff); 353 return alSize == size ? alSize : alSize + 0x1000; 354 } 355 356 static void* alignBuffer(void* pvMem) { return (void*)(((uintptr_t)pvMem) & ~((uintptr_t)0xfff)); } 357 static size_t calcOffset(void* pvBase, void* pvOffset) { return (size_t)(((uintptr_t)pvBase) - ((uintptr_t)pvOffset)); } 358 protected: 359 virtual void load(); 360 virtual void doUpdate(uchar * pAddress, const QRect * pRect); 361 private: 362 uchar* mpMappedAllignedBuffer; 363 size_t mcbAllignedBufferSize; 364 size_t mcbOffset; 365 size_t mcbActualBufferSize; 366 }; 367 368 class VBoxVHWAAlignedPBO 369 { 370 public: 371 void init(size_t size) 372 { 373 374 } 375 376 size_t alignedSize() { return mAlignedSize; } 377 size_t actualSize() { return mActualSize; } 378 size_t requestedSize() { return mRequestedSize; } 379 void* alignedBuffer() { return mAlignedBuffer; } 380 void* actualBuffer() { return mActualBuffer; } 381 382 private: 383 void* mAlignedBuffer; 384 void* mActualBuffer; 385 size_t mAlignedSize; 386 size_t mActualSize; 387 size_t mRequestedSize; 324 388 }; 325 389
Note:
See TracChangeset
for help on using the changeset viewer.