Changeset 51141 in vbox for trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp
- Timestamp:
- Apr 25, 2014 12:51:03 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/util/blitter.cpp
r50624 r51141 23 23 #include "cr_mem.h" 24 24 #include "cr_string.h" 25 #include "cr_bmpscale.h" 25 26 26 27 #include <iprt/cdefs.h> 27 28 #include <iprt/types.h> 28 29 #include <iprt/mem.h> 30 31 static void crMClrFillMem(uint32_t *pu32Dst, int32_t cbDstPitch, uint32_t width, uint32_t height, uint32_t u32Color) 32 { 33 for (uint32_t i = 0; i < height; ++i) 34 { 35 for (uint32_t j = 0; j < width; ++j) 36 { 37 pu32Dst[j] = u32Color; 38 } 39 40 pu32Dst = (uint32_t*)(((uint8_t*)pu32Dst) + cbDstPitch); 41 } 42 } 43 44 void CrMClrFillImgRect(CR_BLITTER_IMG *pDst, const RTRECT *pCopyRect, uint32_t u32Color) 45 { 46 int32_t x = pCopyRect->xLeft; 47 int32_t y = pCopyRect->yTop; 48 int32_t width = pCopyRect->xRight - pCopyRect->xLeft; 49 int32_t height = pCopyRect->yBottom - pCopyRect->yTop; 50 Assert(x >= 0); 51 Assert(y >= 0); 52 uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + pDst->pitch * y + x * 4; 53 54 crMClrFillMem((uint32_t*)pu8Dst, pDst->pitch, width, height, u32Color); 55 } 56 57 void CrMClrFillImg(CR_BLITTER_IMG *pImg, uint32_t cRects, const RTRECT *pRects, uint32_t u32Color) 58 { 59 RTRECT Rect; 60 Rect.xLeft = 0; 61 Rect.yTop = 0; 62 Rect.xRight = pImg->width; 63 Rect.yBottom = pImg->height; 64 65 66 RTRECT Intersection; 67 const RTPOINT ZeroPoint = {0, 0}; 68 69 for (uint32_t i = 0; i < cRects; ++i) 70 { 71 const RTRECT * pRect = &pRects[i]; 72 VBoxRectIntersected(pRect, &Rect, &Intersection); 73 74 if (VBoxRectIsZero(&Intersection)) 75 continue; 76 77 CrMClrFillImgRect(pImg, &Intersection, u32Color); 78 } 79 } 80 81 static void crMBltMem(const uint8_t *pu8Src, int32_t cbSrcPitch, uint8_t *pu8Dst, int32_t cbDstPitch, uint32_t width, uint32_t height) 82 { 83 uint32_t cbCopyRow = width * 4; 84 85 for (uint32_t i = 0; i < height; ++i) 86 { 87 memcpy(pu8Dst, pu8Src, cbCopyRow); 88 89 pu8Src += cbSrcPitch; 90 pu8Dst += cbDstPitch; 91 } 92 } 93 94 void CrMBltImgRect(const CR_BLITTER_IMG *pSrc, const RTPOINT *pSrcDataPoint, bool fSrcInvert, const RTRECT *pCopyRect, CR_BLITTER_IMG *pDst) 95 { 96 int32_t srcX = pCopyRect->xLeft - pSrcDataPoint->x; 97 int32_t srcY = pCopyRect->yTop - pSrcDataPoint->y; 98 Assert(srcX >= 0); 99 Assert(srcY >= 0); 100 Assert(srcX < (int32_t)pSrc->width); 101 Assert(srcY < (int32_t)pSrc->height); 102 103 int32_t dstX = pCopyRect->xLeft; 104 int32_t dstY = pCopyRect->yTop; 105 Assert(dstX >= 0); 106 Assert(dstY >= 0); 107 Assert(dstX < (int32_t)pDst->width); 108 Assert(dstY < (int32_t)pDst->height); 109 110 uint8_t *pu8Src = ((uint8_t*)pSrc->pvData) + pSrc->pitch * (!fSrcInvert ? srcY : pSrc->height - srcY - 1) + srcX * 4; 111 uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + pDst->pitch * dstY + dstX * 4; 112 113 crMBltMem(pu8Src, fSrcInvert ? -((int32_t)pSrc->pitch) : (int32_t)pSrc->pitch, pu8Dst, pDst->pitch, pCopyRect->xRight - pCopyRect->xLeft, pCopyRect->yBottom - pCopyRect->yTop); 114 } 115 116 void CrMBltImg(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, uint32_t cRects, const RTRECT *pRects, CR_BLITTER_IMG *pDst) 117 { 118 RTRECT Intersection; 119 RTRECT RestrictSrcRect; 120 RestrictSrcRect.xLeft = 0; 121 RestrictSrcRect.yTop = 0; 122 RestrictSrcRect.xRight = pSrc->width; 123 RestrictSrcRect.yBottom = pSrc->height; 124 RTRECT RestrictDstRect; 125 RestrictDstRect.xLeft = 0; 126 RestrictDstRect.yTop = 0; 127 RestrictDstRect.xRight = pDst->width; 128 RestrictDstRect.yBottom = pDst->height; 129 130 for (uint32_t i = 0; i < cRects; ++i) 131 { 132 const RTRECT * pRect = &pRects[i]; 133 VBoxRectIntersected(pRect, &RestrictDstRect, &Intersection); 134 135 RTRECT TranslatedSrc; 136 VBoxRectTranslated(&RestrictSrcRect, pPos->x, pPos->y, &TranslatedSrc); 137 138 VBoxRectIntersect(&Intersection, &TranslatedSrc); 139 140 if (VBoxRectIsZero(&Intersection)) 141 continue; 142 143 CrMBltImgRect(pSrc, pPos, false, &Intersection, pDst); 144 } 145 } 146 147 void CrMBltImgRectScaled(const CR_BLITTER_IMG *pSrc, const RTPOINT *pPos, bool fSrcInvert, const RTRECT *pCopyRect, float strX, float strY, CR_BLITTER_IMG *pDst) 148 { 149 RTPOINT UnscaledPos; 150 UnscaledPos.x = CR_FLOAT_RCAST(int32_t, pPos->x / strX); 151 UnscaledPos.y = CR_FLOAT_RCAST(int32_t, pPos->y / strY); 152 153 RTRECT UnscaledCopyRect; 154 155 VBoxRectUnscaled(pCopyRect, strX, strY, &UnscaledCopyRect); 156 157 if (VBoxRectIsZero(&UnscaledCopyRect)) 158 { 159 WARN(("ups")); 160 return; 161 } 162 163 int32_t srcX = UnscaledCopyRect.xLeft - UnscaledPos.x; 164 int32_t srcY = UnscaledCopyRect.yTop - UnscaledPos.y; 165 if (srcX < 0) 166 { 167 WARN(("ups")); 168 srcX = 0; 169 } 170 if (srcY < 0) 171 { 172 WARN(("ups")); 173 srcY = 0; 174 } 175 176 if (srcX >= pSrc->width) 177 { 178 WARN(("ups")); 179 return; 180 } 181 182 if (srcY >= pSrc->height) 183 { 184 WARN(("ups")); 185 return; 186 } 187 188 Assert(srcX >= 0); 189 Assert(srcY >= 0); 190 Assert(srcX < (int32_t)pSrc->width); 191 Assert(srcY < (int32_t)pSrc->height); 192 193 int32_t dstX = pCopyRect->xLeft; 194 int32_t dstY = pCopyRect->yTop; 195 Assert(dstX >= 0); 196 Assert(dstY >= 0); 197 198 int32_t UnscaledSrcWidth = UnscaledCopyRect.xRight - UnscaledCopyRect.xLeft; 199 int32_t UnscaledSrcHeight = UnscaledCopyRect.yBottom - UnscaledCopyRect.yTop; 200 201 UnscaledSrcWidth = RT_MIN(srcX + UnscaledSrcWidth, pSrc->width); 202 UnscaledSrcHeight = RT_MIN(srcY + UnscaledSrcHeight, pSrc->height); 203 204 uint8_t *pu8Src = ((uint8_t*)pSrc->pvData) + pSrc->pitch * (!fSrcInvert ? srcY : pSrc->height - srcY - 1) + srcX * 4; 205 uint8_t *pu8Dst = ((uint8_t*)pDst->pvData) + pDst->pitch * dstY + dstX * 4; 206 207 CrBmpScale32(pu8Dst, pDst->pitch, 208 pCopyRect->xRight - pCopyRect->xLeft, pCopyRect->yBottom - pCopyRect->yTop, 209 pu8Src, 210 fSrcInvert ? -((int32_t)pSrc->pitch) : (int32_t)pSrc->pitch, 211 UnscaledSrcWidth, UnscaledSrcHeight); 212 } 213 214 215 void CrMBltImgScaled(const CR_BLITTER_IMG *pSrc, const RTRECTSIZE *pSrcRectSize, const RTRECT *pDstRect, uint32_t cRects, const RTRECT *pRects, CR_BLITTER_IMG *pDst) 216 { 217 int32_t srcWidth = pSrcRectSize->cx; 218 int32_t srcHeight = pSrcRectSize->cy; 219 int32_t dstWidth = pDstRect->xRight - pDstRect->xLeft; 220 int32_t dstHeight = pDstRect->yBottom - pDstRect->yTop; 221 222 float strX = ((float)dstWidth) / srcWidth; 223 float strY = ((float)dstHeight) / srcHeight; 224 bool fScale = (dstWidth != srcWidth || dstHeight != srcHeight); 225 Assert(fScale); 226 227 RTRECT Intersection; 228 RTRECT UnscaledRestrictSrcRect; 229 UnscaledRestrictSrcRect.xLeft = 0; 230 UnscaledRestrictSrcRect.yTop = 0; 231 UnscaledRestrictSrcRect.xRight = CR_FLOAT_RCAST(int32_t, pSrc->width / strX); 232 UnscaledRestrictSrcRect.yBottom = CR_FLOAT_RCAST(int32_t, pSrc->height / strY); 233 RTRECT RestrictDstRect; 234 RestrictDstRect.xLeft = 0; 235 RestrictDstRect.yTop = 0; 236 RestrictDstRect.xRight = pDst->width; 237 RestrictDstRect.yBottom = pDst->height; 238 239 RTPOINT Pos = {pDstRect->xLeft, pDstRect->yTop}; 240 RTPOINT UnscaledSrcPos; 241 UnscaledSrcPos.x = CR_FLOAT_RCAST(int32_t, Pos.x / strX); 242 UnscaledSrcPos.y = CR_FLOAT_RCAST(int32_t, Pos.y / strY); 243 244 for (uint32_t i = 0; i < cRects; ++i) 245 { 246 const RTRECT * pRect = &pRects[i]; 247 VBoxRectIntersected(pRect, &RestrictDstRect, &Intersection); 248 249 RTRECT TranslatedSrc; 250 VBoxRectTranslated(&UnscaledRestrictSrcRect, UnscaledSrcPos.x, UnscaledSrcPos.y, &TranslatedSrc); 251 252 VBoxRectIntersect(&Intersection, &TranslatedSrc); 253 254 if (VBoxRectIsZero(&Intersection)) 255 continue; 256 257 CrMBltImgRectScaled(pSrc, &Pos, false, &Intersection, strX, strY, pDst); 258 } 259 } 29 260 30 261 /* @param pCtxBase - contains the blitter context info. Its value is treated differently depending on the fCreateNewCtx value
Note:
See TracChangeset
for help on using the changeset viewer.