void triSurf::readSurface(const fileName& fName) { if( fName.ext() == "fms" || fName.ext() == "FMS" ) { readFromFMS(fName); } else if( fName.ext() == "ftr" || fName.ext() == "FTR" ) { readFromFTR(fName); } else { triSurface copySurface(fName); //- copy the points triSurfPoints::points_.setSize(copySurface.points().size()); forAll(copySurface.points(), pI) triSurfPoints::points_[pI] = copySurface.points()[pI]; //- copy the triangles triSurfFacets::triangles_.setSize(copySurface.size()); forAll(copySurface, tI) triSurfFacets::triangles_[tI] = copySurface[tI]; //- copy patches triSurfFacets::patches_ = copySurface.patches(); } }
void Tiles::tileView() { copySurface( 0, 0, screen, tempScreen, &screen->clip_rect, false ); SDL_FillRect( tileSelectScreen, &tileSelectScreen->clip_rect, SDL_MapRGB( tileSelectScreen->format, 0x00, 0x00, 0x00 ) ); int tX = 20, tY = 20; SDL_Rect tempPos[100]; for( int n = 0 ; n <= totalTiles ; n++ ) { tempPos[n] = tPos[n]; tempPos[n].x *= 3; tempPos[n].y *= 3; tempPos[n].w *= 3; tempPos[n].h *= 3; lPos[n] = tPos[n]; lPos[n].w *= 3; lPos[n].h *= 3; lPos[n].x = tX; lPos[n].y = tY; largeTiles = rotozoomSurface( tiles, 0, 3, 0 ); copySurface( tX, tY, largeTiles, tileSelectScreen, &tempPos[n], false ); copySurface( 0, 0, tileSelectScreen, screen, &screen->clip_rect, true ); tX += ( 20 + lPos[n].w ); if( tX > (SCREEN_WIDTH - lPos[n].w - 20) ) { tX = 20; tY += 20 + lPos[n].w; } } }
SDL_Surface * CSDL_Ext::scaleSurfaceFast(SDL_Surface *surf, int width, int height) { if (!surf || !width || !height) return nullptr; //Same size? return copy - this should more be faster if (width == surf->w && height == surf->h) return copySurface(surf); SDL_Surface *ret = newSurface(width, height, surf); switch(surf->format->BytesPerPixel) { case 1: scaleSurfaceFastInternal<1>(surf, ret); break; case 2: scaleSurfaceFastInternal<2>(surf, ret); break; case 3: scaleSurfaceFastInternal<3>(surf, ret); break; case 4: scaleSurfaceFastInternal<4>(surf, ret); break; } return ret; }
Image* ImageBuffer::image() const { if (!m_image) { // It's assumed that if image() is called, the actual rendering to the // GraphicsContext must be done. ASSERT(context()); // This creates a COPY of the image and will cache that copy. This means // that if subsequent operations take place on the context, neither the // currently-returned image, nor the results of future image() calls, // will contain that operation. // // This seems silly, but is the way the CG port works: image() is // intended to be used only when rendering is "complete." cairo_surface_t* newsurface = copySurface(m_data.m_surface); // BitmapImage will release the passed in surface on destruction m_image = BitmapImage::create(newsurface); } return m_image.get(); }
CVideoSurface *CSurfaceFaderBase::fade(CScreenManager *screenManager, CVideoSurface *srcSurface) { if (_index == -1 || _index >= _count) return srcSurface; if (!_count && !setupSurface(screenManager, srcSurface)) return nullptr; srcSurface->lock(); _videoSurface->lock(); CSurfaceArea srCSurfaceArea(srcSurface); CSurfaceArea destSurfaceObj(_videoSurface); // Copy the surface with fading copySurface(srCSurfaceArea, destSurfaceObj); srcSurface->unlock(); _videoSurface->unlock(); ++_index; return _videoSurface; }
HRESULT PrimarySurface::Flip( LPDIRECTDRAWSURFACE lpDDSurfaceTargetOverride, DWORD dwFlags ) { #if LOGGER std::ostringstream str; str << this << " " << __FUNCTION__; if (lpDDSurfaceTargetOverride == nullptr) { str << " NULL"; } else if (lpDDSurfaceTargetOverride == this->_deviceResources->_backbufferSurface) { str << " BackbufferSurface"; } else if (lpDDSurfaceTargetOverride == this->_deviceResources->_frontbufferSurface) { str << " FrontbufferSurface"; } else { str << " " << lpDDSurfaceTargetOverride; } if (dwFlags & DDFLIP_WAIT) { str << " WAIT"; } LogText(str.str()); #endif this->_deviceResources->sceneRenderedEmpty = this->_deviceResources->sceneRendered == false; this->_deviceResources->sceneRendered = false; if (this->_deviceResources->sceneRenderedEmpty && this->_deviceResources->_frontbufferSurface != nullptr && this->_deviceResources->_frontbufferSurface->wasBltFastCalled) { this->_deviceResources->_d3dDeviceContext->ClearRenderTargetView(this->_deviceResources->_renderTargetView, this->_deviceResources->clearColor); this->_deviceResources->_d3dDeviceContext->ClearDepthStencilView(this->_deviceResources->_depthStencilView, D3D11_CLEAR_DEPTH, this->_deviceResources->clearDepth, 0); } if (lpDDSurfaceTargetOverride != nullptr) { if (lpDDSurfaceTargetOverride == this->_deviceResources->_frontbufferSurface) { HRESULT hr; if (FAILED(hr = this->_deviceResources->_backbufferSurface->BltFast(0, 0, this->_deviceResources->_frontbufferSurface, nullptr, 0))) return hr; return this->Flip(this->_deviceResources->_backbufferSurface, 0); } if (lpDDSurfaceTargetOverride == this->_deviceResources->_backbufferSurface) { if (this->_deviceResources->_frontbufferSurface == nullptr) { if (FAILED(this->_deviceResources->RenderMain(this->_deviceResources->_backbufferSurface->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, this->_deviceResources->_displayBpp))) return DDERR_GENERIC; } else { const unsigned short colorKey = 0x8080; int width = 640; int height = 480; int topBlack = 0; if (this->_deviceResources->_displayBpp == 2) { int w = this->_deviceResources->_displayWidth; int x = (this->_deviceResources->_displayWidth - width) / 2; int y = (this->_deviceResources->_displayHeight - height) / 2; unsigned short* buffer = (unsigned short*)this->_deviceResources->_backbufferSurface->_buffer + y * w + x; for (int i = 0; i < height / 2; i++) { if (buffer[i * w] != colorKey) break; topBlack++; } } else { const unsigned int colorKey32 = convertColorB5G6R5toB8G8R8X8(colorKey); int w = this->_deviceResources->_displayWidth; int x = (this->_deviceResources->_displayWidth - width) / 2; int y = (this->_deviceResources->_displayHeight - height) / 2; unsigned int* buffer = (unsigned int*)this->_deviceResources->_backbufferSurface->_buffer + y * w + x; for (int i = 0; i < height / 2; i++) { if (buffer[i * w] != colorKey32) break; topBlack++; } } if (topBlack < height / 2) { height -= topBlack * 2; } RECT rc; rc.left = (this->_deviceResources->_displayWidth - width) / 2; rc.top = (this->_deviceResources->_displayHeight - height) / 2; rc.right = rc.left + width; rc.bottom = rc.top + height; int length = width * height * this->_deviceResources->_displayBpp; char* buffer = new char[length]; copySurface(buffer, width, height, this->_deviceResources->_displayBpp, this->_deviceResources->_backbufferSurface->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, this->_deviceResources->_displayBpp, 0, 0, &rc, false); HRESULT hr = this->_deviceResources->RenderMain(buffer, width, height, this->_deviceResources->_displayBpp); delete[] buffer; if (FAILED(hr)) return DDERR_GENERIC; } HRESULT hr; if (this->_deviceResources->_swapChain) { UINT rate = 24 * this->_deviceResources->_refreshRate.Denominator; UINT numerator = this->_deviceResources->_refreshRate.Numerator + this->_flipFrames; UINT interval = numerator / rate; this->_flipFrames = numerator % rate; interval = max(interval, 1); hr = DD_OK; for (UINT i = 0; i < interval; i++) { this->_deviceResources->_d3dDeviceContext->ResolveSubresource(this->_deviceResources->_backBuffer, 0, this->_deviceResources->_offscreenBuffer, 0, DXGI_FORMAT_B8G8R8A8_UNORM); if (FAILED(hr = this->_deviceResources->_swapChain->Present(1, 0))) { static bool messageShown = false; if (!messageShown) { MessageBox(nullptr, _com_error(hr).ErrorMessage(), __FUNCTION__, MB_ICONERROR); } messageShown = true; hr = DDERR_SURFACELOST; break; } } } else { hr = DD_OK; } if (this->_deviceResources->_frontbufferSurface != nullptr) { if (this->_deviceResources->_frontbufferSurface->wasBltFastCalled) { memcpy(this->_deviceResources->_frontbufferSurface->_buffer2, this->_deviceResources->_frontbufferSurface->_buffer, this->_deviceResources->_frontbufferSurface->_bufferSize); } this->_deviceResources->_frontbufferSurface->wasBltFastCalled = false; } return hr; } } else { HRESULT hr; if (this->_deviceResources->_swapChain) { hr = DD_OK; this->_deviceResources->_d3dDeviceContext->ResolveSubresource(this->_deviceResources->_backBuffer, 0, this->_deviceResources->_offscreenBuffer, 0, DXGI_FORMAT_B8G8R8A8_UNORM); if (FAILED(hr = this->_deviceResources->_swapChain->Present(1, 0))) { static bool messageShown = false; if (!messageShown) { MessageBox(nullptr, _com_error(hr).ErrorMessage(), __FUNCTION__, MB_ICONERROR); } messageShown = true; hr = DDERR_SURFACELOST; } } else { hr = DD_OK; } return hr; } #if LOGGER str.str("\tDDERR_UNSUPPORTED"); LogText(str.str()); #endif return DDERR_UNSUPPORTED; }
PassRefPtr<Image> ImageBuffer::copyImage() const { // BitmapImage will release the passed in surface on destruction return BitmapImage::create(copySurface(m_data.m_surface)); }
void TextboxCreateWindow(Textbox * textbox) { SDL_Surface* temp = NULL; int width = textbox->boxWidth/16; int height = textbox->boxHeight/16; int i, j; temp = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, (width+1)*16, (height+1)*16, 32, 0, 0, 0, 0x000000FF); textbox->background = SDL_DisplayFormatAlpha(temp); textbox->refreshBackground = SDL_DisplayFormatAlpha(temp); for (i = 0; i <= width; i++){ for (j = 0; j <= height; j++){ if ((i == 0) && (j == 0)){ textbox->rcSrcTile.x = 0; textbox->rcSrcTile.y = 0; } else if ((i < width) && (j == 0)){ textbox->rcSrcTile.x = 16; textbox->rcSrcTile.y = 0; } else if ((i == width) && (j == 0)){ textbox->rcSrcTile.x = 32; textbox->rcSrcTile.y = 0; } else if ((i == width) && (j < height)){ textbox->rcSrcTile.x = 32; textbox->rcSrcTile.y = 16; } else if ((i == 0 ) && (j < height)){ textbox->rcSrcTile.x = 0; textbox->rcSrcTile.y = 16; } else if ((i == 0 ) && (j == height)){ textbox->rcSrcTile.x = 0; textbox->rcSrcTile.y = 32; } else if ((i < width ) && (j == height)){ textbox->rcSrcTile.x = 16; textbox->rcSrcTile.y = 32; } else if ((i == width ) && (j == height)){ textbox->rcSrcTile.x = 32; textbox->rcSrcTile.y = 32; } else{ textbox->rcSrcTile.x = 16; textbox->rcSrcTile.y = 16; } textbox->rcDestTile.x = 16*i; textbox->rcDestTile.y = 16*j; // apply tiles to textbox background copySurface(textbox->bgTileset, &textbox->rcSrcTile, textbox->background, &textbox->rcDestTile); copySurface(textbox->bgTileset, &textbox->rcSrcTile, textbox->refreshBackground, &textbox->rcDestTile); } } }
HRESULT BackbufferSurface::BltFast( DWORD dwX, DWORD dwY, LPDIRECTDRAWSURFACE lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwTrans ) { #if LOGGER std::ostringstream str; str << this << " " << __FUNCTION__; str << " " << dwX << " " << dwY; if (lpDDSrcSurface == nullptr) { str << " NULL"; } else if (lpDDSrcSurface == this->_deviceResources->_frontbufferSurface) { str << " FrontbufferSurface"; } else if (lpDDSrcSurface == this->_deviceResources->_offscreenSurface) { str << " OffscreenSurface"; } else { str << " " << lpDDSrcSurface; } str << tostr_RECT(lpSrcRect); if (dwTrans & DDBLTFAST_SRCCOLORKEY) { str << " SRCCOLORKEY"; } if (dwTrans & DDBLTFAST_DESTCOLORKEY) { str << " DESTCOLORKEY"; } if (dwTrans & DDBLTFAST_WAIT) { str << " WAIT"; } if (dwTrans & DDBLTFAST_DONOTWAIT) { str << " DONOTWAIT"; } LogText(str.str()); #endif if (lpDDSrcSurface != nullptr) { if (lpDDSrcSurface == this->_deviceResources->_frontbufferSurface) { copySurface(this->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, this->_deviceResources->_displayBpp, this->_deviceResources->_frontbufferSurface->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, 2, dwX, dwY, lpSrcRect, (dwTrans & DDBLTFAST_SRCCOLORKEY) != 0); this->_deviceResources->_frontbufferSurface->wasBltFastCalled = true; return DD_OK; } if (lpDDSrcSurface == this->_deviceResources->_offscreenSurface) { copySurface(this->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, this->_deviceResources->_displayBpp, this->_deviceResources->_offscreenSurface->_buffer, this->_deviceResources->_displayWidth, this->_deviceResources->_displayHeight, 2, dwX, dwY, lpSrcRect, (dwTrans & DDBLTFAST_SRCCOLORKEY) != 0); return DD_OK; } } #if LOGGER str.str("\tDDERR_UNSUPPORTED"); LogText(str.str()); #endif return DDERR_UNSUPPORTED; }